+ Reply to Thread
Results 1 to 5 of 5

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

  1. #1
    Gerry Gabrisch
    Join Date
    Apr 2010
    Posts
    125
    Points
    12
    Answers Provided
    1


    0

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

    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/arcgisdesk...000000n000000/

    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?

    Code:
    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

  2. #2
    Jeffrey Barrette

    Join Date
    Oct 2009
    Posts
    712
    Points
    201
    Answers Provided
    64


    0

    Default Re: Replace Data Sources from shapefile to feature dataset feature class in an mxd us

    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

  3. #3
    Gerry Gabrisch
    Join Date
    Apr 2010
    Posts
    125
    Points
    12
    Answers Provided
    1


    0

    Default Re: Replace Data Sources from shapefile to feature dataset feature class in an mxd us

    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?

  4. #4
    Jake Skinner

    Join Date
    May 2010
    Posts
    1,598
    Points
    1122
    Answers Provided
    178


    0

    Default Re: Replace Data Sources from shapefile to feature dataset feature class in an mxd us

    Hi gabrisch,

    You actually cannot have a feature class with the same name, even if it resides in a separate feature dataset.

  5. #5
    Jeffrey Barrette

    Join Date
    Oct 2009
    Posts
    712
    Points
    201
    Answers Provided
    64


    0

    Default Re: Replace Data Sources from shapefile to feature dataset feature class in an mxd us

    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/arcgisdesk...000004p000000/

    Jeff

+ Reply to 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