Tutorial | Compute isochrones and routes with the Geo Router plugin#

Dataiku has a Geo Router plugin for computing isochrones and routes. Let’s see how it works!

Get started#

Objectives#

In this tutorial, you will:

  • Use the Compute isochrone recipe from the Geo Router plugin to draw a geometry representing the maximum driving distance around a point.

  • Use the Geo join recipe to filter for locations contained inside an isochrone.

  • Use the Compute route between two points recipe also from the Geo Router plugin to map itineraries.

  • Visualize the results on geometry maps.

Prerequisites#

Create the project#

Let’s get started!

  1. From the Dataiku Design homepage, click + New Project > DSS tutorials > Core Designer > Geo Router Plugin.

  2. From the project homepage, click Go to Flow (or g + f).

Note

You can also download the starter project from this website and import it as a zip file.

You’ll next want to build the Flow.

  1. Click Flow Actions at the bottom right of the Flow.

  2. Click Build all.

  3. Keep the default settings and click Build.

Important

Allow a few minutes for the Flow (in particular the Geo join recipe) to finish computing.

Use case summary#

The project has three data sources:

tx

Each row is a unique credit card transaction that has been either been authorized (a score of 1 in the authorized_flag column) or flagged for potential fraud (a score of 0).

cardholders

Each row is the latitude and longitude coordinates of a unique credit card holder.

merchants

Each row is the latitude and longitude coordinates of a unique merchant, all of which are gas stations.

The Flow joins a small random sample of these three datasets together so that every record in tx_joined is a unique transaction, enriched with data about the location of credit card holders and merchants for that transaction.

Compute isochrones around merchant locations#

Let’s draw our attention to two details of the existing project:

  • The Prepare recipe computing the merchants dataset creates the column merchant_bubble by drawing a circle with a radius of 10 kilometers around the location of a merchant.

  • The Geo join recipe in the project matches card holders within 10 kilometers of a merchant.

This 10 kilometer distance around merchant locations is an “as the crow flies” distance. For some applications however, the true distance between two points is not as important as how long it may take a person to make the trip using a common mode of transport — such as a car.

For answering these kinds of questions, computing an isochrone can be a valuable tool. An isochrone is a geometry that represents the area accessible from a point within a certain amount of time.

Note

To walk through creating the merchant_bubble column yourself, begin from Tutorial | Geographic processors.

Create a recipe to compute isochrones#

Instead of perfect circles, let’s compute an isochrone around each merchant location.

  1. Select the merchants dataset.

  2. From the Actions tab on the right, select Geo Router from the menu of plugin recipes.

  3. Select the Compute isochrone recipe.

  4. Click Set, and name the isochrones dataset as merchant_isochrones.

  5. You may have a different default storage location and format depending on your instance settings. If using an S3 storage, choose a format other than parquet, such as CSV (Metastore compatible).

  6. Click Create Dataset.

  7. Click Create to finish the recipe setup.

Dataiku screenshot of the dialog for creating a compute isochrone recipe.

Define conditions for the isochrones#

Once we have the recipe set up, we can define the conditions for the isochrones.

  1. On the Settings tab of the recipe, provide merchant_geopoint as the geopoint column.

  2. Set the maximum travel time to 30 minutes.

  3. Click Run.

  4. Open the output dataset after allowing a few minutes for it to compute.

Dataiku screenshot of the settings for a compute isochrone recipe.

Note

In the output dataset, you’ll likely notice some cases where an isochrone could not be computed because no nearby route was found. To investigate why this may be, right click on a value in the merchant_geopoint column for a failed row, and click Preview to see where it lies on the map.

View isochrones on a map#

The output data has four new columns. In addition to three columns reporting possible errors, we have an isochrone geometry column. Let’s visualize it on a map!

  1. Navigate to the Charts tab of the merchant_isochrones dataset.

  2. From the chart picker, select Geometry map.

  3. Drag the isochrone column to the Geo field.

  4. Drag merchant_geopoint to the next Geo field. Open the color droplet to change the points to yellow.

  5. Rename the chart Merchant isochrones, and zoom in to explore the results.

Dataiku screenshot of a map of isochrones.

Note

Unlike the uniform “as the crow flies” bubbles, isochrones are irregular because they reflect the ground level reality of traveling in any direction. This can vary significantly based on factors like traffic, speed limits, and the terrain.

Tip

If you’re unfamiliar with maps in Dataiku, see Tutorial | No-code maps.

Geo join merchant isochrones and card holder points#

Now that we have an isochrone representing the reachable distance around a merchant location, let’s find all of the card holders within those areas.

Change schema to geographic storage types#

The Geo join recipe requires join columns to have geopoint or geometry storage types. The cardholders dataset already has the correct storage types, but let’s make this adjustment now for the merchant_isochrones dataset.

  1. Navigate to the Settings tab of the merchant_isochrones dataset.

  2. Navigate to the Schema subtab.

  3. Change the storage type of merchant_geopoint from string to geo point.

  4. Change merchant_bubble and isochrone to geometry.

  5. Click Check Now.

  6. Click Save.

Dataiku screenshot of the schema of a dataset.

Create a Geo join recipe#

With the correct storage types, we can proceed with geo joining the merchant and card holder data.

  1. From the Flow, select the merchants_isochrones and cardholders datasets.

  2. Open the Actions sidebar, and select Geo join from the menu of visual recipes.

  3. Once again, if using an S3 storage, choose a format other than parquet, such as CSV (Metastore compatible).

  4. Click Create Recipe.

Dataiku screenshot of the creation modal for a Geo join recipe.

Define the geo join condition#

Now we can define the geographic condition on which to join these datasets. Let’s retain only merchants that have at least one card holder within the boundary of their isochrone.

  1. Click Left join to open the dropdown, and switch to an Inner join.

  2. Click on the join condition once to open it, and again to edit it.

  3. Set the join condition so that the isochrone column from the merchant_isochrones dataset Contains the cardholder_geopoint column from the cardholders dataset.

  4. Click OK.

  5. Click Run.

  6. Open the output dataset.

Dataiku screenshot of the settings for a Geo join recipe.

View card holders within isochrones on a map#

In the output, you’ll notice far fewer records. Many merchants do not meet the condition of the inner join: they do not have a card holder within their isochrone. On the other hand, some merchants have multiple card holders within their isochrone. They now appear in the dataset multiple times — one merchant record for every qualifying card holder.

Once again, let’s confirm our results on a geometry map. We can start by copy-pasting the settings of the previous chart.

  1. Return to the previous map. One way to get there via the Flow is through the Details tab of the merchants_isochrones dataset’s right panel.

  2. Open the options menu at the bottom left, and click Copy chart to clipboard (as shown in the previous map image).

  3. Navigate to the Charts tab of the merchants_isochrones_joined dataset.

  4. Open the options menu at the chart’s bottom left. Select Paste chart from clipboard. Follow the prompt to Paste and Replace the empty chart.

  5. Drag cardholder_geopoint to the next Geo field.

  6. Rename the chart Cardholders within merchant isochrones, and zoom in to verify that every remaining card holder lies within a merchant isochrone.

Dataiku screenshot of a map of isochrones containing points.

Compute routes between points#

Now that we have found the card holders within a certain driving distance from a merchant, let’s compute the actual routes the card holders would use to reach the merchants!

Create a recipe to compute routes#

The first step is to set up the recipe.

  1. Open the Actions tab of the merchants_isochrones_joined dataset.

  2. Select Geo Router from the menu of plugin recipes.

  3. Select the Compute route between two points recipe.

  4. Set the routes dataset as merchant_cardholder_routes.

  5. As before, avoid using a parquet storage format.

  6. Click Create Dataset.

  7. Create the recipe.

Dataiku screenshot of the dialog for a compute routes recipe.

Define route computation settings#

Once that is in place, we can define the recipe’s parameters.

  1. On the Settings tab of the recipe, set the starting point as cardholder_geopoint.

  2. Set the destination as merchant_geopoint.

  3. Set the distance unit to Kilometers.

  4. Check the box to Output the itinerary as a geometry column.

  5. Click Run, and open the output dataset when it is finished.

Dataiku screenshot of the settings for a compute routes recipe.

Map routes between points#

In addition to three more columns for reporting errors, the output contains three new columns:

time

The estimated driving time between the merchant and card holder points.

distance

The length of the route in kilometers (as chosen in the recipe).

itinerary

A linestring geometry mapping the route between the points.

Once more, let’s check the results on a geometry map. Again, we can copy-paste the previous map as the base for the new map.

  1. Return to the previous map. One way to get there is through the Details tab of the merchants_isochrones_joined dataset in the Flow.

  2. Open the options menu at the bottom left, and click Copy chart to clipboard.

  3. Navigate to the Charts tab of the merchant_cardholder_routes dataset.

  4. Open the options menu at the chart’s bottom left. Select Paste chart from clipboard. Follow the prompt to Paste and Replace the empty chart.

  5. Drag itinerary to the fourth Geo field.

  6. Rename the chart Routes between cardholders and merchants, and zoom in to verify that every remaining card holder lies within a merchant isochrone.

Dataiku screenshot of a map showing routes between points.

What’s next?#

Congratulations! You’ve computed isochrones around a location and routes between two points. These can be especially useful techniques when the “as the crow flies” distance is not as relevant as real-world travel conditions.

Note

For more information on georouting and isochrones, see the reference documentation or the Geo Router plugin page.

You can also find an example gallery project demonstrating many of Dataiku’s geographic features.

Once you are comfortable working with geographic data in Dataiku, you may wish to explore additional geographic functionality offered through other plugins. For an example, try Tutorial | Working with shapefiles and US census data or explore the OpenStreetMap Enrichment plugin!

Tip

You can find this content (and more) by registering for the Dataiku Academy course, Geospatial Analytics. When ready, challenge yourself to earn a certification!