In memory workspace

7912
20
07-27-2020 02:53 AM
ModyBuchbinder
Esri Regular Contributor

Hello all

I could not find any class or example for in memory workspace.

From the other hand there are many arcpy examples with in memory.

So (for example) if I run a GP tool from the SDK and let arcpy create a feature class in memory how do I access it from my code after it was created.

Thanks

0 Kudos
20 Replies
MatthewDriscoll
MVP Alum

 Here is a way you can get a path in python by creating temporary files rather then in memory.  This would be only part of the puzzle, but perhaps this will help you figure out how to achieve what you want.   

10.6. tempfile — Generate temporary files and directories — Python 2.7.18 documentation 

Here is an example on how I have used it to create and open an exported pdf.

# create temporary pdf name variable
tmpdir = tempfile.mkdtemp()
pfilename = tempfile.NamedTemporaryFile(prefix="Property_Map_")
pdfname = pfilename.name + ".pdf"
# Location of the tempoary pdf file
outputpdf = os.path.join(tmpdir, pdfname)

# export layout to a pdf
layout.exportToPDF(outputpdf)

# Open the excel file
Popen("start acrobat %s" % (outputpdf), shell=True)
0 Kudos
ModyBuchbinder
Esri Regular Contributor

There is no problem to create FGDB on disk and access it from the SDK

We would like to use in memory workspace to get better performance for temporary layers.

0 Kudos
NobbirAhmed
Esri Regular Contributor

Instead of the full path to GDB (such as: "C:\myfolder\mygdb.gdb") just use "in_memory" or just "memory". Here is an example:

Syntax in Python:

outfc = r"in_memory\\out_fc" 

Syntax in C# will be:

var outfc = "in_memory\\out_fc" 

Alternatively, you can just use "memory\mydata".

We will add a snippet and sample to Geoprocessing SDK section: GitHub - Esri/arcgis-pro-sdk: ArcGIS Pro SDK for Microsoft .NET is the new .NET SDK for the ArcGIS P... 

This is a new Pro format built and supported in ArcGIS Pro 2.x:
Note: Unlike the memory workspace, in_memory workspace does not support subtypes or domains.
SarahHartholt
Occasional Contributor III

Hi there,

I'm using ArcPro 2.9.0 and am trying to use the "memory\mydata" format to join 2 layers in ModelBuilder. The documentation clearly states that I should not add a file extension. However, when I enter "memory\JoinParcelstoTable" to the Output Dataset box and click away ".shp" is automatically added to the end of my in memory folder path. When I try to run my model it fails on this tool. Any insights would be appreciated.

SarahHartholt_3-1645117835957.png

 

SarahHartholt_2-1645117653353.png

 

 

0 Kudos
ModyBuchbinder
Esri Regular Contributor

Hi Nobbir

Thanks for the great answer.

I understand that if we work in Pro (2.4) we should use memory/out_fc in Python and var outfc = "memory\\out_fc" in the SDK to get the best option.

Thanks

0 Kudos
ModyBuchbinder
Esri Regular Contributor

Hi Nabbir

Just tested it.

Creating a feature class in memory with the GP command works.

The line:

new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"memory")))
fail with wrong Uri.
What are we missing?

Thanks
0 Kudos
NobbirAhmed
Esri Regular Contributor

See the help text, it requires a valid path to a file geodatabase folder that ends with .gdb extension:

ModyBuchbinder
Esri Regular Contributor

So we return to the original question. How do I create a in memory feature class and use it in the SDK??

This is basic functionality in ArcObjects.

0 Kudos
NobbirAhmed
Esri Regular Contributor

I have communicated with our Geodatabase team - they are following this thread. As of now, there is no API yet. 

As of now, for Geoprocessing functionalities, we have "in_memory" and "memory" workspace - what it does is, the string is read as is but then internally interpret and convert it to a geodatabase which lives in memory.