Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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