Class VectorToRaster
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic interfacestatic enumStrategy that determines how new and existing pixel values are merged. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.geotools.coverage.grid.GridCoverage2DconstructCoverage(CharSequence covName) Construct aGridCoverage2Dcontaining all the features that have been drawn to it.org.geotools.coverage.grid.GridCoverage2Dconvert(nz.org.riskscape.engine.relation.Relation relation, nz.org.riskscape.engine.rl.RealizedExpression expression, double scale, org.geotools.geometry.jts.ReferencedEnvelope bounds, String covName) 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.static nz.org.riskscape.problem.ResultOrProblems<Dimension>getDimensions(org.geotools.geometry.jts.ReferencedEnvelope bounds, double scale) static doublegetHeightCrsUnits(org.geotools.geometry.jts.ReferencedEnvelope bounds) static doublegetWidthCrsUnits(org.geotools.geometry.jts.ReferencedEnvelope bounds) voidinitialize(org.geotools.geometry.jts.ReferencedEnvelope bounds, double scale, VectorToRaster.PixelStrategy newPixelStrategy) Initialize the raster to the given bounds and scale.
-
Field Details
-
PROBLEMS
-
-
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 tuplegeometry- 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
Construct a
GridCoverage2Dcontaining 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 rasterscale- 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
-