Before tackling this tutorial, you will need to download and install a dataset following these instructions:
Create a folder called Selection_exercise somewhere under your personal directory (e.g. C:\Users\jdoe\Documents\Tutorials\Selection_exercise\).
Download the data for this exercise then extract the contents of Selection_exercise.zip into your newly created Selection_exercise folder.
Open the Selections.aprx file.
The map document consists of a polygon layer and a point layer.
In the following series of examples, you will learn how to subset features based on attribute queries. These exercises will make use of the Select Layer by Attribute geoprocessing tool.
To access the geoprocessing tool, click on the Geoprocessing toolbox under the View tab.
In the Geoprocessing pane (which should be docked on the right side of the Pro window), type Select Layer by Attribute in the Search window to find the tool.
The first search result should be the geoprocessing tool of interest.
Click on Select Layer By Attribute to activate it.
You will use this tool to tackle the next three queries.
Here, the attribute of interest is Frac_No_HS. We will build a query expression around this field.
Select Counties from the pull-down option in the Input Rows field.
Choose New selection as the selection type.
Click New expression to launch a new expression wizard.
Fill the fields as follows. It should read:
Where Frac_No_HS is greater than or equal to 0.15
Click Run to perform the selection.
Alternatively, you could have made use of an SQL expression. SQL is a popular language used with relational databases.
To use the SQL option, flip the SQL switch and type the following expression:
Frac_No_HS >= 0.15
(If you already defined the expression in the earlier step, this expression will already appear in the expression box).
When done, you should see several selected polygons, 10 to be exact.
To see the exact number of selected polygons, click the List by Selection tab in the Contents pane
Note that when you have the List by Selection selected in the Contents pane, the check boxes next to the layers do not turn the layers on and off. Instead, they enable or disable graphical selection of the layer (i.e. selections that make use of your mouse).
This query will make use of two expressions that will be combined using the And boolean operator.
If you are continuing from the previous step, you will already have satisfied the first criterion. If not do so before continuing to the next step.
Click on the Add Clause link to add the second expression that needs to be satisfied.
Add the expression Frac_Bach is greater than or equal to 0.20. You will join this expression with the previous one using the And boolean operator.
Click Run.
You should have 5 polygons that satisfy the two criteria.
NOTE: Do not clear the selected polygon features! They will be exported to a new shapefile later in this tutorial.
Before starting this exercise, you will need to turn the Schools point layer on if it's not already activated. If you are in the List by Selection mode, you will need to switch back to the List by Drawing Order mode in the Contents pane.
This query has you working with the Schools point layer. However, this layer does not have an attribute that identifies the type of school (e.g. High School, College, etc...). So this query will need to make use of a regular expression whereby we will look for key words in the Name column. More specifically, we will look for the words "High School" (this is, of course, a limiting assumption given that many high schools do not have those words in their names).
Note, however, that there is a problem with this approach in that the words "High School" can also be found in "Junior High School". So to avoid selecting Junior High Schools we will combine two expressions whereby one of the expressions will remove all instances of "Junior High School".
Create a new Select Layer By Attribute query as shown below.
Note that the expression is case sensitive. So the text "high school" is treated differently from "High School"
The SQL equivalent should look like:
NAME LIKE '%High School%' And NAME NOT LIKE '%Junior High School%'
You should have 858 polygons that satisfy the two criteria. (Don't forget to switch back to List by Selection mode to see the number of selected features).
So far, this exercise has shown you how to identify features that meet a defined criteria. But some workflows might require that the selected features be saved as a dedicated GIS data file. In this next step, you will export the selected points to a shapefile called High_schools.shp.
With the high school points selected, right-click on the Schools layer and select Data >> Export Features.
Set the output location to the Selection_exercise folder and the output filename to high_schools.shp.
Click OK to run the geoprocess.
On your own, export the 5 counties selected in an earlier step to a shapefile that you will name bac_and_NoHS.shp.
Make sure that the county polygons are selected. If they are not, ALL features will be exported to the new GIS file.
When running most geoprocessing tools (including exporting features), if one or more features are selected, only those selected features will take part in subsequent geoprocesses. So any selection should only persist as long as is needed. In this example, we exported the selected feature so we can clear the selections from the layer.
To clear the selected points in just the Schools layer (i.e. without clearing the selection from other layers in your project), right-click on the Schools layer and click on Selection >> Clear Selection.
On your own, clear the selection in the Counties layer.
Note that if you wanted to clear all selections from all layers in your current map, you could have clicked on the Clear button under the Map tab.
Another form of selection is the selection by location where features are selected based on their spatial relationship to features from another layer.
In earlier steps, we already created the two layers that will be needed in this step. These are the high_schools and bac_and_NoHS layers.
In the Geoprocessing search bar, type Select Layer by Location.
Note that you might need to click on the Geoprocessing back arrow to get back to the Geoprocessing landing pane.
The first search result should highlight the desired tool. Click on it to open it's window,
In the Select Layer by Location geoprocessing window, set the Input Features to high_schools. This is the layer that we are selecting from.
The spatial relationship we are interested in is containment. So we will choose the Within option from the pull-down menu in the Relationship field.(I.e. we are seeking all points that are within said polygons).
The bac_and_NoHS layer is the polygon layer that is used in the selection (but is not selected from).
This should return 124 selected points that satisfy this criteria.
ArcGIS Pro offers a wide selection of spatial relationship types. While most options seem self-explanatory, some may need further explanation. To learn more about these options, view this online help link.
In this example, the relationship in question defines a certain distance between features. But before we start the selection by location procedure, we will need to create a Junior High schools layer from the Schools layer (recall that we extracted the High schools features earlier in this exercise and not the Junior High Schools).
Using the Select Layer by Attributes tool, select all Schools point features that have the words "Junior High School". Then export to a dedicated shapefile that you will name junior_high.shp.
You should end up with 243 selected points.
Once you've exported the Junior High schools points, clear your selection. (Remember that it's good practice to clear your selection when done).
Now that you have a dedicated Junior High schools points layer, you can proceed with the selection by location workflow.
Bring up the Select Layer by Location geoprocess and populate the fields as shown in the accompanying figure. (Note that if you wish to avoid projected coordinate system distortions, you could choose the geodesic distance option).
The process should return 464 selected high school points.
Export the selected point to a new shapefile that you will name HS_5mi_JHS.*.
Clear your selected features and save and close the map project. This wraps up this tutorial.