Examples of GeneralEnvelope


Examples of org.geotools.geometry.GeneralEnvelope

      final MathTransform GCCRSTodeviceCRSTransform = CRS.findMathTransform(cvCRS, targetCRS, true);
      final MathTransform deviceCRSToGCCRSTransform = GCCRSTodeviceCRSTransformdeviceCRSToGCCRSTransform
          .inverse();
 
      com.vividsolutions.jts.geom.Envelope envelope = request.getBbox();
      GeneralEnvelope destinationEnvelope;
      final boolean lonFirst = sourceCRS.getCoordinateSystem().getAxis(0).getDirection().absolute()
                                        .equals(AxisDirection.EAST);
 
      // the envelope we are provided with is lon,lat always
      if (!lonFirst) {
          destinationEnvelope = new GeneralEnvelope(new double[] {
                      envelope.getMinY(), envelope.getMinX()
                  }, new double[] { envelope.getMaxY(), envelope.getMaxX() });
      } else {
          destinationEnvelope = new GeneralEnvelope(new double[] {
                      envelope.getMinX(), envelope.getMinY()
                  }, new double[] { envelope.getMaxX(), envelope.getMaxY() });
      }
 
      destinationEnvelope.setCoordinateReferenceSystem(sourceCRS);
 
      // this is the destination envelope in the coverage crs
      final GeneralEnvelope destinationEnvelopeInSourceCRS = (!deviceCRSToGCCRSTransform
          .isIdentity()) ? CRS.transform(deviceCRSToGCCRSTransform, destinationEnvelope)
                         : new GeneralEnvelope(destinationEnvelope);
      destinationEnvelopeInSourceCRS.setCoordinateReferenceSystem(cvCRS);
 
      /**
       * Reading Coverage on Requested Envelope
      */
      Rectangle destinationSize = null;
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

    public void formatImageOutputStream(RenderedImage image, OutputStream outStream)
        throws WmsException, IOException {
        // crating a grid coverage
        final GridCoverage2D gc = factory.create("geotiff", image,
                new GeneralEnvelope(mapContext.getAreaOfInterest()));

        // tiff
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Writing tiff image ...");
        }
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

                        if (strCoords.length == 4) {
                            for (int iT = 0; iT < 4; iT++) {
                                coords[iT] = Double.parseDouble(strCoords[iT].trim());
                            }

                            value = (org.opengis.geometry.Envelope) new GeneralEnvelope(new double[] {
                                        coords[0], coords[1]
                                    }, new double[] { coords[2], coords[3] });
                        }
                    }
                }
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

                        if (strCoords.length == 4) {
                            for (int iT = 0; iT < 4; iT++) {
                                coords[iT] = Double.parseDouble(strCoords[iT].trim());
                            }

                            value = (org.opengis.geometry.Envelope) new GeneralEnvelope(new double[] {
                                        coords[0], coords[1]
                                    }, new double[] { coords[2], coords[3] });
                        }
                    }
                }
            } else if (key.equalsIgnoreCase(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName()
                                                                                      .toString())) {
                if ((params.get(key) != null) && params.get(key) instanceof String
                        && (((String) params.get(key)).length() > 0)) {
                    String tmp = (String) params.get(key);

                    if ((tmp.indexOf("[") > 0) && (tmp.indexOf("]") > tmp.indexOf("["))) {
                        tmp = tmp.substring(tmp.indexOf("[") + 1, tmp.indexOf("]")).trim();
                        tmp = tmp.replaceAll(",", "");

                        String[] strCoords = tmp.split(" ");
                        double[] coords = new double[strCoords.length];

                        if (strCoords.length == 4) {
                            for (int iT = 0; iT < 4; iT++) {
                                coords[iT] = Double.parseDouble(strCoords[iT].trim());
                            }

                            value = (org.opengis.geometry.Envelope) new GeneralEnvelope(new double[] {
                                        coords[0], coords[1]
                                    }, new double[] { coords[2], coords[3] });
                        }
                    }
                } else if ((params.get(key) != null)
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

         */

        final ParameterValueGroup readParams = reader.getFormat().getReadParameters();
        final Map parameters = getParametersKVP(readParams);

        final GeneralEnvelope envelope = reader.getOriginalEnvelope();
        double[] minCP = envelope.getLowerCorner().getCoordinates();
        double[] maxCP = new double[] {
                minCP[0] + (envelope.getLength(0) / 20.0),
                minCP[1] + (envelope.getLength(1) / 20.0)
            };
        final GeneralEnvelope subEnvelope = new GeneralEnvelope(minCP, maxCP);
        subEnvelope.setCoordinateReferenceSystem(reader.getCrs());

        parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
            new GridGeometry2D(reader.getOriginalGridRange(), subEnvelope));
        GridCoverage2D gc = (GridCoverage2D) reader.read(getParameters(readParams, parameters,
                    true));
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

        //
        // Do we need to transform?
        //
        ////
        if (CRS.equalsIgnoreMetadata(sourceCRS, DefaultGeographicCRS.WGS84)) {
            return new GeneralEnvelope(envelope);
        }

        ////
        //
        //transform
        //
        ////
        final CoordinateReferenceSystem targetCRS = DefaultGeographicCRS.WGS84;
        final MathTransform mathTransform = CRS.findMathTransform(sourceCRS, targetCRS, true);
        final GeneralEnvelope targetEnvelope;

        if (!mathTransform.isIdentity()) {
            targetEnvelope = CRS.transform(mathTransform, envelope);
        } else {
            targetEnvelope = new GeneralEnvelope(envelope);
        }

        targetEnvelope.setCoordinateReferenceSystem(targetCRS);

        return targetEnvelope;
    }
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

        catch (Exception e) {
            throw (IOException) new IOException( "unable to calculate coverage bounds")
                .initCause( e );
        }
       
        GeneralEnvelope envelope = null;
        if (env == null) {
            envelope = new GeneralEnvelope( coverageBounds );
        }
        else {
            envelope = new GeneralEnvelope( env );
        }
   
        // /////////////////////////////////////////////////////////
        //
        // Do we need to proceed?
        // I need to check the requested envelope in order to see if the
        // coverage we ask intersect it otherwise it is pointless to load it
        // since its reader might return null;
        // /////////////////////////////////////////////////////////
        final CoordinateReferenceSystem sourceCRS = envelope.getCoordinateReferenceSystem();
        CoordinateReferenceSystem destCRS;
        try {
            destCRS = info.getCRS();
        }
        catch (Exception e) {
      final IOException ioe= new IOException( "unable to determine coverage crs");
      ioe.initCause(e);
      throw ioe;
        }
       
        if (!CRS.equalsIgnoreMetadata(sourceCRS, destCRS)) {
            // get a math transform
            MathTransform transform;
      try {
        transform = CRS.findMathTransform(sourceCRS, destCRS,true);
      } catch (FactoryException e) {
        final IOException ioe= new IOException( "unable to determine coverage crs");
        ioe.initCause(e);
        throw ioe;
      }
       
            // transform the envelope
            if (!transform.isIdentity()) {
                try {
                    envelope = CRS.transform(transform, envelope);
                }
                catch (TransformException e) {
                    throw (IOException) new IOException( "error occured transforming envelope").initCause( e );
                }
            }
        }
       
        // just do the intersection since
        envelope.intersect(coverageBounds);
       
        if (envelope.isEmpty()) {
            return null;
        }
       
        envelope.setCoordinateReferenceSystem(destCRS);
       
        // /////////////////////////////////////////////////////////
        //
        // get a reader
        //
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

        final MathTransform GCCRSTodeviceCRSTransform = CRS.findMathTransform(cvCRS, targetCRS, true);
        final MathTransform deviceCRSToGCCRSTransform = GCCRSTodeviceCRSTransformdeviceCRSToGCCRSTransform
            .inverse();

        com.vividsolutions.jts.geom.Envelope envelope = request.getEnvelope();
        GeneralEnvelope destinationEnvelope;
        final boolean lonFirst = sourceCRS.getCoordinateSystem().getAxis(0).getDirection().absolute()
                                          .equals(AxisDirection.EAST);

        // the envelope we are provided with is lon,lat always
        if (!lonFirst) {
            destinationEnvelope = new GeneralEnvelope(new double[] {
                        envelope.getMinY(), envelope.getMinX()
                    }, new double[] { envelope.getMaxY(), envelope.getMaxX() });
        } else {
            destinationEnvelope = new GeneralEnvelope(new double[] {
                        envelope.getMinX(), envelope.getMinY()
                    }, new double[] { envelope.getMaxX(), envelope.getMaxY() });
        }

        destinationEnvelope.setCoordinateReferenceSystem(sourceCRS);

        // this is the destination envelope in the coverage crs
        final GeneralEnvelope destinationEnvelopeInSourceCRS = (!deviceCRSToGCCRSTransform
            .isIdentity()) ? CRS.transform(deviceCRSToGCCRSTransform, destinationEnvelope)
                           : new GeneralEnvelope(destinationEnvelope);
        destinationEnvelopeInSourceCRS.setCoordinateReferenceSystem(cvCRS);

        /**
         * Reading Coverage on Requested Envelope
         */
        Rectangle destinationSize = null;
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

                                            !fquery.getSrsName().toString().equals( filter.getSRS() ) ) {
                                       
                                        //back project bounding box into geographic coordinates
                                        CoordinateReferenceSystem geo = DefaultGeographicCRS.WGS84;
                                       
                                        GeneralEnvelope e = new GeneralEnvelope(
                                            new double[] { filter.getMinX(), filter.getMinY()},
                                            new double[] { filter.getMaxX(), filter.getMaxY()}
                                        );
                                        CoordinateReferenceSystem crs = null;
                                        try {
                                            crs = CRS.decode( filter.getSRS() );
                                            e = CRS.transform(CRS.findMathTransform(crs, geo, true), e);
                                        }
                                        catch( Exception ex ) {
                                            throw new WFSException( ex );
                                        }
                                       
                                        //ensure within bounds defined by srs specified on
                                        // query
                                        try {
                                            crs = CRS.decode( fquery.getSrsName().toString() );
                                        }
                                        catch( Exception ex ) {
                                            throw new WFSException( ex );
                                        }
                                       
                                        GeographicBoundingBox valid =
                                            (GeographicBoundingBox) crs.getDomainOfValidity()
                                            .getGeographicElements().iterator().next();
                                       
                                        if ( e.getMinimum(0) < valid.getWestBoundLongitude() ||
                                            e.getMinimum(0) > valid.getEastBoundLongitude() ||
                                            e.getMaximum(0) < valid.getWestBoundLongitude() ||
                                            e.getMaximum(0) > valid.getEastBoundLongitude() ||
                                            e.getMinimum(1) < valid.getSouthBoundLatitude() ||
                                            e.getMinimum(1) > valid.getNorthBoundLatitude() ||
                                            e.getMaximum(1) < valid.getSouthBoundLatitude() ||
                                            e.getMaximum(1) > valid.getNorthBoundLatitude() ) {
                                               
                                            throw new WFSException( "bounding box out of valid range of crs", "InvalidParameterValue");
                                        }
                                    }
                                   
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

            final AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) meta
                    .getGridCoverageReader(null, HINTS);
            final ParameterValueGroup params = reader.getFormat().getReadParameters();

            // handle spatial domain subset, if needed
            final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope();
            final BoundingBoxType bbox = request.getDomainSubset().getBoundingBox();
            final CoordinateReferenceSystem nativeCRS = originalEnvelope
                    .getCoordinateReferenceSystem();
            final GeneralEnvelope destinationEnvelopeInSourceCRS;
            final GeneralEnvelope destinationEnvelope;
            if (bbox != null) {
                // first off, parse the envelope corners
                double[] lowerCorner = new double[bbox.getLowerCorner().size()];
                double[] upperCorner = new double[bbox.getUpperCorner().size()];
                for (int i = 0; i < lowerCorner.length; i++) {
                    lowerCorner[i] = (Double) bbox.getLowerCorner().get(i);
                    upperCorner[i] = (Double) bbox.getUpperCorner().get(i);
                }
                destinationEnvelope = new GeneralEnvelope(lowerCorner, upperCorner);
                // grab the native crs
                // if no crs has beens specified, the native one is assumed
                if (bbox.getCrs() == null) {
                    destinationEnvelope.setCoordinateReferenceSystem(nativeCRS);
                    destinationEnvelopeInSourceCRS = destinationEnvelope;
                } else {
                    // otherwise we need to transform
                    final CoordinateReferenceSystem bboxCRS = CRS.decode(bbox.getCrs());
                    destinationEnvelope.setCoordinateReferenceSystem(bboxCRS);
                    final MathTransform bboxToNativeTx = CRS.findMathTransform(bboxCRS, nativeCRS,
                            true);
                    destinationEnvelopeInSourceCRS = CRS.transform(bboxToNativeTx,
                            destinationEnvelope);
                    destinationEnvelopeInSourceCRS.setCoordinateReferenceSystem(nativeCRS);
                }
            } else {
                destinationEnvelopeInSourceCRS = reader.getOriginalEnvelope();
                destinationEnvelope = destinationEnvelopeInSourceCRS;
            }

            final GridCrsType gridCRS = request.getOutput().getGridCRS();
            // TODO: handle time domain subset...

            // Compute the target crs, the crs that the final coverage will be
            // served into
            final CoordinateReferenceSystem targetCRS;
            if (gridCRS == null)
                targetCRS = reader.getOriginalEnvelope().getCoordinateReferenceSystem();
            else
                targetCRS = CRS.decode(gridCRS.getGridBaseCRS());

            // grab the grid to world transformation
            MathTransform gridToCRS = reader.getOriginalGridToWorld(PixelInCell.CELL_CORNER);
            if (gridCRS != null) {
                Double[] origin = (Double[]) gridCRS.getGridOrigin();
                Double[] offsets = (Double[]) gridCRS.getGridOffsets();

                // from the specification if grid origin is omitted and the crs
                // is 2d the default it's 0,0
                if (origin == null) {
                    origin = new Double[] { 0.0, 0.0 };
                }

                // if no offsets has been specified we try to default on the
                // native ones
                if (offsets == null) {
                    if (!(gridToCRS instanceof AffineTransform2D)
                            && !(gridToCRS instanceof IdentityTransform))
                        throw new WcsException(
                                "Internal error, the coverage we're playing with does not have an affine transform...");

                    if (gridToCRS instanceof IdentityTransform) {
                        if (gridCRS.getGridType().equals(GridType.GT2dSimpleGrid))
                            offsets = new Double[] { 1.0, 1.0 };
                        else
                            offsets = new Double[] { 1.0, 0.0, 0.0, 1.0 };
                    } else {
                        AffineTransform2D affine = (AffineTransform2D) gridToCRS;
                        if (gridCRS.getGridType().equals(GridType.GT2dSimpleGrid))
                            offsets = new Double[] { affine.getScaleX(), affine.getScaleY() };
                        else
                            offsets = new Double[] { affine.getScaleX(), affine.getShearX(),
                                    affine.getShearY(), affine.getScaleY() };
                    }
                }

                // building the actual transform for the resulting grid geometry
                AffineTransform tx;
                if (gridCRS.getGridType().equals(GridType.GT2dSimpleGrid.getXmlConstant())) {
                    tx = new AffineTransform(offsets[0], 0, 0, offsets[1], origin[0], origin[1]);
                } else {
                    tx = new AffineTransform(offsets[0], offsets[2], offsets[1], offsets[3],
                            origin[0], origin[1]);
                }
                gridToCRS = new AffineTransform2D(tx);
            }

            // now we have enough info to read the coverage, grab the parameters
            // and add the grid geometry info
            final Map parameters = CoverageUtils.getParametersKVP(reader.getFormat()
                    .getReadParameters());
            final GeneralEnvelope intersected = new GeneralEnvelope(destinationEnvelopeInSourceCRS);
            intersected.intersect(originalEnvelope);
            final GridGeometry2D destinationGridGeometry =new GridGeometry2D(PixelInCell.CELL_CENTER, gridToCRS, intersected, null);
            parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
                    destinationGridGeometry);
            coverage = (GridCoverage2D) reader.read(CoverageUtils.getParameters(reader.getFormat()
                    .getReadParameters(), parameters, true));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.