Select to view content in your preferred language

Erase tool in python fails when using a feature layer variable for an input

628
3
06-16-2023 09:07 AM
TonyContreras_Frisco_TX
Frequent Contributor

Hello, I am wondering if this is a bug or my understanding of how this tool works is incorrect. I am running the code below in the python window of ArcGIS Pro 3.1.0

 

gdbBuilding = r"C:\data\city.sde\buildings"
buildingLayer = "buildingLyr"
erase_features = r"C:\data\city.sde\feature_buffer200ft"
temp = arcpy.env.scratchGDB + "\\temp"

arcpy.management.MakeFeatureLayer(gdbBuilding, buildingLayer, "VERIFIED = 1", "")
arcpy.analysis.Erase(buildingLayer, erase_features, temp)

 

I receive the following error:

arcgisscripting.ExecuteError: ERROR 160333: The table was not found.
Failed to execute (Erase).

If I type in the code to run the erase tool, when I get to the part for the first input, the intellisense/autocomplete presents an option for the name of the new Layer that was created. If I select it and use the other parameters the same as before, it runs without issue.

If I provide a string with the same value as the feature layer name variable, it works to my surprise. Variables that point directly to a feature class also work fine.

I tested with the Buffer tool and it worked when using the feature layer name variable as an input.

Cany anyone reproduce this behavior? Should what I'm trying work?

0 Kudos
3 Replies
TonyContreras_Frisco_TX
Frequent Contributor

I changed the feature class to reference a different connection file (the first was a db user with read access to the database, the new connection uses Windows authentication and the user has read/write access) and that allowed things to work. I am not sure why one worked and another failed.

0 Kudos
Luke_Pinner
MVP Regular Contributor

Unrelated to your issue, but this line is not correct

temp = arcpy.env.scratchGDB + "\\temp"

From the Scratch GDB documentation:

The Scratch GDB environment is read-only; you cannot set the location directly.

Instead use Scratch Workspace

temp = arcpy.env.scratchWorkspace + "\\temp"

 

0 Kudos
TonyContreras_Frisco_TX
Frequent Contributor

I am not setting the location of the scratchGDB, rather I am setting a variable to a path that contains the scratchGDB location. The code below would be incorrect:

arcpy.env.scratchGDB = "C:\\Temp"
0 Kudos