操作方法

操作方法:使用 Python 在 ArcGIS Pro 中为布局配置图例项

Last Published: October 22, 2021

摘要

在 ArcGIS Pro 中,可以从图例属性的“图例项目”窗格中选择要在布局图例中显示的类别,如下图所示。

配置图例属性时,ArcGIS Pro 中的“图例项目”窗格

但是,在 ArcPy 中,LegendItem 类不包含用于选择要显示的类别的方法。 有关详细信息,请参阅 ArcGIS Pro:LegendItem。 要启用类别选择,必须在脚本中使用 Python 制图信息模块 (CIM),本文将介绍执行此操作的步骤。

过程

  1. 设置所需工作空间。
p = arcpy.mp.ArcGISProject('current') lyt = p.listLayouts()[0]
  1. 获取布局 CIM 定义。
lyt_cim = lyt.getDefinition('V2')
  1. 遍历所有布局元素以找到 Legend 元素。
for elm in lyt_cim.elements: if elm.name == "Legend": #Legend item changes for itm in elm.items: if itm.name == "GreatLakes": #Update visibility itm.showLayerName = True itm.showHeading = False itm.showGroupLayerName = False
  1. 将 CIM 更改设置回布局
lyt.setDefinition(lyt_cim)

以下代码块演示了完整脚本。

p = arcpy.mp.ArcGISProject('current') lyt = p.listLayouts()[0] #Get the layout's CIM definition lyt_cim = lyt.getDefinition('V2') for elm in lyt_cim.elements: if elm.name == "Legend": #Legend item changes for itm in elm.items: if itm.name == "GreatLakes": itm.showLayerName = True itm.showHeading = False itm.showGroupLayerName = False itm.showLabel = True lyt.setDefinition(lyt_cim)

文章 ID:000026663

从 ArcGIS 专家处获得帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项

相关信息

发现关于本主题的更多内容