Class FeatureGrid

java.lang.Object
nz.org.riskscape.engine.grid.FeatureGrid

public class FeatureGrid extends Object

Surrounds a geometry (called a feature in this context to help distinguish it from other uses of the word geometry) with a grid to allow it to be cut or sampled in to cells as defined by the grid.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    GridGeometry2D typically models the grid with AsciiGridsImageMetadata.RasterSpaceType.PixelIsArea, so we must shunt our coordinates by half at various times during gridding
  • Constructor Summary

    Constructors
    Constructor
    Description
    FeatureGrid(org.locationtech.jts.geom.Geometry feature, org.geotools.referencing.CRS.AxisOrder axisOrder, org.geotools.coverage.grid.GridGeometry2D gridGeometry)
    Construct a new FeatureGrid that applies a GridGeometry2D to a Geometry object.
  • Method Summary

    Modifier and Type
    Method
    Description
    Iterate over the points of the grid formed by intersection of the feature's bounds and the grid.
    double
    The number of crs units between grid cells in the vertical direction, e.g.
    double
    The number of crs units between grid cells in the horizontal direction, e.g.
    protected double
     
    protected double
     
    org.locationtech.jts.geom.Envelope
    The envelope of the feature in grid space, snapped to the grid, so that is the smallest possible size that surrounds the feature.
    org.locationtech.jts.geom.Geometry
    The geometry that is being surrounded by the grid
    org.locationtech.jts.geom.Envelope
     
    org.geotools.geometry.Position2D
    The top left position of the feature within the grid in crs space.
    org.locationtech.jts.geom.GeometryFactory
     
    int
    The number of columns in the grid, i.e.
    org.geotools.coverage.grid.GridGeometry2D
    The geometry of the overall grid, e.g.
    int
    The x position in the original grid where this feature grid starts
    int
    The y position in the original grid where this feature grid starts
    int
    The number of rows in the grid, i.e.
    org.geotools.api.referencing.operation.MathTransform
    A maths transformation from grid coordinates to world crs space

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • HALF_A_PIXEL

      public static final double HALF_A_PIXEL

      GridGeometry2D typically models the grid with AsciiGridsImageMetadata.RasterSpaceType.PixelIsArea, so we must shunt our coordinates by half at various times during gridding

      See Also:
  • Constructor Details

    • FeatureGrid

      public FeatureGrid(org.locationtech.jts.geom.Geometry feature, org.geotools.referencing.CRS.AxisOrder axisOrder, org.geotools.coverage.grid.GridGeometry2D gridGeometry) throws org.geotools.api.geometry.MismatchedDimensionException, org.geotools.api.referencing.operation.TransformException

      Construct a new FeatureGrid that applies a GridGeometry2D to a Geometry object. No re-projection is done by this class, it is up to the caller to ensure that the CoordinateReferenceSystem of the gridGeometry's world matches the CoordinateReferenceSystem of the feature.

      Throws:
      org.geotools.api.geometry.MismatchedDimensionException
      org.geotools.api.referencing.operation.TransformException
  • Method Details

    • getGeometryFactory

      public org.locationtech.jts.geom.GeometryFactory getGeometryFactory()
    • getFeatureGridEnvelopeInWorldCrs

      public org.locationtech.jts.geom.Envelope getFeatureGridEnvelopeInWorldCrs()
      Returns:
      an Envelope based on convering the grid's dimensions to the world's - note that this will not add the extra pixel on to width and height that the geometry does - this method is really here for tests and sanity checking
    • cellIterator

      public Iterator<FeatureGridCell> cellIterator()

      Iterate over the points of the grid formed by intersection of the feature's bounds and the grid.

    • getCellWorldX

      protected double getCellWorldX()
      Returns:
      the cell dimension for the x axis in the World CRS. This will be cellWidth or cellHeight depending on the CRS axis order
    • getCellWorldY

      protected double getCellWorldY()
      Returns:
      the cell dimension for the y axis in the World CRS. This will be cellWidth or cellHeight depending on the CRS axis order
    • getFeature

      public org.locationtech.jts.geom.Geometry getFeature()

      The geometry that is being surrounded by the grid

    • getGridGeometry

      public org.geotools.coverage.grid.GridGeometry2D getGridGeometry()

      The geometry of the overall grid, e.g. this is the grid that we are applying over the top of our feature.

    • getEnvelope

      public org.locationtech.jts.geom.Envelope getEnvelope()

      The envelope of the feature in grid space, snapped to the grid, so that is the smallest possible size that surrounds the feature.

    • getGridToWorld

      public org.geotools.api.referencing.operation.MathTransform getGridToWorld()

      A maths transformation from grid coordinates to world crs space

    • getGridColumns

      public int getGridColumns()

      The number of columns in the grid, i.e. the width, formed by the intersection of the feature and the grid geometry.

    • getGridRows

      public int getGridRows()

      The number of rows in the grid, i.e. the height, formed by the intersection of the feature and the grid geometry.

    • getGridOffsetY

      public int getGridOffsetY()

      The y position in the original grid where this feature grid starts

    • getGridOffsetX

      public int getGridOffsetX()

      The x position in the original grid where this feature grid starts

    • getCellWidth

      public double getCellWidth()

      The number of crs units between grid cells in the horizontal direction, e.g. you can add cellWidth to featureTopLeft to move across one grid cell column.

    • getCellHeight

      public double getCellHeight()

      The number of crs units between grid cells in the vertical direction, e.g. you can add cellHeight to featureTopLeft to move down one grid cell row.

    • getFeatureTopLeft

      public org.geotools.geometry.Position2D getFeatureTopLeft()

      The top left position of the feature within the grid in crs space. The is 'snapped' to the grid geometry and is the maximum position it can be while still encompassing the entire feature.