Barnes Surface??

The Barnes Surface rendering transformation is a Vector-to-Raster transformation which computes a interpolated surface across a set of irregular observation points. It is commonly used as an interpolation technique for weather maps and other meteorological datasets. The surface is generated dynamically from the dataset, so it can be used to visualize changing data. The surface view is created by configuring a layer with a style which invokes the Barnes Surface rendering transformation.

../../_images/barnes_surface.png

Barnes Surface rendering transformation used to render a maximum temperature surface

Technical description??

The Barnes Surface algorithm operates on a regular grid of cells covering a specified extent in the input data space. It computes an initial pass to produce an interpolated value for each grid cell. The value of a cell is determined by its proximity to the input observation points, using a summation of exponential (Gaussian) decay functions for each observation point. Refinement passes may be used to improve the estimate by reducing the error between the computed surface and the observations.

The rendering transformation uses the Barnes Surface algorithm to compute a surface over a set of irregular data points, providing a raster surface as output.

The input is a dataset of points, with an attribute providing an observed value for each point. The radius of influence of each observation point is controlled by the length scale. A number of refinement passes can be performed to improve the surface estimate, with the degree of refinement controlled by the convergence factor.

Usage??

As with all rendering transformations, the transformation is invoked by inserting a transform into a style. The style can then be applied to any layer which is backed by a suitable dataset.

The transformation function is called vec:BarnesSurface. Note that this is the same as the WPS process, as these functions can be invoked as either a WPS process or a rendering transformation.

The transformation parameters are as follows. The order of parameters is not significant.

Name Required? Description
valueAttr Yes Name of the value attribute
dataLimit No Limits the number of input points which are processed
scale Yes Length scale for the interpolation. In units of the input data CRS.
convergence No Convergence factor for refinement. Values can be between 0 and 1. Values below 0.4 are safest. (Default = 0.3)
passes No Number of passes to compute. Values can be 1 or greater. (Default = 2)
minObservations No Minimum number of observations required to support a grid cell. (Default = 2)
maxObservationDistance No Maximum distance (in units of the input data CRS) to an observation for it to support a grid cell. A value of 0 means all observations are used (Default = 0).
noDataValue No The NO_DATA value to use for unsupported grid cells in the output.
pixelsPerCell No Resolution of the computed grid. Larger values improve performance, but may degrade appearance if too large. (Default = 1)
queryBuffer No Distance to expand the query envelope by. Larger values provide a more stable surface. In units of the input data CRS. fault = 0)
outputBBOX Yes Georeferenced bounding box of the output. Not required with YSLD.
outputWidth Yes Output image width. Not required with YSLD.
outputHeight Yes Output image height. Not required with YSLD.

Environment variables as values??

It is a common situation that the output image dimensions be determined by the client at rendering time, to allow for variable window sizes.

In these cases, it is possible to read in special environment variables to the rendering transformation.

There are three environment variables that will be useful to us, which can be used as values for the following input parameters:

Environment variable Description Input parameter
wms_bbox WMS request extent outputBBOX
wms_width Width of resulting image outputWidth
wms_height Height of resulting image outputHeight

The following YSLD syntax for employing environment variables is assumed by default and need not be added to the style:

outputBBOX: ${env(wms_bbox)}
outputWidth: ${env(wms_width)}
outputHeight: ${env(wms_height)}

The following SLD syntax for employing environment variables must be explictly declared:

<ogc:Function name="parameter">
  <ogc:Literal>outputBBOX</ogc:Literal>
  <ogc:Function name="env">
    <ogc:Literal>wms_bbox</ogc:Literal>
  </ogc:Function>
</ogc:Function>

<ogc:Function name="parameter">
  <ogc:Literal>outputWidth</ogc:Literal>
  <ogc:Function name="env">
    <ogc:Literal>wms_width</ogc:Literal>
  </ogc:Function>
</ogc:Function>

<ogc:Function name="parameter">
  <ogc:Literal>outputHeight</ogc:Literal>
  <ogc:Function name="env">
    <ogc:Literal>wms_height</ogc:Literal>
  </ogc:Function>
</ogc:Function>

Input??

The Barnes Surface rendering transformation is applied to a vector input dataset with point geometries. The dataset is supplied in the data parameter, while the observation value for features is supplied in the attribute named in the valueAttr parameter.

To prevent extrapolation into areas unsupported by observations, the influence of observation points can be limited using the minObservations and maxObservationDistance parameters. This also increases performance by reducing the observations evaluated for each grid cell. Uncomputed grid cells are given the value noDataValue.

To ensure the computed surface is stable under panning and zooming the extent for the input data can be expanded by a user-specified distance (queryBuffer). This ensures enough data points are included to avoid edge effects on the computed surface. The expansion distance depends on the length scale, convergence factor, and data spacing in a complex way, so must be manually determined. (A good heuristic is to set the distance at least as large as the length scale.)

To prevent excessive CPU consumption the number of data points processed can be limited using the dataLimit parameter. If the limit is exceeded an output is still produced using the maximum number of points.

To improve performance, the surface grid can be computed at lower resolution than the output raster, using the pixelsPerCell parameter. The computed grid is upsampled to the output raster size using Bilinear Interpolation with Edge Smoothing to maintain quality. There is minimal impact on appearance for small cell sizes (10 pixels or less).

The surface is computed in the CRS (coordinate reference system) of the output. If the output CRS is different to the input CRS the data points are transformed into the output CRS. Likewise, the distance-based parameters scale and maxObservationDistance are converted into the units of the output CRS.

Output??

The output of the transformation is a single-band raster. Each pixel has a floating-point value in the range [0..1] measuring the density of the pixel relative to the rest of the surface. The raster can be styled using a raster symbolizer.

Note

In order for the style to be correctly validated in SLD, the input geometry element must be declared in the raster symbolizer:

<Geometry>
  <ogc:PropertyName>...</ogc:PropertyName>
</Geometry>

YSLD has no such restriction; the geometry: element is not required.

Examples??

This example shows a temperature surface interpolated across a set of data points with a attribute giving the maximum daily temperature on a given day. It shows the generated Barnes Surface, the original input data points (drawn by another style), as well as a base map layer.

The source data used in this example is the world:globaldata_temp layer (available for download on the Sample Data page).

Below are two examples showing how to perform this rendering transformation in both YSLD and SLD. You can adapt these examples to your data with minimal effort by adjusting the parameters.

YSLD??

The surface layer, as seen in the figure at the top of the page, can be produced by the following YSLD:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Default Styler
title: Barnes Surface
abstract: A style that produces a Barnes surface using a rendering transformation
feature-styles:
- name: name
  transform:
    name: vec:BarnesSurface
    params:
      valueAttr: value
      scale: 15.0
      convergence: 0.2
      passes: 3
      minObservations: 1
      maxObservationDistance: 10
      pixelsPerCell: 10
      queryBuffer: 40
  rules:
  - symbolizers:
    - raster:
        opacity: 0.8
        color-map:
          type: ramp
          entries:
          - ['#FFFFFF',0,-990,nodata]
          - ['#2E4AC9',1,-9,nodata]
          - ['#41A0FC',1,-6,values]
          - ['#58CCFB',1,-3,values]
          - ['#76F9FC',1,0,values]
          - ['#6AC597',1,3,values]
          - ['#479364',1,6,values]
          - ['#2E6000',1,9,values]
          - ['#579102',1,12,values]
          - ['#9AF20C',1,15,values]
          - ['#B7F318',1,18,values]
          - ['#DBF525',1,21,values]
          - ['#FAF833',1,24,values]
          - ['#F9C933',1,27,values]
          - ['#F19C33',1,30,values]
          - ['#ED7233',1,33,values]
          - ['#EA3F33',1,36,values]
          - ['#BB3026',1,999,values]

The YSLD example defines the Barnes Surface rendering transformation, giving values for the transformation parameters which are appropriate for the input dataset.

  • On line 9, valueAttr specifies the name of the observation value attribute.
  • On line 10, scale sets a length scale of 15 degrees.
  • On line 11, convergence sets the convergence factor to be 0.2.
  • On line 12, passes requests that 3 passes be performed (one for the initial estimate, and two refinement passes).
  • On line 13, minObervations specifies that the minimum number of observations required to support an estimated cell is 1 (which means every observation point will be represented in the output).
  • On line 14, maxObservationDistance specifies the maximum distance from a computed grid cell to an observation point is 10 degrees.
  • On line 15, pixelsPerCell defines the resolution of computation to be 10 pixels per cell, which provides efficient rendering time while still providing output of reasonable visual quality.
  • On line 16, queryBuffer specifies the query buffer to be 40 degrees, which is chosen to be at least double the length scale for stability.

The raster symbolizer (starting on line 19) is used to style the raster computed by the transformation.

  • On line 20, opacity specifies an overall opacity of 0.8 for the rendered layer.

  • Starting on line 21, color-map defines a color map with which to symbolize the output raster. In this case the color map uses a type of ramp (line 22), which produces a smooth transition between colors.

    Note

    The type could also be intervals, which produces a contour effect with discrete transition between colors (see image below). The first color map tuple specifies that the NO_DATA value of -990 and -9 should be displayed with a fully transparent color of white (masking uncomputed pixels).

    ../../_images/barnes_surface_intervals.png

    Barnes surface using intervals instead of a ramp

SLD??

The surface layer can also be produced by the following SLD:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
 xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
 xmlns="http://www.opengis.net/sld"
 xmlns:ogc="http://www.opengis.net/ogc"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <NamedLayer>
    <Name>Barnes surface</Name>
    <UserStyle>
      <Title>Barnes Surface</Title>
      <Abstract>A style that produces a Barnes surface using a rendering transformation</Abstract>
      <FeatureTypeStyle>
   <Transformation>
     <ogc:Function name="vec:BarnesSurface">
       <ogc:Function name="parameter">
         <ogc:Literal>data</ogc:Literal>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>valueAttr</ogc:Literal>
         <ogc:Literal>value</ogc:Literal>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>scale</ogc:Literal>
         <ogc:Literal>15.0</ogc:Literal>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>convergence</ogc:Literal>
         <ogc:Literal>0.2</ogc:Literal>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>passes</ogc:Literal>
         <ogc:Literal>3</ogc:Literal>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>minObservations</ogc:Literal>
         <ogc:Literal>1</ogc:Literal>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>maxObservationDistance</ogc:Literal>
         <ogc:Literal>10</ogc:Literal>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>pixelsPerCell</ogc:Literal>
         <ogc:Literal>10</ogc:Literal>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>queryBuffer</ogc:Literal>
         <ogc:Literal>40</ogc:Literal>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>outputBBOX</ogc:Literal>
         <ogc:Function name="env">
            <ogc:Literal>wms_bbox</ogc:Literal>
         </ogc:Function>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>outputWidth</ogc:Literal>
         <ogc:Function name="env">
            <ogc:Literal>wms_width</ogc:Literal>
         </ogc:Function>
       </ogc:Function>
       <ogc:Function name="parameter">
         <ogc:Literal>outputHeight</ogc:Literal>
         <ogc:Function name="env">
            <ogc:Literal>wms_height</ogc:Literal>
         </ogc:Function>
       </ogc:Function>
     </ogc:Function>
   </Transformation>
   <Rule>
     <RasterSymbolizer>
       <!-- specify geometry attribute of input to pass validation -->
       <Geometry><ogc:PropertyName>point</ogc:PropertyName></Geometry>
       <Opacity>0.8</Opacity>
       <ColorMap type="ramp" >
         <ColorMapEntry color="#FFFFFF" quantity="-990" label="nodata" opacity="0"/>
         <ColorMapEntry color="#2E4AC9" quantity="-9" label="values"/>
         <ColorMapEntry color="#41A0FC" quantity="-6" label="values" />
         <ColorMapEntry color="#58CCFB" quantity="-3" label="values" />
         <ColorMapEntry color="#76F9FC" quantity="0" label="values" />
         <ColorMapEntry color="#6AC597" quantity="3" label="values" />
         <ColorMapEntry color="#479364" quantity="6" label="values" />
         <ColorMapEntry color="#2E6000" quantity="9" label="values" />
         <ColorMapEntry color="#579102" quantity="12" label="values" />
         <ColorMapEntry color="#9AF20C" quantity="15" label="values" />
         <ColorMapEntry color="#B7F318" quantity="18" label="values" />
         <ColorMapEntry color="#DBF525" quantity="21" label="values" />
         <ColorMapEntry color="#FAF833" quantity="24" label="values" />
         <ColorMapEntry color="#F9C933" quantity="27" label="values" />
         <ColorMapEntry color="#F19C33" quantity="30" label="values" />
         <ColorMapEntry color="#ED7233" quantity="33" label="values" />
         <ColorMapEntry color="#EA3F33" quantity="36" label="values" />
         <ColorMapEntry color="#BB3026" quantity="999" label="values" />
       </ColorMap>
     </RasterSymbolizer>
    </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

In the SLD, Lines 14-70 define the Barnes surface rendering transformation, giving values for the transformation parameters which are appropriate for the input dataset.

  • Line 15 specifes the name of the rendering transformation (vec:BarnesSurface).
  • Line 17 specifies the input dataset parameter name.
  • Lines 20-21 specifies the name of the observation value attribute valueattr to be value.
  • Lines 24-25 sets a length scale of 15 degrees.
  • Lines 28-29 sets the convergence factor to be 0.2.
  • Lines 32-33 requests that 3 passes be performed (one for the initial estimate, and two refinement passes).
  • Lines 36-37 specifies that the minimum number of observations (minObservations) required to support an estimated cell is 1 (which means every observation point will be represented in the output).
  • Lines 40-41 specifies the maximum distance from a computed grid cell to an observation point (maxObservationDistance) is 10 degrees.
  • Lines 44-45 defines the resolution of computation to be 10 pixels per cell (pixelsPerCell), which provides efficient rendering time while still providing output of reasonable visual quality.
  • Lines 48-49 specifies the query buffer (queryBuffer) to be 40 degrees, which is chosen to be at least double the length scale for stability.
  • Lines 51-68 define the output parameters (outputBBOX, outputWidth, and outputHeight), which are obtained from internal environment variables set during rendering, as described above.
  • Lines 72-96 define the symbolizer used to style the raster computed by the transformation (RasterSymbolizer).
  • Line 74 defines the geometry property of the input dataset, which is required for SLD validation purposes.
  • Line 75 specifies an overall opacity of 0.8 for the rendered layer.
  • Lines 76-95 define a color map with which to symbolize the output raster. In this case the color map uses a type of ramp, which produces a smooth transition between colors. The type could also be intervals, which produces a contour effect with discrete transition between colors (see image above).
  • Line 77 specifies that the NO_DATA value of -990 should be displayed with a fully transparent color of white (masking uncomputed pixels).