Skip to content

Commit 3eba62c

Browse files
author
volayaf@gmail.com
committed
Did some R and GRASS testing and debugging
Added the OTB folder with a skeleton of OTB alg provider git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@70 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
1 parent b86bbe5 commit 3eba62c

File tree

9 files changed

+59
-26
lines changed

9 files changed

+59
-26
lines changed

src/otb/OTBAlgorithmProvider.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os
2+
from PyQt4.QtCore import *
3+
from PyQt4.QtGui import *
4+
from sextante.core.AlgorithmProvider import AlgorithmProvider
5+
6+
class GdalAlgorithmProvider(AlgorithmProvider):
7+
8+
def __init__(self):
9+
AlgorithmProvider.__init__(self)
10+
self.createAlgsList()
11+
12+
def getName(self):
13+
return "OTB"
14+
15+
def getIcon(self):
16+
return QIcon(os.path.dirname(__file__) + "/icons/otb.png")
17+
18+
def _loadAlgorithms(self):
19+
self.algs = self.preloadedAlgs
20+
21+
def createAlgsList(self):
22+
self.preloadedAlgs = []
23+

src/otb/__init__.py

Whitespace-only changes.

src/sextante/core/SextanteConfig.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ class SextanteConfig():
1010
VECTOR_POLYGON_STYLE = "VECTOR_POLYGON_STYLE"
1111
SHOW_RECENT_ALGORITHMS = "SHOW_RECENT_ALGORITHMS"
1212
USE_SELECTED = "USE_SELECTED"
13+
USE_FILENAME_AS_LAYER_NAME = "USE_FILENAME_AS_LAYER_NAME"
1314

1415
settings = {}
1516

1617
@staticmethod
1718
def initialize():
1819
SextanteConfig.addSetting(Setting("General", SextanteConfig.USE_SELECTED, "Use only selected features in external application", True))
20+
SextanteConfig.addSetting(Setting("General", SextanteConfig.USE_FILENAME_AS_LAYER_NAME, "Use filename as layer name", True))
1921
SextanteConfig.addSetting(Setting("General", SextanteConfig.SHOW_RECENT_ALGORITHMS, "Show recently executed algorithms", True))
2022
SextanteConfig.addSetting(Setting("General", SextanteConfig.OUTPUT_FOLDER,
2123
"Output folder", SextanteUtils.tempFolder()))

src/sextante/gdal/GdalUtils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def getSupportedRasters():
3939
gdal.AllRegister()
4040

4141
GdalUtils.supportedRasters = {}
42+
GdalUtils.supportedRasters["GTiff"] = ["tif"]
4243
for i in range(gdal.GetDriverCount()):
4344
driver = gdal.GetDriver(i)
4445
if driver == None:

src/sextante/grass/GrassAlgorithm.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,14 @@ def calculateRegion(self):
7474
layer = param.value
7575
else:
7676
layer = QGisLayers.getObjectFromUri(param.value)
77-
self.addToResamplingExtent(layer, first)
77+
self.addToRegion(layer, first)
7878
first = False
7979
elif isinstance(param, ParameterMultipleInput):
80-
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
81-
layers = param.value.split(";")
82-
for layername in layers:
83-
layer = QGisLayers.getObjectFromUri(layername, first)
84-
self.addToResamplingExtent(layer, first)
85-
first = False
80+
layers = param.value.split(";")
81+
for layername in layers:
82+
layer = QGisLayers.getObjectFromUri(layername, first)
83+
self.addToRegion(layer, first)
84+
first = False
8685
else:
8786
self.xmin = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMIN)
8887
self.xmax = SextanteConfig.getSetting(GrassUtils.GRASS_REGION_XMAX)
@@ -93,11 +92,13 @@ def calculateRegion(self):
9392

9493
def addToRegion(self, layer, first):
9594
if first:
95+
self.cellsize = 0
9696
self.xmin = layer.extent().xMinimum()
9797
self.xmax = layer.extent().xMaximum()
9898
self.ymin = layer.extent().yMinimum()
9999
self.ymax = layer.extent().yMaximum()
100-
self.cellsize = (layer.extent().xMaximum() - layer.extent().xMinimum())/layer.width()
100+
if isinstance(layer, QgsRasterLayer):
101+
self.cellsize = (layer.extent().xMaximum() - layer.extent().xMinimum())/layer.width()
101102
else:
102103
self.xmin = min(self.xmin, layer.extent().xMinimum())
103104
self.xmax = max(self.xmax, layer.extent().xMaximum())
@@ -246,7 +247,7 @@ def exportRasterLayer(self, layer):
246247
self.exportedLayers[layer]= destFilename
247248
command = "r.in.gdal"
248249
command +=" input=\"" + layer + "\""
249-
command +=" band=0"
250+
command +=" band=1"
250251
command +=" out=" + destFilename;
251252
command +=" --overwrite -o"
252253
return command

src/sextante/grass/GrassUtils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def createGrassScript(commands):
7373

7474
#temporary gisrc file
7575
output = open(gisrc, "w")
76-
mapset = "temp_mapset"
7776
location = "temp_location"
77+
mapset = "user"
7878
gisdbase = os.path.join(os.path.expanduser("~"), "sextante", "tempdata", "grassdata")
7979
output.write("GISDBASE: " + gisdbase + "\n");
8080
output.write("LOCATION_NAME: " + location + "\n");
@@ -83,11 +83,10 @@ def createGrassScript(commands):
8383
output.close();
8484

8585
output=open(script, "w")
86-
shToolsPath = os.path.basename(shell)
8786
output.write("set HOME=" + os.path.expanduser("~") + "\n");
8887
output.write("set GISRC=" + gisrc + "\n")
89-
output.write("set GRASS_SH=" + shell + "\n")
90-
output.write("set PATH=" + shToolsPath + os.sep + "bin;" + shToolsPath + os.sep + "lib;" + "%PATH%\n")
88+
output.write("set GRASS_SH=" + shell + "\\bin\\sh.exe\n")
89+
output.write("set PATH=" + shell + os.sep + "bin;" + shell + os.sep + "lib;" + "%PATH%\n")
9190
output.write("set WINGISBASE=" + folder + "\n")
9291
output.write("set GISBASE=" + folder + "\n");
9392
output.write("set GRASS_PROJSHARE=" + folder + os.sep + "share" + os.sep + "proj" + "\n")
@@ -104,9 +103,9 @@ def createGrassScript(commands):
104103
output.write("set PATHEXT=%PATHEXT%;.PY\n")
105104
output.write("set PYTHONPATH=%PYTHONPATH%;%WINGISBASE%\\etc\\python;%WINGISBASE%\\etc\\wxpython\\n");
106105
output.write("\n")
107-
output.write("g.gisenv.exe set=\"MAPSET=" + mapset + "\"\n")
108-
output.write("g.gisenv.exe set=\"LOCATION=" + location + "\"\n")
109-
output.write("g.gisenv.exe set=\"LOCATION_NAME=" + location + "\"\n")
106+
output.write("g.gisenv.exe set=\"MAPSET= " + mapset + "\n")
107+
output.write("g.gisenv.exe set=\"LOCATION=" + location + "\n")
108+
output.write("g.gisenv.exe set=\"LOCATION_NAME=" + location + "\n")
110109
output.write("g.gisenv.exe set=\"GISDBASE=" + gisdbase + "\"\n")
111110
output.write("g.gisenv.exe set=\"GRASS_GUI=text\"\n")
112111
for command in commands:
@@ -125,7 +124,7 @@ def createGrassBatchJobFileFromGrassCommands(commands):
125124

126125
@staticmethod
127126
def grassMapsetFolder():
128-
tempfolder = os.path.join(os.path.expanduser("~"), "sextante", "tempdata", "grassdata", "temp_location", "temp_mapset")
127+
tempfolder = os.path.join(os.path.expanduser("~"), "sextante", "tempdata", "grassdata", "temp_location")
129128
mkdir(tempfolder)
130129
return tempfolder
131130

@@ -141,7 +140,7 @@ def createTempMapset():
141140
mkdir(os.path.join(folder, "PERMANENT"))
142141
mkdir(os.path.join(folder, "user"))
143142
mkdir(os.path.join(folder, "PERMANENT", ".tmp"))
144-
mkdir(os.path.join(folder, "PERMANENT", "DEFAULT_WIND"))
143+
GrassUtils.writeGrassWindow(os.path.join(folder, "PERMANENT", "DEFAULT_WIND"));
145144
outfile = open(os.path.join(folder, "PERMANENT", "MYNAME"), "w")
146145
if not latlon:
147146
outfile.write("SEXTANTE GRASS interface: temporary x/y data processing location.\n");
@@ -229,10 +228,11 @@ def executeGrass(commands, progress):
229228
for line in iter(proc.readline, ""):
230229
if "GRASS_INFO_PERCENT" in line:
231230
try:
232-
progress.setPercentage(line[line.rfind(":") + 2:])
231+
progress.setPercentage(int(line[len("GRASS_INFO_PERCENT")+ 2:]))
233232
except:
234233
pass
235-
loglines.append(line)
234+
else:
235+
loglines.append(line)
236236
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
237237
shutil.rmtree(GrassUtils.grassMapsetFolder(), True)
238238

src/sextante/gui/SextantePostprocessing.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from sextante.gui.RenderingStyles import RenderingStyles
88
from sextante.outputs.OutputHTML import OutputHTML
99
from PyQt4.QtGui import *
10+
from sextante.core.SextanteConfig import SextanteConfig
11+
import os
1012
class SextantePostprocessing:
1113

1214
@staticmethod
@@ -17,7 +19,11 @@ def handleAlgorithmResults(alg):
1719
continue
1820
if isinstance(out, (OutputRaster, OutputVector, OutputTable)):
1921
try:
20-
QGisLayers.load(out.value, out.description, alg.crs, RenderingStyles.getStyle(alg.commandLineName(),out.name))
22+
if SextanteConfig.getSetting(SextanteConfig.USE_FILENAME_AS_LAYER_NAME):
23+
name = os.path.basename(out.value)
24+
else:
25+
name = out.description
26+
QGisLayers.load(out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(),out.name))
2127
except Exception, e:
2228
QMessageBox.critical(None, "Error", str(e))
2329
elif isinstance(out, OutputHTML):

src/sextante/r/RAlgorithm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self, descriptionfile):
3636
self.defineCharacteristicsFromFile()
3737

3838
def getIcon(self):
39-
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/script.png")
39+
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/r.png")
4040

4141
def defineCharacteristicsFromFile(self):
4242
self.script = ""
@@ -212,7 +212,7 @@ def getImportCommands(self):
212212
filename = os.path.basename(value)
213213
filename = filename[:-4]
214214
commands.append(param.name + " = readOGR(\"" + value + "\",layer=\"" + filename + "\")")
215-
if isinstance(param, ParameterVector):
215+
if isinstance(param, ParameterTable):
216216
value = param.value
217217
if not value.lower().endswith("csv"):
218218
raise GeoAlgorithmExecutionException("Unsupported input file format.\n" + value)

src/sextante/r/RUtils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from PyQt4.QtGui import *
12
from sextante.core.SextanteConfig import SextanteConfig
23
import os
34
from sextante.core.SextanteUtils import mkdir, SextanteUtils
@@ -69,8 +70,8 @@ def createConsoleOutput():
6970
RUtils.allConsoleResults = []
7071
add = False
7172
lines = open(RUtils.getConsoleOutputFilename())
72-
line = lines.readline().strip("\n").strip(" ")
73-
while line != "":
73+
for line in lines:
74+
line = line.strip("\n").strip(" ")
7475
if line.startswith(">"):
7576
line = line[1:].strip(" ")
7677
if line in RUtils.verboseCommands:
@@ -80,7 +81,6 @@ def createConsoleOutput():
8081
elif add:
8182
RUtils.consoleResults.append("<p>" + line + "</p>\n");
8283
RUtils.allConsoleResults.append(line);
83-
line = lines.readline().strip("\n").strip(" ")
8484

8585

8686
@staticmethod

0 commit comments

Comments
 (0)