Is it possible to encode values from raster bands into pixel output using a MapServer .map file?

More and more I'm finding that a commonly adopted method for moving geographical data for rendering WebGL based maps is the old game developers trick of using PNG/JPG images with float/integer values encoded into the RGBA bytes. These images are then fed into GLSL shaders as textures where they are decoded to the original (but slightly offset) values on the GPU.

There are various projects using this method,and subsequently various utilities that are being used to encode these values. e.g. https://blog.mapbox.com/how-i-built-a-wind-map-with-webgl-b63022b5537f

An example of an encoding algorithm is:

png.r = Math.floor(255 * (u[i] - u.minimum) / (u.maximum - u.minimum));
png.g = Math.floor(255 * (v[i] - v.minimum) / (v.maximum - v.minimum));

This would be an incredibly convenient way of passing texture data directly to GLSL shaders using common mapping tools such as Leaflet, OpenLayers or Mapbox, without the need to pre-process image files

I can generate a greyscale image using

    NAME "encode" STATUS ON
    DATA "vstm-uv.grb2"
      "+proj=longlat +a=6371229 +b=6371229 +no_defs +lon_wrap=180" 
  END #Layer

But i can't figure out how to color these values or process the incoming [red] & [green] bands.

  • Ok from what i can tell this will not be possible. The values will need to be encoded before passing it to the map file. I will keep at this but my current solution is to create the encoded image and generate a worldfile for the PNG. Then I serve the tiles using a MapServer raster layer. – maeneak Jun 11 '19 at 2:25

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.