MW5 Plugin how do I read a Shapefile by its ID?

Hi, I have come a ways on my Plugin and can do a bit with it. I see Layers exposed under the Api but not Shapefile. What is the method of accessing the fields of a given selected shape now that I can get the ID in the ShapeIdentified event?

In MapWinGIS and the 4.8.8 version plugin you could:
Dim SF as Shapefile and read its Fields.

Has this been replaced with something else? If so is there a snippet of code that shows the new way of accessing the fields in the plugin? I have looked at many of the entries on this forum but it seems to always be shapefiles in the context of the component, not MapWindow5 plugins.

I’m thinking it must be IFeature? But I am not sure how to tie it together.

Any help would be appreciated.

Here is my sample code that I have put together by trial and error:

    Private Sub InitPlugin_ShapeIdentified(map As IMuteMap, e As ShapeIdentifiedEventArgs) Handles Me.ShapeIdentified
        ' Debug.Print("Shape Identified")
        ' Debug.Print("Shape Index:   " & e.ShapeIndex.ToString)
        Dim shplst As IShapesList = map.IdentifiedShapes

        If shplst.Count >= 1 Then
            Dim sfs As IFeatureSet = MyMap.Layers(shplst(0).LayerHandle).FeatureSet
            Dim sf As IFeature = sfs.Features(shplst(0).ShapeIndex)
            Dim Itb As IAttributeTable = sfs.Table
            Dim Af As IAttributeField
            For i = 0 To sf.NumFields - 1
                Af = Itb.Fields(i)
                Debug.Print(Af.Name & "  " & _________________)
            Next i
        End If

        ___________________ = where Is The field value?
    End Sub

I can access the fields by name but I am missing something or there is a simpler way to come up with the values. It has to be easy as the built in identifier tool list the fields with values.

Hope this helps

Ok, I see…this works: Debug.Print(Af.Name & " " & Itb.CellValue(i, shplst(0).ShapeIndex).ToString)

I will refine my code to simplify. I hope this helps others, as I didn’t see it elsewhere.

1 Like