1

The goal in my current project is to create a WMS from a GeoTIFF raster layer that was previously uploaded to a PostgreSQL database with PostGIS enabled via "raster2pgsql". That worked out well and I can create a working WMS from a single raster.

My problem is when working with temporal raster data. I have e.g. a GeoTIFF with temperature data from Africa with 10 different bands, where every raster band corresponds to a different year (e.g. data from 1990 to 2000). I successfully uploaded the multiband raster to my database with raster2pgsql (raster2pgsql –s 4326 -F –I –C –t auto myraster.tif schema.table | psql –d database) and created a .map file so i can receive a valid WMS.

The .map file looks like this:

MAP
  NAME          "rd_hist"
  IMAGETYPE     PNG24
  EXTENT        -25 -48 60 44
  SIZE          1000 1000
  PROJECTION    
    "init=epsg:4326"
  END

  WEB
    METADATA
      "wms_title"           "rd_hist"
      "wms_onlineresource"  "https://localhost/cgi-bin/mapserv?map=/ms4w/data/raster/rd_hist.map"
      "wms_srs"             "EPSG:4326"
      "wms_enable_request"    "*"
    END
  END

  LAYER
    NAME        "rd_hist"
    TYPE        RASTER
    STATUS      ON
    DATA        "PG:host=localhost port=5432 sslmode=disable user=postgres password=**** dbname=**** schema=public table=rd_hist column=rast mode=2"

    PROJECTION  
      "init=epsg:4326"
    END

    CLASS
    NAME "rd_hist"
    END

    TEMPLATE    "empty"

    PROCESSING 
      "CLOSE_CONNECTION=DEFER"
    END

    WEB
      METADATA
        "wms_title"           "rd_hist"
        "wms_onlineresource"  "http://localhost/cgi-bin/mapserv?map=/ms4w/data/raster/rd_hist.map"
        "wms_srs"             "EPSG:4326"
      END
    END

  END
END

I now want to enable the layer, so that i can use the "&TIME=xxxx" Parameter on the WMS request to request a single band, corresponding to a specific year. I could not figure out to configure this with the help of the MapServer documentation as this only states WMS Time for vector layers outside of PostGIS.

I am also not quite sure if this approach is actually doable or if i have to upload every year from my raster as a single layer. Maybe there is also an easier solution with getting just a single band directly in the WMS getMap request. But in the end i have to request with the years, as users will be chosing which layer to load depending on the year.

How do I enable my multiband temporal raster that is stored in PostGIS so i can use the &TIME attribute to get only one layer? Is there maybe an easier solution i am not aware of, to store and get multitemporal raster data in PostGIS via MapServer?

8
  • What kind of SQL is required for fetching a single band from PostGIS raster?
    – user30184
    May 31, 2022 at 14:00
  • Right now i am using the database only as a storage. My problem is the correct connection to MapServer so i can fetch a single band in the WMS GetMap request, ideally with the "TIME" attribute. So there should not be any SQL involved.
    – Lore_Kni
    May 31, 2022 at 14:05
  • If raster data is stored as PostGIS raster then SQL is certainly involved because it is the only way to get data out from the database. The MapServer driver may hide the SQL but it is there. Do you believe that ST_AsPNG is used? Or ST_AsGDALRaster postgis.net/docs/RT_ST_AsGDALRaster.html?
    – user30184
    May 31, 2022 at 14:33
  • I guess that the raster driver is selecting all the bands gdal.org/drivers/raster/postgisraster.html and that cannot be controlled in DATA. I suggest to read mapserver.org/id/input/raster.html#raster and see how a band can be selected with PROCESSING "BANDS=x". Then read about variable substitution mapserver.org/cgi/runsub.html. Define a variable "BAND" to be used in PROCESSING "BANDS="%BAND%". But then you must write some pre-processor to convert a year into a corresponding band number. I think I would use single band rasters as TIFF files and tileindex.
    – user30184
    May 31, 2022 at 14:50
  • Thanks again for using MS4W ! (so great to see it so heavily used here by users on StackExchange)
    – mapserving
    May 31, 2022 at 15:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.