Reputation: 5072
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:
Any ideas as to what I am doing wrong in the compression process that would cause the icons to not initially show?
Upvotes: 2
Views: 923
Reputation: 23738
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();
}
}
Upvotes: 3