Skip to content

Commit

Permalink
[BACKPORT] fix broken Assign projection functionality in GDALTools and
Browse files Browse the repository at this point in the history
improve handling output file extension
  • Loading branch information
alexbruy committed Nov 13, 2011
1 parent 19501c6 commit aaae489
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions python/plugins/GdalTools/tools/doProjection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ def __init__( self, iface ):
self.connect( self.batchCheck, SIGNAL( "stateChanged( int )" ), self.switchToolMode )
self.connect( self.recurseCheck, SIGNAL( "stateChanged( int )" ), self.enableRecurse )

#QObject.disconnect( self.base.buttonBox.button( QDialogButtonBox.Ok ), SIGNAL( "clicked()" ), self.onRun )
#QObject.connect( self.base.buttonBox.button( QDialogButtonBox.Ok ), SIGNAL( "clicked()" ), self.checkLayer )

def switchToolMode( self ):
self.setCommandViewerEnabled( not self.batchCheck.isChecked() )
self.progressBar.setVisible( self.batchCheck.isChecked() )
Expand Down Expand Up @@ -102,11 +99,32 @@ def getArguments( self ):
inputFn = self.getInputFileName()
arguments << inputFn
self.tempFile = QString( inputFn )
self.needOverwrite = False
if not self.tempFile.isEmpty():
self.tempFile = self.tempFile.replace( QRegExp( "\.[a-zA-Z]{2,4}$" ), ".tif" ).append( ".tmp" )
if self.tempFile.toLower().contains( QRegExp( "\.tif{1,2}" ) ):
self.tempFile = self.tempFile.replace( QRegExp( "\.[a-zA-Z]{2,4}$" ), ".tif" ).append( ".tmp" )
self.needOverwrite = True
else:
self.tempFile = self.tempFile.replace( QRegExp( "\.[a-zA-Z]{2,4}$" ), ".tif" )
arguments << self.tempFile
return arguments

def finished( self ):
outFn = self.getOutputFileName()
if self.needOverwrite:
oldFile = QFile( outFn )
newFile = QFile( self.tempFile )
if oldFile.remove():
newFile.rename( outFn )

fileInfo = QFileInfo( outFn )
if fileInfo.exists():
if self.base.loadCheckBox.isChecked():
self.addLayerIntoCanvas( fileInfo )
QMessageBox.information( self, self.tr( "Finished" ), self.tr( "Processing completed." ) )
else:
QMessageBox.warning( self, self.tr( "Warning" ), self.tr( "%1 not created." ).arg( outFn ) )

def getInputFileName(self):
return self.inSelector.filename()

Expand Down Expand Up @@ -149,10 +167,3 @@ def updateProgress(self, index, total):
self.progressBar.setValue(index + 1)
else:
self.progressBar.setValue(0)

def finished( self ):
oldFile = QFile( self.getInputFileName() )
newFile = QFile( self.tempFile )
if oldFile.remove():
newFile.rename( self.getInputFileName() )

0 comments on commit aaae489

Please sign in to comment.