赞
踩
哈喽~大家好,因为最近工作需要把mxd中的数据导成tif格式图片,我查了一下关于arcpy库的相关用法并已解决批量导图,此代码支持导出tif,png,jpg,pdf格式,现将方法分享出来,希望能够帮助有需要的朋友,如果此方法帮助到你麻烦点赞关注哟~
1. 打开arcgis中的IDLE(python GUI)
2.点击File-----open;选择要执行的代码
3、点击Run-----Run Module运行代码
等待几秒钟后按照提示输入路径、导出格式、分辨率;等待执行完成即可。
5、哈哈~终于到了最重要的一步,代码如下,如有不足之处希望请联系我指正哟~
- # arcgis批量导图
-
- import arcpy,os
-
- path = raw_input('请输入处理数据路径:')
- title = raw_input('请输入导出格式【PDF,JPEG,PNG,TIFF,GIF】:')
- res = int(input('请输入导出分辨率:'))
- print('-------------程序开始运行--------------')
- count = 0
- for i in os.listdir(path):
- if i[-3:].lower() == 'mxd' and title == 'TIFF':
- count += 1
- print('-----正在导出tif格式,第'+str(count)+'张图片-----')
- mxd = arcpy.mapping.MapDocument(os.path.join(path,i))
- arcpy.mapping.ExportToTIFF(mxd,os.path.join(path,i[:-3] + 'tif'),resolution = res)
- del mxd
- elif i[-3:].lower() == 'mxd' and title == 'PDF':
- count += 1
- print('-----正在导出PDF格式,第'+str(count)+'张图片-----')
- mxd = arcpy.mapping.MapDocument(os.path.join(path,i))
- arcpy.mapping.ExportToPDF(mxd,os.path.join(path,i[:-3] + 'pdf'),resolution = res)
- del mxd
- elif i[-3:].lower() == 'mxd' and title == 'JPEG':
- count += 1
- print('-----正在导出jpg格式,第'+str(count)+'张图片-----')
- mxd = arcpy.mapping.MapDocument(os.path.join(path,i))
- arcpy.mapping.ExportToJPEG(mxd,os.path.join(path,i[:-3] + 'jpg'),resolution = res)
- del mxd
- elif i[-3:].lower() == 'mxd' and title == 'PNG':
- count += 1
- print('-----正在导出png格式,第'+str(count)+'张图片-----')
- mxd = arcpy.mapping.MapDocument(os.path.join(path,i))
- arcpy.mapping.ExportToPNG(mxd,os.path.join(path,i[:-3] + 'png'),resolution = res)
- del mxd
-
- print('-------------程序结束运行--------------')

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。