Package org.geotools.coverage.grid

Examples of org.geotools.coverage.grid.GridCoverage2D


                    try {
                        GridGeometry2D gridGeometry = null;
                        if (geoResource.canResolve(GridGeometry2D.class)) {
                            gridGeometry = geoResource.resolve(GridGeometry2D.class, new NullProgressMonitor());
                        } else if (geoResource.canResolve(GridCoverage.class)) {
                            GridCoverage2D gridCoverage = (GridCoverage2D) geoResource.resolve(GridCoverage.class,
                                    new NullProgressMonitor());
                            gridGeometry = gridCoverage.getGridGeometry();
                        }
                        if (gridGeometry != null)
                            setWidgetsToWindow(OmsBoxUtils.gridGeometry2ProcessingRegion(gridGeometry));

                    } catch (IOException e1) {
View Full Code Here


            JGrassRegion drawMapRegion = new JGrassRegion(minXY.x, maxXY.x, minXY.y, maxXY.y, ewRes, nsRes);
            // JGrassRegion drawMapRegion = new JGrassRegion(drawMapRectangle.getMinX(),
            // drawMapRectangle.getMaxX(), drawMapRectangle.getMinY(), drawMapRectangle
            // .getMaxY(), ewRes, nsRes);
            JGrassMapEnvironment grassMapEnvironment = grassMapGeoResource.getjGrassMapEnvironment();
            GridCoverage2D coverage = JGrassCatalogUtilities.getGridcoverageFromGrassraster(grassMapEnvironment, drawMapRegion);
            coverage = coverage.view(ViewType.RENDERED);
            if (coverage != null) {

                // setting rendering hints
                RenderingHints hints = new RenderingHints(Collections.EMPTY_MAP);
                hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED));
View Full Code Here

                        final Object object = selection.getFirstElement();
                        try {
                            pm.beginTask("Collecting stats...", IProgressMonitor.UNKNOWN);
                            StringBuilder regionString = new StringBuilder();
                            GridCoverage2D geodata = null;
                            if (object instanceof AbstractRasterGeoResource) {
                                AbstractRasterGeoResource rGeo = (AbstractRasterGeoResource) object;
                                AbstractGridCoverage2DReader gridCoverage2DReader = rGeo.resolve(
                                        AbstractGridCoverage2DReader.class, pm);
                                geodata = ((GridCoverage2D) gridCoverage2DReader.read(null));
                                geodata = geodata.view(ViewType.GEOPHYSICS);

                                Envelope envelope = geodata.getEnvelope();
                                DirectPosition lowerCorner = envelope.getLowerCorner();
                                double[] westSouth = lowerCorner.getCoordinate();
                                DirectPosition upperCorner = envelope.getUpperCorner();
                                double[] eastNorth = upperCorner.getCoordinate();
                                GridGeometry2D gridGeometry = geodata.getGridGeometry();
                                GridEnvelope2D gridRange = gridGeometry.getGridRange2D();
                                int rows = gridRange.height;
                                int cols = gridRange.width;

                                AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS();
                                double we_res = XAffineTransform.getScaleX0(gridToCRS);
                                double ns_res = XAffineTransform.getScaleY0(gridToCRS);
                                double north = eastNorth[1];
                                double south = westSouth[1];
                                double east = eastNorth[0];
                                double west = westSouth[0];
                                regionString.append("region:\nwest=");
                                regionString.append(west);
                                regionString.append("\neast=");
                                regionString.append(east);
                                regionString.append("\nsouth=");
                                regionString.append(south);
                                regionString.append("\nnorth=");
                                regionString.append(north);
                                regionString.append("\nwe_res=");
                                regionString.append(we_res);
                                regionString.append("\nns_res=");
                                regionString.append(ns_res);
                                regionString.append("\nrows=");
                                regionString.append(rows);
                                regionString.append("\ncols=");
                                regionString.append(cols);

                            } else if (object instanceof JGrassMapGeoResource) {
                                JGrassMapGeoResource mr = (JGrassMapGeoResource) object;
                                File mapFile = mr.getMapFile();
                                JGrassMapEnvironment mapEnvironment = new JGrassMapEnvironment(mapFile);
                                JGrassRegion jGrassRegion = mapEnvironment.getActiveRegion();

                                int cols = jGrassRegion.getCols();
                                int rows = jGrassRegion.getRows();
                                double north = jGrassRegion.getNorth();
                                double south = jGrassRegion.getSouth();
                                double east = jGrassRegion.getEast();
                                double west = jGrassRegion.getWest();
                                double we_res = jGrassRegion.getWEResolution();
                                double ns_res = jGrassRegion.getNSResolution();
                                regionString.append("region:\nwest=");
                                regionString.append(west);
                                regionString.append("\neast=");
                                regionString.append(east);
                                regionString.append("\nsouth=");
                                regionString.append(south);
                                regionString.append("\nnorth=");
                                regionString.append(north);
                                regionString.append("\nwe_res=");
                                regionString.append(we_res);
                                regionString.append("\nns_res=");
                                regionString.append(ns_res);
                                regionString.append("\nrows=");
                                regionString.append(rows);
                                regionString.append("\ncols=");
                                regionString.append(cols);

                                GeneralParameterValue[] readParams = createGridGeometryGeneralParameter(cols, rows, north, south,
                                        east, west, mapEnvironment.getCoordinateReferenceSystem());
                                AbstractGridFormat format = (AbstractGridFormat) new GrassCoverageFormatFactory().createFormat();
                                AbstractGridCoverage2DReader reader = format.getReader(mapEnvironment.getCELL());
                                geodata = ((GridCoverage2D) reader.read(readParams));
                                geodata = geodata.view(ViewType.GEOPHYSICS);
                            } else {
                                MessageDialog.openInformation(shell, "WARNING", "Unable to read format");
                                return;
                            }

                            GridGeometry2D gridGeometry = geodata.getGridGeometry();
                            GridEnvelope2D gridRange = gridGeometry.getGridRange2D();
                            int rows = gridRange.height;
                            int cols = gridRange.width;
                            AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS();
                            double xRes = XAffineTransform.getScaleX0(gridToCRS);
                            double yRes = XAffineTransform.getScaleY0(gridToCRS);

                            RandomIter inputIter = RandomIterFactory.create(geodata.getRenderedImage(), null);
                            /*
                             * calculate mean, max and min
                             */
                            double mean = 0.0;

                            double[] minMaxMeans = new double[]{Double.MAX_VALUE, Double.MIN_VALUE, 0, 0, 0};
                            int validCells = 0;
                            for( int y = 0; y < rows; y++ ) {
                                for( int x = 0; x < cols; x++ ) {
                                    double value = inputIter.getSampleDouble(x, y, 0);
                                    if (!Double.isNaN(value) && (int) value != -9999) {
                                        if (value < minMaxMeans[0])
                                            minMaxMeans[0] = value;
                                        if (value > minMaxMeans[1])
                                            minMaxMeans[1] = value;
                                        mean = mean + value;
                                        validCells++;
                                    }
                                }
                            }

                            mean = mean / (double) validCells;

                            minMaxMeans[2] = mean;
                            minMaxMeans[3] = validCells;
                            minMaxMeans[4] = validCells * xRes * yRes;

                            /*
                             * print out some system out
                             */
                            StringBuilder sb = new StringBuilder();
                            sb.append("Summary for the map:\n");
                            sb.append("\n");
                            sb.append("range: " + minMaxMeans[0] + " - " + minMaxMeans[1] + "\n");
                            sb.append("mean: " + minMaxMeans[2] + "\n");
                            sb.append("active cells: " + minMaxMeans[3] + "\n");
                            sb.append("active area (assuming metric resolution): " + minMaxMeans[4] + "\n");
                            sb.append(regionString.toString() + "\n");
                            sb.append("data crs: " + geodata.getCoordinateReferenceSystem().getName().toString());

                            MessageDialog.openInformation(shell, "Summary", sb.toString());

                        } catch (Exception e) {
                            String message = "An error occurred while exporting the maps.";
View Full Code Here

    private GridCoverage convertToGridCoverage( IViewportModel viewportModel, BufferedImage image ) {
        ReferencedEnvelope env = viewportModel.getBounds();

        GridCoverageFactory factory = new GridCoverageFactory();

        GridCoverage2D gc = (GridCoverage2D) factory.create("GridCoverage", image, env); //$NON-NLS-1$
        return gc;
    }
View Full Code Here

                    .getGamma());
        }

        SLD.setChannelSelection(s, new SelectedChannelType[]{red, green, blue}, null);
        // get histogram and update
        GridCoverage2D gc = null;
        try {
            gc = (GridCoverage2D) getLayer().getResource(GridCoverage.class, null);
            if (gc != null) {
                updateHistogram(rs, gc);
            }
View Full Code Here

                }
            });

            RasterSymbolizerHelper rsp = new RasterSymbolizerHelper(gc, null);
            rsp.visit(rs);
            GridCoverage2D recoloredGridCoverage = (GridCoverage2D) rsp.getOutput();

            final OperationJAI op = new OperationJAI("Histogram"); //$NON-NLS-1$
            ParameterValueGroup params = op.getParameters();
            params.parameter("Source").setValue(recoloredGridCoverage); //$NON-NLS-1$

            recoloredGridCoverage = (GridCoverage2D) op.doOperation(params, null);
            final Histogram h = (Histogram) recoloredGridCoverage.getProperty("histogram"); //$NON-NLS-1$

            Display.getDefault().asyncExec(new Runnable(){
                public void run() {
                    rgbViewer.updateHistograms(h.getBins());
                }
View Full Code Here

        final Coordinate envelopeCenterOrig = bbox.centre();
        CoordinateReferenceSystem sourceCRS = bbox.getCoordinateReferenceSystem();
        final DecimalFormat formatter = new DecimalFormat("0.####");
        IGeoResource geoResource = layer.getGeoResource();

        GridCoverage2D coverage = null;
        GridGeometry2D gridGeometry = null;
        Coordinate evaluateCoord = null;
        // try to go for the reader first
        boolean isOnGrid = false;
        boolean hasProblem = false;
        Point2D p = null;
        if (geoResource.canResolve(AbstractGridCoverage2DReader.class)) {
            AbstractGridCoverage2DReader reader = geoResource.resolve(AbstractGridCoverage2DReader.class, monitor);
            GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope();
            CoordinateReferenceSystem targetCrs = reader.getCrs();

            if (targetCrs != null) {
                evaluateCoord = transform(sourceCRS, targetCrs, envelopeCenterOrig);
            } else {
                evaluateCoord = envelopeCenterOrig;
                targetCrs = sourceCRS;
            }
            p = new Point2D.Double(evaluateCoord.x, evaluateCoord.y);
            if (originalEnvelope.contains(new DirectPosition2D(p))) {
                double delta = 0.0000001;
                GeneralParameterValue[] parameterValues = createGridGeometryGeneralParameter(1, 1, evaluateCoord.y + delta,
                        evaluateCoord.y - delta, evaluateCoord.x + delta, evaluateCoord.x - delta, targetCrs);
                coverage = reader.read(parameterValues);
                /*
                 * the following is done since the reader might read a singlwe pixel
                 * region and the gridcoordinate would be 0, 0 in that case. Later
                 * we want to supply the gridcoordinate of the position in the whole
                 * coverage.
                 */
                gridGeometry = new GridGeometry2D(reader.getOriginalGridRange(), reader.getOriginalEnvelope());
                isOnGrid = true;
            }
        }
        // else try with coverage
        else if (geoResource.canResolve(GridCoverage.class)) {
            coverage = (GridCoverage2D) geoResource.resolve(GridCoverage.class, monitor);
            CoordinateReferenceSystem targetCrs = coverage.getCoordinateReferenceSystem();
            gridGeometry = coverage.getGridGeometry();
            evaluateCoord = transform(sourceCRS, targetCrs, envelopeCenterOrig);
            p = new Point2D.Double(evaluateCoord.x, evaluateCoord.y);
            Envelope2D envelope2d = coverage.getEnvelope2D();
            if (envelope2d.contains(p)) {
                isOnGrid = true;
            }
        } else {
            hasProblem = true;
        }

        final StringBuilder sb = new StringBuilder();
        if (hasProblem) {
            sb.append("The coverage information could not be read.");
        } else if (isOnGrid) {
            int bands = coverage.getSampleDimensions().length;
            final double[] evaluated = new double[bands];
            try {
                coverage.evaluate(p, evaluated);
            } catch (Exception e) {
                e.printStackTrace();
            }
            final GridCoordinates2D gridCoord = gridGeometry.worldToGrid(new DirectPosition2D(p));
            sb.append("Coverage info:\n\n");
View Full Code Here

                    // }
                    // }
                    //
                    // } else
                    if (geoResource.canResolve(GridCoverage.class)) {
                        GridCoverage2D coverage2D = (GridCoverage2D) geoResource.resolve(GridCoverage.class, pm);
                        dumpMap(coverage2D, fileCrs, newCrs, newPath, isAscii, isTiff);
                    } else {
                        throw new IOException("The selected resource doesn't seem to be a coverage layer: " + geoResource.getTitle());
                    }
View Full Code Here

          DefaultCartesianCS.GENERIC_2D);
    // now create a gridcoverage for the new warped image
    GridCoverageFactory factory = new GridCoverageFactory();
    ReferencedEnvelope ref = new ReferencedEnvelope(0, image.getWidth(null), 0, image.getHeight(null), derivedCRS);

    GridCoverage2D coverage = (GridCoverage2D) factory.create("GridCoverage", image, ref); //$NON-NLS-1$

    // resample the new image with the world CRS
    GridCoverage2D warpedCoverage = null;
    try {
      Operations ops = new Operations(null);
      Coverage resample = ops.resample(coverage, this.crsTarget);
      warpedCoverage = (GridCoverage2D) resample;
      saveImage(warpedCoverage);
View Full Code Here

        double east = envelopeParams.get(EAST);
        double north = envelopeParams.get(NORTH);
        Envelope2D writeEnvelope = new Envelope2D(crs, west, south, east - west, north - south);
        GridCoverageFactory factory = CoverageFactoryFinder.getGridCoverageFactory(null);

        GridCoverage2D coverage2D = factory.create(name, writableRaster, writeEnvelope);
        return coverage2D;
    }
View Full Code Here

TOP

Related Classes of org.geotools.coverage.grid.GridCoverage2D

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.