[GIS] How to create a new feature layer from the selected features

arcobjects

I have a simple tool written in ArcObjects which takes features from a layer and does some processing on them.

I use a feature cursor to loop through all the features in the layer. To perform the necessary processing I have written several functions which accept an IFeatureLayer reference.

What I want to achieve is:

  • I want to process only those features which are selected
  • I don't want to change my code in all my existing functions. So I want to be able to continue to pass an IFeatureLayer reference to these functions.

How can I do this?

Best Answer

Query interface/cast from your original IFeatureLayer reference to IFeatureLayerDefinition and call its CreateSelectionLayer() method.

This will create a new feature layer from the existing feature layer based on its selection and optionally an expression to further filter it.

Related Question