I've been banging my head on this one for a day or so and not sure what it is. I'm writing a couple classes with a variety of methods to process some data. I'm at a stage where I want to calculate the geometry of that polygon layer in a field in acres units. I've discovered what looks like two arcpy options that should be able to do this, the CalculateGeometryAttributes and AddGeometryAttributes functions/methods. I've attempted running both of them and get the same result, a traceback OSError that claims the featureclass does not exist (see below). I have verified the script has access to this featureclass by running other methods against it like creating a field list and printing out all the field names, etc. So this error is kind of stumping me and it seems to be related to only these arcpy functions. I've included the error and a small snippet of code below. This seems like something small that I could be missing, but I just can't seem to figure it out so I could use the help.
main.py
from prepare import Prep
from process import Proc
if __name__ == "__main__":
# Input the abbreviation for the state you want to process.
in_state = "WY"
# This epsg code is meant to be the best projection for the entire state, usually a UTM zone or a custom state projection.
# If you aren't sure which epsg code to use, stick with NAD83 GCS ('4269') or you can try leaving a blank string ''.
epsg = "4269"
# The wetlands_gdb path below may need to be altered if the shared drive file structure changes.
wetlands_gdb = "..\\..\\..\\DATA\\USFWS\\National_Wetlands_Inventory\\20220524_By_State\\{}_geodatabase_wetlands\\{}_geodatabase_wetlands.gdb".format(in_state, in_state)
# Your local project file geodatabase. Include '.gdb' in string.
out_workspace = "WY_testing.gdb"
blob_size = 500
#prep = Prep(in_state, epsg, wetlands_gdb, out_workspace)
proc = Proc(out_workspace, blob_size)
process.py
import os, sys
import arcpy
class Proc():
def __init__(self, out_workspace, blob_size):
self.work = out_workspace
self.blob_size = blob_size
arcpy.env.workspace = self.work
self.fc_list = arcpy.ListFeatureClasses()
self.parcels = [f for f in self.fc_list if 'parcels_over20' in f][0]
self.subs = [f for f in self.fc_list if 'subs_inservice' in f][0]
self.boundary = [f for f in self.fc_list if 'boundary' in f][0]
self.wetlands = [f for f in self.fc_list if 'Wetlands' in f][0]
self.nlcd_vector = [f for f in self.fc_list if 'nlcd_vector' in f][0]
self.subs_buff_out = '{}\\subs_buff_poly'.format(self.work)
self.parcels_buff_out = '{}\\parcels_over20_buffselect'.format(self.work)
self.blobs_out = 'blobs'
self.blobs_exp = 'blobs_exp'
# call first method
self.blob_creator(
self.work, self.parcels_buff_out, self.blob_size, self.blobs_out, self.blobs_exp
)
# 12 --- create blobs with acreage_calc and removes any less than 'blob_size'
def blob_creator(self, work, parcels_out, blob_size, blobs_out, blobs_exp):
print('12 --- blob creator started')
if arcpy.Exists(work):
print('gdb does exist!')
try:
arcpy.env.workspace = work
arcpy.analysis.Buffer(parcels_out, blobs_out, '25 Feet', 'FULL', 'ROUND', 'ALL')
if arcpy.Exists(blobs_out):
# run multipart to singlpart to separate unique blobs
arcpy.management.MultipartToSinglepart(blobs_out, blobs_exp)
print('blobs_exp feature count:', arcpy.management.GetCount(blobs_exp))
if arcpy.Exists(blobs_exp):
arcpy.management.Delete(blobs_out)
arcpy.management.AddField(blobs_exp, 'acreage_calc', 'DOUBLE')
desc = arcpy.Describe(blobs_exp)
print('blobs_exp datatype:', desc.dataType)
arcpy.management.AddGeometryAttributes("{}".format(blobs_exp), 'AREA_GEODESIC', '', 'ACRES')
else:
sys.exit('12 --- could not find exploded blobs')
else:
sys.exit('12 --- could not find blobs poly')
except Exception as e:
print('12 error ---', e)
Error received:
12 error --- Traceback (most recent call last): File "c:\program files\arcgis\pro\Resources\ArcToolbox\scripts\AddGeometryAttributes.py", line 396, in addGeomAtts = AddGeometryAttributes(fc, geomProperties, lUnit, aUnit, cs) File "c:\program files\arcgis\pro\Resources\ArcToolbox\scripts\AddGeometryAttributes.py", line 30, in init desc = arcpy.Describe(fc) File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy_init_.py", line 1287, in Describe return gp.describe(value, data_type) File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing_base.py", line 384, in describe self._gp.Describe(*gp_fixargs(args, True))) OSError: "WY_testing.gdb\blobs_exp" does not exist
Failed to execute (AddGeometryAttributes).
.gdb
', then the geodatabase is not being seen as a folder, and the file (aka table) in the geodatabase is not being searched for in the geodatabase catalog. That means the declaration is outside this function (which you could prove by doing anarcpy.Exists
before calling the function).