if (envelope.isEmpty()) { return null;
if (!requestedEnvelope.isEmpty()) { MathTransform crsToGrid = meta.getGrid().getGridToCRS().inverse(); GeneralEnvelope requestedGrid = CRS.transform(crsToGrid, requestedEnvelope);
/** * Returns {@code false} if at least one ordinate value is not {@linkplain Double#NaN NaN}. The * {@code isNull()} check is a little bit different than {@link #isEmpty()} since it returns * {@code false} for a partially initialized envelope, while {@code isEmpty()} returns {@code * false} only after all dimensions have been initialized. More specifically, the following * rules apply: * * <p> * * <ul> * <li>If <code>isNull() == true</code>, then <code>{@linkplain #isEmpty()} == true</code> * <li>If <code>{@linkplain #isEmpty()} == false</code>, then <code>isNull() == false</code> * <li>The converse of the above-cited rules are not always true. * </ul> * * @return {@code true} if this envelope has NaN values. * @since 2.2 */ public boolean isNull() { if (!isNilCoordinates(ordinates)) { return false; } assert isEmpty() : this; return true; }
/** * Adds a point to this envelope. The resulting envelope is the smallest envelope that contains * both the original envelope and the specified point. After adding a point, a call to {@link * #contains} with the added point as an argument will return {@code true}, except if one of the * point's ordinates was {@link Double#NaN} (in which case the corresponding ordinate have been * ignored). * * <p>This method assumes that the specified point uses the same CRS than this envelope. For * performance reason, it will no be verified unless J2SE assertions are enabled. * * @param position The point to add. * @throws MismatchedDimensionException if the specified point doesn't have the expected * dimension. */ public void add(final DirectPosition position) throws MismatchedDimensionException { ensureNonNull("position", position); final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("position", position.getDimension(), dim); assert equalsIgnoreMetadata(crs, position.getCoordinateReferenceSystem()) : position; for (int i = 0; i < dim; i++) { final double value = position.getOrdinate(i); if (value < ordinates[i] || Double.isNaN(ordinates[i])) ordinates[i] = value; if (value > ordinates[i + dim] || Double.isNaN(ordinates[i + dim])) ordinates[i + dim] = value; } assert isEmpty() || contains(position); }
new GeneralEnvelope(renderingEnvelopeInCoverageCRS); cropEnvelope.intersect(coverageEnvelope); if (cropEnvelope.isEmpty() || cropEnvelope.isNull()) { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info(
/** * Adds an envelope object to this envelope. The resulting envelope is the union of the two * {@code Envelope} objects. * * <p>This method assumes that the specified envelope uses the same CRS than this envelope. For * performance reason, it will no be verified unless J2SE assertions are enabled. * * @param envelope the {@code Envelope} to add to this envelope. * @throws MismatchedDimensionException if the specified envelope doesn't have the expected * dimension. */ public void add(final Envelope envelope) throws MismatchedDimensionException { ensureNonNull("envelope", envelope); final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dim); assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem()) : envelope; for (int i = 0; i < dim; i++) { final double min = envelope.getMinimum(i); final double max = envelope.getMaximum(i); if (min < ordinates[i]) ordinates[i] = min; if (max > ordinates[i + dim]) ordinates[i + dim] = max; } assert isEmpty() || contains(envelope, true); }
/** * Cropping the provided coverage to the requested geographic area. * * @param gc * @param envelope * @param crs * @return */ static GridCoverage2D crop( GridCoverage2D gc, GeneralEnvelope envelope, double[] background, final Hints hints) { final GeneralEnvelope oldEnvelope = (GeneralEnvelope) gc.getEnvelope(); // intersect the envelopes in order to prepare for cropping the coverage // down to the neded resolution final GeneralEnvelope intersectionEnvelope = new GeneralEnvelope(envelope); intersectionEnvelope.setCoordinateReferenceSystem(envelope.getCoordinateReferenceSystem()); intersectionEnvelope.intersect(oldEnvelope); // Do we have something to show? After the crop I could get a null // coverage which would mean nothing to show. if (intersectionEnvelope.isEmpty()) { return null; } // crop final ParameterValueGroup param = processor.getOperation("CoverageCrop").getParameters().clone(); param.parameter("source").setValue(gc); param.parameter("Envelope").setValue(intersectionEnvelope); return (GridCoverage2D) ((Crop) processor.getOperation("CoverageCrop")).doOperation(param, hints); }
@Test public void testConstruction() { GeneralEnvelope empty = new GeneralEnvelope(DefaultGeographicCRS.WGS84); assertTrue(empty.isEmpty()); Envelope2D empty2d = new Envelope2D(); assertTrue(empty2d.isEmpty()); assertTrue(geot3045.isEmpty()); assertTrue(geot4261.isEmpty()); geot4261.add(dp); assertEquals(new GeneralEnvelope(dp, dp), geot4261);
/** * Tests that the conversion of different bound types to ReferencedEnvelope does not lose the * emptiness property * * @throws Exception */ @Test public void testEmptyEnvelopeConversion() throws Exception { // conversion of an empty OGC envelope should stay empty GeneralEnvelope ge = new GeneralEnvelope(new double[] {0, 0}, new double[] {-1, -1}); assertTrue(ge.isEmpty()); assertTrue(ReferencedEnvelope.create(ge, ge.getCoordinateReferenceSystem()).isEmpty()); assertTrue(ReferencedEnvelope.reference(ge).isEmpty()); // conversion of an empty Java Rectangle 2D should stay empty Rectangle2D r2d = new Rectangle2D.Double(0, 0, -1, -1); assertTrue(r2d.isEmpty()); assertTrue(ReferencedEnvelope.create(r2d, null).isEmpty()); // conversion of an empty ReferencedEnvelope should stay empty ReferencedEnvelope re = new ReferencedEnvelope(); assertTrue(re.isEmpty()); assertTrue(ReferencedEnvelope.create(re).isEmpty()); assertTrue(ReferencedEnvelope.create(re, re.getCoordinateReferenceSystem()).isEmpty()); assertTrue(ReferencedEnvelope.reference(re).isEmpty()); } }
if (intersectionEnvelope.isEmpty()) { throw new EmptyIntersectionException("Crop envelope does not intersect in model space");
if (intersectionEnvelope.isEmpty()||intersectionEnvelope.isNull()) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER
if (intersectionEnvelope.isEmpty()||intersectionEnvelope.isNull()) { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("The destination envelope does not intersect the envelope of the source coverage.");
/** * Cropping the provided coverage to the requested geographic area. * * @param gc * @param envelope * @param crs * @return */ private static GridCoverage2D getCroppedCoverage(GridCoverage2D gc, GeneralEnvelope envelope, CoordinateReferenceSystem crs, final Hints hints) { final GeneralEnvelope oldEnvelope = (GeneralEnvelope) gc.getEnvelope(); // intersect the envelopes in order to prepare for crooping the coverage // down to the neded resolution final GeneralEnvelope intersectionEnvelope = new GeneralEnvelope( envelope); intersectionEnvelope.setCoordinateReferenceSystem(crs); intersectionEnvelope.intersect((GeneralEnvelope) oldEnvelope); // Do we have something to show? After the crop I could get a null // coverage which would mean nothing to show. if (intersectionEnvelope.isEmpty()) return null; // crop final ParameterValueGroup param = (ParameterValueGroup) cropParams .clone(); param.parameter("source").setValue(gc); param.parameter("Envelope").setValue(intersectionEnvelope); return (GridCoverage2D) coverageCropFactory.doOperation(param, hints); }
if (intersectionEnvelope.isEmpty()) return null;
if (sourceCRSEnvelope != null) { intersectedEnvelope.intersect(sourceCRSEnvelope); if (intersectedEnvelope.isEmpty()) throw new IllegalArgumentException( "The provided envelope is outside the source CRS definition area");
if (intersectionEnvelope.isEmpty()) { throw new WcsException("The Intersection is null. Check the requested BBOX!");
if (cropEnvelope.isEmpty()) throw new CannotCropException(Errors .format(ErrorKeys.CANT_CROP));
if (intersectionEnvelope.isEmpty()) throw new CannotCropException(Errors .format(ErrorKeys.CANT_CROP));
if (intersectionEnvelope.isEmpty()) throw new CannotCropException(Errors.format(ErrorKeys.CANT_CROP));