Repository navigation
Description
When a raster layer is queried via a WMS GetFeatureInfo request pixels equal to the band's nodata value are returned as regular features with the nodata value as value_0. If the layer has classes the nodata value is classified like any other value.
On the other hand, a GetMap request correctly treats them as nodata and they're drawn transparent. A user triggering a WMS GetFeatureInfo request on an empty area of the map receives the nodata value instead of an empty result.
I noticed this issue on MSC GeoMet with netCDF ocean model output using _FillValue = 1e+20 over land. A GetMap request correctly shows land as empty but a GetFeatureInfo over land returns 1e+20 since the the style's top class is open-ended and captures the nodata value.
The only way a nodata pixel is left out of query results is when its value happens to match none of the layer's classes. Layers without classes or those that have classes with a open-ended range (e.g. ([pixel] >= 38)) will always return it.
This seems to have been previously reported in #3750 which was auto-closed for inactivity.
Steps to reproduce
- Create a 2x1 Float32 GeoTIFF with nodata = -9999, where the left pixel is nodata and the right pixel is 5:
from osgeo import gdal
import numpy as np
ds = gdal.GetDriverByName("GTiff").Create("nodata.tif", 2, 1, 1, gdal.GDT_Float32)
ds.SetGeoTransform([0, 1, 0, 1, 0, -1])
ds.SetProjection("EPSG:4326")
band = ds.GetRasterBand(1)
band.SetNoDataValue(-9999)
band.WriteArray(np.array([[-9999, 5]], dtype="float32"))
ds = None- Mapfile:
MAP
EXTENT 0 0 2 1
SIZE 200 100
PROJECTION
"init=epsg:4326"
END
OUTPUTFORMAT
NAME "png"
DRIVER "AGG/PNG"
IMAGEMODE RGBA
TRANSPARENT ON
END
WEB
METADATA
"wms_enable_request" "*"
"wms_srs" "EPSG:4326"
"wms_title" "test"
END
END
LAYER
NAME "nodata"
TYPE RASTER
STATUS ON
DATA "nodata.tif"
TEMPLATE "dummy"
PROJECTION
"init=epsg:4326"
END
METADATA
"wms_title" "nodata"
"wms_include_items" "all"
END
CLASS
NAME "below 100"
EXPRESSION ( [pixel] < 100 )
STYLE
COLOR 255 0 0
END
END
END
END
- GetMap - here the nodata pixel is transparent as expected:
SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&LAYERS=nodata&STYLES=&CRS=EPSG:4326&BBOX=0,0,1,2&WIDTH=200&HEIGHT=100&FORMAT=image/png&TRANSPARENT=TRUE
The pixels on the nodata side of the GeoTIFF are rendered transparent (not visible) while those with values are rendered in red.
- GetFeatureInfo on nodata cell
SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&LAYERS=nodata&QUERY_LAYERS=nodata&STYLES=&CRS=EPSG:4326&BBOX=0,0,1,2&WIDTH=200&HEIGHT=100&I=50&J=50&INFO_FORMAT=text/plain
Layer 'nodata'
Feature 0:
x = '0.5'
y = '0.5'
value_0 = '-9999'
value_list = '-9999'
class = 'below 100'
red = '255'
green = '0'
blue = '0'
I tried adding PROCESSING "NODATA=-9999" to the layer but the GetFeatureInfo request gives the same result.
Expected behaviour
A query on a nodata pixel returns no feature for that pixel, the same as a query outside the raster's extent which is more consistent with GetMap rendering it as transparent. With the current behaviour an application making GetFeatureInfo requests can't tell nodata from real values without knowing in advance which value the dataset uses for nodata.
I was able to reproduce the above issue with identical results on Linux with the following builds:
- MapServer 8.2.2 (GDAL 3.8.4, PROJ 9.3)
- MapServer 8.6.6 via conda-forge with GDAL 3.13, and PROJ 9.9.
Activity