final CoordinateReferenceSystem sourceCRS = envelope.getCoordinateReferenceSystem(); CoordinateReferenceSystem destCRS; try {
/** * Returns the current coordinate reference system. If no CRS has been {@linkplain * #setCoordinateReferenceSystem explicitly defined}, then the default CRS is {@linkplain * DefaultGeographicCRS#WGS84 WGS84}. */ public CoordinateReferenceSystem getCoordinateReferenceSystem() { return (envelope != null) ? envelope.getCoordinateReferenceSystem() : DefaultGeographicCRS.WGS84; }
final CoordinateReferenceSystem sourceCRS = envelope.getCoordinateReferenceSystem();
CoordinateReferenceSystem nativeCRS = envelope.getCoordinateReferenceSystem(); cinfo.setNativeCRS(nativeCRS);
/** * Constructs a envelope defined by two positions. The coordinate reference system is inferred * from the supplied direct position. * * @param minDP Point containing minimum ordinate values. * @param maxDP Point containing maximum ordinate values. * @throws MismatchedDimensionException if the two positions don't have the same dimension. * @throws MismatchedReferenceSystemException if the two positions don't use the same CRS. * @throws IllegalArgumentException if an ordinate value in the minimum point is not less than * or equal to the corresponding ordinate value in the maximum point. */ public GeneralEnvelope(final GeneralDirectPosition minDP, final GeneralDirectPosition maxDP) throws MismatchedReferenceSystemException, IllegalArgumentException { // Uncomment next lines if Sun fixes RFE #4093999 // ensureNonNull("minDP", minDP); // ensureNonNull("maxDP", maxDP); this(minDP.ordinates, maxDP.ordinates); crs = getCoordinateReferenceSystem(minDP, maxDP); AbstractDirectPosition.checkCoordinateReferenceSystemDimension(crs, ordinates.length / 2); }
requestedEnvelope.getCoordinateReferenceSystem(); final CoordinateReferenceSystem nativeCRS = reader.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(requestCRS, nativeCRS)) {
/** * Returns {@code true} if all the parameters specified by the argument are set. * * @param bitmask Any combination of {@link #CRS_BITMASK}, {@link #ENVELOPE_BITMASK}, {@link * #GRID_RANGE_BITMASK} and {@link #GRID_TO_CRS_BITMASK}. * @return {@code true} if all specified attributes are defined (i.e. invoking the corresponding * method will not thrown an {@link InvalidGridGeometryException}). * @throws IllegalArgumentException if the specified bitmask is not a combination of known * masks. * @since 2.2 * @see javax.media.jai.ImageLayout#isValid */ public boolean isDefined(final int bitmask) throws IllegalArgumentException { if ((bitmask & ~(CRS_BITMASK | ENVELOPE_BITMASK | GRID_RANGE_BITMASK | GRID_TO_CRS_BITMASK)) != 0) { throw new IllegalArgumentException( Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2, "bitmask", bitmask)); } return ((bitmask & CRS_BITMASK) == 0 || (envelope != null && envelope.getCoordinateReferenceSystem() != null)) && ((bitmask & ENVELOPE_BITMASK) == 0 || (envelope != null && !envelope.isNull())) && ((bitmask & GRID_RANGE_BITMASK) == 0 || (gridRange != null)) && ((bitmask & GRID_TO_CRS_BITMASK) == 0 || (gridToCRS != null)); }
/** Converts a {@link GeneralEnvelope} into a {@link ReferencedEnvelope} */ ReferencedEnvelope reference(GeneralEnvelope ge) { return new ReferencedEnvelope( ge.getMinimum(0), ge.getMaximum(0), ge.getMinimum(1), ge.getMaximum(1), ge.getCoordinateReferenceSystem()); }
private static ReferencedEnvelope toReferencedEnvelope(GeneralEnvelope envelope) { double minx = envelope.getMinimum(0); double maxx = envelope.getMaximum(0); double miny = envelope.getMinimum(1); double maxy = envelope.getMaximum(1); CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); ReferencedEnvelope refEnv = new ReferencedEnvelope(minx, maxx, miny, maxy, crs); return refEnv; }
@Override public boolean accept(GranuleDescriptor granuleDescriptor) { // make sure the CRSs match boolean shouldAccept = false; // need to check that the granule matches CRS CoordinateReferenceSystem granuleCRS = granuleDescriptor.getGranuleEnvelope().getCoordinateReferenceSystem(); shouldAccept = CRS.equalsIgnoreMetadata(granuleCRS, this.crs); return shouldAccept && super.accept(granuleDescriptor); }
/** * Sets the envelope to the specified value. If a {@linkplain #setCoordinateReferenceSystem CRS * was previously defined}, the envelope will be reprojected to that CRS. If no CRS was * previously defined, then the CRS will be set to the {@linkplain * Envelope#getCoordinateReferenceSystem envelope CRS}. * * @throws IllegalArgumentException if the envelope is illegal for the {@linkplain * #getCoordinateReferenceSystem current CRS}. */ public void setEnvelope(Envelope envelope) throws IllegalArgumentException { if (this.envelope != null) try { envelope = CRS.transform(envelope, this.envelope.getCoordinateReferenceSystem()); } catch (TransformException exception) { throw new IllegalArgumentException( Errors.format(ErrorKeys.ILLEGAL_COORDINATE_REFERENCE_SYSTEM), exception); } this.envelope = new GeneralEnvelope(envelope); coverage = null; }
/** * Converts a {@link GeneralEnvelope} into a {@link ReferencedEnvelope} * * @param ge * @return */ ReferencedEnvelope reference(GeneralEnvelope ge) { return new ReferencedEnvelope( ge.getMinimum(0), ge.getMaximum(0), ge.getMinimum(1), ge.getMaximum(1), ge.getCoordinateReferenceSystem()); }
/** * Convert the crop envelope into a polygon and the use the world-to-grid transform to get a ROI * for the source coverage. */ public static Polygon getPolygon(final GeneralEnvelope env, final GeometryFactory gf) throws IllegalStateException, MismatchedDimensionException { final Rectangle2D rect = env.toRectangle2D(); final Coordinate[] coord = new Coordinate[] { new Coordinate(rect.getMinX(), rect.getMinY()), new Coordinate(rect.getMinX(), rect.getMaxY()), new Coordinate(rect.getMaxX(), rect.getMaxY()), new Coordinate(rect.getMaxX(), rect.getMinY()), new Coordinate(rect.getMinX(), rect.getMinY()) }; final LinearRing ring = gf.createLinearRing(coord); final Polygon modelSpaceROI = new Polygon(ring, null, gf); // check that we have the same thing here assert modelSpaceROI .getEnvelopeInternal() .equals(new ReferencedEnvelope(rect, env.getCoordinateReferenceSystem())); return modelSpaceROI; }
@Override public boolean accept(GranuleDescriptor granuleDescriptor) { // we have a current CRS group, either it matches or we need to create a new one boolean accepted = currentSubmosaicProducer != null && currentSubmosaicProducer.accept(granuleDescriptor); if (!accepted) { // either we have no producer, or the granule was rejected by the current one, // presumably because its CRS didn't match, we need to create a new one because we've // moved on to the next CoordinateReferenceSystem targetCRS = granuleDescriptor.getGranuleEnvelope().getCoordinateReferenceSystem(); try { RasterLayerResponse transformedResponse = rasterLayerResponse.reprojectTo(granuleDescriptor); if (transformedResponse == null) { return false; } this.currentSubmosaicProducer = new CRSBoundMosaicProducer( transformedResponse, dryRun, targetCRS, granuleDescriptor); perMosaicProducers.add(currentSubmosaicProducer); accepted = true; } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to setup CRS specific sub-mosaic", e); } } return accepted; }
/** * Returns the "real world" coordinate reference system. * * @return The coordinate reference system (never {@code null}). * @throws InvalidGridGeometryException if this grid geometry has no CRS (i.e. <code> * {@linkplain #isDefined isDefined}({@linkplain #CRS_BITMASK})</code> returned {@code * false}). * @see GridGeometry2D#getCoordinateReferenceSystem2D * @since 2.2 */ public CoordinateReferenceSystem getCoordinateReferenceSystem() throws InvalidGridGeometryException { if (envelope != null) { final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); if (crs != null) { assert isDefined(CRS_BITMASK); return crs; } } assert !isDefined(CRS_BITMASK); throw new InvalidGridGeometryException(ErrorKeys.UNSPECIFIED_CRS); }
/** * @param inputEnvelope * @return * @throws Exception */ static GeneralEnvelope reprojectEnvelope( GeneralEnvelope inputEnvelope, final CoordinateReferenceSystem outputCRS) throws Exception { GeneralEnvelope outputEnvelope = null; CoordinateReferenceSystem inputCRS = inputEnvelope.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(inputCRS, outputCRS)) { outputEnvelope = CRS.transform(inputEnvelope, outputCRS); outputEnvelope.setCoordinateReferenceSystem(outputCRS); } // simple copy if (outputEnvelope == null) { outputEnvelope = new GeneralEnvelope(inputEnvelope); outputEnvelope.setCoordinateReferenceSystem(inputCRS); } return null; }
throws FactoryException { assert CRS.equalsIgnoreMetadata(destinationEnvelope.getCoordinateReferenceSystem(), crs) || CRS.findMathTransform(destinationEnvelope.getCoordinateReferenceSystem(), crs) .isIdentity();
coverageEnvelope, coverageEnvelope.getCoordinateReferenceSystem());
/** * 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); }
/** * 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()); } }