Navigation Menu

Skip to content

Commit

Permalink
Made OTB configurable also in linux
Browse files Browse the repository at this point in the history
Added extent parameter

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@74 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf@gmail.com committed Apr 13, 2012
1 parent 5d225c3 commit 8dd4574
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 18 deletions.
43 changes: 43 additions & 0 deletions src/sextante/gui/ExtentSelectionPanel.py
@@ -0,0 +1,43 @@
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.gui.RectangleMapTool import RectangleMapTool
from sextante.core.QGisLayers import QGisLayers


class ExtentSelectionPanel(QtGui.QWidget):

def __init__(self, default):
super(ExtentSelectionPanel, self).__init__(None)
self.setObjectName("ESPanel")
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.setObjectName("hLayout")
self.text = QtGui.QLineEdit()
self.text.setObjectName("label")
self.text.setText(default)
self.text.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.horizontalLayout.addWidget(self.text)
self.pushButton = QtGui.QPushButton()
self.pushButton.setObjectName("pushButton")
self.pushButton.setText("...")
self.pushButton.clicked.connect(self.buttonPushed)
self.horizontalLayout.addWidget(self.pushButton)
self.setLayout(self.horizontalLayout)
canvas = QGisLayers.iface.mapCanvas()
self.prevMapTool = canvas.mapTool()
self.tool = RectangleMapTool(canvas)
self.connect(self.tool, SIGNAL("rectangleCreated()"), self.fillCoords)

def buttonPushed(self):
canvas = QGisLayers.iface.mapCanvas()
canvas.setMapTool(self.tool)

def fillCoords(self):
self.text.setText(str(self.tool.rectangle()))
canvas = QGisLayers.iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)

def getValue(self):
return str(self.text.text())
4 changes: 4 additions & 0 deletions src/sextante/gui/ParametersDialog.py
Expand Up @@ -23,6 +23,8 @@
from sextante.gui.NumberInputPanel import NumberInputPanel
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.gui.InputLayerSelectorPanel import InputLayerSelectorPanel
from sextante.parameters.ParameterExtent import ParameterExtent
from sextante.gui.ExtentSelectionPanel import ExtentSelectionPanel

try:
_fromUtf8 = QtCore.QString.fromUtf8
Expand Down Expand Up @@ -185,6 +187,8 @@ def getWidgetFromParameter(self, param):
item = MultipleInputPanel(opts)
elif isinstance(param, ParameterNumber):
item = NumberInputPanel(param.default)
elif isinstance(param, ParameterExtent):
item = ExtentSelectionPanel(param.default)
else:
item = QtGui.QLineEdit()
item.setText(str(param.default))
Expand Down
80 changes: 80 additions & 0 deletions src/sextante/gui/RectangleMapTool.py
@@ -0,0 +1,80 @@
'''Class taken from GdalTools'''
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *

class RectangleMapTool(QgsMapToolEmitPoint):
def __init__(self, canvas):
self.canvas = canvas
QgsMapToolEmitPoint.__init__(self, self.canvas)

self.rubberBand = QgsRubberBand( self.canvas, True ) # true, its a polygon
self.rubberBand.setColor( Qt.red )
self.rubberBand.setWidth( 1 )

self.reset()

def reset(self):
self.startPoint = self.endPoint = None
self.isEmittingPoint = False
self.rubberBand.reset( True ) # true, its a polygon

def canvasPressEvent(self, e):
self.startPoint = self.toMapCoordinates( e.pos() )
self.endPoint = self.startPoint
self.isEmittingPoint = True

self.showRect(self.startPoint, self.endPoint)

def canvasReleaseEvent(self, e):
self.isEmittingPoint = False
if self.rectangle() != None:
self.emit( SIGNAL("rectangleCreated()") )

def canvasMoveEvent(self, e):
if not self.isEmittingPoint:
return

self.endPoint = self.toMapCoordinates( e.pos() )
self.showRect(self.startPoint, self.endPoint)

def showRect(self, startPoint, endPoint):
self.rubberBand.reset( True ) # true, it's a polygon
if startPoint.x() == endPoint.x() or startPoint.y() == endPoint.y():
return

point1 = QgsPoint(startPoint.x(), startPoint.y())
point2 = QgsPoint(startPoint.x(), endPoint.y())
point3 = QgsPoint(endPoint.x(), endPoint.y())
point4 = QgsPoint(endPoint.x(), startPoint.y())

self.rubberBand.addPoint( point1, False )
self.rubberBand.addPoint( point2, False )
self.rubberBand.addPoint( point3, False )
self.rubberBand.addPoint( point4, True ) # true to update canvas
self.rubberBand.show()

def rectangle(self):
if self.startPoint == None or self.endPoint == None:
return None
elif self.startPoint.x() == self.endPoint.x() or self.startPoint.y() == self.endPoint.y():
return None

return QgsRectangle(self.startPoint, self.endPoint)

def setRectangle(self, rect):
if rect == self.rectangle():
return False

if rect == None:
self.reset()
else:
self.startPoint = QgsPoint(rect.xMaximum(), rect.yMaximum())
self.endPoint = QgsPoint(rect.xMinimum(), rect.yMinimum())
self.showRect(self.startPoint, self.endPoint)
return True

def deactivate(self):
QgsMapTool.deactivate(self)
self.emit(SIGNAL("deactivated()"))
3 changes: 0 additions & 3 deletions src/sextante/gui/SextanteToolbox.py
Expand Up @@ -86,16 +86,13 @@ def editRenderingStyles(self):
dlg = EditRenderingStylesDialog(alg)
dlg.exec_()


def executeAlgorithmAsBatchProcess(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
alg = Sextante.getAlgorithm(item.alg.commandLineName())
dlg = BatchProcessingDialog(alg)
dlg.exec_()



def executeAlgorithm(self):
item = self.algorithmTree.currentItem()
if isinstance(item, TreeAlgorithmItem):
Expand Down
9 changes: 4 additions & 5 deletions src/sextante/otb/OTBAlgorithm.py
Expand Up @@ -56,11 +56,10 @@ def defineCharacteristicsFromFile(self):


def processAlgorithm(self, progress):
if SextanteUtils.isWindows():
path = OTBUtils.otbPath()
libpath = OTBUtils.otbLibPath()
if path == "" or libpath == "":
raise GeoAlgorithmExecutionException("OTB folder is not configured.\nPlease configure it before running OTB algorithms.")
path = OTBUtils.otbPath()
libpath = OTBUtils.otbLibPath()
if path == "" or libpath == "":
raise GeoAlgorithmExecutionException("OTB folder is not configured.\nPlease configure it before running OTB algorithms.")

commands = []
commands.append(path + os.sep + self.cliName)
Expand Down
10 changes: 4 additions & 6 deletions src/sextante/otb/OTBAlgorithmProvider.py
Expand Up @@ -38,12 +38,10 @@ def createAlgsList(self):

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
if SextanteUtils.isWindows():
SextanteConfig.addSetting(Setting("OTB", OTBUtils.OTB_FOLDER, "OTB folder", OTBUtils.otbPath()))
SextanteConfig.addSetting(Setting("OTB", OTBUtils.OTB_LIB_FOLDER, "OTB library folder", OTBUtils.otbLibPath()))
SextanteConfig.addSetting(Setting("OTB", OTBUtils.OTB_FOLDER, "OTB folder", OTBUtils.otbPath()))
SextanteConfig.addSetting(Setting("OTB", OTBUtils.OTB_LIB_FOLDER, "OTB library folder", OTBUtils.otbLibPath()))

def unload(self):
AlgorithmProvider.unload(self)
if SextanteUtils.isWindows():
SextanteConfig.removeSetting(OTBUtils.OTB_FOLDER)
SextanteConfig.removeSetting(OTBUtils.OTB_LIB_FOLDER)
SextanteConfig.removeSetting(OTBUtils.OTB_FOLDER)
SextanteConfig.removeSetting(OTBUtils.OTB_LIB_FOLDER)
1 change: 1 addition & 0 deletions src/sextante/otb/OTBUtils.py
Expand Up @@ -2,6 +2,7 @@
import subprocess
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.SextanteLog import SextanteLog
from sextante.core.SextanteUtils import SextanteUtils

class OTBUtils:

Expand Down
34 changes: 34 additions & 0 deletions src/sextante/parameters/ParameterExtent.py
@@ -0,0 +1,34 @@
from sextante.parameters.Parameter import Parameter

class ParameterExtent(Parameter):
def __init__(self, name="", description="", default="0,1,0,1"):
self.name = name
self.description = description
self.default = default
self.value = None #The value is a string in the form "N,S,E,W"

def setValue(self, text):
tokens = text.split(",")
if len(tokens)!= 4:
return False
try:
n1 = float(tokens[0])
n2 = float(tokens[1])
n3 = float(tokens[2])
n4 = float(tokens[3])
self.value=text
return True
except:
return False

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 ParameterExtent(tokens[0], tokens[1], tokens[2])

2 changes: 2 additions & 0 deletions src/sextante/parameters/ParameterFixedTable.py
Expand Up @@ -12,10 +12,12 @@ def __init__(self, name="", description="", cols=["value"], numRows=3, fixedNumO
self.value = None

def setValue(self, obj):
##TODO: check that it contains a correct number of elements
if isinstance(obj, str):
self.value = obj
else:
self.value = ParameterFixedTable.tableToString(obj)
return True

@staticmethod
def tableToString(table):
Expand Down
5 changes: 1 addition & 4 deletions src/sextante/parameters/ParameterString.py
Expand Up @@ -17,10 +17,7 @@ def serialize(self):

def deserialize(self, s):
tokens = s.split("|")
if len(tokens) == 3:
return ParameterString(tokens[0], tokens[1], tokens[2])
else:
return ParameterString(tokens[0], tokens[1], tokens[2], tokens[3])
return ParameterString(tokens[0], tokens[1], tokens[2])

def getAsScriptCode(self):
return "##" + self.name + "=string " + self.default
1 change: 1 addition & 0 deletions src/sextanteexampleprovider/ExampleAlgorithm.py
Expand Up @@ -5,6 +5,7 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.parameters.ParameterExtent import ParameterExtent


class ExampleAlgorithm(GeoAlgorithm):
Expand Down

0 comments on commit 8dd4574

Please sign in to comment.