1

I have NOAA nightlight rasters cropped to country boundaries that I am trying to display using Mapserver. As such, I am trying to have NODATA pixels i.e. those outside the country boundaries be transparent. The only way I have got this to work is by combining:

OFFSITE 0 0 0

with

PROCESSING "SCALE=AUTO".

This works well in that the pixels outside the countries do not appear. However, the raster data pixels now change transparency "randomly" as you zoom in. I am guessing this is the SCALE=AUTO at work - it is possible to have valid zero data values.

I should mention that the NODATA reported by gdal is -3.4e+38 and Gimp shows the pixels outside the country boundaries have RGB values -500.0 -500.0 -500.0.

I have tried setting OFFSITE -500 -500 -500. This does not work.

I have no clue how to use -3.4e+38 in the mapfile for NODATA.

Below are a few screenshots as I zoom in showing the shifting "optics".

At default view all seems okay ... At default view all seems okay ...

First zoom in shift occurs. Maybe zero pixels in raster? First zoom in shift occurs. Maybe zero pixels in raster?

Zoom in again smaller patch Zoom in again seems smaller patch

Zoom in again. Different shift Zoom in again. Different shift

My mapfile is as below:

  MAP
    IMAGETYPE   PNG
    EXTENT          -180 -90 180 90
    SIZE                    800 600
    IMAGECOLOR  "#ffffffff"
    TRANSPARENT ON
    SHAPEPATH     /path/to/nightlights/rasters

    PROJECTION
      "init=epsg:4326"
    END

    OUTPUTFORMAT
      NAME      GEOTIFF
      DRIVER    GDAL/GTiff
      MIMETYPE  image/tiff
      IMAGEMODE PC256
      EXTENSION tif
    END

    WEB
      METADATA
        "wms_title" "Nightlight Rasters"
        "wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=test.map"
        "wms_description" "nightlights"
        "wms_name" "Nightlights"
        "wms_label" "Nightlights"
        "wms_srs" "EPSG:3857"
        "wms_extent" "-180 -90 180 90"
        "wms_formats" "GEOTIFF"
        "wms_enable_request" "*"
      END
    END

    LAYER
      NAME NL_CTRYCODE_VIIRS.M_NLPERIOD_VCMCFG-MTSALL-MEAN-RGFT_GADM-3.6-SHPZIP
      STATUS ON

      TILEINDEX NL_CTRYCODE_VIIRS.M_NLPERIOD_VCMCFG-MTSALL-MEAN-RGFT_GADM-3.6-SHPZIP_tindex.shp
      TILEITEM  "location"
      OFFSITE 0 0 0

      TYPE RASTER
      PROCESSING "SCALE=AUTO"

      PROJECTION
        "init=epsg:4326"
      END

      METADATA
        "DESCRIPTION" "nightlights"
        "wms_title" "NL_CTRYCODE_VIIRS.M_NLPERIOD_VCMCFG-MTSALL-MEAN-RGFT_GADM-3.6-SHPZIP"
        "wms_timeitem"  "nlPeriod"
        "wms_timeextent"  "201401/201412"
      END

      # CLASSITEM "[pixel]"
      #   CLASS
      #     NAME "NODATA"
      #     EXPRESSION ([pixel] = -339999999999999996123846586046231871488)
      #     #EXPRESSION ([pixel] < 0)
      #     STYLE
      #       OPACITY 0
      #     END
      #   END #END CLASS
      # END #END CLASSITEM

    END #END LAYER

  END #END MAP

I have tried using classes but not sure how to do this. Plus it seems pretty expensive in terms of processing. Though I may need to look at this in future to have the bright spots stand out against the dark areas. I can supply a sample raster as well if it will help.

  • If GDAL finds nodata from the source image there should be no need to use OFFSITE. Comment it out and have a try. – user30184 Sep 11 at 11:40
  • @user30184 When I turn off OFFSITE then I get "square" blocks. The pixels outside the boundaries are black. – Chris Njuguna Sep 11 at 11:57
  • An additional observation: there are negative values in the pixel data all between -1 and 0. Could this be a problem? – Chris Njuguna Sep 11 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.