Expand Up
@@ -46,20 +46,23 @@ class GrassUtils:
GRASS_WIN_SHELL = "GRASS_WIN_SHELL"
GRASS_LOG_COMMANDS = "GRASS_LOG_COMMANDS"
GRASS_LOG_CONSOLE = "GRASS_LOG_CONSOLE"
sessionRunning = False
sessionLayers = {}
@staticmethod
def grassBatchJobFilename ():
'''This is used in linux. This is the batch job that we assign to
GRASS_BATCH_JOB and then call GRASS and let it do the work'''
filename = "grass_batch_job.sh" ;
filename = "grass_batch_job.sh"
batchfile = SextanteUtils .userFolder () + os .sep + filename
return batchfile
@staticmethod
def grassScriptFilename ():
'''this is used in windows. We create a script that initializes
GRASS and then uses grass commands'''
filename = "grass_script.bat" ;
filename = "grass_script.bat"
filename = SextanteUtils .userFolder () + os .sep + filename
return filename
Expand Down
Expand Up
@@ -131,7 +134,7 @@ def createGrassScript(commands):
output .write ("LOCATION_NAME: " + location + "\n " );
output .write ("MAPSET: " + mapset + "\n " );
output .write ("GRASS_GUI: text\n " );
output .close ();
output .close ()
output = open (script , "w" )
output .write ("set HOME=" + os .path .expanduser ("~" ) + "\n " );
Expand All
@@ -146,13 +149,13 @@ def createGrassScript(commands):
output .write ("if \" %GRASS_ADDON_PATH%\" ==\" \" set PATH=%WINGISBASE%\\ bin;%WINGISBASE%\\ lib;%PATH%\n " )
output .write ("if not \" %GRASS_ADDON_PATH%\" ==\" \" set PATH=%WINGISBASE%\\ bin;%WINGISBASE%\\ lib;%GRASS_ADDON_PATH%;%PATH%\n " )
output .write ("\n " )
output .write ("set GRASS_VERSION=" + GrassUtils .getGrassVersion () + "\n " );
output .write ("if not \" %LANG%\" ==\" \" goto langset\n " );
output .write ("FOR /F \" usebackq delims==\" %%i IN (`\" %WINGISBASE%\\ etc\\ winlocale\" `) DO @set LANG=%%i\n " );
output .write ("set GRASS_VERSION=" + GrassUtils .getGrassVersion () + "\n " )
output .write ("if not \" %LANG%\" ==\" \" goto langset\n " )
output .write ("FOR /F \" usebackq delims==\" %%i IN (`\" %WINGISBASE%\\ etc\\ winlocale\" `) DO @set LANG=%%i\n " )
output .write (":langset\n " )
output .write ("\n " )
output .write ("set PATHEXT=%PATHEXT%;.PY\n " )
output .write ("set PYTHONPATH=%PYTHONPATH%;%WINGISBASE%\\ etc\\ python;%WINGISBASE%\\ etc\\ wxpython\\ n" );
output .write ("set PYTHONPATH=%PYTHONPATH%;%WINGISBASE%\\ etc\\ python;%WINGISBASE%\\ etc\\ wxpython\\ n" )
output .write ("\n " )
output .write ("g.gisenv.exe set=\" MAPSET=" + mapset + "\" \n " )
output .write ("g.gisenv.exe set=\" LOCATION=" + location + "\" \n " )
Expand Down
Expand Up
@@ -196,7 +199,7 @@ def createTempMapset():
if not latlon :
outfile .write ("SEXTANTE GRASS interface: temporary x/y data processing location.\n " );
else :
outfile .write ("SEXTANTE GRASS interface: temporary lat/lon data processing location.\n " );
outfile .write ("SEXTANTE GRASS interface: temporary lat/lon data processing location.\n " )
outfile .close ();
if latlon :
outfile = open (os .path .join (folder , "PERMANENT" , "PROJ_INFO" ), "w" )
Expand All
@@ -205,61 +208,61 @@ def createTempMapset():
outfile .write ("ellps: wgs84\n " )
outfile .close ()
outfile = open (os .path .join (folder , "PERMANENT" , "PROJ_UNITS" ), "w" )
outfile .write ("unit: degree\n " );
outfile .write ("units: degrees\n " );
outfile .write ("meters: 1.0\n " );
outfile .write ("unit: degree\n " )
outfile .write ("units: degrees\n " )
outfile .write ("meters: 1.0\n " )
outfile .close ();
GrassUtils .writeGrassWindow (os .path .join (folder , "PERMANENT" , "WIND" ));
GrassUtils .writeGrassWindow (os .path .join (folder , "PERMANENT" , "WIND" ))
mkdir (os .path .join (folder , "user" , "dbf" ))
mkdir (os .path .join (folder , "user" , ".tmp" ))
outfile = open (os .path .join (folder , "user" , "VAR" ), "w" )
outfile .write ("DB_DRIVER: dbf\n " );
outfile .write ("DB_DATABASE: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\n " );
outfile .write ("DB_DRIVER: dbf\n " )
outfile .write ("DB_DATABASE: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\n " )
outfile .close ()
GrassUtils .writeGrassWindow (os .path .join (folder , "user" , "WIND" ));
GrassUtils .writeGrassWindow (os .path .join (folder , "user" , "WIND" ))
@staticmethod
def writeGrassWindow (filename ):
out = open (filename , "w" )
latlon = SextanteConfig .getSetting (GrassUtils .GRASS_LATLON )
if not latlon :
out .write ("proj: 0\n " );
out .write ("zone: 0\n " );
out .write ("north: 1\n " );
out .write ("south: 0\n " );
out .write ("east: 1\n " );
out .write ("west: 0\n " );
out .write ("cols: 1\n " );
out .write ("rows: 1\n " );
out .write ("e-w resol: 1\n " );
out .write ("n-s resol: 1\n " );
out .write ("top: 1\n " );
out .write ("bottom: 0\n " );
out .write ("cols3: 1\n " );
out .write ("rows3: 1\n " );
out .write ("depths: 1\n " );
out .write ("e-w resol3: 1\n " );
out .write ("n-s resol3: 1\n " );
out .write ("t-b resol: 1\n " );
out .write ("proj: 0\n " )
out .write ("zone: 0\n " )
out .write ("north: 1\n " )
out .write ("south: 0\n " )
out .write ("east: 1\n " )
out .write ("west: 0\n " )
out .write ("cols: 1\n " )
out .write ("rows: 1\n " )
out .write ("e-w resol: 1\n " )
out .write ("n-s resol: 1\n " )
out .write ("top: 1\n " )
out .write ("bottom: 0\n " )
out .write ("cols3: 1\n " )
out .write ("rows3: 1\n " )
out .write ("depths: 1\n " )
out .write ("e-w resol3: 1\n " )
out .write ("n-s resol3: 1\n " )
out .write ("t-b resol: 1\n " )
else :
out .write ("proj: 3\n " );
out .write ("zone: 0\n " );
out .write ("north: 1N\n " );
out .write ("south: 0\n " );
out .write ("east: 1E\n " );
out .write ("west: 0\n " );
out .write ("cols: 1\n " );
out .write ("rows: 1\n " );
out .write ("e-w resol: 1\n " );
out .write ("n-s resol: 1\n " );
out .write ("top: 1\n " );
out .write ("bottom: 0\n " );
out .write ("cols3: 1\n " );
out .write ("rows3: 1\n " );
out .write ("depths: 1\n " );
out .write ("e-w resol3: 1\n " );
out .write ("n-s resol3: 1\n " );
out .write ("t-b resol: 1\n " );
out .write ("proj: 3\n " )
out .write ("zone: 0\n " )
out .write ("north: 1N\n " )
out .write ("south: 0\n " )
out .write ("east: 1E\n " )
out .write ("west: 0\n " )
out .write ("cols: 1\n " )
out .write ("rows: 1\n " )
out .write ("e-w resol: 1\n " )
out .write ("n-s resol: 1\n " )
out .write ("top: 1\n " )
out .write ("bottom: 0\n " )
out .write ("cols3: 1\n " )
out .write ("rows3: 1\n " )
out .write ("depths: 1\n " )
out .write ("e-w resol3: 1\n " )
out .write ("n-s resol3: 1\n " )
out .write ("t-b resol: 1\n " )
out .close ()
Expand Down
Expand Up
@@ -293,15 +296,40 @@ def executeGrass(commands, progress):
progress .setConsoleInfo (line )
if SextanteConfig .getSetting (GrassUtils .GRASS_LOG_CONSOLE ):
SextanteLog .addToLog (SextanteLog .LOG_INFO , loglines )
shutil .rmtree (GrassUtils .grassMapsetFolder (), True )
@staticmethod
def getGrassVersion ():
#I do not know if this should be removed or let the user enter it
#or something like that... This is just a temporary thing
return "6.4.0"
# GRASS session is used to hold the layers already exported or produced in GRASS
# between multiple calls to GRASS algorithms. This way they don't have
# to be loaded multiple times and following algorithms can use the results
# of the previous ones.
# Starting a session just involves creating the temp mapset structure
@staticmethod
def startGrassSession ():
if not GrassUtils .sessionRunning :
GrassUtils .createTempMapset ()
GrassUtils .sessionRunning = True
# End session by removing the temporary GRASS mapset and all the layers.
@staticmethod
def endGrassSession ():
shutil .rmtree (GrassUtils .grassMapsetFolder (), True )
GrassUtils .sessionRunning = False
GrassUtils .sessionLayers = {}
@staticmethod
def getSessionLayers ():
return GrassUtils .sessionLayers
@staticmethod
def addSessionLayers (exportedLayers ):
GrassUtils .sessionLayers = dict (GrassUtils .sessionLayers .items () + exportedLayers .items ())
Expand Down