2

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?

1

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.

  • Thanks for the answer. Its somehow not working for me completely, Here is the Code: Sub testing() 'Defined & Set stuff like IMap and ImxDoc SetEverything Dim l As IFeatureLayer Dim fs As IFeatureSelection Dim newL As IFeatureLayer Dim ld As IFeatureLayerDefinition Set l = pMap.layer(0) 'l has 400 records 'Now Selected 1 record in layer l Set fs = l Set ld = l Set newL = ld.CreateSelectionLayer(l.Name & "_1", True, vbNullString, vbNullString) MsgBox newL.featureClass.FeatureCount(Nothing) 'it prints 400 and NOT 1 end sub please help. if I add newL in TOC, then it has 1 record – Shashank Oct 18 '12 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.