AnsweredAssumed Answered

arcPy findAndReplaceWorkspacePath Won't Update Rasters

Question asked by lloydbronn on Mar 14, 2017
Latest reply on Mar 14, 2017 by rastrauch

I'm using ArcGIS 10.3. I have an MXD that contains symbolized global raster images. I have a GP tool that masks these rasters to a country or state and exports the images. I'm trying to update the source background layers and rasters each time a new country is chosen. The layer names are all generic, but the source files all have the country or state name tagged on.  findAndReplaceWorkspacePath works just fine with the background layers (shapefiles), but it won't update the rasters. I've confirmed the old and new sources with print statements, it's just not changing the source. The only time I get images is if I use the default state (Texas) set in the MXD. If I choose any other location, I just get a blank country or state outline image.

 

Here is my code snippet:

 

layer_list = ["Precip","High_Temp","Temp_Departure"]
for filename in layer_list:
layer_name = filename
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("DATASOURCE"):

if layer_name == str(lyr.name):
old_source = os.path.dirname(lyr.dataSource)
##print old_source + "\\" + layer_name
new_source = country_temp_path
##print new_source + "\\" + layer_name

lyr.findAndReplaceWorkspacePath(old_source, new_source, False)
return()

Outcomes