Subscribe to this thread
Home - General / All posts - imageserver: Mapbox Terrain RGB
mdsumner


4,223 post(s)
#03-Aug-20 10:32

Mapbox has this terrain source that is encoded in RGB

https://docs.mapbox.com/help/troubleshooting/access-elevation-data/

I put together this SQL command by modifying the inbuilt imageserver for Mapbox Satellite, note the slot for the api-key, the use of 'pngraw', and the name/s:

-- $manifold$

--

-- Auto-generated

-- New Data Source

--

CREATE DATASOURCE [Mapbox Terrain RGB] (

  PROPERTY 'Source' '{ "Source": "http:\\/\\/api.mapbox.com\\/v4\\/mapbox.terrain-rgb\\/{zoom}\\/{x}\\/{y}.pngraw?access_token={key}", "SourceAgent": "Mozilla\\/5.0 Manifold\\/9.0", "SourceApiKey": "<your-mapbox-api-key>", "SourceCache": true, "SourceCacheTemp": true, "SourceSubtype": "mapboxterrainrgb", "SourceUuid": "86f85933-4904-4932-a498-009c2aadfc85" }',

  PROPERTY 'Type' 'imageserver'

);

I can probably see my way through unpacking the channels into a floating point elevation, but is this something I can manipulate in the CREATE command so that the tiles called on demand are streamed via this conversion?

FWIW as per the above mapbox help page the unpacking is

height = -10000 + ((R * 256 * 256 + G * 256 + B) * 0.1)

-


https://github.com/mdsumner

Dimitri


6,206 post(s)
#03-Aug-20 14:21

Very interesting data source! I've signed up for a Mapbox api key and have used your query to create such a mapbox data source.

is this something I can manipulate in the CREATE command so that the tiles called on demand are streamed via this conversion?

I don't think so.

I haven't tried this, but the way I think to get to what you want is to create a query in the project that refers to the table in the data source, [Mapbox Terrain RGB]::[Web], to return, X, Y, and a Tile field that is a single channel float64 Tile containing the height values computed using the unpacking formula from the three channels in the Tile field of the [Mapbox Terrain RGB]::[Web] table. You can then create an image from that query and it should be a terrain elevation raster.

You can create drawings or images from queries, just like creating a drawing or image from a table. Here's an exampleof creating a drawing from a query.

mdsumner


4,223 post(s)
#03-Aug-20 14:31

Thanks! I made some progress on that query, I will pursue with that guidance.

Progress ... including "do not run that literal command above" - the key boilerplate kills it and I had to restart several times repeating the same mistake 😋


https://github.com/mdsumner

mdsumner


4,223 post(s)
#05-Aug-20 02:41

I'm having problems with the SQL, but to help me understand why is there multiple tiles apparent at Level = 0?

There should be one 256x256 Mapbox tile at Zoom 0 (or is there some extra layer with relationship between Level and Zoom?)

I see that the reported extent is the geographic extent divided by the scale and shifted to put zero outside, but is this described in the help somewhere?


https://github.com/mdsumner

adamw


9,415 post(s)
#18-Aug-20 13:32

In 9 (and 8), the lower the level, the more detail it has. For your data set, level 0 is the base level, with many tiles, and level 20 (looking at the metadata) is likely the one with a single tile.

On decoding tiles, it cannot be done dynamically (the dataport is not smart enough to accept, say, a decoding expression) and for static uses it perhaps makes sense to fetch all tiles from level 17 or so, put them into a table in a MAP file, then decode them there. This will limit interactions with the server and let you fail however many times you want during the decoding step without having to re-download everything every time. :-) Just drop the level field altogether and add an rtree index on x-y-tile, it will create intermediate levels from the data you have upwards.

mdsumner


4,223 post(s)
#19-Aug-20 01:54

Ah cool, thanks got it now.


https://github.com/mdsumner

Manifold User Community Use Agreement Copyright (C) 2007-2019 Manifold Software Limited. All rights reserved.