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
  • 我的个人资料
  • 登出

帮助

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

InsertLayer

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

摘要

可用于将图层插入到数据框或地图文档 (.mxd) 中的图层组内的特定位置处。

讨论

因使用了参考图层来指定准确位置,InsertLayer 可在数据框或图层组中更为精确地定位图层。可在参考图层之前或之后添加图层。

如果参考图层参考了位于数据框根级的图层,那么所插入的图层将添加到数据框的根级中。如果参考图层参考了图层组中的图层,则所插入的图层将添加到该图层组中。因为参考图层为必需参数,所以无法使用 InsertLayer 将图层添加到空数据框或空图层组中。AddLayer 或 AddLayerToGroup 函数则可分别将图层添加到空数据框或图层组中。

插入的图层必须参考已存在的图层(请注意,图层也可以是图层组)。源图层可以来自磁盘上的图层文件、同一地图文档和数据框、同一地图文档不同数据框乃至完全独立的地图文档。

添加图层后,图层在内容列表 (TOC) 中的显示方式取决于源图层及其显示方式。例如,在 TOC 中,有些图层完全折叠且不显示其符号。此设置内置在图层中。如果图层折叠且保存在图层文件中,然后被添加到地图文档中,则通过 InsertLayer 添加该图层时,图层在新的地图文档中将显示为折叠状态。

语法

InsertLayer (data_frame, reference_layer, insert_layer, {insert_position})
参数说明数据类型
data_frame

A reference to a DataFrame object into which the new layer will be inserted.

DataFrame
reference_layer

A Layer object representing an existing layer that determines the location where the new layer will be inserted.

Layer
insert_layer

A reference to a Layer object representing the layer to be inserted.

Layer
insert_position

A constant that determines the placement of the added layer relative to the reference layer.

  • AFTER —Inserts the new layer after or below the reference layer
  • BEFORE —Inserts the new layer before or above the reference layer

(默认值为 BEFORE)

String

代码实例

InsertLayer 示例 1:

以下脚本会插入来自磁盘上的图层文件 (.lyr) 中的新图层,并将其放置于 County Maps 数据框内名为 Lakes 的图层前。

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0]
refLayer = arcpy.mapping.ListLayers(mxd, "Lakes", df)[0]
insertLayer = arcpy.mapping.Layer(r"C:\Project\Data\Rivers.lyr")
arcpy.mapping.InsertLayer(df, refLayer, insertLayer, "BEFORE")
mxd.saveACopy(r"C:\Project\Project2.mxd")
del mxd, insertLayer
InsertLayer 示例 2:

以下脚本将插入一个来自其他独立地图文档的名为 Rivers 的图层,并将其插入到 County Maps 数据框内名为 Lakes 的图层上方。

import arcpy

#Reference layer in secondary map document
mxd2 = arcpy.mapping.MapDocument(r"C:\Project\ProjectTemplate.mxd")
df2 = arcpy.mapping.ListDataFrames(mxd2, "Layers")[0]
insertLayer = arcpy.mapping.ListLayers(mxd2, "Rivers", df2)[0]

#Insert layer into primary map document
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0]
refLayer = arcpy.mapping.ListLayers(mxd, "Lakes", df)[0]
arcpy.mapping.InsertLayer(df, refLayer, insertLayer, "BEFORE")

#Save to a new map document and clear variable references
mxd.saveACopy(r"C:\Project\Project2.mxd")
del mxd, mxd2, insertLayer
有关此主题的反馈?

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. | 隐私政策 | 法律声明