Skip to content

Commit 7484fff

Browse files
author
brushtyler
committed
create VRT with recurse scan of dirs, to fix #3095
some code cleanup, updated labels when in batch mode to follow up the QGis HIG guideline git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14963 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b247530 commit 7484fff

File tree

10 files changed

+152
-223
lines changed

10 files changed

+152
-223
lines changed

python/plugins/GdalTools/tools/GdalTools_utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,32 @@ def getVectorLayers():
117117
count = count +1
118118
return (layers, names)
119119

120+
def getRasterFiles(path, recursive=False):
121+
rasters = QStringList()
122+
if not QFileInfo(path).exists():
123+
return rasters
124+
125+
filter = getRasterExtensions()
126+
workDir = QDir( path )
127+
workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
128+
workDir.setNameFilters( filter )
129+
files = workDir.entryList()
130+
for f in files:
131+
rasters << path + "/" + f
132+
133+
if recursive:
134+
import os
135+
for myRoot, myDirs, myFiles in os.walk( unicode(path) ):
136+
for dir in myDirs:
137+
workDir = QDir( myRoot + "/" + dir )
138+
workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
139+
workDir.setNameFilters( filter )
140+
workFiles = workDir.entryList()
141+
for f in workFiles:
142+
rasters << myRoot + "/" + dir + "/" + f
143+
144+
return rasters
145+
120146
def fillRasterOutputFormat(aFilter = None, filename = None):
121147
shortName = QString()
122148

python/plugins/GdalTools/tools/doBuildVRT.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,42 @@ def __init__(self, iface):
1818
self.setupUi(self)
1919
BasePluginWidget.__init__(self, self.iface, "gdalbuildvrt")
2020

21+
self.recurseCheck.hide()
22+
2123
self.setParamsStatus(
2224
[
2325
(self.inputFilesEdit, SIGNAL("textChanged(const QString &)")),
2426
(self.outputFileEdit, SIGNAL("textChanged(const QString &)")),
2527
(self.resolutionComboBox, SIGNAL("currentIndexChanged(int)"), self.resolutionCheck),
2628
(self.srcNoDataSpin, SIGNAL("valueChanged(int)"), self.srcNoDataCheck, "1.7.0"),
27-
(self.separateCheck, SIGNAL("stateChanged(int)"), None, "1.7.0")
29+
(self.separateCheck, SIGNAL("stateChanged(int)"), None, "1.7.0"),
30+
(self.inputDirCheck, SIGNAL("stateChanged(int)")),
31+
(self.recurseCheck, SIGNAL("stateChanged(int)"), self.inputDirCheck)
2832
]
2933
)
3034

3135
self.connect(self.selectInputFilesButton, SIGNAL("clicked()"), self.fillInputFilesEdit)
3236
self.connect(self.selectOutputFileButton, SIGNAL("clicked()"), self.fillOutputFileEdit)
37+
self.connect( self.inputDirCheck, SIGNAL( "stateChanged( int )" ), self.switchToolMode )
38+
39+
def switchToolMode(self):
40+
self.inputFilesEdit.clear()
41+
42+
if self.inputDirCheck.isChecked():
43+
self.inFileLabel = self.label.text()
44+
self.label.setText( QCoreApplication.translate( "GdalTools", "&Input directory" ) )
45+
46+
self.recurseCheck.show()
47+
48+
QObject.disconnect( self.selectInputFilesButton, SIGNAL( "clicked()" ), self.fillInputFilesEdit )
49+
QObject.connect( self.selectInputFilesButton, SIGNAL( "clicked()" ), self.fillInputDir )
50+
else:
51+
self.label.setText( self.inFileLabel )
52+
53+
self.recurseCheck.hide()
54+
55+
QObject.connect( self.selectInputFilesButton, SIGNAL( "clicked()" ), self.fillInputFilesEdit )
56+
QObject.disconnect( self.selectInputFilesButton, SIGNAL( "clicked()" ), self.fillInputDir )
3357

3458
def fillInputFilesEdit(self):
3559
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
@@ -47,6 +71,13 @@ def fillOutputFileEdit(self):
4771

4872
self.outputFileEdit.setText(outputFile)
4973

74+
def fillInputDir( self ):
75+
inputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the input directory with files for VRT" ))
76+
if inputDir.isEmpty():
77+
return
78+
79+
self.inputFilesEdit.setText( inputDir )
80+
5081
def getArguments(self):
5182
arguments = QStringList()
5283
if self.resolutionCheck.isChecked() and self.resolutionComboBox.currentIndex() >= 0:
@@ -58,7 +89,10 @@ def getArguments(self):
5889
arguments << "-srcnodata"
5990
arguments << str(self.srcNoDataSpin.value())
6091
arguments << self.outputFileEdit.text()
61-
arguments << self.inputFilesEdit.text().split(",")
92+
if self.inputDirCheck.isChecked():
93+
arguments << Utils.getRasterFiles( self.inputFilesEdit.text(), self.recurseCheck.isChecked() )
94+
else:
95+
arguments << self.inputFilesEdit.text().split(",")
6296
return arguments
6397

6498
def getOutputFileName(self):

python/plugins/GdalTools/tools/doOverview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def switchToolMode( self ):
5656
self.inputLayerCombo.setCurrentIndex(-1)
5757
if self.batchCheck.isChecked():
5858
self.inFileLabel = self.label.text()
59-
self.label.setText( QCoreApplication.translate( "GdalTools", "&Input directory:" ) )
59+
self.label.setText( QCoreApplication.translate( "GdalTools", "&Input directory" ) )
6060

6161
self.progressBar.show()
6262

python/plugins/GdalTools/tools/doPctRgb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def switchToolMode( self ):
5353
if self.batchCheck.isChecked():
5454
self.inFileLabel = self.label.text()
5555
self.outFileLabel = self.label_2.text()
56-
self.label.setText( QCoreApplication.translate( "GdalTools", "&Input directory:" ) )
57-
self.label_2.setText( QCoreApplication.translate( "GdalTools", "&Output directory:" ) )
56+
self.label.setText( QCoreApplication.translate( "GdalTools", "&Input directory" ) )
57+
self.label_2.setText( QCoreApplication.translate( "GdalTools", "&Output directory" ) )
5858

5959
self.progressBar.show()
6060

0 commit comments

Comments
 (0)