我正在尝试创建两个数组的单个LineString对象。我尝试了多种方法,但我一直在努力:
>>> array = [(0,0),(1,0),(2,0),(3,0)][(1,3),(1.4,2),(2,0)]
TypeError: list indices must be integers, not tuple
## A
## \
## \
## X
## \
## \
## B-----C-----D-----F
## Test to Identify Junctions - Shared points where two or more lines intersect
def test_find_junctions(self):
g = PreserveTopology()
# LINE BCDF, AXD
array = [(0,0),(1,0),(2,0),(3,0)][(1,3),(1.4,2),(2,0)]
# LINE AXD
#array2 = [(1,3),(1.4,2),(2,0)]
array_as_linestring = LineString(array)
#array2_as_linestring = LineString(array2)
result = g.find_junctions_line(array_as_linestring)
assert_equal(result,(2,0))
答案 0 :(得分:1)
如果您希望将列表放在数组中,则必须将列表括在方括号中,然后用逗号分隔列表。
array = [[(0,0),(1,0),(2,0),(3,0)],[(1,3),(1.4,2),(2,0)]]
答案 1 :(得分:0)
看起来你有两个线段,所以你需要有一个LineString几何列表或一个MultiLineString几何。继续@David的语法错误修复,您可以构建以下任一结构:
from shapely.geometry import LineString, MultiLineString
from shapely.ops import cascaded_union
array = [[(0, 0), (1, 0), (2, 0), (3, 0)], [(1, 3), (1.4, 2), (2, 0)]]
ls = [LineString(ar) for ar in array]
mls = MultiLineString(array)