[GIS] GeoServer remove background color

geoserver

I have single band DEMs I'm trying to use in an ImageMosaic in GeoServer 2.11.2 that displays a black background color by default. I want that background color to go away and the default color ramping to range of displayed values to occur.

enter image description here

The default behavior is almost exactly what I want – when you zoom in, it scales the colors to the min/max of the dataset currently in view.

enter image description here

All I want to do is hide the background color of -9999.0 so that scaling isn't messed up by the nodata color. However all attempts to fix this don't seem to work.

-Setting InputTransparentColor and OutputTransparentColor cause rendering to fail with an error 'Unsupported data type'.

-Setting an SLD ColorMap that hides -9999.0 values 'works' but you need to then to specify the rest of the color ramp which I don't want to do because it needs to be dynamic. (So I don't want this answer).

-Setting an SLD ContrastEnhancement causes a NullPointerException

<ContrastEnhancement>
  <Normalize />
</ContrastEnhancement>

And trying to set VendorOptions inside the ContrastEnhancement Node doesn't validate.

Best Answer

The input/output transparency colors do not work with floating point image mosaics.

The easiest way is probably to add a transparency mask to each of the image, this can be done with GDAL -

gdalwarp -co TILED=YES -co COMPRESS=LZW -srcnondata -9999 -dstnodata -9999 -dstalpha <input image> <output image>

The other options involve creating footprints file or files for the granules in the mosaic, and configuring the behavior of the footprints. See GeoServer Documentation.

Creating the ShapeFile with the actual image footprints can be done with a combination of GDAL tools:

Create a virtual coverage with of the nodata area -

gdal_translate -b mask -of vrt -a_nodata 0 <image file> <image>.vrt

Use polygonize to create polygons that represent the data & nodata regions of the image gdal_polygonize.py -b 1 -8 -q -f gml <image>.vrt <image>.gml footprint DN

Use ogr2ogr to add the data to a shapefile

ogr2ogr -f "ESRI Shapefile" -dialect SQLite -append -sql "select ST_BuildArea(ST_ExteriorRing(geometryProperty)),'<image file>' as location from footprint where DN=255" footprints.shp <image>.gml