Skip to content

Instantly share code, notes, and snippets.

@chriswhong
Last active March 5, 2020 13:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswhong/c51062fd61905a1c19dec50974dba692 to your computer and use it in GitHub Desktop.
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
// 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