Package org.geotools.geometry

Examples of org.geotools.geometry.Envelope2D


    // We take the crop envelope and the source envelope then we check their
    // crs and we also check if they ever overlap.
    //
    // /////////////////////////////////////////////////////////////////////
    // envelope of the source coverage
    final Envelope2D sourceEnvelope = source.getEnvelope2D();
    // crop envelope
    Envelope2D destinationEnvelope = new Envelope2D(cropEnvelope);
    CoordinateReferenceSystem sourceCRS = sourceEnvelope.getCoordinateReferenceSystem();
    CoordinateReferenceSystem destinationCRS = destinationEnvelope.getCoordinateReferenceSystem();
    if (destinationCRS == null) {
      // Do not change the user provided object - clone it first.
      final Envelope2D ge = new Envelope2D(destinationEnvelope);
      destinationCRS = source.getCoordinateReferenceSystem2D();
      ge.setCoordinateReferenceSystem(destinationCRS);
      destinationEnvelope = ge;
    }

    // //
    //
View Full Code Here


                // replace the cropEnvelope with the envelope of the intersection
                // of the ROI and the cropEnvelope.
                // Remember that envelope(intersection(roi,cropEnvelope)) != intersection(cropEnvelope, envelope(roi))
                final Polygon modelSpaceROI = FeatureUtilities.getPolygon(cropEnvelope, GFACTORY);
                Geometry intersection =  IntersectUtils.intersection(cropROI, modelSpaceROI);
                Envelope2D e2d = JTS.getEnvelope2D(intersection.getEnvelopeInternal(), cropEnvelope.getCoordinateReferenceSystem());
                GeneralEnvelope ge = new GeneralEnvelope((org.opengis.geometry.Envelope)e2d);
                cropEnvelope.setEnvelope(ge);
            }

      // //
View Full Code Here

        DirectPosition2D corner = new DirectPosition2D(
                mapPos.getX() - 0.5d * paneArea.getWidth() / newScale,
                mapPos.getY() + 0.5d * paneArea.getHeight() / newScale);
       
        Envelope2D newMapArea = new Envelope2D();
        newMapArea.setFrameFromCenter(mapPos, corner);
        getMapPane().setDisplayArea(newMapArea);
    }
View Full Code Here

        DirectPosition2D corner = new DirectPosition2D(
                mapPos.getX() - 0.5d * paneArea.getWidth() / newScale,
                mapPos.getY() + 0.5d * paneArea.getHeight() / newScale);
       
        Envelope2D newMapArea = new Envelope2D();
        newMapArea.setFrameFromCenter(mapPos, corner);
        getMapPane().setDisplayArea(newMapArea);
    }
View Full Code Here

     * @param ev the mouse event
     */
    @Override
    public void onMouseReleased(MapMouseEvent ev) {
        if (dragged && !ev.getPoint().equals(startPosDevice)) {
            Envelope2D env = new Envelope2D();
            env.setFrameFromDiagonal(startPosWorld, ev.getWorldPos());
            dragged = false;
            getMapPane().setDisplayArea(env);
        }
    }
View Full Code Here

        }, new double[] {
                oldEnvelope.getMinimum(0) + oldEnvelope.getSpan(0) * 5 / 8,
                oldEnvelope.getMinimum(1) + oldEnvelope.getSpan(1) * 5 / 8
        });
        cropEnvelope.setCoordinateReferenceSystem(oldEnvelope.getCoordinateReferenceSystem());
        Envelope2D env2D = new Envelope2D(cropEnvelope);
       
        /*
         * Do the crop without conserving the envelope.
         */
        ParameterValueGroup param = processor.getOperation("CoverageCrop").getParameters();
View Full Code Here

   
    @Test
    public void testWorldToGridPoint() throws Exception {
        GridGeometry2D gg = getRandomCoverage().getGridGeometry();

        Envelope2D worldBounds = gg.getEnvelope2D();
        GridEnvelope2D gridBounds = gg.getGridRange2D();
        GridCoordinates2D gridExp = new GridCoordinates2D();

        DirectPosition worldPoint = worldBounds.getLowerCorner();
        GridCoordinates2D gridCalc = gg.worldToGrid(worldPoint);
        gridExp.setLocation(0, gridBounds.height - 1);
        assertTrue(gridExp.equals(gridCalc));

        worldPoint = worldBounds.getUpperCorner();
        gridCalc = gg.worldToGrid(worldPoint);
        gridExp.setLocation(gridBounds.width - 1, 0);
        assertTrue(gridExp.equals(gridCalc));
    }
View Full Code Here

    @Test
    public void testWorldToGridEnvelope() throws Exception {
        GridGeometry2D gg = getRandomCoverage().getGridGeometry();

        Envelope2D worldBounds = gg.getEnvelope2D();
        GridEnvelope2D gridBounds = gg.getGridRange2D();

        GridEnvelope2D gridEnv = gg.worldToGrid(worldBounds);
        assertTrue(gridBounds.equals(gridEnv));

        // test sub-area conversion by creating an envelope that excludes
        // the first and last grid row and col centres
        double cellWidthX = worldBounds.getWidth() / gridBounds.getWidth();
        double cellWidthY = worldBounds.getHeight() / gridBounds.getHeight();

        Envelope2D subEnv = new Envelope2D(gg.getCoordinateReferenceSystem2D(),
                worldBounds.getMinX() + cellWidthX * 0.6,
                worldBounds.getMinY() + cellWidthY * 0.6,
                worldBounds.getWidth() - cellWidthX * 1.2,
                worldBounds.getHeight() - cellWidthY * 1.2);

 
View Full Code Here

    public void testGridToWorldPoint() throws Exception {
        final double TOL = 1.0E-6;

        GridGeometry2D gg = getRandomCoverage().getGridGeometry();

        Envelope2D worldBounds = gg.getEnvelope2D();
        GridEnvelope2D gridBounds = gg.getGridRange2D();

        double cellWidthX = worldBounds.getWidth() / gridBounds.getWidth();
        double cellWidthY = worldBounds.getHeight() / gridBounds.getHeight();

        GridCoordinates2D low = gridBounds.getLow();
        DirectPosition2D dp = (DirectPosition2D) gg.gridToWorld(low);

        assertTrue(Math.abs(dp.x - (cellWidthX/2) - worldBounds.getMinX()) < TOL);
        assertTrue(Math.abs(dp.y + (cellWidthY/2) - worldBounds.getMaxY()) < TOL);

        GridCoordinates2D high = gridBounds.getHigh();
        dp = (DirectPosition2D) gg.gridToWorld(high);

        assertTrue(Math.abs(dp.x + (cellWidthX/2) - worldBounds.getMaxX()) < TOL);
        assertTrue(Math.abs(dp.y - (cellWidthY/2) - worldBounds.getMinY()) < TOL);
    }
View Full Code Here

    public void testGridToWorldEnvelope() throws Exception {
        final double TOL = 1.0E-6;

        GridGeometry2D gg = getRandomCoverage().getGridGeometry();

        Envelope2D worldBounds = gg.getEnvelope2D();
        GridEnvelope2D gridBounds = gg.getGridRange2D();

        assertTrue(worldBounds.boundsEquals(gg.gridToWorld(gridBounds), 0, 1, TOL));

        // test sub-area conversion
        GridEnvelope2D subGrid = new GridEnvelope2D(
                gridBounds.x + 1,
                gridBounds.y + 1,
                gridBounds.width - 2,
                gridBounds.height - 2);

        Envelope2D subEnv = gg.gridToWorld(subGrid);

        double cellWidthX = worldBounds.getWidth() / gridBounds.getWidth();
        double cellWidthY = worldBounds.getHeight() / gridBounds.getHeight();

        Envelope2D expectedEnv = new Envelope2D(gg.getCoordinateReferenceSystem2D(),
                worldBounds.getMinX() + cellWidthX,
                worldBounds.getMinY() + cellWidthY,
                worldBounds.getWidth() - 2 * cellWidthX,
                worldBounds.getHeight() - 2 * cellWidthY);

        assertTrue( expectedEnv.boundsEquals(subEnv, 0, 1, TOL) );
    }
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.