Examples of GeneralEnvelope


Examples of org.geotools.geometry.GeneralEnvelope

        if("urn:ogc:def:crs:OGC:1.3:CRS84".equals(bbox.getCrs()))
            bbox.setCrs("EPSG:4326");
       
        CoordinateReferenceSystem bboxCRs = CRS.decode(bbox.getCrs());
        Envelope gridEnvelope = meta.getGridCoverage(null, HINTS).getEnvelope();
        GeneralEnvelope gridEnvelopeBboxCRS = null;
        if (bboxCRs instanceof GeographicCRS) {
            try {
                CoordinateOperationFactory cof = CRS.getCoordinateOperationFactory(true);

                final CoordinateOperation operation = cof.createOperation(gridEnvelope
                        .getCoordinateReferenceSystem(), bboxCRs);
                gridEnvelopeBboxCRS = CRS.transform(operation, gridEnvelope);
            } catch (Exception e) {
                // this may happen, there is nothing we can do about it, we just
                // use the back transformed envelope to be more lenient about
                // which coordinate coorections to make on the longitude axis
                // should the antimeridian style be used
            }
        }

        // check the coordinates, but make sure the case 175,-175 is handled
        // as valid for the longitude axis in a geographic coordinate system
        // see section 7.6.2 of the WCS 1.1.1 spec)
        List<Double> lower = bbox.getLowerCorner();
        List<Double> upper = bbox.getUpperCorner();
        for (int i = 0; i < lower.size(); i++) {
            if (lower.get(i) > upper.get(i)) {
                final CoordinateSystemAxis axis = bboxCRs.getCoordinateSystem().getAxis(i);
                // see if the coordinates can be fixed
                if (bboxCRs instanceof GeographicCRS && axis.getDirection() == AxisDirection.EAST) {

                    if (gridEnvelopeBboxCRS != null) {
                        // try to guess which one needs to be fixed
                        final double envMax = gridEnvelopeBboxCRS.getMaximum(i);
                        if (envMax >= lower.get(i))
                            upper.set(i, upper.get(i) + (axis.getMaximumValue() - axis.getMinimumValue()));
                        else
                            lower.set(i, lower.get(i) - (axis.getMaximumValue() - axis.getMinimumValue()));
                           
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

            (Double) envelope.get( "y1" ), (Double) envelope.get( "y2" ),
            crs
        );
        coverage.setNativeBoundingBox(bounds);
       
        GeneralEnvelope boundsLatLon =
            CoverageStoreUtils.getWGS84LonLatEnvelope(new GeneralEnvelope( bounds ) );
        coverage.setLatLonBoundingBox(new ReferencedEnvelope( boundsLatLon ) );
       
        GeneralEnvelope gridEnvelope = new GeneralEnvelope( bounds );
        Map grid = cInfoReader.grid();
        if ( grid != null ) {
            int[] low = (int[]) grid.get( "low" );
            int[] high = (int[]) grid.get( "high" );
           
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

        if(nativeCRS == null) {
            cinfo.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
        }
       
       
        GeneralEnvelope envelope = reader.getOriginalEnvelope();
        cinfo.setNativeBoundingBox( new ReferencedEnvelope( envelope ) );
        cinfo.setLatLonBoundingBox( new ReferencedEnvelope(CoverageStoreUtils.getWGS84LonLatEnvelope(envelope)) );
       
        GridEnvelope originalRange=reader.getOriginalGridRange();
        cinfo.setGrid(new GridGeometry2D(originalRange,reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER),nativeCRS));

        ///////////////////////////////////////////////////////////////////////
        //
        // Now reading a fake small GridCoverage just to retrieve meta
                // information about bands:
        //
        // - calculating a new envelope which is 1/20 of the original one
        // - reading the GridCoverage subset
        //
        ///////////////////////////////////////////////////////////////////////
        Format format = csinfo.getFormat();
        final GridCoverage2D gc;

       
        final ParameterValueGroup readParams = format.getReadParameters();
        final Map parameters = CoverageUtils.getParametersKVP(readParams);
        final int minX=originalRange.getLow(0);
        final int minY=originalRange.getLow(1);
        final int width=originalRange.getSpan(0);
        final int height=originalRange.getSpan(1);
        final int maxX=minX+(width<=5?width:5);
        final int maxY=minY+(height<=5?height:5);
       
        //we have to be sure that we are working against a valid grid range.
        final GridEnvelope2D testRange= new GridEnvelope2D(minX,minY,maxX,maxY);
       
        //build the corresponding envelope
        final MathTransform gridToWorldCorner =  reader.getOriginalGridToWorld(PixelInCell.CELL_CORNER);
        final GeneralEnvelope testEnvelope =CRS.transform(gridToWorldCorner,new GeneralEnvelope(testRange.getBounds()));
        testEnvelope.setCoordinateReferenceSystem(nativeCRS);
       
        parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
            new GridGeometry2D(testRange, testEnvelope));

        //try to read this coverage
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

            styleName = "raster";
        writer.write("<styles default=\"" + styleName + "\"/>\n");
       
        // envelope
        CoordinateReferenceSystem crs = reader.getCrs();
        GeneralEnvelope envelope = reader.getOriginalEnvelope();
        GeneralEnvelope wgs84envelope = CoverageStoreUtils.getWGS84LonLatEnvelope(envelope);
        final String nativeCrsName = CRS.lookupIdentifier(crs, false);
        writer.write("<envelope crs=\"" + crs.toString().replaceAll("\"", "'") + "\" srsName=\"" + nativeCrsName + "\">\n");
        writer.write("<pos>" + wgs84envelope.getMinimum(0) + " " + wgs84envelope.getMinimum(1) + "</pos>\n");
        writer.write("<pos>" + wgs84envelope.getMaximum(0) + " " + wgs84envelope.getMaximum(1) + "</pos>\n");
        writer.write("</envelope>\n");
       
        /**
         * Now reading a fake small GridCoverage just to retrieve meta information:
         * - calculating a new envelope which is 1/20 of the original one
         * - reading the GridCoverage subset
         */

        final ParameterValueGroup readParams = reader.getFormat().getReadParameters();
        final Map parameters = CoverageUtils.getParametersKVP(readParams);
        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(CoverageUtils.getParameters(readParams, parameters,
                    true));
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

            String description = serviceInfo.getDescription();
            URI schema = serviceInfo.getSchema();
            String[] keywords = serviceInfo.getKeywords().toArray(
                    new String[serviceInfo.getKeywords().size()]);

            GeneralEnvelope env = reader.getOriginalEnvelope();
            Envelope bounds = new Envelope(env.getMinimum(0), env.getMaximum(0), env.getMinimum(1),
                    env.getMaximum(1));
            CoordinateReferenceSystem crs = reader.getCrs();
            ImageDescriptor icon = null;
            IGeoResourceInfo rasterInfo = new IGeoResourceInfo(title, name, description, schema,
                    bounds, crs, keywords, icon);
            return rasterInfo;
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

            } finally {
                graphics.dispose();
            }

            GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
            GeneralEnvelope gridEnvelope = new GeneralEnvelope(mapProjection);
            gridEnvelope.setEnvelope(gridCoverageOrigin.x, gridCoverageOrigin.y, gridCoverageMaxX, gridCoverageMaxY);
            return factory.create(commonUrl.toString(), coverageImage, gridEnvelope, null, null, null);
        } catch (Exception e) {
            throw ExceptionUtils.getRuntimeException(e);
        }
    }
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

       
        final MapBounds bounds = mapContext.getBounds();
        final ReferencedEnvelope mapEnvelope = bounds.toReferencedEnvelope(mapContext.getPaintArea(), mapContext.getDPI());
       
        GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);
        GeneralEnvelope gridEnvelope = new GeneralEnvelope(mapEnvelope.getCoordinateReferenceSystem());
        gridEnvelope.setEnvelope(mapEnvelope.getMinX(), mapEnvelope.getMinY(), mapEnvelope.getMaxX(), mapEnvelope.getMaxY());
        final String coverageName = getClass().getSimpleName();
        final GridCoverage2D gridCoverage2D = factory.create(coverageName, image, gridEnvelope, null, null, null);
       
        Style style = this.styleSupplier.load(httpRequestFactory, gridCoverage2D, mapContext);
        return Collections.singletonList(new GridCoverageLayer(gridCoverage2D, style));
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.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

        //
        // ///////////////////////////////////////////////////////////////////
        final GridCoverage2D croppedGridCoverage;

        // intersect the envelopes
        final GeneralEnvelope intersectionEnvelope = new GeneralEnvelope(destinationEnvelopeInSourceCRS);
        intersectionEnvelope.setCoordinateReferenceSystem(sourceCRS);
        intersectionEnvelope.intersect((GeneralEnvelope) sourceEnvelope);

        // dow we have something to show?
        if (intersectionEnvelope.isEmpty()) {
            throw new WcsException("The Intersection is null. Check the requested BBOX!");
        }

        if (!intersectionEnvelope.equals((GeneralEnvelope) sourceEnvelope)) {
            // get the cropped grid geometry
            // final GridGeometry2D cropGridGeometry = getCroppedGridGeometry(
            // intersectionEnvelope, gridCoverage);

            /* Operations.DEFAULT.crop(coverage, intersectionEnvelope) */
            final ParameterValueGroup param = (ParameterValueGroup) cropParams.clone();
            param.parameter("Source").setValue(coverage);
            param.parameter("Envelope").setValue(intersectionEnvelope);
            //param.parameter("ConserveEnvelope").setValue(conserveEnvelope);

            croppedGridCoverage = (GridCoverage2D) cropFactory.doOperation(param, hints);
        } else {
            croppedGridCoverage = (GridCoverage2D) coverage;
        }

        // prefetch to be faster afterwards.
        // This step is important since at this stage we might be loading tiles
        // from disk
        croppedGridCoverage.prefetch(intersectionEnvelope.toRectangle2D());

        return croppedGridCoverage;
    }
View Full Code Here

Examples of org.geotools.geometry.GeneralEnvelope

    public double[] evaluate(DirectPosition point, double[] values)
            throws PointOutsideCoverageException, CannotEvaluateException {

        for (Coverage region : regions) {
            // GeneralEnvelope has a contains method, OpenGIS Envelope does not
            GeneralEnvelope env = ((GeneralEnvelope)region.getEnvelope());
            // avoid incurring exception construction overhead when there are many regions
            if (env.contains(point)) {
                double[] result;
                double x = point.getOrdinate(0);
                double y = point.getOrdinate(1);
                try {
                    result = region.evaluate(point, values);
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.