Package org.geotools.coverage.grid

Examples of org.geotools.coverage.grid.GridGeometry2D


            List< ? > layers = (List< ? >) updatedObject;
            for( Object layer : layers ) {
                if (layer instanceof IGeoResource) {
                    IGeoResource geoResource = (IGeoResource) layer;
                    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());
View Full Code Here


                                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);
                            /*
 
View Full Code Here

        } else {
            DirectPosition2D minDp = new DirectPosition2D(west, south);
            DirectPosition2D maxDp = new DirectPosition2D(east, north);
            env = new Envelope2D(minDp, maxDp);
        }
        readGG.setValue(new GridGeometry2D(gridEnvelope, env));
        readParams[0] = readGG;

        return readParams;
    }
View Full Code Here

        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");
            int length = evaluated.length;
            if (length > 1) {
                for( int i = 0; i < evaluated.length; i++ ) {
                    sb.append("Band ").append(i);
View Full Code Here

        } else {
            DirectPosition2D minDp = new DirectPosition2D(west, south);
            DirectPosition2D maxDp = new DirectPosition2D(east, north);
            env = new Envelope2D(minDp, maxDp);
        }
        readGG.setValue(new GridGeometry2D(gridEnvelope, env));
        readParams[0] = readGG;

        return readParams;
    }
View Full Code Here

        } else {
            DirectPosition2D minDp = new DirectPosition2D(west, south);
            DirectPosition2D maxDp = new DirectPosition2D(east, north);
            env = new Envelope2D(minDp, maxDp);
        }
        readGG.setValue(new GridGeometry2D(gridEnvelope, env));
        readParams[0] = readGG;

        return readParams;
    }
View Full Code Here

        DirectPosition lowerCorner = envelope.getLowerCorner();
        double[] westSouth = lowerCorner.getCoordinate();
        DirectPosition upperCorner = envelope.getUpperCorner();
        double[] eastNorth = upperCorner.getCoordinate();

        GridGeometry2D gridGeometry = gridCoverage.getGridGeometry();
        GridEnvelope2D gridRange = gridGeometry.getGridRange2D();
        int height = gridRange.height;
        int width = gridRange.width;

        AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS();
        double xRes = XAffineTransform.getScaleX0(gridToCRS);
        double yRes = XAffineTransform.getScaleY0(gridToCRS);

        envelopeParams.put(NORTH, eastNorth[1]);
        envelopeParams.put(SOUTH, westSouth[1]);
View Full Code Here

                        GridEnvelope2D gridEnvelope2D = new GridEnvelope2D(0, 0, (int) cols, (int) rows);
                        g2eMapper.setGridRange(gridEnvelope2D);
                        g2eMapper.setPixelAnchor(PixelInCell.CELL_CENTER);
                        MathTransform gridToEnvelopeTransform = g2eMapper.createTransform();

                        GridGeometry outputGridGeometry = new GridGeometry2D(gridEnvelope2D, gridToEnvelopeTransform, crs);

                        GridCoverage2D coverage2D = JGrassCatalogUtilities.getGridcoverageFromGrassraster(jgMEnv, sourceRegion);
                        // GrassCoverageReadParam gcReadParam = new
                        // GrassCoverageReadParam(sourceRegion);
                        GridCoverage2D reprojected = (GridCoverage2D) Operations.DEFAULT.resample(coverage2D, crs,
View Full Code Here

        } else {
            DirectPosition2D minDp = new DirectPosition2D(west, south);
            DirectPosition2D maxDp = new DirectPosition2D(east, north);
            env = new Envelope2D(minDp, maxDp);
        }
        readGG.setValue(new GridGeometry2D(gridEnvelope, env));
        readParams[0] = readGG;

        return readParams;
    }
View Full Code Here

        } else {
            DirectPosition2D minDp = new DirectPosition2D(west, south);
            DirectPosition2D maxDp = new DirectPosition2D(east, north);
            env = new Envelope2D(minDp, maxDp);
        }
        readGG.setValue(new GridGeometry2D(gridEnvelope, env));
        readParams[0] = readGG;

        return readParams;
    }
View Full Code Here

TOP

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

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.