/** * Setup a ROIGeometry on top of a geometry. * It takes care of removing invalid polygon, opened line strings and so on * @param geometry the input geometry to be used as reference to create a new {@link ROIGeometry} * @return a ROI from the input geometry. */ private ROI buildROIGeometry(Geometry geometry) { // cleanup the geometry, extract only the polygons, set oriented operations might // have returned a mix of points and lines in the resulting geometries final List<Polygon> polygons = new ArrayList<Polygon>(); geometry.apply(new GeometryComponentFilter() { public void filter(Geometry geom) { if (geom instanceof Polygon) { polygons.add((Polygon) geom); } } }); // build a polygon or a multipolygon Geometry geom = null; if (polygons.size() == 0) { geom = geomFactory.createMultiPolygon(new Polygon[0]); } else if (polygons.size() == 1) { geom = polygons.get(0); } else { Polygon[] polygonArray = (Polygon[]) polygons.toArray(new Polygon[polygons.size()]); geom = geomFactory.createMultiPolygon(polygonArray); } return new ROIGeometry(geom, this.useAntialiasing, this.useFixedPrecision, this.hints); }
ROI imageBounds = new ROIGeometry(mask); if (footprintManagement){ final ROI footprint = result.getFootprint();
/** * 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 ProcessException { // transform the geometry to raster space so that we can use it as a ROI source Geometry rasterSpaceGeometry; try { rasterSpaceGeometry = JTS.transform(roi, new AffineTransform2D(mt2d.createInverse())); } catch (MismatchedDimensionException e) { throw new ProcessException(e); } catch (TransformException e) { throw new ProcessException(e); } catch (NoninvertibleTransformException e) { throw new ProcessException(e); } // 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 ROIGeometry(simplifiedGeometry); }
geMapper.setPixelAnchor(PixelInCell.CELL_CORNER); Geometry mapped = JTS.transform(inclusionGeometry, geMapper.createTransform().inverse()); this.granuleROIShape = new ROIGeometry(mapped);
ROI roi = new ROIGeometry(simplifiedGeometry, false);
for (int i=0; i<rois.length; i++){ if (globalRoi == null){ globalRoi = new ROIGeometry(((ROIGeometry)rois[i]).getAsGeometry()); } else { globalRoi = globalRoi.add(rois[i]);