Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
applied the patch suggested in ticket #3151,
fix in translate to use the GdalTools_utils to get the crs, 
managed invalid extent in merge tool


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14450 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler committed Oct 29, 2010
1 parent c55855d commit 8fc06d7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 33 deletions.
2 changes: 1 addition & 1 deletion python/plugins/GdalTools/__init__.py
Expand Up @@ -22,7 +22,7 @@ def name():
def description():
return "Integrate gdal tools into qgis"
def version():
return "Version 1.2.10"
return "Version 1.2.15"
def qgisMinimumVersion():
return "1.0"
def classFactory(iface):
Expand Down
57 changes: 35 additions & 22 deletions python/plugins/GdalTools/tools/doMerge.py
Expand Up @@ -18,6 +18,7 @@ def __init__(self, iface):
BasePluginWidget.__init__(self, self.iface, "gdal_merge.py")

self.outputFormat = Utils.fillRasterOutputFormat()
self.extent = None

self.setParamsStatus(
[
Expand All @@ -33,6 +34,7 @@ def __init__(self, iface):

self.connect(self.selectInputFilesButton, SIGNAL("clicked()"), self.fillInputFilesEdit)
self.connect(self.selectOutputFileButton, SIGNAL("clicked()"), self.fillOutputFileEdit)
self.connect(self.intersectCheck, SIGNAL("stateChanged(int)"), self.refreshExtent)

def fillInputFilesEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
Expand All @@ -42,13 +44,27 @@ def fillInputFilesEdit(self):
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

self.inputFilesEdit.setText(files.join(","))
self.intersectCheck.setEnabled( files.count() > 1 )
self.refreshExtent()

def refreshExtent(self):
files = self.inputFilesEdit.text().split( "," )
if files.count() < 2:
self.intersectCheck.setChecked( False )
self.intersectCheck.setEnabled( False )
else:
self.intersectCheck.setEnabled( True )
(self.xmax, self.ymax, self.xmin, self.ymin) = self.getExtent()
self.extent = None
return

self.extent = self.getExtent()
self.someValueChanged()

if not self.intersectCheck.isChecked():
return

if self.extent == None:
QMessageBox.warning( self, self.tr( "Error retrieving the extent" ), self.tr( 'GDAL was unable to retrieve the extent from any file. \nThe "Use intersected extent" option will be unchecked.' ) )
self.intersectCheck.setChecked( False )
elif self.extent.isEmpty():
QMessageBox.warning( self, self.tr( "Empty extent" ), self.tr( 'The computed extent is empty. \nDisable the "Use intersected extent" option to have a nonempty output.' ) )

def fillOutputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
Expand All @@ -63,8 +79,12 @@ def fillOutputFileEdit(self):
def getArguments(self):
arguments = QStringList()
if self.intersectCheck.isChecked():
arguments << "-ul_lr"
arguments << str( self.xmin ) << str( self.ymax ) << str( self.xmax ) << str( self.ymin )
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() )
if self.noDataCheck.isChecked():
arguments << "-n"
arguments << str(self.noDataSpin.value())
Expand Down Expand Up @@ -117,21 +137,14 @@ def getExtent( self ):
files = self.inputFilesEdit.text().split( "," )

i = 0
while i < files.count():
if i == 0:
rect1 = self.getRectangle( files[ 0 ] )
rect2 = self.getRectangle( files[ 1 ] )
res = rect1.intersect( rect2 )
rect1 = res
i = 2
res = rect2 = None
for fileName in files:
if res == None:
res = self.getRectangle( fileName )
continue
rect2 = self.getRectangle( files[ i ] )
res = rect1.intersect( rect2 )
i = i + 1

xMax = res.xMaximum()
xMin = res.xMinimum()
yMax = res.yMaximum()
yMin = res.yMinimum()
rect2 = self.getRectangle( fileName )
if rect2 == None:
continue
res = res.intersect( rect2 )

return ( xMax, yMax, xMin, yMin )
return res
15 changes: 9 additions & 6 deletions python/plugins/GdalTools/tools/doTranslate.py
Expand Up @@ -114,12 +114,12 @@ def fillInputFile( self ):
return
Utils.FileFilter.setLastUsedRasterFilter( lastUsedFilter )

# get SRS for target file if necessary and possible
self.targetSRSEdit.setText( Utils.getRasterSRS( self, inputFile ) )

self.inputLayerCombo.setCurrentIndex(-1)
self.inputLayerCombo.setEditText( inputFile )

# get SRS for target file if necessary and possible
self.refreshTargetSRS()

def fillInputDir( self ):
inputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the input directory with files to Translate" ))
if inputDir.isEmpty():
Expand Down Expand Up @@ -154,9 +154,12 @@ def fillOutputDir( self ):
self.outputFileEdit.setText( outputDir )

def fillTargetSRSEditDefault(self, index):
if index >= 0 and index in self.layers:
layer = self.layers[index]
self.targetSRSEdit.setText("EPSG:" + str(layer.srs().epsg()))
if index < 0:
return
self.refreshTargetSRS()

def refreshTargetSRS(self):
self.targetSRSEdit.setText( Utils.getRasterSRS( self, self.getInputFileName() ) )

def fillTargetSRSEdit(self):
dialog = SRSDialog( "Select the target SRS" )
Expand Down
19 changes: 15 additions & 4 deletions python/plugins/GdalTools/tools/doWarp.py
Expand Up @@ -44,6 +44,7 @@ def __init__(self, iface):
]
)

self.connect(self.inputLayerCombo, SIGNAL("currentIndexChanged(int)"), self.fillSourceSRSEditDefault)
self.connect(self.selectInputFileButton, SIGNAL("clicked()"), self.fillInputFile)
self.connect(self.selectOutputFileButton, SIGNAL("clicked()"), self.fillOutputFileEdit)
self.connect(self.selectSourceSRSButton, SIGNAL("clicked()"), self.fillSourceSRSEdit)
Expand Down Expand Up @@ -100,12 +101,12 @@ def fillInputFile(self):
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

# get SRS for source file if necessary and possible
self.sourceSRSEdit.setText( Utils.getRasterSRS( self, inputFile ) )

self.inputLayerCombo.setCurrentIndex(-1)
self.inputLayerCombo.setEditText(inputFile)

# get SRS for source file if necessary and possible
self.refreshSourceSRS()

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 )
Expand Down Expand Up @@ -144,6 +145,16 @@ def fillSourceSRSEdit(self):
if dialog.exec_():
self.sourceSRSEdit.setText(dialog.getProjection())

def fillSourceSRSEditDefault(self, index):
if index < 0:
return
self.refreshSourceSRS()

def refreshSourceSRS(self):
crs = Utils.getRasterSRS( self, self.getInputFileName() )
self.sourceSRSEdit.setText( crs )
self.sourceSRSCheck.setChecked( not crs.isEmpty() )

def fillTargetSRSEdit(self):
dialog = SRSDialog( "Select the target SRS" )
if dialog.exec_():
Expand All @@ -164,7 +175,7 @@ def getArguments(self):
arguments << "-wm"
arguments << str(self.cacheSpin.value())
if self.resizeGroupBox.isChecked():
arguments << "-ts"
arguments << "-ts"
arguments << str( self.widthSpin.value() )
arguments << str( self.heightSpin.value() )
if self.multithreadCheck.isChecked():
Expand Down

0 comments on commit 8fc06d7

Please sign in to comment.