Search code examples
kmlgoogle-earthkmz

Nesting KMZ files


Is it possible to create one KMZ file that is composed of several smaller KMZ files? I would prefer to not have to manually merge the actual KML entities, but I will if that's the only option.


Solution

  • A KMZ file can have any number of inner KML files (NOT KMZ files). But the first entry in the KMZ file must be the root KML file (typically named doc.kml), which may include network links with references to other KML or KMZ files. Several inner KML files, for example, could reference a shared style (in another KML file) via relative URLs.

    The inner KML files can nest to any level of depth to other KML files so you can create a hierarchy of nested KML files.

    KMZ files within KMZ files is not supported in Google Earth so that is not recommended. If you want a root KMZ file to reference other sub-KMZ files then the sub-KMZ files should not be sub-entries of the root KMZ file but located at the same relative context in the web server or file system.

    Here is what a root KML file in a KMZ file would look like that includes at least two sub-KML files.

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
        <Document>
            <NetworkLink>
                <Link>
                    <href>test1.kml</href>
                </Link>
            </NetworkLink>
            <NetworkLink>
                <Link>
                    <href>test2.kml</href>
                </Link>
            </NetworkLink>
            ...
        </Document>
    </kml>
    

    You can set visibility tag to 0 or add radio folders to selectively load inner KML files or add Region elements to load when given region is active. This would be needed to scale to lots of Features to achieve good performance.

    Reference: https://developers.google.com/kml/documentation/kmlreference#networklink