Summary
Creates polygon masks for features based on color rules.
Note:
A product file installer is available for ArcGIS Production Mapping and ArcGIS Defense Mapping. The product files contain predefined XML masking rule files that can be used for cartographic production.
Learn more about Defense Mapping product files and Production Mapping product files.
Usage
This tool will process the rule file and for each rule, find the intersection of symbolized features based on the colors or symbol parts defined in the rule. It will create a masking polygon at the intersection of the symbolized features. The rule file allows for storing masks in multiple feature classes.
The color rules are defined in an XML file. A rule specifies that symbolized features of a particular color be masked by a source feature that has a particular color.
The following example rule is based on a map specification that dictates that a mask will be created for any location where the outline of a black symbol (color of 0,0,0,100 CMYK) intersects a piece of black annotation.
<RuleGroup> <!-- CMYK Feature Masks --> <Mask Size=".1" Units="Points" Type="Box"/> <Source SymbolPart="Text_Only" LayerType="AnnotationLayer"/> <Target SymbolPart="Outline_Only" LayerType="FeatureLayer"/> <TargetExclusions></TargetExclusions> <Rules> <Rule Name="FeatureMasks_Black_CMYK_1pt"> <MaskFeatureClass>FeatureMasks_Black_CMYK_1pt</MaskFeatureClass> <Source Color="0,0,0,100"/> <Targets> <Target Color="0,0,0,100"/> </Targets> </Rule> </Rules> </RuleGroup>
The size of the mask that will be generated is dependent on the map scale. Ensure that you have set an appropriate reference scale on your map or zoomed the map to the desired scale. The scale should match the scale of the output product to which the mask will be applied.
When creating masks for annotation layers, the annotation should be created at the same scale as the output product.
The projection of the map should match the projection of the output product to which the masks will be applied. If the mask features will be stored in an existing feature dataset, the coordinate system of the feature dataset should match the projection of the output product.
The MaskFeatureClass tag in the mask .xml file determines the name of the mask feature class that will be created. If a feature class with the same name already exists in the database chosen for the output feature dataset, the feature class will be deleted and re-created. Masks will not be appended to existing feature classes.
Masks will be created for all layers in the chosen map that have symbol parts that use the specified colors. To prevent masks from being created for a specific layer, add the name of the layer to the Target Exclusions tag.
Syntax
arcpy.topographic.MakeMasksFromRules(in_map, rule_file, out_feature_dataset)
Parameter | Explanation | Data Type |
in_map | The input map containing symbolized features. | Map |
rule_file | The XML file containing rules that define how features should be masked based on colors and symbol parts. | File |
out_feature_dataset | The output feature dataset. The tool will create a feature dataset containing polygon feature classes that will be used for masking. The spatial reference for the feature dataset will be taken from the map for which masks are generated. | Feature Dataset |
Code sample
The following stand-alone script demonstrates how to create masks for annotation features based on the rules defined in the rule XML file.
# Name: MakeMasksFromRules_sample.py
# Description: This script creates masks for annotation features based on the rules defined in the rule xml file
# Import System Modules
import arcpy
# Check Out Extensions
arcpy.CheckOutExtension('Foundation')
# Setting the environment
arcpy.env.overwriteOutput = True
# Setting Local Variables
in_map = r'C:\Data\NewZealandHistoricBuildings.mapx'
rule_file = r'C:\Data\NewZealandHistoricBuildingAnno_Masking_Rules.xml'
out_feature_dataset = r'C:\Data\Label_your_map.gdb\Masks'
# Calling the Make Masks From Rules to create mask features for the annotation features defined in the rule_file
arcpy.topographic.MakeMasksFromRules(in_map, rule_file, out_feature_dataset)
# Getting all messages, warnings, and errors from the tool run and printing the results back to the user
messages = arcpy.GetMessages(0)
warnings = arcpy.GetMessages(1)
errors = arcpy.GetMessages(2)
arcpy.AddMessage('Tool Messages: {}\nTool Warnings: {}\nTool Errors{}\n'.format(messages, warnings, errors))
# Check In Extensions
arcpy.CheckInExtension('Foundation')
Environments
Licensing information
- Basic: No
- Standard: Requires Production Mapping
- Advanced: Requires Production Mapping