2

我正在尝试创建两个数组的单个 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))
4

2 回答 2

2

看起来你有两个线段,所以你需要有一个 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)
于 2014-07-28T05:13:53.507 回答
1

如果您希望它是一个数组,则必须将列表括在方括号中,然后用逗号分隔列表。

array = [[(0,0),(1,0),(2,0),(3,0)],[(1,3),(1.4,2),(2,0)]]
于 2014-07-28T00:49:32.303 回答