-
Notifications
You must be signed in to change notification settings - Fork 560
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
ops.split inconsistent behavior with LineStrings and MultiLineStrings #701
Comments
Ok. I see the problem here. Visually, those linestrings look like this: When you split the horizontal (A) by the large vertical on top (B) which only touches A, nothing happens. But splitting A by C does work because C crosses A. Now, when you split A by The code causing this is actually pretty accessible (permalink). @staticmethod
def _split_line_with_line(line, splitter):
"""Split a LineString with another (Multi)LineString or (Multi)Polygon"""
# if splitter is a polygon, pick it's boundary
if splitter.type in ('Polygon', 'MultiPolygon'):
splitter = splitter.boundary
assert(isinstance(line, LineString))
assert(isinstance(splitter, LineString) or isinstance(splitter, MultiLineString))
if splitter.crosses(line):
# The lines cross --> return multilinestring from the split
return line.difference(splitter)
elif splitter.relate_pattern(line, '1********'):
# The lines overlap at some segment (linear intersection of interiors)
raise ValueError('Input geometry segment overlaps with the splitter.')
else:
# The lines do not cross --> return collection with identity line
return [line] You can see that the |
@Jeremiah-England thanks for digging into this! It seems like, for lines at least, we could change the crosses test to a touches test and get less surprising results? What do you think about that? |
I think that would work fine, yes. And the behavior makes sense to me. For a bit, I thought we could filter the goems in a MultiLineString I suspect that maybe It was 5 years ago, but if @georgeouzou remembers maybe he could confirm or explain why We can have our cake and eat it too if we want to return early in the case tested for, but carry on with splitting in this issue's case. That would require using |
@Jeremiah-England my memory is a little cloudy on this one, but seeing the code again i can confirm that this was a blind spot. The code should also test for the current case to be complete. Could you continue on with the changes? |
Hey @georgeouzou, thanks for taking the time to look at that! And, yes, if it's OK with everyone I would like to hammer out this case and submit a PR at some point. |
… interior of the line: shapely#701
@georgeouzou @Jeremiah-England thanks for communicating about the intent of the splitter! Splitting on touch seems consistent with https://postgis.net/docs/ST_Split.html, which allows a point to split a line. I'm going to merge #1034 now and it will be in 1.8a1. |
Expected behavior and actual behavior & steps to reproduce the problem
Splitting a linestring A with an intersecting linestring B does not produce the expected output (returns A). Splitting A with a multilinestring containing B and C (C intersecting A as well) produces the desired output (3 segments). This seems inconsistent.
Operating system
Ubuntu 18.04.2 LTS
Shapely version and provenance
Python 3.6.7 - Shapely 1.6.4.post2 (installed from PyPI using pip)
The text was updated successfully, but these errors were encountered: