[postgis-devel] bug, st_within not working for polygon,polygon

Ingo Klinkmann ingo at logix-tt.com
Wed Jul 16 08:23:57 PDT 2008


Hi,

The st_within and st_contains functions does not work as excpected when working with polygons
on postgis1.3, geos 3.0.

Steps to reproduce the Problem:

-- Create Testtable and fill with Polygons of different sizes:
CREATE TABLE geomtest (id serial,geom geometry) with oids;

INSERT INTO geomtest(geom) VALUES (buffer(geometryfromtext('Point(5.0 46.0)',4326),0.7,20000) );
INSERT INTO geomtest(geom) VALUES (buffer(geometryfromtext('Point(5.0 46.0)',4326),0.5,10000) );
INSERT INTO geomtest(geom) VALUES (buffer(geometryfromtext('Point(5.0 46.0)',4326),0.3,1000) );
INSERT INTO geomtest(geom) VALUES (buffer(geometryfromtext('Point(5.0 46.0)',4326),0.2,100) );

-- The polygon is within the polygons we created above
SELECT id  From geomtest WHERE st_within(geometryfromtext('POLYGON((5.0 46.0, 5.01 46.0, 5.01 46.01, 5.0 46.01, 5.0 46.0   ))',4326),geom);
-- RETURN 0 rows.. which is IMHO a bug..

-- This should be same query as above (DE9-IM-Matrix from ogc-doku)
SELECT id  From geomtest WHERE st_relate(geometryfromtext('POLYGON((5.0 46.0, 5.01 46.0, 5.01 46.01, 5.0 46.01, 5.0 46.0   ))',4326),geom,'T*F**F***' );

-- The revers-operation returns also 0 rows.
SELECT id  From geomtest WHERE st_contains(geom,geometryfromtext('POLYGON((5.0 46.0, 5.01 46.0, 5.01 46.01, 5.0 46.01, 5.0 46.0   ))',4326));

-- Tested on:
-- Postgresql "8.3.3" POSTGIS="1.3.3" GEOS="3.0.0-CAPI-1.4.1" PROJ="Rel. 4.4.9, 29 Oct 2004" USE_STAT
-- Postgresql "8.3.3" POSTGIS="1.3.3" GEOS="3.0.0-CAPI-1.4.1" PROJ="Rel. 4.6.0, 21 Dec 2007" USE_STATS

-- Problem does NOT occur on:
-- Postgresql "8.1.11" POSTGIS="1.1.6" GEOS="2.2.3-CAPI-1.1.1" PROJ="Rel. 4.4.9, 29 Oct 2004" USE_STAT
-- (functions without st_ on postgis 1.1.x of course)


greetings
Ingo Klinkmann



More information about the postgis-devel mailing list