Skip to content
Permalink
Browse files
allow to choose input directory in GdalTools Merge tool (fix #4930)
  • Loading branch information
brushtyler committed Feb 11, 2012
1 parent 767ee01 commit d7811a1120e8893ec795b80ac4bd19208f0c4066
Showing with 78 additions and 27 deletions.
  1. +56 −19 python/plugins/GdalTools/tools/doMerge.py
  2. +22 −8 python/plugins/GdalTools/tools/widgetMerge.ui
@@ -19,6 +19,7 @@ def __init__(self, iface):

self.inSelector.setType( self.inSelector.FILE )
self.outSelector.setType( self.outSelector.FILE )
self.recurseCheck.hide()

self.outputFormat = Utils.fillRasterOutputFormat()
self.extent = None
@@ -28,7 +29,9 @@ def __init__(self, iface):
(self.inSelector, SIGNAL("filenameChanged()")),
(self.outSelector, SIGNAL("filenameChanged()")),
(self.noDataSpin, SIGNAL("valueChanged(int)"), self.noDataCheck),
( self.separateCheck, SIGNAL( "stateChanged( int )" ) ),
(self.inputDirCheck, SIGNAL("stateChanged(int)")),
(self.recurseCheck, SIGNAL("stateChanged(int)"), self.inputDirCheck),
( self.separateCheck, SIGNAL( "stateChanged( int )" ) ),
( self.pctCheck, SIGNAL( "stateChanged( int )" ) ),
( self.intersectCheck, SIGNAL( "stateChanged( int )" ) ),
(self.creationOptionsTable, [SIGNAL("cellValueChanged(int, int)"), SIGNAL("rowRemoved()")], self.creationGroupBox)
@@ -37,37 +40,57 @@ def __init__(self, iface):

self.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
self.connect(self.outSelector, SIGNAL("selectClicked()"), self.fillOutputFileEdit)
self.connect(self.intersectCheck, SIGNAL("stateChanged(int)"), self.refreshExtent)
self.connect(self.intersectCheck, SIGNAL("toggled(bool)"), self.refreshExtent)
self.connect(self.inputDirCheck, SIGNAL("stateChanged( int )"), self.switchToolMode)
self.connect(self.inSelector, SIGNAL("filenameChanged()"), self.refreshExtent)

def switchToolMode(self):
self.recurseCheck.setVisible( self.inputDirCheck.isChecked() )
self.inSelector.clear()

if self.inputDirCheck.isChecked():
self.inFileLabel = self.label.text()
self.label.setText( QCoreApplication.translate( "GdalTools", "&Input directory" ) )

QObject.disconnect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
QObject.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputDir)
else:
self.label.setText( self.inFileLabel )

QObject.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFilesEdit)
QObject.disconnect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputDir)

def fillInputFilesEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
files = Utils.FileDialog.getOpenFileNames(self, self.tr( "Select the files to Merge" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
if files.isEmpty():
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)
self.inSelector.setFilename(files)

self.inSelector.setFilename(files.join(","))
def refreshExtent(self):
files = self.getInputFileNames()
self.intersectCheck.setEnabled( files.count() > 1 )
self.refreshExtent()

def refreshExtent(self):
files = self.getInputFileName()
if not self.intersectCheck.isChecked():
self.someValueChanged()
return

if files.count() < 2:
self.intersectCheck.setChecked( False )
self.extent = None
return

self.extent = self.getExtent()
self.someValueChanged()

if not self.intersectCheck.isChecked():
return
self.extent = self.getIntersectedExtent( files )

if self.extent == None:
QMessageBox.warning( self, self.tr( "Error retrieving the extent" ), self.tr( 'GDAL was unable to retrieve the extent from any file. \nThe "Use intersected extent" option will be unchecked.' ) )
self.intersectCheck.setChecked( False )
return

elif self.extent.isEmpty():
QMessageBox.warning( self, self.tr( "Empty extent" ), self.tr( 'The computed extent is empty. \nDisable the "Use intersected extent" option to have a nonempty output.' ) )

self.someValueChanged()

def fillOutputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
@@ -79,6 +102,12 @@ def fillOutputFileEdit(self):
self.outputFormat = Utils.fillRasterOutputFormat( lastUsedFilter, outputFile )
self.outSelector.setFilename( outputFile )

def fillInputDir( self ):
inputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the input directory with files to Merge" ))
if inputDir.isEmpty():
return
self.inSelector.setFilename( inputDir )

def getArguments(self):
arguments = QStringList()
if self.intersectCheck.isChecked():
@@ -105,31 +134,39 @@ def getArguments(self):
arguments << self.outputFormat
arguments << "-o"
arguments << outputFn
arguments << self.getInputFileName()
arguments << self.getInputFileNames()
return arguments

def getOutputFileName(self):
return self.outSelector.filename()

def getInputFileName(self):
return self.inSelector.filename().split( "," )
if self.inputDirCheck.isChecked():
return self.inSelector.filename()
return self.inSelector.filename().split(",", QString.SkipEmptyParts)

def getInputFileNames(self):
if self.inputDirCheck.isChecked():
return Utils.getRasterFiles( self.inSelector.filename(), self.recurseCheck.isChecked() )
return self.inSelector.filename().split(",", QString.SkipEmptyParts)

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

def getExtent( self ):
files = self.getInputFileName()

i = 0
res = rect2 = None
def getIntersectedExtent(self, files):
res = None
for fileName in files:
if res == None:
res = Utils.getRasterExtent( self, fileName )
continue

rect2 = Utils.getRasterExtent( self, fileName )
if rect2 == None:
continue

res = res.intersect( rect2 )
if res.isEmpty():
break

return res

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>342</width>
<height>226</height>
<width>345</width>
<height>276</height>
</rect>
</property>
<property name="sizePolicy">
@@ -22,7 +22,7 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Input files</string>
@@ -32,7 +32,7 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Output file</string>
@@ -42,14 +42,14 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QCheckBox" name="noDataCheck">
<property name="text">
<string>&amp;No data value</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QSpinBox" name="noDataSpin">
<property name="minimum">
<number>-100000</number>
@@ -59,12 +59,26 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="GdalToolsInOutSelector" name="inSelector" native="true"/>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="GdalToolsInOutSelector" name="outSelector" native="true"/>
</item>
<item row="0" 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="2" column="1">
<widget class="QCheckBox" name="recurseCheck">
<property name="text">
<string>Recurse subdirectories</string>
</property>
</widget>
</item>
</layout>
</item>
<item>

0 comments on commit d7811a1

Please sign in to comment.