Select to view content in your preferred language

existence of data in memory and in_memory workspaces

1754
5
Jump to solution
01-13-2023 01:22 PM
DavidAnderson_1701
Frequent Contributor

Working with ArcGIS Pro 2.9.5, ArcGIS API for Python 1.9.1,Python 3.7.11

A Python script is having some problems with the memory data space that have just cropped up.

This code was working in previous versions of Pro in a loop where the in memory veg layer is being redefined.

 

 

veg_layer = r"memory\veg"

if arcpy.Exists(veg_layer):
    arcpy.management.Delete(veg_layer)
arcpy.management.MakeFeatureLayer(inrev_data_by_model_area[ma],veg_layer)

 

 

 

Now the script is failing with error:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000725: Output Layer: Dataset memory/veg_layer already exists.
Failed to execute (MakeFeatureLayer).

 

After running the code above the first time, the Exists command returns false and the Delete command fails with this message

Messages

 
Start Time: Friday, January 13, 2023 1:57:29 PM
WARNING 000110: in_memory/eru_2 does not exist
Succeeded at Friday, January 13, 2023 1:57:29 PM (Elapsed Time: 0.01 seconds)
 

yet rerunning the makefeaturelayer fails.

Somehow the data is both in and not in the memory dataspace.  Same results using the in_memory dataspace.

 

 

 

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

memory workspace and arcpy.Exists... Two of life's greatest mysteries.

If you take it out of your conditional, you will probably see it equate to False when checking if the dataset exists in memory- which is causing the 'exists' error message because its not getting deleted.

If you add a \ to the start of the variable memory\veg_lyr, you will see it equate to True, and execute the deletion.

Screenshot 2023-01-13 152135.png

veg_layer = r"\memory\veg"

fc = r'c:\ArcGIS\Local.gdb\address'
veg_layer1 = arcpy.MakeFeatureLayer_management(fc, r"\memory\veg")

val = arcpy.Exists(veg_layer)
val1 = arcpy.Exists(veg_layer1)

View solution in original post

5 Replies
DavidSolari
Frequent Contributor

I have a feeling that conflating a layer with its underlying data is causing issues here. You're attempting to wipe data with the path "memory/veg_layer" and then creating a feature layer from another data source with the layer name "memory/veg_layer". It looks like you already have the data in your "inrev_data_by_model_area[ma]" object so if you should probably create the feature layer outside the loop and reuse it each go around. Or create a new feature layer each loop with a different name, something like:

for i, thing in enumerate(things):
    lyr = arcpy.management.MakeFeaturelayer(inrev_data_by_model_area[ma], f"layer_{i}")[0]
    # Do stuff with lyr???

Lastly, check your environment settings. If overwriting data is disabled it can lad to issues like this. A common pattern is to store the value of arcpy.env.overwriteOutput, set it to true, run the code that overwrites data, then set the env variable back to the previous state to avoid overwriting the user's preferences unnecessarily.

DavidAnderson_GISS
Occasional Contributor

Kludging up a solution by setting the overwriteOutput seems to be working.

Clearing up the assumptions: inrev_data_by_model_area[ma] variable is a dictionary with the string values for paths to a set of feature classes, indexed by a names which are stored in a list,  where  ma is the index for a list variable loop.

David Anderson
david.anderson@usda.gov
0 Kudos
DavidSolari
Frequent Contributor

Ah that makes more sense. In that case you can probably just make the "ma" variable the name of each new feature layer, that way you can change selection sets and such without clobbering the other layers.

0 Kudos
by Anonymous User
Not applicable

memory workspace and arcpy.Exists... Two of life's greatest mysteries.

If you take it out of your conditional, you will probably see it equate to False when checking if the dataset exists in memory- which is causing the 'exists' error message because its not getting deleted.

If you add a \ to the start of the variable memory\veg_lyr, you will see it equate to True, and execute the deletion.

Screenshot 2023-01-13 152135.png

veg_layer = r"\memory\veg"

fc = r'c:\ArcGIS\Local.gdb\address'
veg_layer1 = arcpy.MakeFeatureLayer_management(fc, r"\memory\veg")

val = arcpy.Exists(veg_layer)
val1 = arcpy.Exists(veg_layer1)
DavidAnderson_1701
Frequent Contributor

Thanks.  I just tested this out.  Works fine.  I could tell the path was the problem.  Tried the \\ and / solutions.  Did not think of a preceding path separator,  I'll note that none of the ESRI documentation I could find about the memory or in_memory data space use the leading \ in the path names.