[postgis-users] problem in Distance function

Michael Fuhr mike at fuhr.org
Thu Aug 17 06:44:32 PDT 2006


On Thu, Aug 17, 2006 at 04:06:30PM -0400, temiz wrote:
> I tried this. But I got:
> ~~~~~~~~~~~~~~~~~~
> SELECT *
> FROM sgr_nuf_bina1
> WHERE
> wkb_geometry && Expand(GeomFromText('POINT(28.28547 38.66539)',-1),100)
> AND
> Distance(GeomFromText('POINT(28.28547 38.66539)',-1),wkb_geometry )< 100
> ~~~~~~~~~~~~~~
> ERROR:  Operation on two geometries with different SRIDs
> 
> what might  the problem be ?

The geometries in the query have SRID -1 but apparently the geometries
in the table have a different SRID.  Use the same SRID in the query
that the table uses.  If you don't know what SRID that is then view
the table definition (e.g., with "\d sgr_nuf_bina1" in psql) and
look at the check constraints.  Another way would be to query
geometry_columns:

SELECT srid FROM geometry_columns WHERE f_table_name = 'sgr_nuf_bina1';

or query the table itself:

SELECT SRID(wkb_geometry) FROM sgr_nuf_bina1
WHERE wkb_geometry IS NOT NULL LIMIT 1;

Incidentally, 100 is almost certainly the wrong distance.  Your
coordinates appear to be long/lat so distance will be measured in
degrees rather than kilometers or meters or whatever you're probably
expecting.  Try using expand() with degrees and distance_sphere()
with meters.

-- 
Michael Fuhr



More information about the postgis-users mailing list