Package org.geotools.gce.grassraster

Examples of org.geotools.gce.grassraster.JGrassMapEnvironment


            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
View Full Code Here


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

                        try {
                            pm.beginTask("Set active region to maps bounds...", toList.size());

                            try {
                                JGrassRegion currentRegion = null;
                                JGrassMapEnvironment grassMapEnvironment = null;

                                for( Object object : toList ) {
                                    if (object instanceof JGrassMapGeoResource) {
                                        JGrassMapGeoResource mr = (JGrassMapGeoResource) object;
                                        JGrassRegion fileWindow = mr.getFileWindow();
                                        if (currentRegion == null) {
                                            currentRegion = mr.getActiveWindow();
                                            grassMapEnvironment = mr.getjGrassMapEnvironment();
                                        }

                                        Envelope envelope = fileWindow.getEnvelope();
                                        if (bounds == null) {
                                            bounds = envelope;
                                        } else {
                                            bounds.expandToInclude(envelope);
                                        }

                                    }
                                    pm.worked(1);
                                }

                                String code = null;
                                try {
                                    CoordinateReferenceSystem jGrassCrs = grassMapEnvironment.getCoordinateReferenceSystem();
                                    try {
                                        Integer epsg = CRS.lookupEpsgCode(jGrassCrs, true);
                                        code = "EPSG:" + epsg;
                                    } catch (Exception e) {
                                        // try non epsg
                                        code = CRS.lookupIdentifier(jGrassCrs, true);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                                JGrassRegion newActiveRegion = JGrassRegion.adaptActiveRegionToEnvelope(bounds, currentRegion);
                                File windFile = grassMapEnvironment.getWIND();
                                JGrassRegion.writeWINDToMapset(windFile.getParent(), newActiveRegion);

                                IMap activeMap = ApplicationGIS.getActiveMap();
                                IBlackboard blackboard = activeMap.getBlackboard();
                                ActiveRegionStyle style = (ActiveRegionStyle) blackboard.get(ActiveregionStyleContent.ID);
View Full Code Here

                    public void run( IProgressMonitor monitor ) throws InvocationTargetException, InterruptedException {

                        try {
                            File cellFile = new File(mapsetPathAndMapName[0] + File.separator + JGrassConstants.CELL
                                    + File.separator + mapsetPathAndMapName[1]);
                            JGrassMapEnvironment mE = new JGrassMapEnvironment(cellFile);
                            double[] dataRange = mE.getRangeFromMapScan();

                            List<String> defColorTable = JGrassColorTable.createDefaultColorTable(dataRange, 255);
                            File colrFile = mE.getCOLR();
                            JGrassUtilities.makeColorRulesPersistent(colrFile, defColorTable, dataRange, 255);
                            makeSomeColor(colrFile.getAbsolutePath());
                        } catch (IOException e) {
                            e.printStackTrace();
                            String message = "An error occurred while persisting the colortable to disk.";
View Full Code Here

        File cellFile = new File(mapPath);
        if (!cellFile.exists()) {
            context.getLayer().setStatus(ILayer.ERROR);
            return;
        }
        JGrassMapEnvironment jGrassMapEnvironment = new JGrassMapEnvironment(cellFile);
        List<String> categories = null;
        List<String> colorRules = null;
        try {
            categories = jGrassMapEnvironment.getCategories();
            colorRules = jGrassMapEnvironment.getColorRules(null);
        } catch (IOException e) {
            e.printStackTrace();
            context.getLayer().setStatus(ILayer.ERROR);
            return;
        }
View Full Code Here

     */
    @SuppressWarnings("nls")
    public static String setColorTableFromRules( File colrFile, double[] dataRange, String[][] colorRules ) throws IOException {
        String name = colrFile.getName();
        File mapsetFile = colrFile.getParentFile().getParentFile();
        JGrassMapEnvironment jGrassMapEnvironment = new JGrassMapEnvironment(mapsetFile, name);

        if (colorRules[0].length == 3) {
            /*
             * the colorrules are without values, so we ramp through them
             * over the range.
             */
            if (dataRange == null) {
                // first try to read the range file
                dataRange = jGrassMapEnvironment.getRangeFromRangeFile();

                if (dataRange == null) {
                    // try to guess it from the color file
                    dataRange = jGrassMapEnvironment.getRangeFromColorTable();
                }

                if (dataRange == null) {
                    // something went wrong. read the map and get the range
                    dataRange = jGrassMapEnvironment.getRangeFromMapScan();
                }
            }

            // calculate the color increment
            float rinc = (float) (dataRange[1] - dataRange[0]) / (float) (colorRules.length - 1);
View Full Code Here

            dataRange = new double[2];
            // need to read the datarange

            String name = colrFile.getName();
            File mapsetFile = colrFile.getParentFile().getParentFile();
            JGrassMapEnvironment jGrassMapEnvironment = new JGrassMapEnvironment(mapsetFile, name);

            // first try to read the range file
            File rangeFile = jGrassMapEnvironment.getCELLMISC_RANGE();
            boolean fileok = true;
            int testread = 0;
            if (rangeFile.exists()) {
                // the range file exists
                InputStream is = new FileInputStream(rangeFile);
View Full Code Here

                 */
                int mapNum = maps.size();
                monitor.beginTask("Reprojecting maps to new Location...", mapNum);
                for( int i = 0; i < mapNum; i++ ) {
                    JGrassMapGeoResource tmpMap = maps.get(i);
                    JGrassMapEnvironment jgMEnv = new JGrassMapEnvironment(tmpMap.getMapFile());

                    try {
                        /*
                         * TODO get envelope from original region and reproject it.
                         * then adapt it to the output resolution and
                         * finally reproject the map on the new grid.
                         */
                        JGrassRegion sourceRegion = jgMEnv.getActiveRegion();
                        CoordinateReferenceSystem sourceCrs = jgMEnv.getCoordinateReferenceSystem();
                        com.vividsolutions.jts.geom.Envelope sourceEnvelope = sourceRegion.getEnvelope();
                        MathTransform tr = CRS.findMathTransform(sourceCrs, crs);
                        com.vividsolutions.jts.geom.Envelope outputEnvelope = JTS.transform(sourceEnvelope, tr);

                        double west = outputEnvelope.getMinX();
                        double east = outputEnvelope.getMaxX();
                        double south = outputEnvelope.getMinY();
                        double north = outputEnvelope.getMaxY();

                        double xResolution = Double.parseDouble(xRes);
                        double yResolution = Double.parseDouble(yRes);
                        Coordinate tmp1 = new Coordinate(west, south);
                        Coordinate tmp2 = new Coordinate(west + xResolution, south + yResolution);
                        JTS.transform(tmp1, tmp1, tr);
                        JTS.transform(tmp2, tmp2, tr);
                        xResolution = tmp2.x - tmp1.x;
                        yResolution = tmp2.y - tmp1.y;

                        // if in metric, snap to integer bounds
                        int intWest = (int) Math.floor(west);
                        int intSouth = (int) Math.floor(south);
                        if (west - intWest < xResolution && south - intSouth < yResolution) {
                            west = intWest;
                            south = intSouth;
                        }

                        double w = east - west;
                        double h = north - south;
                        // modify the envelope to be in the requested resolution
                        double cols = Math.floor(w / xResolution) + 1.0;
                        double rows = Math.floor(h / yResolution) + 1.0;

                        double newEast = west + cols * xResolution;
                        double newNorth = south + rows * yResolution;

                        ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(west, newEast, south, newNorth, crs);

                        GridToEnvelopeMapper g2eMapper = new GridToEnvelopeMapper();
                        g2eMapper.setEnvelope(referencedEnvelope);
                        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,
                                outputGridGeometry, Interpolation.getInstance(Interpolation.INTERP_BICUBIC));

                        JGrassRegion jgRegion = new JGrassRegion(west, newEast, south, newNorth, xResolution, yResolution);

                        // GridCoverage2D coverage2D = tmp.read(null);
                        // GridCoverage2D reprojected = (GridCoverage2D)
                        // Operations.DEFAULT.resample(
                        // coverage2D, crs);
                        // Envelope2D envelope2D = reprojected.getEnvelope2D();
                        // JGrassRegion jgRegion = new JGrassRegion(envelope2D);

                        if (i == 0) {
                            // create the location structure
                            File grassDbFile = jgMEnv.getLOCATION().getParentFile();
                            File newLocationFile = new File(grassDbFile, locationName);
                            try {
                                JGrassCatalogUtilities.createLocation(newLocationFile.getAbsolutePath(), crs, jgRegion);
                                JGrassCatalogUtilities
                                        .createMapset(newLocationFile.getAbsolutePath(), mapsetName, null, jgRegion);
View Full Code Here

        return mapCoverage;
    }

    public static void writeGridCoverageFromGrassraster( File mapFile, JGrassRegion writeRegion, GridCoverage2D grassCoverage )
            throws Exception {
        JGrassMapEnvironment mapEnvironment = new JGrassMapEnvironment(mapFile);
        GrassCoverageFormat format = new GrassCoverageFormatFactory().createFormat();
        GridCoverageWriter writer = format.getWriter(mapEnvironment.getCELL(), null);

        GeneralParameterValue[] readParams = null;
        if (writeRegion == null) {
            writeRegion = mapEnvironment.getActiveRegion();
        }
        readParams = JGrassCatalogUtilities.createGridGeometryGeneralParameter(writeRegion.getCols(), writeRegion.getRows(),
                writeRegion.getNorth(), writeRegion.getSouth(), writeRegion.getEast(), writeRegion.getWest(),
                mapEnvironment.getCoordinateReferenceSystem());

        writer.write(grassCoverage, readParams);
    }
View Full Code Here

            JGrassRegion.writeWINDToMapset(mapsetFile.getAbsolutePath(), window);

            // write the map into it
            String mapName = mapFile.getName();
            mapName = FilenameUtils.getBaseName(mapName);
            JGrassMapEnvironment mapEnvironment = new JGrassMapEnvironment(mapsetFile, mapName);
            GrassCoverageFormat format = new GrassCoverageFormatFactory().createFormat();
            GrassCoverageWriter writer = format.getWriter(mapEnvironment.getCELL(), null);
            GeneralParameterValue[] readParams = null;
            writer.write(geodata, readParams);

            JGrassCatalogUtilities.addServiceToCatalog(locationPath + File.separator
                    + JGrassCatalogUtilities.JGRASS_WORKSPACE_FILENAME, new NullProgressMonitor());
View Full Code Here

TOP

Related Classes of org.geotools.gce.grassraster.JGrassMapEnvironment

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.