I'm creating a raster grid in ArcPy and would like to iterate over it and get each cell's center. The raster grid is in UTM but I'm issuing the coordinates in as GCS WGS 1984 XY. Here's what I'm doing:
import arcpy import os wgs84 = arcpy.SpatialReference(4326) utm = arcpy.SpatialReference(32617) lower_left = arcpy.PointGeometry(arcpy.Point(X=82.4819495, Y=34.2706214), spatial_reference=wgs84).projectAs(utm) upper_right = arcpy.PointGeometry(arcpy.Point(X=82.0848611, Y=34.5154197), spatial_reference=wgs84).projectAs(utm) grid_extent = arcpy.Extent( lower_left.X, lower_left.Y, upper_right.X, upper_right.Y, 0, 0, 0, 0, utm ) cell_size = 25 pixeltype = "F32" # make the rasterinfo object ras_info = arcpy.RasterInfo() ras_info.setSpatialExtent(utm) ras_info.setExtent(grid_extent) ras_info.setCellSize((cell_size, cell_size)) ras_info.setPixelType(pixeltype) # make the raster object ras = arcpy.Raster(ras_info) # Now convert it to points to get all the cell centers ras_cell_centers = arcpy.RasterToPoint_conversion(ras, os.path.join(r"in_memory", "rcc"))
But, when I do
with arcpy.da.SearchCursor(ras_cell_centers, ["SHAPE@XY"]) as cursor: for row in cursor: print(row)
it gives me no point objects (but no errors either).
Where am I going wrong? I would like any solutions that are not IO bound and allows me to do this in memory. I checked out the Raster Cell Iterator and can use it, but it only gives me column-row not the cell's center projected coordinates.