0

I am a Python newbie and I'm trying to repair the data source for an aerial raster in close to 50 individual map documents.

My supervisor deleted the 2014 recently and uploaded the 2015 in its place. The new raster is in the same workspace and has virtually the same path, just a different name.

This is the template I was working with from ArcGIS resources. How would I need to modify it for the task at hand?

import arcpy
mxd = arcpy.mapping.MapDocument("C:\Project\Project.mxd") #I'd like to create a list

for lyr in arcpy.mapping.ListLayers(mxd):
      if lyr.dataSource == (r"C:\Project\Data\Aerial\SID_2014"):
        lyr.replaceDataSource(r"C:\Data\Aerial\SID_2015", "SHAPEFILE_WORKSPACE", "SID_2015")

1 Answer 1

1

I would try this:

import arcpy
mxd = arcpy.mapping.MapDocument("C:\Project\Project.mxd") #I'd like to create a list

for lyr in arcpy.mapping.ListLayers(mxd):
      if lyr.dataSource == (r"C:\Project\Data\Aerial\SID_2014"):
        lyr.replaceDataSource(r"C:\Data\Aerial\SID_2015", "SHAPEFILE_WORKSPACE", "SID_2015")
mxd.save()

At the moment you are making changes to layer properties in your MXD but not saving that MXD.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.