ArcGIS for Desktop

  • 文档
  • 合约
  • 支持

  • My Profile
  • 帮助
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS for Desktop

全面的专业性 GIS

ArcGIS for Server

面向企业的 GIS

ArcGIS for Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 合约
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

帮助

  • 主页
  • 入门
  • 制图
  • 分析
  • 管理数据
  • 工具
  • 更多...

AddLayerToGroup

  • 摘要
  • 讨论
  • 语法
  • 代码实例

摘要

Provides the ability to add a layer to a group layer within a map document (.mxd) using simple placement options.

讨论

AddLayerToGroup is an easy way to add a layer into an already existing group layer. It can add a layer with auto-arrange logic that places the new layer in a group layer similarly to how the Add Data button works in ArcMap; it places the layer based on layer weight rules and geometry type. The other placement choices are either at the top or the bottom of a group layer.

AddLayerToGroup is the only function that can add a layer into an empty group layer. AddLayerToGroup does not allow you to add layers to group layers within a layer file. Layer files should be managed and authored using ArcMap.

The target group layer must be a group layer. The isGroupLayer property on the Layer object is a way of confirming if the returned Layer object is truely a group layer.

The layer that is added must reference an already existing layer (keep in mind that a layer can be a group layer as well). The source can either come from a layer file on disk, from within the same map document and data frame, the same map document but different data frame, or even from a completely separate map document.

The way a layer appears in the table of contents (TOC) after it is added depends on the source layer and how it appears. For example, some layers are completely collapsed and do not display their symbol(s) in the TOC. This setting is built into the layer. If a layer is collasped, saved to a layer file, and then added to a map document, the layer will be collasped in the new map document when added via AddLayerToGroup.

语法

AddLayerToGroup (data_frame, target_group_layer, add_layer, {add_position})
参数说明数据类型
data_frame

A reference to a DataFrame object that contains the group layer to which the new layer will be added.

DataFrame
target_group_layer

A Layer object representing the group layer to which the new layer will be added. It must be a group layer.

Layer
add_layer

A reference to a Layer object representing the layer to be added. This reference can point to a layer file on disk or a layer in a map document.

Layer
add_position

A constant that determines the placement of the added layer within a data frame.

  • AUTO_ARRANGE —Automatically places the layer similar to how the Add Data button works in ArcMap
  • BOTTOM —Places the layer at the bottom of the data frame
  • TOP —Places the layer at the top of the data frame

(默认值为 AUTO_ARRANGE)

String

代码实例

AddLayerToGroup example:

The following script will add a new layer from a layer (.lyr) file on disk and place it at the bottom of a group layer called 24000 Scale Data in a data frame called County Maps.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0]
targetGroupLayer = arcpy.mapping.ListLayers(mxd, "24000 Scale Data", df)[0]
addLayer = arcpy.mapping.Layer(r"C:\Project\Data\StreetsWithLabels.lyr")
arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer, "BOTTOM")
mxd.saveACopy(r"C:\Project\Project2.mxd")
del mxd, addLayer
有关此主题的反馈?

ArcGIS for Desktop

  • 主页
  • 文档
  • 合约
  • 支持

ArcGIS 平台

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • 内部人员博客
  • 用户大会
  • 开发者峰会
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | 隐私政策 | 法律声明