+ Reply to Thread
Results 1 to 4 of 4

Thread: Load Layer from File Geodatabase (.gdb)

  1. #1
    Bryan Deverot
    Join Date
    Aug 2010
    Posts
    2
    Points
    0
    Answers Provided
    0


    0

    Default 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?

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

    I use a File Geodatabase with the name:
    database.gdb
    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
    pDoc.UpdateContents
    pDoc.ActiveView.Refresh

  2. #2

    Join Date
    Jun 2011
    Posts
    1
    Points
    1
    Answers Provided
    0


    0

    Default 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.

    John

  3. #3
    Stephen Lead
    Join Date
    May 2010
    Posts
    708
    Points
    130
    Answers Provided
    23


    0

    Default 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.

    Steve

  4. #4

    Join Date
    Feb 2013
    Posts
    1
    Points
    0
    Answers Provided
    0


    0

    Default 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.

    Cheers!

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts