Python 如何在Shapely中提取无阵列几何对象的坐标

Python 如何在Shapely中提取无阵列几何对象的坐标,python,arrays,shapely,Python,Arrays,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.

如何仅从数组中提取值,而不提取文本“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…
作为浮点数,而不是整个阵列业务

您正在使用数组中的数组


事实上,可以通过
x
y
属性访问的单个坐标。由于返回一个
,您只需执行以下操作:

>>> from shapely.geometry import LineString
>>> line = LineString([(0, 0), (2, 1)])
>>> line.centroid.x
1.0
>>> line.centroid.y
0.5
此外,几何对象(如
线性化
线字符串
等)具有一个属性,该属性返回一个特殊的
坐标序列
对象,您可以从该对象中获取各个坐标:

>>> 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)
>>line.coords
>>>列表(行坐标)
[(0.0, 0.0), (2.0, 1.0)]
>>>直线形心坐标[0]
(1.0, 0.5)

你说得对,我的错。将我的答案向下+向上投票给你。请将你的代码作为文本而不是截图发布。是的,但他只需要一句话。
>>> from shapely.geometry import LineString
>>> line = LineString([(0, 0), (2, 1)])
>>> line.centroid.x
1.0
>>> line.centroid.y
0.5
>>> 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)