Skip to content
Permalink
Browse files

Pass transformContext to raster writer

  • Loading branch information
elpaso authored and nyalldawson committed Apr 16, 2019
1 parent 400e1c7 commit 87998f7f7da2a746cd2c5a35c998edee3922de97
@@ -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``.

@@ -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

@@ -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.
@@ -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 );

@@ -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 )
@@ -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 ) )
@@ -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;

@@ -17,6 +17,7 @@

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


/**
* Write raster file
\param pipe raster pipe
@@ -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.
@@ -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,
@@ -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" );

0 comments on commit 87998f7

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