Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created January 28, 2016 16:49
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 tmcw/99366184c386e3aab354 to your computer and use it in GitHub Desktop.
Save tmcw/99366184c386e3aab354 to your computer and use it in GitHub Desktop.
name lat lng
Tom 42 20
var mapnik = require('mapnik');
mapnik.register_default_input_plugins();
var source = new mapnik.Datasource({
type: 'csv', file: './csv_to_geojson.csv'
});
// get meta-information about this datasource
console.log(source.describe());
// convert this CSV file into GeoJSON
var featureset = source.featureset();
var featureCollection = { type: 'FeatureCollection', features: [] }, feature;
while (feature = featureset.next()) {
featureCollection.features.push(JSON.parse(feature.toJSON()));
}
console.log(JSON.stringify(featureCollection, null, 2));
{
"name": "mapnik-second-act",
"version": "1.0.0",
"description": "demos of useful mapnik functionality",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"mapnik",
"demos"
],
"author": "Tom MacWright",
"license": "ISC",
"dependencies": {
"mapnik": "^3.4.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment