Spatial Query with Circle

7 messages Options
Embed this post
Permalink
Jeremy-78

Spatial Query with Circle

Reply Threaded More More options
Print post
Permalink
Hello,

I'm trying to run a spatial query to know if a point is in a circle.
I use something like that :

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

And my filter is a Circle created like that :

Circle spatialFilter = new Circle(latitude,longitude,radius);

However, I have a ClassCastException (I guess this is due to the fact
that Circle is not of type Geometry):

java.lang.ClassCastException: org.hibernatespatial.Circle
        at org.hibernatespatial.oracle.SDOGeometryType.nullSafeSet(SDOGeometryType.java:88)
        at org.hibernatespatial.GeometryUserType.nullSafeSet(GeometryUserType.java:183)
        at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:156)

So my question is : how can we make spatial queries to search if a
point is in a circle?

Thanks in advance,

Regards,

Jim
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
JPHespanha-3

Re: Spatial Query with Circle

Reply Threaded More More options
Print post
Permalink
 Jim:

I am sending to you (and anyone in the list eventually interested) a
class diagram I have made on the Simple Features for SQL standard
implemented by PostGIS, where you can see that such a class does not
exist, but there is a new type called 'CircularString', or even more
appropriate, the 'CurvePolygon' which could be used for that purpose.
This last one has even the method 'ST_PointonSurface()', to be called
using SQL, of course. These are the SQL/MM types most recently added to
PostGIS.

This does not mean that some other type of implementation is not
possible, because Hibernate Spatial uses the JTS library internally, to
translate database geometry types to Java geometry types. Anyhow, I give
a quick look into the org.hibernatespatial.postgis package and did not
find Circle, not even the SQL/MM types.

As I am not a specialist (rather a newbie) on Hibernate Spatial, JTS and
the likes, I think we have to wait for a response from Karen, perhaps a
hint on how to add the missing geometry types from PostGIS.

PS: by the way, this can be a little tricky, once I heard the last
implementations of SQL/MM types on some databases are not that much
compliant with the standard.

Regards,
JP Hespanha


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On
Behalf Of Jeremy
Sent: Tuesday, November 27, 2007 4:50 PM
To: Hibernate Spatial Users Discussion
Subject: [hibernatespatial-users] Spatial Query with Circle

Hello,

I'm trying to run a spatial query to know if a point is in a circle.
I use something like that :

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

And my filter is a Circle created like that :

Circle spatialFilter = new Circle(latitude,longitude,radius);

However, I have a ClassCastException (I guess this is due to the fact
that Circle is not of type Geometry):

java.lang.ClassCastException: org.hibernatespatial.Circle
        at
org.hibernatespatial.oracle.SDOGeometryType.nullSafeSet(SDOGeometryType.
java:88)
        at
org.hibernatespatial.GeometryUserType.nullSafeSet(GeometryUserType.java:
183)
        at
org.hibernate.type.CustomType.nullSafeSet(CustomType.java:156)

So my question is : how can we make spatial queries to search if a point
is in a circle?

Thanks in advance,

Regards,

Jim
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatia
l-users


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users

SQLMMGeometryTypes.pdf (20K) Download Attachment
Karel Maesen

Re: Spatial Query with Circle

Reply Threaded More More options
Print post
Permalink
In reply to this post by Jeremy-78
Hi Jeremy,

As you already figured out, Circle is not a subclass of Geometry so  
it cannot be passed as a Geometry parameter to a query. The Circle  
class is a utility class used to linearize arc circles.

You could try to either generate a JTS polygon that approximates the  
circle, or generate a "circle" by buffering a point by the radius.  
You could also try to ask the question on the JTS mailing list.

Regards,

Karel Maesen



On 27 Nov 2007, at 16:50, Jeremy wrote:

> Hello,
>
> I'm trying to run a spatial query to know if a point is in a circle.
> I use something like that :
>
>  Query q = session.createQuery("from Event where within
> (location, ?) = true");
>  Type geometryType = new CustomType(GeometryUserType.class, null);
>  q.setParameter(0, filter, geometryType);
>  List result = q.list();
>
> And my filter is a Circle created like that :
>
> Circle spatialFilter = new Circle(latitude,longitude,radius);
>
> However, I have a ClassCastException (I guess this is due to the fact
> that Circle is not of type Geometry):
>
> java.lang.ClassCastException: org.hibernatespatial.Circle
> at org.hibernatespatial.oracle.SDOGeometryType.nullSafeSet
> (SDOGeometryType.java:88)
> at org.hibernatespatial.GeometryUserType.nullSafeSet
> (GeometryUserType.java:183)
> at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:156)
>
> So my question is : how can we make spatial queries to search if a
> point is in a circle?
>
> Thanks in advance,
>
> Regards,
>
> Jim
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> hibernatespatial-users

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
D_Guidi

Re: Spatial Query with Circle

Reply Threaded More More options
Print post
Permalink
A better way is to use distance comparison instead of circleGeom.within



2007/11/27, Karel Maesen <[hidden email]>:

> Hi Jeremy,
>
> As you already figured out, Circle is not a subclass of Geometry so
> it cannot be passed as a Geometry parameter to a query. The Circle
> class is a utility class used to linearize arc circles.
>
> You could try to either generate a JTS polygon that approximates the
> circle, or generate a "circle" by buffering a point by the radius.
> You could also try to ask the question on the JTS mailing list.
>
> Regards,
>
> Karel Maesen
>
>
>
> On 27 Nov 2007, at 16:50, Jeremy wrote:
>
> > Hello,
> >
> > I'm trying to run a spatial query to know if a point is in a circle.
> > I use something like that :
> >
> >  Query q = session.createQuery("from Event where within
> > (location, ?) = true");
> >  Type geometryType = new CustomType(GeometryUserType.class, null);
> >  q.setParameter(0, filter, geometryType);
> >  List result = q.list();
> >
> > And my filter is a Circle created like that :
> >
> > Circle spatialFilter = new Circle(latitude,longitude,radius);
> >
> > However, I have a ClassCastException (I guess this is due to the fact
> > that Circle is not of type Geometry):
> >
> > java.lang.ClassCastException: org.hibernatespatial.Circle
> > at org.hibernatespatial.oracle.SDOGeometryType.nullSafeSet
> > (SDOGeometryType.java:88)
> > at org.hibernatespatial.GeometryUserType.nullSafeSet
> > (GeometryUserType.java:183)
> > at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:156)
> >
> > So my question is : how can we make spatial queries to search if a
> > point is in a circle?
> >
> > Thanks in advance,
> >
> > Regards,
> >
> > Jim
> > _______________________________________________
> > hibernatespatial-users mailing list
> > [hidden email]
> > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/
> > hibernatespatial-users
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>


--
Diego Guidi
http://lacorrente.blogspot.com
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Jeremy-78

Re: Spatial Query with Circle

Reply Threaded More More options
Print post
Permalink
Hello again,

I have two more questions:
1) When I save a Point in the database (Oracle 10g), the SDO_GTYPE is
good (2001) however it is not saved as an SDO_POINT but as an array of
SDO_ORDINATES with one element. Is it possible to modify that?
2) In Oracle, it's possible to have arcs and circles (yes always some
problems with circle ;)), do you think that it's also possible to load
them with Hibernate Spatial? If not, I think that I will have no other
choice than to use the Oracle SDO API instead of the JTS Suite, and
hope it is still possible to use Hibernate Spatial with it?

Thanks!

Jim

On Nov 27, 2007 8:09 PM, Diego Guidi <[hidden email]> wrote:

> A better way is to use distance comparison instead of circleGeom.within
>
>
>
> 2007/11/27, Karel Maesen <[hidden email]>:
>
> > Hi Jeremy,
> >
> > As you already figured out, Circle is not a subclass of Geometry so
> > it cannot be passed as a Geometry parameter to a query. The Circle
> > class is a utility class used to linearize arc circles.
> >
> > You could try to either generate a JTS polygon that approximates the
> > circle, or generate a "circle" by buffering a point by the radius.
> > You could also try to ask the question on the JTS mailing list.
> >
> > Regards,
> >
> > Karel Maesen
> >
> >
> >
> > On 27 Nov 2007, at 16:50, Jeremy wrote:
> >
> > > Hello,
> > >
> > > I'm trying to run a spatial query to know if a point is in a circle.
> > > I use something like that :
> > >
> > >  Query q = session.createQuery("from Event where within
> > > (location, ?) = true");
> > >  Type geometryType = new CustomType(GeometryUserType.class, null);
> > >  q.setParameter(0, filter, geometryType);
> > >  List result = q.list();
> > >
> > > And my filter is a Circle created like that :
> > >
> > > Circle spatialFilter = new Circle(latitude,longitude,radius);
> > >
> > > However, I have a ClassCastException (I guess this is due to the fact
> > > that Circle is not of type Geometry):
> > >
> > > java.lang.ClassCastException: org.hibernatespatial.Circle
> > >     at org.hibernatespatial.oracle.SDOGeometryType.nullSafeSet
> > > (SDOGeometryType.java:88)
> > >     at org.hibernatespatial.GeometryUserType.nullSafeSet
> > > (GeometryUserType.java:183)
> > >     at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:156)
> > >
> > > So my question is : how can we make spatial queries to search if a
> > > point is in a circle?
> > >
> > > Thanks in advance,
> > >
> > > Regards,
> > >
> > > Jim
> > > _______________________________________________
> > > hibernatespatial-users mailing list
> > > [hidden email]
> > > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/
> > > hibernatespatial-users
> >
> > _______________________________________________
> > hibernatespatial-users mailing list
> > [hidden email]
> > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
> >
>
>
> --
> Diego Guidi
> http://lacorrente.blogspot.com
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: Spatial Query with Circle

Reply Threaded More More options
Print post
Permalink
Hi Jeremy,


On 13 Dec 2007, at 14:33, Jeremy wrote:

>
> I have two more questions:
> 1) When I save a Point in the database (Oracle 10g), the SDO_GTYPE is
> good (2001) however it is not saved as an SDO_POINT but as an array of
> SDO_ORDINATES with one element. Is it possible to modify that?

It is currently not possible to modify how points are stored. I'm  
thinking about making this configurable, however. Please note that  
the current behavior works correctly.

> 2) In Oracle, it's possible to have arcs and circles (yes always some
> problems with circle ;)), do you think that it's also possible to load
> them with Hibernate Spatial? If not, I think that I will have no other
> choice than to use the Oracle SDO API instead of the JTS Suite, and
> hope it is still possible to use Hibernate Spatial with it?
>

As you've probably seen on the JTS mailing list, JTS doesn't support  
circles or circular segments because that is not part of the SFS specs.

Hibernate Spatial allows you to read circle geometries. These are  
converted into JTS polygons. Unfortunately, if you modify and store  
them, they will be stored as polygons with linear segments. (Tom  
Acree had a suggestion to improve on this by adding a special  
attribute in the mapping, but we haven't yet implemented that).  So,  
if you really need to store geometries as arcs/circles, then I'm  
afraid you'll need to use the SDO API.

Hope this answers your questions.

Regards,

Karel Maesen

_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Jeremy-78

Re: Spatial Query with Circle

Reply Threaded More More options
Print post
Permalink
Unfortunately, yes I need to store arcs (some objects in my
application can be either polygons or arcs...).
For polygons, everything was working well with hibernate spatial...
however for the arcs, as you said, it seems I have no other choice
than using Oracle SDO API, and consequently I cannot use hibernate
spatial anymore...

Thanks for all your answers, it was very rewarding and as soon as you
manage arcs/circles, I will come back to hibernate spatial :-)

Jim

On Dec 13, 2007 7:29 PM, Karel Maesen <[hidden email]> wrote:

> Hi Jeremy,
>
>
> On 13 Dec 2007, at 14:33, Jeremy wrote:
>
> >
> > I have two more questions:
> > 1) When I save a Point in the database (Oracle 10g), the SDO_GTYPE is
> > good (2001) however it is not saved as an SDO_POINT but as an array of
> > SDO_ORDINATES with one element. Is it possible to modify that?
>
> It is currently not possible to modify how points are stored. I'm
> thinking about making this configurable, however. Please note that
> the current behavior works correctly.
>
> > 2) In Oracle, it's possible to have arcs and circles (yes always some
> > problems with circle ;)), do you think that it's also possible to load
> > them with Hibernate Spatial? If not, I think that I will have no other
> > choice than to use the Oracle SDO API instead of the JTS Suite, and
> > hope it is still possible to use Hibernate Spatial with it?
> >
>
> As you've probably seen on the JTS mailing list, JTS doesn't support
> circles or circular segments because that is not part of the SFS specs.
>
> Hibernate Spatial allows you to read circle geometries. These are
> converted into JTS polygons. Unfortunately, if you modify and store
> them, they will be stored as polygons with linear segments. (Tom
> Acree had a suggestion to improve on this by adding a special
> attribute in the mapping, but we haven't yet implemented that).  So,
> if you really need to store geometries as arcs/circles, then I'm
> afraid you'll need to use the SDO API.
>
> Hope this answers your questions.
>
> Regards,
>
> Karel Maesen
>
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users