python批量替换数值_通过python批量修改mxd的数据源

importarcpy, os

#

该文件夹下的

mxd

将批量执行

mxdFolderPath = r"C:\temp\GJHY-16"

#

'r'

避免被转义

,

\t

#

旧的数据源

#

数据库连接

\orcl.sde

oldDataSources

=

r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\GJHY2.sde"

#

oldDataSources

=

r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Connection

to

127.0.0.1.sde"

#

oldDataSources

=

r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\Connection

to

10.1.4.22.sde"

#

新的数据源

newDataSources

=

r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\GJHY.sde"

#

是否要求新数据源有效

validateNewDataSources = False

saveFolderPath = os.path.join(mxdFolderPath,"save")

if not os.path.exists(saveFolderPath):

os.mkdir(saveFolderPath)

for filename in os.listdir(mxdFolderPath):

fullpath = os.path.join(mxdFolderPath, filename)

ifos.path.isfile(fullpath):

basename, extension = os.path.splitext(filename)

ifextension.lower() == ".mxd":

mxd = arcpy.mapping.MapDocument(fullpath)

printfullpath

#debug

print "====================

更改前:

====================="

brknList = arcpy.mapping.ListBrokenDataSources(mxd)

print "BrokenDataSources

个数

:%d" % len(brknList)

print "

【数据源损坏的图层】

"

iflen(brknList)>0:

forlyr in brknList:

print "- " + lyr.name

print "\t" + lyr.dataSource

# print "

【所有图层】

"

# forlyr in arcpy.mapping.ListLayers(mxd):

#

print "- " + lyr.name

#

iflyr.supports("DATASOURCE"):

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值