5

I loaded a PostGIS raster data through OpenLayers and MapServer.

The code inside the OpenLayers is as following :

localWMS = new OpenLayers.Layer.WMS( 
    "Local WMS layers",
    "http://127.0.0.1:8080/cgi-bin/mapserv.exe?MAP=C:/MapServer/raster.map",
    {
        layers: 'polygon',
        transparent: true,
        alpha:true
    },
    { 
        projection:new OpenLayers.Projection("EPSG:4326"),
        units:'m',
        isBaseLayer: false
    }
);

map.addLayer(localWMS);

And here is my map file, I already set opacity to each class of the layer but nothing happens:

LAYER
    DATA "PG:host=*** dbname=*** schema=public table=london where='rid=3' mode='1'"
    NAME "postgis"
    PROCESSING "SCALE=AUTO"
    PROCESSING "NODATA=-9999"
    STATUS DEFAULT
    TYPE RASTER
    UNITS METERS
    CLASS
      NAME "Minor Impact"
      EXPRESSION ([pixel] >= 0 AND [pixel] < 1.29525335532 )
      STYLE
        ANGLE 360
        OPACITY 50
        COLOR 122 182 245
        SYMBOL 0
        WIDTH 1
      END
    END
    CLASS
      NAME "Moderate Impact"
      EXPRESSION ([pixel] >= 1.29525335532 AND [pixel] < 2.59050671063 )
      STYLE
        ANGLE 360
        OPACITY 50
        COLOR 76 230 0
        SYMBOL 0
        WIDTH 1
      END
    END
    CLASS
      NAME "Severe Impact"
      EXPRESSION ([pixel] >= 2.59050671063 AND [pixel] < 5.69911476339 )
      STYLE
        ANGLE 360
        OPACITY 50
        COLOR 252 228 91
        SYMBOL 0
        WIDTH 1
      END
    END
    CLASS
      NAME "Catastrophic"
      EXPRESSION ([pixel] >=5.69911476339 )
      STYLE
        OPACITY 30
        COLOR 232 16 20
      END
    END
END

The map looks like following :enter image description here

Then, I tried to set one of the opacity to less than 1, the red color just disappeared. enter image description here

But if I set the Opacity of the Layer to 50

LAYER
    DATA "PG:host=*******************'"
    NAME "postgis"
    PROCESSING "SCALE=AUTO"
    PROCESSING "NODATA=-9999"
    STATUS DEFAULT
    TYPE RASTER
    OPACITY 50
    UNITS METERS

Even more strange map appeared. enter image description here

Does anyone know what's the problem about that? Or Does anyone know the proper way to set a transparent raster layer via MapServer?

2

probably what you need is to set both OFFSITE and TRANSPARENCY in the layer section, something like this:

LAYER
NAME 'Raster'
TYPE RASTER
CONNECTIONTYPE postgis
CONNECTION "user=postgres password=... dbname=... host=..."
DATA "bytea FROM rasters"
STATUS OFF
OFFSITE 0 0 0
TRANSPARENCY 100
END

being OFFSITE the color you want to be transparent and TRANSPARENCY which controls the transparency level.

Hope this helps,

0

I set OPACITY in the mapfile for the entire layer (not for each style). Not sure what the OFFSITE does (I don't use that). Like this:

LAYER
DATA "PG:host=*** dbname=*** schema=public table=london where='rid=3' mode='1'"
NAME "postgis"
PROCESSING "SCALE=AUTO"
PROCESSING "NODATA=-9999"
STATUS DEFAULT
TYPE RASTER
OPACITY 50

UNITS METERS
CLASS
  NAME "Minor Impact"
  EXPRESSION ([pixel] >= 0 AND [pixel] < 1.29525335532 )
  STYLE
    ANGLE 360
    COLOR 122 182 245
    SYMBOL 0
    WIDTH 1
  END
END
...

Then in your OpenLayers (javascript) you set the layer to transparent:

 var mapParams = {
                  'layers': 'postgis',
                  'transparent': true
                   }
 var layer_wms = new OpenLayers.Layer.WMS(
                mapParams['layers'],
                serverURL,
                mapParams
            );
 map.addLayers([layer_wms]);
  • I tried the same thing, but the result looks like the 3rd figure. Really Strange. – Yu Guo Jul 18 '13 at 16:25
  • The best solution is just CHange the opacity:0.5 to the OpenLayer Code and It works. – Yu Guo Jul 18 '13 at 16:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.