Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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

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