Skip to content

Instantly share code, notes, and snippets.

@luciovilla
Created October 20, 2017 19:31
Show Gist options
  • Save luciovilla/6619d6dcce07e5bb95902e3f4cb4a056 to your computer and use it in GitHub Desktop.
Save luciovilla/6619d6dcce07e5bb95902e3f4cb4a056 to your computer and use it in GitHub Desktop.
Useful tools for handling KML files

Useful tools for handling KML files

Quickly convert KML to GeoJSON or GeoJSON to SVG and concatenate multiple GeoJSON files via the terminal.

Requirements

Installing

Node.js

First download and install Node.js from https://nodejs.org/en

kml2geojson

In the command line install kml2geojson globally:

npm i -g kml-stream

geojson-to-svg

In the command line install kml2geojson globally:

npm i -g geojson-to-svg

geojson-merge

In the command line install geojson-merge globally:

npm i -g geojson-merge

Using

Convert KML to GeoJSON

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

Convert GeoJSON to SVG

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

Merge multiple GeoJSONs

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.

Bonus

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

@boobo94
Copy link

boobo94 commented Oct 28, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment