Examples of JGrassRegion


Examples of org.geotools.gce.grassraster.JGrassRegion

            if (resource == null || !resource.canResolve(JGrassMapGeoResource.class)) {
                return;
            }
            JGrassMapGeoResource grassMapGeoResource = resource.resolve(JGrassMapGeoResource.class, monitor);

            JGrassRegion fileWindow = new JGrassRegion(grassMapGeoResource.getFileWindow());
            JGrassMapsetGeoResource parent = (JGrassMapsetGeoResource) grassMapGeoResource.parent(new NullProgressMonitor());
            CoordinateReferenceSystem grassCrs = parent.getLocationCrs();
            JGrassRegion screenDrawWindow = new JGrassRegion(envelope.getMinX(), envelope.getMaxX(), envelope.getMinY(),
                    envelope.getMaxY(), fileWindow.getRows(), fileWindow.getCols());

            // to intersect with the data window, we transform the screen window
            JGrassRegion reprojectedScreenDrawWindow = screenDrawWindow;
            if (!CRS.equalsIgnoreMetadata(destinationCRS, grassCrs)) {
                reprojectedScreenDrawWindow = screenDrawWindow.reproject(destinationCRS, grassCrs, true);
            }

            /*
             * if the map is not visible, do not render it
             */
            // JGrassRegion fileWindow = grassMapGeoResource.getFileWindow();
            Rectangle2D.Double fileRectDouble = fileWindow.getRectangle();
            Double reprojScreenRectangle = reprojectedScreenDrawWindow.getRectangle();
            if (!reprojScreenRectangle.intersects(fileRectDouble)) {
                getContext().setStatus(ILayer.DONE);
                getContext().setStatusMessage(THE_MAP_IS_OUTSIDE_OF_THE_VISIBLE_REGION);
                System.out.println(THE_MAP_IS_OUTSIDE_OF_THE_VISIBLE_REGION);
                return;
            }
            /*
             * we will draw only the intersection of the map in the display system = part of visible map
             */
            Rectangle2D drawMapRectangle = reprojectedScreenDrawWindow.getRectangle().createIntersection(fileRectDouble);
            // Rectangle2D drawMapRectangle = fileRectDouble.getBounds2D();
            // resolution is that of the file window
            double ewRes = fileWindow.getWEResolution();
            double nsRes = fileWindow.getNSResolution();
            if (fileRectDouble.getWidth() < ewRes || fileRectDouble.getHeight() < nsRes) {
                getContext().setStatus(ILayer.DONE);
                getContext().setStatusMessage(THE_MAP_IS_OUTSIDE_OF_THE_VISIBLE_REGION);
                System.out.println(THE_MAP_IS_OUTSIDE_OF_THE_VISIBLE_REGION);
                return;
            }
            MathTransform transform = CRS.findMathTransform(destinationCRS, grassCrs, true);
            Coordinate pixelSize = getContext().getPixelSize();

            Coordinate c1 = new Coordinate(envelope.getMinX(), envelope.getMinY());
            Coordinate c2 = new Coordinate(envelope.getMinX() + pixelSize.x, envelope.getMinY() + pixelSize.y);
            Envelope envy = new Envelope(c1, c2);
            Envelope envyTrans = JTS.transform(envy, transform);

            pixelSize = new Coordinate(envyTrans.getWidth(), envyTrans.getHeight());
            /*
             * if the resolution is higher of that of the screen, it doesn't make much sense to draw it
             * all. So for visualization we just use the screen resolution to do things faster.
             */
            if (ewRes < pixelSize.x) {
                ewRes = pixelSize.x;
            }
            if (nsRes < pixelSize.y) {
                nsRes = pixelSize.y;
            }
            fileWindow.setNSResolution(nsRes);
            fileWindow.setWEResolution(ewRes);
            nsRes = fileWindow.getNSResolution();
            ewRes = fileWindow.getWEResolution();
            /*
             * redefine the region of the map to be drawn
             */
            /*
             * snap the screen to fit into the active region grid. This is mandatory for the exactness
             * of the query of the pixels (ex. d.what.rast).
             */
            JGrassRegion activeWindow = grassMapGeoResource.getActiveWindow();
            Coordinate minXY = JGrassRegion.snapToNextHigherInRegionResolution(drawMapRectangle.getMinX(),
                    drawMapRectangle.getMinY(), activeWindow);
            Coordinate maxXY = JGrassRegion.snapToNextHigherInRegionResolution(drawMapRectangle.getMaxX(),
                    drawMapRectangle.getMaxY(), activeWindow);

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

Examples of org.geotools.gce.grassraster.JGrassRegion

                            } 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=");
View Full Code Here

Examples of org.geotools.gce.grassraster.JGrassRegion

        }
    }

    public JGrassRegion getActiveRegionWindow() {
        try {
            return new JGrassRegion(getActiveRegionWindowPath());
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
View Full Code Here

Examples of org.geotools.gce.grassraster.JGrassRegion

            this.name = JGrassMapsetGeoResource.this.name;
            this.title = this.name;
            this.description = "JGrass Mapset (" + getIdentifier() + ")"; //$NON-NLS-1$ //$NON-NLS-2$

            // calculate bounds
            JGrassRegion activeRegionWindow = getActiveRegionWindow();
            this.bounds = new ReferencedEnvelope(activeRegionWindow.getEnvelope(), getCRS());
            super.icon = CatalogUIPlugin.getDefault().getImageDescriptor(ISharedImages.CATALOG_OBJ);
        }
View Full Code Here

Examples of org.geotools.gce.grassraster.JGrassRegion

                        Envelope bounds = null;
                        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);
                                if (style == null) {
                                    style = ActiveregionStyleContent.createDefault();
                                }
                                style.north = (float) newActiveRegion.getNorth();
                                style.south = (float) newActiveRegion.getSouth();
                                style.east = (float) newActiveRegion.getEast();
                                style.west = (float) newActiveRegion.getWest();
                                style.rows = newActiveRegion.getRows();
                                style.cols = newActiveRegion.getCols();
                                style.windPath = windFile.getAbsolutePath();
                                style.crsString = code;

                                blackboard.put(ActiveregionStyleContent.ID, style);
View Full Code Here

Examples of org.geotools.gce.grassraster.JGrassRegion

                            resolutionGroup.setText("output map resolution");

                            String res = "";
                            if (maps.size() > 0) {
                                try {
                                    JGrassRegion activeWindow = maps.get(0).getActiveWindow();
                                    res = String.valueOf(activeWindow.getNSResolution());
                                } catch (IOException e1) {
                                    e1.printStackTrace();
                                }
                            }
                            Label xresLabel = new Label(resolutionGroup, SWT.NONE);
                            xresLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
                            xresLabel.setText("X resolution");

                            xresText = new Text(resolutionGroup, SWT.BORDER);
                            xresText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL
                                    | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_CENTER));
                            xresText.setText(res);

                            Label yresLabel = new Label(resolutionGroup, SWT.NONE);
                            yresLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
                            yresLabel.setText("Y resolution");

                            yresText = new Text(resolutionGroup, SWT.BORDER);
                            yresText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL
                                    | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_CENTER));
                            yresText.setText(res);

                            return parent;
                        }

                        protected void okPressed() {
                            locationName = locNameText.getText();
                            if (locationName == null || locationName.length() < 1) {
                                locationName = "newLocation";
                            }
                            mapsetName = mapsetNameText.getText();
                            if (mapsetName == null || mapsetName.length() < 1) {
                                mapsetName = "newMapset";
                            }
                            xRes = xresText.getText();
                            yRes = yresText.getText();
                            Object crsData = crsText.getData();
                            if (crsData instanceof CoordinateReferenceSystem) {
                                crs = (CoordinateReferenceSystem) crsData;
                            }
                            super.okPressed();
                        }
                    };
                    dialog.setBlockOnOpen(true);
                    open = dialog.open();

                } catch (Exception e) {
                    String message = "An error occurred while exporting the maps.";
                    ExceptionDetailsDialog.openError("ERROR", message, IStatus.ERROR, JGrassPlugin.PLUGIN_ID, e);
                }

            }
        });

        if (open == SWT.CANCEL) {
            return;
        }
        /*
         * run with backgroundable progress monitoring
         */
        IRunnableWithProgress operation = new IRunnableWithProgress(){

            public void run( IProgressMonitor monitor ) throws InvocationTargetException, InterruptedException {
                if (locationName == null || mapsetName == null || crs == null || maps.size() < 1) {
                    MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR);
                    msgBox.setMessage("An error occurred in processing the user supplied data.");
                    msgBox.open();
                    return;
                }
                /*
                 * finally do some processing
                 */
                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);
View Full Code Here

Examples of org.geotools.gce.grassraster.JGrassRegion

     * @throws Exception
     */
    public static GridCoverage2D getGridcoverageFromGrassraster( JGrassMapEnvironment jGrassMapEnvironment,
            JGrassRegion readRegion ) throws Exception {
        CoordinateReferenceSystem crs = jGrassMapEnvironment.getCoordinateReferenceSystem();
        JGrassRegion jGrassRegion = readRegion;
        if (jGrassRegion == null)
            jGrassRegion = jGrassMapEnvironment.getActiveRegion();
        GeneralParameterValue[] readParams = JGrassCatalogUtilities.createGridGeometryGeneralParameter(jGrassRegion.getCols(),
                jGrassRegion.getRows(), jGrassRegion.getNorth(), jGrassRegion.getSouth(), jGrassRegion.getWest(),
                jGrassRegion.getEast(), crs);
        AbstractGridFormat format = (AbstractGridFormat) new GrassCoverageFormatFactory().createFormat();
        GridCoverageReader reader = format.getReader(jGrassMapEnvironment.getCELL());
        GridCoverage2D mapCoverage = ((GridCoverage2D) reader.read(readParams));
        return mapCoverage;
    }
View Full Code Here

Examples of org.geotools.gce.grassraster.JGrassRegion

        System.out.println(props.north);
        System.out.println(props.xres);
        System.out.println(props.crs.getName().toString());

        try {
            JGrassRegion window = new JGrassRegion(props.west, props.east, props.south,
                    props.north, props.xres, props.yres);
            JGrassCatalogUtilities.createLocation(props.locationPath, props.crs, window);
            for( String mapset : props.mapsets ) {
                JGrassCatalogUtilities.createMapset(props.locationPath, mapset, null, null);
                // set the WIND file
View Full Code Here

Examples of org.geotools.gce.grassraster.JGrassRegion

            double w = regionParams.get(JGrassCatalogUtilities.WEST);
            double xres = regionParams.get(JGrassCatalogUtilities.XRES);
            double yres = regionParams.get(JGrassCatalogUtilities.YRES);

            // create the location and mapset
            JGrassRegion window = new JGrassRegion(w, e, s, n, xres, yres);
            File baseFolderFile = new File(props.basePath);
            File locationFile = new File(baseFolderFile, props.locationName);
            File mapsetFile = new File(locationFile, props.mapsetName);
            String locationPath = locationFile.getAbsolutePath();
            JGrassCatalogUtilities.createLocation(locationPath, fileCrs, window);
View Full Code Here

Examples of org.geotools.gce.grassraster.JGrassRegion

                                String newMapName = iDialog.getValue();
                                if (newMapName != null && newMapName.length() > 0) {
                                    newMapName = newMapName.replaceAll("\\s+", "_");

                                    JGrassMapEnvironment oldMapEnvironment = new JGrassMapEnvironment(oldMapFile);
                                    JGrassRegion jGrassRegion = oldMapEnvironment.getActiveRegion();
                                    GeneralParameterValue[] readParams = createGridGeometryGeneralParameter(
                                            jGrassRegion.getCols(), jGrassRegion.getRows(), jGrassRegion.getNorth(),
                                            jGrassRegion.getSouth(), jGrassRegion.getEast(), jGrassRegion.getWest(),
                                            oldMapEnvironment.getCoordinateReferenceSystem());
                                    AbstractGridFormat format = (AbstractGridFormat) new GrassCoverageFormatFactory()
                                            .createFormat();
                                    AbstractGridCoverage2DReader reader = format.getReader(oldMapEnvironment.getCELL());
                                    GridCoverage2D geodata = ((GridCoverage2D) reader.read(readParams));
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.