Is it possible to set env.workspace = "in_memory"
in ArcPy using both ArcGIS Pro and the ArcGIS 10.2.2 (or 10.3) architectures?
What I am trying to do is get the output of a snap pour point operation written to memory as opposed to disk.
I realize I could write to disk then bring it into memory but this would not help. I am trying to optimize a series of tasks minimizing the use of writing to physical media the output of a process that is merely required as an input to the next process.
Answer
I'm going to throw an answer on here because both answers thus far aren't 100% correct.
There are 2 items which can vary from tool to tool.
- if it honors the workspace environment (this item is always documented on the tool help page)
- if it can make use of the
in_memory
workspace (this item may not be explicitly documented. You're more likely to see a note if it DOES NOT supportin_memory
)
To simply answer the "can you set the environment workspace to in_memory". The answer is YES.
>>> import arcpy
>>> arcpy.env.workspace = r"in_memory"
>>> arcpy.CopyFeatures_management(r"c:\temp\foo.shp", "myinmemoutput")
>>> arcpy.Exists("myinmemoutput")
True
Snap Pour Point does honor the workspace environment per it's documentation and explained Python samples. And a test shows you can write output to in_memory
and work with that variable reference...to put into another tool, or save the result
>>> import arcpy
>>> arcpy.env.workspace = r"in_memory"
>>> arcpy.CheckOutExtension("SPATIAL")
u'CheckedOut'
>>> snapOut = arcpy.sa.SnapPourPoint("e:/gpservices101/hydro/US30m/test.gdb/sourcepoint", "e:/gpservices101/hydro/US30m/Region08a/Input/elev_cm", 1,"PourPtID")
>>> snapOut
in_memory\SnapPou_sour1
>>> arcpy.Exists(snapOut)
True
>>> snapOut.save(r"c:\temp\todisk.tif")
>>> arcpy.Exists(r"c:\temp\todisk.tif")
True
No comments:
Post a Comment