StyleItem (arcpy.mapping)

摘要

可以对 StyleItem 类属性进行访问。

讨论

您所选择的用于显示地图中的要素、元素或图形的符号都存储在样式文件 (.style) 中。您可以使用样式管理器 对话框来创建、查看和修改样式及其内容。样式被组织为一组预定义的类别或文件夹,例如颜色图例项标记符号比例尺。单个样式项目存储在具体的类别或文件夹中。例如,图例项文件夹包含了多个不同的图例项样式项目,每个项目具有不同的格式、字号和字型,对应于图例项中显示的不同元素。

引入的 StyleItem 类可满足基本的 arcpy.mapping 要求,以便可以使用自定义设置更新图例项样式项目。在用户界面中,当您向内容列表中添加一个新的图层并且该要素被自动添加到图例中时,将应用默认样式。通过 arcpy.mapping 模块,您可以在 LegendElement 中更新页面布局的各图例项样式项目。具体可通过以下工作流实现。

属性

属性说明数据类型
itemName
(只读)

A string that represents the name of the item the way it appears in the Style Manager dialog box window.

String
itemCategory
(只读)

A string that represents the category of the item the way it appears in the Style Manager dialog box window. Categories are used to group symbols within a style.

String
styleFolderName
(只读)

A string that represents the name of the folder the StyleItem is stored in, for example, Legend Items. Identifying the styleFolderName allows you to determine the type of the style object you have referenced.

String

代码实例

StyleItem 示例

以下脚本将使用上述工作流程并更新图例的图例项样式。将向地图文档中的第一个数据框添加一个图层,并通过名为 NewDefaultLegendStyle 的自定义图例项样式项目更新该图例项样式项目。自定义 .style 文件保存在用户配置文件所在的位置中。

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyrFile = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr")
arcpy.mapping.AddLayer(df, lyrFile, "TOP")
lyr = arcpy.mapping.ListLayers(mxd, 'Rivers', df)[0]
styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items", "NewDefaultLegendStyle")[0]
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
legend.updateItem(lyr, styleItem)
del mxd
5/10/2014