Skip to content
Permalink
Browse files

Patch from Matthias for gdal tools

  • Loading branch information
NathanW2 committed Jun 3, 2013
1 parent 63cc02d commit 52b773fb140fbad7b2cf3f906a0ea2b513b3cb3b
@@ -71,11 +71,11 @@ def __init__( self, iface ):
userPluginPath = QFileInfo( QgsApplication.qgisUserDbFilePath() ).path() + "/python/plugins/GdalTools"
systemPluginPath = QgsApplication.prefixPath() + "/python/plugins/GdalTools"

overrideLocale = QSettings().value( "locale/overrideFlag", QVariant( False ) ).toBool()
overrideLocale = QSettings().value( "locale/overrideFlag", False, type=bool )
if not overrideLocale:
localeFullName = QLocale.system().name()
else:
localeFullName = QSettings().value( "locale/userLocale", QVariant( "" ) ).toString()
localeFullName = QSettings().value( "locale/userLocale", "" )

if QFileInfo( userPluginPath ).exists():
translationPath = userPluginPath + "/i18n/GdalTools_" + localeFullName + ".qm"
@@ -45,20 +45,20 @@

# Escapes arguments and return them joined in a string
def escapeAndJoin(strList):
joined = QString()
joined = ''
for s in strList:
if s.contains(" "):
if s.find(" ") is not -1:
escaped = '"' + s.replace('\\', '\\\\').replace('"', '\\"') + '"'
else:
escaped = s
joined += escaped + " "
return joined.trimmed()
return joined.strip()

# Retrieves last used dir from persistent settings
def getLastUsedDir():
settings = QSettings()
lastProjectDir = settings.value( "/UI/lastProjectDir", QVariant(".") ).toString()
return settings.value( "/GdalTools/lastUsedDir", QVariant(lastProjectDir) ).toString()
lastProjectDir = settings.value( "/UI/lastProjectDir", u"." )
return settings.value( "/GdalTools/lastUsedDir", QVariant(lastProjectDir) )

# Stores last used dir in persistent settings
def setLastUsedDir(filePath):
@@ -73,7 +73,7 @@ def setLastUsedDir(filePath):
# Retrieves GDAL binaries location
def getGdalBinPath():
settings = QSettings()
return settings.value( "/GdalTools/gdalPath", QVariant( "" ) ).toString()
return settings.value( "/GdalTools/gdalPath", u"" )

# Stores GDAL binaries location
def setGdalBinPath( path ):
@@ -83,7 +83,7 @@ def setGdalBinPath( path ):
# Retrieves GDAL python modules location
def getGdalPymodPath():
settings = QSettings()
return settings.value( "/GdalTools/gdalPymodPath", QVariant( "" ) ).toString()
return settings.value( "/GdalTools/gdalPymodPath", u"" )

# Stores GDAL python modules location
def setGdalPymodPath( path ):
@@ -93,7 +93,7 @@ def setGdalPymodPath( path ):
# Retrieves GDAL help files location
def getHelpPath():
settings = QSettings()
return settings.value( "/GdalTools/helpPath", QVariant( "" ) ).toString()
return settings.value( "/GdalTools/helpPath", u"" )

# Stores GDAL help files location
def setHelpPath( path ):
@@ -103,7 +103,7 @@ def setHelpPath( path ):
# Retrieves last used encoding from persistent settings
def getLastUsedEncoding():
settings = QSettings()
return settings.value( "/UI/encoding", QVariant("System") ).toString()
return settings.value( "/UI/encoding", u"System" )

# Stores last used encoding in persistent settings
def setLastUsedEncoding(encoding):
@@ -220,7 +220,7 @@ def getRasterFiles(path, recursive=False):
return rasters

def fillRasterOutputFormat(aFilter = None, filename = None):
shortName = QString()
shortName = ''

if aFilter != None:
supportedRasters = GdalConfig.getSupportedRasters()
@@ -239,7 +239,7 @@ def fillRasterOutputFormat(aFilter = None, filename = None):
return shortName

def fillVectorOutputFormat(aFilter = None, filename = None):
shortName = QString()
shortName = ''

if aFilter != None:
supportedVectors = GdalConfig.getSupportedVectors()
@@ -292,11 +292,11 @@ def getRasterSRS( parent, fileName ):
processSRS.close()

if arr.isEmpty():
return QString()
return ''

info = QString( arr ).split( "\n" ).filter( "AUTHORITY" )
if info.count() == 0:
return QString()
return ''

srs = info[ info.count() - 1 ]
srs = srs.simplified().remove( "AUTHORITY[" )
@@ -338,7 +338,7 @@ def getRasterExtent(parent, fileName):
# so sometimes the dialog excedes the screen width
class FileDialog:
@classmethod
def getDialog(self, parent = None, caption = QString(), acceptMode = QFileDialog.AcceptOpen, fileMode = QFileDialog.ExistingFile, filter = QString(), selectedFilter = None, useEncoding = False):
def getDialog(self, parent = None, caption = '', acceptMode = QFileDialog.AcceptOpen, fileMode = QFileDialog.ExistingFile, filter = '', selectedFilter = None, useEncoding = False):
if useEncoding:
dialog = QgsEncodingFileDialog(parent, caption, getLastUsedDir(), filter, getLastUsedEncoding())
else:
@@ -351,8 +351,8 @@ def getDialog(self, parent = None, caption = QString(), acceptMode = QFileDialog

if not dialog.exec_():
if useEncoding:
return (QString(), None)
return QString()
return ('', None)
return ''

# change the selected filter value
if selectedFilter != None:
@@ -390,34 +390,34 @@ def getDialog(self, parent = None, caption = QString(), acceptMode = QFileDialog
return files

@classmethod
def getOpenFileNames(self, parent = None, caption = QString(), filter = QString(), selectedFilter = None, useEncoding = False):
def getOpenFileNames(self, parent = None, caption = '', filter = '', selectedFilter = None, useEncoding = False):
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.ExistingFiles, filter, selectedFilter, useEncoding)

@classmethod
def getOpenFileName(self, parent = None, caption = QString(), filter = QString(), selectedFilter = None, useEncoding = False):
def getOpenFileName(self, parent = None, caption = '', filter = '', selectedFilter = None, useEncoding = False):
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.ExistingFile, filter, selectedFilter, useEncoding)

@classmethod
def getSaveFileName(self, parent = None, caption = QString(), filter = QString(), selectedFilter = None, useEncoding = False):
def getSaveFileName(self, parent = None, caption = '', filter = '', selectedFilter = None, useEncoding = False):
return self.getDialog(parent, caption, QFileDialog.AcceptSave, QFileDialog.AnyFile, filter, selectedFilter, useEncoding)

@classmethod
def getExistingDirectory(self, parent = None, caption = QString(), useEncoding = False):
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.DirectoryOnly, QString(), None, useEncoding)
def getExistingDirectory(self, parent = None, caption = '', useEncoding = False):
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.DirectoryOnly, '', None, useEncoding)

class FileFilter:
@classmethod
def getFilter(self, typeName):
settings = QSettings()
return settings.value( "/GdalTools/" + typeName + "FileFilter", QVariant( "" ) ).toString()
return settings.value( "/GdalTools/" + typeName + "FileFilter", u"" )

@classmethod
def setFilter(self, typeName, aFilter):
settings = QSettings()
settings.setValue( "/GdalTools/" + typeName + "FileFilter", QVariant( aFilter ) )

# stores the supported raster file filter
rastersFilter = QString()
rastersFilter = ''

# Retrieves the filter for supported raster files
@classmethod
@@ -429,7 +429,7 @@ def allRastersFilter(self):
# separates multiple extensions that joined by a slash
if QGis.QGIS_VERSION[0:3] < "1.5":
formats = self.rastersFilter.split( ";;" )
self.rastersFilter = QString()
self.rastersFilter = ''
for f in formats:
oldExts = QString(f).remove( QRegExp('^.*\(') ).remove( QRegExp('\).*$') )
newExts = QString(oldExts).replace( '/', ' *.' )
@@ -448,7 +448,7 @@ def setLastUsedRasterFilter(self, aFilter):
self.setFilter("lastRaster", aFilter)

# stores the supported vectors file filter
vectorsFilter = QString()
vectorsFilter = ''

# Retrieves the filter for supported vector files
@classmethod
@@ -533,7 +533,7 @@ def getSupportedRasters(self):

longName = QString(driver.LongName).remove( QRegExp( '\(.*$' ) ).trimmed()
shortName = QString(driver.ShortName).remove( QRegExp( '\(.*$' ) ).trimmed()
extensions = QString()
extensions = ''

description = QString(driver.GetDescription())
glob = QStringList()
@@ -597,7 +597,7 @@ def getSupportedVectors(self):
continue

driverName = QString(driver.GetName())
longName = QString()
longName = ''
glob = QStringList()

if driverName.startsWith( "AVCBin" ):
@@ -711,7 +711,7 @@ class SupportedRasters:
@classmethod
def long2ShortName(self, longName):
if longName.isEmpty():
return QString()
return ''

if self.dict_long2shortName.has_key(longName):
return self.dict_long2shortName[longName]
@@ -720,7 +720,7 @@ def long2ShortName(self, longName):
if gdal.GetDriverCount() == 0:
gdal.AllRegister()

shortName = QString()
shortName = ''

# for each loaded GDAL driver
for i in range(gdal.GetDriverCount()):
@@ -740,9 +740,9 @@ def long2ShortName(self, longName):
@classmethod
def filename2ShortName(self, fileName):
if fileName.isEmpty():
return QString()
return ''

shortName = QString()
shortName = ''

# for each raster format search for the file extension
formats = FileFilter.allRastersFilter().split( ";;" )
@@ -57,4 +57,4 @@ def getProjection(self):
if not self.selector.selectedProj4String().isEmpty():
return self.proj4string()

return QString()
return ''
@@ -98,7 +98,7 @@ def getArguments(self):
arguments << self.attributeEdit.text()
if True: # XXX in this moment the -i argument is not optional
arguments << "-i"
arguments << QString(str(self.intervalDSpinBox.value()))
arguments << unicode(self.intervalDSpinBox.value())
arguments << self.getInputFileName()
arguments << self.outSelector.filename()
return arguments
@@ -198,7 +198,7 @@ def algorithmArguments(self, index):
arguments.append("nodata=" + str(self.datametricsNoDataSpin.value()))
return arguments.join(":")

def loadFields(self, vectorFile = QString()):
def loadFields(self, vectorFile = ''):
self.zfieldCombo.clear()

if vectorFile.isEmpty():
@@ -66,7 +66,7 @@ def __init__( self, iface ):


def doCopyLine( self ):
output = QString()
output = ''
items = self.rasterInfoList.selectedItems()
for r in items:
output.append( r.text() + "\n" )
@@ -75,7 +75,7 @@ def doCopyLine( self ):
clipboard.setText( output )

def doCopyAll( self ):
output = QString()
output = ''
for r in range( self.rasterInfoList.count() ):
output.append( self.rasterInfoList.item( r ).text() + "\n" )
if not output.isEmpty():
@@ -84,7 +84,7 @@ def doCopyAll( self ):

def keyPressEvent( self, e ):
if ( e.modifiers() == Qt.ControlModifier or e.modifiers() == Qt.MetaModifier ) and e.key() == Qt.Key_C:
items = QString()
items = ''
for r in range( self.rasterInfoList.count() ):
items.append( self.rasterInfoList.item( r ).text() + "\n" )
if not items.isEmpty():
@@ -122,7 +122,7 @@ def getArguments( self ):

inputFn = self.getInputFileName()
arguments << inputFn
self.tempFile = QString( inputFn )
self.tempFile = inputFn
self.needOverwrite = False
if not self.tempFile.isEmpty():
if self.tempFile.toLower().contains( QRegExp( "\.tif{1,2}" ) ):
@@ -157,7 +157,7 @@ def getOutputFileName( self ):

def getBatchOutputFileName(self, fn):
# get GeoTiff
fn = QString( fn ).replace( QRegExp( "\.[a-zA-Z]{2,4}$" ), ".tif" )
fn = re.sub( r'\.[a-zA-Z]{2,4}$', r'.tif', fn )
return BaseBatchWidget.getBatchOutputFileName( self, fn )

def addLayerIntoCanvas(self, fileInfo):
@@ -145,7 +145,7 @@ def fillInputDir( self ):
workDir.setNameFilters( filter )

# search for a valid SRS, then use it as default target SRS
srs = QString()
srs = ''
for fname in workDir.entryList():
fl = inputDir + "/" + fname
srs = Utils.getRasterSRS( self, fl )
@@ -132,8 +132,8 @@ def setFilename(self, fn=None):
if isinstance(fn, QgsMapLayer):
fn = fn.source()

elif isinstance(fn, str) or isinstance(fn, unicode) or isinstance(fn, QString):
fn = QString( fn )
elif isinstance(fn, str) or isinstance(fn, unicode):
fn = unicode( fn )

elif hasattr(fn, '__iter__') or isinstance(fn, QStringList):
if len( fn ) > 0:
@@ -142,10 +142,10 @@ def setFilename(self, fn=None):
self.filenames = fn
fn = fn.join( "," )
else:
fn = QString()
fn = ''

else:
fn = QString()
fn = ''

if not (self.getType() & self.LAYER):
self.fileEdit.setText( fn )
@@ -215,7 +215,7 @@ def clearComboState(self):
def saveComboState(self):
index = self.combo.currentIndex()
text = self.combo.currentText()
layerID = self.combo.itemData(index).toString() if index >= 0 else ""
layerID = self.combo.itemData(index) if index >= 0 else ""
self.prevState = ( index, text, layerID )

def restoreComboState(self):
@@ -241,7 +241,7 @@ def restoreComboState(self):

def layer(self):
if self.getType() != self.FILE and self.combo.currentIndex() >= 0:
layerID = self.combo.itemData(self.combo.currentIndex()).toString()
layerID = self.combo.itemData(self.combo.currentIndex())
return QgsMapLayerRegistry.instance().mapLayer( layerID )
return None

@@ -259,5 +259,5 @@ def filename(self):
if layer != None:
return layer.source()

return QString()
return ''

0 comments on commit 52b773f

Please sign in to comment.
You can’t perform that action at this time.