Class VectorToRaster

java.lang.Object
nz.org.riskscape.engine.raster.VectorToRaster

public class VectorToRaster extends Object

Utility for producing a GridCoverage2D from a Relation, adapted from some geotools code in an unsupported module

Support for integer encoding has been removed in favour of a floating point only. Note that only the 4-byte wide float type is supported here, although it accepts the 8 bit double value - this is because a raster encoded in sRGB will only be 4 bytes, so some loss of precision of value is possible when rasterizing.

TODO This class should probably be split in to a couple of different classes, particularly one for drawing jts shapes, and maybe another for iterating and producing the coverage

  • Field Details

  • Constructor Details

    • VectorToRaster

      public VectorToRaster()
  • Method Details

    • getHeightCrsUnits

      public static double getHeightCrsUnits(org.geotools.geometry.jts.ReferencedEnvelope bounds)
      Returns:
      the height of the raster bounds in CRS units
    • getWidthCrsUnits

      public static double getWidthCrsUnits(org.geotools.geometry.jts.ReferencedEnvelope bounds)
      Returns:
      the width of the raster bounds in CRS units
    • getDimensions

      public static nz.org.riskscape.problem.ResultOrProblems<Dimension> getDimensions(org.geotools.geometry.jts.ReferencedEnvelope bounds, double scale)
      Returns:
      the dimensions that the raster will have, or a Problem if dimensions are too big
    • convert

      public org.geotools.coverage.grid.GridCoverage2D convert(nz.org.riskscape.engine.relation.Relation relation, nz.org.riskscape.engine.rl.RealizedExpression expression, double scale, org.geotools.geometry.jts.ReferencedEnvelope bounds, String covName) throws nz.org.riskscape.problem.ProblemException
      Throws:
      nz.org.riskscape.problem.ProblemException
    • drawFeature

      public VectorToRaster.DrawFeatureResult drawFeature(Number value, org.locationtech.jts.geom.Geometry geometry)

      Draw the value to the raster for all pixels that intersect the geometry, but only if the feature intersects with the raster bounds.

      Parameters:
      value - expression to get the feature vaule from the tuple
      geometry - expression to get the feature geometry from the tuple
      Returns:
      true if feature was drawn, false if feature geometry or value is null or is outside of initialized bounds.
    • constructCoverage

      public org.geotools.coverage.grid.GridCoverage2D constructCoverage(CharSequence covName)

      Construct a GridCoverage2D containing all the features that have been drawn to it.

      Parameters:
      covName - name given to the produced coverage
      Returns:
      grid coverage
    • initialize

      public void initialize(org.geotools.geometry.jts.ReferencedEnvelope bounds, double scale, VectorToRaster.PixelStrategy newPixelStrategy) throws nz.org.riskscape.problem.ProblemException

      Initialize the raster to the given bounds and scale.

      Parameters:
      bounds - the spatial extent of the raster to produce. Must be in the CRS of the features that will be drawn to the raster
      scale - Converts the bounds width/height (in CRS units) into the number of pixels, i.e. 1 / grid-resolution. e.g. a 50m grid uses a 1/50 scale, so for bounds 10km wide this is 10000 * 0.02 = 200 pixels wide.
      newPixelStrategy - determines how to set vales to pixels that have already been set
      Throws:
      nz.org.riskscape.problem.ProblemException