1

I am trying to split a line with multiple points. I adopt the solution in here, but sometimes it does not work.

from shapely.geometry import LineString, MultiPoint
from shapely.ops import split

line = LineString([(0.1, 0.01), (0.001, 0.001)]) splitter = MultiPoint([line.interpolate((i/6), normalized=True) for i in range(1, 6)]) gcline = split(line, splitter) str(gcline)

The output is

'GEOMETRYCOLLECTION (LINESTRING (0.1 0.01, 0.001 0.001))'

I guess it is because the line is too short. The method works fine for LineString([(0.1, 0.1), (0.001, 0.001)]).

WZhao
  • 121
  • 3

1 Answers1

1

I think I know what happens.

check whether the point lies on the line

line.intersects(splitter[0])
False

It is because of float error. See https://stackoverflow.com/questions/50194077/shapely-unable-to-split-line-on-point-due-to-precision-issues, Shapely floating problems with split()

A good solution was provided by https://gis.stackexchange.com/a/327287/168805.

WZhao
  • 121
  • 3