Feb
10
2009

How to store your map data on the server side

Imagine you want to store your markers, polylines and polygons that are currently on a MapWidget on the server side into a database. How would you do that? My first attempt ended with some Java classes that were mapped via Hibernate in a MySQL database. I created an abstract class “overlay” that was inherited by “point”, “polyline” and “polygon”. Map features, e.g. streets, mountain peaks or alpine huts, had properties of the type of the new classes. That was really great. But the first problems came with need for computings like boundaries and distances or testing for spatial relationships like intersects, touches, crosses, within and contains.

Last week there was a talk of a student about his diploma thesis. Like me, he also wanted to store spatial data into a database. He chose PostgreSQL as the database engine with an extension called PostGIS that “spatially enables” the PostgreSQL server, allowing it to be used as a backend spatial database for geographic information systems (GIS), much like ESRI’s SDE or Oracle’s Spatial extension. PostGIS follows the OpenGIS ”Simple Features Specification for SQL” and has been certified as compliant with the “Types and Functions” profile. Wow, great! Really nice! MySQL in conrast lacks most of this features.

But how does this work with Hibernate? And, if this is possible, into which classes will my database rows be mapped? Let’s ask Google! I found some slides from Chris Hodgson that issued this topic. In his slides he demonstrates the use of Hibernate Spatial, an extension for Hibernate that maps the data into the JTS Topology Suite. Wow, super! Now I can handle spatial computings in database queries and with my Java code! There is a tutorial for your first steps with Hibernate Spatial that works fine (also with Hibernate 3.4 and JTS 1.10). After I’ve finished this tutorial, I tryed to switch my code to this solution and, for now, it seems that it works stable and fast.

2 Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress. Theme: TheBuckmaker