Skip to content

Instantly share code, notes, and snippets.

@nickpeihl
Last active July 9, 2021 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickpeihl/1a77b7f8ed8f70b516a185d55ff0d21e to your computer and use it in GitHub Desktop.
Save nickpeihl/1a77b7f8ed8f70b516a185d55ff0d21e to your computer and use it in GitHub Desktop.
GBFS to GeoJSON
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");
});
{
"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