localtileserver: nodata causes padding

When nodata is set to a certain value (e.g., -1), there are some big black empty tiles surrounding the image.

from localtileserver import TileClient, get_leaflet_tile_layer, examples
from ipyleaflet import Map

client = TileClient('https://github.com/giswqs/data/raw/main/raster/landsat7.tif')
t = get_leaflet_tile_layer(client, nodata=-1)
m = Map(center=client.center(), zoom=client.default_zoom)
m.add(t)
m

nodata = -1 Peek 2024-02-07 21-51

nodata=None image

I noticed the example on the documentation page has a similar issue (a white background). However, it displays correctly when used locally. https://localtileserver.banesullivan.com/ image

Local jupyter image

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

the data outside the raster is set to 0 instead of -1 (because of the datatype issue) so then when we are building the mask we don’t find the -1 value

The zero value is very common in remote sensing imagery.

Sure it is, but the issue here is that the nodata value was set in the file while it should not have!

@vincentsarago Thank you for looking into it. QGIS has an option for ignoring the nodata value. Localtileserver used to be able to ignore the nodata value as well. It would be great if rio-tiler can support this as well.

This is pretty hard, I don’t / can’t cover all data problem. The data provider should understand how raster works IMO. The overriding nodata feature was added because at the time of creation of rio-tiler, some organisation didn’t want to add the nodata metadata tag in their raster because it wasn’t part of the original TIFF specification.

Some werid behavior. Increasing the nodata value will result in a colorful background, which is unexpected.

I’m pretty sure this is expected because you’re overriding the nodata value the ocean which in the red and green bands should be close to DN=0 will then not me masked and thus result in weird colors. If you look at the data array you’ll understand.

👋 after some time looking at the issue I’ve realized the problems are:

  • you’re trying to use -1 nodata value on a uint16 dataset, to GDAL will ignore it
  • your data is a RGB with a bad nodata value (0) but this 0 value is proper data
gdalinfo https://github.com/giswqs/data/raw/main/raster/landsat7.tif
Driver: GTiff/GeoTIFF
Files: none associated
Size is 2181, 1917
Coordinate System is:
PROJCRS["WGS 84 / Pseudo-Mercator",
    BASEGEOGCRS["WGS 84",
        ENSEMBLE["World Geodetic System 1984 ensemble",
            MEMBER["World Geodetic System 1984 (Transit)"],
            MEMBER["World Geodetic System 1984 (G730)"],
            MEMBER["World Geodetic System 1984 (G873)"],
            MEMBER["World Geodetic System 1984 (G1150)"],
            MEMBER["World Geodetic System 1984 (G1674)"],
            MEMBER["World Geodetic System 1984 (G1762)"],
            MEMBER["World Geodetic System 1984 (G2139)"],
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]],
            ENSEMBLEACCURACY[2.0]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4326]],
    CONVERSION["Popular Visualisation Pseudo-Mercator",
        METHOD["Popular Visualisation Pseudo Mercator",
            ID["EPSG",1024]],
        PARAMETER["Latitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["False easting",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["easting (X)",east,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["northing (Y)",north,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Web mapping and visualisation."],
        AREA["World between 85.06°S and 85.06°N."],
        BBOX[-85.06,-180,85.06,180]],
    ID["EPSG",3857]]
Data axis to CRS axis mapping: 1,2
Origin = (-13651650.000000000000000,4576290.000000000000000)
Pixel Size = (30.000000000000000,-30.000000000000000)
Metadata:
  AREA_OR_POINT=Area
  OVR_RESAMPLING_ALG=NEAREST
  TIFFTAG_RESOLUTIONUNIT=1 (unitless)
  TIFFTAG_XRESOLUTION=1
  TIFFTAG_YRESOLUTION=1
Image Structure Metadata:
  COMPRESSION=DEFLATE
  INTERLEAVE=PIXEL
  LAYOUT=COG
Corner Coordinates:
Upper Left  (-13651650.000, 4576290.000) (122d38' 5.49"W, 37d58'40.08"N)
Lower Left  (-13651650.000, 4518780.000) (122d38' 5.49"W, 37d34'10.00"N)
Upper Right (-13586220.000, 4576290.000) (122d 2'49.53"W, 37d58'40.08"N)
Lower Right (-13586220.000, 4518780.000) (122d 2'49.53"W, 37d34'10.00"N)
Center      (-13618935.000, 4547535.000) (122d20'27.51"W, 37d46'26.05"N)
Band 1 Block=512x512 Type=Byte, ColorInterp=Red
  NoData Value=0
  Overviews: 1091x959, 546x480
Band 2 Block=512x512 Type=Byte, ColorInterp=Green
  NoData Value=0
  Overviews: 1091x959, 546x480
Band 3 Block=512x512 Type=Byte, ColorInterp=Blue
  NoData Value=0
  Overviews: 1091x959, 546x480
Screenshot 2024-02-13 at 5 46 23 PM

Sadly there is no option in rio-tiler to ignore nodata value (just to overwrite) 😓

The easiest way to fix this is to edit the file and to remove the nodata value

I tried light mode on my local Jupyter and Google Colab. This issue persists. Same thing for folium.

image