I'm trying to create an in-memory feature class, and I assume the way to do this is to first create an in-memory geodatabase and then copy the feature class to this geodatabase. I'm able to create the geodatabase, but the copy operation fails. Here is my code:
MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties("MyMemoryGDB");
Geodatabase geodatabase = SchemaBuilder.CreateGeodatabase(memoryConnectionProperties);
var parameters = Geoprocessing.MakeValueArray(@"C:\Users\kbmeinstein\Desktop\DeformTest\50Ma_Pro_Deftest_model_save.gdb\DefMotion_50Ma", @"in_memory\MyMemoryGDB", "test");
IGPResult result = await Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", parameters, null, null, null, GPExecuteToolFlags.AddOutputsToMap);
Any suggestions how to get this to work would be greatly appreciated.
Solved! Go to Solution.
I'm so sorry, Karen. I skipped over the geoprocessing call and didn't really pay attention to which tool you were trying to use.
I also specified "in_memory" which is incorrect. It's possible that this did work, but "in_memory" feature classes cannot be displayed on a map, and if you attempt to do so, Pro copies the feature class to a file geodatabase. (More information here)
Try using "memory" instead of "in_memory". If this doesn't work, I'll bring in a geoprocessing expert.
--Rich
Hi Karen,
Geoprocessing only knows how to work with a single memory geodatabase- the one called "memory". You can execute your copy like this:
var parameters = Geoprocessing.MakeValueArray(@"C:\Users\kbmeinstein\Desktop\DeformTest\50Ma_Pro_Deftest_model_save.gdb\DefMotion_50Ma", @"in_memory\test");
IGPResult result = await Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", parameters, null, null, null, GPExecuteToolFlags.AddOutputsToMap);
If you later need to access this new table using the Pro SDK, you can do so with the following code:
MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties();
Geodatabase geodatabase = SchemaBuilder.CreateGeodatabase(memoryConnectionProperties);
FeatureClass testFeatureClass = geodatabase.OpenDataset<FeatureClass>("test");
(In this instance, the CreateGeodatabase call doesn't really create a new geodatabase, but rather returns a connection to the existing memory geodatabase.)
I hope this helps,
--Rich
Hi Rich,
Thanks for the help! Unfortunately this didn't work. I'm wondering if the FeatureClasstoFeatureClass parameters are correct. According to the documentation (https://pro.arcgis.com/en/pro-app/latest/tool-reference/conversion/feature-class-to-feature-class.ht...) there are 3 required parameters: input features, output location and output name, while your code only has 2 parameters.
If I change the parameters to this:
var parameters = Geoprocessing.MakeValueArray(@"C:\Users\kbmeinstein\Desktop\DeformTest\50Ma_Pro_Deftest_model_save.gdb\DefMotion_50Ma", @"in_memory", "test");
The code works, but the feature class is copied to a file geodatabase called default.gdb instead to memory.
I'm so sorry, Karen. I skipped over the geoprocessing call and didn't really pay attention to which tool you were trying to use.
I also specified "in_memory" which is incorrect. It's possible that this did work, but "in_memory" feature classes cannot be displayed on a map, and if you attempt to do so, Pro copies the feature class to a file geodatabase. (More information here)
Try using "memory" instead of "in_memory". If this doesn't work, I'll bring in a geoprocessing expert.
--Rich
Yay! That worked! Thanks so much!
Hi Again Rich,
When I try to access the in-memory feature class using this code:
MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties();
Geodatabase geodatabase = SchemaBuilder.CreateGeodatabase(memoryConnectionProperties);
FeatureClass testFeatureClass = geodatabase.OpenDataset<FeatureClass>("test");
It throws an error on the CreateGeodatabase line that says the workspace already exists.
I think I found a solution to my previous question. If I put these lines:
MemoryConnectionProperties memoryConnectionProperties = new MemoryConnectionProperties();
Geodatabase geodatabase = SchemaBuilder.CreateGeodatabase(memoryConnectionProperties);
before the FeatureClasstoFeatureClass geoprocessing stuff, then I can access the feature class after the geoprocessing is done using:
FeatureClass testFeatureClass = geodatabase.OpenDataset<FeatureClass>("test");
Thanks for letting me know, Karen. We'll take a look at it- might be a bug. Glad you found a workaround at least.
--Rich