Label
Esri ArcMap must be opened, the file used in this example will be the KY_Railroad file and it should be visible on the map. This file contains railroads located in the Commonwealth of Kentucky and is the only required information for this example. Additional files such as a state or county map of Kentucky might be useful. For this example, an online background map should not be used because it will obscure the data being displayed and modified.
Steps for Simple Labeling using Python Script
|
|
When the attributes of the railroad file are displayed, they will be abbreviated; not the full name. If the abbreviated names are used on a map, the user might not know what the abbreviated name means for all the railroads. For example, while a national railroad line like CN (Canadian National) might be known, a regional line like PAL (Paducah and Louisville) might not. Therefore, on the produced map, the names displayed should be the full name and not the abbreviated name.
Additional Elif statements could be written for other railroads in Kentucky, review the attributes to see what other railroads are contained in the file. In the code shown in the first column of the table, two new commands are introduced. The def statement is a defining function. There must be a colon placed at the end of the statement. In this code, the FindLabel statement is used to locate the field named RROWNER as long as the indention is used. FindLabel is a reserved name for the label window. The other statement was the return statement. In many ways, this statement is similar to a print command, which shows a value on the console. With the Return command, the value is added to the map.
The result of running the expression is displayed in Figure 4.
Note; that there are tracks labeled: Unknown, Paducah and Louisville and Canadian National, only a small part of the state is visible. No content has been changed in the attribute table only how the information is displayed has been modified.
Additional Elif statements could be written for other railroads in Kentucky, review the attributes to see what other railroads are contained in the file. In the code shown in the first column of the table, two new commands are introduced. The def statement is a defining function. There must be a colon placed at the end of the statement. In this code, the FindLabel statement is used to locate the field named RROWNER as long as the indention is used. FindLabel is a reserved name for the label window. The other statement was the return statement. In many ways, this statement is similar to a print command, which shows a value on the console. With the Return command, the value is added to the map.
The result of running the expression is displayed in Figure 4.
Note; that there are tracks labeled: Unknown, Paducah and Louisville and Canadian National, only a small part of the state is visible. No content has been changed in the attribute table only how the information is displayed has been modified.
Advanced Labels
In the previous example, Python Code was placed in the expression window. In the Label Expression window, Python scripts can have embedded code. Xml code is commonly used in web page design. The xml code can be used to control such features as color, font size, font face, along with features such as bold, underline, mark through, etc.
The format for xml code is “<tag>” + text + “</tag>”, xml code always is opened with a < > and closed with </>. To find a list of potential tags that can be used in Esri ArcMap use the following hyperlink: http://desktop.arcgis.com/en/desktop/latest/map/working-with-text/formatting-tags-available-in-arcmap.htm
To explore these advanced labeling features the same code used in the previous example will be the starting point and then modified as seen in the second table. The changes that will be made: The labeling for the Canadian National railroad will be made red and a larger font size than the default font. The labeling for the Paducah and Louisville railroad will be made bold and have a green color.
The only changes that have been made to the two lines for Canadian National railroad and Paducah and Louisville railroad. It is very important to notice in the format on how the brackets are used.
The format for xml code is “<tag>” + text + “</tag>”, xml code always is opened with a < > and closed with </>. To find a list of potential tags that can be used in Esri ArcMap use the following hyperlink: http://desktop.arcgis.com/en/desktop/latest/map/working-with-text/formatting-tags-available-in-arcmap.htm
To explore these advanced labeling features the same code used in the previous example will be the starting point and then modified as seen in the second table. The changes that will be made: The labeling for the Canadian National railroad will be made red and a larger font size than the default font. The labeling for the Paducah and Louisville railroad will be made bold and have a green color.
The only changes that have been made to the two lines for Canadian National railroad and Paducah and Louisville railroad. It is very important to notice in the format on how the brackets are used.
The label for the Canadian National railroad now appears red and that the size of the font is larger than the other labels. In addition, the Paducah and Louisville railroad is green and bold. The boldness is a little hard to discern. The Unknown label was unchanged and the default parameters were used.In both of these label color changes, only a single color was used while the depth of the color was different. It is important to experiment with how using two or three colors together will change the color that is displayed. If all three colors were set to the maximum the color would be white. If all three colors are set to the minimum value, the color is black. For example, pure yellow would be R=255, G=255, B=0. More than 16.5 million colors can be defined using 8 bit RGB. For a better understanding a good website is:
http://rapidtables.com/web/color/Web_Color.htm?T1=255+255+255#color%20table If more than one color is being used after the return statement do not put a comma between the colors. CMYK (cyan, magenta, yellow, black) can also be used, but the scale range is 0 - 100. For example, (partial script) return "< CLR yellow = '95'... |