Question

I am writing a C# program using http://www.icsharpcode.net/opensource/sharpziplib/ to compress to a zip file a KMZ file that will contain a KML file and icons.

My attempt:

  1. After opening the KMZ file in Google earth the icons do now show.
  2. I then convert the KMZ to a zip file so I can inspect its contents.
  3. I rename the icon to a different name then back to its original name.
  4. I then change it back to a KMZ file and open in Google earth and the icons show fine.

Any ideas as to what I am doing wrong in the compression process that would cause the icons to not initially show?

Was it helpful?

Solution

One trick to get KMZ files created with CSharpZipLib to properly work with Google Earth is turning off the Zip64 mode which is not compatible with Google Earth.

For KMZ files to be interoperable in Google Earth and other earth browsers it must be ZIP 2.0 compatible using "legacy" compression methods (e.g. deflate) and not use extensions such as Zip64. This issue is mentioned in the KML Errata.

Here's snippet of C# code to create a KMZ file:

using (FileStream fileStream = File.Create(ZipFilePath)) // Zip File Path (String Type)
{
    using (ZipOutputStream zipOutputStream = new ZipOutputStream(fileStream))
    {
        // following line must be present for KMZ file to work in Google Earth
        zipOutputStream.UseZip64 = UseZip64.Off;

        // now normally create the zip file as you normally would 
        // add root KML as first entry
        ZipEntry zipEntry = new ZipEntry("doc.kml");
        zipOutputStream.PutNextEntry(zipEntry);  
        //build you binary array from FileSystem or from memory... 
        zipOutputStream.write(/*binary array*/); 
        zipOutputStream.CloseEntry();
        // next add referenced file entries (e.g. icons, etc.)
        // ...
        //don't forget to clean your resources and finish the outputStream
        zipOutputStream.Finish();
        zipOutputStream.Close();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top