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 Answer 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 recordShashank– Shashank2012年10月18日 09:23:26 +00:00Commented Oct 18, 2012 at 9:23