Last active
March 5, 2020 13:19
-
-
Save chriswhong/c51062fd61905a1c19dec50974dba692 to your computer and use it in GitHub Desktop.
How to parse a CSV with a well-known text geometry column and convert to geojson FeatureCollection with the 'wellknown' package
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
// Use papa parse to download and parse a CSV | |
Papa.parse('data/nyc_zoning_lots.csv', { | |
download: true, | |
header: true, | |
complete: ({ data }) => { | |
// transform array of objects to geojson FeatureCollection | |
const FC = { | |
type: 'FeatureCollection', | |
features: data.map((row) => { // map csv rows to geojson features | |
const geometry = wellknown.parse(row.geom) // WKT to geojson geometry | |
delete row.geom | |
const properties = { | |
...row // the rest of the row becomes properties | |
} | |
return { | |
geometry, | |
properties, | |
} | |
}) | |
} | |
customLayerSetup(FC) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment