This week we will learn different mechanisms for selecting certain locations and measuring nearby in space. For relation to the reading, this is similar logic to that conducted in Risk Terrain Modeling - we will just be working with vector data instead of raster data though. The data can be downloaded from blackboard, or from https://www.dropbox.com/s/joqvlns9p7fq5kk/9_SelectNear.zip?dl=0.
For a hypothetical project, say you are a crime analyst and the Chief asked you to identify locations along main arterials in Albany that are at high risk of assault and robbery. You have already identified risk factors you think are pertinent: public housing projects, bars, and ATM locations. So you wish to pick locations that are nearby any of these risk factors. This tutorial will walk you through different ways of doing this.
Here we will be using a dataset of street units - street midpoints and intersections in Albany (point data). We will also be using a dataset of schools, bars, and ATM locations. The overview of the project will be:
First, I have provided an mxd map document in the data, named “Albany.mxd”, that references data used in week 2 - Albany Streets, On Premise Alcohol locations (i.e. bars), and the border of Albany. When you open up this mxd document though you will see that the layers do not show up, and they are prefixed with a red exclamation point.
The mxd document is just a container on how to display spatial information, it does not actually contain the spatial data itself. When you make an mxd document, it contains a link to the original data location. This mxd document still expects the data to be located in the folders on the machine I originally created it in.
You do have access to these three data layers though - they were in the second weeks tutorial - bars, streets, and the border for Albany. So what we are going to do is tell ArcMap where the data is located on your personal machine. Right click on any of the layers, and then go down to Data -> Repair Data Source
Now here I selected the Bars data layer, so I navigate to where I had the data for week 2 located and select the Alb_OnPremise_Liquor
shapefile. When I hit add, ArgGIS intelligently updates the location for all of the layers in the data frame. So you should now see the full Albany map.
Next we are going to add in the new data layers for this week, a set of street units (street intersections and midpoints), Public Housing locations, and ATM locations in Albany. Click off all of the layers in the table of contents except for the street units (which cover most of the city) and the border.
Now what we are going to do next is only select intersections of main arterials. Open up the attribute table for the street units layer, and in the top left corner select the dropdown arrow and then Select By Attributes
Here we are going to select intersections, and then select places that have a street code of 3 or 4. The field TOTALINT
measures the number of separate streets connected to a street unit, so places with a TOTALINT of greater than 1 are intersections. Then the fields ACC_N1 to ACC_N5 measure the types of streets that are part of that street unit. Here main arterials are those with a classification of 3 or 4, so we are going to select street units that are connected to at least one of these ACC codes. You can see the AND/OR statement to select places with these criteria below.
Now you should see that many points are highlighted in the map along several recognizable main arterials in Albany, such as New Scotland and Western. Now right click on the street units layers and then go down to Selection -> Create Layer from Selected Features.
This then makes a new layer in the map only showing those intersections. Hit the clear selection button (highlighted in red below), and then turn off the street units layer in the table of contents. If your select by attributes query was correct, this should result in 1,879 points in the new layer.
In the prior section I showed you how you can select features based on attributes. You can also select features based on spatial location as well. First turn on the public housing location layer in the table of contents. Then make their icons large and colorful, so you can clearly see them behind the intersections. Here I make them big, green squares. Now in the file menu, go to Selection -> Select by Location
Fill out the dialog as shown below. We are going to select points from our selected layer of street units (the target) that are within 300 meters of public housing locations (the source). In the spatial selection method make sure that “are within a distance” is the method of choice. And then hit OK.
You should now see that only street units nearby the public housing locations are selected. Open up the attribute table for the Albany_StreetUnits selection
, and add a field named NearPH
. In the lower part of the attribute table, there is an ability to only view selected records. Hit this (circled in red), and then in the field calculator set the field NearPH
equal to 1.
If you go back to the full table view (circled in red below), you will now see that only those points that were selected are filled in with a 1, but all other points still have a zero. This is the default behavior for field calculations in ArcGIS - only selected locations are updated based on whatever you put in the field calculator dialog. This is an easy way to mark locations if they are nearby some point of interest.
Previously I have shown you how to join a table to a spatial layer based on attributes. Here we are going to do a spatial join, and join the nearest ATM location to the intersections of interest. First turn off the public housing locations, and turn on the ATM locations. Again make them some large and garish color so they are easily spotted. Here I make them big, green circles.
Now right click on the Albany_StreetUnits selection
layer, and then select joins and relates, then select Join. In the menu that comes up, in the top selection select Join data from another layer based on spatial location. Then in the next dropdown select BankOwned_ATMS_Albany. Make sure the bullet next to the operation of joining the closest points is selected. Then in the final box specify where to save the file and name the resulting file Inter_join_ATM
.
Once this is finished, ArcGIS automatically adds the layer in ArcMap. Open up the attribute table for the new Inter_join_ATM
layer, and then scroll all the way to the right. You will see that each of the intersections now has the nearest ATM location and a field named Distance. Often it is difficult to know what exact distance this is, so select the first record in the table by clicking on the little square at the leftmost part of the table. Note that for this particular intersection, the distance is alittle over 476. Then right click that same grey square on the first row and select Zoom To. You can see the highlighted location and the dialog in the screenshot below.
Now in the toolbars select the tool that looks like alittle ruler. This pops up a box for our ruler tool. Select the dropdown arrow to the right of the sigma symbol, and for distance make sure that meters are selected.
Now you can use the tool by simply clicking on two points. Here We can see that the distance field is in meters, as the distance to the nearest ATM by our ruler tool is also 476 meters.
The prior two sections how to calculate places nearby other places, and how to estimate exact distances to the nearest location. What if you want to count up the number of points nearby though - given a threshold of nearby? To do that we can make a buffer of the point source, here intersections, that you want to count the total of something nearby. Here we will count the number of bars within 500 meters.
First in the file menu go to Geoprocessing -> Buffer.
Next input the Inner_join_ATM
layer in the input features, specify where to save the resulting buffered shapefile, and then in the distance value field set the linear unit to 500 meters. Keep the dissolve type as None.
Hit ok, and then this takes a minute to finish, and automatically adds the buffer file to the map. It should look like below - a series of very many overlapping buffers. If you had selected to Dissolve the buffers, the resulting file would merge any two circles that overlapped together, which in this circumstance would just result in one big blob.
Next we are going to do another spatial join, but instead of joining the nearest location, we are going to count up the number of bars that fall within our buffers. It is the same join dialog as previous, just right click on your buffers, go to join, and then fill in the dialog as below. Make sure to select the Alb_OnPremise_Liquor
as the join layer, and select the first bullet option in 2, counting up the number of points that fall inside of it. Here I gave the new file we are making the name Buf_Count_Bar
.
Again this layer is automatically added to the map. Drag the new buffer layer and the bars to the top of the table of contents, and make sure the orange bars are on top of the Buf_Count_Bar layer. Now open up the attribute table, and again scroll to the right. You will see a field named Count_
, along with all the prior data we have added so far, in the buffer. Go down to the 14th row (FID 13, since it starts at 0), and select that row. If you scroll over to the right in the table, you will see that it has a count of 5 bars. You can then see in the map below (I have added the red circle highlight) that you can count up 5 bars within that selected buffer.
Now it is easier to visualize this pattern as a point pattern instead of all these overlapping buffers. Right click on the Buf_Count_Bar layer and select Properties. Then navigate to the Symbology tab. A quick and dirty way to revert the buffers to points is the visualize the Count_ variable as a graduated symbol that places the point symbol at the centroid of the polygon. In the left hand side make sure Quantities -> Graduated Symbols are selected, and in the Fields dropdown select the Count_ variable. Your dialog should now look similar to below.
Currently this still displays the background of the buffers as blue, here we are going to change the background to be entirely invisible, so only the original midpoint is shown. On the right hand side of the dialog, click the background button (that is a polygon swatch). This brings up the usual polygon symbol selector. For both the fill and the outline color change them to no-color.
Once you hit ok, you map should then look like below. We can see the concentration of the locations with the highest counts of bars are downtown and towards Lark/Delaware.
This symbology trick for buffers works ok quickly, but a more permanent solution is to export our data, and then add in this new data into our original intersection points. Open the attribute table for Buf_Count_Bar, and select the dropdown in the top left corner, and then select export. This will only export the table - not the geographic data. Specify where you want to save the table, and in the Save as type dropdown make sure to select a dBase Table (it often defaults to save in another database format). Name the table SU_withScores.dbf
.
Once you hit save, it will ask if you want to import the table into the map. Choose yes to import into the map. Now we are going to join this table based on attributes to our selected intersection layer. Join the new table to the intersection layer by right clicking on the intersection layer and selecting join. In the dialog make sure to change it to join attributes from a table, select SU_withScores in the dropdown, and merge based on SU_ID.
Now right click on the intersection layer, and then go to Properties. Navigate to the Definition Query tab, and select Query Builder. This is similar to select by Attributes, but this makes a filter of what to show in the map. In the query builder select only locations that have over 10 bars within 500 meters (text shown below) and hit ok.
Once you navigate back to the map you will see that only locations in downtown Albany are selected.
For your homework, I want you to combine all three metrics into one final risk score, and only map locations above a particular threshold. The formula I want you to use in plain language is:
[Count of Bars divided by 10] + [Near Public Housing multiplied by 3] + [3 + (Distance to nearest ATM divided by 6300)*-3]
In the field calculator in ArcGIS add a new field named RiskScore
, and then use the field calculator to calculate the metric. The formula in the field calculator will look like:
[Count_]/10 + [NearPH]*3 + 3 + ( [Distance] /6300)*-3
This basically weights each of the different metrics equally, and for each risk factor it can have a minimum value of zero and a maximum value of 3. Bars divided by 10 and near public housing should be pretty straightforward, but for an explanation of the last term, if the distance is zero, the term gets 3, the further away from an ATM, the score reduces until it is zero for places that are 6300 meters away.
Use either select by attributes or the definition query to only map locations that have a score above 5 for this metric. Make a nice map of the outline of Albany, the streets, and those intersections that are above the threshold. Export the map to a PDF file, and turn in this file for your homework.