Package org.geotools.geometry

Examples of org.geotools.geometry.GeneralEnvelope


      LOGGER.info(new StringBuilder("Coverage before: ").append("\n")
          .append(gc.getCoordinateReferenceSystem().toWKT()).append(
              gc.getEnvelope().toString()).toString());
    }
    final CoordinateReferenceSystem sourceCRS = gc.getCoordinateReferenceSystem2D();
    final GeneralEnvelope sourceEnvelope = (GeneralEnvelope) gc.getEnvelope();
    final GridGeometry2D sourcedGG = (GridGeometry2D) gc.getGridGeometry();
    final MathTransform sourceG2W = sourcedGG.getGridToCRS(PixelInCell.CELL_CENTER);

    // /////////////////////////////////////////////////////////////////////
    //
    //
    // CROP
    //
    //
    // /////////////////////////////////////////////////////////////////////

    // /////////////////////////////////////////////////////////////////////
    //
    // Crop the original coverage.
    //
    // /////////////////////////////////////////////////////////////////////
    double xc = sourceEnvelope.getMedian(0);
    double yc = sourceEnvelope.getMedian(1);
    double xl = sourceEnvelope.getSpan(0);
    double yl = sourceEnvelope.getSpan(1);
    final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] {
        xc - xl / 4.0, yc - yl / 4.0 }, new double[] { xc + xl / 4.0,
        yc + yl / 4.0 });
    final CoverageProcessor processor = CoverageProcessor.getInstance();
    final ParameterValueGroup param = processor
        .getOperation("CoverageCrop").getParameters();
    param.parameter("Source").setValue(gc);
    param.parameter("Envelope").setValue(cropEnvelope);
    final GridCoverage2D cropped = (GridCoverage2D) processor.doOperation(param);

    // /////////////////////////////////////////////////////////////////////
    //
    // Check that we got everything correctly after the crop.
    //
    // /////////////////////////////////////////////////////////////////////
    // checking the ranges of the output image.
    final GridGeometry2D croppedGG = (GridGeometry2D) cropped.getGridGeometry();
    final GridEnvelope croppedGR = croppedGG.getGridRange();
    final MathTransform croppedG2W = croppedGG.getGridToCRS(PixelInCell.CELL_CENTER);
    final GeneralEnvelope croppedEnvelope = (GeneralEnvelope) cropped.getEnvelope();
    assertTrue("min x do not match after crop", 29 == croppedGR.getLow(0));
    assertTrue("min y do not match after crop", 30 == croppedGR.getLow(1));
    assertTrue("max x do not match after crop", 90 == croppedGR.getHigh(0)+1);
    assertTrue("max y do not match after crop", 91 == croppedGR.getHigh(1)+1);
    // check that the affine transform are the same thing
    assertTrue(
        "The Grdi2World tranformations of the original and the cropped covearage do not match",
        sourceG2W.equals(croppedG2W));
    // check that the envelope is correct
    final GeneralEnvelope expectedEnvelope = new GeneralEnvelope(croppedGR,PixelInCell.CELL_CENTER, croppedG2W, cropped.getCoordinateReferenceSystem2D());
    assertTrue("Expected envelope is different from the computed one",expectedEnvelope.equals(croppedEnvelope, XAffineTransform.getScale((AffineTransform) croppedG2W) / 2.0, false));

    //release things
    cropped.dispose(true);
    gc.dispose(true);
    try{
View Full Code Here


        value.setValue(true);
       
        // switching axes
        final CoordinateReferenceSystem latLon4267=CRS.decode("EPSG:4267");
        assertEquals(CRS.getAxisOrder(latLon4267), AxisOrder.NORTH_EAST);
        final GeneralEnvelope envelope = (GeneralEnvelope) CRS.transform(coverage.getEnvelope(), latLon4267);
        envelope.setCoordinateReferenceSystem(latLon4267);
       
        coverage=CoverageFactoryFinder.getGridCoverageFactory(GeoTools.getDefaultHints()).create(
                coverage.getName(),
                coverage.getRenderedImage(),
                envelope
View Full Code Here

     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
            throws Exception {
        GeneralEnvelope envelope = (GeneralEnvelope) value;

        List<Node> timePositions = (List<Node>) node.getChildren("timePosition");

        if (timePositions != null && !timePositions.isEmpty()) {
            final Map<String, Object> properties = new HashMap<String, Object>(
                    4);
            properties.put(CoordinateReferenceSystem.NAME_KEY, "WGS84");
            properties.put(CoordinateReferenceSystem.DOMAIN_OF_VALIDITY_KEY, ExtentImpl.WORLD);

            CoordinateReferenceSystem crs = new DefaultCompoundCRS(properties,
                    new CoordinateReferenceSystem[] {envelope.getCoordinateReferenceSystem(), DefaultTemporalCRS.TRUNCATED_JULIAN });

            double[] minCP = new double[envelope.getDimension() + 1];
            double[] maxCP = new double[envelope.getDimension() + 1];

            for (int i = 0; i < envelope.getDimension(); i++) {
                minCP[i] = envelope.getLowerCorner().getOrdinate(i);
                maxCP[i] = envelope.getUpperCorner().getOrdinate(i);
            }

            DefaultTemporalCRS TCRS = (DefaultTemporalCRS) ((CompoundCRS) crs).getCoordinateReferenceSystems().get(1);

            Node timePositionNodeBegin = timePositions.get(0);
            Node timePositionNodeEnd = timePositions.get(1);
            minCP[minCP.length - 1] = TCRS.toValue(((DefaultPosition)timePositionNodeBegin.getValue()).getDate());
            maxCP[maxCP.length - 1] = TCRS.toValue(((DefaultPosition)timePositionNodeEnd.getValue()).getDate());

            GeneralDirectPosition minDP = new GeneralDirectPosition(minCP);
            minDP.setCoordinateReferenceSystem(crs);
            GeneralDirectPosition maxDP = new GeneralDirectPosition(maxCP);
            maxDP.setCoordinateReferenceSystem(crs);

            GeneralEnvelope envelopeWithTime = new GeneralEnvelope(minDP, maxDP);

            return envelopeWithTime;
        }

        return envelope;
View Full Code Here

     * <!-- end-user-doc -->
     */
    @Override
    public Element encode(Object object, Document document, Element value)
            throws Exception {
        GeneralEnvelope envelope = (GeneralEnvelope) object;

        if (envelope == null) {
            value.appendChild(document.createElementNS(GML.NAMESPACE, GML.Null.getLocalPart()));
        }

View Full Code Here

        return null;
    }

    public Object getProperty(Object object, QName name) {
        GeneralEnvelope envelope = (GeneralEnvelope) object;

        if (envelope == null) {
            return null;
        }

        if (name.getLocalPart().equals("timePosition")) {
            CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();

            TemporalCRS temporalCRS = null;

            if (crs instanceof CompoundCRS) {
                List CRSs = ((DefaultCompoundCRS) crs).getCoordinateReferenceSystems();

                for (Object item : CRSs) {
                    if (item instanceof TemporalCRS) {
                        temporalCRS = (TemporalCRS) item;
                    }
                }
            }

            if (temporalCRS != null) {
                List<Position> envelopePositions = new LinkedList<Position>();

                Position beginning = new DefaultPosition(((DefaultTemporalCRS) temporalCRS).toDate(envelope.getLowerCorner().getOrdinate(envelope.getDimension() - 1)));
                Position ending = new DefaultPosition(((DefaultTemporalCRS) temporalCRS).toDate(envelope.getUpperCorner().getOrdinate(envelope.getDimension() - 1)));

                envelopePositions.add(beginning);
                envelopePositions.add(ending);

                return envelopePositions;
View Full Code Here

                assertEquals(CoverageUtilities.UCUM.ELEVATION_UNITS.getSymbol(), descriptor.getUnitSymbol());

                // subsetting the envelope
                final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D
                        .createValue();
                final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
                final GeneralEnvelope reducedEnvelope = new GeneralEnvelope(new double[] {
                        originalEnvelope.getLowerCorner().getOrdinate(0),
                        originalEnvelope.getLowerCorner().getOrdinate(1) }, new double[] {
                        originalEnvelope.getMedian().getOrdinate(0),
                        originalEnvelope.getMedian().getOrdinate(1) });
                reducedEnvelope.setCoordinateReferenceSystem(reader
                        .getCoordinateReferenceSystem(coverageName));

                // Selecting bigger gridRange for a zoomed result
                final Dimension dim = new Dimension();
                GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
View Full Code Here

                assertEquals("450.0", reader.getMetadataValue(coverageName, "ELEVATION_DOMAIN_MAXIMUM"));

                // subsetting the envelope
                final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D
                        .createValue();
                final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
                final GeneralEnvelope reducedEnvelope = new GeneralEnvelope(new double[] {
                        originalEnvelope.getLowerCorner().getOrdinate(0),
                        originalEnvelope.getLowerCorner().getOrdinate(1) }, new double[] {
                        originalEnvelope.getMedian().getOrdinate(0),
                        originalEnvelope.getMedian().getOrdinate(1) });
                reducedEnvelope.setCoordinateReferenceSystem(reader
                        .getCoordinateReferenceSystem(coverageName));

                // Selecting bigger gridRange for a zoomed result
                final Dimension dim = new Dimension();
                GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
View Full Code Here

                }

                // subsetting the envelope
                final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D
                        .createValue();
                final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
                final GeneralEnvelope reducedEnvelope = new GeneralEnvelope(new double[] {
                        originalEnvelope.getLowerCorner().getOrdinate(0),
                        originalEnvelope.getLowerCorner().getOrdinate(1) }, new double[] {
                        originalEnvelope.getMedian().getOrdinate(0),
                        originalEnvelope.getMedian().getOrdinate(1) });
                reducedEnvelope.setCoordinateReferenceSystem(reader
                        .getCoordinateReferenceSystem(coverageName));

                // Selecting bigger gridRange for a zoomed result
                final Dimension dim = new Dimension();
                GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
View Full Code Here

                }

                // subsetting the envelope
                final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D
                        .createValue();
                final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
                final GeneralEnvelope reducedEnvelope = new GeneralEnvelope(new double[] {
                        originalEnvelope.getLowerCorner().getOrdinate(0),
                        originalEnvelope.getLowerCorner().getOrdinate(1) }, new double[] {
                        originalEnvelope.getMedian().getOrdinate(0),
                        originalEnvelope.getMedian().getOrdinate(1) });
                reducedEnvelope.setCoordinateReferenceSystem(reader
                        .getCoordinateReferenceSystem(coverageName));

                // Selecting bigger gridRange for a zoomed result
                final Dimension dim = new Dimension();
                GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
View Full Code Here

              assertEquals(3, sigmaMetadata.split(",").length);

              // subsetting the envelope
              final ParameterValue<GridGeometry2D> gg = AbstractGridFormat.READ_GRIDGEOMETRY2D
                      .createValue();
              final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(coverageName);
              final GeneralEnvelope reducedEnvelope = new GeneralEnvelope(new double[] {
                      originalEnvelope.getLowerCorner().getOrdinate(0),
                      originalEnvelope.getLowerCorner().getOrdinate(1) }, new double[] {
                      originalEnvelope.getMedian().getOrdinate(0),
                      originalEnvelope.getMedian().getOrdinate(1) });
              reducedEnvelope.setCoordinateReferenceSystem(reader
                      .getCoordinateReferenceSystem(coverageName));

              // Selecting bigger gridRange for a zoomed result
              final Dimension dim = new Dimension();
              GridEnvelope gridRange = reader.getOriginalGridRange(coverageName);
View Full Code Here

TOP

Related Classes of org.geotools.geometry.GeneralEnvelope

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.