Skip to content

Commit

Permalink
added raster creation in rasterize tool, to fix #3545
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15469 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler committed Mar 13, 2011
1 parent 99d48bd commit b95d84c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
25 changes: 23 additions & 2 deletions python/plugins/GdalTools/tools/doRasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ def __init__(self, iface):
self.setupUi(self)
BasePluginWidget.__init__(self, self.iface, "gdal_rasterize")

# set the default QSpinBoxes and QProgressBar value
self.widthSpin.setValue(3000)
self.heightSpin.setValue(3000)

self.lastEncoding = Utils.getLastUsedEncoding()

self.setParamsStatus(
[
(self.inputLayerCombo, [SIGNAL("currentIndexChanged(int)"), SIGNAL("editTextChanged(const QString &)")] ),
(self.outputFileEdit, SIGNAL("textChanged(const QString &)")),
(self.attributeComboBox, SIGNAL("currentIndexChanged(int)"))
(self.attributeComboBox, SIGNAL("currentIndexChanged(int)")),
( [self.widthSpin, self.heightSpin], SIGNAL( "valueChanged(int)" ), self.resizeGroupBox, "1.8.0" ),
]
)

Expand Down Expand Up @@ -63,18 +68,34 @@ def fillInputFileEdit(self):

def fillOutputFileEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
outputFile = Utils.FileDialog.getOpenFileName(self, self.tr( "Select the raster file to save the results to" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter)

# rasterize supports output file creation for GDAL 1.8
gdalVersion = Utils.GdalConfig.version()
fileDialogFunc = Utils.FileDialog.getSaveFileName
if gdalVersion < "1.8.0":
fileDialogFunc = Utils.FileDialog.getOpenFileName
outputFile = fileDialogFunc(self, self.tr( "Select the raster file to save the results to" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter)
if outputFile.isEmpty():
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)

self.outputFileEdit.setText(outputFile)

# 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)

def getArguments(self):
arguments = QStringList()
if self.attributeComboBox.currentIndex() >= 0:
arguments << "-a"
arguments << self.attributeComboBox.currentText()
if self.resizeGroupBox.isChecked():
arguments << "-ts"
arguments << str( self.widthSpin.value() )
arguments << str( self.heightSpin.value() )
if self.inputLayerCombo.currentIndex() >= 0:
arguments << "-l"
arguments << QFileInfo(self.layers[ self.inputLayerCombo.currentIndex() ].source()).baseName()
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/GdalTools/tools/doTileIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__( self, iface ):
#( self.recurseCheck, SIGNAL( "stateChanged( int )" ),
( self.outputFileEdit, SIGNAL( "textChanged( const QString & )" ) ),
( self.indexFieldEdit, SIGNAL( "textChanged( const QString & )" ), self.indexFieldCheck),
( self.absolutePathCheck, SIGNAL( "stateChanged( int )" ) ),
( self.skipDifferentProjCheck, SIGNAL( "stateChanged( int )" ) )
( self.absolutePathCheck, SIGNAL( "stateChanged( int )" ), None, "1.5.0" ),
( self.skipDifferentProjCheck, SIGNAL( "stateChanged( int )" ), None, "1.5.0" )
]
)

Expand Down
6 changes: 3 additions & 3 deletions python/plugins/GdalTools/tools/doTranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ def getArguments(self):
arguments << "-co"
arguments << opt
if self.outsizeCheck.isChecked() and self.outsizeSpin.value() != 100:
arguments << "-outsize"
arguments << self.outsizeSpin.text()
arguments << self.outsizeSpin.text()
arguments << "-outsize"
arguments << self.outsizeSpin.text()
arguments << self.outsizeSpin.text()
if self.expandCheck.isChecked():
arguments << "-expand"
arguments << self.expand_method[self.expandCombo.currentIndex()]
Expand Down
54 changes: 50 additions & 4 deletions python/plugins/GdalTools/tools/widgetRasterize.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>570</width>
<height>119</height>
<width>509</width>
<height>214</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -21,7 +21,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
Expand Down Expand Up @@ -82,7 +82,7 @@
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Output file for rasterized vectors (raster, must exists)</string>
<string>&amp;Output file for rasterized vectors (raster)</string>
</property>
<property name="buddy">
<cstring>selectOutputFileButton</cstring>
Expand Down Expand Up @@ -112,6 +112,52 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="resizeGroupBox">
<property name="title">
<string>New size (required if output file doens't exist)</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Image width</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="widthSpin">
<property name="maximum">
<number>999999</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Image height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="heightSpin">
<property name="maximum">
<number>999999</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit b95d84c

Please sign in to comment.