Skip to content

Instantly share code, notes, and snippets.

@eeeschwartz
Created November 5, 2014 17:51
Show Gist options
  • Save eeeschwartz/909a4cfab8e5b81fbb49 to your computer and use it in GitHub Desktop.
Save eeeschwartz/909a4cfab8e5b81fbb49 to your computer and use it in GitHub Desktop.
Quick and dirty esri REST to GeoJSON adapter
def format_leaf_collection(geo_json)
esri_formatted = JSON.parse(geo_json)
features = esri_formatted['features'].map do |feature|
properties = feature['attributes']
title = "Hello! Leaf collection status in your area is now '#{properties['Status']}'."
title += " Collection dates are #{properties['Dates']}" if properties['Dates']
{
type: "Feature",
id: properties['OBJECTID'],
properties: {
title: title
},
geometry: {
type: "Polygon",
coordinates: feature['geometry']['rings']
}
}
end
{
type: "FeatureCollection",
features: features
}.to_json
end
get '/lexington-leaf-collection' do
content_type :json
source = 'http://services1.arcgis.com/Mg7DLdfYcSWIaDnu/ArcGIS/rest/services/Leaf_Collection/FeatureServer/1/query?where=++objectid%3Dobjectid&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&distance=&units=esriSRUnit_Meter&outFields=*&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=4326&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&resultOffset=0&resultRecordCount=&returnZ=false&returnM=false&f=pjson&token='
connection = Faraday.new(url: source) do |conn|
conn.headers['Content-Type'] = content_type
conn.adapter Faraday.default_adapter
end
format_leaf_collection connection.get.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment