문제

I am using, for the first time, the scikit-image package's MCP class to find the minimum cost path between two points over a cost Raster from ArcGIS converted to a NumPy array using the RasterToNumPyArray tool. However, part of the MCP class attributes necessary for this are the start and end indices.
I do not know how to take a set of points (ArcGIS shapefile that has the lat,long coordinates) and convert that to the location index on a NumPy array generated from a raster with spatial data. I know I can assign the raster-cell OID to the point in ArcGIS, but I am not sure how that can transfer over to the index on the NumPy array. Does anyone know if this is possible?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top