Hello everyone,
First of all, thanks for any input you can provide.
I'm very, very new to Python and I have a two-part challenge. I have to clip residential parcels from a raster, save those parcels under their APN number, then buffer the structure on each parcel.
Decided to do the clipping first and put a Python code together. Although the .tif files populate in my gdb folder, I can't open them. Could those files be corrupted? They range between 1 and 2 MB, but I can't seem to open them in any software.
I've also been unsuccessful at running the same script while using jpeg instead of tif.
Here's the code:
import arcpy
# Set environment settings
arcpy.env.workspace = r"C:\Users\Projects\FINALPython"
arcpy.env.overwriteOutput = True
# Define paths to feature classes and raster layer
parcels_fc = "Parcels_Clip"
raster_layer = "RGB_FBRanch 9.6.23.tif"
# Get APN field name
apn_field = arcpy.ListFields(parcels_fc, "APN")[0].name
# Create a search cursor to iterate through parcels and clip the raster layer
with arcpy.da.SearchCursor(parcels_fc, ["SHAPE@", apn_field]) as cursor:
for row in cursor:
# Define output path for clipped raster
apn_number = row[1]
clipped_output = arcpy.CreateUniqueName("clipped_{}.tif".format(apn_number))
# Clip raster layer using individual parcel
arcpy.management.Clip(raster_layer, "#", clipped_output, row[0], "", "ClippingGeometry")
Thanks so much for your input..