Getting a user’s selected feature in ArcGIS VBA/VB.NET

Dim pFL2 As IFeatureLayer
Set pFL2 = pMap.Layer(0)

Set pF2 As IFeature

Dim pfs As IFeatureSelection
Set pfs = pFL2
Dim id As Long
id = pfs.SelectionSet.IDs.Next
Set pF2 = pFL2.FeatureClass.GetFeature(id) ‘ this is line 2

Then you can do stuff on the Ifeature pF2 and pf2.Shape

Advertisements
Post a comment or leave a trackback: Trackback URL.

Comments

  • K  On October 20, 2011 at 10:34 am

    Looping on selected features using ENUMID:

    Dim pFeatureSelection As IFeatureSelection
    pFeatureSelection = pFeatureLayer
    Dim pEnumID As IEnumIDs
    pEnumID = pFeatureSelection.SelectionSet.IDs
    Dim id As Long
    id = pEnumID.Next

    Do While Not id = -1
    pFeature = pFeatureLayer.FeatureClass.GetFeature(id)
    id = pEnumID.Next
    Loop

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: