Last active
July 9, 2021 18:02
-
-
Save nickpeihl/1a77b7f8ed8f70b516a185d55ff0d21e to your computer and use it in GitHub Desktop.
GBFS to GeoJSON
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
var gbfs2geojson = require("gbfs2geojson-js"); | |
var fs = require("fs"); | |
var autoDiscoveryUrl = | |
"https://ckan0.cf.opendata.inter.prod-toronto.ca/dataset/2b44db0d-eea9-442d-b038-79335368ad5a/resource/142dfb32-d81b-474b-811a-dfc47560ac26/download/bike-share-json.json"; | |
var data; | |
gbfs2geojson.getAllData(autoDiscoveryUrl, data, (data, err) => { | |
if (err) { | |
throw err; | |
} | |
const features = Object.values(data) | |
.filter((feature) => { | |
return feature.hasOwnProperty("geometry"); | |
}) | |
.map((feature) => { | |
// 🙄 | |
feature.geometry.coordinates.reverse(); | |
return feature; | |
}); | |
const fc = { type: "FeatureCollection", features }; | |
fs.writeFileSync("./stations.json", JSON.stringify(fc), "utf-8"); | |
}); |
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
{ | |
"name": "gbfs2geojson", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"gbfs2geojson-js": "^1.0.4" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment