How to create a GeoJSON isochrone

by Niharika Sisodia
on Sep 17, 2018 9:26:37 AM

What is GeoJSON?

GeoJSON is a specification for storing and representing geographic data in JSON format. If you have JSON data that contains latitude and longitude values, the data needs to be converted to GeoJSON format before you can view it on a map.

What is an isochrone?

An isochrone, in this context, is a shape that shows all locations that are reachable within a set travel time limit. For example, the image below shows all the locations you can reach within 45 minutes assuming you depart Times Square, Manhattan at 1pm on a weekday.

GeoJSON-isochroneHow do you create an isochrone?

In this blog, we use the TravelTime API to create an isochrone shape. The API’s TimeMap feature returns JSON response. We can convert JSON to GEOJSON using the steps below. Take a look at an example TimeMap response.

Example of an isochrone shape returned by the TravelTime API using TimeMap

GeoJSON-isochroneGET AN API KEY

The response is made up of:

Shells

This is the term to describe the makeup of the isochrone. The lat/long coordinates describe the linear ring of the isochrone. This defines the points that should be joined up to define the isochrone shape.

GeoJSON-isochrone

Holes

This is the term to describe the areas within the total isochrone shapes that aren’t reachable. The coordinates of the cut out are given to the user.

GeoJSON-isochrone

To get more information on how to create an isochrone using the TravelTime API take a look at this tutorial

How to convert a TravelTime TimeMap JSON response to GeoJSON

The TimeMap endpoint returns an array of shapes for each successful search queried in the request. The shape consists of a linear ring of coordinates for the shell of the polygon and an array of linear rings for holes within the polygon. Coordinates are in a { ‘lat’: <latitude>, ‘lng’: <longitude> } format. See full JSON response here.

In GeoJSON this can be represented as MultiPolygons inside a FeatureCollection. Firstly we need to convert coordinates to a [<longitude>, <latitude>] format.

Converting coordinates in a linear ring

This can be achieved by mapping each coordinates object in the response to an array of coordinates:

Converting the array of shapes into a MultiPolygon

For this we iterate through all shapes, converting their linear rings with the previous function to convert coordinates, combine all rings into a single array where the first element of the array is the shell and put all resulting rings into a MultiPolygon object as specified in the GeoJson specification.

Converting the complete response

If the response has not yet been parsed from JSON we need to parse it first. Then we iterate through each result and convert their shapes into a MultiPolygon with the function above. Finally, we put the array of resulting MultiPolygons into the FeatureCollection object and return it. The result of this function can be converted back to a JSON string and written to a file or sent to another service as input.

Complete code

The complete code for reference:

Converting JSON to GeoJSON in Python

Here is an equivalent code snippet in Python:

Viewing GeoJSON within an application

After the response has been converted, it can be viewed using a number of applications.

GeoJSON is compatible with several mapping API’s, including:

  • Leaflet
  • Google
  • Open Layers

It is also compatible with other open source software, including:

  • QGIS
  • PostGIS

GET AN API KEY

Learn more about isochrones here.

 

Related

IKEA's marketing team uses TravelTime to create a drive time map

IKEA uses TravelTime to build a drive time map. See how their marketing team use it to adjust messaging to their audience.

Evelina Bezubec Oct 10, 2019 11:25:38 AM
READ

Isochrone analysis made easy

Isochrone analysis simplified. Learn how to use isochrone analysis in mapping. Improve customer service, logistics or plan an office relocation using isochrones analysis techniques. Save time and costs, and retain staff using the TravelTime platform.

Niharika Sisodia Apr 1, 2019 10:15:00 AM
READ

Isochrone API tutorial: see how far you can travel within a time limit with Leaflet & TravelTime API polygons

How far you can travel within 'X' minutes using different modes of transport? This isochrone API tutorial helps you make travel time maps. Use the TravelTime API for smart location intelligence.

Niharika Sisodia Mar 14, 2019 11:10:35 AM
READ

Isochrone map design inspiration

Perfect your isochrone map design. Use these tips to make your isochrone map easy to understand. Improve user experience by creating a simple and aesthetically pleasing isochrone map.

Niharika Sisodia Feb 11, 2019 9:05:01 AM
READ

How far can I travel in 15 minutes or 1 hour? This map shows you.

How far can I travel within a time limit? Make a map to show you where you can reach within a certain travel time. Change the mode of transport and time of day. Add up to three starting locations and filter the intersection between them.

Niharika Sisodia Nov 26, 2018 9:17:41 AM
READ

Create your own driving commute distance map in the USA & beyond

Create a commute distance map and drive time map. View potential areas to work on a commute distance map. Search by travel time instead of distance.

Niharika Sisodia Nov 14, 2018 1:45:13 PM
READ