Select to view content in your preferred language

Allow ArcPy replaceDataSource of layer to use dataset stored in_memory

1485
4
02-25-2012 08:07 PM
Status: Open
Labels (1)
GraemeBrowning
Frequent Contributor

I use in_memory workspaces to speed up some Python script tools that get published as Geoprocessing Services significantly.

The tools open MXDs and perform, among other things, an ExportToPDF.

In the MXD there is a layer that references a dataset stored on disk.

At runtime a new dataset gets created with the same schema as that above, so that it can replace it as the data source but, given a choice, I would like that new dataset to ONLY be written to the in_memory workspace.

My testing suggests that using in_memory workspaces like this is not supported by either Layer.replaceDataSource or Layer.findAndReplaceWorkspacePath.

There appears to be no ArcPy way to replace the data source of a layer with a feature class stored in the in_memory workspace so that it can be displayed in a map that gets exported to PDF before the in_memory workspace is deleted.

It looks like this would possible using ArcObjects and an InMemoryWorkspaceFactory but I need an ArcPy solution.

If there is no way to do this using ArcPy at ArcGIS 10.0 (and nothing coming at 10.1) then what I will do is to propose as an ArcGIS Idea that Layer.replaceDataSource be enhanced to support a workspace_type=INMEMORY_WORKSPACE option.

I have also posted this to the ArcGIS Discussion Forums and at Stack Exchange GIS but have had no replies there so far.

4 Comments
GraemeBrowning
This, or something very similar, has just come up as a requirement for someone else at http://gis.stackexchange.com/questions/60326/trying-to-use-arcpy-to-copy-a-feature-layer-from-the-to...
CaseyBentz
I have this same requirement. I am looking at this as a better option than deleting the features from a file geodatabase FC and appending the new features because we keep corrupting the geodatabase with all the editing...
MikePetermn
Same issue for me. I need to use an in_memory workspace for performance reasons.
TimBarnes

+1 I also need this in creating a custom tool. It doesn't make sense to use the In_memory workspace if you are forced to write a featureclass to be able to do tasks within an MXD.