add featureclass from geodatabase featuredataset

2916
4
02-08-2011 11:28 AM
TanaHaluska
New Contributor
Hello
I'm new to vb and dotnet. I'm running arcgis 10. I think I am close but need help finishing my procedure below. The code below works up to the point where I have the message box.  The error I get is "Unable to cast COM object of type 'System.__ComObject" to interface type 'ESRI.ArcGIS.Carto.IFeatureLayer'" I've tried several variations on the last few lines but can't figure it out.  I'm inexperienced in casting, which I think is what I need to do here. Any help is appreciated.  I just want to add the featureclass that is inside the geodatabase featuredataset to the map document.
thanks
tlh

Private Sub LoadInundationLayers()
        Dim pMxDoc As IMxDocument = DirectCast(m_app.document, IMxDocument)
        Dim pMap As IMap = pMxDoc.FocusMap
        Dim pFLayer As ESRI.ArcGIS.Carto.IFeatureLayer
        Dim pWSFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = New FileGDBWorkspaceFactory
        Dim pFWS As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace
        Dim pFDSet As ESRI.ArcGIS.Geodatabase.IFeatureDataset
        Dim pFCContainer As ESRI.ArcGIS.Geodatabase.IFeatureClassContainer
        Dim pFClass As ESRI.ArcGIS.Geodatabase.IFeatureClass
        Dim intParcNum As Integer = 9
        intInundationStage = 413000
        Dim strGDBName As String = strDefaultWorkspace & "\Processed_Data\ShorelineManagementTool_" & frmScenSet.lblVertDatStage.Text & ".gdb"
        Dim strFDSetName As String = "InundationAreasParcel_" & intParcNum
        Dim strFClassName As String = "p" & intParcNum & intInundationStage & "_polygon"
       
        Try
            pFWS = pWSFactory.OpenFromFile(strGDBName, 0)
            pFDSet = pFWS.OpenFeatureDataset(strFDSetName)
            pFCContainer = CType(pFDSet, ESRI.ArcGIS.Geodatabase.IFeatureClassContainer)
            pFClass = pFCContainer.ClassByName(strFClassName)
            MsgBox("code works up to here")
            pFLayer = pFClass
            pMap.AddLayer(pFLayer)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
0 Kudos
4 Replies
JeffMatson
Occasional Contributor III
It should work by updating the following two lines of code:


Dim pFLayer As ESRI.ArcGIS.Carto.IFeatureLayer = New FeatureLayer  

pFLayer.FeatureClass = pFClass
0 Kudos
TanaHaluska
New Contributor
Hi Jeff
I get an error "Implementing class ESRI.ArcGIS.Carto.FeatureLayerClass for interface ESRI.ArcGIS.Carto.FeatureLayer can not be found.
thanks for your help
tlh
0 Kudos
JeffMatson
Occasional Contributor III
You might check your project references, see the following link:

http://forums.esri.com/Thread.asp?c=93&f=1170&t=261461

hope that helps,

Jeff
0 Kudos
TanaHaluska
New Contributor
Jeff:
It worked! I just needed to modify the code as you stated and add the display reference.
thank you so much!
tlh
0 Kudos