3.5. Rasters

Finally we will look at using CSS styling for the portrayal of raster data.

../../../_images/RasterSymbology.svg

Raster Symbology

Review of raster symbology:

  • Raster data is Grid Coverage where values have been recorded in a regular array. In OGC terms a Coverage can be used to look up a value or measurement for each location.

  • When queried with a “sample” location:

    • A grid coverage can determine the appropriate array location and retrieve a value. Different techniques may be used interpolate an appropriate value from several measurements (higher quality) or directly return the “nearest neighbor” (faster).

    • A vector coverages would use a point-in-polygon check and return an appropriate attribute value.

    • A scientific model can calculate a value for each sample location

  • Many raster formats organize information into bands of content. Values recorded in these bands and may be mapped into colors for display (a process similar to theming an attribute for vector data).

    For imagery the raster data is already formed into red, green and blue bands for display.

  • As raster data has no inherent shape, the format is responsible for describing the orientation and location of the grid used to record measurements.

These raster examples use a digital elevation model consisting of a single band of height measurements. The imagery examples use an RGB image that has been hand coloured for use as a base map.

Reference:

The exercise makes use of the usgs:dem and ne:ne1 layers.

3.5.1. Image

The raster-channels is the key property for display of images and raster data. The value auto is recommended, allowing the image format to select the appropriate red, green and blue channels for display.

  1. Navigate to the Styles page.

  2. Click Add a new style and choose the following:

    Name:

    image_example

    Workspace:

    No workspace

    Format:

    CSS

  3. Replace the initial CSS definition with:

    * {
      raster-channels: auto;
    }
    
  4. And use the Layer Preview tab to preview the result.

    ../../../_images/raster_image_1.png
  5. If required a list three band numbers can be supplied (for images recording in several wave lengths) or a single band number can be used to view a grayscale image.

    * {
      raster-channels: 2;
    }
    
  6. Isolating just the green band (it wil be drawn as a grayscale image):

    ../../../_images/raster_image_2.png

3.5.2. DEM

A digital elevation model is an example of raster data made up of measurements, rather than colors information.

The usgs:dem layer used used for this exercise:

  1. Return to the the Styles page.

  2. Click Add a new style and choose the following:

    Name:

    raster_example

    Workspace:

    No workspace

    Format:

    CSS

  3. When we use the raster-channels property set to auto the rendering engine will select our single band of raster content, and do its best to map these values into a grayscale image. Replace the content of the style with:

    * {
      raster-channels: auto;
    }
    
  4. Use the Layer Preview tab to preview the result. The range produced in this case from the highest and lowest values.

    ../../../_images/raster_dem_1.png
  5. We can use a bit of image processing to emphasis the generated color mapping by making use raster-contrast-enhancement.

    * {
      raster-channels: 1;
      raster-contrast-enhancement: histogram;
    }
    
  6. Image processing of this sort should be used with caution as it does distort the presentation (in this case making the landscape look more varied then it is in reality.

    ../../../_images/raster_dem_2.png

3.5.2.1. Color Map

The approach of mapping a data channel directly to a color channel is only suitable to quickly look at quantitative data.

For qualitative data (such as land use) or simply to use color, we need a different approach:

  1. Apply the following CSS to our usgs:DEM layer:

    * {
      raster-channels: auto;
      raster-color-map: color-map-entry(#9080DB, 0)
                        color-map-entry(#008000, 1)
                        color-map-entry(#105020, 255)
                        color-map-entry(#FFFFFF, 4000);
    }
    
  2. Resulting in this artificial color image:

    ../../../_images/raster_dem_3.png
  3. An opacity value can also be used with color-map-entry.

    * {
      raster-channels: auto;
      raster-color-map: color-map-entry(#9080DB, 0, 0.0)
                        color-map-entry(#008000, 1, 1.0)
                        color-map-entry(#105020, 200, 1.0)
                        color-map-entry(#FFFFFF, 4000, 1.0);
    }
    
  4. Allowing the areas of zero height to be transparent:

    ../../../_images/raster_dem_4.png
  5. Raster format for GIS work often supply a “no data” value, or contain a mask, limiting the dataset to only the locations with valid information.

3.5.2.2. Custom

We can use what we have learned about color maps to apply a color brewer palette to our data.

This exploration focuses on accurately communicating differences in value, rather than strictly making a pretty picture. Care should be taken to consider the target audience and medium used during palette selection.

  1. Restore the raster_example CSS style to the following:

    * {
      raster-channels: auto;
    }
    
  2. Producing the following map preview.

    ../../../_images/raster_01_auto.png
  3. To start with we can provide our own grayscale using two color map entries.

    * {
      raster-channels: auto;
      raster-color-map: color-map-entry(#000000, 0)
                        color-map-entry(#FFFFFF, 4000);
    }
    
  4. Use the Map tab to zoom in and take a look.

    This is much more direct representation of the source data. We have used our knowledge of elevations to construct a more accurate style.

    ../../../_images/raster_02_straight.png
  5. While our straightforward style is easy to understand, it does leave a bit to be desired with respect to clarity.

    The eye has a hard time telling apart dark shades of black (or bright shades of white) and will struggle to make sense of this image. To address this limitation we are going to switch to the ColorBrewer 9-class PuBuGn palette. This is a sequential palette that has been hand tuned to communicate a steady change of values.

    ../../../_images/raster_03_elevation.png
  6. Update your style with the following:

    * {
      raster-channels: auto;
      raster-color-map:
         color-map-entry(#014636,   0)
         color-map-entry(#016c59, 500)
         color-map-entry(#02818a,1000)
         color-map-entry(#3690c0,1500)
         color-map-entry(#67a9cf,2000)
         color-map-entry(#a6bddb,2500)
         color-map-entry(#d0d1e6,3000)
         color-map-entry(#ece2f0,3500)
         color-map-entry(#fff7fb,4000);
    }
    
    ../../../_images/raster_04_PuBuGn.png
  7. A little bit of work with alpha (to mark the ocean as a no-data section):

    * {
      raster-channels: auto;
      raster-color-map:
         color-map-entry(#014636,   0,0)
         color-map-entry(#014636,   1)
         color-map-entry(#016c59, 500)
         color-map-entry(#02818a,1000)
         color-map-entry(#3690c0,1500)
         color-map-entry(#67a9cf,2000)
         color-map-entry(#a6bddb,2500)
         color-map-entry(#d0d1e6,3000)
         color-map-entry(#ece2f0,3500)
         color-map-entry(#fff7fb,4000);
    }
    
  8. And we are done:

    ../../../_images/raster_05_alpha.png

3.5.2.3. Bonus

3.5.3. Explore Contrast Enhancement

  1. A special effect that is effective with grayscale information is automatic contrast adjustment.

  2. Make use of a simple contrast enhancement with usgs:dem:

    * {
        raster-channels: auto;
        raster-contrast-enhancement: normalize;
    }
    
  3. Can you explain what happens when zoom in to only show a land area (as indicated with the bounding box below)?

    ../../../_images/raster_contrast_1.png

    Note

    Discussion provided at the end of the workbook.

3.5.4. Challenge Intervals

  1. The raster-color-map-type property dictates how the values are used to generate a resulting color.

    • ramp is used for quantitative data, providing a smooth interpolation between the provided color values.

    • intervals provides categorization for quantitative data, assigning each range of values a solid color.

    • values is used for qualitative data, each value is required to have a color-map-entry or it will not be displayed.

  2. Chalenge: Update your DEM example to use intervals for presentation. What are the advantages of using this approach for elevation data?

    Note

    Answer provided at the end of the workbook.

3.5.5. Explore Image Processing

Additional properties are available to provide slight image processing during visualization.

Note

In this section are we going to be working around a preview issue where only the top left corner of the raster remains visible during image processing. This issue has been reported as GEOS-6213.

Image processing can be used to enhance the output to highlight small details or to balance images from different sensors allowing them to be compared.

  1. The raster-contrast-enhancement property is used to turn on a range of post processing effects. Settings are provided for normalize or histogram or none;

    * {
        raster-channels: auto;
        raster-contrast-enhancement: normalize;
    }
    
  2. Producing the following image:

    ../../../_images/raster_image_3.png
  3. The raster-gamma property is used adjust the brightness of raster-contrast-enhancement output. Values less than 1 are used to brighten the image while values greater than 1 darken the image.

    * {
       raster-channels: auto;
       raster-contrast-enhancement: none;
       raster-gamma: 1.5;
    }
    
  4. Providing the following effect:

    ../../../_images/raster_image_4.png

3.5.6. Challenge Clear Digital Elevation Model Presentation

  1. Now that you have seen the data on screen and have a better understanding how would you modify our initial gray-scale example?

  2. Challenge: Use what you have learned to present the usgs:dem clearly.

    Note

    Answer provided at the end of the workbook.

3.5.7. Challenge Raster Opacity

  1. There is a quick way to make raster data transparent, raster-opacity property works in the same fashion as with vector data. The raster as a whole will be drawn partially transparent allow content from other layers to provide context.

  2. Challenge: Can you think of an example where this would be useful?

    Note

    Discussion provided at the end of the workbook.