Exercise: Labels As Symbols
Exercise: Labels As Symbols
MOOC
Exercise
Labels as Symbols
Section 4 Exercise 3
February 2, 2021
Cartography. MOOC
Labels as Symbols
Instructions
Use this guide and ArcGIS Pro to reproduce the results of the exercise on your own.
Note: The version of ArcGIS Pro that you are using for this course may produce slightly
different results from the screen shots that you see in the course materials.
Time to complete
Approximately 50-60 minutes
Software requirements
ArcGIS Pro 2.7
ArcGIS Pro Standard license (or higher)
Note: The MOOC provides a separate ArcGIS account (user name and password) that you
will need to use to license ArcGIS Pro and access other software applications used
throughout the MOOC exercises. This account (user name ending with _cart) provides the
appropriate ArcGIS Online role, ArcGIS Pro license, ArcGIS Pro extensions, and credits.
We strongly recommend that you use the provided course ArcGIS account to ensure that
you have the appropriate licensing to complete the exercises. Exercises may require
credits. Using the provided course ArcGIS account ensures that you do not consume your
organization's credits. Esri is not responsible for any credits consumed if you use a different
account. Moreover, Esri will not provide technical support to students who use a different
account.
Introduction
On a map, labels serve many purposes. Although labels can give cartographers headaches
when map space is scarce, they are important because they designate features, names, and
other characteristics.
In thematic mapping, you use symbols to show differences in amount or type. You might use
proportional symbols to show differences in the quantity of something as it differs from one
place to another. You might use a color scheme ranging from light to dark to show changes in
magnitude between areas or use different hues to show differences in categorical information.
What if you combine all these approaches?
Labels can operate as literal symbols. For instance, you could position a label over an area to
show the data value for that area. Then, there is no need to symbolize the map because the
label indicates data values and spares people from trying to interpret the data values through
symbols. But maybe you could go further. You could give the labels different colors to signify
certain characteristics and size them differently to show other information.
c Extract the files to a folder on your local computer, saving them in a location that you will
remember.
a If necessary, start ArcGIS Pro and sign in using your provided course ArcGIS credentials
(user name ending with _cart).
b From the main ArcGIS Pro start page, click Open Another Project.
c Browse to the location where you saved the exercise data files and open the
LabelsAsSymbols.ppkx project package.
The project opens with the Proportional Labels map active. This map contains a simple
polygon layer of the counties of the United States active. The Contents pane displays two
views of the data: one in the Diverging Hue layer, which is currently turned on, and another in
the Blended Hue layer. Although the layers are symbolized differently, they depict the same
data. This setting is just to give you some context for what you are mapping: the share of the
vote for Republicans and Democrats in the 2016 presidential election.
The diverging and blended hue maps are just two different ways to look at the same dataset.
They show you where greater and lesser shares of votes occurred for the two parties. You will
not use these maps for the final proportional labels, but they can help you understand the
underlying pattern of the data.
Note: If you would like to check your work as you go through this exercise, result layers are
provided in the 2016 US Election map.
d Save your project with a name such as LabelsAsSymbols_<your first and last
name>.aprx in the folder on your computer where you are saving your work.
a If necessary, for the Proportional Labels map, open the Contents pane.
Hint: On the ribbon, click the View tab, and then in the Windows group, click Contents.
b In the Contents pane, open the attribute table for either the Diverging Hue or Blended
Hue layers (both layers point to the same data).
Hint: In the Contents pane, right-click the layer name and choose Attribute Table.
The layer attribute table contains several fields, some of which are described in the following
table:
You can examine the values in the different fields to familiarize yourself with the data that you
will be working with.
a In the Contents pane, right-click the Diverging Hue layer and choose Copy.
b At the top of the Contents pane, right-click the Proportional Labels map item and choose
Paste.
The copied layer is added at the top of the Contents pane, and you now have two Diverging
Hue layers.
Because you will be adding many labels and do not want a conflicting background, you will
create a completely neutral background for the map by symbolizing the layer with a single
symbol.
e In the Contents pane, click the Labels > 60% layer to select it, if necessary.
f From the Feature Layer contextual tab, on the Appearance tab, in the Drawing group,
click the Symbology down arrow and choose Single Symbol.
i In the Appearance section, change Color to No Color, the Outline Color to No Color, and
the Outline Width to 0 pt.
k If necessary, in the Contents pane, turn off the Diverging Hue layer.
You now have a completely blank canvas on which to make your labeled map, with just the
Geography and Coastal_vignette layers visible below the transparent Labels > 60% layer.
Note: If you are zoomed in, you will see the state outlines. For context, you may want to zoom
out so that you see the entire continental United States.
a In the Contents pane, with the Labels > 60% layer selected, click the Labeling tab.
This tab provides access to the core labeling properties of your layer.
c From the Labeling tab, in the Layer group, click Label to activate dynamic labeling on the
layer.
If you wait a short while (you can see the spinning Drawing icon in the bottom-right corner of
the map window that tells you ArcGIS Pro is busy drawing), your labels appear, although they
are currently far from impressive.
Because the drawing of many labels takes time, you can apply a definition query to work on
only a subset of labels.
d In the Contents pane, right-click the Labels > 60% layer and choose Properties.
e In the Layer Properties dialog box, click the Definition Query tab, and then click New
Definition Query.
You have just used an expression to apply a filter to how the map behaves. This technique is a
simple form of specifying an expression using the dialog box.
You can also change the color of your labels and adjust the number of significant figures
shown in the Labeling pane, using Arcade Expressions to modify the properties of the labels.
This ability introduces you to the idea that you can build complex symbology based on
different aspects of the data that cannot be implemented through the default renderers. It
provides the possibility of effectively modifying symbology in any way you want over and
above the out-of-the-box options.
a In a text editor, such as Notepad (Windows) or TextEdit (Mac), open the Expressions1.txt
file from the location on your computer where you saved the exercise data files.
Take a deep breath ... because the file contains code.
Arcade Expressions is a lightweight expression language. Like other expression languages, it
can perform mathematical calculations and evaluate logical statements. It was designed
specifically for creating custom visualizations and labeling expressions in the ArcGIS platform,
and it provides a powerful way to customize your maps.
This course is not about how to code, but coding can be useful in cartography to extend out-
of-the-box functionality. One of the best ways to learn is to look at some code and follow
along.
The following code is listed in the Expressions1.txt file:
Remember that the Continuous_percent field in the attribute table of the data that you are
using to generate labels had both positive and negative values. The column includes the
percentage that Democrats won, with a negative sign in front of the value if Democrats won
the county. The column includes the percentage Republicans won, with no sign in front if
Republicans won the county.
The Continuous_percent field, therefore, holds the winning percentage for each county and
provides a way to determine whether it was Republican or Democratic.
You will use this field to make your labels and show the winning percentage by county across
the map.
However, you do not want to display the negative sign on the finished map. Using logic and
calculation, the code writes a short function to return values that are all in the positive range.
The first part of the code states that if the value in the field is assessed as positive based on
the calculation 50 + continuousValue (the Continuous_percent value), return the value and
return only the numeric values before the decimal point by using a single #.
If you specify '#.#', a single decimal place would be returned and so on. The next part of the
code states that if this calculation is false, the value must be negative.
The calculation 50 - continuousValue (the Continuous_percent value) checks for negative
values and returns just the integer portion of the value.
The final line of code draws the labels.
b In the Contents pane, ensure that the Layers > 60% layer is selected.
c From the Labeling tab, in the Label Class group, next to the Field drop-down list, click the
Expression button .
The Label Class pane opens. You can dock or undock it as desired.
Hint: At the top of the pane, click the Options down arrow and choose Dock.
d In the Label Class pane, from the Class tab, ensure that Language is set to Arcade.
e In your text editor, copy the code from the Expressions1.txt file.
f In the Label Class pane, in the Expression field, paste the code, overwriting any existing
content.
h Click Apply.
After a few seconds, integer labels replace the previous labels, and you are on your way to
making a useful map.
This version of the code extends the previous one. It includes the function that assesses
whether the value in the Continuous_percent field is positive or negative, but there are
additional lines of code and three additional functions.
• FindDEMColor specifies a mix of colors using the RGB scheme for values of data that
are eventually returned as Democratic, blue.
• FindGOPColor specifies a mix of colors using the RGB scheme for values of data that
are eventually returned as Republican, red.
• FindColor uses the same logic as FindText in the original code to apply the
FindGOPColor function to positive values and the FindDEMColor function to negative
values.
An additional command is inserted in the last line to draw the text using the specified colors.
b In the Label Class pane, click in the Expression field, press Ctrl + A to select all the code,
and then press Delete to delete it.
c In your text editor, copy the code from the Expressions2.txt file.
d In the Label Class pane, paste the code into the Expression field.
f Click Apply.
The same labels appear, but they are red or blue depending on whether the Democratic or
Republican candidate won the county.
The difference between the code in Expressions2.txt and this code is that FindDEMColor and
FindGOPColor have expanded if-then-else statements to specify different colors for values
that fall within different bands. These expanded statements effectively apply a choropleth-
style shading scheme to the labels.
b In the Label Class pane, in the Expression field, delete the existing code.
Hint: Press Ctrl + A to select all the code, and then press Delete.
c In your text editor, copy the code from the Expressions3.txt file.
d In the Label Class pane, paste the code into the Expression field and validate the syntax
of the code.
Like the other expressions, this expression should be valid.
e Click Apply.
Your labels should now have a different value of blue or red to emphasize the strength of vote
using a blended hue color scheme, where light colors represent low data values and dark
colors represent high data values. For now, the labels appear only for counties with values
above 60% (because the definition query that you originally set up still applies) but not for
those in the mid-range.
Next, you will apply some transparency to the labels to give some more emphasis than others.
g In the Label Class pane, delete any existing code in the Expression field.
h In your text editor, copy the code from the Expressions4.txt file.
i In the Label Class pane, paste the code into the Expression field and validate the syntax
of the code.
Like the other expressions, this expression should be valid.
j Click Apply.
The code is virtually the same except for how color is specified. In Expressions3.txt, a different
set of RGB values was specified for each label class. A variable, baseColor, is used to set a
solid red and a solid blue within each function. In this updated code, the colors are
additionally modified by varying the alpha channel for each label class. Varying the alpha
channel controls the amount of transparency applied to each color, which has the effect of
emphasizing and de-emphasizing different label colors. Each symbol has the same red or
blue, but the lower values have increased transparency applied, blending them into the
background. This expression applies the same technique as the value-by-alpha choropleth
mapping technique that you created in the Section 3 exercise Thematic Mapping, except
applied to labels instead of the map itself.
This version of the code has an added function that applies different font sizes to different
labels depending on how they are specified in the FindSize function. The 10 specified
classes return font sizes between 7 and 24 points.
b In the Label Class pane, in the Expression field, select the existing code and delete it.
c In your text editor, copy the code from the Expressions5.txt file.
d In the Label Class pane, paste the code into the Expression field, validate the syntax of
the code, and click Apply.
Your labels should now take on a different value of blue or red to emphasize the strength of
vote using a diverging hue color scheme. They should also now differ in size based on the
total number of votes cast for the candidate.
a In the Contents pane, ensure that the Labels > 60% layer is selected and click the
Appearance tab.
b In the Visibility Range group, in the In Beyond field, type 1:6,058,572 and press Enter to
set the scale.
This scale sets a value roughly midway between two of the standard web map zoom scales
(which you used in the Section 3 exercise Thematic Mapping). It ensures that when the map is
published as a web map, the map will be visible as a user settles on a particular zoom scale. It
will turn off at the point when another scale-based rendering becomes visible.
c In the Out Beyond field, type 1:14,791,436 and press Enter to set the scale.
This layer will now appear only between those two zoom scales. You can zoom in and out of
the map beyond the two scale extremities to see how the layer visibility changes.
Note: It may take a moment for the labels to draw.
You will now create another layer to manage visibility at even smaller scales.
d In the Contents pane, right-click the Labels > 60% layer and choose Copy.
e At the top of the Contents pane, right-click the Proportional Labels map item and choose
Paste.
g Paste another copy of the layer to the Proportional Labels map item and rename it All
Labels.
h In the Contents pane, select the Labels > 70% layer and click the Appearance tab, if
necessary.
Again, you will set a zoom scale to manage visibility.
i In the Visibility Range group, for In Beyond, type 1:14,791,437 and press Enter to set the
scale.
k In the Contents pane, right-click the Labels > 70% layer and choose Properties.
Next, you will edit the definition query to define which labels are visible.
l In the Layer Properties dialog box, click the Definition Query tab, if necessary, and then
on the existing query, click Edit.
m Modify the existing query to the following query expression: Where Win_percent Is
Greater Than Or Equal To 70.
Note: If necessary, delete any extra numbers to the right of the decimal place so that you are
left with only the integer 70.
n Click Apply.
p In the Contents pane, select the All Labels layer and click the Appearance tab, if
necessary.
r For Out Beyond, type 1:6,058,573 and press Enter to set the scale.
s In the Contents pane, double-click the All Labels layer to open the Layer Properties dialog
box.
t From the Definition Query tab, point to the existing query and click the red X to remove
the existing Win_percent >= 60 query.
u If the Remove Definition Query dialog box appears, click Yes to verify that you want to
delete the definition query from the layer.
v Click OK.
The All Labels layer now draws only when the scale is 1:6,058,573 or larger. Because the map
is at a scale sufficient enough to allow enough space for all labels, all labels are drawn.
You are using visibility ranges to change the amount of detail on the map and to make the
data legible at different scales. You can use this approach whenever you need to have some
control over the scales at which information appears on the map.
w Zoom in and out of the map to see how the layers turn on and off at different times.
symbology set up using Arcade Expressions. You are effectively going to take a picture of
your map and publish the resulting tiles. It will draw far more rapidly as a web map than
alternative options.
a From the Share tab, in the Share As group, click the Web Layer button (not the down
arrow) to open the Share As Web Layer pane.
b In the Share As Web Layer pane, from the General tab, confirm that the Name field is set
to Proportional Labels.
c Add your first and last name to the end of the file name so that it is unique.
Note: Because all students in this class are creating a web layer for this exercise, the name of
your web layer must be unique to avoid overwriting other people's work. Make a note of the
name that you typed because you will need it to find the layer in ArcGIS Online.
Next, you will add a summary item description and tags to help you and others find this layer,
either in your organization or the general public, depending on how you want it shared. Tags
also help group different types of items together, such as maps, map layers, or applications,
so they can easily be searched.
d For Summary, type Cached tile layer for Section 4: Labels as Symbols.
f If you would like, add additional tags, pressing Enter after each one.
h For Location, click the down arrow and choose your Username.cart folder.
i For Share With, check the Everyone and Cartography. boxes, if necessary.
j At the top of the Share As Web Layer pane, click the Configuration tab.
Next, you will import a custom tiling scheme XML file that contains your preferred scales and
settings.
l In the Load Tiling Scheme dialog box, browse to the location where you saved the
exercise data files.
n In the Share As Web Layer pane, leave all other settings as the default, and then click
Publish.
The process may take a few minutes. When the layer is successfully published, you will see a
green message at the bottom of the Share As Web Layer pane.
This process publishes a cached raster map at three scales (in the Albers Equal Area Conic
projection) to your ArcGIS Online account. We do not want to use Web Mercator because it is
inappropriate for a thematic map of a large area like the United States (where equal area is
important for interpretation). These projection and scale settings are specified in the XML file
that ArcGIS Pro uses to publish.
In the Section 3 exercise Thematic Mapping stretch goal, you may have made one of these
XML files yourself, but here, it is provided for you. If you wanted to modify the parameters,
you could go back to the Section 3 exercise Thematic Mapping and recall how you made one
of these XML specification files.
b Sign in to ArcGIS Online using your provided course ArcGIS credentials (user name
ending with _cart), as explained in the Section 1 exercise Make a Map.
Hint: In ArcGIS Pro, you can find the ArcGIS user name that you are currently using by
clicking on your name in the top-right corner of the ArcGIS Pro window. You will use the same
user name to sign in to ArcGIS Online.
c If necessary, at the top of the page, click Home to go to the ArcGIS Online organization
home page for this course.
d At the top of the organization home page, click Map to open a new map.
f In the Search For Layers pane, type the name of your tile layer (for example, Proportional
labels_<your first and last name>) and press Enter to search for your newly created
cached tiles layer.
You should see one result in the search result list.
Note: Avoid adding the layer to the map because it is in a different projection.
You will save your web map in ArcGIS Online before exiting.
h At the top of the ArcGIS Online map window, click Save and choose Save As.
i In the Save Map dialog box, give your web map a title, tags, and a summary.
n If you are continuing to the stretch goals, leave ArcGIS Pro open; otherwise, exit ArcGIS
Pro.
Conclusion
You have made a Proportional Labels map using some code built with Arcade Expressions.
This technique introduces you to a powerful way to modify symbols and labels beyond the
defaults and the options in the various symbology and labeling panes.
Although this course is not about teaching you how to code, learning a little about how to
create expressions can greatly expand your ability to modify the rendering of your map data.
It allows you to go beyond the defaults of what is offered out-of-the-box.
Finally, you have published your map as a web map. If you follow the stretch goals, you will
also make an app in ArcGIS Online that includes pop-ups to give people access to meaningful
results.
Stretch goals
One of the primary purposes of cartography is to effectively communicate information to a
wider audience. The most beautiful map ever created is not useful if no one ever sees it. One
way that you can share your maps is using ArcGIS Online and ArcGIS Web AppBuilder to
create a web app that anyone can see and interact with. If you would like to continue to
explore how to use the map you created to communicate more effectively using pop-ups and
share your map as an app, you can complete the following high-level tasks:
• Create a cleaner version of your web map suitable for sharing with others; remember
that one of the key ideas behind cartography is to omit detail to clarify the message.
• See how minimal you can make the web map app's layout.
• Because the labels are actually on the map, consider adding a small information box
to explain what it is that people are seeing.