views:

528

answers:

5

Does anyone know what compression to use in Java for creating KMZ files that have images stored within them? I tried using standard Java compression (and various modes, BEST_COMPRESSION, DEFAULT_COMPRESSION, etc), but my compressed file and the kmz file always come out slightly different don't load in google earth. It seems like my png images in particular (the actual kml file seems to compress the same way).

Has anyone successfully created a kmz archive that links to local images (and gets stored in the files directory) from outside of google earth?

thanks

Jeff

A: 

Sure, I have package Kmz files with images in c#. AFAIK the only compression method that is supported is ZIP (PKZIP-compatible). What library in Java are you using?

Fraser
I was just using the standard java Zip classes...
Jeff Storey
+1  A: 

KMZ is simply a zip file with a KML file and assets. For example, the london_eye.kmz kmz file contains:

   $ unzip -l london_eye.kmz 
    Archive:  london_eye.kmz
      Length     Date   Time    Name
     --------    ----   ----    ----
       451823  09-27-07 08:47   doc.kml
            0  09-26-07 07:39   files/
         1796  12-31-79 00:00   files/Blue_Tile.JPG
       186227  12-31-79 00:00   files/Legs.dae
         3960  12-31-79 00:00   files/Olive.JPG
      1662074  12-31-79 00:00   files/Wheel.dae
        65993  12-31-79 00:00   files/Wooden_Fence.jpg
         7598  12-31-79 00:00   files/a0.gif
         7596  12-31-79 00:00   files/a1.gif
         7556  12-31-79 00:00   files/a10.gif
         7569  12-31-79 00:00   files/a11.gif
         7615  12-31-79 00:00   files/a12.gif
         7587  12-31-79 00:00   files/a13.gif
         7565  12-31-79 00:00   files/a14.gif
         7603  12-31-79 00:00   files/a15.gif
         7599  12-31-79 00:00   files/a16.gif
         7581  12-31-79 00:00   files/a17.gif
         7606  12-31-79 00:00   files/a18.gif
         7613  12-31-79 00:00   files/a19.gif
         7607  12-31-79 00:00   files/a2.gif
         7592  12-31-79 00:00   files/a3.gif
         7615  12-31-79 00:00   files/a4.gif
         7618  12-31-79 00:00   files/a5.gif
         7618  12-31-79 00:00   files/a6.gif
         7578  12-31-79 00:00   files/a7.gif
         7609  12-31-79 00:00   files/a8.gif
         7603  12-31-79 00:00   files/a9.gif
        57185  12-31-79 00:00   files/capsule.dae
       310590  12-31-79 00:00   files/groundoverlay.jpg
       224927  12-31-79 00:00   files/mechanism.dae
       160728  12-31-79 00:00   files/shadowoverlay.jpg
        33044  12-31-79 00:00   files/shed.dae
     --------                   -------
      3310275                   32 files

You can build this with java.util.zip, or even with jar if you want.

As far as the images go, they should not be compressed, since they already contain compressed data. You don't get any significant savings.

vy32
have you actually done this with java.util.zip? when i do that, I still can't get google earth to open it? and I've noticed that the compressions is slightly different than if I put the files in google earth.
Jeff Storey
A: 

There is a library for dealing with KML in Java called JAK (Java API for KML).

Unfortunately, it seems to have a bug: Issue 1: save KMZ file does not work - so it looks like you're not the first one who has problems with generating a KMZ file...

Jesper
thanks. I haven't been able to get the kmz zipping to work with standard java zipping either. you'd think it would be easier.
Jeff Storey
A: 

As simsong said, KMZ is simply zipped KML. One thing I did notice is that doc.kml needs to be the first entry in the zip file for it to work reliably. I don't recall doing anything special with the images (apart from putting everything but doc.kml in a subdirectory). My KMZ files are generated using java.util.zip.

jackrabbit
A: 

(not enough rep) COMMENT: Different encoders may produce slightly different compressions. Gzip (the underlying standard) is just a file format, not an encoding methodology. An infinite number of compressed files could decode into the same raw file.

So, it's probably not the compression that's causing your problem.

Venning