arcgis数据驱动根据字段名称自动导出JPG,兼切割栅格图像

下面是导出JPG

import os
import sys
reload(sys) 
sys.setdefaultencoding('utf-8')
... mxd = arcpy.mapping.MapDocument("CURRENT")
... for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...   mxd.dataDrivenPages.currentPageID = pageNum
...   fieldname=u"a"   #修改自己想要的字段,双引号内为字段名称*必填*
...   a=mxd.dataDrivenPages.pageRow.getValue (fieldname)
...   path=r'F:\dr\dltbwl'   
...   if os.path.exists(path):
...     path_2=os.path.join(path,str(a))
...     print(path_2)
...     arcpy.mapping.ExportToJPEG(mxd, path_2 + ".jpg",resolution=400)    # 按 照字段名称出图
...     mxd.saveACopy(path_2 + ".mxd")                           # 按照字段名称 保存mxd
...   else: 
...     print("当前目录下不存在该文件夹,调用 makedirs 创建该文件夹")
...     os.makedirs(path)
...     path_2=os.path.join(path,str(a))
...     print(path_2)
...     arcpy.mapping.ExportToJPEG(mxd, path_2 + ".jpg",resolution=400)
...     mxd.saveACopy(path_2 + ".mxd")
... del mxd

下面的代码可以切割栅格影像 ,原理是根据驱动页面导出多个局部tif栅格

 

 

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
...     mxd.dataDrivenPages.currentPageID = pageNum
...     fieldname=u"ID"
...     a=mxd.dataDrivenPages.pageRow.getValue (fieldname)
...     path=r'F:\dr\dltbwl'
...     path_2=os.path.join(path,str(a))
...     df = arcpy.mapping.ListDataFrames(mxd,)[0]
...     arcpy.mapping.ExportToTIFF(mxd, path_2 + ".tif", df,
...                            df_export_width=1600,
...                            df_export_height=1200,
...                            geoTIFF_tags=True)

效果如下: 

arcgis数据驱动根据字段名称自动导出JPG,兼切割栅格图像_第1张图片

你可能感兴趣的:(数据驱动)