postgres DWithinExpression with geographies/meters

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

postgres DWithinExpression with geographies/meters

Viatcheslav.Sysoltsev
Hi people,

I have unexpected results using the DWithinExpression (Hibernate-spatial 4.0-M1) with postgis2.0.2-1.

My geometry field is defined as:

@Entity(name = "SlavaTest")
public class SlavaTestDO {
...
    @Type(type = "org.hibernate.spatial.GeometryType")
    private Geometry geometry;
...
}

The criteria:

Geometry mask;
double distance;
...
Criteria crit = session.createCriteria(SlavaTestDO.class);
crit.add(SpatialRestrictions.distanceWithin("geometry", mask, distance));
crit.addOrder(Order.asc("id"));
List<SlavaTestDO> list = crit.list();

results in sql (captured using log4jdbc):
538  [main] DEBUG jdbc.sqltiming  -  sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
1. select this_.id as id1_0_, this_.geometry as geometry1_0_, this_.timestamp as timestamp1_0_, this_.title as title1_0_ from SlavaTest this_ where ST_DWithin(this_.geometry,SRID=4326;POLYGON((9 53.5,9 53.51,9.01 53.51,9.01 53.5,9 53.5)),2000.0) order by this_.id asc {executed in 101 msec}

The query returns the whole table for distance=2000. I guess postgres uses the first overload of ST_DWithin function (http://postgis.org/docs/ST_DWithin.html), which takes the geometries. The second overload from psql would return 5 entities:

=> select count(*) from SlavaTest this_ where ST_DWithin(geometry, ST_GeogFromText('SRID=4326;POLYGON((9 53.5,9 53.51,9.01 53.51,9.01 53.5,9 53.5))'), 2000.0);
 count
-------
     5
(1 row)


I know the geographies are not supported right now (http://www.hibernatespatial.org/jira/browse/HIBSPA-54), but is there any workaround to use DWithin in hibernate spatial with postgis dialect with meters?

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