我正在尝试从一个使用numpy和arcpy的要素类中获取一个2D数组。。。在
import arcpy
import numpy
locxyarray = arcpy.da.FeatureClassToNumPyArray("Points", ['SHAPE@XY', 'PrimeKey'])
结果是:
^{pr2}$我想要的:
array([(506173.7478, 5455684.263900001, 1),
(506175.22869999986, 5455648.723099999, 2),
(506229.03359999973, 5455661.5572999995, 3),
(506250.25939999986, 5455614.169500001, 4),
(506305.54509999976, 5455579.122300001, 5),
(506331.70710000023, 5455688.2129, 6)],
dtype=[('SHAPE@XY', '<f8', (2,)), ('PrimeKey', '<i4')])
我想要上面的,这样我就可以按0列或1列排序,然后按该顺序返回2列。。。另外,我需要能够计算X的平均值和Y的平均值,并提取值高于或低于平均值的所有质数键。在
编辑-现在可以使数组“看起来”正确
locxyarray = arcpy.da.FeatureClassToNumPyArray("Points", ['SHAPE@X', 'SHAPE@Y', 'PrimeKey'])
>>array([(506173.7478, 5455684.263900001, 1),
(506175.22869999986, 5455648.723099999, 2),
(506229.03359999973, 5455661.5572999995, 3),
(506250.25939999986, 5455614.169500001, 4),
(506305.54509999976, 5455579.122300001, 5),
(506331.70710000023, 5455688.2129, 6)],
dtype=[('SHAPE@X', '<f8'), ('SHAPE@Y', '<f8'), ('PrimeKey', '<i4')])
但我无法计算X或Y列的平均值。。。(索引器错误:索引过多)
解决方案(请参阅下面的“解决方案”中的注释,这是一个摘要):
import arcpy
import numpy as np
locxyarray = arcpy.da.FeatureClassToNumPyArray("Points", ['SHAPE@X','SHAPE@Y','PrimeKey'])
LSideLocs = np.where(locxyarray['SHAPE@X']<=np.mean(locxyarray['SHAPE@X']))
RSideLocs = np.where(locxyarray['SHAPE@X']>=np.mean(locxyarray['SHAPE@X']))
你可以用field的名字玩。在
像这样:
注意,
dtype
不能保持不变,因为现在数组元素由三个字段组成,而不是原来的两个字段。在相关问题 更多 >
编程相关推荐