-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_datasource_paths.py
46 lines (35 loc) · 1.28 KB
/
change_datasource_paths.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
Tool: Change Datasource Paths
Source: change_datasource_paths.py
Author: [email protected]
License: X/MIT, (c) 2011 Environment Yukon
When data has moved to a different workspace AND feature dataset the regular
`findAndReplaceWorkspacePath` does not work. This script rectifies that.
Required Arguments:
- layer file to re-path
- new path to workspace containing the feature class
- where to save the layer files
More information:
http://gis.stackexchange.com/questions/6884/change-data-source-path-in-lyr-files-in-arcgis-10
'''
import arcpy, os
# layer file to re-path
fname = arcpy.GetParameterAsText(0)
# new path to workspace containing the feature class
target_wspace = arcpy.GetParameterAsText(1)
# where to save the layer files
savedir = arcpy.GetParameterAsText(2)
lyr = arcpy.mapping.Layer(fname)
fixed_fname = os.path.join(savedir, lyr.longName)
print '\nOld layer properties (%s)' % (fname)
print 'workspace:\t', lyr.workspacePath
print 'full path:\t', lyr.dataSource
try:
lyr.replaceDataSource(target_wspace, 'FILEGDB_WORKSPACE', lyr.datasetName, True)
lyr.saveACopy(fixed_fname)
except:
print arcpy.GetMessages()
print '\nNew layer properties (%s)' % (fixed_fname)
print 'workspace:\t', lyr.workspacePath
print 'full path:\t', lyr.dataSource
del lyr