ArcGIS python代码将所有子目录的相对路径更改为

问题描述 投票:1回答:1

是python的新手,但是在大学里有一些编码经验。当我准备GIS项目数据库以从本地托管过渡到云托管(刚从家中开始工作)时,我试图找到一种方法将每个mxd文件中的路径从绝对更改为相对。我发现了2个代码片段,我认为这些片段可能有效,但无法使它们协同工作。来自ArcGIS的代码仅适用于一个文件夹,我希望它可以在根目录的每个子目录上运行。感谢您的帮助!

ArcGIS Python部分

import arcpy, os

#workspace to search for MXDs
Workspace = r"c:\Temp\MXDs"
arcpy.env.workspace = Workspace

#list map documents in folder
mxdList = arcpy.ListFiles("*.mxd")

#set relative path setting for each MXD in list.
for file in mxdList:
    #set map document to change
    filePath = os.path.join(Workspace, file)
    mxd = arcpy.mapping.MapDocument(filePath)
    #set relative paths property
    mxd.relativePaths = True
    #save map doucment change
    mxd.save()

子目录代码

... from fnmatch import fnmatch
... 
... root = 'C:\\user\projects'
... pattern = "*.mxd"
... 
... for path, subdirs, files in os.walk(root):
...     for name in files:
...         if fnmatch(name, pattern)
...             mxdList = arcpy.ListFiles
...             
python path gis arcgis
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.