Skip to content

MapServer TILEINDEXes with Database RASTERS

Mark Garcia edited this page Jul 11, 2018 · 3 revisions

Database TILEINDEXes are a little odd in MapServer, they require 2 separate layers, a TILEINDEX layer and a RASTER layer that refers to the TILEINDEX layer.

In Postgres a TILEINDEX view is required and can be created as follows:-

CREATE or REPLACE MATERIALISED VIEW my_raster_tindex AS
SELECT 'PG:host=HOST port=PORT dbname=''DATABASE'' user=''USER'' password=''PASSWORD''  schema=''SCHEMA''  table=''TABLE'' mode=''1'' where=rid='||rid as location, ST_ConvexHull(rast) as shape from rasters_table

For Postgres you may want to create a service file instead of storing every parameter (including the password). i.e. SELECT 'PG:dbname=DATABASE service=SERVICE schema=.... Note that you still need to specify dbname ahead of service because of this outstanding issue in GDAL.

In Oracle, you'll want to create the TILEINDEX as a view to the GEORASTER table of interest.

create or replace view my_raster_tindex as
select some_attribute, 'geor: user/pass@tns,
       raster_table_DATA,'||r.raster.rasterid location,
       R.RASTER.spatialextent shape from rasters_table r;

This view will then be used for the TILEINDEX layer

LAYER
  name raster_tindex
  TYPE polygon
  PROJECTION
    "init=epsg:xxxx"
  END
  CONNECTIONTYPE ORACLESPATIAL
  CONNECTION "user/pass@tns"
  DATA "shape from my_raster_tindex using srid xxxx"
END

Then you add a second layer that is the actual RASTER layer

LAYER
  name db_raster_layer
  TYPE RASTER
  PROJECTION
    "init=epsg:xxxx"
  END
  TILEINDEX "raster_tindex"   #THIS NAME MUST MATCH THE TILEINDEX LAYER NAME
  TILEITEM "location"   #not actually needed if column is named location
  STATUS OFF
  OFFSITE 0 0 0
END

One last piece that is needed is to set the SHAPEPATH to null so that the paths to the raster files are treated as database connections and not files.

Add

SHAPEPATH ""

Clone this wiki locally