ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

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

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS Developers

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

ArcGIS Solutions

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

ArcGIS Marketplace

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

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

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

MaskLayer

获得 Production Mapping 许可后可用。

  • 描述
  • 讨论
  • 语法
  • 代码示例

描述

Configures and applies layer masking settings for a specific data frame.

讨论

Masking features can be useful when there is text on a map or chart that is obscured by other features or symbology. With grids and graticules layers, masking can be used to hide gridlines when annotation appears inside the grid.

Grid annotation before masking has been applied
Grid annotation before masking has been applied
Grid annotation after masking has been applied
Grid annotation after masking has been applied
注:

To use symbol levels with this function, symbol-level drawing must be enabled on the layer before execution. This setting is found on the layer's Symbology tab. The location of this setting varies, depending on the renderer that is used. A 0 represents the bottommost symbol layer.

语法

MaskLayer (data_frame, operation, masking_layer, masked_layer, {symbol_levels})
参数说明数据类型
data_frame

The DataFrame object that will have masking applied.

DataFrame
operation

Indicates whether a masking and masked layer relationship are added or removed from the masking settings:

  • APPEND—Adds a layer setting to the layer masking settings
  • REMOVE—Removes a layer setting from the layer masking settings. This option removes the masked layer entirely and all the related symbol levels.
String
masking_layer

The Layer object that will mask the masked layer. The polygons in this layer will be used to hide parts of the masked layer.

Layer
masked_layer

The Layer object that will be masked by the masking layer. The features in this layer will be hidden by the polygons from the masking layer.

Layer
symbol_levels
[symbol_levels,...]

A list of symbol levels (layers) that will be hidden from the masked layer.

String

代码示例

MaskLayer example 1

This sample masks annotation layers in a map.

import arcpy
import arcpyproduction

# Check out Production Mapping license
arcpy.CheckOutExtension("Foundation")

# Load map and get active from the map
mxd = arcpy.mapping.MapDocument(r'C:\project\masking\MaskingExamples.mxd')
df = mxd.activeDataFrame

# Get list of the data frame layers
layers = arcpy.mapping.ListLayers(df)

# Get sample layers
highways_layer = layers[2]
rivers_layer = layers[3]

# Get masked layer
mask_layer = layers[4]

# Enable masking on the data frame
arcpyproduction.mapping.EnableLayerMasking(df,'true')

# Mask layer annotation layer
arcpyproduction.mapping.MaskLayer(df, 'APPEND', mask_layer, highways_layer) # fully hide highways
arcpyproduction.mapping.MaskLayer(df, 'APPEND', mask_layer, rivers_layer, "1") # partilly hide rives

# Save updated map
mxd.save()

# Check in Production Mapping license
arcpy.CheckInExtension("Foundation")
MaskLayer example 2

This sample enables masking on some layers and disables masking on others.

import arcpy
import arcpyproduction

# Check out Production Mapping license
arcpy.CheckOutExtension("Foundation")

# Load map and get active from the map
mxd = arcpy.mapping.MapDocument(r'C:\project\masking\MaskingExamples.mxd')
df = mxd.activeDataFrame

# Get list of the data frame layers
layers = arcpy.mapping.ListLayers(df)

# Get masked layer
mask_layer = layers[4]

# Enable masking on the data frame
arcpyproduction.mapping.EnableLayerMasking(df,'true')

# Find all polyline layers and mask them and unmask all other feature layers
for layer in layers:
    if layer.isFeatureLayer:
        if 'Polyline' == arcpy.Describe(layer.dataSource).shapeType:
            arcpyproduction.mapping.MaskLayer(df, 'APPEND', mask_layer, layer)
        elif (mask_layer != layer): # masked and masking layer cannot be the same
            arcpyproduction.mapping.MaskLayer(df, 'REMOVE', mask_layer, layer)

# Save updated map
mxd.save()

# Check in Production Mapping license
arcpy.CheckInExtension("Foundation")
MaskLayer example 3

This sample masks annotation features inside the grid. Mask features are used as the masking layer, and the gridline is used for the masked layer.

import arcpy
import arcpyproduction

# for testing
#arcpy.env.overwriteOutput=True

# Check out Production Mapping license
arcpy.CheckOutExtension("Foundation")

# Define variables
mxd = arcpy.mapping.MapDocument(r'C:\project\masking\ClipDataFrameTest.mxd')
df = arcpy.mapping.ListDataFrames(mxd)[0]
anno_layer = arcpy.MakeFeatureLayer_management(r'C:\project\masking\Grids.gdb\NAD_83\ANO_NAD_83_500000')
anno_masks = r'C:\project\masking\Grids.gdb\AnnoMasks'
gridline_layer = arcpy.mapping.ListLayers(mxd,"GLN_NAD_83",df)[0]

# Create masks from the grid annotation features and create layer object
masks=arcpy.FeatureOutlineMasks_cartography(anno_layer,r'C:\project\masking\Grids.gdb\AnnoMasks','250000',arcpy.SpatialReference(3719),'10','CONVEX_HULL','ALL_FEATURES')
anno_mask_layer=arcpy.mapping.Layer(masks.getOutput(0))

# Add masks to map and create masking layer
arcpy.mapping.AddLayer(df, anno_mask_layer,'BOTTOM')
masking_layer = arcpy.mapping.ListLayers(mxd,anno_mask_layer.name,df)[0]

# Enable masking on the first data frame
arcpyproduction.mapping.EnableLayerMasking(df,'ENABLE')

# Mask the gridline features with the masking features
arcpyproduction.mapping.MaskLayer(df,'APPEND',masking_layer,gridline_layer)

# Save MXD
mxd.save()

# Check in Production Mapping license
arcpy.CheckInExtension("Foundation")

相关主题

  • EnableLayerMasking
  • 使用掩膜
  • 使用符号级别绘制
  • Introduction to arcpyproduction.mapping

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2021 Esri. | 隐私政策 | 法律声明