Quickly convert KML to GeoJSON
or GeoJSON to SVG
and concatenate multiple GeoJSON
files via the terminal.
First download and install Node.js from https://nodejs.org/en
In the command line install kml2geojson
globally:
npm i -g kml-stream
In the command line install kml2geojson
globally:
npm i -g geojson-to-svg
In the command line install geojson-merge
globally:
npm i -g geojson-merge
In the terminal use the following command below. Just replace INPUT
with the path of the KML file and OUTPUT
with the any name for the GeoJSON file you fancy.
kml2geojson < INPUT.kml > OUTPUT.geojson
This works well with small GeoJSON files. Useful for graphic designers who use Illustrator or just for a quick static image for web. In the terminal use the following command below. Just replace INPUT
with the path of the KML file and OUTPUT
with the any name for the GeoJSON file you fancy.
geojson2svg --input INPUT.geojson > OUTPUT.svg
With the GeoJSON files all in one folder, use the following command to merge them all. Just replace OUTPUT
with the any name for the combined GeoJSON file you want.
geojson-merge *.geojson > OUTPUT.geojson
** Just make sure that your terminal is in the same directory as your GeoJSON files.
I learned all this during the fire coverage at the San Francisco Chronicle. I found the semi-updated KML/KMZ files for current fire locations and perimeters provided by United States Geological Survey (USGS). You can also download historical fire data too. If you have Google Earth Pro, you download them and view them quickly. All of which can be found here: https://rmgsc.cr.usgs.gov/outgoing/GeoMAC
Thanks for this resource.
I wrote a small article about how I ended handling the KML/KMZ in Nodejs - https://boobo94.github.io/tutorials/create-kml-kmz-nodejs/.
Hope it helps!