How to create a GeoJSON isochrone

by Niharika Sisodia
on Sep 12, 2018

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-isochrone

Click 

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

Click

Learn more about isochrones here.

 

Related

Tutorial for Making Isochrones With Postman & Traveltime API

With this Time Map endpoint tutorial using postman, you can get a list of coordinates showing a perimeter of where’s reachable within a travel time limit.

Evelina Bezubec Nov 4, 2019
READ

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 9, 2019
READ

5 ways to do geocoding for free

Discover solutions that do geocoding for free. Find out which free geocoders have the best functionality. Convert addresses and postcodes into coordinates.

Evelina Bezubec Sep 9, 2019
READ

5 Google Places API alternatives for points of interest data

Find Google Places API alternatives. Connect to a reliable 'points of interest' database via an API. Improve user experience and perfect your location search tool.

Louisa Bainbridge Jun 14, 2019
READ

The guide to TravelTime API limits

Discover the volume of searches you can do per month and per minute on the TravelTime API free plan. You can use more than one search in an API request.

Louisa Bainbridge May 16, 2019
READ

Step by step free geocoding for Leaflet

Geocoding for Leaflet. Learn how to use a geocoder that is Leaflet-compatible. Convert addresses and postcodes into coordinates to be displayed on a Leaflet map.

Louisa Bainbridge May 7, 2019
READ