I am a little confused about how objects are being defined and represented and mostly because some of the solutions I find for solving issues I have demand that the input data be in an other form than the one I manage to generate.
Let say that I wish to divide a LineString into 6 equal segments, then this method work perfectly:
from shapely.geometry import LineString, MultiPoint
from shapely.ops import split
line = LineString([(0, 0), (10, 10)])
splitter = MultiPoint([line.interpolate((i/4), normalized=True) for i in range(1, 4)])
split(line, splitter).wkt
which returns:
'GEOMETRYCOLLECTION (LINESTRING (0 0, 2.5 2.5), LINESTRING (2.5 2.5, 5 5), LINESTRING (5 5, 7.5 7.5), LINESTRING (7.5 7.5, 10 10))'
With my method (on my data)
zone_short_edges['line'] = zone_short_edges.apply(lambda row: LineString([row['fr_point'], row['to_point']]), axis=1) #Create a linestring column
zone_short_edges['midpoint'] = zone_short_edges.apply(lambda row: row['line'].centroid, axis=1) #Find centroid
zone_short_edges = zone_short_edges.set_geometry("line")
zone_short_edges = zone_short_edges.set_geometry("midpoint")
I generate POINT
s and LINESTRING
s of this type:
id vertex_id fr_point \
1 Allé 119 2 POINT (119.79008 28.35047)
3 Allé 119 4 POINT (122.85067 44.85106)
to_point seg_length \
1 POINT (122.85067 28.08433) 3.072140
3 POINT (119.92314 44.71798) 2.930553
line \
1 LINESTRING (119.79008 28.35047, 122.85067 28.0...
3 LINESTRING (122.85067 44.85106, 119.92314 44.7...
midpoint
1 POINT (121.32038 28.21740)
3 POINT (121.38690 44.78452)
that is, LINESTRING (119.79008 28.35047, 122.85067 28.0454, 122.3434 23.323)
. And I therefore cannot use the linestring splitting method. Also, the result of the method is linestrings in the form I have to begin with.
What is the difference between LineString([(0, 0), (10, 10)])
and LINESTRING((0 0), (10 10))
?