Skip to content
Permalink
Browse files

Option to choose output extent for save as raster

  • Loading branch information
mhugent committed Jul 11, 2012
1 parent 55ec17a commit eec208cab5abdda29dcd4890795580775a8a707b
@@ -3771,7 +3771,7 @@ void QgisApp::saveAsRasterFile()
return;
}

QgsRasterLayerSaveAsDialog d( rasterLayer->dataProvider() );
QgsRasterLayerSaveAsDialog d( rasterLayer->dataProvider(), mMapCanvas->extent() );
if ( d.exec() == QDialog::Accepted )
{
QgsRasterFileWriter fileWriter( d.outputFileName() );
@@ -3781,7 +3781,10 @@ void QgisApp::saveAsRasterFile()
//fileWriter.setMaxTileWidth( d.maximumTileSizeX() );
//fileWriter.setMaxTileHeight( d.maximumTileSizeY() );
}
fileWriter.writeRaster( rasterLayer->dataProvider(), d.nColumns() );

QProgressDialog pd( 0, tr( "Abort..." ), 0, 0 );
pd.setWindowModality( Qt::WindowModal );
fileWriter.writeRaster( rasterLayer->dataProvider(), d.nColumns(), d.outputRectangle(), &pd );
}
}

@@ -260,7 +260,6 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeARGBRaster( QgsRaster
{
break;
}

}

//fill into red/green/blue/alpha channels
@@ -2,9 +2,9 @@
#include "qgsrasterdataprovider.h"
#include <QFileDialog>

QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider,
QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent,
QWidget* parent, Qt::WindowFlags f ): QDialog( parent, f ),
mDataProvider( sourceProvider )
mDataProvider( sourceProvider ), mCurrentExtent( currentExtent )

{
setupUi( this );
@@ -30,6 +30,9 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
mMaximumSizeXLineEdit->setText( QString::number( 2000 ) );
mMaximumSizeYLineEdit->setText( QString::number( 2000 ) );
}

//extent
setOutputExtent( mCurrentExtent );
}

QPushButton* okButton = mButtonBox->button( QDialogButtonBox::Ok );
@@ -45,6 +48,10 @@ void QgsRasterLayerSaveAsDialog::setValidators()
mRowsLineEdit->setValidator( new QIntValidator( this ) );
mMaximumSizeXLineEdit->setValidator( new QIntValidator( this ) );
mMaximumSizeYLineEdit->setValidator( new QIntValidator( this ) );
mXMinLineEdit->setValidator( new QDoubleValidator( this ) );
mXMaxLineEdit->setValidator( new QDoubleValidator( this ) );
mYMinLineEdit->setValidator( new QDoubleValidator( this ) );
mYMaxLineEdit->setValidator( new QDoubleValidator( this ) );
}

QgsRasterLayerSaveAsDialog::~QgsRasterLayerSaveAsDialog()
@@ -80,6 +87,19 @@ void QgsRasterLayerSaveAsDialog::on_mSaveAsLineEdit_textChanged( const QString&
okButton->setEnabled( QFileInfo( text ).absoluteDir().exists() );
}

void QgsRasterLayerSaveAsDialog::on_mCurrentExtentButton_clicked()
{
setOutputExtent( mCurrentExtent );
}

void QgsRasterLayerSaveAsDialog::on_mProviderExtentButton_clicked()
{
if ( mDataProvider )
{
setOutputExtent( mDataProvider->extent() );
}
}

int QgsRasterLayerSaveAsDialog::nColumns() const
{
return mColumnsLineEdit->text().toInt();
@@ -114,3 +134,16 @@ QString QgsRasterLayerSaveAsDialog::outputFormat() const
{
return ""; //soon...
}

QgsRectangle QgsRasterLayerSaveAsDialog::outputRectangle() const
{
return QgsRectangle( mXMinLineEdit->text().toDouble(), mYMinLineEdit->text().toDouble(), mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
}

void QgsRasterLayerSaveAsDialog::setOutputExtent( const QgsRectangle& r )
{
mXMinLineEdit->setText( QString::number( r.xMinimum() ) );
mXMaxLineEdit->setText( QString::number( r.xMaximum() ) );
mYMinLineEdit->setText( QString::number( r.yMinimum() ) );
mYMaxLineEdit->setText( QString::number( r.yMaximum() ) );
}
@@ -2,14 +2,15 @@
#define QGSRASTERLAYERSAVEASDIALOG_H

#include "ui_qgsrasterlayersaveasdialogbase.h"
#include "qgsrectangle.h"

class QgsRasterDataProvider;

class QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRasterLayerSaveAsDialogBase
{
Q_OBJECT
public:
QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, QWidget* parent = 0, Qt::WindowFlags f = 0 );
QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent, QWidget* parent = 0, Qt::WindowFlags f = 0 );
~QgsRasterLayerSaveAsDialog();

int nColumns() const;
@@ -19,15 +20,20 @@ class QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRasterLayerSave
bool tileMode() const;
QString outputFileName() const;
QString outputFormat() const;
QgsRectangle outputRectangle() const;

private slots:
void on_mBrowseButton_clicked();
void on_mSaveAsLineEdit_textChanged( const QString& text );
void on_mCurrentExtentButton_clicked();
void on_mProviderExtentButton_clicked();

private:
QgsRasterDataProvider* mDataProvider;
QgsRectangle mCurrentExtent;

void setValidators();
void setOutputExtent( const QgsRectangle& r );
};

#endif // QGSRASTERLAYERSAVEASDIALOG_H
@@ -7,13 +7,13 @@
<x>0</x>
<y>0</y>
<width>415</width>
<height>248</height>
<height>383</height>
</rect>
</property>
<property name="windowTitle">
<string>Save raster layer as...</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="mFormatLabel">
<property name="text">
@@ -79,6 +79,90 @@
</layout>
</item>
<item row="3" column="0" colspan="3">
<widget class="QGroupBox" name="mExtentGroupBox">
<property name="title">
<string>Extent</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="mCurrentExtentButton">
<property name="text">
<string>Current Extent</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mProviderExtentButton">
<property name="text">
<string>Provider extent</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mXMinLabel">
<property name="text">
<string>X min</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mXMinLineEdit"/>
</item>
<item row="1" column="2">
<widget class="QLabel" name="mXMaxLabel">
<property name="text">
<string>X max</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="mXMaxLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mYMinLabel">
<property name="text">
<string>Y min</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="mYMinLineEdit"/>
</item>
<item row="2" column="2">
<widget class="QLabel" name="mYMaxLabel">
<property name="text">
<string>Y max</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="mYMaxLineEdit">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QGroupBox" name="mTilesGroupBox">
<property name="title">
<string>Tiles</string>
@@ -107,14 +191,14 @@
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="mTileModeCheckBox">
<property name="text">
<string>One output file per tile</string>
<string>Create VRT</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>

0 comments on commit eec208c

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