Skip to content
Permalink
Browse files
define extent for grid analisys, to fix #3332
git-svn-id: http://svn.osgeo.org/qgis/trunk@14976 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler committed Dec 27, 2010
1 parent 517c002 commit 1650e86b109f8191c4fe67295e12f7727e2739e3
@@ -22,7 +22,7 @@ def name():
def description():
return "Integrate gdal tools into qgis"
def version():
return "Version 1.2.19"
return "Version 1.2.20"
def qgisMinimumVersion():
return "1.0"
def icon():
@@ -15,11 +15,10 @@ def __init__(self, iface):
self.iface = iface
self.canvas = self.iface.mapCanvas()

self.clipper = ClipperSelector(self.canvas)

self.setupUi(self)
BasePluginWidget.__init__(self, self.iface, "gdal_merge.py", None, self.iface.mainWindow())

self.extentSelector.setCanvas(self.canvas)
self.outputFormat = Utils.fillRasterOutputFormat()

self.inputFiles = QStringList()
@@ -29,50 +28,28 @@ def __init__(self, iface):
[
(self.outputFileEdit, SIGNAL("textChanged(const QString &)")),
(self.noDataSpin, SIGNAL("valueChanged(int)"), self.noDataCheck),
(self.pctCheck, SIGNAL("stateChanged(int)"))
(self.pctCheck, SIGNAL("stateChanged(int)")),
( self.extentSelector, [SIGNAL("selectionStarted()"), SIGNAL("newExtentDefined()")] )
]
)

self.connect(self.selectOutputFileButton, SIGNAL("clicked()"), self.fillOutputFileEdit)
self.connect(self.clipper, SIGNAL("clippingRectangleCreated()"), self.fillCoords)
self.connect(self.x1CoordEdit, SIGNAL("textChanged(const QString &)"), self.coordsChanged)
self.connect(self.x2CoordEdit, SIGNAL("textChanged(const QString &)"), self.coordsChanged)
self.connect(self.y1CoordEdit, SIGNAL("textChanged(const QString &)"), self.coordsChanged)
self.connect(self.y2CoordEdit, SIGNAL("textChanged(const QString &)"), self.coordsChanged)
self.connect(self.clipper, SIGNAL("deactivated()"), self.pauseClipping)
self.connect(self.btnEnableClip, SIGNAL("clicked()"), self.startClipping)
self.connect(self.extentSelector, SIGNAL("newExtentDefined()"), self.checkRun)
self.connect(self.extentSelector, SIGNAL("selectionStarted()"), self.checkRun)

def show_(self):
self.connect(self.canvas, SIGNAL("layersChanged()"), self.fillInputFiles)
self.btnEnableClip.setVisible(False)
self.extentSelector.start()
BasePluginWidget.show_(self)

self.fillInputFiles()
self.fillCoords()
self.checkRun()

def onClosing(self):
self.disconnect(self.canvas, SIGNAL("layersChanged()"), self.fillInputFiles)
self.stopClipping()
self.extentSelector.stop()
BasePluginWidget.onClosing(self)

def stopClipping(self):
self.isClippingStarted = False
self.canvas.unsetMapTool(self.clipper)
self.clipper.reset()
self.btnEnableClip.setVisible(False)

def startClipping(self):
self.canvas.setMapTool(self.clipper)
self.isClippingStarted = True
self.btnEnableClip.setVisible(False)
self.coordsChanged()

def pauseClipping(self):
if not self.isClippingStarted:
return

self.btnEnableClip.setVisible(True)

def fillInputFiles(self):
self.inputFiles = QStringList()

@@ -88,59 +65,19 @@ def fillInputFiles(self):
self.inputFiles << layer.source()

if self.inputFiles.isEmpty():
self.stopClipping()
self.extentSelector.stop()

if self.isVisible() and self.warningDialog.isHidden():
msg = QString( self.tr("No active raster layers. You must add almost one raster layer to continue.") )
self.warningDialog.showMessage(msg)
else:
self.warningDialog.hide()
self.startClipping()

self.checkRun()

def isCoordsValid(self):
return not ( self.x1CoordEdit.text().isEmpty() or \
self.x2CoordEdit.text().isEmpty() or \
self.y1CoordEdit.text().isEmpty() or \
self.y2CoordEdit.text().isEmpty() )

def coordsChanged(self):
if not self.isCoordsValid():
self.clipper.setClippingRectangle(None)
else:
point1 = QgsPoint( float(self.x1CoordEdit.text()), float(self.y1CoordEdit.text()) )
point2 = QgsPoint( float(self.x2CoordEdit.text()), float(self.y2CoordEdit.text()) )
rect = QgsRectangle(point1, point2)

self.clipper.setClippingRectangle(rect)

self.checkRun()

def fillCoords(self):
rect = self.clipper.clippingRectangle()
if rect != None:
self.x1CoordEdit.setText( str(rect.xMinimum()) )
self.x2CoordEdit.setText( str(rect.xMaximum()) )
self.y1CoordEdit.setText( str(rect.yMaximum()) )
self.y2CoordEdit.setText( str(rect.yMinimum()) )
else:
self.x1CoordEdit.clear()
self.x2CoordEdit.clear()
self.y1CoordEdit.clear()
self.y2CoordEdit.clear()
self.extentSelector.start()

self.checkRun()

def checkRun(self):
self.someValueChanged()

self.x1CoordEdit.setEnabled( not self.inputFiles.isEmpty() )
self.x2CoordEdit.setEnabled( not self.inputFiles.isEmpty() )
self.y1CoordEdit.setEnabled( not self.inputFiles.isEmpty() )
self.y2CoordEdit.setEnabled( not self.inputFiles.isEmpty() )

self.base.enableRun( not self.inputFiles.isEmpty() and self.isCoordsValid() )
self.base.enableRun( not self.inputFiles.isEmpty() and self.extentSelector.getExtent() != None )

def fillOutputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
@@ -163,8 +100,8 @@ def getArguments(self):
arguments << str(self.noDataSpin.value())
if self.pctCheck.isChecked():
arguments << "-pct"
if self.isCoordsValid():
rect = self.clipper.clippingRectangle()
if self.extentSelector.isCoordsValid():
rect = self.extentSelector.getExtent()
if rect != None:
arguments << "-ul_lr"
arguments << str(rect.xMinimum())
@@ -186,77 +123,3 @@ def getOutputFileName(self):
def addLayerIntoCanvas(self, fileInfo):
self.iface.addRasterLayer(fileInfo.filePath())


class ClipperSelector(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.isEmittingPoint = False

self.startPoint = self.endPoint = None

def reset(self):
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
self.emit( SIGNAL("clippingRectangleCreated()") )

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 clippingRectangle(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 setClippingRectangle(self, rect):
if rect == None:
self.reset()
return

self.startPoint = QgsPoint(rect.xMaximum(), rect.yMaximum())
self.endPoint = QgsPoint(rect.xMinimum(), rect.yMinimum())
self.showRect(self.startPoint, self.endPoint)

def deactivate(self):
QgsMapTool.deactivate(self)
self.emit(SIGNAL("deactivated()"))

@@ -3,7 +3,6 @@
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from osgeo import ogr

from ui_widgetGrid import Ui_GdalToolsWidget as Ui_Widget
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
@@ -14,12 +13,16 @@ class GdalToolsDialog(QWidget, Ui_Widget, BasePluginWidget):
def __init__(self, iface):
QWidget.__init__(self)
self.iface = iface
self.canvas = self.iface.mapCanvas()
self.algorithm = ('invdist', 'average', 'nearest', 'datametrics')
self.datametrics = ('minimum', 'maximum', 'range')

self.setupUi(self)
BasePluginWidget.__init__(self, self.iface, "gdal_grid")

self.extentSelector.setCanvas(self.canvas)
#self.extentSelector.stop()

# set the default QSpinBoxes value
self.invdistPowerSpin.setValue(2.0)

@@ -40,17 +43,26 @@ def __init__(self, iface):
([self.nearestRadius1Spin, self.nearestRadius2Spin, self.nearestAngleSpin, self.nearestNoDataSpin], SIGNAL("valueChanged(double)")),
(self.datametricsCombo, SIGNAL("currentIndexChanged(int)")),
([self.datametricsRadius1Spin, self.datametricsRadius2Spin, self.datametricsAngleSpin, self.datametricsNoDataSpin], SIGNAL("valueChanged(double)")),
(self.datametricsMinPointsSpin, SIGNAL("valueChanged(int)"))
(self.datametricsMinPointsSpin, SIGNAL("valueChanged(int)")),
(self.extentSelector, [SIGNAL("selectionStarted()"), SIGNAL("newExtentDefined()")], self.extentGroup)
]
)

self.connect(self.selectInputFileButton, SIGNAL("clicked()"), self.fillInputFileEdit)
self.connect(self.selectOutputFileButton, SIGNAL("clicked()"), self.fillOutputFileEdit)
self.connect(self.inputLayerCombo, SIGNAL("currentIndexChanged(int)"), self.fillFieldsCombo)
self.connect(self.extentGroup, SIGNAL("toggled(bool)"), self.onExtentCheckedChenged)

# fill layers combo
self.fillInputLayerCombo()

def onClosing(self):
self.extentSelector.stop()
BasePluginWidget.onClosing(self)

def onExtentCheckedChenged(self, enabled):
self.extentSelector.start() if enabled else self.extentSelector.stop()

def fillInputLayerCombo(self):
self.inputLayerCombo.clear()
( self.layers, names ) = Utils.getVectorLayers()
@@ -98,6 +110,15 @@ def getArguments(self):
elif not self.inputLayerCombo.currentText().isEmpty():
arguments << "-l"
arguments << QFileInfo(self.inputLayerCombo.currentText()).baseName()
if self.extentGroup.isChecked():
rect = self.extentSelector.getExtent()
if rect != None:
arguments << "-txe"
arguments << str(rect.xMinimum())
arguments << str(rect.xMaximum())
arguments << "-tye"
arguments << str(rect.yMaximum())
arguments << str(rect.yMinimum())
if self.algorithmCheck.isChecked() and self.algorithmCombo.currentIndex() >= 0:
arguments << "-a"
arguments << self.algorithmArguments(self.algorithmCombo.currentIndex())
@@ -109,8 +130,8 @@ def getArguments(self):
return arguments

def getInputFileName(self):
if self.inputLayerCombo.currentIndex() >= 0:
return self.layers[self.inputLayerCombo.currentIndex()].source()
#if self.inputLayerCombo.currentIndex() >= 0:
# return self.layers[self.inputLayerCombo.currentIndex()].source()
return self.inputLayerCombo.currentText()

def getOutputFileName(self):
Loading

0 comments on commit 1650e86

Please sign in to comment.