What is the optimal route to get to a group of locations? And what happens when there is a “disruption” on particular pathways? This workshop examines the amount of time (cost) that it takes to traverse a given network of roads between a series of provided locations.
Part I. Download and prepare the data
First, download and unzip the states, county, and city geodatabase from our class server:
The US Department of Transportation provides nationwide spatial data of our road network. Let’s download their data to use in this workshop, where we will conduct a series of network analyses.
What? Just California?For the purposes of this workshop, we will only use the road networks for California. Using the nationwide network would have been preferred, but given that larger datasets take much longer to run “geo” processes, we will first extract the roads for California.
Extract California roads
- Open ArcMap
- Add NHPNLine.shp and US_States
- Turn off NHPNLine, and highlight California (use the selection tool)
- Go to Selection, Select by Location, select features from NHPLine, source layer: us_states, and check the “use selected features”
- Right click on NHPNLine, Data, Export Data, put it in your geodatabase, and give it the filename ca_roads
Extract the counties for California.
- Add us_counties to ArcMap
- Go to Selection, Select by Attributes
- The FIPS code for California is 06. Enter the following SQL query and apply:
- Right click on us_counties, data, export data, and save it as ca_counties in your geodatabase.
Extract the cities for California
By now you should have a handle on how to filter and create new spatial layers. Repeat the steps to generate ca_cities from the us_cities layer.
Close ArcMap. There is no need to save the project at this time.
Get in the Zone! (11)
Before we begin to create a network dataset, we need to set the correct projection for our project. For any type of spatial analysis that requires geoprocessing, it is highly recommended to use a projected coordinate system, and to have every single layer in your project have the same projection.
- Open the search window, and enter “batch project“
- Click on the Batch Project tool
- Drag and drop the three California datasets into the the input feature class box
- For Output Workspace, navigate to your workshop2018.gdb geodatabase
- For Output Coordinate System, choose NAD 1983 UTM Zone 11N (type in the search box to find it)
- Click OK
- You should now have three new layers in your geodatabase. Rename them as:
- ca_cities_1 -> ca_cities_utm
- ca_counties_1 -> ca_counties_utm
- ca_roads_1 -> ca_roads_utm
Part II. Calculating Cost
We now have all our data projected and ready to go. But before we do any network analysis, we want to create “cost” fields in our network dataset. Essentially, we want to measure cost as a factor of time. Faster roads, like interstate and freeways, will assume a lower cost of travel (less minutes), while slower roads, like arterial roads, will assume a higher cost (more minutes to travel).
Let’s take a look at how the Department of Transportation classifies different roads on the network. The metadata is available on their website here. Scroll down until you find the documentation on the FCLASS field.
In order to simplify our cost calculation, we will create our own reclassification using only 3 classes. To do so, we will group all freeways and interstates into one class, arterial roads in another, and all the remaining roads as a third class.
- Open a new ArcMap project
- Add ca_roads_utm (the one that has the UTM projection)
- Right click on ca_roads_utm and go to properties and click on the Fields tab
- Deselect all the fields except for MILES and FCLASS
- Open its attribute table
- Add a new field, and name it NewClass, and give it a type Short Integer.
- Once created, right click on the header, and select Field Calculator.
- Make sure the parser is set to VB Script
- Check the Show Codeblock box
- Enter the following formula in the Pre-Logic Script Code
dim n if [FCLASS] = 1 or [FCLASS] = 11 or [FCLASS] = 12 then n = 1 elseif [FCLASS] = 2 or [FCLASS] = 6 or [FCLASS] = 14 or [FCLASS] = 16 then n = 2 else n = 3 end if
- Enter “n” in the second box labeled NewClass=
- Now let’s assign speed limits to each class. Create a new field, and title it Speed of type Short Integer.
- In the field calculator, enter the following VB script:
dim n if [NewClass] = 1 then n = 60 elseif [NewClass] = 2 then n = 40 elseif [NewClass] = 3 then n = 20 end if
- Now add another field, and name it Time_Minutes.
- Give it a type Float.
- In the field calculator, enter the following formula:
Creating a disruption on the network
We have now created a cost field in terms of how many minutes it costs to travel each segment of our network. Let’s presume, however, that a disruption has occurred, and certain segments of our network incur a 10% increase in cost. To make matters simple for our workshop, let’s presume that all roads within Los Angeles County will incur this additional cost of 10%. In other words, it takes 10% longer to travel roads in Los Angeles County as compared to any other roads on the network.
- Create a new field for our disrupted cost, and name it Time_Minutes_LA
- Give it a type Float
- In the field calculator, copy the values from Time_Minutes
- Now select only the roads that are within LA County.
- Use the selection tool to highlight LA County
- Go to Selection, Select by Location.
- Select features from ca_roads_utm that intersect with selected features (checkbox) from ca_counties_utm
- In the attribute table for the ca_roads_utm, notice that 8878 out of 61,973 segments are selected. Click on the “Show selected records button”
- Click on the header for Time_Minutes_LA and bring up the field calculator.
- Add 10% cost to the selected LA County Roads
- Save your project as NetworkWorkshop.mdb
- Close ArcMap
We now have two cost fields in our network data. Next, we will create a network dataset that allows ArcMap to run analyses.
Part III. Creating a Network Data Set
- Open ArcCatalog and locate your geodatabase.
- Right click on the geodatabase and click “New” then “Feature Data Set”
- Add a new feature dataset and call it “ca_transportation“
- Give it a NAD 1983 UTM Zone 11N coordinate system.
- Ignore the other options, and finish.
- Drag the ca_roads_utm layer into the ca_transportation feature dataset you just created
- Right click on ca_transportation, New, Network Dataset
- Proceed through the New Network Dataset Wizard:
- Give it a name
- Choose ca_roads_utm as the feature class participating in the network dataset.
- Choose to model turns in the network.
- Choose “None” for elevation modeling.
- Add an attribute for the network dataset called “Minutes”
- Make sure the units are minutes in the dialogue box.
- In evaluators, make sure the that “Type” is Field and that the Value is “Time_Minutes”
- Duplicate the “Minutes” field
- Change the value from “Time_Minutes” to “Time_Minutes_LA”; this will be used to model traffic in LA.
- Rename “Minutes_2” to “Minutes_LA”
- Give it a name
- Title the network dataset as “ca_transportation_ND”
- Choose “yes” to build the Network Dataset.
Take a break while the Network Data Set builds
Part IV. Network Analysis
- Close ArcCatalog and re-open ArcMap
- Add the following layers into your map:
- Go into the “ca_transportation feature class” and add:
- Do not add all features that participate in the network database as we don’t really need them.
- Go to “Customize” and then “Extensions“.
- Make sure the Network Analyst Extension has a check mark next to it, indicating that it is on.
- Right click anywhere near the toolbar and click on “Network Analyst” to turn on the Network Analyst Toolbar:
- Click the Network Analysis Window Icon:
- Our task will be to calculate an Origin-Destination Cost Matrix from the most populous city in California to the next 10 populous cities.
- Click the Network Analyst dropdown and select “New OD Cost Matrix“
- New layers should propagate in both the Network Analysis window and the Table of Contents for the project.
- Open the attribute table for ca_cities_utm and order by population_2007.
- Select the highest value, which happens to be Los Angeles.
- With the city highlighted, we will right click on “Origins” and click “Load locations”
- Return to the attribute table and choose the next 10 cities:
- Right click on Destinations:
- Load the data in.
- Close the attribute table.
- Go back to the Network Analyst toolbar and click on “Solve”
- The Origin-Destinations will be calculated.
- Right click on “Lines” and open the attribute table for the to see to OD-Matrix.
- Export as a csv file to save it out of ArcMap.
- To simulate Los Angeles traffic, we will use the Minutes_LA field.
- First, let’s copy the OD Matrix we just made. Right click on OD Cost Matrix in the table of contents and click Copy
- Right click on the Layers and choose Paste Layer
- You should rename the layer to OD Cost Matrix LA
- Now on the Network Analyst window click on OD Matrix Properties
- Switch to the “Analysis Settings” tab
- Choose Minutes_LA
- Choose to solve the analysis again.
- Open the attribute table for the lines.
- Compare the two OD-Matrices.
Pop quiz: Travel to which cities have been negatively impacted by Los Angeles traffic?
Choose a topic of interest that can be visualized as a county based US map from data that is available on Social Explorer. Download your data of choice from Social Explorer, join it to the county layer provided in this workshop, and symbolize it to create a choropleth map. Add a short paragraph description that describes the map.