Skip to content

Commit

Permalink
Added UI elements for specifying resolution in Rasterize
Browse files Browse the repository at this point in the history
  • Loading branch information
Tentotwo committed Mar 18, 2013
1 parent 5743f52 commit 796762a
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 19 deletions.
21 changes: 15 additions & 6 deletions python/plugins/GdalTools/tools/doRasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def __init__(self, iface):
# set the default QSpinBoxes and QProgressBar value
self.widthSpin.setValue(3000)
self.heightSpin.setValue(3000)
self.horizresSpin.setValue(1)
self.vertresSpin.setValue(1)

self.lastEncoding = Utils.getLastUsedEncoding()

Expand All @@ -55,13 +57,16 @@ def __init__(self, iface):
(self.inSelector, SIGNAL("filenameChanged()")),
(self.outSelector, SIGNAL("filenameChanged()")),
(self.attributeComboBox, SIGNAL("currentIndexChanged(int)")),
( [self.widthSpin, self.heightSpin], SIGNAL( "valueChanged(int)" ), self.resizeGroupBox, "1.8.0" ),
( [self.widthSpin, self.heightSpin], SIGNAL( "valueChanged(int)" )),
( [self.horizresSpin, self.vertresSpin], SIGNAL( "valueChanged(double)" ))
]
)

self.connect(self.inSelector, SIGNAL("selectClicked()"), self.fillInputFileEdit)
self.connect(self.outSelector, SIGNAL("selectClicked()"), self.fillOutputFileEdit)
self.connect(self.inSelector, SIGNAL("layerChanged()"), self.fillFieldsCombo)
self.connect(self.radioSetSize, SIGNAL("toggled(bool)"), self.someValueChanged)
self.connect(self.radioSetResolution, SIGNAL("toggled(bool)"), self.someValueChanged)

def onLayersChanged(self):
self.inSelector.setLayers( Utils.LayerRegistry.instance().getVectorLayers() )
Expand Down Expand Up @@ -101,24 +106,28 @@ def fillOutputFileEdit(self):

self.outSelector.setFilename(outputFile)

# required either -ts or -tr to create the output file
# required either -ts or -tr to create the output file
if gdalVersion >= "1.8.0":
if not QFileInfo(outputFile).exists():
QMessageBox.information( self, self.tr( "Output size required" ), self.tr( "The output file doesn't exist. You must set up the output size to create it." ) )
self.resizeGroupBox.setChecked(True)
QMessageBox.information( self, self.tr( "Output size or resolution required" ), self.tr( "The output file doesn't exist. You must set up the output size or resolution to create it." ) )
self.radioSetSize.setChecked(True)

def getArguments(self):
arguments = QStringList()
if self.attributeComboBox.currentIndex() >= 0:
arguments << "-a"
arguments << self.attributeComboBox.currentText()
if self.resizeGroupBox.isChecked():
if self.radioSetSize.isChecked():
arguments << "-ts"
arguments << str( self.widthSpin.value() )
arguments << str( self.heightSpin.value() )
if self.radioSetResolution.isChecked():
arguments << "-tr"
arguments << str( self.horizresSpin.value() )
arguments << str( self.vertresSpin.value() )
inputFn = self.getInputFileName()
if not inputFn.isEmpty():
arguments << "-l"
arguments << "-l"
arguments << QFileInfo( inputFn ).baseName()
arguments << inputFn
arguments << self.getOutputFileName()
Expand Down
181 changes: 168 additions & 13 deletions python/plugins/GdalTools/tools/widgetRasterize.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>509</width>
<height>165</height>
<height>532</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -71,19 +71,42 @@
</layout>
</item>
<item>
<widget class="QGroupBox" name="resizeGroupBox">
<property name="title">
<string>New size (required if output file doens't exist)</string>
<widget class="QRadioButton" name="radioKeepSize">
<property name="text">
<string>Keep existing raster size and resolution</string>
</property>
<property name="checkable">
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioSetSize">
<property name="text">
<string>Raster size in pixels</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QLabel" name="label_11">
</widget>
</item>
<item>
<widget class="QWidget" name="widgetSize" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>30</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelWidth">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
Expand All @@ -95,15 +118,15 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item>
<widget class="QSpinBox" name="widthSpin">
<property name="maximum">
<number>999999</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_12">
<item>
<widget class="QLabel" name="labelHeight">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
Expand All @@ -118,7 +141,7 @@
</property>
</widget>
</item>
<item row="0" column="3">
<item>
<widget class="QSpinBox" name="heightSpin">
<property name="maximum">
<number>999999</number>
Expand All @@ -128,6 +151,105 @@
</layout>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioSetResolution">
<property name="text">
<string>Raster resolution in map units per pixel</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widgetResolution" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>30</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="labelHorizontal">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Horizontal</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="horizresSpin">
<property name="decimals">
<number>8</number>
</property>
<property name="maximum">
<double>999999999.990000009536743</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelVertical">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Vertical</string>
</property>
<property name="indent">
<number>40</number>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="vertresSpin">
<property name="inputMethodHints">
<set>Qt::ImhNone</set>
</property>
<property name="decimals">
<number>8</number>
</property>
<property name="maximum">
<double>999999999.990000009536743</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
Expand All @@ -139,5 +261,38 @@
</customwidget>
</customwidgets>
<resources/>
<connections/>
<connections>
<connection>
<sender>radioSetSize</sender>
<signal>toggled(bool)</signal>
<receiver>widgetSize</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>254</x>
<y>128</y>
</hint>
<hint type="destinationlabel">
<x>254</x>
<y>163</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioSetResolution</sender>
<signal>toggled(bool)</signal>
<receiver>widgetResolution</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>254</x>
<y>198</y>
</hint>
<hint type="destinationlabel">
<x>254</x>
<y>233</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 796762a

Please sign in to comment.