Sunday 1 June 2008

KMZ files on-the-fly with PHP ZIP extension

When I'm creating thematic maps with KML, I often end up with a series of files; legend images, icon images, 3D Collada objects and the KML file itself. The KML file is often large because of complex geometries repeated for several time steps. Fortunately, KML files and linked images and 3D objects can be zipped into one KMZ archive, which make file transfer easier and more efficient.

I'm using the PHP ZIP extension to create KMZ files on-the-fly. Basically, a KMZ file has the same properties as a ZIP file. With the PHP extension you can open a new KMZ archive and add your KML code (named "doc.kml") and images/3D objects that are linked with the href element.

For my last blog post, I created a KMZ archive (download) containing one KML file, one folder and three images. The original files are 1,418 kB in total while the KMZ file is only 153 kB - a lot of bandwidth saved!



Anonymous said...

Nice idea

Is it possible to have the php source? I can't manage to do like you..

Bjørn Sandvik said...


The PHP source code is available here.


Anonymous said...

Thanks !

(same anonymous ;) )

Diogo Gara said...

Hi Bjorn,

I enjoyed a lot your work over maps, i´m trying to use PHP zip to convert a KML to KMZ, i´ve tried your code but the google earth cannot opened the kmz, when renaming to zip and trying to unzip, there is a CRC error, i noticed that Google earth need double quotes , example: , and in your code you use using single quotes. Did you have such a problem in your trials? Regards. Diogo G.Caetano.