I'm new to using Shapely, and I have some question. I have a LineString and I wish to split it based on intersections of other LineStrings.
If the intersection turns out to be a single point, then we can simply use the following code to obtain a GeometryCollection of LineStrings split at that intersection point:
ip = ls.intersection(other_ls) # assuming ip here is a single Point()
However, if the intersection of two LineStrings is also another LineString (i.e., a shared path), then running the following code:
ops.split(ls, other_ls) # assuming that the intersection is also a LineString
returns an error:
ValueError: Input geometry segment overlaps with the splitter.
where again, the blue LineString is our observed and the red LineString is the one to split the blue one. The resultant would be a GeometryCollection of three LineStrings but of course it is also possible to obtain a GeometryCollection of two LineStrings as a result just depending on where the red LineString is situated. I wish to be able to do this, but using
ops.split() does not seem to work.
But I am not exactly sure how to do it correctly. Here is a rough pseudocode that I came up with but I am not sure if it is right or whether it would be efficient when it is implemented. I'm not really looking for a top-notch solution when it comes to runtime. But at least something that works.
ls = observed_linestring
other_linestrings = list_consisting_of_other_linestrings
for ol in other_linestrings:
intersections = ol.intersection(ls)
point_intersections = [x for x in intersections if x is a Point]
for point in point_intersections:
splits = ops.split(ls, point)