Geographic Information Systems Asked on April 19, 2021
I’ve been asked to develop a strategy to work with Layers that have not yet been added to a Map.
From what I can tell, one cannot simply create a new layer as one can with ArcObjects. One must use a method on the LayerFactory
, all of which add a layer to the map upon creation.
So instead of using Layers, I thought I would have my analysis engine deal with layer definitions, e.g. CIMFeatureLayer
, which can exist outside of a map.
For example, my analysis engine would generate CIMFeatureLayers
and then, once I’m ready to present the layer, I would use something similar to LayerFactory.CreateFeaturelayer
to create a layer from the CIMFeatureLayer
.
I’ve searched but cannot find any method that does this.
Clearly Pro does this behind the scenes – if I save a .lyrx file and look at it in a text editor, I see that it is a json serialization of a CIMLayerDocument
with CIMFeatureLayers
within it. How can I do what Pro does when it reads the .lyrx file?
Update
I also tried this code, but SetDefinition doesn’t seem to do anything.
private void Test()
{
var def = MapView.Active.Map.Layers[0].GetDefinition() as CIMFeatureLayer;
var fLayer = LayerFactory.CreateLayer(def.FeatureTable.DataConnection,MapView.Active.Map) as FeatureLayer;
fLayer.SetName("my layer");
// name remains "my layer" Setdefinition has no discernable effect
fLayer.SetDefinition(def);
}
You can use this:
private void Test()
{
var layer=await QueuedTask.Run(()=>MapView.Active.Map.Layers[0].GetDefinition() as CIMFeatureLayer);
var fLayer = await QueuedTask.Run(()=>LayerFactory.CreateLayer(polyLayer.FeatureTable.DataConnection, MapView.Active.Map)) as FeatureLayer;
await QueuedTask.Run(()=> fLayer.SetName("My Name"));
await QueuedTask.Run(()=> fLayer.SetDefinition(polyLayer));
}
Answered by osman on April 19, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP