Skip to content

Commit

Permalink
Pass transformContext to raster writer
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Apr 17, 2019
1 parent 400e1c7 commit 87998f7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Expand Up @@ -201,6 +201,7 @@ Interpolates the value on the given point from given dataset.
public slots:

virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext );

%Docstring
Sets the coordinate transform context to ``transformContext``.

Expand Down
24 changes: 23 additions & 1 deletion python/core/auto_generated/raster/qgsrasterfilewriter.sip.in
Expand Up @@ -81,8 +81,26 @@ Ownership of the returned provider is passed to the caller.
.. versionadded:: 3.0
%End


WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = 0 ) /Deprecated/;
%Docstring
Write raster file

:param pipe: raster pipe
:param nCols: number of output columns
:param nRows: number of output rows (or -1 to automatically calculate row number to have square pixels)
:param outputExtent: extent to output
:param crs: crs to reproject to
:param feedback: optional feedback object for progress reports

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

WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = 0 );
const QgsCoordinateReferenceSystem &crs,
const QgsCoordinateTransformContext &transformContext,
QgsRasterBlockFeedback *feedback = 0 );
%Docstring
Write raster file

Expand All @@ -91,9 +109,13 @@ Write raster file
:param nRows: number of output rows (or -1 to automatically calculate row number to have square pixels)
:param outputExtent: extent to output
:param crs: crs to reproject to
:param transformContext: coordinate transform context
:param feedback: optional feedback object for progress reports

.. versionadded:: 3.8
%End


QString outputUrl() const;
%Docstring
Returns the output URL for the raster.
Expand Down
23 changes: 16 additions & 7 deletions src/core/raster/qgsrasterfilewriter.cpp
Expand Up @@ -68,8 +68,17 @@ QgsRasterFileWriter::QgsRasterFileWriter()

}


// Deprecated!
QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback )
{
return writeRaster( pipe, nCols, nRows, outputExtent, crs, ( pipe && pipe->provider() ) ? pipe->provider()->transformContext() : QgsCoordinateTransformContext(), feedback );
}

QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext,
QgsRasterBlockFeedback *feedback )
{
QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );

Expand Down Expand Up @@ -142,13 +151,13 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeRaster( const QgsRast
}
else
{
WriterError e = writeDataRaster( pipe, &iter, nCols, nRows, outputExtent, crs, feedback );
WriterError e = writeDataRaster( pipe, &iter, nCols, nRows, outputExtent, crs, transformContext, feedback );
return e;
}
}

QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback )
const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext, QgsRasterBlockFeedback *feedback )
{
QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
if ( !iter )
Expand Down Expand Up @@ -231,7 +240,7 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster( const Qgs
QgsRasterProjector *projector = pipe->projector();
if ( projector && projector->destinationCrs() != projector->sourceCrs() )
{
QgsCoordinateTransform ct( projector->destinationCrs(), projector->sourceCrs(), srcProvider->transformContext() );
QgsCoordinateTransform ct( projector->destinationCrs(), projector->sourceCrs(), transformContext );
srcExtent = ct.transformBoundingBox( outputExtent );
}
if ( !srcProvider->extent().contains( srcExtent ) )
Expand Down Expand Up @@ -496,10 +505,10 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeImageRaster( QgsRaste
iter->setMaximumTileWidth( mMaxTileWidth );
iter->setMaximumTileHeight( mMaxTileHeight );

void *redData = qgsMalloc( mMaxTileWidth * mMaxTileHeight );
void *greenData = qgsMalloc( mMaxTileWidth * mMaxTileHeight );
void *blueData = qgsMalloc( mMaxTileWidth * mMaxTileHeight );
void *alphaData = qgsMalloc( mMaxTileWidth * mMaxTileHeight );
void *redData = qgsMalloc( static_cast<size_t>( mMaxTileWidth * mMaxTileHeight ) );
void *greenData = qgsMalloc( static_cast<size_t>( mMaxTileWidth * mMaxTileHeight ) );
void *blueData = qgsMalloc( static_cast<size_t>( mMaxTileWidth * mMaxTileHeight ) );
void *alphaData = qgsMalloc( static_cast<size_t>( mMaxTileWidth * mMaxTileHeight ) );
int iterLeft = 0, iterTop = 0, iterCols = 0, iterRows = 0;
int fileIndex = 0;

Expand Down
29 changes: 25 additions & 4 deletions src/core/raster/qgsrasterfilewriter.h
Expand Up @@ -17,6 +17,7 @@

#include "qgis_core.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransformcontext.h"
#include <QDomDocument>
#include <QDomElement>
#include <QString>
Expand Down Expand Up @@ -93,6 +94,7 @@ class CORE_EXPORT QgsRasterFileWriter
const QgsCoordinateReferenceSystem &crs,
int nBands ) SIP_FACTORY;


/**
* Write raster file
\param pipe raster pipe
Expand All @@ -101,9 +103,27 @@ class CORE_EXPORT QgsRasterFileWriter
\param outputExtent extent to output
\param crs crs to reproject to
\param feedback optional feedback object for progress reports
\deprecated since QGIS 3.8, use version with transformContext instead
*/
Q_DECL_DEPRECATED WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr ) SIP_DEPRECATED;

/**
* Write raster file
\param pipe raster pipe
\param nCols number of output columns
\param nRows number of output rows (or -1 to automatically calculate row number to have square pixels)
\param outputExtent extent to output
\param crs crs to reproject to
\param transformContext coordinate transform context
\param feedback optional feedback object for progress reports
\since QGIS 3.8
*/
WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
const QgsCoordinateReferenceSystem &crs,
const QgsCoordinateTransformContext &transformContext,
QgsRasterBlockFeedback *feedback = nullptr );


/**
* Returns the output URL for the raster.
Expand Down Expand Up @@ -210,7 +230,8 @@ class CORE_EXPORT QgsRasterFileWriter
private:
QgsRasterFileWriter(); //forbidden
WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext,
QgsRasterBlockFeedback *feedback = nullptr );

// Helper method used by previous one
WriterError writeDataRaster( const QgsRasterPipe *pipe,
Expand Down Expand Up @@ -282,8 +303,8 @@ class CORE_EXPORT QgsRasterFileWriter

//! False: Write one file, TRUE: create a directory and add the files numbered
bool mTiledMode = false;
double mMaxTileWidth = 500;
double mMaxTileHeight = 500;
int mMaxTileWidth = 500;
int mMaxTileHeight = 500;

QList< int > mPyramidsList;
QString mPyramidsResampling = QStringLiteral( "AVERAGE" );
Expand Down

0 comments on commit 87998f7

Please sign in to comment.