0

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).

5
  • 1
    The error may not be in this code. How are you invoking the function? Did you escape the backslash or use raw formatting?
    – Vince
    Commented Jul 12, 2022 at 16:05
  • I've isolated the error to this code. It seems it might be an arcpy parameter problem, the in_features (first param) of the tool 'AddGeometryAttributes' does not like that I used a variable as input. It might want a string version of that variable. I'm doing some testing to see if this is the issue. I'll post back here if it is. Thanks for your comment. Commented Jul 12, 2022 at 17:10
  • If it's giving an OS error on a "file" containing '.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 an arcpy.Exists before calling the function).
    – Vince
    Commented Jul 12, 2022 at 17:26
  • so my main.py receives user input for gdb and everything is run from the root project directory, so relative paths. at the time of writing this my string for gdb input was just "WY_testing.gdb" as out_worksapce variable fed to the Proc class. I'm not sure I can edit this post or I would include the other part of the code to show you. If I add a gdb "Exists" check before I run this code above, the check comes back truthy. Commented Jul 12, 2022 at 18:19
  • oh i see edit now. I'll add some info. Commented Jul 12, 2022 at 18:22

1 Answer 1

1

It appears the path's you are creating and passing into the tools are half relative paths, half full paths, as such I think the tool is blowing up while trying to rectify the path to the dataset.

Your error traceback looks like:

OSError: "WY_testing.gdb\blobs_exp" does not exist

This is a strange half-relative, half-full path. Generally when using a relative path, you'd only use the featureclass name, like blobs_exp, and your workspace would be set to the full path of your GDB, something like c:\mydata\WY_testing.gdb. I can't tell what your work variable is pointing at based on your code. The even stranger thing is it blows up in the AddGeometry tool, making it sound like the tools before it are able to rectify the path. However, those tools before the AddGeometry are system tools and might be able to handle the path better than AddGeometry which is a system-script tool (but this is just a guess).

I'd suggest going back and re-working your code and your paths. Either be 100% relative, or 100% fully qualified. Personally, I prefer fully qualified as there leaves no guessing which path is being passed in. Build up a path like:

import os
workspace = "c:/mydata/WY_testing.gdb"
fc = "blobexp"
fullyQualifiedFC = os.path.join(workspace, fc)
arcpy.MyToolDoesSomething(fullyQualifiedFC)

I'll also mention (and it shouldn't have any baring on your question at hand), the AddGeometryTool appears to be deprecated in favor of the CalculateGeometryTool in Pro 3.0. (deprecated tools will continue to work, but will not be updated/fix moving forward) Something to keep in mind if you update.

2
  • hi, thanks for your response. some quick background, the scripts and project/working geodatabase are all in the same directory (except for the one wetlands_gdb input in main.py), so that being said they should all be relative paths, or that was the intent atleast. This is the 12th step in multiple step processing and I haven't had any issues until this. I have tried to use the 'CalculateGeometryAttributes' instead of 'AddGeometryAttributes' and I get the same error. Im pretty stumped on this one but I do think you are right that it has something to do with the path. Commented Jul 15, 2022 at 17:59
  • ok after testing the full path to the gdb and fc, the CalculateGeometryAttributes arcpy method seems to work. kind of annoying that relative paths can't be used or don't seem to work, but I think I can move past this issue now. thank you again for responding and for your recommended solutions and info. Commented Jul 15, 2022 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.