如何在Shapely中提取没有数组的几何对象的坐标

How to extract coordinates of a geometric object without array in Shapely

如何从没有文本 "array" 和 "typecode" 的数组中仅提取值?

数组是shapely.linestring.centroid.xy:

a = LineString.centroid.xy
print(a)
>> (array('d', [-1.72937...45182697]), array('d', [2.144161...64685937]))
print(a[0])
>> array('d', [-1.7293720645182697])

我只需要 -1.7293... 作为浮点数而不是整个 array 业务。

print(a[0][0])

您正在使用数组中的数组。

import array
a=(array.array('d',[-2.2,3,2,2]),array('d',[2,3,4]))
print(a[0][0])

其实个别坐标是Point can be accessed by x and y properties. And since object.centroidreturns一个Point,你可以简单的做:

>>> from shapely.geometry import LineString
>>> line = LineString([(0, 0), (2, 1)])
>>> line.centroid.x
1.0
>>> line.centroid.y
0.5

此外,PointLinearRingLineString 等几何对象有一个 coords 属性,returns 一个特殊的 CoordinateSequence 对象您可以从中获取个人坐标:

>>> line.coords
<shapely.coords.CoordinateSequence at 0x7f60e1556390>
>>> list(line.coords)
[(0.0, 0.0), (2.0, 1.0)]
>>> line.centroid.coords[0]
(1.0, 0.5)