Skip to content
Permalink
Browse files
started grass algorithm provider
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@48 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Mar 21, 2012
1 parent b7d940e commit 772e8e7c67d61a2f76efb4f7e282e3e0f809b24b
Showing with 2,610 additions and 214 deletions.
  1. +1 −6 src/sextante/SextantePlugin.py
  2. +1 −2 src/sextante/core/GeoAlgorithm.py
  3. +25 −10 src/sextante/core/QGisLayers.py
  4. +3 −2 src/sextante/core/Sextante.py
  5. +8 −1 src/sextante/core/SextanteConfig.py
  6. +227 −0 src/sextante/grass/GrassAlgorithm.py
  7. +50 −0 src/sextante/grass/GrassAlgorithmProvider.py
  8. +235 −0 src/sextante/grass/GrassUtils.py
  9. 0 src/sextante/grass/__init__.py
  10. +6 −0 src/sextante/grass/description/alg_0.txt
  11. +6 −0 src/sextante/grass/description/alg_1.txt
  12. +6 −0 src/sextante/grass/description/alg_10.txt
  13. +6 −0 src/sextante/grass/description/alg_100.txt
  14. +9 −0 src/sextante/grass/description/alg_101.txt
  15. +16 −0 src/sextante/grass/description/alg_102.txt
  16. +6 −0 src/sextante/grass/description/alg_103.txt
  17. +14 −0 src/sextante/grass/description/alg_104.txt
  18. +11 −0 src/sextante/grass/description/alg_105.txt
  19. +4 −0 src/sextante/grass/description/alg_106.txt
  20. +12 −0 src/sextante/grass/description/alg_107.txt
  21. +11 −0 src/sextante/grass/description/alg_108.txt
  22. +5 −0 src/sextante/grass/description/alg_109.txt
  23. +8 −0 src/sextante/grass/description/alg_11.txt
  24. +6 −0 src/sextante/grass/description/alg_110.txt
  25. +6 −0 src/sextante/grass/description/alg_111.txt
  26. +9 −0 src/sextante/grass/description/alg_112.txt
  27. +11 −0 src/sextante/grass/description/alg_113.txt
  28. +6 −0 src/sextante/grass/description/alg_114.txt
  29. +22 −0 src/sextante/grass/description/alg_115.txt
  30. +9 −0 src/sextante/grass/description/alg_116.txt
  31. +14 −0 src/sextante/grass/description/alg_117.txt
  32. +8 −0 src/sextante/grass/description/alg_118.txt
  33. +7 −0 src/sextante/grass/description/alg_119.txt
  34. +15 −0 src/sextante/grass/description/alg_12.txt
  35. +9 −0 src/sextante/grass/description/alg_120.txt
  36. +7 −0 src/sextante/grass/description/alg_121.txt
  37. +30 −0 src/sextante/grass/description/alg_122.txt
  38. +18 −0 src/sextante/grass/description/alg_123.txt
  39. +26 −0 src/sextante/grass/description/alg_124.txt
  40. +10 −0 src/sextante/grass/description/alg_125.txt
  41. +7 −0 src/sextante/grass/description/alg_126.txt
  42. +10 −0 src/sextante/grass/description/alg_127.txt
  43. +6 −0 src/sextante/grass/description/alg_128.txt
  44. +7 −0 src/sextante/grass/description/alg_129.txt
  45. +17 −0 src/sextante/grass/description/alg_13.txt
  46. +6 −0 src/sextante/grass/description/alg_130.txt
  47. +9 −0 src/sextante/grass/description/alg_131.txt
  48. +11 −0 src/sextante/grass/description/alg_132.txt
  49. +6 −0 src/sextante/grass/description/alg_133.txt
  50. +6 −0 src/sextante/grass/description/alg_134.txt
  51. +7 −0 src/sextante/grass/description/alg_135.txt
  52. +12 −0 src/sextante/grass/description/alg_136.txt
  53. +6 −0 src/sextante/grass/description/alg_137.txt
  54. +6 −0 src/sextante/grass/description/alg_138.txt
  55. +23 −0 src/sextante/grass/description/alg_139.txt
  56. +8 −0 src/sextante/grass/description/alg_14.txt
  57. +5 −0 src/sextante/grass/description/alg_140.txt
  58. +5 −0 src/sextante/grass/description/alg_141.txt
  59. +20 −0 src/sextante/grass/description/alg_142.txt
  60. +9 −0 src/sextante/grass/description/alg_143.txt
  61. +6 −0 src/sextante/grass/description/alg_144.txt
  62. +7 −0 src/sextante/grass/description/alg_145.txt
  63. +5 −0 src/sextante/grass/description/alg_146.txt
  64. +11 −0 src/sextante/grass/description/alg_147.txt
  65. +8 −0 src/sextante/grass/description/alg_148.txt
  66. +12 −0 src/sextante/grass/description/alg_149.txt
  67. +8 −0 src/sextante/grass/description/alg_15.txt
  68. +20 −0 src/sextante/grass/description/alg_150.txt
  69. +9 −0 src/sextante/grass/description/alg_151.txt
  70. +11 −0 src/sextante/grass/description/alg_152.txt
  71. +8 −0 src/sextante/grass/description/alg_153.txt
  72. +5 −0 src/sextante/grass/description/alg_154.txt
  73. +4 −0 src/sextante/grass/description/alg_155.txt
  74. +8 −0 src/sextante/grass/description/alg_156.txt
  75. +13 −0 src/sextante/grass/description/alg_157.txt
  76. +17 −0 src/sextante/grass/description/alg_158.txt
  77. +21 −0 src/sextante/grass/description/alg_159.txt
  78. +5 −0 src/sextante/grass/description/alg_16.txt
  79. +18 −0 src/sextante/grass/description/alg_160.txt
  80. +6 −0 src/sextante/grass/description/alg_161.txt
  81. +7 −0 src/sextante/grass/description/alg_162.txt
  82. +6 −0 src/sextante/grass/description/alg_163.txt
  83. +8 −0 src/sextante/grass/description/alg_164.txt
  84. +10 −0 src/sextante/grass/description/alg_165.txt
  85. +14 −0 src/sextante/grass/description/alg_166.txt
  86. +5 −0 src/sextante/grass/description/alg_167.txt
  87. +4 −0 src/sextante/grass/description/alg_168.txt
  88. +7 −0 src/sextante/grass/description/alg_169.txt
  89. +11 −0 src/sextante/grass/description/alg_17.txt
  90. +10 −0 src/sextante/grass/description/alg_170.txt
  91. +20 −0 src/sextante/grass/description/alg_171.txt
  92. +8 −0 src/sextante/grass/description/alg_172.txt
  93. +10 −0 src/sextante/grass/description/alg_173.txt
  94. +10 −0 src/sextante/grass/description/alg_174.txt
  95. +11 −0 src/sextante/grass/description/alg_175.txt
  96. +14 −0 src/sextante/grass/description/alg_176.txt
  97. +11 −0 src/sextante/grass/description/alg_177.txt
  98. +8 −0 src/sextante/grass/description/alg_178.txt
  99. +4 −0 src/sextante/grass/description/alg_18.txt
  100. +19 −0 src/sextante/grass/description/alg_19.txt
  101. +6 −0 src/sextante/grass/description/alg_2.txt
  102. +8 −0 src/sextante/grass/description/alg_20.txt
  103. +6 −0 src/sextante/grass/description/alg_21.txt
  104. +10 −0 src/sextante/grass/description/alg_22.txt
  105. +6 −0 src/sextante/grass/description/alg_23.txt
  106. +5 −0 src/sextante/grass/description/alg_24.txt
  107. +6 −0 src/sextante/grass/description/alg_25.txt
  108. +6 −0 src/sextante/grass/description/alg_26.txt
  109. +9 −0 src/sextante/grass/description/alg_27.txt
  110. +10 −0 src/sextante/grass/description/alg_28.txt
  111. +9 −0 src/sextante/grass/description/alg_29.txt
  112. +7 −0 src/sextante/grass/description/alg_3.txt
  113. +20 −0 src/sextante/grass/description/alg_30.txt
  114. +10 −0 src/sextante/grass/description/alg_31.txt
  115. +9 −0 src/sextante/grass/description/alg_32.txt
  116. +5 −0 src/sextante/grass/description/alg_33.txt
  117. +15 −0 src/sextante/grass/description/alg_34.txt
  118. +10 −0 src/sextante/grass/description/alg_35.txt
  119. +11 −0 src/sextante/grass/description/alg_36.txt
  120. +4 −0 src/sextante/grass/description/alg_37.txt
  121. +10 −0 src/sextante/grass/description/alg_38.txt
  122. +11 −0 src/sextante/grass/description/alg_39.txt
  123. +7 −0 src/sextante/grass/description/alg_4.txt
  124. +21 −0 src/sextante/grass/description/alg_40.txt
  125. +11 −0 src/sextante/grass/description/alg_41.txt
  126. +5 −0 src/sextante/grass/description/alg_42.txt
  127. +8 −0 src/sextante/grass/description/alg_43.txt
  128. +18 −0 src/sextante/grass/description/alg_44.txt
  129. +6 −0 src/sextante/grass/description/alg_45.txt
  130. +33 −0 src/sextante/grass/description/alg_46.txt
  131. +12 −0 src/sextante/grass/description/alg_47.txt
  132. +12 −0 src/sextante/grass/description/alg_48.txt
  133. +9 −0 src/sextante/grass/description/alg_49.txt
  134. +12 −0 src/sextante/grass/description/alg_5.txt
  135. +3 −0 src/sextante/grass/description/alg_50.txt
  136. +8 −0 src/sextante/grass/description/alg_51.txt
  137. +5 −0 src/sextante/grass/description/alg_52.txt
  138. +9 −0 src/sextante/grass/description/alg_53.txt
  139. +12 −0 src/sextante/grass/description/alg_54.txt
  140. +5 −0 src/sextante/grass/description/alg_55.txt
  141. +12 −0 src/sextante/grass/description/alg_56.txt
  142. +5 −0 src/sextante/grass/description/alg_57.txt
  143. +4 −0 src/sextante/grass/description/alg_58.txt
  144. +5 −0 src/sextante/grass/description/alg_59.txt
  145. +6 −0 src/sextante/grass/description/alg_6.txt
  146. +19 −0 src/sextante/grass/description/alg_60.txt
  147. +23 −0 src/sextante/grass/description/alg_61.txt
  148. +6 −0 src/sextante/grass/description/alg_62.txt
  149. +16 −0 src/sextante/grass/description/alg_63.txt
  150. +9 −0 src/sextante/grass/description/alg_64.txt
  151. +4 −0 src/sextante/grass/description/alg_65.txt
  152. +6 −0 src/sextante/grass/description/alg_66.txt
  153. +10 −0 src/sextante/grass/description/alg_67.txt
  154. +5 −0 src/sextante/grass/description/alg_68.txt
  155. +8 −0 src/sextante/grass/description/alg_69.txt
  156. +12 −0 src/sextante/grass/description/alg_7.txt
  157. +9 −0 src/sextante/grass/description/alg_70.txt
  158. +12 −0 src/sextante/grass/description/alg_71.txt
  159. +6 −0 src/sextante/grass/description/alg_72.txt
  160. +7 −0 src/sextante/grass/description/alg_73.txt
  161. +10 −0 src/sextante/grass/description/alg_74.txt
  162. +5 −0 src/sextante/grass/description/alg_75.txt
  163. +13 −0 src/sextante/grass/description/alg_76.txt
  164. +5 −0 src/sextante/grass/description/alg_77.txt
  165. +11 −0 src/sextante/grass/description/alg_78.txt
  166. +17 −0 src/sextante/grass/description/alg_79.txt
  167. +9 −0 src/sextante/grass/description/alg_8.txt
  168. +11 −0 src/sextante/grass/description/alg_80.txt
  169. +33 −0 src/sextante/grass/description/alg_81.txt
  170. +7 −0 src/sextante/grass/description/alg_82.txt
  171. +19 −0 src/sextante/grass/description/alg_83.txt
  172. +5 −0 src/sextante/grass/description/alg_84.txt
  173. +8 −0 src/sextante/grass/description/alg_85.txt
  174. +9 −0 src/sextante/grass/description/alg_86.txt
  175. +7 −0 src/sextante/grass/description/alg_87.txt
  176. +14 −0 src/sextante/grass/description/alg_88.txt
  177. +19 −0 src/sextante/grass/description/alg_89.txt
  178. +6 −0 src/sextante/grass/description/alg_9.txt
  179. +11 −0 src/sextante/grass/description/alg_90.txt
  180. +24 −0 src/sextante/grass/description/alg_91.txt
  181. +6 −0 src/sextante/grass/description/alg_92.txt
  182. +18 −0 src/sextante/grass/description/alg_93.txt
  183. +6 −0 src/sextante/grass/description/alg_94.txt
  184. +16 −0 src/sextante/grass/description/alg_95.txt
  185. +9 −0 src/sextante/grass/description/alg_96.txt
  186. +8 −0 src/sextante/grass/description/alg_97.txt
  187. +12 −0 src/sextante/grass/description/alg_98.txt
  188. +20 −0 src/sextante/grass/description/alg_99.txt
  189. +27 −0 src/sextante/gui/HTMLViewerDialog.py
  190. +13 −1 src/sextante/gui/ParametersDialog.py
  191. BIN src/sextante/images/grass.png
  192. +28 −3 src/sextante/modeler/ModelerDialog.py
  193. +4 −1 src/sextante/parameters/ParameterString.py
  194. +0 −1 src/sextante/parameters/ParameterVector.py
  195. +157 −163 src/sextante/saga/SagaAlgorithm.py
  196. +0 −21 src/sextante/saga/SagaBlackList.py
  197. +0 −1 src/sextante/saga/SagaUtils.py
  198. +2 −2 src/sextante/saga/description/alg_142.txt
@@ -1,8 +1,6 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *


import os, sys
import inspect
from sextante.core.Sextante import Sextante
@@ -26,7 +24,7 @@ def __init__(self, iface):
self.iface = iface
QGisLayers.setInterface(iface)
Sextante.initialize()
Sextante .setInterface(iface)
Sextante.setInterface(iface)

def initGui(self):
self.toolbox = SextanteToolbox(self.iface)
@@ -77,9 +75,6 @@ def initGui(self):
QObject.connect(self.aboutAction, SIGNAL("triggered()"), self.openAbout)
self.menu.addAction(self.aboutAction)




menuBar = self.iface.mainWindow().menuBar()
menuBar.insertMenu(menuBar.actions()[-1], self.menu)

@@ -6,8 +6,6 @@
from PyQt4 import QtGui
import os.path
from sextante.core.SextanteUtils import SextanteUtils
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.parameters.ParameterBoolean import ParameterBoolean


class GeoAlgorithm:
@@ -20,6 +18,7 @@ def __init__(self):
self.defineCharacteristics()
self.providerName = ""
self.crs = None
self.helpfile = None

#methods to overwrite when creating a custom geoalgorithm
#=========================================================
@@ -3,6 +3,7 @@
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
from os import path
from sextante.core.SextanteConfig import SextanteConfig

class QGisLayers:

@@ -15,7 +16,7 @@ def getRasterLayers():
raster = list()

for layer in layers:
if layer.type() == layer.RasterLayer :
if layer.type() == layer.RasterLayer and not layer.usesProvider():
raster.append(layer)
return raster

@@ -24,7 +25,7 @@ def getVectorLayers(shapetype=-1):
layers = QGisLayers.iface.legendInterface().layers()
vector = list()
for layer in layers:
if layer.type() == layer.VectorLayer:
if layer.type() == layer.VectorLayer and not layer.usesProvider():
if shapetype == QGisLayers.ALL_TYPES or layer.geometryType() == shapetype:
vector.append(layer)
return vector
@@ -62,18 +63,32 @@ def load(layer, name = None, crs = None):
settings.setValue("/Projections/defaultBehaviour", QVariant(""))
if name == None:
name = path.split(layer)[1]
if layer.endswith("shp"):
qgslayer = QgsVectorLayer(layer, name, 'ogr')
qgslayer = QgsVectorLayer(layer, name , 'ogr')
if qgslayer.isValid():
if crs != None:
qgslayer.setCrs(crs, False)
qgslayer.setCrs(crs,False)
if qgslayer.geometryType == 0:
style = SextanteConfig.getSetting(SextanteConfig.VECTOR_POINT_STYLE)
elif qgslayer.geometryType == 1:
style = SextanteConfig.getSetting(SextanteConfig.VECTOR_LINE_STYLE)
else:
style = SextanteConfig.getSetting(SextanteConfig.VECTOR_POLYGON_STYLE)
qgslayer.loadNamedStyle(style)
QgsMapLayerRegistry.instance().addMapLayer(qgslayer)
else:
qgslayer = QgsRasterLayer(layer, name)
if crs != None:
qgslayer.setCrs(crs,False)
QgsMapLayerRegistry.instance().addMapLayer(qgslayer)
except Exception:
QtGui.QMessageBox(None, "Error", "Could not load layer: " + str(layer))
if qgslayer.isValid():
if crs != None:
qgslayer.setCrs(crs,False)

style = SextanteConfig.getSetting(SextanteConfig.RASTER_STYLE)
qgslayer.loadNamedStyle(style)
QgsMapLayerRegistry.instance().addMapLayer(qgslayer)
QGisLayers.iface.legendInterface().refreshLayerSymbology(qgslayer)
else:
QtGui.QMessageBox.critical(None, "Error", "Could not load layer: " + str(layer))
except Exception, e:
QtGui.QMessageBox.critical(None, "Error", "Could not load layer: " + str(layer))
finally:
if prjSetting:
settings.setValue("/Projections/defaultBehaviour", prjSetting)
@@ -1,6 +1,5 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
from sextante.saga.SagaAlgorithmProvider import SagaAlgorithmProvider
from sextante.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider
import copy
@@ -16,12 +15,14 @@
from sextante.modeler.ProviderIcons import ProviderIcons
from sextante.r.RAlgorithmProvider import RAlgorithmProvider
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.grass.GrassAlgorithmProvider import GrassAlgorithmProvider

class Sextante:

iface = None
providers = [SagaAlgorithmProvider(), ScriptAlgorithmProvider(),
MMQGISAlgorithmProvider(), FToolsAlgorithmProvider(), RAlgorithmProvider()]
MMQGISAlgorithmProvider(), FToolsAlgorithmProvider(),
RAlgorithmProvider(), GrassAlgorithmProvider()]
algs = {}
actions = {}
contextMenuActions = []
@@ -4,14 +4,21 @@
class SextanteConfig():

OUTPUT_FOLDER = "OUTPUT_FOLDER"
RASTER_STYLE = "RASTER_STYLE"
VECTOR_POINT_STYLE = "VECTOR_POINT_STYLE"
VECTOR_LINE_STYLE = "VECTOR_LINE_STYLE"
VECTOR_POLYGON_STYLE = "VECTOR_POLYGON_STYLE"

settings = {}

@staticmethod
def initialize():
SextanteConfig.addSetting(Setting("General", SextanteConfig.OUTPUT_FOLDER,
"Output folder", os.path.join(SextanteUtils.userFolder(),"outputs" )))

SextanteConfig.addSetting(Setting("General", SextanteConfig.RASTER_STYLE,"Style for raster layers",""))
SextanteConfig.addSetting(Setting("General", SextanteConfig.VECTOR_POINT_STYLE,"Style for point layers",""))
SextanteConfig.addSetting(Setting("General", SextanteConfig.VECTOR_LINE_STYLE,"Style for line layers",""))
SextanteConfig.addSetting(Setting("General", SextanteConfig.VECTOR_POLYGON_STYLE,"Style for polygon layers",""))

@staticmethod
def addSetting(setting):
@@ -0,0 +1,227 @@
import os
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.parameters.ParameterTable import ParameterTable
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.outputs.OutputRaster import OutputRaster
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.outputs.OutputVector import OutputVector
from sextante.saga.SagaUtils import SagaUtils
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.core.SextanteLog import SextanteLog
from sextante.parameters.ParameterFactory import ParameterFactory
from sextante.outputs.OutputFactory import OutputFactory
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.QGisLayers import QGisLayers
from sextante.grass.GrassUtils import GrassUtils
import time
from sextante.core.SextanteUtils import SextanteUtils

class GrassAlgorithm(GeoAlgorithm):

def __init__(self, descriptionfile):
GeoAlgorithm.__init__(self)
self._descriptionFile = descriptionfile
self.defineCharacteristicsFromFile()
self.numExportedLayers = 0
self.needsregion = False

def getIcon(self):
return QIcon(os.path.dirname(__file__) + "/../images/grass.png")

def defineCharacteristicsFromFile(self):
lines = open(self._descriptionFile)
line = lines.readline().strip("\n").strip()
self.name = line
line = lines.readline().strip("\n").strip()
self.group = line
while line != "":
try:
line = line.strip("\n").strip()
if line.startswith("Parameter"):
self.addParameter(ParameterFactory.getFromString(line))
elif line.startswith("Region"):
self.needsregion = True
else:
self.addOutput(OutputFactory.getFromString(line))
line = lines.readline().strip("\n").strip()
except Exception,e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + self._descriptionFile + "\n" + line)
raise e
lines.close()

def calculateResamplingExtent(self):
auto = SextanteConfig.getSetting(GrassUtils.GRASS_AUTO_REGION)
if auto:
first = True;
for param in self.parameters:
if isinstance(param, ParameterRaster):
if isinstance(param.value, QgsRasterLayer):
value = param.value
else:
value = QGisLayers.getObjectFromUri(param.value)
if first:
self.xmin = value.extent().xMinimum()
self.xmax = value.extent().xMaximum()
self.ymin = value.extent().yMinimum()
self.ymax = value.extent().yMaximum()
self.cellsize = (value.extent().xMaximum() - value.extent().xMinimum())/value.getRasterXDim()
first = False
else:
self.xmin = min(self.xmin, value.extent().xMinimum())
self.xmax = max(self.xmax, value.extent().xMaximum())
self.ymin = min(self.ymin, value.extent().yMinimum())
self.ymax = max(self.ymax, value.extent().yMaximum())
self.cellsize = max(self.cellsize, (value.extent().xMaximum() - value.extent().xMinimum())/value.getRasterXDim())
else:
self.xmin = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_XMIN)
self.xmax = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_XMAX)
self.ymin = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_YMIN)
self.ymax = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_YMAX)
self.cellsize = SextanteConfig.getSetting(SagaUtils.SAGA_RESAMPLING_REGION_CELLSIZE)


def processAlgorithm(self, progress):
path = GrassUtils.grassPath()
if path == "":
raise GeoAlgorithmExecutionException("GRASS folder is not configured.\nPlease configure it before running GRASS algorithms.")
useSelection = SextanteConfig.getSetting(SagaUtils.SAGA_USE_SELECTED)

commands = []
self.exportedLayers = {}
self.numExportedLayers = 0;

if self.needsregion:
self.calculateResamplingExtent()
GrassUtils.createTempMapset();

if self.needsregion:
command = "g.region"
command += " n=" + str(self.ymax)
command +=" s=" + str(self.ymin)
command +=" e=" + str(self.xmax)
command +=" w=" + str(self.xmin)
command +=" res=" + str(self.cellsize);
commands.append(command)

#1: Export layer to grass mapset
for param in self.parameters:
if isinstance(param, ParameterRaster):
if param.value == None:
continue
value = param.value
commands.append(self.exportRasterLayer(value))
if isinstance(param, ParameterVector):
if param.value == None:
continue
value = param.value
self.exportVectorLayer(value)
if isinstance(param, ParameterTable):
pass
if isinstance(param, ParameterMultipleInput):
if param.value == None:
continue
layers = param.value.split(";")
if layers == None or len(layers) == 0:
continue
if param.datatype == ParameterMultipleInput.TYPE_RASTER:
for layer in layers:
commands.append(self.exportRasterLayer(layer))
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
for layer in layers:
if (not value.endswith("shp")) or useSelection:
commands.append(self.exportRasterLayer(layer))

#2: set parameters and outputs
command = self.name
for param in self.parameters:
if param.value == None:
continue
if isinstance(param, (ParameterRaster, ParameterVector)):
value = param.value
if value in self.exportedLayers.keys():
command+=(" " + param.name + "=" + self.exportedLayers[value])
else:
command+=(" " + param.name + "=" + value)
elif isinstance(param, ParameterMultipleInput):
s = param.value
for layer in self.exportedLayers.keys():
s = s.replace(layer, self.exportedLayers[layer])
s = s.replace(";",",")
command+=(" " + param.name + "=" + s);
elif isinstance(param, ParameterBoolean):
if param.value:
command += param.name
else:
command+=(" " + param.name + "=" + str(param.value));

for out in self.outputs:
command+=(" " + out.name + "=" + out.name);

command += " --overwrite"
commands.append(command)

#3:Export resulting layers to a format that qgis can read
for out in self.outputs:
if isinstance(out, OutputRaster):
filename = out.value
#Raster layer output: adjust region to layer before exporting
commands.append("g.region rast=" + out.name)
command = "r.out.gdal -c createopt=\"TFW=YES,COMPRESS=LZW\""
command += " input="
command += out.name
command += " output=\"" + filename + "\""
commands.append(command)
if isinstance(out, OutputVector):
command = "v.out.ogr -e -z input=" + out.name
command += " dsn=\"" + os.path.dirname(out.value) + "\""
command += " format=ESRI_Shapefile"
command += " olayer=" + os.path.basename(out.value)
command += " type=auto"
commands.append(command)

#4 Run GRASS
GrassUtils.createGrassScript(commands)
loglines = []
loglines.append("GRASS execution commands")
for line in commands:
loglines.append(line)
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
GrassUtils.executeGrass(progress);


def exportVectorLayer(self, filename):
destFilename = self.getTempFilename()
self.exportedLayers[filename]= destFilename
command = "v.in.ogr"
command += " min_area=-1"
command +=" dsn=\"" + os.path.dirname(filename) + "\""
command +=" layer=" + os.path.basename(filename)
command +=" output=" + destFilename;
command +=" --overwrite -o"
return command


def exportRasterLayer(self, layer):
destFilename = self.getTempFilename()
self.exportedLayers[layer]= destFilename
command = "r.in.gdal"
command +=" input=\"" + layer + "\""
command +=" band=0"
command +=" out=" + destFilename;
command +=" --overwrite -o"
return command


def getTempFilename(self):
self.numExportedLayers+=1
filename = str(time.time()) + str(SextanteUtils.NUM_EXPORTED)
SextanteUtils.NUM_EXPORTED +=1

return filename


0 comments on commit 772e8e7

Please sign in to comment.