Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Shapely中多行线对象中的线串顺序_Python_Shapely - Fatal编程技术网

Python Shapely中多行线对象中的线串顺序

Python Shapely中多行线对象中的线串顺序,python,shapely,Python,Shapely,我有一个MultiLineString对象,其中组成它的LineStrings没有正确排序(或者至少没有按照我希望的顺序排序) 例如,假设我有以下两行字符串: from shapely.geometry import * LineIWant = MultiLineString([((0,0),(2,5)),((2,5),(7,10)),((7,10),(6,15))]) LineIHave = MultiLineString([((0,0),(2,5)),((7,10),(6,15)),((2,

我有一个
MultiLineString
对象,其中组成它的
LineStrings
没有正确排序(或者至少没有按照我希望的顺序排序)

例如,假设我有以下两行字符串:

from shapely.geometry import *
LineIWant = MultiLineString([((0,0),(2,5)),((2,5),(7,10)),((7,10),(6,15))])
LineIHave = MultiLineString([((0,0),(2,5)),((7,10),(6,15)),((2,5),(7,10))])
正如您所看到的,坐标是这样的,所有的线段都连接/匹配起来,但在我拥有的对象中,它们不是有序的。当我尝试使用插值方法沿对象获得75%的点时,这是有问题的:

LineIHave.interpolate(.75, normalized=True)

关于如何对我的
多行字符串
对象中的
行字符串
进行重新排序,有什么建议吗?

尝试将多行字符串设置为单个行字符串:

from shapely.ops import linemerge
linemerge(LineIHave)  # LINESTRING (0 0, 2 5, 7 10, 6 15)
linemerge(LineIWant)  # LINESTRING (0 0, 2 5, 7 10, 6 15)
如果linemerge将线定向错误,则可以将其反转:

LineString(linemerge(LineIWant).coords[::-1])  # LINESTRING (6 15, 7 10, 2 5, 0 0)