[postgis-users] Incorrect results from queries specifying an SRID

cp cplists at yeroc.ca
Fri May 28 09:31:15 PDT 2004


Hello,

I'm getting some unexpected results from queries that specify an SRID.  
I have a table with features (MULTILINESTRING) stored with an SRID of 
4267 (NAD27).  Querying with a geometry with a matching SRID returns the 
expected results:

SELECT * FROM gis
WHERE geometry && GeometryFromText('BOX3D(-113.8895 57.1833,-113.7113 
57.0681)'::box3d, 4267);

But when I perform an equivalent query using SRID26712 (NAD27/UTM Zone 
12) like so:

SELECT * FROM gis
WHERE geometry && GeometryFromText('BOX3D(325356 6341280,335614 
6328019)'::box3d, 26712);

The query returns 0 rows.

What appears to be happening is that the query is ignoring the specified 
SRID (or I'm specifying it incorrectly?) and is instead querying as if 
the specified coordinates were SRID 4267.  Of course, since they're 
actually UTM coordinates they don't match anything.  My expectation 
would be for postgis to automatically transform the coordinates to match 
the SRID of the geometries stored in the table (4267) or at least to 
give me an error.

My workaround for now is to wrap my query with a transform myself like so:

SELECT * FROM gis
WHERE geometry && transform(GeometryFromText('BOX3D(325356 
6341280,335614 6328019)'::box3d, 26712), 4267);

This shouldn't be necessary in my opinion :(  Furthermore, the result of 
my second query is incorrect...unless of course, I'm doing something 
wrong. :/

I'm running postgresql v7.4.1 with postgis version 0.8:

select postgis_version();
            postgis_version
---------------------------------------
 0.8 USE_GEOS=1 USE_PROJ=1 USE_STATS=1

I hope someone can shed some light on this.

Thanks,
Corey






More information about the postgis-users mailing list