Henry,
Would you mind posting a screenshot of your data, as well as the error? Also, are you running this in ArcMap or Pro? And are you using Model Builder for this?
I am running it in Arcmap, I'm not using the model builder. It was a toolbox that I downloaded off the internet from someone who developed the script. I can post a screenshot of the script and of the layers when the script is done running.
These are the two images that show the layers and the error messages. This failed after 4 hours and 48 minutes of running.
The python code is as follows:
arcpy.env.overwriteOutput = True
# Local variables...
inputFeatureZone = arcpy.GetParameterAsText(0)
joinField = arcpy.GetParameterAsText(1)
valueRaster = arcpy.GetParameterAsText(2)
joinedFC = arcpy.GetParameterAsText(3)
#Loop through features
inRows = arcpy.SearchCursor(inputFeatureZone)
inRow = inRows.next()
#input variables
strFID = '"FID" ='
zone = "zone"
cellAssign = "CELL_CENTER"
priority = "NONE"
newSelection = "NEW_SELECTION"
# Make a layer from the feature class
arcpy.MakeFeatureLayer_management(inputFeatureZone, zone)
while inRow:
#selct the fid to process
arcpy.SelectLayerByAttribute_management(zone, newSelection, strFID + str(inRow.FID))
#create a unique name for the zone
uniqueZone = arcpy.CreateUniqueName("zone.shp", arcpy.env.workspace)
uniqueTable = arcpy.CreateUniqueName("ZSasT", arcpy.env.workspace)
#create a temporary feature to use for zonal stats as table
arcpy.CopyFeatures_management(zone, uniqueZone)
outZSaT = ZonalStatisticsAsTable(uniqueZone, joinField, valueRaster, uniqueTable, "NODATA", "ALL")
#move to next record.
inRow = inRows.next()
#Clear the last selection.
arcpy.SelectLayerByAttribute_management(zone, "CLEAR_SELECTION")
#merge the tables so the can be joined to the zone feature class
mergedTable = arcpy.CreateUniqueName("merge.dbf", arcpy.env.workspace)
tableList = arcpy.ListTables()
fullPathTableList = []
for table in tableList:
fullPathTableList.append(arcpy.Describe(table).catalogPath)
arcpy.Merge_management(fullPathTableList, mergedTable)
#join them
arcpy.AddJoin_management(zone, joinField, mergedTable, joinField)
#save the joined data as a new feature
arcpy.CopyFeatures_management(zone, joinedFC)
# clean up old output features
arcpy.Delete_management(tempDIR + os.sep + tempWorkspace)
print "Process Complete"
#free memory
del inRow, tableList, zone
I don't know anything about python so this is completely foreign to me. If there is something wrong with the code, I wouldn't know, or know how to fix it.
Sounds like there must be an issue with the tool you downloaded. If I were
you, I would attempt to run this with the Zonal Statistics as Table tool in
ArcMap. Try following these steps:
1) Place all of your buffers in one feature class.
2) For your raster, open the attribute field and select only the
forested pixels.
3) Open the Zonal Statistics as Table tool.
4) Use your buffer for the input feature data and select your our unique
identifier field as your Zone field.
5) Under Statistics type, leave as All.
6) Run the tool.
7) Once the table gets generated, you’ll have a count of all the forested
pixels within each buffer.
😎 Add a new field titled ‘ForestedAcres’ and calculate your Count field by
0.222394 to get your total forested acres.
9) Add another field called ‘BufferAcres’ and calculate the total acres for
each buffer.
10) Add another field called ForestedPerc and use Field Calculator to
divide your ForestedAcres by your BufferAcres field to find the percentage
of forested acres. ex. ForestedAcres/BufferAcres * 100
I will try this tomorrow. I have tried zonal statistics as table before but it comes up with an incorrect count of the pixels. If it happens again I can post the attribute table here to show you what I mean. Does this work on overlapping buffer zones or no? All of my buffers are around points and each one overlaps. I thought maybe that was why zonal statistics as table did not work.
I have tried to do Zonal Statistics as Table on one of my feature classes and it does not give me the same number of outputs in the table as there are buffer zones. Additionally, the Area values for the output table are not all equal, which i assume they need to be. Is there something I am doing wrong?
Are you using your unique identifier as your Zone Field? If not, that may
be causing the issue. I wouldn't think the area values have to be equal
unless all your buffers are the same distance.
All of my buffers are the same distance, 2km. I'm using a field that assigns a unique number to each buffer, the "Name" field which contains values "FSP001" - "FSP078". Each value is unique in this field. All of the buffers overlap as well.