I am new to Hibernate Spatial, and am trying to perform a simple query of objects within a given radius. I've created a number of entries in my database with properties corresponding to a latitude and longitude, using data from Google Maps and other sources. This property is defined like this in my Entity class:
@Column
@Type(type = "org.hibernate.spatial.GeometryType")
private Point coordinates = null;
I'm now trying to figure out how to do a search of all entity objects that have coordinates that fall within a radius of x kilometers from a given point. For example, I'd like to find objects that fall within a 50 kilometer radius of the point (12.34567, -76.54321). However, I can't find any examples or tutorials that would explain how to do this in Hibernate Spatial.
Can anyone give me any information on how a query like this can be constructed?
See
this resourcefor a tutorial with "Spatial Queries", which a special dialect and the JTS library (Open Source).Basically you do the following (copy/paste from the referenced page):
.......
For generating a circle, see this resource (search for "Arcs, Circles and Curves"). Again a copy/paste from there:
Besides you always have the workaround, in which to add some additional fields ( mapped with
insertable=false, updatable=false
) to map to the same columns used by theorg.hibernate.spatial.GeometryType
and then use them in your query. For computing the distance, check the euclidian distance formula.