Skip to content
Permalink
Browse files

add mask option to gdal_polygonize

  • Loading branch information
alexbruy committed May 10, 2011
1 parent 0ef7c7a commit 9647ac877f9ca86e70b0f0d43ab75afcfb887df4
Showing with 71 additions and 46 deletions.
  1. +19 −0 python/plugins/GdalTools/tools/doPolygonize.py
  2. +52 −46 python/plugins/GdalTools/tools/widgetPolygonize.ui
@@ -25,15 +25,18 @@ def __init__(self, iface):
[
(self.inSelector, SIGNAL("filenameChanged()")),
(self.outSelector, SIGNAL("filenameChanged()")),
(self.maskSelector, SIGNAL("filenameChanged()"), self.maskCheck),
(self.fieldEdit, SIGNAL("textChanged(const QString &)"), self.fieldCheck)
]
)

self.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFileEdit)
self.connect(self.outSelector, SIGNAL("selectClicked()"), self.fillOutputFileEdit)
self.connect(self.maskSelector, SIGNAL("selectClicked()"), self.fillMaskFileEdit)

def onLayersChanged(self):
self.inSelector.setLayers( Utils.LayerRegistry.instance().getRasterLayers() )
self.maskSelector.setLayers( Utils.LayerRegistry.instance().getRasterLayers() )

def fillInputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
@@ -55,10 +58,23 @@ def fillOutputFileEdit(self):
self.outSelector.setFilename(outputFile)
self.lastEncoding = encoding

def fillMaskFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
maskFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the input file for Polygonize" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter )
if maskFile.isEmpty():
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

self.maskSelector.setFilename(maskFile)

def getArguments(self):
arguments = QStringList()
arguments << self.getInputFileName()
outputFn = self.getOutputFileName()
maskFn = self.getMaskFileName()
if self.maskCheck.isChecked() and not maskFn.isEmpty():
arguments << "-mask"
arguments << maskFn
if not outputFn.isEmpty():
arguments << "-f"
arguments << self.outputFormat
@@ -74,6 +90,9 @@ def getOutputFileName(self):

def getInputFileName(self):
return self.inSelector.filename()

def getMaskFileName(self):
return self.maskSelector.filename()

def addLayerIntoCanvas(self, fileInfo):
vl = self.iface.addVectorLayer(fileInfo.filePath(), fileInfo.baseName(), "ogr")
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>449</width>
<height>94</height>
<width>446</width>
<height>121</height>
</rect>
</property>
<property name="sizePolicy">
@@ -19,50 +19,56 @@
<property name="windowTitle">
<string>Polygonize (Raster to vector)</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Input file (raster)</string>
</property>
<property name="buddy">
<cstring>inSelector</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Output file for polygons (shapefile)</string>
</property>
<property name="buddy">
<cstring>outSelector</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="fieldCheck">
<property name="text">
<string>&amp;Field name</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="fieldEdit">
<property name="text">
<string>DN</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="GdalToolsInOutSelector" name="inSelector" native="true"/>
</item>
<item row="1" column="1">
<widget class="GdalToolsInOutSelector" name="outSelector" native="true"/>
</item>
</layout>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Input file (raster)</string>
</property>
<property name="buddy">
<cstring>inSelector</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="GdalToolsInOutSelector" name="inSelector" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Output file for polygons (shapefile)</string>
</property>
<property name="buddy">
<cstring>outSelector</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="GdalToolsInOutSelector" name="outSelector" native="true"/>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="fieldCheck">
<property name="text">
<string>&amp;Field name</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="fieldEdit">
<property name="text">
<string>DN</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="maskCheck">
<property name="text">
<string>Use mask</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="GdalToolsInOutSelector" name="maskSelector" native="true"/>
</item>
</layout>
</widget>

0 comments on commit 9647ac8

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