I am reading the documentation of Mapbox's Terrain-RGB tiles. It says:
- Buffered tiles. Each map tile includes a 1-pixel buffer around the
edges to enable tile interpolation in uses cases like terrain meshes.
To confirm this, I decided to inspect two adjacent Terrain-RGB tiles: 14/8106/5578 and 14/8107/5578.
Download pngraw files:
curl "https://api.mapbox.com/v4/mapbox.terrain-rgb/14/8106/5578.pngraw?access_token=ACCESS_TOKEN" \
-o terrain-rgb_14_8106_5578.pngraw
curl "https://api.mapbox.com/v4/mapbox.terrain-rgb/14/8107/5578.pngraw?access_token=ACCESS_TOKEN" \
-o terrain-rgb_14_8107_5578.pngraw
Read in contents to numpy arrays:
from PIL import Image
import numpy as np
im_14_8106_5578 = Image.open('terrain-rgb_14_8106_5578.pngraw')
im_14_8107_5578 = Image.open('terrain-rgb_14_8107_5578.pngraw')
array_14_8106_5578 = np.array(im_14_8106_5578)
array_14_8107_5578 = np.array(im_14_8107_5578)
The .shape
of both arrays are: (256, 256, 4)
. The source files are 256 by 256 pixel, 4 channel (RGBA) pngraws. The B channel of terrain-rgb_14_8106_5578.pngraw
, ie array_14_8106_5578[:,:,2]
is:
array([[197, 211, 224, ..., 69, 67, 65],
[211, 223, 235, ..., 72, 70, 69],
[225, 236, 246, ..., 74, 73, 72],
...,
[ 55, 54, 54, ..., 79, 68, 56],
[ 62, 62, 62, ..., 87, 74, 62],
[ 70, 70, 69, ..., 95, 81, 68]], dtype=uint8)
The B channel of terrain-rgb_14_8107_5578.pngraw
, ie array_14_8107_5578[:,:,2]
is:
array([[ 63, 61, 59, ..., 194, 180, 165],
[ 67, 66, 64, ..., 197, 183, 169],
[ 71, 71, 70, ..., 200, 187, 173],
...,
[ 45, 36, 27, ..., 68, 67, 67],
[ 52, 43, 34, ..., 70, 70, 69],
[ 58, 50, 41, ..., 72, 72, 72]], dtype=uint8)
I hoped to confirm the 1-pixel buffer around the edges by inspecting these arrays, but this has visibly failed. To be fully clear, I also made a drawing with the two arrays above:
Why don't the values of the edge-pixels show up in the neighbouring tiles, if the tiles are indeed buffered? Do I misunderstand what this buffering entails?
I would like to create my own RGB-encoded elevation tiles. To be able to do that successfully, I would like to have a deep understanding of Mapbox's Terrain-RGB tiles.
Best Answer
If one queries for
mapbox-terrain-dem-v1
webp tiles, instead ofterrain-rgb
pngraws, the buffer indeed shows up. Get data:Python:
array_14_8106_5578[:,:,2]
is then:and
array_14_8107_5578[:,:,2]
becomes:The buffer is observable.