Add data in to arc from a table????

742
2
Jump to solution
10-07-2014 09:45 AM
PatrickRobb
New Contributor

Hello,

I am looking for a way in either model builder or Python (or anything at this point) to import from a table, files in a file geodatabase. I am looking at roughly 600 files in said geodatabase and it can be a little time consuming to manually pull them in to ArcGIS. The table consists of the file name and file path. Does anyone know if this is possible and if so how do I go about it.

Thanks in advance... Hopefully

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Patrick,

Below is some example code you can run in the Python window within ArcMap.  It will iterate through a table called 'DataLocation' in the File Geodatabase 'Test'.  It concatenates the fields 'FilePath' and 'FileName' to add the table/feature class it references.

import arcpy

from arcpy import env

env.workspace = r"C:\temp\python\test.gdb"

mxd = arcpy.mapping.MapDocument("CURRENT")

df = arcpy.mapping.ListDataFrames(mxd, "*")[0]

table = "DataLocation"

fields = ["FilePath", "FileName"]

with arcpy.da.SearchCursor(table, fields) as cursor:

    for row in cursor:

        path = row[0] + "\\" + row[1]

        try:

            fGDB_Table = arcpy.mapping.TableView(path)

            arcpy.mapping.AddTableView(df, fGDB_Table)

        except ValueError:

            addLayer = arcpy.mapping.Layer(path)

            arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")

del mxd, cursor

View solution in original post

2 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Patrick,

Below is some example code you can run in the Python window within ArcMap.  It will iterate through a table called 'DataLocation' in the File Geodatabase 'Test'.  It concatenates the fields 'FilePath' and 'FileName' to add the table/feature class it references.

import arcpy

from arcpy import env

env.workspace = r"C:\temp\python\test.gdb"

mxd = arcpy.mapping.MapDocument("CURRENT")

df = arcpy.mapping.ListDataFrames(mxd, "*")[0]

table = "DataLocation"

fields = ["FilePath", "FileName"]

with arcpy.da.SearchCursor(table, fields) as cursor:

    for row in cursor:

        path = row[0] + "\\" + row[1]

        try:

            fGDB_Table = arcpy.mapping.TableView(path)

            arcpy.mapping.AddTableView(df, fGDB_Table)

        except ValueError:

            addLayer = arcpy.mapping.Layer(path)

            arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")

del mxd, cursor

PatrickRobb
New Contributor

Awesome... Thank you.

Do you think this will work using a database not in the fgdb?

0 Kudos