Monday, July 9, 2012

ChronoDB and geographical coordinates


Important notice. On July 13, 2012, the ChronoDB project was renamed CrNiCKL, which is pronounced like "chronicle". All packages, demos included, have been renamed. The new project website is at http://agent.ch/timeseries/crnickl/. The old project remains accessible for a while at http://agent.ch/timeseries/chronodb/. The remainder of this article remains valid mutatis mutandis.

I've just released another ChronoDB demo to show how to set up a database with time series of geographical coordinates. The demo can be found in the package ch.agent.chronodb.demo.geocoord in archive chronodb-demo-1.1.0.jar at the ChronoDB project website or on SourceForge.

GeoCoord is a toy Java interface for geographical coordinates, with three methods:

boolean isNear(GeoCoord coord); boolean isNear(GeoCoord coord, double distance); double distanceTo(GeoCoord coord); In the demo, GeoCoords are implemented as cartesian coordinates. The glue with ChronoDB is provided by a simple value scanner GeoCodeValueScanner and a less simple implementation of ValueAccessMethods<GeoCoord> named AccessMethodsForGeoCoord. The Database class itself is so small it can be listed completely here: package ch.agent.chronodb.demo.geocoord; import ch.agent.chronodb.jdbc.JDBCDatabase; public class GeoCoordDatabase extends JDBCDatabase { public GeoCoordDatabase(String name) { super(name); setAccessMethods(GeoCoordValueScanner.class.getName(), new AccessMethodsForGeoCoord()); } }

To make things interesting the demo uses a special time domain, with time points at 7:00 AM, 9:00 AM, 3:11 PM, and 9:33:20 PM every Monday, Tuesday, Friday, and Saturday. For a refresher on time domains, please have a look at my previous post.

Here is what running the demo looks like (commands are on a single line and output has been truncated):

$ jar xf chronodb-demo-1.1.0.jar lib $ java -cp chronodb-demo-1.1.0.jar \ ch.agent.chronodb.demo.geocoord.GeoCoordDemo Resources/geocoord.parm 2012-04-09 09:00:00 8151km (machin) 2012-04-09 15:11:00 7000km (machin) --- clip clip --- 2012-07-09 07:00:00 7053km (truc) 2012-07-09 09:00:00 8367km (bidule) 2012-07-09 15:11:00 9582km (bidule) 2012-07-09 21:33:20 6889km (machin) $ The exact figures vary with each run because the data is random.

No comments:

Post a Comment