/** * Converts a {@link Envelope} into a {@link ReferencedEnvelope} * * @param envelope * @return */ ReferencedEnvelope reference(Envelope envelope) { ReferencedEnvelope env = new ReferencedEnvelope(envelope.getCoordinateReferenceSystem()); env.expandToInclude(envelope.getMinimum(0), envelope.getMinimum(1)); env.expandToInclude(envelope.getMaximum(0), envelope.getMaximum(1)); return env; }
ensureNonNull("envelope", envelope); final int dimension = getDimension(); if (envelope.getDimension() != dimension) { return false; assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem()) : envelope; for (int i = 0; i < dimension; i++) { double epsilon; if (epsIsRelative) { epsilon = Math.max(getSpan(i), envelope.getSpan(i)); epsilon = (epsilon > 0 && epsilon < Double.POSITIVE_INFINITY) ? epsilon * eps : eps; } else { if (!(Math.abs(getMinimum(i) - envelope.getMinimum(i)) <= epsilon && Math.abs(getMaximum(i) - envelope.getMaximum(i)) <= epsilon)) { return false;
HashMap<String, Double> envelopeParams = new HashMap<String, Double>(); Envelope envelope = gridCoverage.getEnvelope(); DirectPosition lowerCorner = envelope.getLowerCorner(); double[] westSouth = lowerCorner.getCoordinate(); DirectPosition upperCorner = envelope.getUpperCorner(); double[] eastNorth = upperCorner.getCoordinate(); GridGeometry2D gridGeometry = gridCoverage.getGridGeometry(); GridEnvelope2D gridRange = gridGeometry.getGridRange2D(); int height = gridRange.height; int width = gridRange.width; int minY = gridRange.y; AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS(); double xRes = XAffineTransform.getScaleX0(gridToCRS); double yRes = XAffineTransform.getScaleY0(gridToCRS);
public String getBoundsStr() { if (bounds == null) { return null; } else { return bounds.getMinimum(0) + "," + bounds.getMinimum(1) + "," + bounds.getMaximum(0) + "," + bounds.getMaximum(1); } }
public CRSEnvelope(Envelope envelope) { this.srsName = CRS.toSRS(envelope.getCoordinateReferenceSystem()); // this.srsName = epsgCode; this.minX = envelope.getMinimum(0); this.maxX = envelope.getMaximum(0); this.minY = envelope.getMinimum(1); this.maxY = envelope.getMaximum(1); }
final CoordinateReferenceSystem sourceCRS = sourceCoverage.getCoordinateReferenceSystem(); if (targetCRS == null) { if (targetGG != null && targetGG.isDefined(GridGeometry2D.CRS_BITMASK)) { targetCRS = targetGG.getCoordinateReferenceSystem(); } else { if (targetGG != null && targetGG.isDefined(GridGeometry2D.CRS_BITMASK)) { final GridGeometry2D sourceGG = sourceCoverage.getGridGeometry(); final MathTransform gridToCRS; switch (envelope.getDimension()) { return targetCoverage; final GridGeometry2D sourceGG = sourceCoverage.getGridGeometry(); final CoordinateReferenceSystem compatibleSourceCRS = compatibleSourceCRS( if (CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { targetEnvelope.setCoordinateReferenceSystem(targetCRS); if (!(new GeneralEnvelope(source).contains(target, true))) { if (interpolation != null && !(interpolation instanceof InterpolationNearest)) {
(GridCoverage2DReader) GRID_PROPERTY_NAME.evaluate(gridWrapper); if (CRS.equalsIgnoreMetadata( reader.getCoordinateReferenceSystem(), gridGeometry.getCoordinateReferenceSystem())) { && readGG.getGridToCRS2D() instanceof AffineTransform2D) { AffineTransform2D atOriginal = (AffineTransform2D) g2w; AffineTransform2D atMap = (AffineTransform2D) readGG.getGridToCRS2D(); if (XAffineTransform.getScale(atMap) < XAffineTransform.getScale(atOriginal)) { PixelInCell.CELL_CORNER, atOriginal, worldEnvelope.getCoordinateReferenceSystem(), null); new ReferencedEnvelope(readGG.getEnvelope()); CoordinateReferenceSystem coverageCRS = coverage.getCoordinateReferenceSystem2D(); if (!CRS.equalsIgnoreMetadata( renderingEnvelope.getCoordinateReferenceSystem(), coverageCRS)) { renderingEnvelope = renderingEnvelope.transform(coverageCRS, true); if (coverage.getEnvelope2D().intersects(renderingEnvelope)) {
final GridEnvelope gridRange = targetCoverage.getGridGeometry().getGridRange(); new GeneralEnvelope( new double[] {targetCoverage.getEnvelope().getMinimum(0), -43.5}, new double[] {targetCoverage.getEnvelope().getMaximum(0), -43.0}); expectedEnvelope.setCoordinateReferenceSystem(CRS.decode("EPSG:4326", true)); expectedEnvelope, scale, (GeneralEnvelope) targetCoverage.getEnvelope(), scale); assertTrue( CRS.equalsIgnoreMetadata( targetCoverage.getCoordinateReferenceSystem(), expectedEnvelope.getCoordinateReferenceSystem())); assertEquals(gridRange.getSpan(0), 360); assertEquals(gridRange.getSpan(1), 120);
public void testTransformWgs84PolarStereographic() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true); Envelope2D envelope = new Envelope2D(DefaultGeographicCRS.WGS84); envelope.add(-180, -90); envelope.add(180, 0); Envelope transformed = CRS.transform(envelope, crs); // the result is a square assertEquals(transformed.getMaximum(0), transformed.getMaximum(1), 1d); assertEquals(transformed.getMinimum(0), transformed.getMinimum(1), 1d); assertEquals(Math.abs(transformed.getMinimum(0)), transformed.getMaximum(0), 1d); assertEquals(transformed.getMaximum(0), 1.236739621845986E7, 1d); }
@Test public void testZoomlevel3() throws IOException { MBTilesReader reader = new MBTilesReader(getClass().getResource("world_lakes.mbtiles"), null); GeneralParameterValue[] parameters = new GeneralParameterValue[1]; GridGeometry2D gg = new GridGeometry2D( new GridEnvelope2D(new Rectangle(500, 500)), new ReferencedEnvelope(0, 90.0, -85.0, 0, MBTilesReader.WGS_84)); parameters[0] = new Parameter<GridGeometry2D>(AbstractGridFormat.READ_GRIDGEOMETRY2D, gg); GridCoverage2D gc = reader.read(parameters); RenderedImage img = gc.getRenderedImage(); assertEquals(0, gc.getEnvelope().getMinimum(0), 0.01); assertEquals(-20037508.34, gc.getEnvelope().getMinimum(1), 0.01); assertEquals(15028131.25, gc.getEnvelope().getMaximum(0), 0.01); assertEquals(0, gc.getEnvelope().getMaximum(1), 0.01); assertEquals(768, img.getWidth()); assertEquals(1024, img.getHeight()); }
for (String variantCode : variants) { variant = variant(variantCode); is900913Compatible = variant != null && CRS.equalsIgnoreMetadata(targetCrs, variant); if (is900913Compatible) { break; final org.opengis.geometry.Envelope envelope = CRS.getEnvelope(targetCrs); if (envelope == null) { return null; if (envelope.getSpan(0) < tolerance || envelope.getSpan(1) < tolerance) { GeographicBoundingBox latLonBBox = CRS.getGeographicBoundingBox(targetCrs); ReferencedEnvelope bbox = new ReferencedEnvelope(new GeneralEnvelope(latLonBBox)); Polygon geometry = JTS.toGeometry(bbox); double distanceTolerance = Math.max(bbox.getSpan(0), bbox.getSpan(1)) / 2E5; Geometry densifiedGeom = Densifier.densify(geometry, distanceTolerance); MathTransform mathTransform; aovGeom = JTS.toGeometry(new Envelope(envelope.getMinimum(0), envelope.getMaximum(0), envelope.getMinimum(1), envelope.getMaximum(1)));
final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); if (crs != null && !equalsIgnoreMetadata(crs, sourceCRS)) { throw new MismatchedReferenceSystemException( Errors.format(ErrorKeys.MISMATCHED_COORDINATE_REFERENCE_SYSTEM)); final GeneralEnvelope transformed = transform(mt, envelope, centerPt); continue; final double min = envelope.getMinimum(i); final double max = envelope.getMaximum(i); final double v1 = axis.getMinimumValue(); final double v2 = axis.getMaximumValue(); sourcePt = new GeneralDirectPosition(dimension); for (int j = 0; j < dimension; j++) { sourcePt.setOrdinate(j, envelope.getMedian(j)); transformed.add(targetPt = mt.transform(sourcePt, targetPt)); transformed.add(targetPt = mt.transform(sourcePt, targetPt)); sourcePt.setOrdinate(i, envelope.getMedian(i)); final CoordinateSystemAxis axis = sourceCS.getAxis(i); if (equalsIgnoreMetadata(DefaultCoordinateSystemAxis.LONGITUDE, axis)) { double minLon = envelope.getMinimum(i); double maxLon = envelope.getMaximum(i);
static ReferencedEnvelope findBounds(GridCoverage2D raster) { org.opengis.geometry.Envelope e = raster.getEnvelope(); return new ReferencedEnvelope( e.getMinimum(0), e.getMaximum(0), e.getMinimum(1), e.getMaximum(1), raster.getCoordinateReferenceSystem()); }
/** * Tests the transformations of an envelope when the two CRS have identify transforms but * different datum names */ @Test public void testEnvelopeTransformation2() throws FactoryException, TransformException { final CoordinateReferenceSystem WGS84Altered = CRS.parseWKT(WKT.WGS84_ALTERED); final CoordinateReferenceSystem WGS84 = DefaultGeographicCRS.WGS84; final MathTransform crsTransform = CRS.findMathTransform(WGS84, WGS84Altered, true); assertTrue(crsTransform.isIdentity()); final GeneralEnvelope firstEnvelope; firstEnvelope = new GeneralEnvelope(new double[] {-124, 42}, new double[] {-122, 43}); firstEnvelope.setCoordinateReferenceSystem(WGS84); // this triggered a assertion error in GEOT-2934 Envelope transformed = CRS.transform(firstEnvelope, WGS84Altered); // check the envelope is what we expect assertEquals(transformed.getCoordinateReferenceSystem(), WGS84Altered); double EPS = 1e-9; assertEquals(transformed.getMinimum(0), firstEnvelope.getMinimum(0), EPS); assertEquals(transformed.getMinimum(1), firstEnvelope.getMinimum(1), EPS); assertEquals(transformed.getMaximum(0), firstEnvelope.getMaximum(0), EPS); assertEquals(transformed.getMaximum(1), firstEnvelope.getMaximum(1), EPS); }
@Test public void testNoLimits() throws Exception { Map<String, Object> raw = getWorld(); authenticate("cite", "cite"); GridCoverage[] coverages = executeGetCoverageKvp(raw); // basic checks assertEquals(1, coverages.length); GridCoverage2D coverage = (GridCoverage2D) coverages[0]; final CoordinateReferenceSystem wgs84Flipped = CRS.decode("urn:ogc:def:crs:EPSG:6.6:4326"); assertEquals(wgs84Flipped, coverage.getEnvelope().getCoordinateReferenceSystem()); assertEquals(-90.0, coverage.getEnvelope().getMinimum(0), 1e-6); assertEquals(-180.0, coverage.getEnvelope().getMinimum(1), 1e-6); assertEquals(90.0, coverage.getEnvelope().getMaximum(0), 1e-6); assertEquals(180.0, coverage.getEnvelope().getMaximum(1), 1e-6); // make sure it has not been cropped int[] value = new int[3]; // some point in USA coverage.evaluate((DirectPosition) new DirectPosition2D(wgs84Flipped, 40, -90), value); assertTrue(value[0] > 0); assertTrue(value[1] > 0); assertTrue(value[2] > 0); // some point in Europe coverage.evaluate((DirectPosition) new DirectPosition2D(wgs84Flipped, 45, 12), value); assertTrue(value[0] > 0); assertTrue(value[1] > 0); assertTrue(value[2] > 0); CoverageCleanerCallback.disposeCoverage(coverage); }
crs = CRS.decode(bbox.getEPSGCode()); env = new ReferencedEnvelope( bbox.getMinX(), bbox.getMaxX(), new ReferencedEnvelope( env.getMinimum(0), env.getMaximum(0), env.getMinimum(1), env.getMaximum(1), crs);
@Test public void testKvpBasic() throws Exception { Map<String, Object> raw = baseMap(); final String getLayerId = getLayerId(TASMANIA_BM); raw.put("identifier", getLayerId); raw.put("format", "image/tiff"); raw.put("BoundingBox", "-90,-180,90,180,urn:ogc:def:crs:EPSG:6.6:4326"); raw.put("store", "false"); raw.put("GridBaseCRS", "urn:ogc:def:crs:EPSG:6.6:4326"); GridCoverage[] coverages = executeGetCoverageKvp(raw); assertEquals(1, coverages.length); GridCoverage2D coverage = (GridCoverage2D) coverages[0]; assertEquals( CRS.decode("urn:ogc:def:crs:EPSG:6.6:4326"), coverage.getEnvelope().getCoordinateReferenceSystem()); }
if (envelope == null) throw new IllegalArgumentException("Specified envelope is null"); Envelope requestedWGS84; final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(crs, DefaultGeographicCRS.WGS84)) { GeneralEnvelope env = CRS.transform(envelope, DefaultGeographicCRS.WGS84); if (get2D) { requestedWGS84 = new Envelope2D(env); requestedWGS84 = env; ((GeneralEnvelope) requestedWGS84) .setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); else return new GeneralEnvelope(envelope);
public void testTransformPolarStereographicToOther() throws Exception { CoordinateReferenceSystem antarcticPs = CRS.decode("EPSG:3031", true); CoordinateReferenceSystem australianPs = CRS.decode("EPSG:3032", true); Envelope2D envelope = new Envelope2D(antarcticPs); envelope.add(-4223632.8125, -559082.03125); envelope.add(5053710.9375, 3347167.96875); Envelope transformed = CRS.transform(envelope, australianPs); // has a false easting and northing, we can only check the spans are equal assertEquals(transformed.getSpan(0), transformed.getSpan(1), 1d); assertEquals(transformed.getMaximum(0), 1.2309982175378662E7, 1d); }
(AffineTransform) ((GridGeometry2D) gc.getGridGeometry()).getGridToCRS2D(); final double dx = XAffineTransform.getScaleX0(gridToWorld); final double dy = XAffineTransform.getScaleY0(gridToWorld); final RenderedImage image = gc.getRenderedImage(); int Nx = image.getWidth(); int Ny = image.getHeight(); final Envelope oldEnv = gc.getEnvelope2D(); final double W = oldEnv.getSpan(0); final double H = oldEnv.getSpan(1); if ((dx - dy) > ArcGridWriter.ROTATION_EPS) { new GeneralGridEnvelope(new int[] {0, 0}, new int[] {Nx, Ny}); final GridGeometry2D newGridGeometry = new GridGeometry2D(newGridrange, new GeneralEnvelope(gc.getEnvelope()));