0

我第一次使用 scikit-image 包的MCP类来查找成本栅格上两点之间的最小成本路径,该成本栅格使用RasterToNumPyArray工具从 ArcGIS 转换为 NumPy 数组。但是,为此必需的部分 MCP 类属性是开始和结束索引。
我不知道如何获取一组点(具有经纬度坐标的 ArcGIS shapefile)并将其转换为从具有空间数据的栅格生成的 NumPy 数组上的位置索引。我知道我可以将栅格单元 OID 分配给 ArcGIS 中的点,但我不确定如何将其转移到 NumPy 数组上的索引。有谁知道这是否可能?

4

1 回答 1

0

Alright, here is the only solution I could sort out myself:

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]

Now I have the start and end indices for my mcp process. If the directionality of the start and end points is important in your analysis, then you will have to tweak this to be able to identify them in the array, but it wouldn't be too difficult.

于 2013-08-22T22:36:37.683 回答