@Before public void setupTest() { Rectangle2D bounds = new Rectangle2D.Double(-20.0, -20.0, 40.0, 40.0); this.envelope2D = new Envelope2D(crs, bounds); this.australia = new Envelope2D(this.crs); australia.include(40, 110); australia.include(10, 150); this.newZealand = new Envelope2D(DefaultEngineeringCRS.CARTESIAN_2D); newZealand.include(50, 165); newZealand.include(33, 180); this.somewhereIntersectingAustralia = new Envelope2D(this.crs); somewhereIntersectingAustralia.include(50, 145); somewhereIntersectingAustralia.include(33, 180); this.somewhereInAustralia = new Envelope2D(this.crs); somewhereInAustralia.include(35, 140); somewhereInAustralia.include(40, 145); }
/** * This method creates a new {@link GridGeometry2D} object based on that of the {@link * GridCoverage2D} defined by the index. * * @param sources * @param index * @return */ private static GridGeometry2D extractFinalGridGeometry( GridCoverage2D[] sources, int index) { // Select the GridGeometry of the first coverage GridGeometry2D gg = sources[index].getGridGeometry(); MathTransform g2w = gg.getGridToCRS2D(PixelOrientation.UPPER_LEFT); // Initial Bounding box Envelope2D bbox = gg.getEnvelope2D(); // Number of the sources to use int numSources = sources.length; // Cycle on all the GridCoverages in order to create the final Bounding box for (int i = 0; i < numSources; i++) { bbox.include(sources[i].getEnvelope2D()); } // Creation of a final GridGeometry containing the final Bounding Box GridGeometry2D finalGG = new GridGeometry2D( PixelInCell.CELL_CORNER, g2w, bbox, GeoTools.getDefaultHints()); return finalGG; } }
globalBbox.include(source.getEnvelope2D());
@Test public void testInclude() throws Exception { assertEquals("unexpected bounds x min after include", 10, australia.x, 0); assertEquals("unexpected bounds y min after include", 110, australia.y, 0); assertEquals("unexpected bounds width after include", 30, australia.width, 0); assertEquals("unexpected bounds height after include", 40, australia.height, 0); try { australia.include(newZealand); fail("Expected a mismatch of CoordinateReferenceSystem"); } catch (MismatchedReferenceSystemException t) { // expected } try { australia.include(this.envelope2D); // expected assertEquals("unexpected bounds x min after include", -20, australia.x, 0); assertEquals("unexpected bounds y min after include", -20, australia.y, 0); assertEquals("unexpected bounds width after include", 60, australia.width, 0); assertEquals("unexpected bounds height after include", 170, australia.height, 0); } catch (MismatchedReferenceSystemException t) { fail("Expected a match of CoordinateReferenceSystem"); } }
envelope.include(g.getEnvelope());
envelope.include(g.getEnvelope());