Nov 18, 2022 • Blog

Point in Polygon Tutorial: Travel Time Catchment Area Edition

facebook iconx icon

Contents

This tutorial helps you to:

  1. Identify if a point falls within a travel time polygon area
  2. Calculate travel times to every point within a polygon area
  3. Draw the travel time polygon if you require a visualisation

It includes code examples in many languages including Python, R, Java and JavaScript

At the end of the tutorial we will also include answers to the most important questions:

  1. How much will it cost me?
  2. How many polygons can I create?
  3. Which transport modes can I use to do this?
  4. Where do you get your data?
Blog gif

Example use case

A retailer wants to filter their database of 500 customers to see how many fall within a 30 minute drive of their newly proposed ‘Times Square, New York’ store location. We’ll use this example throughout this tutorial, but you can adjust your request to suit your needs.

Filtering point in a polygon & calculating travel times to every reachable point

In our example, the retailer finds out that 375 of their 500 customers in their database fall within a 30 minute drive, and 125 are unreachable in this time limit. The retailer can see the exact amount of time from the store to the 375 reachable customers. For the remaining 125, there is no value calculated.

To get this information, we use the Travel Time Matrix API, using the time filter endpoint. The request requires the user to specify some parameters:

  • Transport mode
  • Departure time or arrival time. If you don't want a specific time, you can use a range, explore this option more here.
  • Location lat/long
  • Travel time

In our example we've chosen:

  • Driving
  • Departing at 3pm
  • 'Times Square, New York' as our location
  • 30-minute travel time catchment area

The snippet above is a cURL request. We've included some examples for the most common coding languages. The code snippets assume that customers data is read from the 'custom.csv' file. However, it could be your designated database, CRM or other system.

Point in polygon Java

Java code snippet in a nutshell
  • Reads the "customers.csv" file - the retailer's "database" consisting of 500 ids and location coordinates of customers as per example use case description above
  • Accepts the following parameters, required for time filtering: Transport mode, Departure time, Location, Travel time
  • Calculates the results and logs the unreachable customers list to a console
  • Additional information for using TravelTime API with Java can be found here

Point in polygon R

R code snippet in a nutshell
  • Reads the "customers.csv" file - the retailer's "database" consisting of 500 ids and location coordinates of customers as per example use case description above
  • Accepts the following parameters, required for time filtering: Transport mode, Departure time, Location, Travel time
  • Calculates the results, pretty prints the reachable customers to a separate .json format file and logs the unreachable customers to a console
  • Additional information for using TravelTime API with R can be found here

Point in polygon Python

Python code snippet in a nutshell
  • Reads the "customers.csv" file - the retailer's "database" consisting of 500 ids and location coordinates of customers as per example use case description above
  • Accepts the following parameters, required for time filtering: Transport mode, Departure time, Location, Travel time
  • Calculates the results, pretty prints the reachable customers to a separate .json format file and logs the unreachable customers to a console
  • Additional information for using TravelTime API with Python can be found here

Point in polygon JavaScript

JavaScript code snippet in a nutshell
  • Reads the "customers.csv" file - the retailer's "database" consisting of 500 ids and location coordinates of customers as per example use case description above
  • Accepts the following parameters, required for time filtering: Transport mode, Departure time, Location, Travel time
  • Calculates the results, pretty prints the reachable customers to a separate .json format file and logs the unreachable customers to a console
  • Additional information for using TravelTime API with JavaScript can be found here

Drawing the travel time polygon

The snippet below shows the API request needed so that the retailer can draw a 30 minute drive time area from 'Times Square, New York'. If you need a more detailed tutorial on how to visualise this shape on a map,please follow this tutorial.

This uses the Isochrone API. The parameters used in this request are the same as the Time Filter endpoint request above.

FAQs

  1. How much will it cost me?
  2. How many polygons can I create?
  3. Which transport modes can I use to do this?
  4. Where do you get your data?
Visualise locations like never before.
Transform journey time data into an unlimited number of dynamic isochrones maps every month, for one fixed price.
Try for free
cta accent icon
facebook iconx icon

Contents

Calculate thousands of travel times with the TravelTime API

Discover more
cta accent icon