Skip to content

Commit 5e98be1

Browse files
committedJun 14, 2013
fix GdalTools warp
1 parent 84d7766 commit 5e98be1

File tree

3 files changed

+45
-46
lines changed

3 files changed

+45
-46
lines changed
 

‎python/plugins/GdalTools/tools/GdalTools_utils.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,15 @@ def getRasterSRS( parent, fileName ):
299299
return ''
300300

301301
info = string.split( arr, sep="\n" )
302-
# TODO .filter( "AUTHORITY" )
303-
if info.count() == 0:
302+
if len(info) == 0:
304303
return ''
305304

306-
srs = info[ info.count() - 1 ]
307-
srs = srs.simplified().remove( "AUTHORITY[" )
308-
srs = re.sub("\"", '', re.sub("\]{2,4},?", '', srs) )
309-
info = srs.split( "," )
310-
srs = info[ 0 ] + ":" + info[ 1 ]
311-
return srs
305+
for elem in info:
306+
m = re.match("^\s*AUTHORITY\[\"([a-z]*[A-Z]*)\",\"(\d*)\"\]", elem)
307+
if m and len(m.groups()) == 2:
308+
return '%s:%s' % (m.group(1), m.group(2))
309+
310+
return ''
312311

313312
def getRasterExtent(parent, fileName):
314313
processSRS = QProcess( parent )

‎python/plugins/GdalTools/tools/dialogSRS.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ def proj4string(self):
5151
return self.selector.selectedProj4String()
5252

5353
def getProjection(self):
54-
if self.authid().startswith("EPSG:", Qt.CaseInsensitive):
54+
if self.authid().upper().startswith("EPSG:"):
5555
return self.authid()
5656

57-
if not self.selector.selectedProj4String().isEmpty():
57+
if self.selector.selectedProj4String():
5858
return self.proj4string()
5959

6060
return ''

‎python/plugins/GdalTools/tools/doWarp.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def onLayersChanged(self):
116116
def fillInputFile(self):
117117
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
118118
inputFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the input file for Warp" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
119-
if inputFile.isEmpty():
119+
if not inputFile:
120120
return
121121
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)
122122
self.inSelector.setFilename(inputFile)
@@ -127,7 +127,7 @@ def fillInputFile(self):
127127
def fillOutputFileEdit(self):
128128
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
129129
outputFile = Utils.FileDialog.getSaveFileName(self, self.tr( "Select the raster file to save the results to" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
130-
if outputFile.isEmpty():
130+
if not outputFile:
131131
return
132132
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)
133133

@@ -137,15 +137,15 @@ def fillOutputFileEdit(self):
137137
def fillMaskFile(self):
138138
lastUsedFilter = Utils.FileFilter.lastUsedVectorFilter()
139139
maskFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the mask file" ), Utils.FileFilter.allVectorsFilter(), lastUsedFilter )
140-
if maskFile.isEmpty():
140+
if not maskFile:
141141
return
142142
Utils.FileFilter.setLastUsedVectorFilter(lastUsedFilter)
143143
self.maskSelector.setFilename(maskFile)
144144

145145

146146
def fillInputDir( self ):
147147
inputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the input directory with files to Warp" ))
148-
if inputDir.isEmpty():
148+
if not inputDir:
149149
return
150150

151151
self.inSelector.setFilename( inputDir )
@@ -154,13 +154,13 @@ def fillInputDir( self ):
154154
workDir = QDir( inputDir )
155155
workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
156156
workDir.setNameFilters( filter )
157-
if workDir.entryList().count() > 0:
157+
if len(workDir.entryList()) > 0:
158158
fl = inputDir + "/" + workDir.entryList()[ 0 ]
159159
self.sourceSRSEdit.setText( Utils.getRasterSRS( self, fl ) )
160160

161161
def fillOutputDir( self ):
162162
outputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the output directory to save the results to" ))
163-
if outputDir.isEmpty():
163+
if not outputDir:
164164
return
165165
self.outSelector.setFilename( outputDir )
166166

@@ -177,54 +177,54 @@ def fillSourceSRSEditDefault(self):
177177
def refreshSourceSRS(self):
178178
crs = Utils.getRasterSRS( self, self.getInputFileName() )
179179
self.sourceSRSEdit.setText( crs )
180-
self.sourceSRSCheck.setChecked( not crs.isEmpty() )
180+
self.sourceSRSCheck.setChecked( crs != '' )
181181

182182
def fillTargetSRSEdit(self):
183183
dialog = SRSDialog( "Select the target SRS", self )
184184
if dialog.exec_():
185185
self.targetSRSEdit.setText(dialog.getProjection())
186186

187187
def getArguments(self):
188-
arguments = QStringList()
189-
if self.sourceSRSCheck.isChecked() and not self.sourceSRSEdit.text().isEmpty():
190-
arguments << "-s_srs"
191-
arguments << self.sourceSRSEdit.text()
192-
if self.targetSRSCheck.isChecked() and not self.targetSRSEdit.text().isEmpty():
193-
arguments << "-t_srs"
194-
arguments << self.targetSRSEdit.text()
188+
arguments = []
189+
if self.sourceSRSCheck.isChecked() and self.sourceSRSEdit.text():
190+
arguments.append("-s_srs")
191+
arguments.append(self.sourceSRSEdit.text())
192+
if self.targetSRSCheck.isChecked() and self.targetSRSEdit.text():
193+
arguments.append("-t_srs")
194+
arguments.append(self.targetSRSEdit.text())
195195
if self.resamplingCheck.isChecked() and self.resamplingCombo.currentIndex() >= 0:
196-
arguments << "-r"
197-
arguments << self.resampling_method[self.resamplingCombo.currentIndex()]
196+
arguments.append("-r")
197+
arguments.append(self.resampling_method[self.resamplingCombo.currentIndex()])
198198
if self.cacheCheck.isChecked():
199-
arguments << "-wm"
200-
arguments << str(self.cacheSpin.value())
199+
arguments.append("-wm")
200+
arguments.append(str(self.cacheSpin.value()))
201201
if self.resizeGroupBox.isChecked():
202-
arguments << "-ts"
203-
arguments << str( self.widthSpin.value() )
204-
arguments << str( self.heightSpin.value() )
202+
arguments.append("-ts")
203+
arguments.append(str( self.widthSpin.value() ))
204+
arguments.append(str( self.heightSpin.value() ))
205205
if self.multithreadCheck.isChecked():
206-
arguments << "-multi"
206+
arguments.append("-multi")
207207
if self.noDataCheck.isChecked():
208-
nodata = self.noDataEdit.text().trimmed()
209-
if not nodata.isEmpty():
210-
arguments << "-dstnodata"
211-
arguments << nodata
208+
nodata = self.noDataEdit.text().strip()
209+
if nodata:
210+
arguments.append("-dstnodata")
211+
arguments.append(nodata)
212212
if self.maskCheck.isChecked():
213213
mask = self.getMaskFileName()
214-
if not mask.isEmpty():
215-
arguments << "-q"
216-
arguments << "-cutline"
217-
arguments << mask
218-
arguments << "-dstalpha"
214+
if mask:
215+
arguments.append("-q")
216+
arguments.append("-cutline")
217+
arguments.append(mask)
218+
arguments.append("-dstalpha")
219219
if self.isBatchEnabled():
220220
return arguments
221221

222222
outputFn = self.getOutputFileName()
223-
if not outputFn.isEmpty():
224-
arguments << "-of"
225-
arguments << self.outputFormat
226-
arguments << self.getInputFileName()
227-
arguments << outputFn
223+
if outputFn:
224+
arguments.append("-of")
225+
arguments.append(self.outputFormat)
226+
arguments.append(self.getInputFileName())
227+
arguments.append(outputFn)
228228
return arguments
229229

230230
def getInputFileName(self):

0 commit comments

Comments
 (0)
Please sign in to comment.