Skip to content

Commit

Permalink
Added PrameterCRS and CRS selectors
Browse files Browse the repository at this point in the history
Fixed GRASS bug when using v.* algorithms

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@135 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Apr 20, 2012
1 parent 66e027a commit 319e082
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/sextante/grass/GrassAlgorithm.py
Expand Up @@ -143,7 +143,7 @@ def processAlgorithm(self, progress):
if param.value == None:
continue
value = param.value
self.exportVectorLayer(value)
commands.append(self.exportVectorLayer(value))
if isinstance(param, ParameterTable):
pass
if isinstance(param, ParameterMultipleInput):
Expand Down Expand Up @@ -200,7 +200,7 @@ def processAlgorithm(self, progress):
command = "r.out.gdal -c createopt=\"TFW=YES,COMPRESS=LZW\""
command += " input="
command += out.name
command += " output=\"" + filename + "\""
command += " output=\"" + filename[:-4] + "\""
commands.append(command)
if isinstance(out, OutputVector):
command = "v.out.ogr -e input=" + out.name
Expand Down Expand Up @@ -242,7 +242,7 @@ def exportVectorLayer(self, orgFilename):
command = "v.in.ogr"
command += " min_area=-1"
command +=" dsn=\"" + os.path.dirname(filename) + "\""
command +=" layer=" + os.path.basename(filename)
command +=" layer=" + os.path.basename(filename)[:-4]
command +=" output=" + destFilename;
command +=" --overwrite -o"
return command
Expand All @@ -260,7 +260,7 @@ def exportRasterLayer(self, layer):


def getTempFilename(self):
filename = str(time.time()) + str(SextanteUtils.getNumExportedLayers())
filename = "tmp" + str(time.time()).replace(".","") + str(SextanteUtils.getNumExportedLayers())
return filename


2 changes: 1 addition & 1 deletion src/sextante/grass/GrassAlgorithmProvider.py
Expand Up @@ -55,7 +55,7 @@ def createAlgsList(self):
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + descriptionFile)
except Exception,e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + descriptionFile)
self.createDescriptionFiles()
#self.createDescriptionFiles()

def _loadAlgorithms(self):
self.algs = self.preloadedAlgs
Expand Down
27 changes: 27 additions & 0 deletions src/sextante/gui/CrsSelectionDialog.py
@@ -0,0 +1,27 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *

class CrsSelectionDialog(QDialog):

def __init__(self):
QDialog.__init__(self)
self.epsg = None
layout = QVBoxLayout()
self.selector = QgsProjectionSelector(self)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close)
layout.addWidget(self.selector)
layout.addWidget(buttonBox)
self.setLayout(layout)

self.connect(buttonBox, SIGNAL("accepted()"), self.okPressed)
self.connect(buttonBox, SIGNAL("rejected()"), self.cancelPressed)

def okPressed(self):
self.epsg = self.selector.selectedEpsg()
self.close()

def cancelPressed(self):
self.epsg = None
self.close()
35 changes: 35 additions & 0 deletions src/sextante/gui/CrsSelectionPanel.py
@@ -0,0 +1,35 @@
from PyQt4 import QtGui, QtCore
from sextante.core.SextanteUtils import SextanteUtils
from sextante.gui.CrsSelectionDialog import CrsSelectionDialog

class CrsSelectionPanel(QtGui.QWidget):

def __init__(self, default):
super(CrsSelectionPanel, self).__init__(None)
self.epsg = default
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.text = QtGui.QLineEdit()
self.text.setEnabled(False)
self.text.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text)
self.pushButton = QtGui.QPushButton()
self.pushButton.setText("...")
self.pushButton.clicked.connect(self.showSelectionDialog)
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)
self.setText()

def showSelectionDialog(self):
dialog = CrsSelectionDialog()
dialog.exec_()
if dialog.epsg:
self.epsg = str(dialog.epsg)
self.setText()

def setText(self):
self.text.setText("EPSG:" + str(self.epsg))

def getValue(self):
return self.epsg
8 changes: 3 additions & 5 deletions src/sextante/gui/ParametersDialog.py
Expand Up @@ -20,6 +20,7 @@

from sextante.gui.ParametersPanel import ParametersPanel
from sextante.parameters.ParameterFile import ParameterFile
from sextante.parameters.ParameterCrs import ParameterCrs

try:
_fromUtf8 = QtCore.QString.fromUtf8
Expand Down Expand Up @@ -124,7 +125,7 @@ def setParamValue(self, param, widget):
for index in widget.selectedoptions:
value.append(options[index])
return param.setValue(value)
elif isinstance(param, (ParameterNumber, ParameterFile)):
elif isinstance(param, (ParameterNumber, ParameterFile, ParameterCrs)):
return param.setValue(widget.getValue())
else:
return param.setValue(str(widget.text()))
Expand All @@ -142,11 +143,8 @@ def accept(self):
break
if iterateParam:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
#SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, self.alg.getAsCommand())
ret = AlgorithmExecutor.runalgIterating(self.alg, iterateParam, self)
AlgorithmExecutor.runalgIterating(self.alg, iterateParam, self)
QApplication.restoreOverrideCursor()
#if ret:
#SextantePostprocessing.handleAlgorithmResults(self.alg)
else:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, self.alg.getAsCommand())
Expand Down
4 changes: 4 additions & 0 deletions src/sextante/gui/ParametersPanel.py
Expand Up @@ -22,6 +22,8 @@
from sextante.core.SextanteConfig import SextanteConfig
from sextante.parameters.ParameterFile import ParameterFile
from sextante.gui.FileSelectionPanel import FileSelectionPanel
from sextante.parameters.ParameterCrs import ParameterCrs
from sextante.gui.CrsSelectionPanel import CrsSelectionPanel

class ParametersPanel(QtGui.QWidget):

Expand Down Expand Up @@ -198,6 +200,8 @@ def getWidgetFromParameter(self, param):
item = NumberInputPanel(param.default, param.isInteger)
elif isinstance(param, ParameterExtent):
item = ExtentSelectionPanel(self.paramDialog, param.default)
elif isinstance(param, ParameterCrs):
item = CrsSelectionPanel(param.default)
else:
item = QtGui.QLineEdit()
item.setText(str(param.default))
Expand Down
24 changes: 24 additions & 0 deletions src/sextante/parameters/ParameterCrs.py
@@ -0,0 +1,24 @@
from sextante.parameters.Parameter import Parameter

class ParameterCrs(Parameter):

def __init__(self, name="", description="", default = "4326"):
'''The values is the EPSG code of the CRS'''
self.name = name
self.description = description
self.value = None
self.default = default

def getValueAsCommandLineParameter(self):
return "\"" + str(self.value) + "\""

def serialize(self):
return self.__module__.split(".")[-1] + "|" + self.name + "|" + self.description +\
"|" + str(self.default)

def deserialize(self, s):
tokens = s.split("|")
return ParameterCrs(tokens[0], tokens[1], tokens[2])

def getAsScriptCode(self):
return "##" + self.name + "=crs " + str(self.default)
3 changes: 2 additions & 1 deletion src/sextante/parameters/ParameterFactory.py
Expand Up @@ -11,6 +11,7 @@
from sextante.parameters.ParameterFixedTable import ParameterFixedTable
from sextante.parameters.ParameterExtent import ParameterExtent
from sextante.parameters.ParameterFile import ParameterFile
from sextante.parameters.ParameterCrs import ParameterCrs

class ParameterFactory():

Expand All @@ -19,7 +20,7 @@ def getFromString(s):
classes = [ParameterBoolean, ParameterMultipleInput,ParameterNumber,
ParameterRaster, ParameterString, ParameterVector, ParameterTableField,
ParameterTable, ParameterSelection, ParameterRange, ParameterFixedTable,
ParameterExtent, ParameterFile]
ParameterExtent, ParameterFile, ParameterCrs]
for clazz in classes:
if s.startswith(clazz().parameterName()):
return clazz().deserialize(s[len(clazz().parameterName())+1:])

0 comments on commit 319e082

Please sign in to comment.