QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
qgsrasterfilewritertask.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterfilewritertask.cpp
3  ---------------------------
4  begin : Apr 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgsrasterinterface.h"
20 #include "qgsrasterdataprovider.h"
21 
22 // Deprecated!
24  const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs )
25  : QgsRasterFileWriterTask( writer, pipe, columns, rows, outputExtent, crs,
26  ( pipe && pipe->provider() ) ? pipe->provider()->transformContext() : QgsCoordinateTransformContext() )
27 {
28 }
29 
31  const QgsRectangle &outputExtent,
33  const QgsCoordinateTransformContext &transformContext )
34  : QgsTask( tr( "Saving %1" ).arg( writer.outputUrl() ), QgsTask::CanCancel )
35  , mWriter( writer )
36  , mRows( rows )
37  , mColumns( columns )
38  , mExtent( outputExtent )
39  , mCrs( crs )
40  , mPipe( pipe )
41  , mFeedback( new QgsRasterBlockFeedback() )
42  , mTransformContext( transformContext )
43 {
44 }
45 
47 {
48  mFeedback->cancel();
50 }
51 
53 {
54  if ( !mPipe )
55  return false;
56 
58 
59  mError = mWriter.writeRaster( mPipe.get(), mColumns, mRows, mExtent, mCrs, mTransformContext, mFeedback.get() );
60 
61  return mError == QgsRasterFileWriter::NoError;
62 }
63 
65 {
66  if ( result )
67  emit writeComplete( mWriter.outputUrl() );
68  else
69  {
70  emit errorOccurred( mError );
71  QString errorMsg;
72  if ( !mFeedback->errors().isEmpty() )
73  errorMsg = mFeedback->errors().front();
74  emit errorOccurred( mError, errorMsg );
75  }
76 }
77 
78 
QgsTask task which performs a QgsRasterFileWriter layer saving operation as a background task...
A rectangle specified with double values.
Definition: qgsrectangle.h:41
void setProgress(double progress)
Sets the task's current progress.
Base class for processing modules.
Definition: qgsrasterpipe.h:46
const QgsCoordinateReferenceSystem & crs
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
Abstract base class for long running background tasks.
void cancel() override
Notifies the task that it should terminate.
Q_DECL_DEPRECATED WriterError writeRaster(const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback=nullptr)
Write raster file.
Contains information about the context in which a coordinate transform is executed.
void finished(bool result) override
If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether ...
bool run() override
Performs the task's operation.
void writeComplete(const QString &outputUrl)
Emitted when writing the layer is successfully completed.
virtual void cancel()
Notifies the task that it should terminate.
Q_DECL_DEPRECATED QgsRasterFileWriterTask(const QgsRasterFileWriter &writer, QgsRasterPipe *pipe, int columns, int rows, const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs)
Constructor for QgsRasterFileWriterTask.
This class represents a coordinate reference system (CRS).
void errorOccurred(int error)
Emitted when an error occurs which prevented the file being written (or if the task is canceled)...
Task can be canceled.
Feedback object tailored for raster block reading.
QString outputUrl() const
Returns the output URL for the raster.
The raster file writer which allows you to save a raster to a new file.