收藏 分享(赏)

通过python批量修改mxd的数据源.doc

上传人:精品资料 文档编号:10404133 上传时间:2019-11-07 格式:DOC 页数:2 大小:16.94KB
下载 相关 举报
通过python批量修改mxd的数据源.doc_第1页
第1页 / 共2页
通过python批量修改mxd的数据源.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、import arcpy, os#该文件夹下的 mxd 将批量执行mxdFolderPath = r“C:tempGJHY-16“ #加r避免被转义, 如t#旧的数据源 # 数据库连接orcl.sdeoldDataSources = r“C:UsersAdministratorAppDataRoamingESRIDesktop10.0ArcCatalogGJHY2.sde“# oldDataSources = r“C:UsersAdministratorAppDataRoamingESRIDesktop10.0ArcCatalogConnection to 127.0.0.1.sde“# ol

2、dDataSources = r“C:UsersAdministratorAppDataRoamingESRIDesktop10.0ArcCatalogConnection to 10.1.4.22.sde“#新的数据源newDataSources = r“C:UsersAdministratorAppDataRoamingESRIDesktop10.0ArcCatalogGJHY.sde“#是否要求新数据源有效validateNewDataSources = FalsesaveFolderPath = os.path.join(mxdFolderPath,“save“)if not os.p

3、ath.exists(saveFolderPath):os.mkdir(saveFolderPath)for filename in os.listdir(mxdFolderPath):fullpath = os.path.join(mxdFolderPath, filename)if os.path.isfile(fullpath):basename, extension = os.path.splitext(filename)if extension.lower() = “.mxd“:mxd = arcpy.mapping.MapDocument(fullpath)print fullpa

4、th#debugprint “=更改前:=“brknList = arcpy.mapping.ListBrokenDataSources(mxd)print “BrokenDataSources 个数:%d“ % len(brknList)print “【数据源损坏的图层 】:“if len(brknList)0:for lyr in brknList:print “- “ + lyr.nameprint “t“ + lyr.dataSource# print “【所有图层】:“# for lyr in arcpy.mapping.ListLayers(mxd):# print “- “ +

5、lyr.name# if lyr.supports(“DATASOURCE“):# print “t“ + lyr.dataSource# else:# print “t *该图层无 dataSource 属性。“# 修改数据源mxd.findAndReplaceWorkspacePaths(oldDataSources,newDataSources,validateNewDataSources)print “=更改后:=“ #debugbrknList = arcpy.mapping.ListBrokenDataSources(mxd)print “BrokenDataSources 个数:

6、%d“ % len(brknList)print “【数据源损坏的图层 】:“if len(brknList)0:for lyr in brknList:print “- “ + lyr.nameprint “t“ + lyr.dataSource # print “【所有图层】:“# for lyr in arcpy.mapping.ListLayers(mxd):# print “- “ + lyr.name# if lyr.supports(“DATASOURCE“):# print “t“ + lyr.dataSource# else:# print “t *该图层无 dataSour

7、ce 属性。“# 保存 -注意:存为副本后,由副本再次存为副本会报错# mxd.save() # newFilePath = filename.replace(“.mxd“,“_new.mxd“)newFilePath = os.path.join(saveFolderPath,filename)print “保存至: %s“ %newFilePathif os.path.exists(newFilePath):os.remove(newFilePath)# mxd.saveACopy(newFilePath)mxd.saveACopy(newFilePath,“10.0“)del mxdprint “OK!“

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报