Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curious Warning : Ring Self-intersection at or near point 0 1 #63

Open
lexman opened this issue Aug 4, 2016 · 5 comments
Open

Curious Warning : Ring Self-intersection at or near point 0 1 #63

lexman opened this issue Aug 4, 2016 · 5 comments

Comments

@lexman
Copy link

lexman commented Aug 4, 2016

Hello,
when using mapbox-vector-tile with some shape from Postgis this message appears in the log :

Ring Self-intersection at or near point 0 1

I've been able to isolate a test case :

import mapbox_vector_tile
geom = "POLYGON ((0 0, 4 0, 4 4, 0 4, 0 1, 3 3, 3 1, 0 1, 0 0 ))"
mapbox_vector_tile.encode([
  {
    "name": "test",
    "features": [
      {
        "geometry": geom,
        "properties":{}
      }
    ]
  }
])

The shape looks like :
capture du 2016-08-03 18 20 28

The funny thing is, if you describe the exact same shape another way (with an inner ring), the message does not appear any more :

import mapbox_vector_tile
geom = "POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0), (0 1, 3 3, 3 1, 0 1))"
mapbox_vector_tile.encode([
  {
    "name": "test",
    "features": [
      {
        "geometry": geom,
        "properties":{}
      }
    ]
  }
])

This looks like it's a case of invalid geometry. Also, if I send the tile produced to a mobile working with mapbox iOS SDK, it craches.

@zerebubuth
Copy link
Member

I think this might be down to the OGC "standard" definition of polygon validity. If I'm remembering correctly, it's allowed for an interior ring to touch, but not cross, an exterior ring once. But it's not okay for a ring (exterior or interior) to touch or cross itself.

However, the latest version of the Mapbox vector tile specification says:

Linear rings MUST be geometric objects that have no anomalous geometric points, such as self-intersection or self-tangency. ... Polygon geometries MUST NOT have any interior rings that intersect and interior rings MUST be enclosed by the exterior ring.

The first sentence would (like the OGC standard), appear to exclude the first polygon with the self-tangential exterior ring. It's not clear to me whether the second sentence would also exclude the second polygon with the tangential interior ring. The documentation does show an example with clearly overlapping exterior and interior, though!

Do both, or just the second, examples crash the SDK? I should think that's a bug in the SDK as, even with invalid input, crashing is probably undesired behaviour.

@lexman
Copy link
Author

lexman commented Aug 5, 2016

Hello, you're right the first version of the polygon is not OGC valid, and if you query Postgis with

SELECT ST_AsText(ST_MakeValid(ST_GeomFromText('POLYGON ((0 0, 4 0, 4 4, 0 4, 0 1, 3 3, 3 1, 0 1, 0 0 ))')))

You get

"POLYGON((0 1,0 4,4 4,4 0,0 0,0 1),(0 1,3 1,3 3,0 1))"

Sorry for fake bug... I'm closing.

@lexman lexman closed this as completed Aug 5, 2016
@mapsam
Copy link

mapsam commented Aug 5, 2016

@lexman @zerebubuth the OGC invalid winding order example on the specification page was pointed out by @nvkelso a couple weeks back - it's on my list to fix! Apologies for the potential confusion. https://github.com/mapbox/vector-tiles/issues/19

@zerebubuth
Copy link
Member

@lexman we're doing a similar thing to ST_MakeValid inside the vector tile encoder, so either input should produce working output!

Just to make absolutely sure; the output tile of the first example (self-touching exterior ring - OGC invalid) crashes the SDK, but the output tile for the second one (interior ring touching outer - OGC valid) is okay? Or do they both have problems?

@zerebubuth zerebubuth reopened this Aug 5, 2016
@lexman
Copy link
Author

lexman commented Aug 20, 2016

Sorry for answering so late... We've fixed a few issues, we've upgraded to version 4 and we've made use of on-_invalid_geometry_make_valid. But in the rush we didn't test every step to see what really fixed the issue because our mobile developper is on hollydays. Actually, the application crashes could have been caused by a layer not simplified enought. It would produce some 1MB tiles and we suspect it caused memory issues on the iphone.

If we run again in a similare case :(, we'll re-open this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants