MaskLayer (arcpyproduction.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.
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.
语法
参数 | 说明 | 数据类型 |
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:
| 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 |
代码实例
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")
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")
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")