132 changes: 80 additions & 52 deletions python/plugins/sextante/grass/GrassUtils.py
Original file line number Diff line number Diff line change
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
16 changes: 16 additions & 0 deletions python/plugins/sextante/grass/description/v.db.select.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
v.db.select
v.db.select - Prints vector map attributes
Vector (v.*)
ParameterVector|map|Name of input vector map |-1|False
ParameterNumber|layer|Layer Number|1|None|1
ParameterString|columns|Name of attribute column(s), comma separated|
ParameterBoolean|-c|Do not include column names in output|False
ParameterString|fs|Output field separator|,
*ParameterString|where|WHERE conditions of SQL statement without 'where' keyword|
*ParameterString|vs|Output vertical record separator|
*ParameterString|nv|Null value indicator|
*ParameterBoolean|-v|Vertical output (instead of horizontal)|False
*ParameterBoolean|-r|Print minimal region extent of selected vector features instead of attributes|False
ParameterString|file|Name for output file|


2 changes: 1 addition & 1 deletion python/plugins/sextante/r/RAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def processAlgorithm(self, progress):
f.close()
if self.showConsoleOutput:
htmlfilename = self.getOutputValue(RAlgorithm.R_CONSOLE_OUTPUT)
f = open(htmlfilename)
f = open(htmlfilename, "w")
f.write(RUtils.getConsoleOutput())
f.close()

Expand Down
5 changes: 2 additions & 3 deletions python/plugins/sextante/saga/SagaAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ def processAlgorithm(self, progress):
f.close()
command+=( " -" + param.name + " " + tempTableFile)
elif isinstance(param, ParameterExtent):
#'we have to substract half cell size, since saga is center based, not corner based
#'we have to substract/add half cell size, since saga is center based, not corner based
halfcell = self.getOutputCellsize() / 2
offset = [halfcell, 0, halfcell, 0]
offset = [halfcell, -halfcell, halfcell, -halfcell]
values = param.value.split(",")
for i in range(4):
command+=(" -" + self.extentParamNames[i] + " " + str(float(values[i]) + offset[i]));
Expand Down Expand Up @@ -326,7 +326,6 @@ def getOutputCellsize(self):
if param.value is not None and param.name == "USER_SIZE":
cellsize = float(param.value)
break;
QtGui.QMessageBox.critical(None, "", str(cellsize));
return cellsize


Expand Down