workspacefactory/featuredataset confusion

675
0
02-17-2011 06:57 AM
TanaHaluska
New Contributor
Hello
I'm new to vb.net and arcobjects, using arcgis10. I have posted a subroutine below that should load featureclasses from one or many featuredatasets inside a single geodatabase.  The geodatabase has a featuredataset for each parcel.  Inside each featuredataset there are several inundation polygons for that parcel.  The for loop is supposed to loop through each selected parcel and load the specified inundation area from the geodatabase. After running the code with 2 parcels selected, it appears that inundation areas for both parcels are loaded into the map document, but the names of the layers are the same, when they should be unique. When I turn off one inundation polygon the other still remains, but one I turned off won't turn back on and the source path breaks. Or, when viewing the layers in the table of contents by order displayed and then by source, the source path breaks. Also one of the parcel inundation layer disappears completely. I've inserted msgbox comments throughout to confirm the names of the featureclasses and other variables, they all appear correct when running the code. The tables appear to be loading correctly, but not the featureclasses.  I tried setting all variables to nothing at the bottom of the loop to try to clear this up, but no luck.  If I retrieve a featureclass from one featuredataset inside a geodatabase and then switch to a different featuredataset in the same geodatabase, do I have to somehow close the first featurdataset?  I presume I can use the same workspace factory for both featuredatasets within the same geodatabase. If anyone can see something I'm doing wrong, please advise.
many thanks.
tlh

Public Sub LoadParcel()
        Try
   Dim pMxDoc As IMxDocument = DirectCast(m_app.document, IMxDocument)
            Dim pMap As IMap = pMxDoc.FocusMap
            Dim pFLayer As ESRI.ArcGIS.Carto.IFeatureLayer = New FeatureLayer
            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 tableCollection As ITableCollection = TryCast(pMap, ITableCollection)
            Dim pTable As ITable
            Dim strGDBName As String = strDefaultWorkspace & "\Processed_Data\ShorelineManagementTool_" & LStageDat & ".gdb"
            Dim OneParcelList() As String = SelParc.Split(",")
For i = 0 To intNumParcelsSel - 1
                Dim intParcNum As Integer = OneParcelList(i)
                MsgBox("intParcNum: " & intParcNum)
                Dim strFDSetName As String = "InundationAreasParcel_" & intParcNum
                MsgBox("strFDSetName: " & strFDSetName)
                Dim dblStage As Double = LStage
                intInundationStage = (Int((dblStage + 0.05) * 10) * 10)
                Dim strFClassName As String = "p" & intParcNum & intInundationStage & "_polygon"
                MsgBox("strFClassName: " & strFClassName)
                pFWS = pWSFactory.OpenFromFile(strGDBName, 0)
                pFDSet = pFWS.OpenFeatureDataset(strFDSetName)
                pFCContainer = CType(pFDSet, ESRI.ArcGIS.Geodatabase.IFeatureClassContainer)
                pFClass = pFCContainer.ClassByName(strFClassName)
                pFLayer.FeatureClass = pFClass
                pFLayer.Name = strFClassName
                pMap.AddLayer(pFLayer)
                'pFLayer.Name = strFClassName
                MsgBox("pFLayer.Name: " & pFLayer.Name)
                pTable = pFWS.OpenTable("p" & intParcNum & intInundationStage & "_cf")
                tableCollection.AddTable(pTable)
                strFDSetName = Nothing
                strFClassName = Nothing
                pFDSet = Nothing
                pFCContainer = Nothing
                pFClass = Nothing
                pFLayer.FeatureClass = Nothing
                pFLayer.Name = Nothing
                pTable = Nothing
            Next
       Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
0 Kudos
0 Replies