Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

arcpy: changing lyr data source (raster layers)

$
0
0

I am trying to create a lyr file for each raster file in a folder.
To get exact same display settings I thought I would create a lyr file, then, using arcpy copy-paste it for each file in folder and change the data sources.

The script generates new lyr files but does not change data sources – and gives no error. So, what am I doing wrong?

import arcpy
lyrFile = arcpy.mapping.Layer(r"C:temprstsample.lyr")
arcpy.env.workspace=r"C:temprst"
for i in arcpy.ListDatasets(): 
lyrFile.replaceDataSource(lyrFile.workspacePath,"RASTER_WORKSPACE",i)
lyrFile.saveACopy(lyrFile.workspacePath+i)

Viewing all articles
Browse latest Browse all 767

Trending Articles