Skip to content
Permalink
Browse files
allow to use loaded layers as input files (instead of file selector) …
…for GDALTools Build Virtual Raster
  • Loading branch information
etiennesky authored and brushtyler committed Mar 10, 2012
1 parent 892cc39 commit 9da5d0345ba165970a4fca5a05bb8b1bf108ad6a
Showing with 40 additions and 14 deletions.
  1. +22 −3 python/plugins/GdalTools/tools/doBuildVRT.py
  2. +18 −11 python/plugins/GdalTools/tools/widgetBuildVRT.ui
@@ -3,6 +3,7 @@
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *

from ui_widgetBuildVRT import Ui_GdalToolsWidget as Ui_Widget
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
@@ -38,6 +39,7 @@ def __init__(self, iface):
self.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
self.connect(self.outSelector, SIGNAL("selectClicked()"), self.fillOutputFileEdit)
self.connect( self.inputDirCheck, SIGNAL( "stateChanged( int )" ), self.switchToolMode )
self.connect( self.useSelectedLayersCheck, SIGNAL( "stateChanged( int )" ), self.switchLayerMode )

def switchToolMode(self):
self.recurseCheck.setVisible( self.inputDirCheck.isChecked() )
@@ -55,6 +57,12 @@ def switchToolMode(self):
QObject.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
QObject.disconnect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputDir)

def switchLayerMode(self):
enableInputFiles = not self.useSelectedLayersCheck.isChecked()
self.inputDirCheck.setEnabled( enableInputFiles )
self.inSelector.setEnabled( enableInputFiles )
self.recurseCheck.setEnabled( enableInputFiles )

def fillInputFilesEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
files = Utils.FileDialog.getOpenFileNames(self, self.tr( "Select the files for VRT" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter)
@@ -88,10 +96,13 @@ def getArguments(self):
if self.allowProjDiffCheck.isChecked():
arguments << "-allow_projection_difference"
arguments << self.getOutputFileName()
if self.inputDirCheck.isChecked():
arguments << Utils.getRasterFiles( self.getInputFileName(), self.recurseCheck.isChecked() )
if self.useSelectedLayersCheck.isChecked():
arguments << self.getInputFileNamesFromSelectedLayers()
else:
arguments << self.getInputFileName()
if self.inputDirCheck.isChecked():
arguments << Utils.getRasterFiles( self.getInputFileName(), self.recurseCheck.isChecked() )
else:
arguments << self.getInputFileName()
return arguments

def getOutputFileName(self):
@@ -102,6 +113,14 @@ def getInputFileName(self):
return self.inSelector.filename()
return self.inSelector.filename().split(",")

def getInputFileNamesFromSelectedLayers(self):
layers = iface.mapCanvas().layers()
files = list()
for layer in layers:
if layer.type() == QgsMapLayer.RasterLayer and layer.providerType() == "gdal":
files.append( str(layer.source()) )
return files

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

@@ -26,13 +26,20 @@
<enum>QLayout::SetNoConstraint</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="useSelectedLayersCheck">
<property name="text">
<string>Use selected layers for input</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="inputDirCheck">
<property name="text">
<string>Choose input directory instead of files</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Input files</string>
@@ -42,14 +49,14 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QCheckBox" name="recurseCheck">
<property name="text">
<string>Recurse subdirectories</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Output file</string>
@@ -59,14 +66,14 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QCheckBox" name="resolutionCheck">
<property name="text">
<string>&amp;Resolution</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QComboBox" name="resolutionComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -94,14 +101,14 @@
</item>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QCheckBox" name="srcNoDataCheck">
<property name="text">
<string>&amp;Source No Data</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QSpinBox" name="srcNoDataSpin">
<property name="minimum">
<number>-100000</number>
@@ -111,20 +118,20 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QCheckBox" name="separateCheck">
<property name="text">
<string>Se&amp;parate</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="GdalToolsInOutSelector" name="inSelector" native="true"/>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="GdalToolsInOutSelector" name="outSelector" native="true"/>
</item>
<item row="7" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="allowProjDiffCheck">
<property name="text">
<string>Allow projection difference</string>

0 comments on commit 9da5d03

Please sign in to comment.