I have different .kmz files, each one contains a .png and a .kml, let's say: a.kmz, b.kmz, c.kmz. I would like to use a bash script to obtain a unique .kmz file, let's say d.kmz, that contains all the previous layers. I simply tried to compress the .kml files and call the result d.kmz, but it does not work.

  • 1
    My 2 cents: You're going to need to find a software that can read/write KML/KMZ. KML is XML. Unless you can write some bash to read and parse the location components of a KML (which sounds like a lot of work), otherwise you'll create malformed XML (KML) output
    – KHibma
    Nov 5, 2018 at 19:12
  • If you add all the kmz files to Google Earth and do so in the same Places in its table of contents (e.g. Temporary Places), then save that Place to a new kmz, it will include all the individual kmz files.
    – John
    Nov 5, 2018 at 20:58

1 Answer 1


As you know, a KMZ file is a zipped version of a KML file, where the KML is compressed (very helpful for large datasets), and media files such as icon images, overlay images, balloon images, sound files, 3d models and others can be included in the KMZ's zip archive.

When Earth opens a KMZ file, it looks in the KMZ for ONE KML file. Usually there is just one. The convention is to name it doc.kml, but the name isn't important. If it finds more than one, then it will open just one of them. This is likely the issue you're running into by simply combining all the original KML files into one KMZ.

You'll need to actually combine the KML files into one KML, and then zip that up with the PNGs into your KMZ file. This can be done with a variety of software packages, from geospatial processing tools to basic XML tools (since KML is based on XML). If you use an XML tool, you'll probably need to have it open up each KML file, extract the content, and then recombine the contents from each KML into a new KML with the correct KML tags as a wrapper. The "content" you extract can either be the top level container (Document or Folder), in which case you'll need to put them inside a single container in the new file... or you can extract the contents out of that top level container (eg: Placemarks, overlays, etc.), and write those into the new file inside a new top level container.

Alternatively, as mentioned in one of the comments, if you just need to do this once or a few times, you can easily let Google Earth Pro do it for you, by opening your existing KMZ files in Earth, Making a new Folder in your My Places list, dragging the contents of the KMZs into that folder, and then saving the folder out as a new KMZ file.

Good luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.