-
Notifications
You must be signed in to change notification settings - Fork 443
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
Improve how zero-length linestring are handled by relate #346
base: master
Are you sure you want to change the base?
Conversation
Perhaps we could use a |
I thing the first change (Adding the point to the graph) is worthwhile even if touches still does not return an intuitive result (may also be the case for other predicates which definition depends on the geometry dimension) |
Agreed that changing the semantics of A slightly less intrusive option would be to have relate compute an "effective dimension", and use that in the IM predicates. It's still expensive to test for a polygon with effective dimension 1, however, so probably should not do that. And that means that |
@@ -292,6 +292,7 @@ private void addLineString(LineString line) | |||
if (coord.length < 2) { | |||
hasTooFewPoints = true; | |||
invalidPoint = coord[0]; | |||
addPoint(coord[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a BIG comment here indicating that this is an enhancement to standard OGC semantics, and is potentially a source of (as yet unknown) logic bugs.
I will add a comment. |
I had to go a little further to keep all tests positives. Beside the change in GeometryGraph, I changed
|
This is starting to feel like a major change to semantics. I'm feeling uncomfortable about changing the dimension value based on geometry coordinates, because of both semantics changes and also cost of computation. I'd prefer to see operation semantics changed where needed to be extended to handle collapsed geometry. I.e in the minimal case allow |
I wanted to explore your proposition to change the dimension during operations instead of changing the semantic of getDimension, but in IntersectionMatrix, all public methods where dimension has an impact on the result take the dimension as a parameter like |
One way to extend the existing predicates (which use full IM computation) is to provide a Actually perhaps that's promising too much, since it can't realistically check for polygons collapsing to a line. So it could just check for collapse to a point, and perhaps be called |
Really this comes down to what the use cases are. I can see the utility of extending some of the predicates to handle all possible geometries. And enhancing centroid makes sense too. But doing this does not require a major change to semantics and existing test cases. |
Is there a PostGIS issue which reported the limitation in ST_Intersects? |
About polygon collapsing : maybe we can handle the simple cases by traversing all segments of the outer ring from the starting point in cw and in ccw and check that all pairs of segments are equal and opposite. Cases where a point lies in the interior of another segment are not processed, but these case are subject to precision issues and it sounds reasonable to let them out. |
Where would you implement getEffectiveDimension so that it can be used by different algorithm like IM or interiorPoint ?
And some points against
|
I did not write an issue in the PostGIS list yet because I did not have the opportunity to test the very last version (I use PostGIS 2.4). I'll try to install it and test it ASAP. |
Good summary of the issues around changing the semantics of |
Good question about where to implement |
As for the proposed algorithm for detecting polygons collapsed to a line, is it really worth doing this for such a small subset of "linear" polygons? Is this really a use case? This touches on a deeper issue about this whole proposal. It seems to me that it's not just extending the domain of (say) the intersects function, but also that a system can determine whether it can trust the result of calling that function on a geometry. At the moment the contract is that valid geometries will produce valid answers, and otherwise there are no guarantees. If intersects is extended to handle some (technically) invalid geometry, does that really help anything? The valid domain can be documented, of course, and perhaps that useful for important operations like intersects. But it's still most useful to have an automated check - otherwise it's risky to embed the operation deep inside an process. This makes me even more reluctant to cope with this by changing More understanding of use cases might help here. |
Polygons collapsed to a line : seems to me that the proposition only excludes the case where the endpoint of a segment lies in the middle of another segment. A case which is sensible to precision problems (ex. dimension 1 in a projection may become dimension 2 after reprojection). To handle a larger set of cases, I can only imagine something based on area or using some sort of tolerance. But perhaps I may have missed something. |
It seems like there would be many more cases where a collapsed polygon had segment endpoints which do not line up exactly. So my question is whether it's really worth trying to handle linear collapses given the cost of checking the general case. Actually note that it's (theoretically) easy to test intersects for polygons no matter what kind of shape their linework is in. And it seems like a worthwhile goal to extend intersects to handle this. Really the issue is that the current intersects algorithm requires a hack to get it to work. But noted before, there are other ways of computing this which don't require that hack. |
If intersects is extended to handle some (technically) invalid geometry, does that really help anything?
This is the only use case I have for now. In this case just adding a point in the GeometryGraph seems to solve the problem. Maybe it is enough. The dimension question arise when we try to get consistent results for all predicates (predicates sensible to dimension) and for all kinds of collapsed geometries. I agree that adding another method to Geometry is not very exciting. Adding a helper class/method to return trueDimension would probably be enough, but in both cases, my feeling is that having two kinds of dimension may make the library more difficult to understand and to use correctly. |
There are many theoretically true geometric statements which are false when computed by JTS! This does seem like one of the easier ones to fix, so I suppose it doesn't hurt to implement it (although as you say it doesn't fix other predicates). My concern is how to document this and maintain the semantics going forward. A unit test will help of course, but it's still a bit obscure. |
@mukoki are you still interested in this PR? I would rather see a PR that addresses just the issue of handling zero-length lines in |
Adding the point to the graph instead of doing nothing fix the problem with LineString.intersects in case of 0-length linestring.
LineString.touches with a 0-length geometry still does not return the same result as if it was a point, because touches consider the dimension of input geometry (1 instead of 0). Maybe the dimension returned by LineString should be 0 rather than 1 in this case.
I tested with
LineString#getDimension() {return getLength() == 0 ? 0 : 1}
but it breaks some tests asserting that empty linestring dimension must be 1.