Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] added GUI for gdaldem, to fix #3064
git-svn-id: http://svn.osgeo.org/qgis/trunk@15495 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler committed Mar 15, 2011
1 parent 1ecb5be commit 6e430c3
Show file tree
Hide file tree
Showing 7 changed files with 677 additions and 26 deletions.
13 changes: 12 additions & 1 deletion python/plugins/GdalTools/GdalTools.py
Expand Up @@ -198,10 +198,16 @@ def initGui( self ):
self.menu.addAction(self.rgb)

self.tileindex = QAction( QIcon( ":icons/tileindex.png" ), QCoreApplication.translate( "GdalTools", "Tile index" ), self.iface.mainWindow() )
self.rgb.setStatusTip( QCoreApplication.translate( "GdalTools", "Build a shapefile as a raster tileindex" ) )
self.tileindex.setStatusTip( QCoreApplication.translate( "GdalTools", "Build a shapefile as a raster tileindex" ) )
QObject.connect( self.tileindex, SIGNAL( "triggered()" ), self.doTileIndex )
self.menu.addAction(self.tileindex)

if self.GdalVersion >= "1.7":
self.dem = QAction( QIcon( ":icons/dem.png" ), QCoreApplication.translate( "GdalTools", "DEM" ), self.iface.mainWindow() )
self.dem.setStatusTip( QCoreApplication.translate( "GdalTools", "Tool to analyze and visualize DEMs" ) )
QObject.connect( self.dem, SIGNAL( "triggered()" ), self.doDEM )
self.menu.addAction(self.dem)

self.settings = QAction( QCoreApplication.translate( "GdalTools", "GdalTools settings" ), self.iface.mainWindow() )
self.settings.setStatusTip( QCoreApplication.translate( "GdalTools", "Various settings for Gdal Tools" ) )
QObject.connect( self.settings, SIGNAL( "triggered()" ), self.doSettings )
Expand Down Expand Up @@ -311,6 +317,11 @@ def doTileIndex( self ):
d = TileIndex( self.iface )
d.show_()

def doDEM( self ):
from tools.doDEM import GdalToolsDialog as DEM
d = DEM( self.iface )
d.show_()

def doSettings( self ):
from tools.doSettings import GdalToolsSettingsDialog as Settings
d = Settings( self.iface )
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/GdalTools/__init__.py
Expand Up @@ -22,7 +22,7 @@ def name():
def description():
return "Integrate gdal tools into qgis"
def version():
return "Version 1.2.23"
return "Version 1.2.24"
def qgisMinimumVersion():
return "1.0"
def icon():
Expand Down
Binary file added python/plugins/GdalTools/icons/dem.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 22 additions & 21 deletions python/plugins/GdalTools/resources.qrc
@@ -1,23 +1,24 @@
<RCC>
<qresource>
<file>icons/contour.png</file>
<file>icons/merge.png</file>
<file>icons/polygonize.png</file>
<file>icons/rasterize.png</file>
<file>icons/sieve.png</file>
<file>icons/vrt.png</file>
<file>icons/warp.png</file>
<file>icons/proximity.png</file>
<file>icons/nearblack.png</file>
<file>icons/grid.png</file>
<file>icons/translate.png</file>
<file>icons/raster-info.png</file>
<file>icons/projection-add.png</file>
<file>icons/raster-overview.png</file>
<file>icons/raster-clip.png</file>
<file>icons/raster-paletted.png</file>
<file>icons/raster-rgb.png</file>
<file>icons/tileindex.png</file>
<file>icons/about.png</file>
</qresource>
<qresource prefix="/" >
<file>icons/contour.png</file>
<file>icons/merge.png</file>
<file>icons/polygonize.png</file>
<file>icons/rasterize.png</file>
<file>icons/sieve.png</file>
<file>icons/vrt.png</file>
<file>icons/warp.png</file>
<file>icons/proximity.png</file>
<file>icons/nearblack.png</file>
<file>icons/grid.png</file>
<file>icons/translate.png</file>
<file>icons/raster-info.png</file>
<file>icons/projection-add.png</file>
<file>icons/raster-overview.png</file>
<file>icons/raster-clip.png</file>
<file>icons/raster-paletted.png</file>
<file>icons/raster-rgb.png</file>
<file>icons/tileindex.png</file>
<file>icons/about.png</file>
<file>icons/dem.png</file>
</qresource>
</RCC>
144 changes: 144 additions & 0 deletions python/plugins/GdalTools/tools/doDEM.py
@@ -0,0 +1,144 @@
# -*- coding: utf-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *

from ui_widgetDEM import Ui_GdalToolsWidget as Ui_Widget
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
import GdalTools_utils as Utils

class GdalToolsDialog(QWidget, Ui_Widget, BasePluginWidget):

def __init__(self, iface):
QWidget.__init__(self)
self.iface = iface
self.modes = ("hillshade", "slope", "aspect", "color-relief", "TRI", "TPI", "roughness")

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

# set the default QSpinBoxes and QProgressBar value
self.bandSpin.setValue(1)

self.hillshadeZFactorSpin.setValue(1)
self.hillshadeScaleSpin.setValue(1)
self.hillshadeAltitudeSpin.setValue(45.0)
self.hillshadeAzimuthSpin.setValue(315.0)
self.slopeScaleSpin.setValue(1)

self.outputFormat = Utils.fillRasterOutputFormat()

self.setParamsStatus(
[
(self.inputLayerCombo, [SIGNAL("currentIndexChanged(int)"), SIGNAL("editTextChanged(const QString &)")] ),
(self.outputFileEdit, SIGNAL("textChanged(const QString &)")),
(self.computeEdgesCheck, SIGNAL("stateChanged(int)"), None, "1.8.0"),
(self.bandSpin, SIGNAL("valueChanged(int)"), self.bandCheck),
(self.creationOptionsTable, [SIGNAL("cellValueChanged(int, int)"), SIGNAL("rowRemoved()")], self.creationGroupBox),
(self.modeCombo, SIGNAL("currentIndexChanged(int)")),
([self.hillshadeZFactorSpin, self.hillshadeScaleSpin, self.hillshadeAltitudeSpin, self.hillshadeAzimuthSpin], SIGNAL("valueChanged(double)")),
(self.slopeScaleSpin, SIGNAL("valueChanged(double)")),
(self.slopePercentCheck, SIGNAL("stateChanged(int)")),
([self.aspectTrigonometricCheck, self.aspectZeroForFlatCheck], SIGNAL("stateChanged(int)")),
(self.colorConfigFileEdit, SIGNAL("textChanged(const QString &)")),
([self.colorExactRadio, self.colorNearestRadio], SIGNAL("toggled(bool)"), self.colorMatchGroupBox),
(self.colorAlphaCheck, SIGNAL("stateChanged(int)"))
]
)

self.connect(self.selectInputFileButton, SIGNAL("clicked()"), self.fillInputFileEdit)
self.connect(self.selectOutputFileButton, SIGNAL("clicked()"), self.fillOutputFileEdit)
self.connect(self.colorSelectConfigFileButton, SIGNAL("clicked()"), self.fillColorConfigFileEdit)
self.connect(self.modeCombo, SIGNAL("currentIndexChanged(int)"), self.showModeParams)

def showModeParams(self, index):
self.stackedWidget.setVisible( index < 4 )

def onLayersChanged(self):
self.fillInputLayerCombo()

def fillInputLayerCombo(self):
self.inputLayerCombo.clear()
( self.layers, names ) = Utils.LayerRegistry.instance().getRasterLayers()
self.inputLayerCombo.addItems( names )

def fillInputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
inputFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the file for DEM" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter)
if inputFile.isEmpty():
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

self.inputLayerCombo.setCurrentIndex(-1)
self.inputLayerCombo.setEditText(inputFile)

def fillOutputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
outputFile = Utils.FileDialog.getSaveFileName(self, self.tr( "Select the raster file to save the results to" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
if outputFile.isEmpty():
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

self.outputFormat = Utils.fillRasterOutputFormat( lastUsedFilter, outputFile )
self.outputFileEdit.setText(outputFile)

def fillColorConfigFileEdit(self):
configFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the color configuration file" ), "*")
if configFile.isEmpty():
return

self.colorConfigFileEdit.setText(configFile)

def getArguments(self):
mode = self.modes[ self.modeCombo.currentIndex() ]
arguments = QStringList()
arguments << mode
arguments << self.getInputFileName()
if mode == "color-relief":
arguments << self.colorConfigFileEdit.text()
arguments << self.outputFileEdit.text()
if mode == "hillshade":
arguments << "-z" << str(self.hillshadeZFactorSpin.value())
arguments << "-s" << str(self.hillshadeScaleSpin.value())
arguments << "-az" << str(self.hillshadeAzimuthSpin.value())
arguments << "-alt" << str(self.hillshadeAltitudeSpin.value())
elif mode == "slope":
if self.slopePercentCheck.isChecked():
arguments << "-p"
arguments << "-s" << str(self.slopeScaleSpin.value())
elif mode == "aspect":
if self.aspectTrigonometricCheck.isChecked():
arguments << "-trigonometric"
if self.aspectZeroForFlatCheck.isChecked():
arguments << "-zero_for_flat"
elif mode == "color-relief":
if self.colorAlphaCheck.isChecked():
arguments << "-alpha"
if self.colorMatchGroupBox.isChecked():
if self.colorExactRadio.isChecked():
arguments << "-exact_color_entry"
elif self.colorNearestRadio.isChecked():
arguments << "-nearest_color_entry"
if self.computeEdgesCheck.isChecked():
arguments << "-compute_edges"
if self.bandCheck.isChecked():
arguments << "-b" << str(self.bandSpin.value())
if not self.outputFileEdit.text().isEmpty():
arguments << "-of" << self.outputFormat
if self.creationGroupBox.isChecked():
for opt in self.creationOptionsTable.options():
arguments << "-co" << opt
return arguments

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

def getOutputFileName(self):
return self.outputFileEdit.text()

def addLayerIntoCanvas(self, fileInfo):
self.iface.addRasterLayer(fileInfo.filePath())

6 changes: 3 additions & 3 deletions python/plugins/GdalTools/tools/doGrid.py
Expand Up @@ -39,7 +39,7 @@ def __init__(self, iface):
(self.outputFileEdit, SIGNAL("textChanged(const QString &)")),
(self.zfieldCombo, SIGNAL("currentIndexChanged(int)"), self.zfieldCheck),
(self.algorithmCombo, SIGNAL("currentIndexChanged(int)"), self.algorithmCheck),
(self.stackedWidget, SIGNAL("currentChanged(int)"), self.algorithmCheck),
(self.stackedWidget, None, self.algorithmCheck),
([self.invdistPowerSpin, self.invdistSmothingSpin, self.invdistRadius1Spin, self.invdistRadius2Spin, self.invdistAngleSpin, self.invdistNoDataSpin], SIGNAL("valueChanged(double)")),
([self.invdistMaxPointsSpin, self.invdistMinPointsSpin], SIGNAL("valueChanged(int)")),
([self.averageRadius1Spin, self.averageRadius2Spin, self.averageAngleSpin, self.averageNoDataSpin], SIGNAL("valueChanged(double)")),
Expand All @@ -56,14 +56,14 @@ def __init__(self, iface):
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)
self.connect(self.extentGroup, SIGNAL("toggled(bool)"), self.onExtentCheckedChanged)


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

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

def onLayersChanged(self):
Expand Down

0 comments on commit 6e430c3

Please sign in to comment.