Working with in_memory?

857
2
Jump to solution
06-03-2012 11:35 PM
BartłomiejStaroń
New Contributor III
How to "move" shapefile() to in_memory workspace?

I try copy, but is not supported.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MarcinGasior
Regular Contributor
The following code works for me:
import arcpy, os         inSHP = r"C:\tmp\myShapefile.shp"         #shapefile name         featName = os.path.basename(inSHP)         #build path to in_memory feature clas         inMemoryFC = os.path.join("in_memory",featName[:-4])          arcpy.CopyFeatures_management(inSHP, inMemoryFC)          #OPTIONAL - check         featCount = int(arcpy.GetCount_management(inMemoryFC).getOutput(0))         print featCount

View solution in original post

2 Replies
MarcinGasior
Regular Contributor
The following code works for me:
import arcpy, os         inSHP = r"C:\tmp\myShapefile.shp"         #shapefile name         featName = os.path.basename(inSHP)         #build path to in_memory feature clas         inMemoryFC = os.path.join("in_memory",featName[:-4])          arcpy.CopyFeatures_management(inSHP, inMemoryFC)          #OPTIONAL - check         featCount = int(arcpy.GetCount_management(inMemoryFC).getOutput(0))         print featCount
AndresCastillo
MVP Regular Contributor

Some more notes on in_memory:

The in_memory workspace is only valid for geoprocessing tools; it is not a general-purpose virtual directory when you can write any data.

Clean up after using "in_memory" using Delete_management

For example,

 

Projects = os.path.join("in_memory","Projects")
arcpy.MakeFeatureLayer_management(<pathToFC>,"Proj_lyr")
arcpy.CopyFeatures_management("Proj_lyr",Projects)
arcpy.Delete_management("Proj_lyr")
print("Projects Copied")

 

 

https://pro.arcgis.com/en/pro-app/latest/tool-reference/appendices/using-the-in-memory-output-workspace.htm 

https://pro.arcgis.com/en/pro-app/latest/help/analysis/geoprocessing/basics/the-in-memory-workspace.htm 

https://desktop.arcgis.com/en/arcmap/10.3/analyze/modelbuilder/the-in-memory-workspace.htm 

https://gis.stackexchange.com/questions/35468/what-is-the-proper-syntax-and-usage-for-arcgis-in-memory-workspace 

https://community.esri.com/t5/arcgis-pro-sdk-questions/in-memory-workspace/m-p/787036 

0 Kudos