通过arcgis数据驱动页面可以输出要素类中每一个要素对应的图片,但是有部分需求如下:输出每一个要素图片,且图片上只能显示该要素,与其相邻或者相交的要素不可显示。
通过arcpy代码实现如下:
# coding=utf-8
import arcpy
mxd = arcpy.mapping.MapDocument(r"F:\map.mxd")
lyr = arcpy.mapping.ListLayers(mxd)[0]
df = arcpy.mapping.ListDataFrames(mxd)[0]
rows = arcpy.SearchCursor(lyr)
for row in rows:
geo = row.shape
print geo.extent
df.panToExtent(geo.extent)
outFile = r"F:\output\\"+ row.getValue("SEARCHNO")+".tif"
query = "SEARCHNO = '" + row.getValue("SEARCHNO")+"'"
lyr.definitionQuery = query
print lyr.definitionQuery
arcpy.mapping.ExportToJPEG(mxd, outFile, "PAGE_LAYOUT", 400)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
其中
query = "SEARCHNO = '" + row.getValue("SEARCHNO")+"'"
lyr.definitionQuery = query
的目的是过滤其他要素代码