I work with zoning info and have a series of census blocks that are overlapped by a larger zone. I used the identity tool to split the census blocks so that where they overlap they are separated, which increased my zones from about 8,000 to 15,000. In order to have a number of other statistics calculated I need to calculate the percent of area that each split zone is of the whole area (poor wording - i.e. my first zone was 100 acres, split into 3 that are 25, 25, and 50, so the zones are 25%, 25% and 50% of the original acreage).
I'm pretty new to ArcPy and used the following code but keep getting an error message when trying to run my code. It says my error is on line 2850 but I only have 21 lines of code.
"RuntimeError Traceback (most recent call last)
In [12]:
Line 21: row.setValue(percent, row.getValue(originalblockarea)/(blockarea))
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\arcobjects.py, in getValue:
Line 2580: return convertArcObjectToPythonObject(self._arc_object.GetValue(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds."
My code is as follows:
censusblocks = r'C:\Users\c.....'
evaczone = r'C:\Users\c.....'
originalblocks = r'C:\Users\.....Blocks_ExportFeatures'
with arcpy.da.SearchCursor(censusblocks, ["SHAPE@", "GEOID", "Shape_Area", "Percentage_OG"]) as blockcursor:
blockshape = [0]
blockid = [1]
blockarea = [2]
percent = [3]
with arcpy.da.SearchCursor(originalblocks, ["SHAPE@", "GEOID", "Shape_Area"]) as originalcursor:
originalblockid = [1]
originalblockarea = [2]
cursor = arcpy.UpdateCursor(censusblocks)
for row in cursor:
if blockid == originalblockid:
idmatch = True
row.setValue(percent, row.getValue(originalblockarea)/(blockarea))
I'm trying to divide the original acreage (originalblockarea) by the new area (blockarea) and then update the field "Percentage_OG" with the value. I was not taught ArcPy and have been trying to learn it myself so please let me know if there's an issue with my code too.
forloop inside the two DA cursors 2) You are not assigning row contents, but one element constant arrays to variables. There are code samples to teach you how to use cursors in the documentation. And lots of code examples here on proper use of dictionaries.