Class HeatmapProcess

  • All Implemented Interfaces:
    VectorProcess

    public class HeatmapProcess
    extends Object
    implements VectorProcess
    A Process that uses a HeatmapSurface to compute a heatmap surface over a set of irregular data points as a GridCoverage. Heatmaps are known more formally as Multivariate Kernel Density Estimation.

    The appearance of the heatmap is controlled by the kernel radius, which determines the "radius of influence" of input points. The radius is specified by the radiusPixels parameter, which is in output pixels. Using pixels allows easy estimation of a value which will give a visually effective result, and ensures the heatmap appearance changes to match the zoom level.

    By default each input point has weight 1. Optionally the weights of points may be supplied by an attribute specified by the weightAttr parameter.

    All geometry types are allowed as input. For non-point geometries the centroid is used.

    To improve performance, the surface grid can be computed at a lower resolution than the requested output image using the pixelsPerCell parameter. The grid is upsampled to match the required image size. Upsampling uses Bilinear Interpolation to maintain visual quality. This gives a large improvement in performance, with minimal impact on visual quality for small cell sizes (for instance, 10 pixels or less).

    To ensure that the computed surface is stable (i.e. does not display obvious edge artifacts under zooming and panning), the data extent is expanded to be larger than the specified output extent. The expansion distance is equal to the size of radiusPixels in the input CRS.

    Parameters

    M = mandatory, O = optional
    • data (M) - the FeatureCollection containing the point observations
    • radiusPixels (M)- the density kernel radius, in pixels
    • weightAttr (M)- the feature type attribute containing the observed surface value
    • pixelsPerCell (O) - The pixels-per-cell value determines the resolution of the computed grid. Larger values improve performance, but degrade appearance. (Default = 1)
    • outputBBOX (M) - The georeferenced bounding box of the output area
    • outputWidth (M) - The width of the output raster
    • outputHeight (M) - The height of the output raster
    The output of the process is a GridCoverage2D with a single band, with cell values in the range [0, 1].

    Computation of the surface takes places in the CRS of the output. If the data CRS is different to the output CRS, the input points are transformed into the output CRS.

    Using the process as a Rendering Transformation

    This process can be used as a RenderingTransformation, since it implements the invertQuery(... Query, GridGeometry) method. In this case the queryBuffer parameter should be specified to expand the query extent appropriately. The output raster parameters may be provided from the request extents, using the following SLD environment variables:
    • outputBBOX - env var = wms_bbox
    • outputWidth - env var = wms_width
    • outputHeight - env var = wms_height
    When used as an Rendering Transformation the data query is rewritten to expand the query BBOX, to ensure that enough data points are queried to make the computed surface stable under panning and zooming.

    Author:
    Martin Davis - OpenGeo
    • Constructor Detail

      • HeatmapProcess

        public HeatmapProcess()
    • Method Detail

      • invertQuery

        public Query invertQuery​(Integer argRadiusPixels,
                                 ReferencedEnvelope argOutputEnv,
                                 Integer argOutputWidth,
                                 Integer argOutputHeight,
                                 Query targetQuery,
                                 GridGeometry targetGridGeometry)
                          throws ProcessException
        Given a target query and a target grid geometry returns the query to be used to read the input data of the process involved in rendering. In this process this method is used to:
        • determine the extent & CRS of the output grid
        • expand the query envelope to ensure stable surface generation
        • modify the query hints to ensure point features are returned
        Note that in order to pass validation, all parameters named here must also appear in the parameter list of the execute method, even if they are not used there.
        Parameters:
        argRadiusPixels - the feature type attribute that contains the observed surface value
        targetQuery - the query used against the data source
        targetGridGeometry - the grid geometry of the destination image
        Returns:
        The transformed query
        Throws:
        ProcessException
      • expandBBox

        protected Filter expandBBox​(Filter filter,
                                    double distance)
      • extractPoints

        protected void extractPoints​(SimpleFeatureCollection obsPoints,
                                     String attrName,
                                     MathTransform trans,
                                     HeatmapSurface heatMap)
                              throws CQLException
        Extract points from a feature collection, and stores them in the heatmap
        Parameters:
        obsPoints - features to extract
        attrName - expression or property name used to evaluate the geometry from a feature
        trans - transform for extracted points
        heatMap - heatmap to add points to
        Throws:
        CQLException - if attrName can't be parsed