Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Forked from kenichi/gist:d39a340bb4483d97b78b
Last active August 29, 2015 14:02
Show Gist options
  • Save aaronpk/3735083bbe040775a56f to your computer and use it in GitHub Desktop.
Save aaronpk/3735083bbe040775a56f to your computer and use it in GitHub Desktop.
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