【ArcPy】从地图文档MXD出图(PDF或JPG格式)

Python工具代码,非Python窗口脚本,可以自行编辑处理一下。

# coding=gbk
import arcpy
from arcpy import mapping
import os

def main():
    inFolder=arcpy.GetParameterAsText(0)
    outFormat=arcpy.GetParameterAsText(1).lower()
    resolution=arcpy.GetParameter(2)
    outFolder=arcpy.GetParameterAsText(3)    
    for r,dirs,files in os.walk(inFolder):
        for mxdFile in files:
            if mxdFile[-3:].lower()=="mxd":
                arcpy.SetProgressorLabel(u"Exporting {}".format(mxdFile))
                arcpy.AddMessage('>>>正在输出 {} 文档为图件。'.format(mxdFile))
                mxd=mapping.MapDocument(os.path.join(r,mxdFile))
                if outFormat=='jpg':
                    mapping.ExportToJPEG(mxd,os.path.join(outFolder,mxdFile[:-3]+"jpg"),resolution=resolution)
                elif outFormat=='pdf':
                    mapping.ExportToPDF(mxd,os.path.join(outFolder,mxdFile[:-3]+"pdf"))
                del mxd

if __name__ == '__main__':
    main()

 

posted @ 2023-02-12 17:25  yzhyingcool  阅读(167)  评论(0编辑  收藏  举报