Good day everyone,
I am trying to find solution to a particular problem with reading raster values. I have a point feature class in local coordinate system (3057) and I also have a raster in .gtx format that is in WGS 1984 (in Spatial Reference tab in "Properties -> Raster Information"). I need to extract a raster value based on the location of a point feature using arcpy. From the search on the web, I ended up using RasterToNumPyArray() to convert the raster and then read the value from it based on a point location. However, for some reason the coordinate of the point does not align to the same location in the raster and usually returns the raster value of None. I think the problem that I am facing has something to do with projecting the data because for some reason the script stops when comes to arcpy.projectAs(). I appreciate if someone knows how to tackle this issue.
My code includes the following:
point = ['SHAPE@'] that I am reading with UpdateCursor()
raster_desc = arcpy.Describe(gtx_raster)
raster_sr = raster_desc.spatialReference
point_x_local = point.centroid.X
point_y_local = point.centroid.Y
point_centroid = arcpy.Point(point_x_local, point_y_local)
point_projected = point_centroid.projectAs(raster_sr)
raster_array = arcpy.RasterToNumPyArray(gtx_raster, (point_projected.X, point_projected.Y),1, 1, nodata_to_value=None)
raster_value = float(raster_array[0, 0])