Преобразовать местоположение точки на растровом слое в местоположение точки в массиве NumPy
Я впервые использую класс MCP пакета scikit-image, чтобы найти путь минимальной стоимости между двумя точками растрового растра из ArcGIS, преобразованного в массив NumPy с помощью инструмента RasterToNumPyArray. Однако частью атрибутов класса MCP, необходимых для этого, являются начальный и конечный индексы.
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. Кто-нибудь знает возможно ли это?
1 ответ
Хорошо, вот единственное решение, которое я мог бы решить сам:
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. Если в вашем анализе важна направленность начальной и конечной точек, вам придется настроить это, чтобы иметь возможность идентифицировать их в массиве, но это не будет слишком сложно.