Skip to content

Instantly share code, notes, and snippets.

@ungoldman
Last active August 29, 2015 14:10
Show Gist options
  • Save ungoldman/05603d639276b0c1f69d to your computer and use it in GitHub Desktop.
Save ungoldman/05603d639276b0c1f69d to your computer and use it in GitHub Desktop.
geojson2csv w/ polygons

Getting polygons from GeoJSON to CSV

As of v0.1.1, geojson2csv doesn't work with polygons. Trying to figure out the best way to represent polygons in a CSV in the first place and ran into this issue.

See morganherlocker/geojson2csv#1

var geojson2csv = require('geojson2csv')
console.log('hello')
geojson2csv('./polygon.geojson', './output.csv', function(err){
if (err) throw err
console.log('hi')
})
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 2 columns, instead of 13 in line 1.
lat,lon
43.2421875,56.17002298293205,55.54687499999999,46.07323062540838,86.484375,56.559482483762245,61.17187499999999,63.074865690586634,48.8671875,61.438767493682825,43.2421875,56.17002298293205,undefined
{
"name": "geojson2csv-polygons",
"main": "index.js",
"dependencies": {
"geojson2csv": "^0.1.1"
},
"license": "ISC"
}
Display the source blob
Display the rendered blob
Raw
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
43.2421875,
56.17002298293205
],
[
55.54687499999999,
46.07323062540838
],
[
86.484375,
56.559482483762245
],
[
61.17187499999999,
63.074865690586634
],
[
48.8671875,
61.438767493682825
],
[
43.2421875,
56.17002298293205
]
]
]
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment