2

I have two polygons such that polygon A (pie-shaped) covers polygon B (rectangle) as shown here: https://wktmap.com/?6aaf8c11.

Why does PostGIS return false for ST_Intersects(A, B), but true for ST_Covers(A, B)? It does not make any sense.

SELECT st_intersects(ST_GeomFromText('POLYGON((16.00061 45.822171,15.99285240563651 45.8293452320342,15.990050859670909 45.82732350122485,15.988282915930574 45.82479740769603,15.987721633066801 45.82201422308267,15.988421953356983 45.8192463848863,16.00061 45.822171))',4326), ST_GeomFromText('POLYGON((15.989 45.82, 15.989 45.82, 15.989 45.82, 15.989 45.82, 15.989 45.82))',4326));
 st_intersects 
---------------
 f
(1 row)
SELECT st_covers(ST_GeomFromText('POLYGON((16.00061 45.822171,15.99285240563651 45.8293452320342,15.990050859670909 45.82732350122485,15.988282915930574 45.82479740769603,15.987721633066801 45.82201422308267,15.988421953356983 45.8192463848863,16.00061 45.822171))',4326), ST_GeomFromText('POLYGON((15.989 45.82, 15.989 45.82, 15.989 45.82, 15.989 45.82, 15.989 45.82))',4326));
 st_covers 
-----------
 t
(1 row)
SELECT PostGIS_version();
            postgis_version            
---------------------------------------
 3.2 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

SELECT version();
                                                                version                                                                 
----------------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 14.12 (Ubuntu 14.12-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
(1 row)

2 Answers 2

5

The small rectangle is an invalid polygon, as all coordinates are identical:

ST_GeomFromText('POLYGON((15.989 45.82, 15.989 45.82, 15.989 45.82, 15.989 45.82, 15.989 45.82))',4326))

Calculating spatial relations with invalid polygons leads to undefined result...

2
  • 1
    Yes, you are right. I copy-pasted the wrong point where all the coordinates were the same. PostGIS method ST_intersects works as expected when I replace the polygon with the correct one: POLYGON((15.989 45.821, 15.99 45.821, 15.99 45.82, 15.989 45.82, 15.989 45.821)). Thanks a lot. Commented Jul 23 at 8:12
  • 1
    @KrešimirPripužić if your question can be considered answered, please mark the answer as accepted so it is clear to everyone at first sight: gis.stackexchange.com/help/someone-answers
    – Pieter
    Commented Jul 23 at 11:44
-2

One possible reason is definitions of terms.

I would expect a function called "Intersects" to look at whether the boundaries of two shapes cross each other, because that's what "Intersect" means. Looking at your Wktmap link, those two shapes do not intersect because the boundaries do not cross each other.

Disclaimer: I know nothing about PostGIS, this is a geometry-based answer.

2
  • For e.g. lines this is the case, for polygons the entire surface is taken in account to determine if there is an intersection (both the boundaries and the interiors). This is the case for any GIS software I know of, e.g. PostGIS, ESRI ArcMap,...
    – Pieter
    Commented Jul 23 at 7:30
  • @Pieter - Thanks. Good thing I included the disclaimer.
    – Trams
    Commented Jul 23 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.