Résumé
The Symbol class provides access to basic symbol properties and methods.
Discussion
The Symbol class represents a symbol that is associated with a renderer. This class exposes a basic, generic set of helper members that can be applied to point, line, and polygon symbols. The easiest way to update a symbol is to use the applySymbolFromGallery method. You can change a symbol to use an existing, named symbol that is in a symbol gallery saved with the project.
The color and outlineColor properties return a Python dictionary. The dictionary has a single key that matches the color model name, and the value is a list of color properties. For example, here is the RGB representation of red: {'RGB' : [255, 0, 0, 100]}. The properties change depending on the color model. The last parameter for all color models is an alpha or opacity value. The alpha or opacity value behaves the opposite way as transparency in the application user interface. If you set this value to 100 in the dictionary, it will appear as a 0% in the transparency control on the ribbon or in the Symbology pane.
You can read the value of all supported color models, but you can only modify a subset. The following is a list of supported color models:
- {'CMYK' : [Cyan, Magenta, Yellow, Black, Alpha]}—Read/Write
- {'HSL' : [Hue, Saturation, Lightness, Alpha]}—Read/Write
- {'HSV' : [Hue, Saturation, Value, Alpha]}—Read/Write
- {'RGB' : [Red, Green, Blue, Alpha]}—Read/Write
- {'Lab' : [Lightness, a, b, Alpha]}—Read-only
- {'Grayscale' : [Gray, Alpha]}—Read-only
Propriétés
Propriété | Explication | Type de données |
angle (Lecture et écriture) | Gets and sets the rotation value of a point symbol. | Double |
color (Lecture et écriture) | Gets and sets the color of a point, line, or polygon symbol using a Python dictionary. | Dictionary |
name (Lecture seule) | Gets the name associated with the symbol. A valid value is only available if a symbol is referenced using the listSymbolsFromGallery method. | String |
outlineColor (Lecture et écriture) | Gets and sets the outline color of a symbol using a Python dictionary. | Dictionary |
outlineWidth (Lecture et écriture) | Gets and sets the outline width of a symbol. | Double |
size (Lecture et écriture) | Gets and sets the size of a point symbol, the width of a line symbol, or the outline width of a polygon symbol. | Double |
useRealWorldUnits (Lecture et écriture) | Gets and sets whether the symbol size properties are rendered using real world units or page units. When set to True, the symbol will draw using real world units, for example, meters. | Boolean |
Vue d’ensemble des méthodes
Méthode | Explication |
applySymbolFromGallery (wildcard, {index}) | applySymbolFromGallery provides a mechanism to set a symbol to one that exists in a system or project style gallery. |
listSymbolsFromGallery ({wildcard}) | listSymbolsFromGallery provides a mechanism to return a list of symbols that exists in a system or project style gallery. |
Méthodes
applySymbolFromGallery (wildcard, {index})
Paramètre | Explication | Type de données |
wildcard | A string used to find symbols based on the symbol name or tag value. A partial word search works. (La valeur par défaut est None) | String |
index | A list index value based on the number of possible symbols that are returned with the same name. (La valeur par défaut est 0) | Integer |
It is possible to have multiple symbols in a project with the same name. It is important that you author your project with symbol names that can be easily searched using a unique value. An index number can be used to return a specific symbol. For example, there are multiple point symbols called Airport. The index corresponds to the order you see the symbols in the gallery. If you wanted to reference the second symbol, try, for example, airportSym = symbol.applySymbolFromGallery('Airport', 1).
listSymbolsFromGallery ({wildcard})
Paramètre | Explication | Type de données |
wildcard | A string used to find symbols based on the symbol name or tag value. A partial word search works. (La valeur par défaut est None) | String |
You may not always know the index value to use, because different projects may have different collections of symbols. The listSymbolsFromGallery method can be used for this purpose. It allows you to iterate through the symbols with a common name and interrogate individual symbol properties such as size or color so you can identify which specific symbol to reference.
Exemple de code
The following script applies a symbol called Extent Transparent from a gallery in the project to a polygon layer. Next, it alters a few of the symbol properties such as color (using the RGB color model), outlineColor (using the CMYK color model), and size.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(os.path.join(relpath, "Symbol.aprx"))
m = p.listMaps('Map')[0]
lyr = m.listLayers("Study Areas")[0]
sym = lyr.symbology
sym.renderer.symbol.applySymbolFromGallery("Extent Transparent Wide Gray")
sym.renderer.symbol.color = {'RGB' : [255, 0, 0, 60]}
sym.renderer.symbol.outlineColor = {'CMYK' : [25, 50, 75, 25, 100]}
sym.renderer.symbol.size = 3
lyr.symbology = sym
p.saveACopy(os.path.join(relpath, "SavedOutput.aprx"))
The following script iterates through symbols in the gallery that have a common name. It isolates the symbol of interest based on the size property and applies that symbol to the layer.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(os.path.join(relpath, "Symbol.aprx"))
m = p.listMaps('Map')[0]
lyr = m.listLayers("Airports")[0]
sym = lyr.symbology
if sym.renderer.type == "SimpleRenderer":
airportSymList = sym.renderer.symbol.listSymbolsFromGallery("Airport")
for symbol in airportSymList:
if symbol.size == 14.0:
sym.renderer.symbol = symbol
lyr.symbology = sym
p.saveACopy(os.path.join(relpath, "SavedOutput.aprx"))
Vous avez un commentaire à formuler concernant cette rubrique ?