问题
my question is, how to get an elevation profile of the specified route from the MapBox service.
On the input we have path / route as the array of coordinates (latitute, longitute). As the result we would like to get the array of the pairs coordinate - elevation.
In case the resolution of elevation data is higher than the route coordinates provided, the result should contain also the elevation data between the original coordinates. The new points on the route would be generated according to the elevation data resolution. In case the resolution of elevation data is lower, it should interpolate the elevation values from the known data for the queried points. We would like to get results as precise as possible.
As the datasource for our solution we would like to use the MapBox service. However we did not find any documented MapBox API for this specific problem. We only found references to some Surface API, that is no longer supported.
As we understand Mapbox now stores elevation data in the format of Terrain-RGB map tiles. We identified the following steps to be able to solve our problem using MapBox:
- Decode the route coordinates to the minimal set of map tiles.
- Query the map tiles using MapBox API.
- For each coordinate of the route, map it to the specific image pixel.
- Translate the RGB color value of the pixel to the elevation in meters.
Is this algorithm correct? I think, that generating elevation profile for specific route is a common problem is there any tool that provides solution for our problem out of the box, maybe some SDK? Are we missing something? Thanks a lot.
回答1:
Short Answer
For the goal you have in mind, I would advise not using the Terrain-RGB raster tileset. Rather, you should use the Tilequery API to retrieve the elevation for the points along your route from the Mapbox Terrain v2 vector tileset.
Longer answer
There are two possible sources and methods that can be used to retrieve elevation data from Mapbox, and the choice really depends on your needs. Both approaches are outlined in greater detail in troubleshooting documentation you've linked to: https://docs.mapbox.com/help/troubleshooting/access-elevation-data/
Here's the tl;dr for each approach:
1. Retrieve the data from the Terrain-RGB raster tiles
This is the process you've outlined in your original question. This approach is good if you'd like to do things like styling hillshades accurately or generating a 3D mesh for a video game. Note that this method of not well suited for finding the elevation for specific lat/lon coordinate pairs.
2. Retrieve the data from the Mapbox Terrain v2 vector tiles
This process requires you to request an elevation for each point along your route. You can do this by making requests to the Mapbox Tilequery API. To your point about needing to interpolate coordinates between your route coordinates, you can use the Turf.js library to "explode" your line geometry into an array of coordinate pairs that you then pass to the Tilequery API one at a time. Most importantly, you retrieve the correct elevation data from the tileset by parsing the response you receive from the API request.
⚠️ Disclaimer: I currently work at Mapbox ⚠️
来源:https://stackoverflow.com/questions/56078658/how-to-get-elevation-profile-data-from-mapbox