Replace Data Sources from shapefile to feature dataset feature class in an mxd using

4377
4
Jump to solution
10-03-2011 10:50 AM
GerryGabrisch
Occasional Contributor III
We have migrated a bulk of our GIS data from shapefiles into feature classes within feature datasets (ArcGIS-file geodatabase-feature datasets).
I am trying to develop a Python script to automatically replace the most popular datasets in an mxd with the paths to the new data. 

My problem is that both the data model (shapefile to feature dataset feature class) has changed, and the feature class name has changed.

The replaceDataSource() and replaceWorkspacePaths() methods do not have parameter for connecting to feature datasets.
See http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/MapDocument/00s30000000n000000/

The code posted below works if I move my feature class out of the feature dataset within the file geodatabase (meaning the syntax is good). Still, how to I set the replaceDataSource to a feature data set?

try:
    import arcpy.mapping, os, sys, string, traceback
    mxd = arcpy.mapping.MapDocument("CURRENT")
    for dataframe in arcpy.mapping.ListDataFrames(mxd):
        BrokenLinkList = arcpy.mapping.ListBrokenDataSources(dataframe)      
        for item in  BrokenLinkList:
            print item.datasetName
            if item.datasetName == r"LummiReservationFullBoundary":
                print "droppin' in"
                #The path to the new directory...
                newWorkspace = r"Z:\Data\Boundaries\Administrative\Lummi.gdb\TribalBoundaries"
                #The new dataset name...
                datasetName = r"LummiReservation"
               
                #This should have a "FEATUREDATASET" options to replace FILEGDB_WORKSPACE.
                item.replaceDataSource (newWorkspace, "FILEGDB_WORKSPACE", datasetName, False)
    arcpy.RefreshTOC()
    #mxd.save()
    del mxd
    print "Done"
except arcpy.ExecuteError: 
    msgs = arcpy.GetMessages(2) 
    arcpy.AddError(msgs) 
    print msgs
except:
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
    arcpy.AddError(pymsg)
    arcpy.AddError(msgs)
    print pymsg + "\n"
    print msgs
Tags (2)
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor
When specifying the new workspace name, do NOT include the name of the feature dataset.  The workspace is simply the path to the .gdb (in your case).  The feature dataset will automatically get resolved.

newWorkspace = r"Z:\Data\Boundaries\Administrative\Lummi.gdb\TribalBoundaries"

should be

newWorkspace = r"Z:\Data\Boundaries\Administrative\Lummi.gdb"


Jeff

View solution in original post

4 Replies
JeffBarrette
Esri Regular Contributor
When specifying the new workspace name, do NOT include the name of the feature dataset.  The workspace is simply the path to the .gdb (in your case).  The feature dataset will automatically get resolved.

newWorkspace = r"Z:\Data\Boundaries\Administrative\Lummi.gdb\TribalBoundaries"

should be

newWorkspace = r"Z:\Data\Boundaries\Administrative\Lummi.gdb"


Jeff
GerryGabrisch
Occasional Contributor III
Great, that worked thanks!

What if there are more than one feature feature datasets in the gdb and each feature dataset has a feature class with the same name?
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi gabrisch,

You actually cannot have a feature class with the same name, even if it resides in a separate feature dataset.
0 Kudos
JeffBarrette
Esri Regular Contributor
And this is why we only need to provide a path to the workspace, which in your case is the .gdb.

A good document that addresses different update data source scenarios is found at the follolwing link.  It even includes a scenario that involves feature data sets.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Updating_and_fixing_data_sources_with_...

Jeff