QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgsrasterpipe.h"
22 
23 // Deprecated!
25  const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs )
26  : QgsRasterFileWriterTask( writer, pipe, columns, rows, outputExtent, crs,
27  ( pipe && pipe->provider() ) ? pipe->provider()->transformContext() : QgsCoordinateTransformContext() )
28 {
29 }
30 
32  const QgsRectangle &outputExtent,
34  const QgsCoordinateTransformContext &transformContext )
35  : QgsTask( tr( "Saving %1" ).arg( writer.outputUrl() ), QgsTask::CanCancel )
36  , mWriter( writer )
37  , mRows( rows )
38  , mColumns( columns )
39  , mExtent( outputExtent )
40  , mCrs( crs )
41  , mPipe( pipe )
42  , mFeedback( new QgsRasterBlockFeedback() )
43  , mTransformContext( transformContext )
44 {
45  QgsRenderContext renderContext;
47  mFeedback->setRenderContext( renderContext );
48 }
49 
51 
53 {
54  mFeedback->cancel();
56 }
57 
59 {
60  if ( !mPipe )
61  return false;
62 
64 
65  mError = mWriter.writeRaster( mPipe.get(), mColumns, mRows, mExtent, mCrs, mTransformContext, mFeedback.get() );
66 
67  return mError == QgsRasterFileWriter::NoError;
68 }
69 
71 {
72  if ( result )
73  emit writeComplete( mWriter.outputUrl() );
74  else
75  {
76  emit errorOccurred( mError );
77  QString errorMsg;
78  if ( !mFeedback->errors().isEmpty() )
79  errorMsg = mFeedback->errors().front();
80  emit errorOccurred( mError, errorMsg );
81  }
82 }
83 
84 
QgsRasterFileWriter::NoError
@ NoError
Definition: qgsrasterfilewriter.h:49
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
qgsrasterpipe.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsRasterPipe
Contains a pipeline of raster interfaces for sequential raster processing.
Definition: qgsrasterpipe.h:49
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsRasterFileWriter::outputUrl
QString outputUrl() const
Returns the output URL for the raster.
Definition: qgsrasterfilewriter.h:132
QgsTask::cancel
virtual void cancel()
Notifies the task that it should terminate.
Definition: qgstaskmanager.cpp:91
Qgis::RendererUsage::Export
@ Export
Renderer used for printing or exporting to a file.
qgsrasterinterface.h
QgsRasterFileWriterTask::run
bool run() override
Performs the task's operation.
Definition: qgsrasterfilewritertask.cpp:58
QgsTask::setProgress
void setProgress(double progress)
Sets the task's current progress.
Definition: qgstaskmanager.cpp:232
qgsrasterfilewritertask.h
QgsFeedback::progressChanged
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
QgsRasterFileWriterTask::writeComplete
void writeComplete(const QString &outputUrl)
Emitted when writing the layer is successfully completed.
QgsRasterFileWriterTask::cancel
void cancel() override
Notifies the task that it should terminate.
Definition: qgsrasterfilewritertask.cpp:52
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsRasterFileWriter
The raster file writer which allows you to save a raster to a new file.
Definition: qgsrasterfilewriter.h:39
QgsRasterFileWriterTask::QgsRasterFileWriterTask
Q_DECL_DEPRECATED QgsRasterFileWriterTask(const QgsRasterFileWriter &writer, QgsRasterPipe *pipe, int columns, int rows, const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs)
Constructor for QgsRasterFileWriterTask.
Definition: qgsrasterfilewritertask.cpp:24
QgsRasterFileWriterTask::finished
void finished(bool result) override
If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether ...
Definition: qgsrasterfilewritertask.cpp:70
QgsRasterBlockFeedback
Feedback object tailored for raster block reading.
Definition: qgsrasterinterface.h:41
QgsRasterFileWriter::writeRaster
Q_DECL_DEPRECATED WriterError writeRaster(const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback=nullptr)
Write raster file.
Definition: qgsrasterfilewriter.cpp:79
QgsRasterFileWriterTask::errorOccurred
void errorOccurred(int error)
Emitted when an error occurs which prevented the file being written (or if the task is canceled).
QgsRasterFileWriterTask::~QgsRasterFileWriterTask
~QgsRasterFileWriterTask() override
QgsRenderContext::setRendererUsage
void setRendererUsage(Qgis::RendererUsage usage)
Sets the renderer usage.
Definition: qgsrendercontext.h:1011
QgsRasterFileWriterTask
QgsTask task which performs a QgsRasterFileWriter layer saving operation as a background task....
Definition: qgsrasterfilewritertask.h:39
qgsrasterdataprovider.h
QgsTask
Abstract base class for long running background tasks. Tasks can be controlled directly,...
Definition: qgstaskmanager.h:54