I have written code that selects rows of a buffer shapefile based on that file's intersection with a polygon that represents the extent of a raster. In the photo below, the code selects all of the red dots for this given polygon.
Using a cursor, I am going through those selected buffers and clipping an associated raster by each buffer. The code below was working when I wrote it three months ago; however, since updating, I am having a problem grabbing the SHAPE@ token as a polygon to clip the raster. I would have been using ArcGIS Pro 2.8.3 when I wrote and ran the code successfully, and I have Version 2.9.1 now.
I believe I've isolated the problem to the
row command. Previously, I'm under the impression that I was grabbing a polygon object. Now, however, my output for the lines,
print(' row: ', row) print(' row: ', row)
row as two different outputs, a Polygon object that I want and the geoprocessing geometry object that it now gives me:
row: ['LCRas_0', <Polygon object at 0x1f56ab62108[0x1f56db53300]>] row: <geoprocessing describe geometry object object at 0x000001F56DB53300>
The clip code that once worked is now giving me a blank output. I've also tried Extract by Mask, but receive an ERROR 999999 when I try to specify that the output extent should be that of the buffer.
Could this be a bug in the versions, or am I missing something simple?
arcpy.env.addOutputsToMap = False fields = ['RasterName', 'SHAPE@'] j=0 #code was made pieacemeal to work on 3 comps; number changes depending where in the shapefile you're at buff_file = r"I:\test\test_buffs.shp" for poly in listp: #record lc file that corresponds lc_file = poly[:-9].replace(" ", "") path = r"I:\test\Classified" cor_rast = os.path.join(path, str(lc_file+"_classified.tif")) raster_xmin = arcpy.GetRasterProperties_management(cor_rast, "LEFT") raster_xmax = arcpy.GetRasterProperties_management(cor_rast, "RIGHT") raster_ymin = arcpy.GetRasterProperties_management(cor_rast, "BOTTOM") raster_ymax = arcpy.GetRasterProperties_management(cor_rast, "TOP") extent = raster_xmin + " " + raster_ymin + " " + raster_xmax + " " + raster_ymax print('Starting arcpy.da.UpdateCursor') with arcpy.da.UpdateCursor(arcpy.management.SelectLayerByLocation(buff_file, "INTERSECT", poly),fields) as cursor: #select by polygon for row in cursor: rname = str("LCRas_" + str(j)) #make raster name path = r"I:\test\Rasters" #set path where raster output will happen rpath = os.path.join(path, str(rname+".tif")) #create name of raster file print(' Starting arcpy.Clip_management for ', rpath) print(' cor_rast: ', cor_rast) print(' raster_xmin: ', raster_xmin) print(' raster_xmax: ', raster_xmax) print(' raster_ymin: ', raster_ymin) print(' raster_ymax: ', raster_ymax) print(' extent: ', extent) print(' row: ', row) print(' row: ', row) arcpy.Clip_management(cor_rast, extent, rpath, row, "0", "ClippingGeometry", 'MAINTAIN_EXTENT') #extract raster from land cover print(' Ended arcpy.Clip_management for ', rpath) row = rname #set row to equal raster name cursor.updateRow(row) #updates row to have raster column j=j+1 print('Ended arcpy.da.UpdateCursor')```