Retrieving Layer Name from IFeature

2717
1
04-25-2011 05:36 AM
ChristopherHaviland
New Contributor
I want to be able to retrieve the layer name of a IFeature object.  I was previously using the AliasName property of the FeatureClass of the IFeature object, but in some cases of using an enterprise SQL Server DB, this does not represent the full name of the layer like ILayer.Name.  Can I retrieve the ILayer interface from the IFeature object that I have?  I did find that in my one particular test case that comparing the FeatureClass of the IFeature interface and the FeatureClass of the ILayer interface (re-casted as IFeatureLayer) works, but is this a proper method of determining the layer that a feature is on?  The code to retrieve the IFeature inteface that I am using is not available to edit since I would normally be able to retrieve the layer from that.

Thanks in advance
0 Kudos
1 Reply
JamesCrandall
MVP Frequent Contributor
I am not totally certain exactly what you need to accomplish, but if you are having difficulty with acquiring a layer in the TOC (that has been altered/changed/shortened) because the name you are passing is difficult to match up to fully qualified names from ArcSDE, then you could utilize the IDataset:Name property.

I use the following function when I need to access a specific layer in the TOC by passing it's fully qualified SDE name:


Private Function ReturnFLayer(ByVal inName As String) As IFeatureClass
        Try

            Dim pDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument
            Dim pMap As ESRI.ArcGIS.Carto.IMap
            Dim pLayer As ESRI.ArcGIS.Carto.IFeatureLayer
            Dim dataset As IDataset
            Dim i As Short
            'Layer name to find
            Dim sLayerName As String = inName
            Dim Name As String

            pDoc = m_application.Document
            pMap = pDoc.FocusMap
            For i = 0 To pMap.LayerCount - 1

                pLayer = pMap.Layer(i)
                dataset = pLayer.FeatureClass
                Name = dataset.Name

                If Name = sLayerName Then
                    pLayer = pMap.Layer(i)
                    Exit For
                End If
            Next

            Return pLayer.FeatureClass

        Catch ex As Exception
            MsgBox(ex.ToString)
            Return Nothing
        End Try
    End Function
0 Kudos