Arcpy.mapping 现在更改为 arcpy.mp
此示例说明了如何使用 ArcGIS Desktop 引用图层的标注类。
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Yosemite National Park")[0]
for lyr in arcpy.mapping.ListLayers(mxd, df):
if lyr.supports("SHOWLABLES"):
lblClasses = lyr.labelClasses
此示例说明了如何使用 ArcGIS Pro 引用图层的标注类。
p = arcpy.mp.ArcGISProject("CURRENT")
m = p.listMaps("Yosemite National Park")[0]
for lyr in m.listLayers():
if lyr.supports("SHOWLABELS"):
lblClasses = lyr.listLabelClasses()
======================
aprx = arcpy.mp.ArcGISProject("CURRENT") for m in aprx.listMaps(): print("Map: " + m.name) for lyr in m.listLayers(): print(" " + lyr.name) print("Layouts:") for lyt in aprx.listLayouts(): print(f" {lyt.name} ({lyt.pageHeight} x {lyt.pageWidth} {lyt.pageUni
布局示例 2
下面的脚本会通过缩放至每个属于名为约塞米蒂国家公园的地图的书签来更新地图框的感兴趣区域,并将结果导出至各个 PDF 文档。
import arcpy, os
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
lyt = aprx.listLayouts("Main Attractions*")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT", "Yosemite National Park*")[0]
bkmks = mf.map.listBookmarks()
for bkmk in bkmks:
mf.zoomToBookmark(bkmk)
lyt.exportToPDF(os.path.join(r"C:\Projects\YosemiteNP", f"{bkmk.name}.pdf"))
del aprx
布局示例 3
下面的脚本将检查是否存在地图系列,然后将其两个页面导出为 PDF。
import arcpy
import os
import sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(relpath + "\\MapSeries\\US_States.aprx")
l = p.listLayouts()[0]
if not l.mapSeries is None:
ms = l.mapSeries
if ms.enabled:
ms.currentPageNumber = ms.getPageNumberFromName("Rhode Island")
ms.exportToPDF(relpath + "\\Output\\Ex1_RI.pdf", "CURRENT", resolution=300)
ms.currentPageNumber = ms.getPageNumberFromName("Washington")
ms.exportToPDF(relpath + "\\Output\\Ex1_WA.pdf", "CURRENT")