This tutorial shows ArcGIS users how to create a distance and travel time matrix in ArcGIS using the TravelTime add-in. Using public transport data, we can perform an extensive distance analysis and calculate travel times from many origin-destination routes very quickly.
- Using TravelTime to create a distance matrix in ArcGIS
- Calculating employee travel times by public transport and driving
- What the analysis shows
A distance matrix is a two-dimensional array containing the distances between different locations.
Creating a distance matrix can be beneficial for various reasons. For example, they can be used for calculating travel times from popular origin-destination routes in transport planning. In retail store planning, they are used for calculating customer travel times from their homes to the retailers’ current locations, competitor locations and prospect locations.
With regards to the current pandemic, they can help Covid vaccine centre planning, by calculating travel times from home locations to local vaccine centres.
A distance and travel time matrix can help calculate travel times between thousands of origins and destinations
In this tutorial, we’ll show ArcGIS users how to create a distance and travel time matrix in ArcGIS Pro using the TravelTime add-in, which features a distance matrix calculator tool. This will be done using a fictional use case where a company wants to understand how an office relocation will impact employee commute times, with the aim of pinpointing the most suitable office location.
By creating a distance matrix in ArcGIS Pro, we can compare the travel times from the home offices of employees to multiple office locations through a proximity analysis. This allows us to compare the travel times for all employees to all office locations, we can decide what would be the optimal new office location, namely the one with the lowest travel times for its employees.
Using TravelTime to create a distance matrix in ArcGIS
We’ll now explain how to use the TravelTime add-in for ArcGIS Pro to create a distance matrix. Our analysis will focus on London. We will start with creating a list of ten (random) employee addresses and a list of five (random) potential office locations in London. These lists are saved as two separate tables that we can import into ArcGIS Pro and geocode them.
STEP 1: Generating random London addresses and store them inside a CSV file
Starting off with generating a list of ten random addresses, we can use this website and copy the returned London postcodes into a Notepad file that we’ll save as a CSV (comma-separated) file in a local file directory, including a header that indicates three specific columns. This is done to give ArcGIS Pro as much info as possible when geocoding the addresses.
To create five office location addresses, repeat the exact procedure as described above: refreshing the Random London Postcode URL will result in new addresses. An example CSV file containing 10 fictional employee addresses can look like this:
ADDRESS, CITY, COUNTRY
NW8 7EA, London, UK
W2 6AH, London, UK
N17 6RQ, London, UK
N2 8EN, London, UK
W2 4RJ, London, UK
SW15 5LF, London, UK
E16 2ER, London, UK
SE1 9BA, London, UK
SE18 4HH, London, UK
NW8 0NU, London, UK
STEP 2: Adding the tables to the table of contents inside ArcGIS Pro
With the two newly created address tables, we can open ArcGIS Pro and create a new, empty project where we add both tables to the table of contents. This is done by expanding the Add Data drop-down menu Add Data on the Map tab on the ribbon interface, and clicking “Data - add data to the map”.
The result of this operation should be that we have now two tables being added to the table of contents on the left of the screen:
Note that we have not yet added any data to the map. This will be the next step.
STEP 3: Geocoding the address data from the two tables
The two tables can be converted to locations on a map using Pro’s geocoding tool. Rather than searching for the geocoding toolbox, you can right-click any of the two tables in the table of contents and choose “Geocode Table” to geocode the address table. The geocoding workflow is described in the tool itself and self-explanatory.
After choosing the input table, choose “ArcGIS World Geocoding Service” as the locator of choice and click next. This is a geocoding tool from Esri that consumes ArcGIS credits. The tool correctly assigns the data from our tables to Esri’s locator fields, so no changes are necessary from our side. Your screen should like this:
Click next, leave the output as it is and choose “routing” for Preferred Location Type. Click next and check “United Kingdom” as the Country of choice. Click next and choose “Postal” under category as we used postcodes in our tables. Now select “Run” to run the tool and have the results added to your map.
Repeat this process for the second table and change the map’s coordinate system to WGS 1984 Web Mercator by right-clicking “Map” in the table of contents and choosing Properties and Coordinate Systems next.
We changed the map symbology and chose red dots for the five office locations and blue dots for the employee address locations. Finally, we added a number to each location through the Label Properties menu adding the ObjectID field as an Arcade expression, which helps to distinguish between different locations during the analysis later on. The resulting map looks as follows:
Now that we’ve converted the table’s addresses to locations on a map, we are now ready to calculate the distance matrix using the TravelTime add-in which has to be downloaded and installed first, and activated with an API key.
Calculating employee travel times by public transport and driving
The TravelTime add-in includes a Time Filter tool for creating a distance matrix. The tool is capable of creating matrices with thousands of origins and destinations if needed.
In this case, we’re interested in a distance matrix with travel times from each ten employee addresses to all five office locations, resulting in a 5x10 matrix. This can be done in one go using the Time Filter tool that is found in the TravelTime Toolbox in the Catalog window.
You can display it by clicking the “Show the Toolbox” button, the second-left button in the TravelTime Platform menu on the ribbon interface:
Next, we click “Time Filter Simple” in the TravelTime Toolbox in ArcCatalog and fill in the required parameters to create the distance matrix. We use the maximum travel time of 240 minutes to see how much time it takes to reach the office locations from all employee addresses. For travel mode, we choose “Driving”:
Looking at the table of contents, we see a new feature class with corresponding star-shaped symbology on the map. We repeat the same process, but now we choose “public transport” as our travel mode:
We’ll now have a look at the corresponding attribute tables that show the actual distance matrices for both output layers and interpret the results.
What the analysis shows
The Time Filter tool creates two kinds of output after running it:
- It produces an output layer featuring one or two classes: green stars for reachable destinations within the allowed travel time and grey stars for non-reachable ones.
- It creates a distance matrix that is accessed by opening the output layer’s attribute table.
As for the first output, the stars on the map, we can see that for both driving and public transport modes, all destinations are reachable within the four-hour time limit we specified under the travel time parameter before running the tool.
As all five office locations are marked with green stars, it means they can be reached within four hours driving or using public transport from our employee addresses. This is to be expected since all origins and destinations are within a relatively small area.
Next, we open up the attribute tables to have a look at the individual origin-destinations travel times:
Looking at the amount of rows, we see that we have 50 rows in total, which corresponds with our 10x5 origin/destinations options. For each row, we see the ID of both origin and destination, so we can infer their corresponding locations on the map.
If this analysis is repeated using the Time Filter Advanced tool instead of Time Filter Simple, the ID fields can be set in advance to see which row corresponds to which origin and destination. This is shown in the image below, showing both the origin and destination address locations for each origin/destination pair:
The value of one in the column named “reachable” is a Boolean value for True. The travel_time columns specify the travel time from the origin to their destination in seconds. This information allows us to answer the two questions below.
1. What are the best and worst office locations based on average commute times?
Sorting the distance matrix by destination in ascending order and calculating the average travel time per destination, we get a better overview of the travel times per destination.
We also add an extra field to store the travel time in minutes, rather than seconds (displayed in the image above). This is done by adding a field and calculating the individual fields by right-clicking the field name and selecting Calculate Field and using the !travel_time! / 60 as a Python3 expression. Click ‘OK’ and the fields are populated automatically by ArcGIS Pro.
After selecting the individual rows per destination (holding the shift button as you select multiple rows of the distance matrix with your mouse, the rows should be marked in light-blue), right-click the newly populated field with the travel time in minutes and choose “Statistics” to inspect the average commute times per office location in minutes:
The resulting statistics screen is displayed below. Here, we are interested in the mean commute times for public transport of our selection, in this case all different origins to destination 1, which is exactly 50 minutes:
Repeating this procedure for every destination for both travel modes, we get the following average commute times:
Destination 1: 41.6 minutes (driving time) 50 minutes (public transport)
Destination 2: 52.4 minutes (driving time) 53.1 minutes (public transport)
Destination 3: 59.2 minutes (driving time) 70.5 minutes (public transport)
Destination 4: 70.6 minutes (driving time) 72.6 minutes (public transport)
Destination 5: 47.5 minutes (driving time) 59 minutes (public transport)
Based on these numbers, we can conclude that Destination 1 would be the best office location based on average commute times, whereas Destination 4 would be the worst office location based on average public transport commute times.
2. What’s the average difference in commute times between the employees’ current office and the next best location?
Let’s suppose the employee’s current office is Destination 1, with an average commute time of 50 minutes. The next best location in this case would be Destination 2, with an average commute time of 53.1 minutes. The average difference in commute times in this case would be 3.1 minutes.
The TravelTime add-in has the ability to create travel time and distance matrices and assess public transport data. We have shown that we can do extensive commute time analysis for many origin-destinations at once using the Time Filter tool from the add-in.
The tool can also be used when a new location opens: for hiring new staff at the office location, a GIS user could layer demographic data in addition to travel times to see how many people of a certain social demographic live within a commutable distance of each new office location.
The add-in can also be used to analyse what local amenities the new office location requires, e.g. walking travel time to points of interest such as supermarkets, cafes and more.
To create your own analysis, download a free trial of the TravelTime add-in for ArcGIS Pro here.