Archive for the ‘ofy’ Category

javageomodel with objectify

with 3 comments

GeoModel is an useful project (originally in python) ported to java which aims to make your life easier when you want to search near by coordinates in maps using bigtable as storage.

The only thing is that javageomodel is too coupled with JPA/JDO and I want to use Objectify. Well, there’s too much code that can be refactored, but this simple change satisfied my needs:

proximityFetch #old
List<T> proximityFetch(Point center, int maxResults, double maxDistance, Class<T> entityClass, GeocellQuery baseQuery, PersistenceManager pm)

proximityFetch #new
List<T> proximityFetch(Point center, int maxResults, double maxDistance, LocationCapableRepositorySearch<T> repositorySearch)

If you want to search over your LocationCapable entities, you should give a LocationCapableRepositorySearch<T> for javageomodel (ofy sample):

public class OfyEntityLocationCapableRepositorySearchImpl implements
		LocationCapableRepositorySearch<Entity> {

	private Objectify ofy;

	public EntityLocationCapableRepositorySearchImpl(Objectify ofy) {
		this.ofy = ofy;

	public List<Entity> search(List<String> geocells) {
		return ofy.query(Entity.class)
				.filter("coordinates.geocells in ", geocells).list();


You might be looking for GeocellQuery. You could just change your LocationCapableRepositorySearch constructor waiting for a query and add some new filters to your search.

Now an Objectify proximity search looks like:

LocationCapableRepositorySearch<Entity> ofySearch = 
                    new OfyEntityLocationCapableRepositorySearchImpl(ofy);

List<Entity> entities = GeocellManager.proximityFetch(center, 20, 1000, ofySearch);

and I’ve created a JPALocationCapableRepositorySearchImpl for JPA searches:

LocationCapableRepositorySearch<Entity> jpaSearch = 
                    new JPALocationCapableRepositorySearchImpl<Entity>(baseQuery, pm, Entity.class);

List<Entity> entities = GeocellManager.proximityFetch(center, 40, 1000, jpaSearch);

You can find the new source at http://github.com/bfuster/javageomodel


Written by brunofuster

September 21, 2010 at 10:47 am

Posted in gae, geomodel, java, ofy