My attempt is to view raster values in the command window. The follwing code is thought to do this by converting the raster to a point feature file and by successively scanning the values at the points:
import arcpy, os
arcpy.env.workspace = os.path.join('H:\\','myexample')
arcpy.env.outputZFlag = 'Enabled'
arcpy.conversion.RasterToPoint('myraster','mypointfeaturefile.shp')
with arcpy.da.SearchCursor('mypointfeaturefile.shp', 'SHAPE@XYZ') as cursor:
for row in cursor:
print(u'{0}, {1}, {2}'.format(row[0], row[1], row[2]))
The arcpy.conversion.RasterToPoint
process works fine: a raster value can be retrieved from mypointfeaturefile.shp
in ArcGIS Pro by activating Explore
and clicking onto a point of mypointfeaturefile.shp
. Therefore, the points in mypointfeaturefile.shp
seem to hold raster values as Z-values. However, the 6th line for row in cursor
returns the error message:
RuntimeError: Cannot find field 'SHAPE@XYZ'. Input feature class is not M- or Z-enabled.
I was following the SearchCursor documentation together with Barbarossa's case and assumed that the point feature file would be Z-enabled by the 3rd line
arcpy.env.outputZFlag = 'Enabled'
However, this does not seem to be the case. What am I missing in this process to make mypointfeaturefile.shp
Z-enabled?
System:
- OS: Windows 11 Pro, 21H2
- arcpy: version 3.11.1