[GIS] Bulk edit and merge KML files

google earthkmlkmz

Trying to do some research into drought patterns of the US using KMZ files from droughtmonitor.unl.edu.

My problem is that there are too many files to work with. 857 total.
Records are every 7 days from 01/04/2000 – 03/22/16

I would like to merge each year into one KML. Doing this in Google Earth from importing all the separate files is very time consuming and causes GE to crash about halfway through. Also I would like to clean up some folder names. Each folder is 66 characters and is repeated in the subfolder.

How would I merge multiple KMZ/L files into a single KMZ/L file and clean up the folder names?

Example:

From

Top folder: U.S. Drought Monitor Released: 2000/01/06 Valid 7am EST 2000/01/04
  Subfolder: U.S. Drought Monitor Released: 2000/01/06 Valid 7am EST 2000/01/04
Top folder: U.S. Drought Monitor Released: 2000/01/06 Valid 7am EST 2000/01/11
  Subfolder: U.S. Drought Monitor Released: 2000/01/06 Valid 7am EST 2000/01/11

To

Top Folder: Merged 2000 Drought Maps
  Subfolder: 2000/01/04
  Subfolder: 2000/01/11

Here is a link to a drought map KMZ.
http://droughtmonitor.unl.edu/data/kmz/usdm_20000104.kmz

Best Answer

This sounds like a job for some scripting!

KMZ files are zipped KML files (rename it to .zip, and extract, to find the KML.) KML files are essentially XML files, a type of markup language which is readable in programs like Notepad++.

If you open the KML file in a text editor, you get stuff like this:

<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="missoulaparcel_subset" id="missoulaparcel_subset">
    <SimpleField name="gid" type="int"></SimpleField>
    <SimpleField name="parcelid" type="string"></SimpleField>

...etc

What you can do is identify the parts of a KML file that refer to individual features, and stitch them together into one (much larger) file. It appears as though the Placemark tag starts a feature, and /Placemark ends it - so it should be possible to (relatively easily) write a script to extract all of these features, and append them into a single file.

Alternatively, it looks like there are libraries like pyKML which can operate on KML files. I would probably try to use that, if I didn't feel like writing a script to do it manually.