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?

blah238
35.9k8 gold badges97 silver badges204 bronze badges
asked Oct 18, 2012 at 5:53

1 Answer 1

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.

answered Oct 18, 2012 at 6:16
1
  • 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 Commented Oct 18, 2012 at 9:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.