我第一次使用scikit-image软件包的MCP类来查找使用RasterToNumPyArray从ArcGIS转换为NumPy数组的成本栅格上两点之间的最小成本路径工具。但是,为此所需的部分MCP类属性是开始和结束索引 我不知道如何获取一组点(具有lat,long坐标的ArcGIS shapefile)并将其转换为从具有空间数据的栅格生成的NumPy阵列上的位置索引。我知道我可以将栅格单元格OID分配给ArcGIS中的点,但我不确定它是如何转移到NumPy数组上的索引的。有谁知道这是否可行?
答案 0 :(得分:0)
好的,这是我能解决的唯一解决方案:
import arcpy
from arcpy.sa import *
import numpy as np
arcpy.CheckOutExtension("Spatial")
arcpy.env.extent = "MAXOF" # this ensures the extents of all my rasters will be the same, VERY IMPORTANT
extract = ExtractByMask("cost.img", "points.shp") # this step creates a raster that only has two value cells (where my points are) but the extent is that of my cost raster and the rest of the cells are NoData
extract = Con(extract>0,500,0) # changes the value of those two points to 500, a value much higher than the other cells, choose whatever value (positive or negative) that you know won't be in your cost raster
cost = arcpy.RasterToNumPyArray("cost.img")
calc = arcpy.RasterToNumPyArray(extract)
points = np.where(calc==500) #This produces the indices of all the entries in the array that are 500. However, the output is not in (12, 8), (17, 4) format, it looks like: (array([12, 17]), array([8, 4])) so must create the point indices with the next two lines
start = points[0][0], points[1][0]
end = points[0][1], points[1][1]
现在我有mcp进程的开始和结束索引。如果起点和终点的方向性在分析中很重要,那么你必须调整它以便能够在数组中识别它们,但这并不会太困难。