Understanding road envelopes

When a Road is returned in a response, what traits do Bounds and Envelope describe?

[
  {
    "$type": "Tfl.Api.Presentation.Entities.RoadCorridor, Tfl.Api.Presentation.Entities",
    "id": "a2",
    "displayName": "A2",
    "statusSeverity": "Good",
    "statusSeverityDescription": "No Exceptional Delays",
    "bounds": "[[-0.0857,51.44091],[0.17118,51.49438]]",
    "envelope": "[[-0.0857,51.44091],[-0.0857,51.49438],[0.17118,51.49438],[0.17118,51.44091],[-0.0857,51.44091]]",
    "url": "/Road/a2"
  }
]

So my gut feeling is that bounds is the start and end points of the envelope and the envelope describes points along the road. But I don’t understand how the coordinates work, my cursory googling is pointing me to a little ways off the coast of Somalia.

I can’t seem to find a blog post or piece of documentation that explains how to map these values.

The points are lines. They tend to go along the direction of a road. We map them as lines and put a an area around them to create a complex polygon. The maths for creating the polygons from series of lines is non-trivial

The first coordinate is the longitude and the second number in each pair is the latitude. You need to use various geospatial techniques to accurately map them to a curved surface. For many small distances, simple trigonometry works, but if you’re doing anything over a few miles, you need to do the maths properly.

You can see what we do by searching for #jambusterlondon on Twitter. The coloured areas shows the coordinate mapping. Our apps also use this but do a lot more.

Hope that helps,

Here’s a few pictures, each of these have two lines in them. We optimise some pictures to speed up image generation

Rob

1 Like

I think this is where I tripped up, should have spotted that. Was going off of [Latitude, Longitude]. :sweat_smile:

Cheers for the pointers, it looks like I’ve got a little more research ahead of me than I’d previously anticipated. :grin:

It’s tricky. TfL also embeds lines inside the JSON at different levels so you can’t assume the JSON has just two levels. Also the lines don’t always work contiguously.

We ended up writing a lot of code to handle geospatial calculations. If you are using Openstreetmap or similar then you need to be accurate on your calculations as any graphics will simply be wrong.

If you look at the images above you can see that the middle of the radius of each curve is on a road, if you get that wrong a) it looks rubbish b) it’s wrong!

Rob