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

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

Map circle distance or map drive time distance

Map circle distance using the TravelTime radius map tool. Compare distance to travel time. Create your own travel time map using the TravelTime Platform.

Niharika Sisodia Oct 23, 2018 11:34:54 AM
READ

3 ways to use business location analysis

Use business location analysis tools to support business decision making. Visualize staff commute times and create a travel time matrix for office relocation.

Niharika Sisodia Oct 17, 2018 11:50:01 AM
READ

How to use a radius map tool Google alternative

A radius map tool Google alternative. Draw a circle around a point and compare to travel times.

Niharika Sisodia Sep 26, 2018 11:35:54 AM
READ