The team members behind Mappixie are also the founders of the Open Source project Geolatte. Geolatte offers a set of modular GIS components for Java that facilitate painless integration of many aspects of GIS in a business-line application.
Whenever you see a map on our site, it was processed by a set of Geolatte components. The diagram below shows how drive time zones are calculated and rendered.
To create a drive time map, the following steps are executed.
First of all, we need route data. This will be used to render background maps (or tiles) and to calculate the drive time polygon. This data is available from large map providers such as TomTom and Navteq. Fortunately there is a free alternative as well, called OpenStreetMap. The latter is a community driven effort to build a map of the world. Its quality varies from region to region, but overall it’s quite good.
We render our background maps using mapnik, a very good open source map renderer . In order to use mapnik with OSM, it is best to import the OSM data – available as a (huge) XML file – into a database. We use a Postgres database with the PostGIS extension (which allows you to use geometry types). We use the osm2psql script to import the data.
The data used for rendering cannot be used to do route calculations since osm2psql does not import important data such as network nodes and speed limits. In order to get this data in our database as well, we use Osmosis with a custom plugin that splits roads at certain points . This step is a bit more involved and out of scope for this article so I won’t dive into it deeper.
At this point, we have all the data we need to generate a drive time map. First, the route network is build up in memory using geolatte-graph . Hibernate Spatial (also an OSS project of one of the Mappixie members) is used to load the data in Java. Geolatte-graph offers a set of fast graph algorithms (such as Dijkstra and A*) that can be used to quickly calculate a drive time zone polygon.
In order to generate an image (tile), we overlay our previously generated background tiles with the drive time zone polygon. The tile request is handled by geolatte-mapserver (via TileCache – see further), which speaks the WMS protocol. It knows which tile is requested and automatically creates a background tile by composing and cropping our background tiles (see figure below).
We still need to get the drive time polygon on the generated background tile. This is where geolatte-maprenderer comes in . This component is a renderer that allows to express all drawing operations in terms of spatial coordinates. This makes it easy to draw the drivetime polygon on the background tile (see figure above). Geolatte-maprenderer is called by geolatte-mapserver through a custom Mappixie plugin which allows to post-process the pre-generated background tile and apply overlay effects such as multiply.
Because we don’t want to render the same tile each time a client zooms and pans the map, we use TileCache .