How to identify a shapefile layer

Hello,
I try to click a shape on map to do identify, but it doesn’t work, no error message.

I show the result in a listbox. Will anybody help or show me some identify code that works?

Thanks a lot!
Lang

axMap1.ShapesIdentified += AxMap1ShapesIdentified;

axMap1.SendMouseDown= true;
axMap1.CursorMode = tkCursorMode.cmIdentify;
private void AxMap1ShapesIdentified(object sender, _DMapEvents_ShapesIdentifiedEvent e)
        {
            listBox1.Items.Clear();
            var shp = e.selectedShapes;
            int layerHandle = shp.LayerHandle[0];
            Shapefile sf = axMap1.get_Shapefile(layerHandle);
            if (sf != null)
            {
                string s = "";
                for (int i = 0; i < sf.NumFields; i++)
                {
                    string val = sf.get_CellValue(i, shp.ShapeIndex[0]).ToString();
                    if (val == "") val = "null";
                    string it = sf.Table.Field[i].Name + ":   " + val + ";\n ";
                    listBox1.Items.Add(it);
                    
                }

            }
        }

Hello @lang

To start with, have you set the Identifiable property for the Shapefile layers of interest?

I’ll see if I can find some sample code.

Regards.

I found some VB.NET code that handles the ShapeIdentified event (as opposed to the ShapesIdentified). Interestingly, it appears that the IdentifiedShapes property is not in the documentation. I hope this helps.

Private Sub AxMap1_ShapeIdentified(sender As Object, e As AxMapWinGIS._DMapEvents_ShapeIdentifiedEvent) Handles AxMap1.ShapeIdentified
    Dim shapes As SelectionList = AxMap1.IdentifiedShapes()
    Dim desc As String
    If shapes.Count > 0 Then
        Dim sf As Shapefile = AxMap1.get_Shapefile(e.layerHandle)
        Dim s As Shape = sf.Shape(e.shapeIndex)
        If e.layerHandle = _RoadsLayerHandle Then
            With sf
                desc = String.Format("Roadname = {0}, FromID = {1}, ToID = {2}",
                                     .CellValue(.FieldIndexByName("roadname"), e.shapeIndex),
                                     .CellValue(.FieldIndexByName("FromID"), e.shapeIndex),
                                     .CellValue(.FieldIndexByName("ToID"), e.shapeIndex))
            End With
            MsgBox(desc, , "Edge Description")
        Else
            MessageBox.Show(shapes.Count & " shapes identified" & vbCrLf &
                            AxMap1.get_LayerName(e.layerHandle) & ":" & e.shapeIndex, "AxMap1_ShapeIdentified")
        End If
    End If
End Sub

Hi Jerry,

Sorry for the delayed response! I tried it with different ways and got it to work. Thank you for emphasize ShapeIdentified, not ShapesIdentified. The _DMapEvents_ShapesIdentifiedEvent does’t return the properties we need. _DMapEvents_ShapeIdentifiedEvent does. Which is the key. Thank you so much for the guidance!

See my code:
after InitializeComponent()
Add the function to delegate:

axMap1.ShapeIdentified += AxMap1ShapeIdentified;
void AxMap1ShapeIdentified(object sender, _DMapEvents_ShapeIdentifiedEvent e)
    {
        SelectionList shapes = axMap1.IdentifiedShapes;
        if (shapes.Count > 0)
        {
            Shapefile sf = axMap1.get_Shapefile(e.layerHandle);

            string s = "";
            for (int i = 0; i < sf.NumFields; i++)
            {
                string val = sf.get_CellValue(i, e.shapeIndex).ToString();
                if (val == "") val = "null";
                s = sf.Table.Field[i].Name + ":   " + val + ";\n ";
                listBox1.Items.Add(s);
               
            }
            //MessageBox.Show(s, "Result");
        }
    }

Thanks for sharing your working code.

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.