Skip to content

Instantly share code, notes, and snippets.

@muziejus
Created February 6, 2016 05:20
Show Gist options
  • Save muziejus/7ed7ea4de94800a9bd12 to your computer and use it in GitHub Desktop.
Save muziejus/7ed7ea4de94800a9bd12 to your computer and use it in GitHub Desktop.
Make a geojson file out of the app dump for CitiBike locations
# citibike stations: http://appservices.citibikenyc.com/v1/station/list
# Save this json file as "citibikestations.json"
# The result is a file called "citibikestations.geojson," which Qgis will read with no trouble. Leaflet too.
require 'json'
bike_stations = JSON.parse(File.read('citibikestations.json'))
geojson_array = bike_stations["results"].map do |p|
{ "type" => "Feature",
"geometry" => {
"type" => "Point",
"coordinates" => [p["longitude"], p["latitude"]]
},
"properties" => {
"name" => p["label"],
"status" => p["status"],
"id" => p["id"]
# Add other properties, like bikes available or whatever, as you see fit.
}
}
end
geojson = { "type" => "FeatureCollection", "features" => geojson_array }
File.open('citibikestations.geojson', 'w') do |f|
f.write geojson.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment