Mapbox – Troubleshooting Missing 1-Pixel Buffer in Terrain-RGB Tiles

mapboxpythonrasterrgbterrain

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:

enter image description here

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 of terrain-rgb pngraws, the buffer indeed shows up. Get data:

rm -f terrain-dem_14_8106_5578.webp
rm -f terrain-dem_14_8107_5578.webp

curl "https://api.mapbox.com/raster/v1/mapbox.mapbox-terrain-dem-v1/14/8106/5578.webp?access_token=ACCESS_TOKEN" \
      -o terrain-dem_14_8106_5578.webp

curl "https://api.mapbox.com/raster/v1/mapbox.mapbox-terrain-dem-v1/14/8107/5578.webp?access_token=ACCESS_TOKEN" \
      -o terrain-dem_14_8107_5578.webp

Python:

from PIL import Image
import numpy as np

im_14_8106_5578 = Image.open('terrain-dem_14_8106_5578.webp')
im_14_8107_5578 = Image.open('terrain-dem_14_8107_5578.webp')

array_14_8106_5578 = np.array(im_14_8106_5578)
array_14_8107_5578 = np.array(im_14_8107_5578)

array_14_8106_5578[:,:,2] is then:

array([[191, 198, 205, ...,  62,  61,  59],
       [197, 204, 211, ...,  63,  62,  61],
       [204, 210, 216, ...,  65,  64,  63],
       ...,
       [ 67,  67,  67, ...,  61,  55,  50],
       [ 72,  71,  71, ...,  64,  59,  54],
       [ 76,  76,  75, ...,  68,  63,  58]], dtype=uint8)

and array_14_8107_5578[:,:,2] becomes:

array([[ 61,  59,  58, ..., 152, 145, 139],
       [ 62,  61,  60, ..., 154, 147, 141],
       [ 64,  63,  62, ..., 156, 149, 142],
       ...,
       [ 55,  50,  45, ...,  70,  69,  67],
       [ 59,  54,  49, ...,  71,  70,  69],
       [ 63,  58,  53, ...,  72,  71,  71]], dtype=uint8)

The buffer is observable.

Related Question