Package org.geotools.geometry

Examples of org.geotools.geometry.Envelope2D


     */
    public Envelope2D reduce(final Envelope envelope) {
        if (envelope == null) {
            return null;
        }
        return new Envelope2D(crs2D,
                envelope.getMinimum(axisDimensionX),
                envelope.getMinimum(axisDimensionY),
                envelope.getSpan   (axisDimensionX),
                envelope.getSpan   (axisDimensionY));
    }
View Full Code Here


     * @see #getEnvelope
     */
    public Envelope2D getEnvelope2D() throws InvalidGridGeometryException {
        if (envelope!=null && !envelope.isNull()) {
            assert isDefined(ENVELOPE_BITMASK);
            return new Envelope2D(crs2D,
                    envelope.getMinimum(axisDimensionX),
                    envelope.getMinimum(axisDimensionY),
                    envelope.getSpan   (axisDimensionX),
                    envelope.getSpan   (axisDimensionY));
            // Note: we didn't invoked reduce(Envelope) in order to make sure that
View Full Code Here

            Point2D trLow = mt.transform(new Point2D.Double(low.x - 0.5, low.y - 0.5), null);

            GridCoordinates2D high = gridEnv.getHigh();
            Point2D trHigh = mt.transform(new Point2D.Double(high.x + 0.5, high.y + 0.5), null);

            return new Envelope2D(
                    new DirectPosition2D(crs2D, trLow.getX(), trLow.getY()),
                    new DirectPosition2D(crs2D, trHigh.getX(), trHigh.getY()));

        } else {
            throw new IllegalArgumentException(
View Full Code Here

      // get the original envelope and the crs
      //
      // //
      final CoordinateReferenceSystem crs = source
          .getCoordinateReferenceSystem2D();
      final Envelope2D envelope = source.getEnvelope2D();     

      // /////////////////////////////////////////////////////////////////////
      //
      // Transcode the xPeriod and yPeriod parameters by applying the
      // WorldToGrid transformation for the source coverage.
      //
      // I am assuming that the supplied values are in the same CRS as the
      // source coverage. We here apply
      //
      // /////////////////////////////////////////////////////////////////////
      final double xPeriod = parameters.parameter("xPeriod")
          .doubleValue();
      final double yPeriod = parameters.parameter("yPeriod")
          .doubleValue();
      if(!Double.isNaN(xPeriod)&&!Double.isNaN(yPeriod)){

        // build the new one that spans over the requested area
        // NOTE:
        final DirectPosition2D LLC = new DirectPosition2D(crs, envelope.x,
            envelope.y);
        LLC.setCoordinateReferenceSystem(crs);
        final DirectPosition2D URC = new DirectPosition2D(crs, envelope.x
            + xPeriod, envelope.y + yPeriod);
        URC.setCoordinateReferenceSystem(crs);
        final Envelope2D shrinkedEnvelope = new Envelope2D(LLC, URC);
 
        // transform back into raster space
        final Rectangle2D transformedEnv = CRS.transform(
            worldToGridTransform, shrinkedEnvelope).toRectangle2D();
 
View Full Code Here

    public void testGoogleWorld() throws Exception {
        File world = TestData.copy(this, "geotiff/world.tiff");
        RenderedImage image = ImageIO.read(world);
       
        final CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true);
        Envelope2D envelope = new Envelope2D(wgs84, -180, -90, 360, 180);
        GridCoverage2D gcFullWorld = new GridCoverageFactory().create("world", image, envelope);

        // crop, we cannot reproject it fully to the google projection
        final Envelope2D cropEnvelope = new Envelope2D(wgs84, -180, -80, 360, 160);
        GridCoverage2D gcCropWorld = (GridCoverage2D) Operations.DEFAULT.crop(gcFullWorld, cropEnvelope);
       
        // resample
        Hints.putSystemDefault(Hints.RESAMPLE_TOLERANCE, 0d);
        GridCoverage2D gcResampled = (GridCoverage2D) Operations.DEFAULT.resample(gcCropWorld, CRS.decode("EPSG:3857"),
View Full Code Here

    public void testWarpCompareGoogleWorld() throws Exception {
        File world = TestData.copy(this, "geotiff/world.tiff");
        RenderedImage image = ImageIO.read(world);
       
        final CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true);
        Envelope2D envelope = new Envelope2D(wgs84, -180, -90, 360, 180);
        GridCoverage2D gcFullWorld = new GridCoverageFactory().create("world", image, envelope);

        // crop, we cannot reproject it fully to the google projection
        final Envelope2D cropEnvelope = new Envelope2D(wgs84, -180, -80, 360, 160);
        GridCoverage2D gcCropWorld = (GridCoverage2D) Operations.DEFAULT.crop(gcFullWorld, cropEnvelope);
       
        // resample with approximation
        Hints.putSystemDefault(Hints.RESAMPLE_TOLERANCE, 0.333d);
        GridCoverage2D gcResampledApprox = (GridCoverage2D) Operations.DEFAULT.resample(gcCropWorld, CRS.decode("EPSG:3857"),
View Full Code Here

        g.dispose();
       
        // build a coverage around it
        CoordinateReferenceSystem wgs84LatLon = CRS.decode("EPSG:4326");
        final GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
        GridCoverage2D coverage = factory.create("translated", ti, new Envelope2D(wgs84LatLon, 3, 5, 6, 8));
       
        // verify we're good
        int[] pixel = new int[3];
        coverage.evaluate((DirectPosition) new DirectPosition2D(4, 6), pixel);
        assertEquals(0, pixel[0]);
        assertEquals(255, pixel[1]);
        assertEquals(0, pixel[2]);
       
        // now reproject flipping the axis
        CoordinateReferenceSystem wgs84LonLat = CRS.decode("EPSG:4326", true);
        GridGeometry gg = new GridGeometry2D(new GridEnvelope2D(-10, -10, 5, 5), (Envelope) new Envelope2D(wgs84LonLat, 5, 3, 8, 6));
        GridCoverage2D flipped = (GridCoverage2D) Operations.DEFAULT.resample(coverage, wgs84LonLat, 
                gg, Interpolation.getInstance(Interpolation.INTERP_NEAREST));

        // before the fix the pixel would have been black
        flipped.evaluate((DirectPosition) new DirectPosition2D(6, 4), pixel);
View Full Code Here

        double newScale = scale / zoom;

        DirectPosition2D corner = new DirectPosition2D(mapPos.getX() - 0.5d * paneArea.width / newScale, mapPos.getY() + 0.5d
                * paneArea.height / newScale);

        Envelope2D newMapArea = new Envelope2D();
        newMapArea.setFrameFromCenter(mapPos, corner);
        getMapPane().setDisplayArea(newMapArea);
    }
View Full Code Here

        if ( ! isTriggerMouseButton(ev)) {
            return;
        }

        if (dragged) {
            Envelope2D env = new Envelope2D();
            env.setFrameFromDiagonal(startDragPos, ev.getMapPosition());
            dragged = false;
            getMapPane().setDisplayArea(env);
        } else {
            Rectangle paneArea = getMapPane().getVisibleRect();

            double scale = getMapPane().getWorldToScreenTransform().getScaleX();
            double newScale = scale * zoom;

            DirectPosition2D corner = new DirectPosition2D(startDragPos.getX() - 0.5d * paneArea.width / newScale,
                    startDragPos.getY() + 0.5d * paneArea.height / newScale);

            Envelope2D newMapArea = new Envelope2D();
            newMapArea.setFrameFromCenter(startDragPos, corner);
            getMapPane().setDisplayArea(newMapArea);
        }

    }
View Full Code Here

        param.parameter(Mosaic.POLICY).setValue("coarse");
        // Mosaic
        GridCoverage2D mosaic = (GridCoverage2D) processor.doOperation(param);

        // Check that the final GridCoverage BoundingBox is equal to the union of the separate coverages bounding box
        Envelope2D expected = coverage1.getEnvelope2D();
        expected.include(resampled.getEnvelope2D());
        // Mosaic Envelope
        Envelope2D actual = mosaic.getEnvelope2D();

        // Check the same Bounding Box
        assertEqualBBOX(expected, actual);

        // Check that the final Coverage resolution is equal to that of the first coverage
        double initialRes = calculateResolution(coverage1);
        double finalRes = calculateResolution(mosaic);
        double percentual = Math.abs(initialRes - finalRes) / initialRes;
        Assert.assertTrue(percentual < TOLERANCE);

        // Check that on the center of the image there are nodata
        DirectPosition point = new DirectPosition2D(mosaic.getCoordinateReferenceSystem(),
                actual.getCenterX(), actual.getCenterY());
        double nodata = CoverageUtilities.getBackgroundValues(coverage1)[0];
        double result = ((int[]) mosaic.evaluate(point))[0];
        Assert.assertEquals(nodata, result, TOLERANCE);

        // Check that on the Upper Left border pixel there is valid data
        point = new DirectPosition2D(mosaic.getCoordinateReferenceSystem(), actual.getMinX()
                + finalRes, actual.getMinY() + finalRes);
        result = ((int[]) mosaic.evaluate(point))[0];
        Assert.assertNotEquals(nodata, result, TOLERANCE);

        // Coverage and RenderedImage disposal
        mosaic.dispose(true);
View Full Code Here

TOP

Related Classes of org.geotools.geometry.Envelope2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.