Skip to content
Permalink
Browse files

fix gdaltools merge, tileindex and info

  • Loading branch information
etiennesky committed Jun 14, 2013
1 parent 6370153 commit 84d77663d8478e14dbd6534d624545a632db7307
@@ -322,15 +322,24 @@ def getRasterExtent(parent, fileName):
if arr == '':
return

ulCoord = lrCoord = ''
xUL = yLR = xLR = yUL = 0
info = string.split( arr, sep="\n" )
ulCoord = info[ info.indexOf( QRegExp( "^Upper\sLeft.*" ) ) ].simplified()
lrCoord = info[ info.indexOf( QRegExp( "^Lower\sRight.*" ) ) ].simplified()
ulCoord = ulCoord[ulCoord.indexOf( "(" ) + 1 : ulCoord.indexOf( ")" ) - 1].split( "," )
lrCoord = lrCoord[lrCoord.indexOf( "(" ) + 1 : lrCoord.indexOf( ")" ) - 1].split( "," )
xUL = ulCoord[0].toDouble()[0]
yUL = ulCoord[1].toDouble()[0]
xLR = lrCoord[0].toDouble()[0]
yLR = lrCoord[1].toDouble()[0]
for elem in info:
m = re.match("^Upper\sLeft.*", elem)
if m:
ulCoord = m.group(0).strip()
ulCoord = ulCoord[string.find(ulCoord,"(") + 1 : string.find(ulCoord,")") - 1].split( "," )
xUL = float(ulCoord[0])
yUL = float(ulCoord[1])
continue
m = re.match("^Lower\sRight.*", elem)
if m:
lrCoord = m.group(0).strip()
lrCoord = lrCoord[string.find(lrCoord,"(") + 1 : string.find(lrCoord,")") - 1].split( "," )
xLR = float(lrCoord[0])
yLR = float(lrCoord[1])
continue

return QgsRectangle( xUL, yLR, xLR, yUL )

@@ -71,15 +71,15 @@ def doCopyLine( self ):
items = self.rasterInfoList.selectedItems()
for r in items:
output.append( r.text() + "\n" )
if not output.isEmpty():
if output:
clipboard = QApplication.clipboard()
clipboard.setText( output )

def doCopyAll( self ):
output = ''
for r in range( self.rasterInfoList.count() ):
output.append( self.rasterInfoList.item( r ).text() + "\n" )
if not output.isEmpty():
if output:
clipboard = QApplication.clipboard()
clipboard.setText( output )

@@ -88,7 +88,7 @@ def keyPressEvent( self, e ):
items = ''
for r in range( self.rasterInfoList.count() ):
items.append( self.rasterInfoList.item( r ).text() + "\n" )
if not items.isEmpty():
if items:
clipboard = QApplication.clipboard()
clipboard.setText( items )
else:
@@ -111,7 +111,7 @@ def finished( self ):
def fillInputFileEdit( self ):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
inputFile = Utils.FileDialog.getOpenFileName( self, self.tr( "Select the file to analyse" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
if inputFile.isEmpty():
if not inputFile:
return
Utils.FileFilter.setLastUsedRasterFilter( lastUsedFilter )

@@ -45,7 +45,7 @@ def __init__(self, iface):
self.outSelector.setType( self.outSelector.FILE )
self.recurseCheck.hide()
# use this for approx. previous UI
#self.creationOptionsTable.setType(QgsRasterFormatSaveOptionsWidget.Table)
#self.creationOptionsWidget.setType(QgsRasterFormatSaveOptionsWidget.Table)

self.outputFormat = Utils.fillRasterOutputFormat()
self.extent = None
@@ -59,7 +59,9 @@ def __init__(self, iface):
(self.recurseCheck, SIGNAL("stateChanged(int)"), self.inputDirCheck),
( self.separateCheck, SIGNAL( "stateChanged( int )" ) ),
( self.pctCheck, SIGNAL( "stateChanged( int )" ) ),
( self.intersectCheck, SIGNAL( "stateChanged( int )" ) )
( self.intersectCheck, SIGNAL( "stateChanged( int )" ) ),
(self.creationOptionsWidget, SIGNAL("optionsChanged()")),
(self.creationOptionsGroupBox, SIGNAL("toggled(bool)"))
]
)

@@ -88,20 +90,20 @@ def switchToolMode(self):
def fillInputFilesEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
files = Utils.FileDialog.getOpenFileNames(self, self.tr( "Select the files to Merge" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
if files.isEmpty():
if not files:
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)
self.inSelector.setFilename(files)

def refreshExtent(self):
files = self.getInputFileNames()
self.intersectCheck.setEnabled( files.count() > 1 )
self.intersectCheck.setEnabled( len(files) > 1 )

if not self.intersectCheck.isChecked():
self.someValueChanged()
return

if files.count() < 2:
if len(files) < 2:
self.intersectCheck.setChecked( False )
return

@@ -120,7 +122,7 @@ def refreshExtent(self):
def fillOutputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
outputFile = Utils.FileDialog.getSaveFileName(self, self.tr( "Select where to save the Merge output" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
if outputFile.isEmpty():
if not outputFile:
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

@@ -129,37 +131,37 @@ def fillOutputFileEdit(self):

def fillInputDir( self ):
inputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the input directory with files to Merge" ))
if inputDir.isEmpty():
if not inputDir:
return
self.inSelector.setFilename( inputDir )

def getArguments(self):
arguments = QStringList()
arguments = []
if self.intersectCheck.isChecked():
if self.extent != None:
arguments << "-ul_lr"
arguments << str( self.extent.xMinimum() )
arguments << str( self.extent.yMaximum() )
arguments << str( self.extent.xMaximum() )
arguments << str( self.extent.yMinimum() )
arguments.append("-ul_lr")
arguments.append(str( self.extent.xMinimum() ))
arguments.append(str( self.extent.yMaximum() ))
arguments.append(str( self.extent.xMaximum() ))
arguments.append(str( self.extent.yMinimum() ))
if self.noDataCheck.isChecked():
arguments << "-n"
arguments << str(self.noDataSpin.value())
arguments.append("-n")
arguments.append(str(self.noDataSpin.value()))
if self.separateCheck.isChecked():
arguments << "-separate"
arguments.append("-separate")
if self.pctCheck.isChecked():
arguments << "-pct"
if self.creationGroupBox.isChecked():
for opt in self.creationOptionsTable.options():
arguments << "-co"
arguments << opt
arguments.append("-pct")
if self.creationOptionsGroupBox.isChecked():
for opt in self.creationOptionsWidget.options():
arguments.append("-co")
arguments.append(opt)
outputFn = self.getOutputFileName()
if not outputFn.isEmpty():
arguments << "-of"
arguments << self.outputFormat
arguments << "-o"
arguments << outputFn
arguments << self.getInputFileNames()
if outputFn:
arguments.append("-of")
arguments.append(self.outputFormat)
arguments.append("-o")
arguments.append(outputFn)
arguments.extend(self.getInputFileNames())
return arguments

def getOutputFileName(self):
@@ -168,12 +170,12 @@ def getOutputFileName(self):
def getInputFileName(self):
if self.inputDirCheck.isChecked():
return self.inSelector.filename()
return self.inSelector.filename().split(",", QString.SkipEmptyParts)
return self.inSelector.filename().split(",")

def getInputFileNames(self):
if self.inputDirCheck.isChecked():
return Utils.getRasterFiles( self.inSelector.filename(), self.recurseCheck.isChecked() )
return self.inSelector.filename().split(",", QString.SkipEmptyParts)
return self.inSelector.filename().split(",")

def addLayerIntoCanvas(self, fileInfo):
self.iface.addRasterLayer(fileInfo.filePath())
@@ -62,14 +62,14 @@ def __init__( self, iface ):

def fillInputDirEdit( self ):
inputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the input directory with raster files" ))
if inputDir.isEmpty():
if not inputDir:
return
self.inSelector.setFilename( inputDir )

def fillOutputFileEdit( self ):
lastUsedFilter = Utils.FileFilter.lastUsedVectorFilter()
outputFile, encoding = Utils.FileDialog.getSaveFileName( self, self.tr( "Select where to save the TileIndex output" ), Utils.FileFilter.allVectorsFilter(), lastUsedFilter, True )
if outputFile.isEmpty():
if not outputFile:
return
Utils.FileFilter.setLastUsedVectorFilter(lastUsedFilter)

@@ -78,16 +78,16 @@ def fillOutputFileEdit( self ):
self.lastEncoding = encoding

def getArguments( self ):
arguments = QStringList()
if self.indexFieldCheck.isChecked() and not self.indexFieldEdit.text().isEmpty():
arguments << "-tileindex"
arguments << self.indexFieldEdit.text()
arguments = []
if self.indexFieldCheck.isChecked() and self.indexFieldEdit.text():
arguments.append("-tileindex")
arguments.append(self.indexFieldEdit.text())
if self.absolutePathCheck.isChecked():
arguments << "-write_absolute_path"
arguments.append("-write_absolute_path")
if self.skipDifferentProjCheck.isChecked():
arguments << "-skip_different_projection"
arguments << self.getOutputFileName()
arguments << Utils.getRasterFiles( self.getInputFileName(), self.recurseCheck.isChecked() )
arguments.append("-skip_different_projection")
arguments.append(self.getOutputFileName())
arguments.extend(Utils.getRasterFiles( self.getInputFileName(), self.recurseCheck.isChecked() ))
return arguments

def getOutputFileName( self ):
@@ -135,15 +135,15 @@ def setFilename(self, fn=None):
elif isinstance(fn, str) or isinstance(fn, unicode):
fn = unicode( fn )

#TODO fix and test
#elif hasattr(fn, '__iter__') or isinstance(fn, QStringList):
# if len( fn ) > 0:
# fn = QStringList() << fn
# if self.getType() & self.MULTIFILE:
# self.filenames = fn
# fn = fn.join( "," )
# else:
# fn = ''
#TODO test
elif isinstance(fn, list):
if len( fn ) > 0:
if self.getType() & self.MULTIFILE:
self.filenames = fn
#fn = "".join( fn, "," )
fn = ",".join( fn )
else:
fn = ''

else:
fn = ''
@@ -106,7 +106,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="creationGroupBox">
<widget class="QGroupBox" name="creationOptionsGroupBox">
<property name="title">
<string>&amp;Creation Options</string>
</property>
@@ -121,7 +121,7 @@
<number>0</number>
</property>
<item>
<widget class="QgsRasterFormatSaveOptionsWidget" name="creationOptionsTable" native="true"/>
<widget class="QgsRasterFormatSaveOptionsWidget" name="creationOptionsWidget" native="true"/>
</item>
</layout>
</widget>

0 comments on commit 84d7766

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