Zonal Statistics for Overlapping Zones Consistent failure

983
8
09-18-2019 11:34 AM
HenrySymanski
New Contributor
I am trying to run Zonal Statistics for Overlapping Zones on some Buffer feature classes that overlap, and I'm trying to calculate % forest cover under each buffer zone. I have a reclassed basemap that is either forest or non-forest as 1 and 0 values in a raster. I downloaded and ran the script and it succeeded in calculating the zonal statistics for my first feature class and it took about 12 minutes. Since then, I have not gotten it to succeed, and it has taken over 2 hours to complete, and fails every time with Error 001156: cannot write OID FSP001 to table (FSP001 being the name of one of my buffers). It always has this error regardless of which feature class I input into the script. The raster is just a reclassed basemap. I would like to avoid doing each zone individually as there are over 500 of them. I've run this script about 10 times, and every time it has the same error, except for the first time when it succeeded, despite there being no discernible difference between the first feature class and the second one. I am not sure what I am doing wrong and it is highly discouraging. The script (I think) uses an iterator to return geometric data, but it takes a very long time and continues to fail. 
0 Kudos
8 Replies
ClaytonCooley1
New Contributor II

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?

0 Kudos
HenrySymanski
New Contributor

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. 

0 Kudos
HenrySymanski
New Contributor

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. 

0 Kudos
ClaytonCooley
New Contributor

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

0 Kudos
HenrySymanski
New Contributor

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.

0 Kudos
HenrySymanski
New Contributor

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?

0 Kudos
ClaytonCooley
New Contributor

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.

0 Kudos
HenrySymanski
New Contributor

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.

0 Kudos