Exercise 10: Configuring live traffic on a network dataset
In this exercise, you will create a network dataset in a geodatabase using San Diego street, turn, and signpost features. The network dataset will also include historical and, optionally, live traffic data, which makes it possible to view travel speeds for different times of day and solve time-dependent network problems.
To complete this tutorial exercise and finish with a fully functioning network dataset that processes live traffic, you need to sign up for a live traffic feed from a data provider. The data provider will then give you a user name and password to access their traffic feeds. You will enter the user credentials in the Update Traffic Data geoprocessing tool to read data from the feed and convert it to a format that Network Analyst can read. The three data providers currently supported by Network Analyst are INRIX, NAVTEQ, and TomTom.
In the final set of steps of this exercise, you will learn how to visualize traffic in ArcMap. The next tutorial exercise, Exercise 11, demonstrates how to solve a network analysis based on dynamic traffic speeds.
![Note Note](rsrc/note.png)
The data for this exercise and the other exercises in the Network Analyst tutorial is available on ArcGIS.com. After downloading the data, you can extract it wherever you like. It may be helpful, however, to extract it to C:\arcgis\ArcTutor since the tutorial refers to this path as the default location for the data.
![Legacy Legacy](rsrc/legacy.png)
The tutorial data that accompanies this exercise was updated for ArcGIS 10.1 Service Pack 1 and posted to ArcGIS.com to include a model and a script. Please make sure that you have the latest ArcTutor data before starting this exercise.
Create a folder for storing live-traffic files (DTF files)
Network datasets enabled with live traffic rely on a continual feed of traffic files from a data provider to get up-to-date travel speeds. Later in this tutorial exercise, you will run a geoprocessing tool to make the live-traffic files from a traffic feed, which are called dynamic traffic format (DTF) files. For now, however, you need to create an empty folder where you plan to store these files so that when you create the network dataset, you can point it to this folder.
- Open Windows Explorer.
- Create a folder named TrafficFiles in a location where you have read-write access. For example, you may want to create the folder in C:\Data, so the full path would be C:\Data\TrafficFiles.
Next, you will create the network dataset and point it to the TrafficFiles folder so that the network can get the latest travel speeds. Although the folder is empty now, you will run a geoprocessing tool at regular intervals to get DTF files and keep them up to date.
Creating a network dataset
- Start ArcCatalog by clicking Start > All Programs > ArcGIS > ArcCatalog 10.2.2..
-
Enable the ArcGIS Network Analyst extension.
-
Click Customize > Extensions.
The Extensions dialog box opens.
- Check Network Analyst.
- Click Close.
-
Click Customize > Extensions.
-
On the Standard toolbar, click the Connect To Folder button
.
The Connect to Folder dialog box opens.
-
Navigate to the folder with the Network Analyst tutorial data.
The default location for the tutorial data is C:\ArcGIS\ArcTutor\Network Analyst\Tutorial.
-
Click OK.
A shortcut to the folder is added to Catalog Tree under Folder Connections.
- In Catalog Tree, expand \ArcTutor\Network Analyst\Tutorial > Exercise10 > SanDiego.gdb.
-
Click the Transportation feature dataset.
The feature classes in the feature dataset are listed on the Contents tab of ArcCatalog.
-
Right-click the Transportation feature dataset and click New > Network Dataset.
The New Network Dataset wizard opens.
- Type SanDiego_ND as the name for the network dataset.
- Click Next.
- Check the Streets feature class to use it as a source for the network dataset.
- Click Next.
- Click Yes to model turns in the network.
- Check RestrictedTurns to select it as a turn feature source.
-
Click Next.
Information about configuring connectivity is displayed. Since you will use the default settings in this case, you don't need to change any settings here.
- Click Next.
- This dataset has elevation fields, so make sure that the Using Elevation Fields option is chosen. Choose F_ZLEV for the from-end of the streets source and T_ZLEV for the to-end.
- Click Next.
- In the Live Traffic: Streets-TMC Table section, make sure that Table is set to Streets_TMC, and that TMC Field is set to TMC.
- Click Traffic Feed Location to select the property.
A button with an ellipsis appears on the right side of the property.
- Click the ellipsis button.
The Live Traffic Feed Location dialog box appears. It lets you specify one of three options: no traffic feed will be referenced at this time (None), a folder will contain DTF files (Folder), or a geoprocessing service will feed the network dataset live-traffic data.
- Click Folder, then click the browse button
.
The Live Traffic Feed Location Folder dialog box appears.
- Browse to and click the TrafficFiles folder you created in the first two steps of this exercise, for example, C:\Data\TrafficFiles. (Note that you can use a uniform naming convention, or UNC, paths to refer to this folder. This is useful if you plan to share multiple network datasets across a local computer network.)
- Click OK.
You are returned to the Live Traffic Feed Location dialog box, which displays the TrafficFiles folder path.
- Click at the end of the folder path shown in the Folder text box and type \v1.
The full path should look something like the following: C:\Data\TrafficFiles\v1.
- Click OK.
The TrafficFiles folder appears in the Traffic Feed Location property of the New Network Dataset wizard.
- Click Next.
A page showing all the current network attributes is displayed.
- Click the TravelTime attribute to select it and click Evaluators.
The Evaluators dialog box appears.
- Click the Source Values tab.
- Press CTRL and click the two rows that start with Streets to select them.
- Right-click either of the rows and click Value > Properties.
The Edge Traffic Evaluators dialog box opens.
- Click the Weekdays drop-down list and choose Minutes.
- Click the Weekends drop-down list and choose Minutes.
- Click OK.
The Edge Traffic Evaluators dialog box closes.
- Choose WeekdayFallbackTravelTime from the Attribute drop-down list and inspect the properties on the Source Values tab. Repeat this step for the WeekendFallbackTravelTime.
Notice that both sets of evaluators for the Streets source read the same Minutes field. This is why you are removing these two network attributes and using the Minutes network attribute in the edge traffic evaluator instead.
- Click OK to close the Evaluators dialog box.
- In the New Network Dataset wizard, click WeekdayFallbackTravelTime and click Remove.
- Click WeekendFallbackTravelTime and click Remove.
You can configure historical and live traffic data with this page of the wizard. Configuring historical traffic data is required to set up live traffic data.
The SanDiego geodatabase contains two tables that store historical traffic data: Patterns and Streets_Patterns.
The Patterns table acts as the Profiles table for the network dataset. Each profile describes the variation of travel speeds in 15-minute intervals over the course of a day.
The Streets_Patterns table functions as the Streets-Profiles table. The records in the table link edge source features with profiles in the Patterns table. A representative profile can be specified for each day of the week for each digitized direction of a source feature. By linking street source features with traffic profiles, the streets' varying traffic speeds can be described for an entire week.
The travel speeds in the Patterns table are relative to a free-flow speed so that many different source features with different free-flow speeds can share the same profile. This design minimizes storage requirements.
The Streets-TMC table is used with live traffic data. It links source features with standard traffic message channel (TMC) codes, which in turn relate to live travel speeds stored in the dynamic traffic format (DTF) files. DTF files are designed specifically for network datasets to read and understand. The Update Traffic Data tool creates DTF files by connecting to a data provider's traffic feed, reading the data, and converting it to the dynamic traffic format. You will run this tool later in the exercise and store the output files in the TrafficFiles folder you created.
The ArcGIS Network Analyst extension recognizes the schema of the tables and automatically configures the historical traffic sections of this page in the wizard. It also configures the table for the live-traffic section, but not the Traffic Feed Location property.
When you download traffic data for the first time, a folder named v1 is added to the TrafficFiles folder. You need to add that to the folder path shown.
The wizard creates several cost attributes from some of the data you provided. Minutes and Meters are created automatically from similarly named attributes in the source feature data. The TravelTime attribute is created from the information you filled out in the traffic page of the New Network Dataset wizard. The WeekdayFallbackTravelTime and WeekendFallbackTravelTime attributes are created to support the TravelTime attribute. Each of these network attributes have evaluators that determine attribute values. The TravelTime attribute has an edge traffic evaluator, which you'll examine in the next set of steps.
Note that the evaluation order is listed. Because you configured live traffic, the evaluator tries to retrieve travel costs from live traffic data first by looking for relevant DTF files in the TrafficFiles folder. Since that folder is empty right now, the evaluator would fall back to historical traffic. Similarly, if live traffic isn't available for the given time or street, the network dataset would attempt to use the next best option instead: historical traffic. If historical traffic data isn't available, the travel costs are retrieved from the cost attributes specified in the Weekdays or Weekends attribute, depending on the day of the week for which the data is being queried.
For this dataset, however, the evaluators for WeekdayFallbackTravelTime and WeekendFallbackTravelTime both pull their values from the Minutes cost attribute, which means these two fallback attributes aren't really broken down by weekday and weekend. To make it clearer that these values are the same, you'll change Weekdays and Weekends to read directly from Minutes, then remove the WeekdayFallbackTravelTime and WeekendFallbackTravelTime attributes from the network dataset.
The time-zone attribute
Network Analyst needs a time-zone attribute to correctly convert date and time values from live traffic data to local time-zone values. The time-zone attribute was created for you in this exercise; it is created automatically when the following conditions were met:
The geodatabase in which you are creating the network dataset includes a time-zone table, which is a table with a text field named MSTimeZone.
There is an integer field named TimeZoneID in the edge source feature class, or there is exactly one record in the time-zone table.
Network Analyst knows to create field evaluators when it sees a TimeZoneID field on the edge sources, because TimeZoneID should contain integer values that relate edge source features to the ObjectIDs of time zones listed in the time-zone table.
If Network Analyst doesn't see the TimeZoneID field, but sees that there is exactly one record in the time-zone table, it can make a default evaluator that points to that time-zone record. This is useful when your entire study area is contained by one time zone.
The San Diego network dataset is completely within one time zone. In the following steps, you will examine how Network Analyst configured the time-zone network attribute for this dataset.
- Right-click the TimeZoneID attribute to display a context menu, then click Related Time Zone Table.
Another context menu appears showing that TimeZones is already checked. TimeZones is the name of the table that has an MSTimeZone text field. Network Analyst recognized the field and, therefore, automatically associated the time-zone network attribute with the table.
- Press ESC twice to exit the two context menus.
- With TimeZoneID selected, click Evaluators.
The Evaluators dialog box opens. No evaluators are defined on the Source Values tab because the Streets feature class doesn't have a TimeZoneID field.
- Click the Default Values tab.
Each source feature type is listed in separate rows. The Edge row indicates that all edges are assigned a constant evaluator that evaluates to 1, which matches the Object ID value of the only record in the TimeZones table. The MSTimeZone value for that record is Pacific Standard Time, so this evaluator ensures that all edges in this network dataset are marked as being in Pacific standard time.
- Click Cancel to close the Evaluators dialog box.
Building the network dataset
- Click Next.
- Click Yes to set up directions.
-
Click Next.
A summary of all the settings is displayed for your review.
- Click Finish.
A progress bar opens showing you that Network Analyst is creating the network dataset.
-
Click Yes.
The Build Network Dataset progress bar opens; it will disappear when the build process is finished.
The new network dataset, SanDiego_ND, is added to the SanDiego geodatabase. The system junctions feature class, SanDiego_ND_Junctions, is added too.
Once the network is created, the system asks if you want to build it. The build process determines which network elements are connected and populates the attributes of the network dataset. You must build the network before you can perform any network analysis on it.
Live traffic feed
You've just created and built the network dataset. Now you can assemble a mechanism to automatically download the live-traffic data to the TrafficFiles folder. The network dataset you created is set up to look for current travel speeds in the TrafficFiles folder. In the following subsections, you will use a geoprocessing model tool that generates DTF files in the TrafficFiles folder, create a Python script to run the model, then create a Windows Scheduler task to run the script at set intervals. This will provide a fresh supply of live-traffic data for your network dataset.
Data provider account
Downloading traffic data from a data provider requires you to have a user name and password. To complete this tutorial exercise with a fully functioning network dataset that processes live traffic, you need to contact one of the supported data providers and set up an account. The three data providers currently supported by Network Analyst are INRIX, NAVTEQ, and TomTom.
Not all providers cover the same regions, and many regions aren't covered by live traffic at all. When choosing a data provider for your own network datasets, consider whether the provider covers your study area. All three data providers supported in the Update Traffic Data geoprocessing tool have traffic information for the San Diego area, so you can set up an account with any of them to complete this tutorial exercise.
![Tip Tip](rsrc/tip.png)
To get an idea of which regions are supported by the different providers and the Update Traffic Data geoprocessing tool, open the Update Traffic Data tool dialog box and choose different values for the Provider parameter while looking at the regions listed in the Regions parameter.
The providers and regions available for the Update Traffic Data tool may change between ArcGIS releases and service packs. It's important to get the latest release and, if applicable, the latest service pack to ensure supported regions are listed and functioning properly.
The model tool
Assuming you received the necessary credentials to access a traffic feed, the next step is to open the geoprocessing model tool, which runs the Update Traffic Data, and enter the following information:
- Your data provider
- Your user name and password
- The data provider's region that feeds traffic data for San Diego
![Dive-in Dive-in](rsrc/divein.png)
You don't have to run the Update Traffic Data tool in a model; instead, you could modify the Python script described in the next section to run the Update Traffic Data tool directly. However, your user name and password would be exposed in a script. By using a model and the Update Traffic Data tool dialog box to enter this information, your user name and password are encrypted.
- In Catalog Tree, expand \ArcTutor\Network Analyst\Tutorial > Exercise10 > TrafficTools.tbx.
- Right-click the Download Traffic Data geoprocessing model and choose Edit.
The Download Traffic Data tool opens in ModelBuilder.
- Double-click Update Traffic Data.
The Update Traffic Data tool dialog box appears.
- Click Show Help to see parameter-specific documentation in the side panel.
- Fill out the tool dialog box. Use the substeps below and the side-panel help as a reference.
- For Provider, choose the data provider you contacted to get data-access credentials.
- For User Name, specify the user name you set up with your data provider.
- For Password, specify the password you set up with your data provider.
- For Regions, select the region that covers San Diego, California.
- For Traffic Data Output Folder, specify the path to the TrafficFiles folder you created in the first section of this tutorial exercise. The example was C:\Data\TrafficFiles.
- For
Expected Update Interval in Minutes, specify the interval after
which a new traffic file will be downloaded.
In other words, how often do you want traffic speeds to be updated? Common values for this property are 5, 10, or 15 minutes. You should make sure that you don't set an interval that is more frequent than the update interval of the data from the provider; otherwise, you will download the same data more than once.
Tip:
Make a note of the Expected Update Interval in Minutes value; it will be required when you create a task in Windows Task Scheduler.
- For
Maximum File Age in Minutes, specify the time interval after which
the traffic files are automatically deleted. The default is to keep
the files for 12 hours (720 minutes).
You may want to keep a record of what live traffic speeds were like at a given time. You can store the files for as long as you like, but they occupy disk space, which can add up over time, and add up quickly for large regions.
- Click OK.
The tool dialog box closes and the model is updated. The input, tool, and output parameter now have color fills.
- Click the Save button
and close the Download Traffic Data ModelBuilder window.
The Python script
In this section, you will run a Python script that calls the geoprocessing model you configured in the last section. The name of the script is DownloadTraffic.py.
Running the Python script or the geoprocessing model produces the same results: Update Traffic Data runs and DTF files are created in the TrafficFiles folder. The Python script is needed because, in the next section of this exercise, you will use Windows Task Scheduler to download traffic data at regular intervals. Windows Task Scheduler can't directly execute geoprocessing models because model tools need to run within the ArcGIS Desktop environment; however, Task Scheduler can execute .py (Python) files because they can run directly from the operating system.
You will run the script from the command prompt so that any error messages encountered are reported.
- Click Start > All Programs > Accessories > Command Prompt.
- Follow the substeps below to open the folder that contains the DownloadTraffic.py file in the Command Prompt window. The default path to the file is C:\ArcGIS\ArcTutor\Network Analyst\Tutorial\Exercise10.
Tip:
If you aren't using Windows XP, you can skip the substeps below by navigating to the folder using Windows Explorer, pressing SHIFT, right-clicking the folder, and choosing Open command window here.
- Type the name of the drive to which you copied DownloadTraffic.py, type a colon, then press ENTER.
For example, if the file is in a folder on the C: drive, type C:.
- Type cd, followed by a space and the path to the folder that contains the DownloadTraffic.py file, then press ENTER.
Example: cd C:\ArcGIS\ArcTutor\Network Analyst\Tutorial\Exercise10.
- Type the name of the drive to which you copied DownloadTraffic.py, type a colon, then press ENTER.
- Run the script by typing the name of the file, DownloadTraffic.py, and pressing ENTER.
Note:
If a Python interpreter opens instead of the script executing, type the path to the python.exe file, followed by a space, then the script name. If Python was installed in C:\Python27\ArcGIS10.1, you would type C:\Python27\ArcGIS10.1\python.exe DownloadTraffic.py. This format first indicates which program will run the file, followed by the name of the file the program will run.
The Windows Scheduler task
Now you will set up the task in Windows Task Scheduler to run the Python script then download the latest live-traffic data every five minutes.
- Open the Windows Task Scheduler by clicking Start then typing Task Scheduler in the Windows search box and pressing ENTER.
- Click Task Scheduler Library.
- On the Actions pane, click Create Basic Task.
The Create Basic Task Wizard opens.
- Type a name and, optionally, a description for the task, for example, "DownloadTraffic" for the name, and "Downloads traffic at regular intervals to support an ArcGIS network dataset" for the description.
- Click Next.
The Task Trigger page is displayed.
- Under When do you want the task to start?,
click One time.
Although the objective is to run the task every five minutes or so, that option isn't available here. By choosing One time now, you will be able to modify the task properties later so the task runs after a given number of minutes rather than days or weeks.
- Click Next.
The One Time page is displayed.
- Specify a date and time to begin downloading traffic data. The current time is appropriate in most cases.
- Click Next.
The Action page is displayed.
- Under What action do you want the task to perform?, click Start a program.
- Click Next.
The Start a Program page is displayed.
- Click browse, which is next to the Program/script text box, and select the Python interpreter executable (python.exe). This file was referenced earlier when you ran the script using the command line and is often found in the following location: C:\Python27\ArcGIS10.1\python.exe.
- In the Add arguments text box, type the full folder path to the DownloadTraffic.py file and enclose the path in quotation marks (").
Example: "C:\ArcGIS\ArcTutor\Network Analyst\Tutorial\Exercise10\DownloadTraffic.py"
- Click Next.
The Summary page is displayed.
- Check Open the Properties dialog for this task when I click Finish.
- Click Finish.
The dialog box with the task's properties is displayed.
- Click the Triggers tab.
- Click the One time trigger and click
Edit.
The Edit Trigger dialog box appears.
- In the Advanced Settings frame, check Repeat task every, then choose from the drop-down list the same value that you set in the DownloadTrafficData model tool for the Expected Update Interval in Minutes parameter. A common value for this property is 5 minutes, but 10 and 15 minutes are not uncommon.
- Choose Indefinitely from the for a duration of drop-down list. Optionally, choose another duration to ensure the task stops after a certain time period.
- Click OK.
The Edit Trigger dialog box closes.
- The property settings you've made work for most users; however, you should look at the other properties available in the dialog box to see if they might prevent the task from running. For example, if you are working on a laptop that isn't plugged into an electrical outlet, you should click the Conditions tab and uncheck Start the task only if the computer is on AC power.
- Click OK.
The task properties dialog box closes.
- As a test to check whether the traffic feed is set up correctly, wait a few intervals and make sure that the folder location specified in the Output Traffic Data Folder parameter of the DownloadTrafficData tool has new traffic files. If you used the folder location suggested earlier, you would find the traffic files in C:\Data\TrafficFiles\v1; they will have a suffix of .dtf.
- Close Task Scheduler.
A black window will appear and stay open whenever the DownloadTraffic script is running. New traffic files will be created in the output traffic data folder you specified when the script is completed. The traffic files will remain there until the script runs again and sees that a traffic file has been in the output folder longer than the duration specified in the Update Traffic Data tool's Maximum File Age in Minutes parameter. If the traffic file's lifetime is longer than the maximum, the file is deleted.
Disabling and reenabling the DownloadTraffic task in Task Scheduler
You may want to prevent the task and script from running while you're not working on this tutorial exercise. The steps in this section are for your reference, but they should not be completed now if you are continuing with the rest of this exercise or exercise 11.
- Open the Windows Task Scheduler by clicking Start then typing Task Scheduler in the Windows search box and pressing ENTER.
- Click Task Scheduler Library.
- Find the DownloadTraffic task in the list of tasks. Right-click it and choose Disable.
After creating and building the network dataset, you set up a geoprocessing model to download live-traffic data and hide your user name and password. You ran the model through a Python file to ensure it could run directly from the operating system and thus through Windows Task Scheduler. Finally, you created a task in Task Scheduler to run the script periodically. The result is a continual fresh supply of traffic data (DTF files) that the network dataset can access.
Visualizing traffic data
Your San Diego network dataset is ready to display live traffic conditions in a map.
- Click the ArcMap button
.
- If the ArcMap - Getting Started dialog box opens, click Cancel.
- Click the Add Data button
.
- Navigate to the SanDiego_ND network dataset that you just created and built.
- Click SanDiego_ND to select it, then click Add.
The Adding Network Layer dialog box opens.
- Click No to add the network dataset only.
The network dataset layer is added to the table of contents and the map display. Current travel speeds are drawn on the map. Green represents freely flowing traffic. Yellow, orange, and red represent progressively slower traffic speeds relative to each street's free-flow speed. Because traffic is drawn relative to free-flow speeds, not as absolute speeds, a residential street with a current travel speed and free-flow speed of 25 miles per hour appears as a green line, while a major highway with a current travel speed of 25 mph appears red if its free-flow speed is much faster, such as 65 mph.
By default, ArcMap draws traffic conditions for the current date and time. For edges with live traffic, this means you are seeing traffic conditions as they are right now. Edges that have historical data, but not live data, display traffic conditions as they tend to be at this time, for this day of the week. (All the traffic in the map may appear green if it is late evening or early morning in San Diego.)
Dive-in:
Network Analyst assumes your operating system's clock and time zone settings are correct. If your operating system's time zone doesn't match the network dataset's time zone—which would mean you are probably not in the Pacific standard time zone—the necessary time-zone conversion is handled for you. The TimeZoneID network attribute makes this seamless conversion possible so that you see current traffic conditions in San Diego or any other part of the world a network dataset may cover.
You can choose to filter out historical traffic data to see only those edges that are currently associated with live traffic data by changing the layer properties as described in the next steps.
- Right-click the SanDiego_ND layer in the table of contents and choose Properties.
- Click the Symbology tab.
- Check Show live traffic only and click OK.
The traffic rendered from historical data is filtered from the map leaving only the edges having live traffic data.
- Repeat the previous three steps to see historical and live traffic again.
- On the Tools toolbar, click the Time Slider button
.
The Time Slider dialog box appears.
- The slider should be enabled. Point to the Enable/Disable time on map button
and click the button if it reads Enable time on map.
- Click the time slider bar and drag it to the time and date for which you want to view traffic; optionally, type that information in the time slider text box and press ENTER instead.
If the time and date you want are outside the current time extent, you need to change the time extent as described in the substeps below.
- Click the Options button
on the Time Slider window.
- Click the Time Extent tab.
- Choose <Undefined> from the Restrict full time extent to drop-down list.
- Change the Start time or End time values so your target time and date are within the bounds.
- Click OK.
- Set the time slider to your target time and date.
Traffic patterns generally vary according to local times. If you are looking at traffic data in a different time zone than the one set on your operating system, you may want to set the time slider's time zone reference to match that of the area of the map you are viewing. This will allow you to avoid mentally converting times before each adjustment you make to the time slider.
To change the time slider's time zone setting, follow these substeps.
- Click the Options button
on the Time Slider window.
- Click the Time Display tab.
- Choose the time zone of the area you are viewing from the Time zone drop-down list.
- Click Adjust for daylight saving changes, unless the daylight saving time isn't honored in that area.
- Click OK.
- Click the Options button
You can see travel speeds for different times and dates by using the time slider as indicated below.
Now that you have seen live traffic conditions on a map, you may want to solve a network analysis given those conditions; for example, you may want to find the quickest driving route or service area for right now. Exercise 11 shows how you can do that.