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

Allow construction of LinearRings with < 4 points #406

Closed
dbaston opened this issue Feb 6, 2021 · 6 comments
Closed

Allow construction of LinearRings with < 4 points #406

dbaston opened this issue Feb 6, 2021 · 6 comments

Comments

@dbaston
Copy link
Member

dbaston commented Feb 6, 2021

If we can't construct them, we can't repair them. As discussed at r-spatial/sf#1589 and locationtech/jts#558

@dr-jts
Copy link
Contributor

dr-jts commented Feb 7, 2021

The minimum number of points in a LinearRing can definitely be reduced to 3, instead of 4. That will handle the data in both issues above. I haven't seen any data which requires a lower limit, so probably best to make the minimal change for now.

@dr-jts
Copy link
Contributor

dr-jts commented Feb 8, 2021

See JTS PR 682 and 683.

@jratike80
Copy link

I wonder what MakeValid should do. To remove the flat ring that does not have any area, or to maintain the topology by creating a minimal buffer or by adding a fourth point with a small offset?

@dr-jts
Copy link
Contributor

dr-jts commented Mar 15, 2021

I wonder what MakeValid should do. To remove the flat ring that does not have any area, or to maintain the topology by creating a minimal buffer or by adding a fourth point with a small offset?

That's a very timely question, since I'm working on a GeometryFixer class for JTS (for eventual port into GEOS, since it has slightly different semantics to MakeValid. I'm not sure there's an obvious right answer. I do NOT think that the flat ring should be buffered or have points added, however, for reasons of performance and (more importantly) avoidance of introducing unexpected coordinates.

So the options for fixing a ring with too few points seem to be:

  • turn it into a LineString or a Point
  • turn it into a LINEARING EMPTY

There is the same issue for a ring with many points but which is flat, and a LineString with too few points.

Another approach I am considering is that if the ring (or line) is an atomic geometry, then reduce it to a geometry of inherent dimensional type; OR if if the ring/line is part of a collection, then drop it. This avoids creating collections of mixed type, which are awkward to handle.

Feedback welcome.

@jratike80
Copy link

jratike80 commented Mar 15, 2021

When I think where I have met such geometries, OpenStreetMap data has always had them for some reason, and at least some MVT vector tile writers degenerate rings into straight lines occasionally. As a user of the data I would probably appreciate to have an option to get placeholders for locating those places because originally they may have been meaningful. POINT would do for that purpose. LINEARRING EMPTY is theoretically fine but otherwise useless, I think.

Maybe in most cases I would like to get rid of the flat rings and others like in your latter approach. In typical GIS data degenerated things feel like something that is left from bad simplification. If data provider really wanted to use topology preserving simplification it is still impossible to fix the data afterwards because probably there are also successfully removed rings. The OpenStreetmap case is different because the contributor maybe digitized and tagged the data just that way and they just did not know how to do it right.

My main vector tool is OpenJUMP so I do not fear collections, but for most GIS users they are complicated.

@dr-jts
Copy link
Contributor

dr-jts commented Mar 15, 2021

@jratike80 Sounds like there needs to be some options for users to use when making valid geometries. At least one to indicate whether to drop collapsed elements, or to preserve them as lower-dimension elements.

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

4 participants