Strange behaviour from ST_MakeValid when holes escape polygon outer ring

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange behaviour from ST_MakeValid when holes escape polygon outer ring

Craig de Stigter-2
Hi folks

We've been using an internal geometry-fixing function for a long time, and I'm looking into replacing it with ST_MakeValid().

I've come across a strange edge-case where ST_MakeValid() appears to incorrectly treat polygons as a set of linework, rather than a shell and a set of holes.

This means that when you give it a shape with a hole that partially escapes the exterior ring, instead of that part getting discarded it forms the outer ring of a new polygon, thus creating a multipolygon.

I expected it to take the outer ring and ST_Difference() all the inner rings from the outer ring.

Here's some screenshots to demonstrate:

Expected: https://drive.google.com/file/d/0By4X8bGnhCGEQjdzQlpsY0xlelk/view?usp=sharing

Would anyone who knows a bit more about ST_MakeValid() be able to comment on this? (If I dug into the source and was able to submit a patch to fix this, would it be likely to be accepted?)

--
Regards,
Craig

Developer
Koordinates

<a href="tel:+64%2021%20256%209488" style="color:rgb(17,85,204)" target="_blank">+64 21 256 9488 / koordinates.com / @koordinates

_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|

Re: Strange behaviour from ST_MakeValid when holes escape polygon outer ring

Darafei "Komяpa" Praliaskouski
ST_MakeValid tries to reconstruct geometry without losing vertices.

The only sane way I can think of to do it without losing vertices is to stop treating the inner ring as inner ring and mark it as outer.

If you need a geometry fixup function that does processing with losing vertices, ST_MakeValid isn't semantically what you need.

вт, 11 окт. 2016 г. в 23:24, Craig de Stigter <[hidden email]>:
Hi folks

We've been using an internal geometry-fixing function for a long time, and I'm looking into replacing it with ST_MakeValid().

I've come across a strange edge-case where ST_MakeValid() appears to incorrectly treat polygons as a set of linework, rather than a shell and a set of holes.

This means that when you give it a shape with a hole that partially escapes the exterior ring, instead of that part getting discarded it forms the outer ring of a new polygon, thus creating a multipolygon.

I expected it to take the outer ring and ST_Difference() all the inner rings from the outer ring.

Here's some screenshots to demonstrate:

Expected: https://drive.google.com/file/d/0By4X8bGnhCGEQjdzQlpsY0xlelk/view?usp=sharing

Would anyone who knows a bit more about ST_MakeValid() be able to comment on this? (If I dug into the source and was able to submit a patch to fix this, would it be likely to be accepted?)

--
Regards,
Craig

Developer
Koordinates

<a href="tel:+64%2021%20256%209488" style="color:rgb(17,85,204)" class="gmail_msg" target="_blank">+64 21 256 9488 / koordinates.com / @koordinates
_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|

Re: Strange behaviour from ST_MakeValid when holes escape polygon outer ring

Craig de Stigter-2
Aha, cheers. In fact I see that's mentioned in the docs too, but I hadn't really understood what it meant until you pointed it out.

I'm curious if there's a situation in which that's a useful behaviour? It strikes me as a very strange quirk...

On 12 October 2016 at 09:35, Komяpa <[hidden email]> wrote:
ST_MakeValid tries to reconstruct geometry without losing vertices.

The only sane way I can think of to do it without losing vertices is to stop treating the inner ring as inner ring and mark it as outer.

If you need a geometry fixup function that does processing with losing vertices, ST_MakeValid isn't semantically what you need.

вт, 11 окт. 2016 г. в 23:24, Craig de Stigter <[hidden email]>:
Hi folks

We've been using an internal geometry-fixing function for a long time, and I'm looking into replacing it with ST_MakeValid().

I've come across a strange edge-case where ST_MakeValid() appears to incorrectly treat polygons as a set of linework, rather than a shell and a set of holes.

This means that when you give it a shape with a hole that partially escapes the exterior ring, instead of that part getting discarded it forms the outer ring of a new polygon, thus creating a multipolygon.

I expected it to take the outer ring and ST_Difference() all the inner rings from the outer ring.

Here's some screenshots to demonstrate:

Expected: https://drive.google.com/file/d/0By4X8bGnhCGEQjdzQlpsY0xlelk/view?usp=sharing

Would anyone who knows a bit more about ST_MakeValid() be able to comment on this? (If I dug into the source and was able to submit a patch to fix this, would it be likely to be accepted?)

--
Regards,
Craig

Developer
Koordinates

<a href="tel:+64%2021%20256%209488" style="color:rgb(17,85,204)" class="m_7140635769007187356gmail_msg" target="_blank">+64 21 256 9488 / koordinates.com / @koordinates
_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users



--
Regards,
Craig

Developer
Koordinates

<a href="tel:+64%2021%20256%209488" style="color:rgb(17,85,204)" target="_blank">+64 21 256 9488 / koordinates.com / @koordinates

_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users
Reply | Threaded
Open this post in threaded view
|

Re: Strange behaviour from ST_MakeValid when holes escape polygon outer ring

Darafei "Komяpa" Praliaskouski
There are, for instance, non-OGC-to-OGC data conversions that have to reinvent which rings are outer and which rings are inner.
OpenStreetMap data schema allows them not marked (so - multipolygon is just a collection of rings). ST_MakeValid is very useful on processing these, as users usually don't draw useless lines, and you should guess the inner/outer the same way usual editor's graphical library guesses them to get the best result in your database - which ST_MakeValid is good at.

On a globe, all the rings of a polygon are technically outer - consider a ST_Buffer(equator line, 10) - this polygon technically has two rings on a globe, both outer, both denote just a single piece of area.. :)

ср, 12 окт. 2016 г. в 1:54, Craig de Stigter <[hidden email]>:
Aha, cheers. In fact I see that's mentioned in the docs too, but I hadn't really understood what it meant until you pointed it out.

I'm curious if there's a situation in which that's a useful behaviour? It strikes me as a very strange quirk...

On 12 October 2016 at 09:35, Komяpa <[hidden email]> wrote:
ST_MakeValid tries to reconstruct geometry without losing vertices.

The only sane way I can think of to do it without losing vertices is to stop treating the inner ring as inner ring and mark it as outer.

If you need a geometry fixup function that does processing with losing vertices, ST_MakeValid isn't semantically what you need.

вт, 11 окт. 2016 г. в 23:24, Craig de Stigter <[hidden email]>:
Hi folks

We've been using an internal geometry-fixing function for a long time, and I'm looking into replacing it with ST_MakeValid().

I've come across a strange edge-case where ST_MakeValid() appears to incorrectly treat polygons as a set of linework, rather than a shell and a set of holes.

This means that when you give it a shape with a hole that partially escapes the exterior ring, instead of that part getting discarded it forms the outer ring of a new polygon, thus creating a multipolygon.

I expected it to take the outer ring and ST_Difference() all the inner rings from the outer ring.

Here's some screenshots to demonstrate:

Expected: https://drive.google.com/file/d/0By4X8bGnhCGEQjdzQlpsY0xlelk/view?usp=sharing

Would anyone who knows a bit more about ST_MakeValid() be able to comment on this? (If I dug into the source and was able to submit a patch to fix this, would it be likely to be accepted?)

--
Regards,
Craig

Developer
Koordinates

<a href="tel:+64%2021%20256%209488" style="color:rgb(17,85,204)" class="m_-1782887543623602053m_7140635769007187356gmail_msg gmail_msg" target="_blank">+64 21 256 9488 / koordinates.com / @koordinates
_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users



--
Regards,
Craig

Developer
Koordinates

<a href="tel:+64%2021%20256%209488" style="color:rgb(17,85,204)" class="gmail_msg" target="_blank">+64 21 256 9488 / koordinates.com / @koordinates
_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-users