Sonntag, 30. Mai 2010

Geospatial JDO queries on the Google AppEngine (+ GWT)

From time to time one might feel the urgent need to execute geospatial queries on the Google AppEngine. Thinking in common SQL this is pretty easy, just a combined WHERE clause:

SELECT * FROM t_spatialdata
WHERE latitude >= south AND latitude <= north AND longitude >= west AND longitude <= east

Unfortunately something like this is not possible, when using AppEngine, as you can only filter by one argument (i.e. only by latitude). I think the reason for this is that AppEngine internally sorts the table and then 'cuts' away what doesn't match the filter.

So this problem can basically be solved, by using a algorithm called Geohash, which unfortunately didn't want to return proper results, at least not the implementations I found. (The 'official' implementation uses the BitSet-Class which is not present when using AppEngine/GWT)

The solution I went for is the "javageomodel"-project which follows (afaik) a similar algorithm but worked.

The problem you will face, when trying to use this in your AppEngine project is that it will be missing (just at runtime!) two classes from the Apache Commons project: StringUtils and Validator. At least the latter one is over 1MByte in size. So I decided to replace the Validator lines with standard "assert"-calls, but adding the jars probably would have worked too.

For your convenience I uploaded the final jar that works fine:
A how to use this for actual queries is located here:


  1. Hi Nicolas
    Is Geohash more efficient than the simple query you showed at the top, or is it just useful as a workaround, as you described for AppEngine?

  2. Does the Javageomodel Proximity search work. It seems the geocells and geocellsp values are switched in the geocellmanager

  3. Hello guys, just posted a javageomodel with objectify, decoupled from JPA/JDO