4 Replies Latest reply on Apr 3, 2014 11:53 PM by sweety88

    Load Layer from File Geodatabase (.gdb)

      Below is a post I found on the old ESRI forum.  When I add a raster from my file geodatabase, I want it to programatically load the layer file as well.  Where do I insert the code below to do that?


      I use a File Geodatabase with the name:
      I have some layers in this gdb, which I want to load to ArcMap programmatically.(the database.gdb is a folder with files inside with extensions .freelist, .gdbindexes, .gdbtable, .gdbtablx and .spx)
      Wherever I look in the forum I get code for an mdb Geodatabase.
      How can I load a layer from a File Geodatabase?

      The following code didn't work. I get an automation error at the line pWorkspaceFactory.OpenFromFile("C:\ZZZ\database.gdb", 0)
      It only works (I think) with mdb files

      Thank you 
        Dim pWorkspaceFactory As IWorkspaceFactory
      Set pWorkspaceFactory = New FileGDBWorkspaceFactory

      'Open the Access Workspace
      Dim pWorkspace As IFeatureWorkspace
      Set pWorkspace = pWorkspaceFactory.OpenFromFile("C:\ZZZ\database.gdb", 0)

      'Open the featureclass
      Dim pFeatureClass As IFeatureClass
      Set pFeatureClass = pWorkspace.OpenFeatureClass("LayerName")

      'Create a new Feature Layer
      Dim pFeatureLayer As IFeatureLayer
      Set pFeatureLayer = New FeatureLayer

      'Set the feature class to the geodatabase featureclass
      Set pFeatureLayer.FeatureClass = pFeatureClass
      pFeatureLayer.Name = pFeatureClass.AliasName

      'Add the new layer to ArcMap
      Dim pDoc As IMxDocument
      Set pDoc = ThisDocument
      Dim pMap As IMap
      Set pMap = pDoc.FocusMap
      pMap.AddLayer pFeatureLayer

      'Refresh the view and table of contents
        • Unable to load gdbtable / gdbindexes
          I am running the trial version of ArcGIS Desktop 10. I received a folder with .gdbtable , .gdbindexes, .freelist files. I've tried connecting the folder, importing the dataset, etc.. and I am failing bigtime. I've changed the extension on the folder to .gdb and tried importing that way. My goal is to convert the files to .dwg or .dxf for autocad, but I can't get to viewing. Any help is appreciated.

          • Re: Load Layer from File Geodatabase (.gdb)
            Hi John,

            It sounds like the geodatabase you received may be corrupt - try requesting it again.

            Tell the dataset creator to zip the entire geodatabase directory, from one level above the the files you're seeing.

            Eg, if the file is called C:\data\FileName.gdb, they should open C:\data in Windows, right-click on FileName.gdb, and zip this. This will create a zip file containing FileName.gdb, which will contain the constituent files.

            You should be able to preview the geodatabase in ArcCatalog, or add it to ArcMap using the Add Data option.

            • Re: Load Layer from File Geodatabase (.gdb)
              Just learned that while you have downloaded <FILENAME>.gdb.zip, you must create new folder> "<FILENAME>.gdb" >extract zip file to new folder.... THEN ArcMap will recognize the data. 

              If you simply extract your data to a file without creating the destination folder with a .gdb extension, it will not be recognized.

              1 of 1 people found this helpful
              • Re: Load Layer from File Geodatabase (.gdb)

                  We are making a iOS application for offline viewing of map.
                We have .tpk file to show offline map and .gdb file for database to show related information of map layers.
                But we are unable to read the .gdb file.

                Should the extension be something different? How should we add this file in our application?
                And how can we read this file to get the data of layers.

                Please help for this.

                Sweety Singh