Skip to content
Permalink
Browse files

Add transform context to raster file writer task

  • Loading branch information
elpaso authored and nyalldawson committed Apr 17, 2019
1 parent 6e0bd82 commit 3d687e5558917f1407d1dafb7fc35cc955cbfdf0
@@ -28,15 +28,34 @@ QGIS interface.
%End
public:

QgsRasterFileWriterTask( const QgsRasterFileWriter &writer, QgsRasterPipe *pipe /Transfer/,
int columns, int rows,
const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs ) /Deprecated/;
%Docstring
Constructor for QgsRasterFileWriterTask. Takes a source ``writer``,
``columns``, ``rows``, ``outputExtent`` and destination ``crs``.
Ownership of the ``pipe`` is transferred to the writer task, and will
be deleted when the task completes.

.. deprecated:: since QGIS 3.8, use version with transformContext instead
%End


QgsRasterFileWriterTask( const QgsRasterFileWriter &writer, QgsRasterPipe *pipe /Transfer/,
int columns, int rows,
const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs );
const QgsCoordinateReferenceSystem &crs,
const QgsCoordinateTransformContext &transformContext
);
%Docstring
Constructor for QgsRasterFileWriterTask. Takes a source ``writer``,
``columns``, ``rows``, ``outputExtent`` and destination ``crs``.
``columns``, ``rows``, ``outputExtent``, destination ``crs`` and
coordinate ``transformContext`` .
Ownership of the ``pipe`` is transferred to the writer task, and will
be deleted when the task completes.

.. deprecated:: since QGIS 3.8, use version with transformContext instead
%End

virtual void cancel();
@@ -7595,7 +7595,7 @@ QString QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer, const bool defau
QString outputFormat = d.outputFormat();

QgsRasterFileWriterTask *writerTask = new QgsRasterFileWriterTask( fileWriter, pipe.release(), d.nColumns(), d.nRows(),
d.outputRectangle(), QgsProject::instance()->transformContext(), d.outputCrs() );
d.outputRectangle(), d.outputCrs(), QgsProject::instance()->transformContext() );

// when writer is successful:

@@ -17,11 +17,20 @@

#include "qgsrasterfilewritertask.h"
#include "qgsrasterinterface.h"
#include "qgsrasterdataprovider.h"

QgsRasterFileWriterTask::QgsRasterFileWriterTask( const QgsRasterFileWriter &writer, QgsRasterPipe *pipe,
int columns, int rows,
// Deprecated!
QgsRasterFileWriterTask::QgsRasterFileWriterTask( const QgsRasterFileWriter &writer, QgsRasterPipe *pipe, int columns, int rows,
const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs )
: QgsRasterFileWriterTask( writer, pipe, columns, rows, outputExtent, crs,
( pipe && pipe->provider() ) ? pipe->provider()->transformContext() : QgsCoordinateTransformContext() )
{
}

QgsRasterFileWriterTask::QgsRasterFileWriterTask( const QgsRasterFileWriter &writer, QgsRasterPipe *pipe, int columns, int rows,
const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs )
const QgsCoordinateReferenceSystem &crs,
const QgsCoordinateTransformContext &transformContext )
: QgsTask( tr( "Saving %1" ).arg( writer.outputUrl() ), QgsTask::CanCancel )
, mWriter( writer )
, mRows( rows )
@@ -30,7 +39,9 @@ QgsRasterFileWriterTask::QgsRasterFileWriterTask( const QgsRasterFileWriter &wri
, mCrs( crs )
, mPipe( pipe )
, mFeedback( new QgsRasterBlockFeedback() )
{}
, mTransformContext( transformContext )
{
}

void QgsRasterFileWriterTask::cancel()
{
@@ -45,7 +56,7 @@ bool QgsRasterFileWriterTask::run()

connect( mFeedback.get(), &QgsRasterBlockFeedback::progressChanged, this, &QgsRasterFileWriterTask::setProgress );

mError = mWriter.writeRaster( mPipe.get(), mColumns, mRows, mExtent, mCrs, mFeedback.get() );
mError = mWriter.writeRaster( mPipe.get(), mColumns, mRows, mExtent, mCrs, mTransformContext, mFeedback.get() );

return mError == QgsRasterFileWriter::NoError;
}
@@ -21,6 +21,7 @@
#include "qgis_core.h"
#include "qgstaskmanager.h"
#include "qgsrasterfilewriter.h"
#include "qgscoordinatetransformcontext.h"
#include "qgsrasterinterface.h"
#include "qgsrasterpipe.h"

@@ -45,11 +46,28 @@ class CORE_EXPORT QgsRasterFileWriterTask : public QgsTask
* \a columns, \a rows, \a outputExtent and destination \a crs.
* Ownership of the \a pipe is transferred to the writer task, and will
* be deleted when the task completes.
* \deprecated since QGIS 3.8, use version with transformContext instead
*/
Q_DECL_DEPRECATED QgsRasterFileWriterTask( const QgsRasterFileWriter &writer, QgsRasterPipe *pipe SIP_TRANSFER,
int columns, int rows,
const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs ) SIP_DEPRECATED;


/**
* Constructor for QgsRasterFileWriterTask. Takes a source \a writer,
* \a columns, \a rows, \a outputExtent, destination \a crs and
* coordinate \a transformContext .
* Ownership of the \a pipe is transferred to the writer task, and will
* be deleted when the task completes.
* \deprecated since QGIS 3.8, use version with transformContext instead
*/
QgsRasterFileWriterTask( const QgsRasterFileWriter &writer, QgsRasterPipe *pipe SIP_TRANSFER,
int columns, int rows,
const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs );
const QgsCoordinateReferenceSystem &crs,
const QgsCoordinateTransformContext &transformContext
);

void cancel() override;

@@ -87,6 +105,8 @@ class CORE_EXPORT QgsRasterFileWriterTask : public QgsTask

QgsRasterFileWriter::WriterError mError = QgsRasterFileWriter::NoError;

QgsCoordinateTransformContext mTransformContext;

};

#endif //QGSRASTERFILEWRITERTASK_H
@@ -17,6 +17,7 @@

from qgis.core import (
QgsApplication,
QgsCoordinateTransformContext,
QgsRasterLayer,
QgsRasterPipe,
QgsRasterFileWriter,
@@ -57,7 +58,7 @@ def testSuccess(self):
tmp = create_temp_filename('success.tif')
writer = QgsRasterFileWriter(tmp)

task = QgsRasterFileWriterTask(writer, pipe, 100, 100, raster_layer.extent(), raster_layer.crs())
task = QgsRasterFileWriterTask(writer, pipe, 100, 100, raster_layer.extent(), raster_layer.crs(), QgsCoordinateTransformContext())

task.writeComplete.connect(self.onSuccess)
task.errorOccurred.connect(self.onFail)
@@ -82,7 +83,7 @@ def testLayerRemovalBeforeRun(self):
tmp = create_temp_filename('remove_layer.tif')
writer = QgsRasterFileWriter(tmp)

task = QgsRasterFileWriterTask(writer, pipe, 100, 100, raster_layer.extent(), raster_layer.crs())
task = QgsRasterFileWriterTask(writer, pipe, 100, 100, raster_layer.extent(), raster_layer.crs(), QgsCoordinateTransformContext())

task.writeComplete.connect(self.onSuccess)
task.errorOccurred.connect(self.onFail)

0 comments on commit 3d687e5

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