Create Spatial query using HQL

2 Messages Forum Options Options
Embed this topic
Permalink
Jo
Create Spatial query using HQL
Reply Threaded MoreMore options
Print post
Permalink
Hi,

is there a tutorial or something like that explained using of spatial hql queries?
I tried to create a query to find all geometries in a bounding box.
query = from <table> where crosses(<geometry>, ?) = true
<geometry> = jts Polygon
(modified the example on hibernatespatial.org).
...that gives a QuerySyntaxException.

How can I create a query to get the desired geometries?

Thanks,

Jo
--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@...
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen
Re: Create Spatial query using HQL
Reply Threaded MoreMore options
Print post
Permalink
Hi Jo,

You have several options.  If you want a simple window query (i.e.  
finding all objects (at least) within a bounding box) you can use the  
SpatialRestrictions static factory class:

    Criteria testCriteria = session.createCriteria(Event.class);
    testCriteria.add( SpatialRestrictions.filter("location",  
filter)  ) ;

with 'filter' being a JTS geometry , and 'location' the name of the  
Geometry-valued property in the Event class

To use HQL you could try this:

  Query q = session.createQuery("from Event where within
( location, ?) = True");
  Type geomType = new CustomType(GeometryUserType.class, null);
  q.setParameter(0, filter, geomType);
  List results = q.list();

The first line creates the query, the third sets the filter  
parameter. The second line is needed so that Hibernate understands  
how to deal with the parameter object.

The spatial functions are as specified by the OGC Specification  
Simple Feature for SQL Specification (http://
portal.opengeospatial.org/files/?artifact_id=829), chapter 2.

Hope this helps.

Karel Maesen


On 23 Sep 2008, at 09:51, Johannes Lauer wrote:

> Hi,
>
> is there a tutorial or something like that explained using of  
> spatial hql queries?
> I tried to create a query to find all geometries in a bounding box.
> query = from <table> where crosses(<geometry>, ?) = true
> <geometry> = jts Polygon
> (modified the example on hibernatespatial.org).
> ...that gives a QuerySyntaxException.
>
> How can I create a query to get the desired geometries?
>
> Thanks,
>
> Jo
> --
> Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit  
> allen: http://www.gmx.net/de/go/multimessenger
> _______________________________________________
> hibernatespatial-users mailing list
> hibernatespatial-users@...
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@...
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users