Skip to content

Instantly share code, notes, and snippets.

@ddd1600
Last active January 8, 2016 18:25
Show Gist options
  • Save ddd1600/8396569b05b817ecb995 to your computer and use it in GitHub Desktop.
Save ddd1600/8396569b05b817ecb995 to your computer and use it in GitHub Desktop.
geoference plugin helper
require 'geocoder'
require 'highline/import'
puts "to use this tool again after running, run `GeoreferencerBuddy.go`.\nto use just the lat/lng plucker, there is also a class method called `pluck`"
#
#this tool is best if added as an alias to .bash_profile or equivalent.
#example:
#alias georeference='ruby /Users/davo/helpers/georeference_buddy.rb'
#alias geo='georeference'
class GeoreferenceBuddy
def self.pluck_lat_lng(geocoder_response)
geocoder_response[0].data['geometry']['location'].values
end
def self.go
$query, $resp, $lat, $lng = nil, nil, nil, nil
#artifacts ($query, $resp, $lat & $lng) cleared. starting georeference helper process.\n****************************\n"
city_state = ask "City, State?"
puts "running for #{city_state}"
continue = true
while continue == true
$query = (ask "please type an intersection") + ", " + city_state
raise "your query needs to include the word 'and' in some form or symbol" unless $query.downcase =~ /and|\&/
$resp = Geocoder.search($query)
if $resp.count > 1
puts "more than one match returned. shown below. using first one by default"
ap $resp
puts "--------\ncontinuing with process for first match...\n"
end
$lat,$lng = pluck_lat_lng($resp)
`echo #{$lat}| pbcopy`
ask "copied latitude to clipboard. press any key to continue\n#{$lat}"
`echo #{$lng} | pbcopy`
ask "copied longitude (#{$lng} to clipboard process completed. press any key to continue.\n#{$lng}"
continue_loop_response = ask ="\npress 's' or 'n' to halt process. otherwise press enter to start over with a new spot\n"
continue = continue_loop_response.downcase =~ /s|n/ ? false : true
end
puts "aut-o-mation."
end# of method
end# of class
GeoreferenceBuddy.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment