/** * Checks if any coverage in the list already fully contains the area of the test coverage * * @param coverages * @param test * @return */ private boolean coveragesContainArea(List<GridCoverage2D> coverages, GridCoverage2D test) { for (GridCoverage2D coverage : coverages) { if (coverage.getEnvelope2D().contains((BoundingBox) test.getEnvelope2D())) { return true; } } return false; }
@Override public Point2D mapDestPoint(Point2D destPt, int sourceIndex) { if (destPt == null) { throw new IllegalArgumentException("Bad dest pt"); // JaiI18N.getString("Generic0")); } else if (sourceIndex < 0 || sourceIndex >= getNumSources()) { throw new IndexOutOfBoundsException("Bad src"); // JaiI18N.getString("Generic1")); } double[] coords = new double[] {destPt.getX(), destPt.getY()}; try { mapDestPoint(coords); } catch (TransformException e) { LOGGER.log(Level.WARNING, "Error transforming coords", e); return null; } Point2D ret = ((Point2D) destPt.clone()); ret.setLocation(coords[0], coords[1]); if (dst.getEnvelope2D().contains(ret)) return ret; else return null; }
@Test public void testContainsBoundingBox() { boolean testContains; try { testContains = australia.contains((BoundingBox) envelope2D); // expected assertFalse(testContains); } catch (MismatchedReferenceSystemException t) { fail("Expected a match of CoordinateReferenceSystem"); } try { testContains = australia.contains((BoundingBox) somewhereInAustralia); // expected assertTrue(testContains); } catch (MismatchedReferenceSystemException t) { fail("Expected a match of CoordinateReferenceSystem"); } }
@Test public void testContainsDirectPosition() { boolean testContains; DirectPosition2D positionInAustralia = new DirectPosition2D(crs, 30, 120); DirectPosition2D positionOutsideAustralia = new DirectPosition2D(crs, 30, 170); try { testContains = australia.contains((DirectPosition) positionOutsideAustralia); // expected assertFalse(testContains); } catch (MismatchedReferenceSystemException t) { fail("Expected a match of CoordinateReferenceSystem"); } try { testContains = australia.contains((DirectPosition) positionInAustralia); // expected assertTrue(testContains); } catch (MismatchedReferenceSystemException t) { fail("Expected a match of CoordinateReferenceSystem"); } }
@Override public InfoToolResult getInfo(DirectPosition2D pos) throws Exception { InfoToolResult result = new InfoToolResult(); if (isValid()) { DirectPosition trPos = InfoToolHelperUtils.getTransformed(pos, getContentToLayerTransform()); if (cachedCoverage == null || !cachedCoverage.getEnvelope2D().contains(trPos)) { if (!renewCachedCoverage(trPos)) { return result; } } try { Object objArray = cachedCoverage.evaluate(trPos); Number[] bandValues = InfoToolHelperUtils.asNumberArray(objArray); if (bandValues != null) { result.newFeature("Raw values"); for (int i = 0; i < bandValues.length; i++) { result.setFeatureValue("Band " + i, bandValues[i]); } } } catch (PointOutsideCoverageException e) { // The empty result will be returned } } return result; }
@Override public Point2D mapDestPoint(Point2D destPt, int sourceIndex) { if (destPt == null) { throw new IllegalArgumentException("Bad dest pt");// JaiI18N.getString("Generic0")); } else if (sourceIndex < 0 || sourceIndex >= getNumSources()) { throw new IndexOutOfBoundsException("Bad src");// JaiI18N.getString("Generic1")); } double coords[] = new double[] { destPt.getX(), destPt.getY() }; try { mapDestPoint(coords); } catch (TransformException e) { LOGGER.log(Level.WARNING, "Error transforming coords", e); return null; } Point2D ret = ((Point2D) destPt.clone()); ret.setLocation(coords[0], coords[1]); if (dst.getGridGeometry().getEnvelope2D().contains(ret)) return ret; else return null; }
@Override public Point2D mapDestPoint(Point2D destPt, int sourceIndex) { if (destPt == null) { throw new IllegalArgumentException("Bad dest pt");// JaiI18N.getString("Generic0")); } else if (sourceIndex < 0 || sourceIndex >= getNumSources()) { throw new IndexOutOfBoundsException("Bad src");// JaiI18N.getString("Generic1")); } double coords[] = new double[] { destPt.getX(), destPt.getY() }; try { mapDestPoint(coords); } catch (TransformException e) { LOGGER.log(Level.WARNING, "Error transforming coords", e); return null; } Point2D ret = ((Point2D) destPt.clone()); ret.setLocation(coords[0], coords[1]); if (dst.getGridGeometry().getEnvelope2D().contains(ret)) return ret; else return null; }
@Override public InfoToolResult getInfo(DirectPosition2D pos) throws Exception { InfoToolResult result = new InfoToolResult(); if (isValid()) { DirectPosition trPos = InfoToolHelperUtils.getTransformed(pos, getContentToLayerTransform()); if (cachedCoverage == null || !cachedCoverage.getEnvelope2D().contains(trPos)) { if (!renewCachedCoverage(trPos)) { return result; } } try { Object objArray = cachedCoverage.evaluate(trPos); Number[] bandValues = InfoToolHelperUtils.asNumberArray(objArray); if (bandValues != null) { result.newFeature("Raw values"); for (int i = 0; i < bandValues.length; i++) { result.setFeatureValue("Band " + i, bandValues[i]); } } } catch (PointOutsideCoverageException e) { // The empty result will be returned } } return result; }