Navigation Menu

Skip to content

Commit

Permalink
added -cutline option to gdaltools warp tool, to fix #3066
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15476 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler committed Mar 14, 2011
1 parent fa9f666 commit 36fc12a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 13 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.22"
return "Version 1.2.23"
def qgisMinimumVersion():
return "1.0"
def icon():
Expand Down
39 changes: 36 additions & 3 deletions python/plugins/GdalTools/tools/doWarp.py
Expand Up @@ -40,7 +40,9 @@ def __init__(self, iface):
(self.cacheSpin, SIGNAL("valueChanged(int)"), self.cacheCheck),
( [self.widthSpin, self.heightSpin], SIGNAL( "valueChanged(int)" ), self.resizeGroupBox ),
(self.multithreadCheck, SIGNAL("stateChanged(int)")),
(self.noDataEdit, SIGNAL( "textChanged( const QString & )" ), self.noDataCheck)
(self.noDataEdit, SIGNAL( "textChanged( const QString & )" ), self.noDataCheck),
(self.cutlineLayerCombo, [SIGNAL("currentIndexChanged(int)"), SIGNAL("editTextChanged(const QString &)")], self.cutlineCheck, "1.6.0"),
(self.selectCutlineFileButton, None, self.cutlineCheck, "1.6.0")
]
)

Expand All @@ -49,6 +51,7 @@ def __init__(self, iface):
self.connect(self.selectOutputFileButton, SIGNAL("clicked()"), self.fillOutputFileEdit)
self.connect(self.selectSourceSRSButton, SIGNAL("clicked()"), self.fillSourceSRSEdit)
self.connect(self.selectTargetSRSButton, SIGNAL("clicked()"), self.fillTargetSRSEdit)
self.connect(self.selectCutlineFileButton, SIGNAL("clicked()"), self.fillCutlineFile)
self.connect( self.batchCheck, SIGNAL( "stateChanged( int )" ), self.switchToolMode )


Expand Down Expand Up @@ -90,12 +93,19 @@ def switchToolMode( self ):

def onLayersChanged(self):
self.fillInputLayerCombo()
self.fillCutlineLayerCombo()

def fillInputLayerCombo(self):
self.inputLayerCombo.clear()
( self.layers, names ) = Utils.LayerRegistry.instance().getRasterLayers()
( self.inputLayers, names ) = Utils.LayerRegistry.instance().getRasterLayers()
self.inputLayerCombo.addItems( names )

def fillCutlineLayerCombo(self):
self.cutlineLayerCombo.clear()
( self.cutlineLayers, names ) = Utils.LayerRegistry.instance().getVectorLayers()
self.cutlineLayerCombo.addItems( names )


def fillInputFile(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
inputFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the input file for Warp" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
Expand All @@ -119,6 +129,17 @@ def fillOutputFileEdit(self):
self.outputFormat = Utils.fillRasterOutputFormat( lastUsedFilter, outputFile )
self.outputFileEdit.setText(outputFile)

def fillCutlineFile(self):
lastUsedFilter = Utils.FileFilter.lastUsedVectorFilter()
cutlineFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the cutline file" ), Utils.FileFilter.allVectorsFilter(), lastUsedFilter )
if cutlineFile.isEmpty():
return
Utils.FileFilter.setLastUsedVectorFilter(lastUsedFilter)

self.cutlineLayerCombo.setCurrentIndex(-1)
self.cutlineLayerCombo.setEditText(cutlineFile)


def fillInputDir( self ):
inputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the input directory with files to Warp" ))
if inputDir.isEmpty():
Expand Down Expand Up @@ -187,6 +208,13 @@ def getArguments(self):
if not nodata.isEmpty():
arguments << "-dstnodata"
arguments << nodata
if self.cutlineCheck.isChecked():
cutline = self.getCutlineFileName()
if not cutline.isEmpty():
arguments << "-q"
arguments << "-cutline"
arguments << cutline
arguments << "-dstalpha"
if self.isBatchEnabled():
return arguments

Expand All @@ -199,12 +227,17 @@ def getArguments(self):

def getInputFileName(self):
if self.inputLayerCombo.currentIndex() >= 0:
return self.layers[self.inputLayerCombo.currentIndex()].source()
return self.inputLayers[self.inputLayerCombo.currentIndex()].source()
return self.inputLayerCombo.currentText()

def getOutputFileName(self):
return self.outputFileEdit.text()

def getCutlineFileName(self):
if self.cutlineLayerCombo.currentIndex() >= 0:
return self.cutlineLayers[self.cutlineLayerCombo.currentIndex()].source()
return self.cutlineLayerCombo.currentText()

def addLayerIntoCanvas(self, fileInfo):
self.iface.addRasterLayer(fileInfo.filePath())

Expand Down
52 changes: 43 additions & 9 deletions python/plugins/GdalTools/tools/widgetWarp.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>415</width>
<height>417</height>
<height>453</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -19,15 +19,15 @@
<property name="windowTitle">
<string>Warp</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="batchCheck">
<property name="text">
<string>Batch mode (for processing whole directory)</string>
</property>
</widget>
</item>
<item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
Expand Down Expand Up @@ -203,14 +203,14 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QCheckBox" name="cacheCheck">
<property name="text">
<string>&amp;Memory used for caching</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QSpinBox" name="cacheSpin">
<property name="suffix">
<string>MB</string>
Expand All @@ -223,9 +223,43 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="cutlineCheck">
<property name="text">
<string>Cutline</string>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QComboBox" name="cutlineLayerCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectCutlineFileButton">
<property name="text">
<string>Select...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<item row="2" column="0">
<widget class="QGroupBox" name="resizeGroupBox">
<property name="title">
<string>Resize</string>
Expand Down Expand Up @@ -283,10 +317,10 @@
</layout>
</widget>
</item>
<item>
<item row="3" column="0">
<widget class="QProgressBar" name="progressBar"/>
</item>
<item>
<item row="4" column="0">
<widget class="QCheckBox" name="multithreadCheck">
<property name="text">
<string>Use m&amp;ultithreaded warping implementation</string>
Expand Down

0 comments on commit 36fc12a

Please sign in to comment.