Pick new points of a feature

06-01-2021 10:27 AM
New Contributor II

Good day All,

I am unable to figure out how to find all features using ArcObjects 10.6. My code is working on selected feature (1 point) only. It doesn't work on multiple points added. 

My code is in vb.net. Any help is appreciated.


Dim pMxDoc As IMxDocument
pMxDoc = CType(My.ArcMap.Application.Document, IMxDocument)
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pEnumFeat As IEnumFeature = TryCast(pMap.FeatureSelection, IEnumFeature)
Dim pFeat As IFeature = pEnumFeat.Next


If pFeat Is Nothing Then
MessageBox.Show("No Feature Selected.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

Dim pFields As IFields
Dim enumFeatSetup As IEnumFeatureSetup = CType(pEnumFeat, IEnumFeatureSetup)
enumFeatSetup.AllFields = True

While pFeat IsNot Nothing
' How to loop through all new poins added?
pFields = pFeat.Fields

sIndex = pFeat.Value(pFeat.Fields.FindField("INDEX"))

sUni = GetUniqueValue(sIndex)

pFeat.Value(pFeat.Fields.FindField("UNIQUE")) =sUni

pFeat = pEnumFeat.Next
End While



0 Kudos
1 Reply
MVP Frequent Contributor

Firstly when posting code please insert it and set the language  using the </> tool on the toolbar, to see it you need to click on the 3 dots icon. It makes it easier for people to read your code and help you.

Below is a VBA script knocked together and it functioned as expected (note the syntax colouring...)



Public Sub test()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pEnumFeat As IEnumFeature
Set pEnumFeat = pMap.FeatureSelection

Dim enumFeatSetup As IEnumFeatureSetup
Set enumFeatSetup = pEnumFeat
enumFeatSetup.AllFields = True

Dim pFeat As IFeature
Set pFeat = pEnumFeat.Next

Dim i As Integer
i = pFeat.Fields.FindField("PROV_NAME")

Do While Not pFeat Is Nothing
    Debug.Print pFeat.Value(i)
    Set pFeat = pEnumFeat.Next
End Sub



So this worked for me which made me wonder if you understand what pMap.FeatureSelection is doing. It's returning an enumerator over ALL selections in ALL layers in the map. Your code logic is assuming that ALL layers with a selection have an INDEX and UNIQUE field. Is this your intention?

If you intend to update a single layer then its much safer to get the selection set from IFeatureSelection which has been cast to point to a single FeatureLayer.

0 Kudos