Select to view content in your preferred language

Batch Project Geodatabase Script

2443
2
08-02-2010 05:47 AM
JordanHoaglund1
Emerging Contributor
Hi All, I have 90 geodatabases, all in the the same folder and projected in WGS84.  I need to get all the data in those geodatabases re-projected into WGS84 Web Mercator.  I'm hoping there is a relatively simple python script (compatible with ArcInfo 9.3.1) that can do this.

I found the following script in the old forums, but being a relative newb to python I'm not sure what to do with it...

import arcgisscripting, os
gp = arcgisscripting.create(9.3)

sourceGDB = r"C:\New Personal Geodatabase.mdb"

def fcsFromWorkspace(workspace):
    gp.workspace = workspace
    fcList = gp.listfeatureclasses()
    for fc in fcList:
        print "Do whatever gp process with: " + fc

fcsFromWorkspace(sourceGDB)

datasetList = gp.listdatasets()
for dataset in datasetList:
    fcsFromWorkspace(sourceGDB + os.sep + dataset)


Thanks in advance!
0 Kudos
2 Replies
DavidWynne
Esri Contributor
Try this code (modify as you need).  It creates a new sub folder name 'projected', and creates new copies of the geodatabases and populates them with projected versions of the datasets and featureclasses from the originals.

I've hard-coded a couple things, including the starting workspace, and change the coordinate system and transformation as needed.  For the coordinate system, I'm pointing to a .prj file on disk.


import arcgisscripting, os
gp = arcgisscripting.create(9.3)

gp.overwriteOutput = True
gp.workspace = "c:/temp/base"

outputCS = gp.CreateObject("SpatialReference")
outputCS.createFromFile(os.path.join(gp.getinstallinfo()['InstallDir'],
                                     "Geographic Coordinate Systems/North America/NAD 1927.prj"))
transformation = ""

outFolder = os.path.join(gp.workspace, "projected")
gp.CreateFolder_management(*os.path.split(outFolder))
    
for gdb in gp.ListWorkspaces("", "ACCESS"):  # Get all personal geodatabases
    gp.workspace = gdb
    gdb = os.path.basename(gdb)
    toProject = gp.ListFeatureClasses() + gp.ListDatasets()
    gp.CreatePersonalGDB_management(outFolder, gdb)
    gp.BatchProject_management(toProject,
                               os.path.join(outFolder, gdb),
                               outputCS,
                               "",
                               transformation)
0 Kudos
JordanHoaglund1
Emerging Contributor
Thanks David!  I had to modify for file geodatabases, but it worked perfectly.  My (slight) modifications are below;

[HTML]import arcgisscripting, os
gp = arcgisscripting.create(9.3)

gp.overwriteOutput = True
gp.workspace = "B:\NRCA"

outputCS = gp.CreateObject("SpatialReference")
outputCS.createFromFile(os.path.join(gp.getinstallinfo()['InstallDir'],"Coordinate Systems/Projected Coordinate Systems/World/WGS 1984 Web Mercator (Auxiliary Sphere).prj"))

transformation = ""

outFolder = os.path.join(gp.workspace, "projected")
gp.CreateFolder_management(*os.path.split(outFolder))
   
for gdb in gp.ListWorkspaces("", "FileGDB"):  # Get all personal geodatabases
    gp.workspace = gdb
    gdb = os.path.basename(gdb)
    toProject = gp.ListFeatureClasses() + gp.ListDatasets()
    gp.CreateFileGDB_management(outFolder, gdb)
    gp.BatchProject_management(toProject,
                               os.path.join(outFolder, gdb),
                               outputCS,
                               "",
                               transformation)
[/HTML]
0 Kudos