Search in sources :

Example 1 with FastLiteShape

use of org.hortonmachine.gears.utils.features.FastLiteShape in project hortonmachine by TheHortonMachine.

the class CoverageUtilities method prepareROI.

/**
 * Utility method for transforming a geometry ROI into the raster space, using the provided affine transformation.
 *
 * @param roi a {@link Geometry} in model space.
 * @param mt2d an {@link AffineTransform} that maps from raster to model space. This is already referred to the pixel corner.
 * @return a {@link ROI} suitable for using with JAI.
 * @throws ProcessException in case there are problems with ivnerting the provided {@link AffineTransform}. Very unlikely to happen.
 */
public static ROI prepareROI(Geometry roi, AffineTransform mt2d) throws Exception {
    // transform the geometry to raster space so that we can use it as a ROI source
    Geometry rasterSpaceGeometry = JTS.transform(roi, new AffineTransform2D(mt2d.createInverse()));
    // simplify the geometry so that it's as precise as the coverage, excess coordinates
    // just make it slower to determine the point in polygon relationship
    Geometry simplifiedGeometry = DouglasPeuckerSimplifier.simplify(rasterSpaceGeometry, 1);
    // build a shape using a fast point in polygon wrapper
    return new ROIShape(new FastLiteShape(simplifiedGeometry));
}
Also used : PreparedGeometry(org.locationtech.jts.geom.prep.PreparedGeometry) Geometry(org.locationtech.jts.geom.Geometry) ROIShape(javax.media.jai.ROIShape) FastLiteShape(org.hortonmachine.gears.utils.features.FastLiteShape) AffineTransform2D(org.geotools.referencing.operation.transform.AffineTransform2D)

Aggregations

ROIShape (javax.media.jai.ROIShape)1 AffineTransform2D (org.geotools.referencing.operation.transform.AffineTransform2D)1 FastLiteShape (org.hortonmachine.gears.utils.features.FastLiteShape)1 Geometry (org.locationtech.jts.geom.Geometry)1 PreparedGeometry (org.locationtech.jts.geom.prep.PreparedGeometry)1