-
-
Save aaronpk/3735083bbe040775a56f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'terraformer' | |
require 'geotrigger' | |
require 'launchy' | |
require 'gist' | |
# create a new FeatureCollection | |
# | |
fc = Terraformer::FeatureCollection.new | |
# create a Geotrigger Application session with credentials stored in ~/.geotrigger under the :foo key | |
# | |
a = Geotrigger::Application.new config: :foo | |
# iterate each trigger in the application with a tag of 'foo', parsing the geometry GeoJSON | |
# fragments into features, and adding them to the FeatureCollection | |
# | |
a.triggers(tags: 'foo').each {|t| fc << Terraformer.parse(t.condition['geo']['geojson']).to_feature} | |
# pipe the FeatureCollection to the http://geojson.io editor | |
# | |
json = fc.to_json | |
encoded = URI.encode_www_form_component json | |
# check if the encoded length is longer than 2000 cause some browsers might not like that | |
if encoded.length > 2000 | |
# upload to gist | |
gist_id = Gist.gist('hello world')['id'] | |
url = "http://geojson.io/#id=gist:/#{gist_id}" | |
else | |
url = "http://geojson.io/#data=data:application/json,#{encoded}" | |
end | |
Launchy.open url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment