Opened 4 years ago

Closed 4 years ago

#4863 closed defect (fixed)

Geometry doesn't contain itself when ST_Scale down

Reported by: mattzen Owned by: pramsey
Priority: medium Milestone: PostGIS 3.1.2
Component: postgis Version: 3.1.x
Keywords: Cc:

Description

I'm trying to check if a geometry contains a scaled-down version of its oriented bounding box, and was expecting the following query to return true:

# select st_contains(geometry, st_scale(st_orientedenvelope(geometry),
 'SRID=3857; POINT(0.8 0.8)', st_centroid(geometry))) from (select
 'SRID=3857; POLYGON((-141972.789895508 6755731.24770785,-141935.49511986 
 6755733.56891884,-141934.403428904 6755716.1146343,-141971.698204552 
 6755713.77835553,-141972.789895508 6755731.24770785))'::geometry as
 geometry) x;
 st_contains
-------------
 f
(1 row)

That seemed strange, so I tried exporting the geometries to visualise them and it really seemed like it should be true. Then I tried this query (note that I'm serialising the scaled geom to EWKB and parsing the result):

# select st_contains(geometry, 
 st_geomfromewkb(st_asewkb(st_scale(st_orientedenvelope(geometry),
 'SRID=3857; POINT(0.8 0.8)', st_centroid(geometry))))) from (select
 'SRID=3857; POLYGON((-141972.789895508 6755731.24770785,-141935.49511986 
 6755733.56891884,-141934.403428904 6755716.1146343,-141971.698204552 
 6755713.77835553,-141972.789895508 6755731.24770785))'::geometry as
 geometry) x;
 st_contains
-------------
 t
(1 row)

Just in case I was misunderstanding what ST_Contains is supposed to do, I tried with ST_Covers as well and got the same result.

Post* versions:

# select postgis_full_version();
                                                                       postgis_full_version
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="3.1.1 aaf4c79" [EXTENSION] PGSQL="130" GEOS="3.9.0-CAPI-1.16.2" 
 PROJ="7.2.1" LIBXML="2.9.10" LIBJSON="0.15" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 
 (Internal)"
(1 row)

# select version();
                                                     version
------------------------------------------------------------------------------------------------------------------
 PostgreSQL 13.1 on x86_64-apple-darwin19.6.0, compiled by Apple clang version 
 12.0.0 (clang-1200.0.32.2), 64-bit
(1 row)

Change History (5)

comment:1 by Paul Ramsey <pramsey@…>, 4 years ago

In 055b74d/git:

Ensure bboxes are refreshed after cooridinate transforms in scale/affine. References #4863

comment:2 by Paul Ramsey <pramsey@…>, 4 years ago

In 9ef629f7/git:

Ensure bboxes are refreshed after cooridinate transforms in scale/affine. References #4863

comment:3 by Paul Ramsey <pramsey@…>, 4 years ago

In 29e1db1/git:

Ensure bboxes are refreshed after cooridinate transforms in scale/affine. References #4863

comment:4 by Paul Ramsey <pramsey@…>, 4 years ago

In e9b9d34/git:

Ensure bboxes are refreshed after cooridinate transforms in scale/affine. References #4863

comment:5 by pramsey, 4 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.