POSTGIS TopologyException: side location conflict
Asked Answered
O

3

8

I'm trying to execute a simple st_intersects query:

select st_intersects('MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))','POLYGON((3 4.5,3 5,4 5,4 4,3 4.5))');

which crush the console and returns the following error:

Error: GEOSIntersects: TopologyException: side location conflict at: 6 4

Which is completely odd because the following query works:

select st_intersects('MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))','POLYGON((3 4,3 5,4 5,4 4,3 4))');

The only difference between the two is the 4 / 4.5 in the last polygon..

I use POSTGIS version 2.2.1 what am i missing here?

Oddson answered 6/3, 2017 at 13:45 Comment(0)
O
14

I found a relevant solution to my problem.

select st_intersects(st_buffer('MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))',0),'POLYGON((3 4.5,3 5,4 5,4 4,3 4.5))');

When i added the st_buffer it merge the two polygons of the multipolygon to one and solved the issue.

Oddson answered 8/3, 2017 at 13:4 Comment(2)
Thank you. You've saved me lots of hours of searching!Whoa
This should be marked as the accepted answer so it floats to the top.Spinoff
D
6

you can check that the MultiPolygon geometry in your query is not a valid MultiPolygon:

=> select st_isvalid(
    st_geomfromtext(
        'MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))'
));
NOTICE:  Self-intersection at or near point 6 6
 st_isvalid
------------
 f
(1 row)

the reason for this is that the Polygon (5 5,8 8,11 5,8 2,5 5) defining the "hole" (inner ring) intersects the outer ring (1 5,4 8,7 5,4 2,1 5).

It would be either necessary to fix the input manually, or one can use ST_MakeValid to do the job (it automatically detects and handles the overlapping parts):

=> select st_intersects(
    st_makevalid(
        'MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))'
    ),
    'POLYGON((3 4.5,3 5,4 5,4 4,3 4.5))'
);
 st_intersects 
---------------
 t
(1 row)
Decorous answered 7/3, 2017 at 16:45 Comment(1)
Thanks for the answer but it still doesn't explain why the second polygon intersect doesn't return any errorOddson
M
0

I tried to compare a polygon and a collection of small polygons with ST_CoveredBy. I tried to collect my small polygons with ST_collect and got the same error. I validated them with st_IsValid, turned ST_collect(geom_1,geom_2...) >> ST_Union() and it worked.

Metrist answered 13/12, 2023 at 13:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.