How to create Layer from selected features

202
3
10-22-2018 08:03 AM
Highlighted
Occasional Contributor

Is there a simpler way to create a layer from selected features? 

From the research I have done I would:

Get the selected feature-->create a list/array of OBJECTIDs-->Copy the layer containing the selected features --> apply a definition query based on the list of OBJECTIDs-->

This is obviously an abbreviated description, but I do not see a simpler approach.

Reply
0 Kudos
3 Replies
Highlighted
Esri Regular Contributor

Hi Brad,

You could also add a definition to a feature layer using BasicFeatureLayer.SetDefinitionQuery.

You can see a sample with this method: QueryBuilderControl

Thanks

Uma

Highlighted
Occasional Contributor

Uma, I used CreateFeatureLayer then the SetDefinitionQuery method on the layer.  

var slectionLayer = LayerFactory.Instance.CreateFeatureLayer(uri, mapView, 0, "Selection Layer")

selectionLayer.SetDefinitionQuery(defQuery);‍‍‍

I noticed that the CreateFeatureLayer method has the optional parameter RendererDefinition. I couldn't find any documentation or examples on how to use this parameter to set a simple single symbol renderer. I found plenty for graduated and unique colour symbol examples. 

This isn't a big deal.  I just used the CIMSimpleRenderer class to create a renderer then SetRenderer after the layer has loaded. 

Just curious how this would work since I initially wanted the layer load with the renderer set. 

Thanks.

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi Brad,

Here are some snippets that make simple renderers:

SimpleRenderers

Thanks

Uma

Reply
0 Kudos