mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Patch from Matthias for gdal tools
This commit is contained in:
parent
63cc02d67e
commit
52b773fb14
@ -71,11 +71,11 @@ class GdalTools:
|
|||||||
userPluginPath = QFileInfo( QgsApplication.qgisUserDbFilePath() ).path() + "/python/plugins/GdalTools"
|
userPluginPath = QFileInfo( QgsApplication.qgisUserDbFilePath() ).path() + "/python/plugins/GdalTools"
|
||||||
systemPluginPath = QgsApplication.prefixPath() + "/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:
|
if not overrideLocale:
|
||||||
localeFullName = QLocale.system().name()
|
localeFullName = QLocale.system().name()
|
||||||
else:
|
else:
|
||||||
localeFullName = QSettings().value( "locale/userLocale", QVariant( "" ) ).toString()
|
localeFullName = QSettings().value( "locale/userLocale", "" )
|
||||||
|
|
||||||
if QFileInfo( userPluginPath ).exists():
|
if QFileInfo( userPluginPath ).exists():
|
||||||
translationPath = userPluginPath + "/i18n/GdalTools_" + localeFullName + ".qm"
|
translationPath = userPluginPath + "/i18n/GdalTools_" + localeFullName + ".qm"
|
||||||
|
@ -45,20 +45,20 @@ import sys
|
|||||||
|
|
||||||
# Escapes arguments and return them joined in a string
|
# Escapes arguments and return them joined in a string
|
||||||
def escapeAndJoin(strList):
|
def escapeAndJoin(strList):
|
||||||
joined = QString()
|
joined = ''
|
||||||
for s in strList:
|
for s in strList:
|
||||||
if s.contains(" "):
|
if s.find(" ") is not -1:
|
||||||
escaped = '"' + s.replace('\\', '\\\\').replace('"', '\\"') + '"'
|
escaped = '"' + s.replace('\\', '\\\\').replace('"', '\\"') + '"'
|
||||||
else:
|
else:
|
||||||
escaped = s
|
escaped = s
|
||||||
joined += escaped + " "
|
joined += escaped + " "
|
||||||
return joined.trimmed()
|
return joined.strip()
|
||||||
|
|
||||||
# Retrieves last used dir from persistent settings
|
# Retrieves last used dir from persistent settings
|
||||||
def getLastUsedDir():
|
def getLastUsedDir():
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
lastProjectDir = settings.value( "/UI/lastProjectDir", QVariant(".") ).toString()
|
lastProjectDir = settings.value( "/UI/lastProjectDir", u"." )
|
||||||
return settings.value( "/GdalTools/lastUsedDir", QVariant(lastProjectDir) ).toString()
|
return settings.value( "/GdalTools/lastUsedDir", QVariant(lastProjectDir) )
|
||||||
|
|
||||||
# Stores last used dir in persistent settings
|
# Stores last used dir in persistent settings
|
||||||
def setLastUsedDir(filePath):
|
def setLastUsedDir(filePath):
|
||||||
@ -73,7 +73,7 @@ def setLastUsedDir(filePath):
|
|||||||
# Retrieves GDAL binaries location
|
# Retrieves GDAL binaries location
|
||||||
def getGdalBinPath():
|
def getGdalBinPath():
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
return settings.value( "/GdalTools/gdalPath", QVariant( "" ) ).toString()
|
return settings.value( "/GdalTools/gdalPath", u"" )
|
||||||
|
|
||||||
# Stores GDAL binaries location
|
# Stores GDAL binaries location
|
||||||
def setGdalBinPath( path ):
|
def setGdalBinPath( path ):
|
||||||
@ -83,7 +83,7 @@ def setGdalBinPath( path ):
|
|||||||
# Retrieves GDAL python modules location
|
# Retrieves GDAL python modules location
|
||||||
def getGdalPymodPath():
|
def getGdalPymodPath():
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
return settings.value( "/GdalTools/gdalPymodPath", QVariant( "" ) ).toString()
|
return settings.value( "/GdalTools/gdalPymodPath", u"" )
|
||||||
|
|
||||||
# Stores GDAL python modules location
|
# Stores GDAL python modules location
|
||||||
def setGdalPymodPath( path ):
|
def setGdalPymodPath( path ):
|
||||||
@ -93,7 +93,7 @@ def setGdalPymodPath( path ):
|
|||||||
# Retrieves GDAL help files location
|
# Retrieves GDAL help files location
|
||||||
def getHelpPath():
|
def getHelpPath():
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
return settings.value( "/GdalTools/helpPath", QVariant( "" ) ).toString()
|
return settings.value( "/GdalTools/helpPath", u"" )
|
||||||
|
|
||||||
# Stores GDAL help files location
|
# Stores GDAL help files location
|
||||||
def setHelpPath( path ):
|
def setHelpPath( path ):
|
||||||
@ -103,7 +103,7 @@ def setHelpPath( path ):
|
|||||||
# Retrieves last used encoding from persistent settings
|
# Retrieves last used encoding from persistent settings
|
||||||
def getLastUsedEncoding():
|
def getLastUsedEncoding():
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
return settings.value( "/UI/encoding", QVariant("System") ).toString()
|
return settings.value( "/UI/encoding", u"System" )
|
||||||
|
|
||||||
# Stores last used encoding in persistent settings
|
# Stores last used encoding in persistent settings
|
||||||
def setLastUsedEncoding(encoding):
|
def setLastUsedEncoding(encoding):
|
||||||
@ -220,7 +220,7 @@ def getRasterFiles(path, recursive=False):
|
|||||||
return rasters
|
return rasters
|
||||||
|
|
||||||
def fillRasterOutputFormat(aFilter = None, filename = None):
|
def fillRasterOutputFormat(aFilter = None, filename = None):
|
||||||
shortName = QString()
|
shortName = ''
|
||||||
|
|
||||||
if aFilter != None:
|
if aFilter != None:
|
||||||
supportedRasters = GdalConfig.getSupportedRasters()
|
supportedRasters = GdalConfig.getSupportedRasters()
|
||||||
@ -239,7 +239,7 @@ def fillRasterOutputFormat(aFilter = None, filename = None):
|
|||||||
return shortName
|
return shortName
|
||||||
|
|
||||||
def fillVectorOutputFormat(aFilter = None, filename = None):
|
def fillVectorOutputFormat(aFilter = None, filename = None):
|
||||||
shortName = QString()
|
shortName = ''
|
||||||
|
|
||||||
if aFilter != None:
|
if aFilter != None:
|
||||||
supportedVectors = GdalConfig.getSupportedVectors()
|
supportedVectors = GdalConfig.getSupportedVectors()
|
||||||
@ -292,11 +292,11 @@ def getRasterSRS( parent, fileName ):
|
|||||||
processSRS.close()
|
processSRS.close()
|
||||||
|
|
||||||
if arr.isEmpty():
|
if arr.isEmpty():
|
||||||
return QString()
|
return ''
|
||||||
|
|
||||||
info = QString( arr ).split( "\n" ).filter( "AUTHORITY" )
|
info = QString( arr ).split( "\n" ).filter( "AUTHORITY" )
|
||||||
if info.count() == 0:
|
if info.count() == 0:
|
||||||
return QString()
|
return ''
|
||||||
|
|
||||||
srs = info[ info.count() - 1 ]
|
srs = info[ info.count() - 1 ]
|
||||||
srs = srs.simplified().remove( "AUTHORITY[" )
|
srs = srs.simplified().remove( "AUTHORITY[" )
|
||||||
@ -338,7 +338,7 @@ def getRasterExtent(parent, fileName):
|
|||||||
# so sometimes the dialog excedes the screen width
|
# so sometimes the dialog excedes the screen width
|
||||||
class FileDialog:
|
class FileDialog:
|
||||||
@classmethod
|
@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:
|
if useEncoding:
|
||||||
dialog = QgsEncodingFileDialog(parent, caption, getLastUsedDir(), filter, getLastUsedEncoding())
|
dialog = QgsEncodingFileDialog(parent, caption, getLastUsedDir(), filter, getLastUsedEncoding())
|
||||||
else:
|
else:
|
||||||
@ -351,8 +351,8 @@ class FileDialog:
|
|||||||
|
|
||||||
if not dialog.exec_():
|
if not dialog.exec_():
|
||||||
if useEncoding:
|
if useEncoding:
|
||||||
return (QString(), None)
|
return ('', None)
|
||||||
return QString()
|
return ''
|
||||||
|
|
||||||
# change the selected filter value
|
# change the selected filter value
|
||||||
if selectedFilter != None:
|
if selectedFilter != None:
|
||||||
@ -390,26 +390,26 @@ class FileDialog:
|
|||||||
return files
|
return files
|
||||||
|
|
||||||
@classmethod
|
@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)
|
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.ExistingFiles, filter, selectedFilter, useEncoding)
|
||||||
|
|
||||||
@classmethod
|
@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)
|
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.ExistingFile, filter, selectedFilter, useEncoding)
|
||||||
|
|
||||||
@classmethod
|
@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)
|
return self.getDialog(parent, caption, QFileDialog.AcceptSave, QFileDialog.AnyFile, filter, selectedFilter, useEncoding)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getExistingDirectory(self, parent = None, caption = QString(), useEncoding = False):
|
def getExistingDirectory(self, parent = None, caption = '', useEncoding = False):
|
||||||
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.DirectoryOnly, QString(), None, useEncoding)
|
return self.getDialog(parent, caption, QFileDialog.AcceptOpen, QFileDialog.DirectoryOnly, '', None, useEncoding)
|
||||||
|
|
||||||
class FileFilter:
|
class FileFilter:
|
||||||
@classmethod
|
@classmethod
|
||||||
def getFilter(self, typeName):
|
def getFilter(self, typeName):
|
||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
return settings.value( "/GdalTools/" + typeName + "FileFilter", QVariant( "" ) ).toString()
|
return settings.value( "/GdalTools/" + typeName + "FileFilter", u"" )
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setFilter(self, typeName, aFilter):
|
def setFilter(self, typeName, aFilter):
|
||||||
@ -417,7 +417,7 @@ class FileFilter:
|
|||||||
settings.setValue( "/GdalTools/" + typeName + "FileFilter", QVariant( aFilter ) )
|
settings.setValue( "/GdalTools/" + typeName + "FileFilter", QVariant( aFilter ) )
|
||||||
|
|
||||||
# stores the supported raster file filter
|
# stores the supported raster file filter
|
||||||
rastersFilter = QString()
|
rastersFilter = ''
|
||||||
|
|
||||||
# Retrieves the filter for supported raster files
|
# Retrieves the filter for supported raster files
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -429,7 +429,7 @@ class FileFilter:
|
|||||||
# separates multiple extensions that joined by a slash
|
# separates multiple extensions that joined by a slash
|
||||||
if QGis.QGIS_VERSION[0:3] < "1.5":
|
if QGis.QGIS_VERSION[0:3] < "1.5":
|
||||||
formats = self.rastersFilter.split( ";;" )
|
formats = self.rastersFilter.split( ";;" )
|
||||||
self.rastersFilter = QString()
|
self.rastersFilter = ''
|
||||||
for f in formats:
|
for f in formats:
|
||||||
oldExts = QString(f).remove( QRegExp('^.*\(') ).remove( QRegExp('\).*$') )
|
oldExts = QString(f).remove( QRegExp('^.*\(') ).remove( QRegExp('\).*$') )
|
||||||
newExts = QString(oldExts).replace( '/', ' *.' )
|
newExts = QString(oldExts).replace( '/', ' *.' )
|
||||||
@ -448,7 +448,7 @@ class FileFilter:
|
|||||||
self.setFilter("lastRaster", aFilter)
|
self.setFilter("lastRaster", aFilter)
|
||||||
|
|
||||||
# stores the supported vectors file filter
|
# stores the supported vectors file filter
|
||||||
vectorsFilter = QString()
|
vectorsFilter = ''
|
||||||
|
|
||||||
# Retrieves the filter for supported vector files
|
# Retrieves the filter for supported vector files
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -533,7 +533,7 @@ class GdalConfig:
|
|||||||
|
|
||||||
longName = QString(driver.LongName).remove( QRegExp( '\(.*$' ) ).trimmed()
|
longName = QString(driver.LongName).remove( QRegExp( '\(.*$' ) ).trimmed()
|
||||||
shortName = QString(driver.ShortName).remove( QRegExp( '\(.*$' ) ).trimmed()
|
shortName = QString(driver.ShortName).remove( QRegExp( '\(.*$' ) ).trimmed()
|
||||||
extensions = QString()
|
extensions = ''
|
||||||
|
|
||||||
description = QString(driver.GetDescription())
|
description = QString(driver.GetDescription())
|
||||||
glob = QStringList()
|
glob = QStringList()
|
||||||
@ -597,7 +597,7 @@ class GdalConfig:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
driverName = QString(driver.GetName())
|
driverName = QString(driver.GetName())
|
||||||
longName = QString()
|
longName = ''
|
||||||
glob = QStringList()
|
glob = QStringList()
|
||||||
|
|
||||||
if driverName.startsWith( "AVCBin" ):
|
if driverName.startsWith( "AVCBin" ):
|
||||||
@ -711,7 +711,7 @@ class GdalConfig:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def long2ShortName(self, longName):
|
def long2ShortName(self, longName):
|
||||||
if longName.isEmpty():
|
if longName.isEmpty():
|
||||||
return QString()
|
return ''
|
||||||
|
|
||||||
if self.dict_long2shortName.has_key(longName):
|
if self.dict_long2shortName.has_key(longName):
|
||||||
return self.dict_long2shortName[longName]
|
return self.dict_long2shortName[longName]
|
||||||
@ -720,7 +720,7 @@ class GdalConfig:
|
|||||||
if gdal.GetDriverCount() == 0:
|
if gdal.GetDriverCount() == 0:
|
||||||
gdal.AllRegister()
|
gdal.AllRegister()
|
||||||
|
|
||||||
shortName = QString()
|
shortName = ''
|
||||||
|
|
||||||
# for each loaded GDAL driver
|
# for each loaded GDAL driver
|
||||||
for i in range(gdal.GetDriverCount()):
|
for i in range(gdal.GetDriverCount()):
|
||||||
@ -740,9 +740,9 @@ class GdalConfig:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def filename2ShortName(self, fileName):
|
def filename2ShortName(self, fileName):
|
||||||
if fileName.isEmpty():
|
if fileName.isEmpty():
|
||||||
return QString()
|
return ''
|
||||||
|
|
||||||
shortName = QString()
|
shortName = ''
|
||||||
|
|
||||||
# for each raster format search for the file extension
|
# for each raster format search for the file extension
|
||||||
formats = FileFilter.allRastersFilter().split( ";;" )
|
formats = FileFilter.allRastersFilter().split( ";;" )
|
||||||
|
@ -57,4 +57,4 @@ class GdalToolsSRSDialog(QDialog):
|
|||||||
if not self.selector.selectedProj4String().isEmpty():
|
if not self.selector.selectedProj4String().isEmpty():
|
||||||
return self.proj4string()
|
return self.proj4string()
|
||||||
|
|
||||||
return QString()
|
return ''
|
||||||
|
@ -98,7 +98,7 @@ class GdalToolsDialog(QWidget, Ui_Widget, BasePluginWidget):
|
|||||||
arguments << self.attributeEdit.text()
|
arguments << self.attributeEdit.text()
|
||||||
if True: # XXX in this moment the -i argument is not optional
|
if True: # XXX in this moment the -i argument is not optional
|
||||||
arguments << "-i"
|
arguments << "-i"
|
||||||
arguments << QString(str(self.intervalDSpinBox.value()))
|
arguments << unicode(self.intervalDSpinBox.value())
|
||||||
arguments << self.getInputFileName()
|
arguments << self.getInputFileName()
|
||||||
arguments << self.outSelector.filename()
|
arguments << self.outSelector.filename()
|
||||||
return arguments
|
return arguments
|
||||||
|
@ -198,7 +198,7 @@ class GdalToolsDialog(QWidget, Ui_Widget, BasePluginWidget):
|
|||||||
arguments.append("nodata=" + str(self.datametricsNoDataSpin.value()))
|
arguments.append("nodata=" + str(self.datametricsNoDataSpin.value()))
|
||||||
return arguments.join(":")
|
return arguments.join(":")
|
||||||
|
|
||||||
def loadFields(self, vectorFile = QString()):
|
def loadFields(self, vectorFile = ''):
|
||||||
self.zfieldCombo.clear()
|
self.zfieldCombo.clear()
|
||||||
|
|
||||||
if vectorFile.isEmpty():
|
if vectorFile.isEmpty():
|
||||||
|
@ -66,7 +66,7 @@ class GdalToolsDialog( QWidget, Ui_Widget, BasePluginWidget ):
|
|||||||
|
|
||||||
|
|
||||||
def doCopyLine( self ):
|
def doCopyLine( self ):
|
||||||
output = QString()
|
output = ''
|
||||||
items = self.rasterInfoList.selectedItems()
|
items = self.rasterInfoList.selectedItems()
|
||||||
for r in items:
|
for r in items:
|
||||||
output.append( r.text() + "\n" )
|
output.append( r.text() + "\n" )
|
||||||
@ -75,7 +75,7 @@ class GdalToolsDialog( QWidget, Ui_Widget, BasePluginWidget ):
|
|||||||
clipboard.setText( output )
|
clipboard.setText( output )
|
||||||
|
|
||||||
def doCopyAll( self ):
|
def doCopyAll( self ):
|
||||||
output = QString()
|
output = ''
|
||||||
for r in range( self.rasterInfoList.count() ):
|
for r in range( self.rasterInfoList.count() ):
|
||||||
output.append( self.rasterInfoList.item( r ).text() + "\n" )
|
output.append( self.rasterInfoList.item( r ).text() + "\n" )
|
||||||
if not output.isEmpty():
|
if not output.isEmpty():
|
||||||
@ -84,7 +84,7 @@ class GdalToolsDialog( QWidget, Ui_Widget, BasePluginWidget ):
|
|||||||
|
|
||||||
def keyPressEvent( self, e ):
|
def keyPressEvent( self, e ):
|
||||||
if ( e.modifiers() == Qt.ControlModifier or e.modifiers() == Qt.MetaModifier ) and e.key() == Qt.Key_C:
|
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() ):
|
for r in range( self.rasterInfoList.count() ):
|
||||||
items.append( self.rasterInfoList.item( r ).text() + "\n" )
|
items.append( self.rasterInfoList.item( r ).text() + "\n" )
|
||||||
if not items.isEmpty():
|
if not items.isEmpty():
|
||||||
|
@ -122,7 +122,7 @@ class GdalToolsDialog( QWidget, Ui_Widget, BaseBatchWidget ):
|
|||||||
|
|
||||||
inputFn = self.getInputFileName()
|
inputFn = self.getInputFileName()
|
||||||
arguments << inputFn
|
arguments << inputFn
|
||||||
self.tempFile = QString( inputFn )
|
self.tempFile = inputFn
|
||||||
self.needOverwrite = False
|
self.needOverwrite = False
|
||||||
if not self.tempFile.isEmpty():
|
if not self.tempFile.isEmpty():
|
||||||
if self.tempFile.toLower().contains( QRegExp( "\.tif{1,2}" ) ):
|
if self.tempFile.toLower().contains( QRegExp( "\.tif{1,2}" ) ):
|
||||||
@ -157,7 +157,7 @@ class GdalToolsDialog( QWidget, Ui_Widget, BaseBatchWidget ):
|
|||||||
|
|
||||||
def getBatchOutputFileName(self, fn):
|
def getBatchOutputFileName(self, fn):
|
||||||
# get GeoTiff
|
# 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 )
|
return BaseBatchWidget.getBatchOutputFileName( self, fn )
|
||||||
|
|
||||||
def addLayerIntoCanvas(self, fileInfo):
|
def addLayerIntoCanvas(self, fileInfo):
|
||||||
|
@ -145,7 +145,7 @@ class GdalToolsDialog(QWidget, Ui_Widget, BaseBatchWidget):
|
|||||||
workDir.setNameFilters( filter )
|
workDir.setNameFilters( filter )
|
||||||
|
|
||||||
# search for a valid SRS, then use it as default target SRS
|
# search for a valid SRS, then use it as default target SRS
|
||||||
srs = QString()
|
srs = ''
|
||||||
for fname in workDir.entryList():
|
for fname in workDir.entryList():
|
||||||
fl = inputDir + "/" + fname
|
fl = inputDir + "/" + fname
|
||||||
srs = Utils.getRasterSRS( self, fl )
|
srs = Utils.getRasterSRS( self, fl )
|
||||||
|
@ -132,8 +132,8 @@ class GdalToolsInOutSelector(QWidget, Ui_GdalToolsInOutSelector):
|
|||||||
if isinstance(fn, QgsMapLayer):
|
if isinstance(fn, QgsMapLayer):
|
||||||
fn = fn.source()
|
fn = fn.source()
|
||||||
|
|
||||||
elif isinstance(fn, str) or isinstance(fn, unicode) or isinstance(fn, QString):
|
elif isinstance(fn, str) or isinstance(fn, unicode):
|
||||||
fn = QString( fn )
|
fn = unicode( fn )
|
||||||
|
|
||||||
elif hasattr(fn, '__iter__') or isinstance(fn, QStringList):
|
elif hasattr(fn, '__iter__') or isinstance(fn, QStringList):
|
||||||
if len( fn ) > 0:
|
if len( fn ) > 0:
|
||||||
@ -142,10 +142,10 @@ class GdalToolsInOutSelector(QWidget, Ui_GdalToolsInOutSelector):
|
|||||||
self.filenames = fn
|
self.filenames = fn
|
||||||
fn = fn.join( "," )
|
fn = fn.join( "," )
|
||||||
else:
|
else:
|
||||||
fn = QString()
|
fn = ''
|
||||||
|
|
||||||
else:
|
else:
|
||||||
fn = QString()
|
fn = ''
|
||||||
|
|
||||||
if not (self.getType() & self.LAYER):
|
if not (self.getType() & self.LAYER):
|
||||||
self.fileEdit.setText( fn )
|
self.fileEdit.setText( fn )
|
||||||
@ -215,7 +215,7 @@ class GdalToolsInOutSelector(QWidget, Ui_GdalToolsInOutSelector):
|
|||||||
def saveComboState(self):
|
def saveComboState(self):
|
||||||
index = self.combo.currentIndex()
|
index = self.combo.currentIndex()
|
||||||
text = self.combo.currentText()
|
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 )
|
self.prevState = ( index, text, layerID )
|
||||||
|
|
||||||
def restoreComboState(self):
|
def restoreComboState(self):
|
||||||
@ -241,7 +241,7 @@ class GdalToolsInOutSelector(QWidget, Ui_GdalToolsInOutSelector):
|
|||||||
|
|
||||||
def layer(self):
|
def layer(self):
|
||||||
if self.getType() != self.FILE and self.combo.currentIndex() >= 0:
|
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 QgsMapLayerRegistry.instance().mapLayer( layerID )
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -259,5 +259,5 @@ class GdalToolsInOutSelector(QWidget, Ui_GdalToolsInOutSelector):
|
|||||||
if layer != None:
|
if layer != None:
|
||||||
return layer.source()
|
return layer.source()
|
||||||
|
|
||||||
return QString()
|
return ''
|
||||||
|
|
||||||
|
@ -37,9 +37,9 @@ class GdalToolsBaseBatchWidget(BasePluginWidget):
|
|||||||
BasePluginWidget.__init__(self, iface, commandName)
|
BasePluginWidget.__init__(self, iface, commandName)
|
||||||
|
|
||||||
def getBatchArguments(self, inFile, outFile = None):
|
def getBatchArguments(self, inFile, outFile = None):
|
||||||
arguments = QStringList()
|
arguments = []
|
||||||
arguments << self.getArguments()
|
arguments.append( self.getArguments() )
|
||||||
arguments << inFile
|
arguments.append( inFile )
|
||||||
if outFile != None:
|
if outFile != None:
|
||||||
arguments << outFile
|
arguments << outFile
|
||||||
return arguments
|
return arguments
|
||||||
@ -62,9 +62,9 @@ class GdalToolsBaseBatchWidget(BasePluginWidget):
|
|||||||
|
|
||||||
# if overwrites existent files
|
# if overwrites existent files
|
||||||
if outDir == None or outDir == inDir:
|
if outDir == None or outDir == inDir:
|
||||||
return QString( fn ).append( ".tmp" )
|
return fn + ".tmp"
|
||||||
|
|
||||||
return QString( fn ).mid( len(inDir) ).prepend( outDir )
|
return outDir + fn[len(inDir):]
|
||||||
|
|
||||||
def onRun( self ):
|
def onRun( self ):
|
||||||
if not self.isBatchEnabled():
|
if not self.isBatchEnabled():
|
||||||
@ -85,7 +85,7 @@ class GdalToolsBaseBatchWidget(BasePluginWidget):
|
|||||||
for f in self.inFiles:
|
for f in self.inFiles:
|
||||||
self.outFiles.append( self.getBatchOutputFileName( f ) )
|
self.outFiles.append( self.getBatchOutputFileName( f ) )
|
||||||
|
|
||||||
self.errors = QStringList()
|
self.errors = []
|
||||||
self.batchIndex = 0
|
self.batchIndex = 0
|
||||||
self.batchTotal = len( self.inFiles )
|
self.batchTotal = len( self.inFiles )
|
||||||
self.setProgressRange( self.batchTotal )
|
self.setProgressRange( self.batchTotal )
|
||||||
@ -112,7 +112,7 @@ class GdalToolsBaseBatchWidget(BasePluginWidget):
|
|||||||
BasePluginWidget.onFinished(self, exitCode, status)
|
BasePluginWidget.onFinished(self, exitCode, status)
|
||||||
return
|
return
|
||||||
|
|
||||||
msg = QString.fromLocal8Bit( self.base.process.readAllStandardError() )
|
msg = bytes.decode( bytes( self.base.process.readAllStandardError() ) )
|
||||||
if not msg.isEmpty():
|
if not msg.isEmpty():
|
||||||
self.errors.append( ">> " + self.inFiles[self.batchIndex] + "<br>" + msg.replace( "\n", "<br>" ) )
|
self.errors.append( ">> " + self.inFiles[self.batchIndex] + "<br>" + msg.replace( "\n", "<br>" ) )
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class GdalToolsBaseBatchWidget(BasePluginWidget):
|
|||||||
self.base.stop()
|
self.base.stop()
|
||||||
|
|
||||||
if not self.errors.isEmpty():
|
if not self.errors.isEmpty():
|
||||||
msg = QString( "Processing of the following files ended with error: <br><br>" ).append( self.errors.join( "<br><br>" ) )
|
msg = u"Processing of the following files ended with error: <br><br>" + "<br><br>".join( self.errors )
|
||||||
QErrorMessage( self ).showMessage( msg )
|
QErrorMessage( self ).showMessage( msg )
|
||||||
|
|
||||||
inDir = self.getInputFileName()
|
inDir = self.getInputFileName()
|
||||||
@ -146,17 +146,17 @@ class GdalToolsBaseBatchWidget(BasePluginWidget):
|
|||||||
canvas = self.iface.mapCanvas()
|
canvas = self.iface.mapCanvas()
|
||||||
previousRenderFlag = canvas.renderFlag()
|
previousRenderFlag = canvas.renderFlag()
|
||||||
canvas.setRenderFlag( False )
|
canvas.setRenderFlag( False )
|
||||||
notCreatedList = QStringList()
|
notCreatedList = []
|
||||||
for item in self.outFiles:
|
for item in self.outFiles:
|
||||||
fileInfo = QFileInfo( item )
|
fileInfo = QFileInfo( item )
|
||||||
if fileInfo.exists():
|
if fileInfo.exists():
|
||||||
if self.base.loadCheckBox.isChecked():
|
if self.base.loadCheckBox.isChecked():
|
||||||
self.addLayerIntoCanvas( fileInfo )
|
self.addLayerIntoCanvas( fileInfo )
|
||||||
else:
|
else:
|
||||||
notCreatedList << item
|
notCreatedList.append( item )
|
||||||
canvas.setRenderFlag( previousRenderFlag )
|
canvas.setRenderFlag( previousRenderFlag )
|
||||||
|
|
||||||
if notCreatedList.isEmpty():
|
if len( notCreatedList ) == 0:
|
||||||
QMessageBox.information( self, self.tr( "Finished" ), self.tr( "Operation completed." ) )
|
QMessageBox.information( self, self.tr( "Finished" ), self.tr( "Operation completed." ) )
|
||||||
else:
|
else:
|
||||||
QMessageBox.warning( self, self.tr( "Warning" ), self.tr( "The following files were not created: \n%1" ).arg( notCreatedList.join( ", " ) ) )
|
QMessageBox.warning( self, self.tr( "Warning" ), self.tr( "The following files were not created: \n%1" ).arg( notCreatedList.join( ", " ) ) )
|
||||||
|
@ -106,8 +106,7 @@ class GdalToolsBasePluginWidget:
|
|||||||
if outFn == None:
|
if outFn == None:
|
||||||
return
|
return
|
||||||
|
|
||||||
outFn = QString(outFn)
|
if outFn == '':
|
||||||
if outFn.isEmpty():
|
|
||||||
QMessageBox.warning(self, self.tr( "Warning" ), self.tr( "No output file created." ) )
|
QMessageBox.warning(self, self.tr( "Warning" ), self.tr( "No output file created." ) )
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user