[postgis-users] ST_within bug?
Johannes Sommer
johann.online at gmx.de
Wed Feb 13 03:44:53 PST 2008
Hi,
I ve got a problem with the ST_Within() function. It does not always
return correct answers.
SELECT AsText(geometry) FROM test WHERE t_id=3;
-->result:
"POLYGON((
4506577.35665529 5381992.48407281,
4506597.92548351 5381745.65813424,
4506999.01763368 5381784.22468715,
4506834.46700796 5382069.61717861,
4506615.92320819 5382085.04379977,
4506577.35665529 5381992.48407281))"
-- (WKT/WKB):
SELECT ST_Within(ST_GeomFromText('POLYGON((
4506577.35665529 5381992.48407281,
4506597.92548351 5381745.65813424,
4506999.01763368 5381784.22468715,
4506834.46700796 5382069.61717861,
4506615.92320819 5382085.04379977,
4506577.35665529 5381992.48407281))', 31468), a.geometry) FROM test a
WHERE t_id=3;
-->result: false (but obviously it should be true)
-- (WKT/WKT):
SELECT ST_Within(ST_GeomFromText('POLYGON((
4506577.35665529 5381992.48407281,
4506597.92548351 5381745.65813424,
4506999.01763368 5381784.22468715,
4506834.46700796 5382069.61717861,
4506615.92320819 5382085.04379977,
4506577.35665529 5381992.48407281))', 31468), (SELECT AsText(geometry)
FROM test WHERE t_id=3));
--> result:
ERROR: Operation on two geometries with different SRIDs
KONTEXT: SQL function "st_within" statement 1
Ok - I understand this reaction, because AsText returns no SRID.
-- (WKT/WKT):
SELECT ST_Within((select st_astext(geometry) FROM test WHERE t_id=3),
(SELECTst_astext(geometry) FROM test WHERE t_id=3));
-->result: true (as it should be)
-- (WKB/WKB):
select st_within((SELECT geometry FROM test WHERE t_id=3), (SELECT
geometry FROM test WHERE t_id=3));
-->result: true (correct)
SELECT ST_Within((select st_astext(geometry) FROM test WHERE t_id=3),
(SELECTst_astext(geometry) FROM test WHERE t_id=3));
So the problem is that the Desktop Client tries to insert a geometry
object as GeometryFromText / ST_GeomFromText / GeomFromText
and I have to compare this new geometry object with an existing Polygon.
It makes no difference if I use _st_within / st_within / within,
geometryfromtext / st_geomfromtext / geomfromtext or astext / st_astext.
I used:
-Windows XP, "POSTGIS="1.3.1" GEOS="3.0.0rc4-CAPI-1.3.3" PROJ="Rel.
4.5.0, 22 Oct 2006" USE_STATS",
"PostgreSQL 8.2.5 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC)
3.4.2 (mingw-special)"
-Linux, "POSTGIS="1.3.2" GEOS="3.0.0rc5-CAPI-1.4.0" PROJ="Rel. 4.6.0, 21
Dec 2007" USE_STATS",
"PostgreSQL 8.2.6 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.2.1
(SUSE Linux)"
Where am I going wrong?
regards,
Johannes
More information about the postgis-users
mailing list