Skip to content
Permalink
Browse files

fix GdalTools warp

  • Loading branch information
etiennesky committed Jun 14, 2013
1 parent 84d7766 commit 5e98be126685f4ea883fbb5918273edffe2143dd
@@ -299,16 +299,15 @@ def getRasterSRS( parent, fileName ):
return ''

info = string.split( arr, sep="\n" )
# TODO .filter( "AUTHORITY" )
if info.count() == 0:
if len(info) == 0:
return ''

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

return ''

def getRasterExtent(parent, fileName):
processSRS = QProcess( parent )
@@ -51,10 +51,10 @@ def proj4string(self):
return self.selector.selectedProj4String()

def getProjection(self):
if self.authid().startswith("EPSG:", Qt.CaseInsensitive):
if self.authid().upper().startswith("EPSG:"):
return self.authid()

if not self.selector.selectedProj4String().isEmpty():
if self.selector.selectedProj4String():
return self.proj4string()

return ''
@@ -116,7 +116,7 @@ def onLayersChanged(self):
def fillInputFile(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
inputFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the input file for Warp" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
if inputFile.isEmpty():
if not inputFile:
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)
self.inSelector.setFilename(inputFile)
@@ -127,7 +127,7 @@ def fillInputFile(self):
def fillOutputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
outputFile = Utils.FileDialog.getSaveFileName(self, self.tr( "Select the raster file to save the results to" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
if outputFile.isEmpty():
if not outputFile:
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

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


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

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

def fillOutputDir( self ):
outputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the output directory to save the results to" ))
if outputDir.isEmpty():
if not outputDir:
return
self.outSelector.setFilename( outputDir )

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

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

def getArguments(self):
arguments = QStringList()
if self.sourceSRSCheck.isChecked() and not self.sourceSRSEdit.text().isEmpty():
arguments << "-s_srs"
arguments << self.sourceSRSEdit.text()
if self.targetSRSCheck.isChecked() and not self.targetSRSEdit.text().isEmpty():
arguments << "-t_srs"
arguments << self.targetSRSEdit.text()
arguments = []
if self.sourceSRSCheck.isChecked() and self.sourceSRSEdit.text():
arguments.append("-s_srs")
arguments.append(self.sourceSRSEdit.text())
if self.targetSRSCheck.isChecked() and self.targetSRSEdit.text():
arguments.append("-t_srs")
arguments.append(self.targetSRSEdit.text())
if self.resamplingCheck.isChecked() and self.resamplingCombo.currentIndex() >= 0:
arguments << "-r"
arguments << self.resampling_method[self.resamplingCombo.currentIndex()]
arguments.append("-r")
arguments.append(self.resampling_method[self.resamplingCombo.currentIndex()])
if self.cacheCheck.isChecked():
arguments << "-wm"
arguments << str(self.cacheSpin.value())
arguments.append("-wm")
arguments.append(str(self.cacheSpin.value()))
if self.resizeGroupBox.isChecked():
arguments << "-ts"
arguments << str( self.widthSpin.value() )
arguments << str( self.heightSpin.value() )
arguments.append("-ts")
arguments.append(str( self.widthSpin.value() ))
arguments.append(str( self.heightSpin.value() ))
if self.multithreadCheck.isChecked():
arguments << "-multi"
arguments.append("-multi")
if self.noDataCheck.isChecked():
nodata = self.noDataEdit.text().trimmed()
if not nodata.isEmpty():
arguments << "-dstnodata"
arguments << nodata
nodata = self.noDataEdit.text().strip()
if nodata:
arguments.append("-dstnodata")
arguments.append(nodata)
if self.maskCheck.isChecked():
mask = self.getMaskFileName()
if not mask.isEmpty():
arguments << "-q"
arguments << "-cutline"
arguments << mask
arguments << "-dstalpha"
if mask:
arguments.append("-q")
arguments.append("-cutline")
arguments.append(mask)
arguments.append("-dstalpha")
if self.isBatchEnabled():
return arguments

outputFn = self.getOutputFileName()
if not outputFn.isEmpty():
arguments << "-of"
arguments << self.outputFormat
arguments << self.getInputFileName()
arguments << outputFn
if outputFn:
arguments.append("-of")
arguments.append(self.outputFormat)
arguments.append(self.getInputFileName())
arguments.append(outputFn)
return arguments

def getInputFileName(self):

0 comments on commit 5e98be1

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