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));
}
Aggregations