arcpy CalculateGeometryAttributes and AddGeometryAttributes returning OSError: "data" does not exist

989
13
07-12-2022 08:42 AM
jwhaney
New Contributor

So I've posted this in gis stackexchange because I had an easier time with their code editor. Not sure if it's against rules to post a link to that post, but I'm gonna do it anyway...

python 3 - ArcPy AddGeometryAttributes and CalculateGeometryAttributes return Traceback OSError: "da...

 

Essentially I'm having a problem as in the title here. Not sure what's going on and could use some help troubleshooting. I'll post the error below, but if you'd like to see my code please use the link above since trying to paste the code neatly here is a nightmare.

Error:

12 error --- Traceback (most recent call last):
File "c:\program files\arcgis\pro\Resources\ArcToolbox\scripts\AddGeometryAttributes.py", line 396, in <module>
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).

0 Kudos
13 Replies
DanPatterson
MVP Esteemed Contributor
0 Kudos
jwhaney
New Contributor

thanks, I did use the code editor you specify in that link, I just think that code editor stinks.

0 Kudos
DanPatterson
MVP Esteemed Contributor

Use your python IDE and copy and paste is the easiest.  It isn't really a substitute for an IDE, ... it should be called a code repository if anything


... sort of retired...
0 Kudos
by Anonymous User
Not applicable

The code editor here isn't too bad... Try using the full path to the dataset for that method:  rf'x:\..\..\..\

{blobs_exp}'

def blob_creator(self, parcels_out, blob_size, blobs_out, blobs_exp): 
    print('12 --- blob creator started') 
    try:
        # the following is run successfully
        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; this is successful
            arcpy.management.MultipartToSinglepart(blobs_out, blobs_exp) 
            # the following successfully prints out 'blobs_exp' feature count after it is created
            print('blobs_exp feature count:', arcpy.management.GetCount(blobs_exp)) 
          
            if arcpy.Exists(blobs_exp): 
                # the following is accessed after passing truthy exists 
                arcpy.management.AddField(blobs_exp, 'acreage_calc', 'DOUBLE') 
                # the following successfully accesses 'blobs_exp' via Describe 
                desc = arcpy.Describe(blobs_exp) 
                print('blobs_exp datatype:', desc.dataType) 

                # the following fails 
                arcpy.management.AddGeometryAttributes(blobs_exp, 'AREA', '', 'ACRES') 
                # the following commented out code also failed with same error 
                #arcpy.management.CalculateGeometryAttributes(blobs_exp, [["acreage_calc", "AREA_GEODESIC"]], '', area_unit="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)

    except Exception as e:
        print('12 error ---', e)

 

0 Kudos
jwhaney
New Contributor

thanks for the reply. to be clear, I did find the option to add code like you did above, but when formatting it inside the code editor, that was the pain. I got it where I wanted it and then when I submitted an error was thrown. I'll try it again, could have been user error, but not sure why there isn't just a simple markdown or other method to format. Tabs did not work at all either inside the editor. Oh well, like I said I'll try it out again, maybe I was too quick to dismiss.

0 Kudos
RhettZufelt
MVP Frequent Contributor

It looks like the Add Geometry Attributes expects a different input. (without the variable, or, variable set to string of feature class)

Does this work for you?

 

arcpy.env.workspace = r"\\path\to\FGDB.gdb"     # Set to database holding the blobs_exp feature class
arcpy.AddGeometryAttributes_management("blobs_exp",'AREA', '', 'ACRES')

 

 

R_

 

0 Kudos
RhettZufelt
MVP Frequent Contributor

But, did either of the posts get you what you needed?

also, this forum tends to throws errors when posting quite a bit, and for no reason.  When that happens, you can normally hit the preview button a time or two until the error goes away, then post.

R_

0 Kudos
jwhaney
New Contributor

I'm looking into your suggestion about how arcpy might want a string input rather than a variable for this tool, but I haven't had any resolution yet. I'm still testing. 

0 Kudos
jwhaney
New Contributor

To provides some additional info, this is where user input is provided and you can see the out_workspace variable is where I'm getting the path to the project gdb. I've tried changing this text input adding the 'r' and only having the gdb name with file ext and that's how the 11 methods before this one all worked fine, so I just don't know. Everything is run from the root directory and I haven't had any issues until now. 

 

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 = r".\\WY_testing.gdb"
    blob_size = 500
    #prep = Prep(in_state, epsg, wetlands_gdb, out_workspace)
    proc = Proc(out_workspace, blob_size)

 

 

And this is the Proc class with just the method I'm having issues with:

 

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'
        
        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')
        # below this does successfully print
        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)

 

 

0 Kudos