Geo Data Processing with ndjson

You can convert GeoJSON to Newline delimited JSON for other processing. This is an example of Command Line Cartography, inspired by Mike Bostock.

Install the Command Line Interface

# Install once
#  npm install -g ndjson-cli

Convert from GeoJSON

By splitting out by the key d.features

ndjson-cat hikes.geojson  | ndjson-split 'd.features' > hikes.ndjson

Convert to GeoJSON

To convert a newline-delimited JSON stream of values to a JSON array, the inverse of ndjson-split is ndjson-reduce.

This command line operation

  • calls ndjson-reduce
  • reads the file hikes.ndjson
  • pipe, |, the results to ndjson-map and decorate with a base GeoJSON structure
  • writes the file hikes2.geojson
ndjson-reduce < hikes.ndjson | ndjson-map '{type: "FeatureCollection", features: d}' > hikes2.geojson

Example


Geo-Data-Processing-with-ndjson

KML to GeoJSON

togeojson export.kml
togeojson export.kml > export.geojson

# Reduce file size by removing
geojson-precision export.geojson export.precision.geojson