Class JGrassRegion


  • public class JGrassRegion
    extends Object
    Represents the geographic region used in the jGrass engines.

    JGrass calculations always work against a particular geographic region, which contains the boundaries of the region as well as the information of the region's resolution and the number of rows and cols of the region.

    Warning: since the rows and cols have to be integers, the resolution is may be recalculated to fulfill this constraint. Users should not wonder if the asked resolution is not available in the supplied boundaries.

    Since:
    3.0
    Author:
    Andrea Antonello - www.hydrologis.com
    • Field Detail

      • BLACKBOARD_KEY

        public static final String BLACKBOARD_KEY
        The identifier string for the JGrassRegion.

        Useful for environments that work with blackboards. For example the Udig layers support blackboards.

        See Also:
        Constant Field Values
    • Constructor Detail

      • JGrassRegion

        public JGrassRegion​(String regionFilePath)
                     throws IOException
        Creates a new instance of JGrassRegion.

        The supplied path has to be of the format of a GRASS WIND file.

        Parameters:
        regionFilePath - a GRASS region file path.
        Throws:
        IOException
      • JGrassRegion

        public JGrassRegion​(double west,
                            double east,
                            double south,
                            double north,
                            int rows,
                            int cols)
        Creates a new instance of JGrassRegion.

        This constructor may be used when boundaries and number of rows and columns are available.

        Parameters:
        west - the western boundary.
        east - the eastern boundary.
        south - the southern boundary.
        north - the nothern boundary.
        rows - the number of rows.
        cols - the number of cols.
      • JGrassRegion

        public JGrassRegion​(double west,
                            double east,
                            double south,
                            double north,
                            double weres,
                            double nsres)
        Creates a new instance of JGrassRegion.

        This constructor may be used when boundaries and the resolution is available.

        Parameters:
        west - the western boundary.
        east - the eastern boundary.
        south - the southern boundary.
        north - the northern boundary.
        weres - the east-west resolution.
        nsres - the north -south resolution.
      • JGrassRegion

        public JGrassRegion​(JGrassRegion region)
        Creates a new instance of JGrassRegion by duplicating an existing region.
        Parameters:
        region - a region from which to take the setting from.
      • JGrassRegion

        public JGrassRegion​(ReferencedEnvelope envelope2D)
        Creates a new instance of JGrassRegion from an Envelope2D .
        Parameters:
        envelope2D - the envelope2D from which to take the setting from.
      • JGrassRegion

        public JGrassRegion​(String west,
                            String east,
                            String south,
                            String north,
                            String ewres,
                            String nsres)
        Creates a new instance of JGrassRegion from given strings.
        Parameters:
        west - the western boundary string.
        east - the eastern boundary string.
        south - the southern boundary string.
        north - the nothern boundary string.
        ewres - the x resolution string.
        nsres - the y resolution string.
      • JGrassRegion

        public JGrassRegion​(String west,
                            String east,
                            String south,
                            String north,
                            int rows,
                            int cols)
        Creates a new instance of JGrassRegion from given strings.
        Parameters:
        west - the western boundary string.
        east - the eastern boundary string.
        south - the southern boundary string.
        north - the nothern boundary string.
        rows - the string of rows.
        cols - the string of cols.
    • Method Detail

      • setExtent

        public void setExtent​(JGrassRegion region)
        Sets the extent of this window using another window.
        Parameters:
        region - another window object
      • getEnvelope

        public Envelope getEnvelope()
        Creates JTS envelope from the current region.
        Returns:
        the JTS envelope wrapping the current region.
      • getRectangle

        public Rectangle2D.Double getRectangle()
        Creates a rectangle from the current region.

        Note that the rectangle width and height are world coordinates.

        Returns:
        the rectangle wrapping the current region.
      • snapToNextHigherInRegionResolution

        public static Coordinate snapToNextHigherInRegionResolution​(double x,
                                                                    double y,
                                                                    JGrassRegion region)
        Snaps a geographic point to be on the region grid.

        Moves the point given by X and Y to be on the grid of the supplied region.

        Parameters:
        x - the easting of the arbitrary point.
        y - the northing of the arbitrary point.
        region - the active window from which to take the grid.
        Returns:
        the snapped coordinate.
      • getActiveRegionFromMapset

        public static JGrassRegion getActiveRegionFromMapset​(String mapsetPath)
                                                      throws IOException
        Computes the active region from the supplied mapset path.
        Parameters:
        mapsetPath - the path to the mapset folder.
        Returns:
        the active region.
        Throws:
        IOException
      • writeWINDToMapset

        public static void writeWINDToMapset​(String mapsetPath,
                                             JGrassRegion activeRegion)
                                      throws IOException
        Writes active region window to the supplied mapset.
        Parameters:
        mapsetPath - the path to the mapset folder.
        activeRegion - the active region.
        Throws:
        IOException
      • writeDEFAULTWINDToLocation

        public static void writeDEFAULTWINDToLocation​(String locationPath,
                                                      JGrassRegion region)
                                               throws IOException
        Write default region to the PERMANENT mapset.
        Parameters:
        locationPath - the path to the location folder.
        region - a region.
        Throws:
        IOException
      • adaptActiveRegionToEnvelope

        public static JGrassRegion adaptActiveRegionToEnvelope​(Envelope sourceEnvelope,
                                                               JGrassRegion sourceRegion)
        Creates a region from envelope bounds snapped to a region grid.

        This takes an envelope and a JGrass region and creates a new region to match the bounds of the envelope, but the grid of the region. This is important if the region has to match some feature layer.

        The bounds of the new region contain completely the envelope.

        Parameters:
        sourceEnvelope - the envelope to adapt.
        sourceRegion - the region from which to take the grid to be snapped.
        Returns:
        a new region, created from the envelope bounds snapped to the region grid.
      • getProj

        public int getProj()
        Getter for proj
        Returns:
        the proj
      • setProj

        public void setProj​(int proj)
        Setter for proj
        Parameters:
        proj - the proj to set
      • getZone

        public int getZone()
        Getter for zone
        Returns:
        the zone
      • setZone

        public void setZone​(int zone)
        Setter for zone
        Parameters:
        zone - the zone to set
      • getNorth

        public double getNorth()
        Getter for north
        Returns:
        the north
      • setNorth

        public void setNorth​(double north)
        Setter for north
        Parameters:
        north - the north to set
      • getSouth

        public double getSouth()
        Getter for south
        Returns:
        the south
      • setSouth

        public void setSouth​(double south)
        Setter for south
        Parameters:
        south - the south to set
      • getWest

        public double getWest()
        Getter for west
        Returns:
        the west
      • setWest

        public void setWest​(double west)
        Setter for west
        Parameters:
        west - the west to set
      • getEast

        public double getEast()
        Getter for east
        Returns:
        the east
      • setEast

        public void setEast​(double east)
        Setter for east
        Parameters:
        east - the east to set
      • getNSResolution

        public double getNSResolution()
        Getter for ns_res
        Returns:
        the ns_res
      • setNSResolution

        public void setNSResolution​(double ns_res)
        Setter for ns_res
        Parameters:
        ns_res - the ns_res to set
      • getWEResolution

        public double getWEResolution()
        Getter for we_res
        Returns:
        the we_res
      • setWEResolution

        public void setWEResolution​(double we_res)
        Setter for we_res
        Parameters:
        we_res - the we_res to set
      • getRows

        public int getRows()
        Getter for rows
        Returns:
        the rows
      • setRows

        public void setRows​(int rows)
        Setter for rows
        Parameters:
        rows - the rows to set
      • getCols

        public int getCols()
        Getter for cols.
        Returns:
        the cols.
      • setCols

        public void setCols​(int cols)
        Setter for cols.
        Parameters:
        cols - the cols to set.
      • getAdditionalGrassEntries

        public LinkedHashMap<String,​String> getAdditionalGrassEntries()
        Getter for additionalGrassEntries.
        Returns:
        the additionalGrassEntries.
      • setAdditionalGrassEntries

        public void setAdditionalGrassEntries​(LinkedHashMap<String,​String> additionalGrassEntries)
        Setter for additionalGrassEntries.
        Parameters:
        additionalGrassEntries - the additionalGrassEntries to set.