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

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));
List<SlavaTestDO> list = crit.list();

results in sql (captured using log4jdbc):
538  [main] DEBUG jdbc.sqltiming  -  sun.reflect.NativeMethodAccessorImpl.invoke0(
1. select 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 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 (, 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);
(1 row)

I know the geographies are not supported right now (, but is there any workaround to use DWithin in hibernate spatial with postgis dialect with meters?

-- Slava
hibernatespatial-users mailing list
[hidden email]