es.unex.sextante.gui.grass
Class GrassUtils

java.lang.Object
  extended by es.unex.sextante.gui.grass.GrassUtils

public class GrassUtils
extends java.lang.Object


Field Summary
static java.lang.String colorTableExt
           
static java.lang.String colorTableIdentifier
           
static java.lang.String colorTableVersion
           
static int GEOM_TYPE_FACE
           
static int GEOM_TYPE_KERNEL
           
static int GEOM_TYPE_LINE
           
static int GEOM_TYPE_POINT
           
static int GEOM_TYPE_POLYGON
           
static int MAJOR_MAX
           
static int MAJOR_MIN
           
static int MINOR_MAX
           
static int MINOR_MIN
           
static java.lang.String TEMP_PREFIX
           
 
Constructor Summary
GrassUtils()
           
 
Method Summary
static void cancelProcess()
           
static java.io.File createStartupScript()
          Creates a compact startup script for GRASS.
static void createTempMapset()
          Creates a temporary location and mapset(s) for GRASS data processing.
static void deleteComFile()
           
static void deleteTempMapset()
          Deletes the location and mapset(s) for GRASS data processing.
static java.lang.String getBatchJobFile()
           
static java.io.File getComFile()
           
static java.lang.ProcessBuilder getGrassExecutable()
          Returns a ProcesBuilder ready to execute grass.
static java.lang.String getGroup(GeoAlgorithm grass)
          Return the group associated to a GRASS algorithm.
static int getNumFaces(java.lang.String sMapName)
          Returns the number of geometries of type FACE in a GRASS map.
static int getNumGeoms(java.lang.String sMapName, int iGeomType)
          Returns the number of geometries of a specified type in a GRASS map.
static int getNumKernels(java.lang.String sMapName)
          Returns the number of geometries of type KERNEL in a GRASS map.
static int getNumLines(java.lang.String sMapName)
          Returns the number of geometries of type LINE in a GRASS map.
static int getNumPoints(java.lang.String sMapName)
          Returns the number of geometries of type POINT in a GRASS map.
static int getNumPolygons(java.lang.String sMapName)
          Returns the number of geometries of type POLYGON in a GRASS map.
static java.lang.Process getProcess()
           
static java.lang.String getTempMapName()
          Returns a GRASS map name which can be safely used to store an imported layer (i.e. there is no chance that it will overwrite an existing map in the mapset).
static java.lang.String getTempMapName(java.lang.String sPrefix)
          Returns a GRASS map name which can be safely used to store an imported layer or any other GRASS element (a region setting, a group) that is significant in our context.
static boolean isLatLon()
          Checks if the current GRASS mapset (rather: the location of which it is part) works in lat/lon degrees.
static boolean isMap3D(java.lang.String sMapName)
          Checks if a GRASS vector map contains 3D data.
static boolean isMultiGeom(java.lang.String sMapName)
           
static boolean isProcessCanceled()
           
static boolean isSupported()
           
static void runGRASS(java.lang.StringBuffer sCommand, java.lang.String sMessage, GrassAlgorithm alg)
          Runs a batch of GRASS commands.
static void setExecutable(java.lang.String pathname)
          A convenience method to set the owner's execute permission for this abstract pathname.
static void setInterruptible(boolean choice)
           
static void writeColorTable(Output out)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAJOR_MIN

public static final int MAJOR_MIN
See Also:
Constant Field Values

MAJOR_MAX

public static final int MAJOR_MAX
See Also:
Constant Field Values

MINOR_MIN

public static final int MINOR_MIN
See Also:
Constant Field Values

MINOR_MAX

public static final int MINOR_MAX
See Also:
Constant Field Values

GEOM_TYPE_POINT

public static final int GEOM_TYPE_POINT
See Also:
Constant Field Values

GEOM_TYPE_LINE

public static final int GEOM_TYPE_LINE
See Also:
Constant Field Values

GEOM_TYPE_POLYGON

public static final int GEOM_TYPE_POLYGON
See Also:
Constant Field Values

GEOM_TYPE_FACE

public static final int GEOM_TYPE_FACE
See Also:
Constant Field Values

GEOM_TYPE_KERNEL

public static final int GEOM_TYPE_KERNEL
See Also:
Constant Field Values

colorTableExt

public static final java.lang.String colorTableExt
See Also:
Constant Field Values

colorTableIdentifier

public static final java.lang.String colorTableIdentifier
See Also:
Constant Field Values

colorTableVersion

public static final java.lang.String colorTableVersion
See Also:
Constant Field Values

TEMP_PREFIX

public static final java.lang.String TEMP_PREFIX
See Also:
Constant Field Values
Constructor Detail

GrassUtils

public GrassUtils()
Method Detail

getProcess

public static java.lang.Process getProcess()

isProcessCanceled

public static boolean isProcessCanceled()

setInterruptible

public static void setInterruptible(boolean choice)

cancelProcess

public static void cancelProcess()

createStartupScript

public static java.io.File createStartupScript()
Creates a compact startup script for GRASS. The script code created may vary, depending on the operating system. This also creates a temporary GRASS settings file (GISCR).

Returns:
The file handler for the created script, NULL on failure.

getGrassExecutable

public static java.lang.ProcessBuilder getGrassExecutable()
Returns a ProcesBuilder ready to execute grass.

Returns:
a ProcesBuilder ready to execute grass

isSupported

public static boolean isSupported()

getBatchJobFile

public static java.lang.String getBatchJobFile()

getGroup

public static java.lang.String getGroup(GeoAlgorithm grass)
Return the group associated to a GRASS algorithm. The string is returns is already in the current locale language

Parameters:
grass - a GRASS algorithm
Returns:
The name of the group the given algorithm should be put into in the toolbox tree.

getTempMapName

public static java.lang.String getTempMapName(java.lang.String sPrefix)
Returns a GRASS map name which can be safely used to store an imported layer or any other GRASS element (a region setting, a group) that is significant in our context. When using the name returned by this function, there is virtually no chance that it will overwrite any existing data in the mapset. Note: valid GRASS MAP names must not contain spaces or special characters, must start on a letter and should not include "-" (minus)

Parameters:
sPrefix - a prefix for the temp map name

getTempMapName

public static java.lang.String getTempMapName()
Returns a GRASS map name which can be safely used to store an imported layer (i.e. there is no chance that it will overwrite an existing map in the mapset). Note: valid GRASS MAP names must not contain spaces or special characters, must start on a letter and should not include "-" (minus)


getNumGeoms

public static int getNumGeoms(java.lang.String sMapName,
                              int iGeomType)
                       throws GrassExecutionException
Returns the number of geometries of a specified type in a GRASS map. This methods runs the GRASS command "v.info" to obtain statistics for the GRASS map.

Parameters:
sMapName - Name of GRASS map to query
iGeomType - Type of geometry to query. Choices are: GEOM_TYPE_POINT, GEOM_TYPE_LINE, GEOM_TYPE_POLYGON
Throws:
GrassExecutionException

getNumPoints

public static int getNumPoints(java.lang.String sMapName)
                        throws GrassExecutionException
Returns the number of geometries of type POINT in a GRASS map. This methods runs the GRASS command "v.info" to obtain statistics for the GRASS map.

Parameters:
sMapName - Name of GRASS map to query
Throws:
GrassExecutionException

getNumLines

public static int getNumLines(java.lang.String sMapName)
                       throws GrassExecutionException
Returns the number of geometries of type LINE in a GRASS map. This methods runs the GRASS command "v.info" to obtain statistics for the GRASS map.

Parameters:
sMapName - Name of GRASS map to query
Throws:
GrassExecutionException

getNumPolygons

public static int getNumPolygons(java.lang.String sMapName)
                          throws GrassExecutionException
Returns the number of geometries of type POLYGON in a GRASS map. This methods runs the GRASS command "v.info" to obtain statistics for the GRASS map.

Parameters:
sMapName - Name of GRASS map to query
Throws:
GrassExecutionException

getNumFaces

public static int getNumFaces(java.lang.String sMapName)
                       throws GrassExecutionException
Returns the number of geometries of type FACE in a GRASS map. A face is a simple 3D polygon used to build triangulated 3D meshes. Some GRASS modules output 3D triangles (faces). Note: In GRASS, the entitites that are usually called "polygons" in any other GIS are actually called "areas" and they are topological objects, consisting of boundaries and centroids. Proper GRASS areas only exist if there are no major topological problems in the data (specifidally: overlap). Data with badly overlapping polygons cannot be processed in GRASS without topological cleaning. This methods runs the GRASS command "v.info" to obtain statistics for the GRASS map.

Parameters:
sMapName - Name of GRASS map to query
Throws:
GrassExecutionException

getNumKernels

public static int getNumKernels(java.lang.String sMapName)
                         throws GrassExecutionException
Returns the number of geometries of type KERNEL in a GRASS map. A kernel is a 3D point. It has the same function as a 2D centroid for an area in GRASS. However, threre is still a discussion about what is the full equivalent of a 2D area in 3D. So for the time being, we will just treat kernels like simple 3D points. This methods runs the GRASS command "v.info" to obtain statistics for the GRASS map.

Parameters:
sMapName - Name of GRASS map to query
Throws:
GrassExecutionException

isMap3D

public static boolean isMap3D(java.lang.String sMapName)
                       throws GrassExecutionException
Checks if a GRASS vector map contains 3D data. This methods runs the GRASS command "v.info" to obtain statistics for the GRASS map.

Parameters:
sMapName - Name of GRASS map to query
Throws:
GrassExecutionException

isLatLon

public static boolean isLatLon()
Checks if the current GRASS mapset (rather: the location of which it is part) works in lat/lon degrees. We need this information, because some GRASS modules do not work (well) with lat/lon input data.

Returns:
"true" if the current mapset works in lat/lon, "false" otherwise.

isMultiGeom

public static boolean isMultiGeom(java.lang.String sMapName)
                           throws GrassExecutionException
Throws:
GrassExecutionException

runGRASS

public static void runGRASS(java.lang.StringBuffer sCommand,
                            java.lang.String sMessage,
                            GrassAlgorithm alg)
                     throws GrassExecutionException
Runs a batch of GRASS commands.

Parameters:
sCommand - String buffer containing GRASS commands
sMessage - String with message to write into logfile
Throws:
GrassExecutionException

setExecutable

public static void setExecutable(java.lang.String pathname)
                          throws GrassExecutionException
A convenience method to set the owner's execute permission for this abstract pathname.

Parameters:
pathname - a pathname string
Throws:
GrassExecutionException

createTempMapset

public static void createTempMapset()
                             throws java.io.IOException
Creates a temporary location and mapset(s) for GRASS data processing. A minimal set of folders and files is created in the system's default temporary directory. The settings files are written with sane defaults, so GRASS can do its work. File structure and content will vary slightly depending on whether the user wants to process lat/lon or x/y data.

Throws:
java.io.IOException

deleteTempMapset

public static void deleteTempMapset()
Deletes the location and mapset(s) for GRASS data processing.


writeColorTable

public static void writeColorTable(Output out)

getComFile

public static java.io.File getComFile()

deleteComFile

public static void deleteComFile()