mapbox / rio-rgbify

Encoded arbitrary bit depth rasters in pseudo base-256
MIT License
99 stars 36 forks source link

Error occurred over-altitude terrain RGB raster tileset in Mapbox GL JS #33

Open chingchai opened 2 years ago

chingchai commented 2 years ago

Hi, I use my DEM generate from Drone using OpenDroneMap. After that, I use gdal_warp to re-project my DSM to EPSG:3857 and transform the greyscale data into the RGB data using rio-rgbify and last step i use gdal2tiles.py to generate xyz tiles. But i got error when add tiles layer to Mapbox GL JS as the picture shown below.

        this.map.addSource("mydem", {
          type: "raster-dem",
          tiles: [
            "https://url/tiles/dem-rgb-v2/{z}/{x}/{y}.png",
          ],
          tileSize: 512,
          maxzoom: 18
        });
        this.map.setTerrain({ source: "mydem", exaggeration: 0.7 });

image

image

Nitaym commented 2 years ago

Hey, I'm seeing a very similar issue. My process is the same: gdalwarp to 3857, then rgbify.

Check out these edges that appear (left and center are rgbify, right is mapbox online for reference): image

Here are the PNGs. rgbify: image

From mapbox: image

Using the tiles in 3D yields very similar results to what you're seeing: image

Nitaym commented 2 years ago

Hey, for whoever runs into this in the future:

The problem is in gdal2tiles, where it resamples the images using conventional algorithms for image resizing (nearest neighbor, bilinear, etc). However, since terrainpng pixels are not really colors, but encoded elevation values, the resampling actually creates problems in the data - See images above.

I couldn't find any method that works with GDAL directly. Ended up tiling directly from python with rasterio, then converting the data to terrainpng per tile.

Nitaym commented 2 years ago

Quick note:

Jrodseth commented 1 year ago

Using nearest neighbor resampling when computing tiles via gdal2tiles will prevent interpolation between pixels.

e.g. gdal2tiles.py **-r near** --xyz -z 10-20 -tilesize=512 rgbify_input.tif ./tiles/

This won't produce spiking along boundaries where red and green band values change, but it instead will result in a blocky appearance at high zoom levels. Likely acceptable for some use cases.