In the ArcGIS 10 SDK I copied an object by value using the IObjectCopy interface. I can't find a similar thing in the ArcGIS Desktop SDK. I guess its available in the Enterprise SDK but that's not what i am working with. So, what would be equivalent code in Pro if I had this in ArcGIS 10?
'deep clone the IFeatureSelection because it's possible that the Origin and Proximity sources are the same.
Dim objectCopyB As IObjectCopy = New ObjectCopy
Dim objB As Object = objectCopyB.Copy(pFeatSelOriginB)
Dim pFeatSelOrigCloneB As IFeatureSelection = CType(objB, IFeatureSelection)
Hi,
You can use EditOperation Copy method. Below is code for map selection copy layer by layer:
var mv = MapView.Active;
return QueuedTask.Run(() =>
{
var sel_set = mv.Map.GetSelection().ToDictionary();
if (sel_set.Count() == 0)
return false;
//do the copy
var editOp = new EditOperation()
{
Name = "Copy",
ErrorMessage = "Copy failed"
};
foreach (var kvp in sel_set)
{
editOp.Copy(kvp.Key, kvp.Key, kvp.Value);
}
return editOp.Execute();
});
ok let me give that a try.
I'm not sure this is the routine that will give me what i need. I need to clone a feature layer so that I can manipulate it before sending it to a GP. Essentially I want to use a temp layer that is not to be added to the map.
In ArcGIS 10 I did this and it worked great:
If pOriginalFeatLayer Is Nothing Then Throw New ArgumentNullException(NameOf(pOriginalFeatLayer))
'get the feature class (Or feature table) from original layer
Dim pFeatClass As IFeatureClass = pOriginalFeatLayer.FeatureClass
'create a New FeatureLayer using the same feature class/table (this creates a layer pointing to the same data)
Dim pCloneFeatLayer As IFeatureLayer = New FeatureLayer With {.FeatureClass = pFeatClass}
'copy basic properties
pCloneFeatLayer.Name = pOriginalFeatLayer.Name + "_Cloned" 'new name
It's just a layer in memory that is for temporay6 work and therefore not needed to be in the map.
There is no possibility to have map layer not added to map. You can use Copy Features GP tool and as an output use memory workspace
//get the active map
MapView activeView = MapView.Active;
//get the first layer in the active map
var layer = activeView.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First();
if(layer == null)
return;
var parameters = Geoprocessing.MakeValueArray(layer, @"memory\clonedFC");
IGPResult result = await Geoprocessing.ExecuteToolAsync("CopyFeatures_management", parameters, null, null, null, GPExecuteToolFlags.AddToHistory);
What about creating a map in memory and adding the layer to that?
Sorry, I can't help you to create a map in memory.
Ok here is what i have an it seems to work without exceptions. I haven't tried sending this to my GP so that's the second part of the challenge.
// do the basic clone of the layer
Map map = null;
FeatureLayer cloneFeatLayer = null;
await QueuedTask.Run(() =>
{
// we create the layer and do not display in the active map but instead we will
// create a map in memory and add the layer to this temporary map.
map = MapFactory.Instance.CreateMap("ForCloneLayer", MapType.Map);
// get the URI of the original layer
Uri uri = originalFeatLayer.GetPath();
Debug.Print($"uri=[{uri}]");
// create feature layer creation parameters. for this routine we will only need the basics.
var flyrCreatnParam = new FeatureLayerCreationParams(uri)
{
Name = originalFeatLayer.Name + "_Cloned",
IsVisible = false,
DefinitionQuery = null,
//MinimumScale = 1000000,
//MaximumScale = 5000,
//DefinitionQuery = new DefinitionQuery(whereClause: "Population > 100000", name: "More than 100k"),
//RendererDefinition = new SimpleRendererDefinition()
//{
// SymbolTemplate = SymbolFactory.Instance.ConstructPointSymbol(CIMColor.CreateRGBColor(255, 0, 0), 8, SimpleMarkerStyle.Hexagon).MakeSymbolReference()
//}
};
cloneFeatLayer = LayerFactory.Instance.CreateLayer<FeatureLayer>(flyrCreatnParam, map);
});
Then calling it like so
// test the cloning
FeatureLayer originCloneLayer = await lyrOrigin.GetBasicClone();
originCloneLayer = null;
// just for testing
GC.Collect();
GC.WaitForPendingFinalizers();