地图制图与输出

实验内容

代码

1 创建布局元素的列表

import arcpy.mapping as mapping
mxd = mapping.MapDocument(r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.mxd")
for el in mapping.ListLayoutElements(mxd):
    if el.name != "":
        print(el.name)

2 限制返回的布局元素

import arcpy.mapping as mapping
mxd = mapping.MapDocument(r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.mxd")
for el in mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT","*Crime*"):
    print(el.name)

3 更新布局元素的属性

import arcpy.mapping as mapping
mxd = mapping.MapDocument(r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.mxd")
elLeg = mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT","*Crime*")[0]
elLeg.title = "Crime by School District"
for item in elLeg.listLegendItemLayers():
    print(item.name)

4 导出地图为PDF文件

import arcpy.mapping as mapping
mxd = mapping.MapDocument(r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.mxd")
mapping.ExportToPDF(mxd,r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.pdf")
print("Export Done")

5 导出地图为图像文件

import arcpy.mapping as mapping
mxd = mapping.MapDocument(r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.mxd")
for df in mapping.ListDataFrames(mxd):
    if df.name == "Crime":
        mapping.ExportToJPEG(mxd,r"E:\ArcPyStudy\Data\ArcpyBook\Ch2\Crime_Ch2_new.jpg",df)
print("Export Done")