Sunday, July 24, 2005

A simple Java KMZ Servlet Filter for use with the Google Earth client

Google Earth reads KML and KMZ files, the MIME types for these are:

  • application/ kml
  • application/ kmz

The KMZ format looks to be simply a PKZipped version of the KML file. Although rather interestingly there is scope to add images and perhaps other media (e.g. 3d models, video and audio) into the zip file.

It seems that at present the main body of Google Earth developers are using PHP but as you can see from my recent posts I have been having some success developing for it with JSP technologies.

First, I tried to load a GZipped file into Google Earth but that didn't appear to work. It looks that Google Earth currently only supports "PKZIP" style files at present.

I thought to myself that I could create a Servlet Filter to dynamically create PKZIP files. I found an old article entitled Two Servlet Filters Every Web Application Should Have (circa 2003, virtually Jurassic!) on O'Reilly's OnJava that describes how to create a GZIP compression servlet filter to automatically compress the output of JSPs. I need to produce something very similar but this time with the emphasis on PKZIP.

It took a little longer that I expected to get my KMZFilter working. It seems that "all modern browsers" are assumed to accept the gzip encoding. Therefore there no longer seems to much point in searching for "gzip" in the accept-encoding request header as most browsers don't bother to send that header anymore. Additionally it isn't quite as straight forward as changing all the references in the GZIPFilter to either.

The KMZ servlet filter version I produced does no yet support zipping up multiple files. To support multiple files I'd need to work out from the requested filename (e.g. index.kmz) the file list that I'd need to include in the zip file, perhaps an XML properties file would do the trick (actually that would be quite an elegant solution).

My web.xml contains the following, note that I have mapped the KMZ extension to JSP so that I can carry on writing JSP to do the actual KML file creation:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"







Kudos to Jayson Falkner as I stole most of the code from his GZIPFilter but you are very welcome to have the source code filter for the KMZFilter I produced. I make no guarantees about the filters reliability, actually that probably goes for almost everything I produce (I will not be a hostage to responsibility)!!

Download KMZFilter source code

I ran into another little problem that was fixed by updating my Google Earth client to the latest version (at this time 3.0.0395(beta)) and "Presto Chango!" it works great.

Inspired by the compression filter example that comes with Tomcat I have improved my filter and it works much better now.


This was not helped by the Servlet Filters responses of <html><body></body></html> rather than an error I could actually do something with! If I were being professional about it I'd also add some code to make sure, even when responding with a servlet exception that the response from this filter was always KML/KMZ.


for ict 99 said...

The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Final Year Project Centers in Chennai.

Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

madin said...

This is the Nike Barcelona 2020 Windbreaker track jacket (kids').A really stylish look, cheap Soccer Jerseys the new Nike FC Barcelona 2020 windbreaker has a three-color block design - the top chevron is light brilliant yellow, cheap swansea city Jerseys combined with the club's famous Blaugrana colors.