Skip to content
Permalink
Browse files

Raster transform context

  • Loading branch information
elpaso authored and nyalldawson committed Apr 17, 2019
1 parent b3a448a commit 654a78d6ff331d5345e21e42a08bba3be83c79d3
@@ -31,6 +31,8 @@ struct QgsRasterViewPort

int mSrcDatumTransform;
int mDestDatumTransform;

QgsCoordinateTransformContext mTransformContext;
};

/************************************************************************
@@ -103,7 +103,7 @@ bool QgsRasterBooleanLogicAlgorithmBase::prepareAlgorithm( const QVariantMap &pa
{
input.projector = qgis::make_unique< QgsRasterProjector >();
input.projector->setInput( input.sourceDataProvider.get() );
input.projector->setCrs( layer->crs(), mCrs );
input.projector->setCrs( layer->crs(), mCrs, context.transformContext() );
input.interface = input.projector.get();
}
mInputs.emplace_back( std::move( input ) );
@@ -140,7 +140,7 @@ bool QgsRasterLayerZonalStatsAlgorithm::prepareAlgorithm( const QVariantMap &par
{
mProjector = qgis::make_unique< QgsRasterProjector >();
mProjector->setInput( mZonesDataProvider.get() );
mProjector->setCrs( zonesLayer->crs(), layer->crs() );
mProjector->setCrs( zonesLayer->crs(), layer->crs(), context.transformContext() );
mZonesInterface = mProjector.get();
}
break;
@@ -158,7 +158,7 @@ bool QgsRasterLayerZonalStatsAlgorithm::prepareAlgorithm( const QVariantMap &par
{
mProjector = qgis::make_unique< QgsRasterProjector >();
mProjector->setInput( mSourceDataProvider.get() );
mProjector->setCrs( layer->crs(), zonesLayer->crs() );
mProjector->setCrs( layer->crs(), zonesLayer->crs(), context.transformContext() );
mSourceInterface = mProjector.get();
}
break;
@@ -176,7 +176,7 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculation( QgsFeedback
if ( uniqueRasterEntries[layerRef.first].raster->crs() != mOutputCrs )
{
QgsRasterProjector proj;
proj.setCrs( ref.raster->crs(), mOutputCrs );
proj.setCrs( ref.raster->crs(), mOutputCrs, ref.raster->dataProvider()->transformContext() );
proj.setInput( ref.raster->dataProvider() );
proj.setPrecision( QgsRasterProjector::Exact );
layerRef.second.reset( proj.block( ref.bandNumber, rect, mNumOutputColumns, 1 ) );
@@ -227,7 +227,7 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculation( QgsFeedback
if ( it->raster->crs() != mOutputCrs )
{
QgsRasterProjector proj;
proj.setCrs( it->raster->crs(), mOutputCrs );
proj.setCrs( it->raster->crs(), mOutputCrs, it->raster->dataProvider()->transformContext() );
proj.setInput( it->raster->dataProvider() );
proj.setPrecision( QgsRasterProjector::Exact );

@@ -516,7 +516,7 @@ QgsRasterCalculator::Result QgsRasterCalculator::processCalculationGPU( std::uni
if ( ref.layer->crs() != mOutputCrs )
{
QgsRasterProjector proj;
proj.setCrs( ref.layer->crs(), mOutputCrs );
proj.setCrs( ref.layer->crs(), mOutputCrs, ref.layer->dataProvider()->transformContext() );
proj.setInput( ref.layer->dataProvider() );
proj.setPrecision( QgsRasterProjector::Exact );
block.reset( proj.block( ref.band, rect, mNumOutputColumns, 1 ) );
@@ -7546,7 +7546,7 @@ QString QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer, const bool defau
if ( d.outputCrs() != rasterLayer->crs() )
{
QgsRasterProjector *projector = new QgsRasterProjector;
projector->setCrs( rasterLayer->crs(), d.outputCrs() );
projector->setCrs( rasterLayer->crs(), d.outputCrs(), rasterLayer->dataProvider()->transformContext() );
if ( !pipe->insert( 2, projector ) )
{
QgsDebugMsg( QStringLiteral( "Cannot set pipe projector" ) );
@@ -7565,7 +7565,7 @@ QString QgisApp::saveAsRasterFile( QgsRasterLayer *rasterLayer, const bool defau
QgsDebugMsg( QStringLiteral( "Cannot get pipe projector" ) );
return QString();
}
projector->setCrs( rasterLayer->crs(), d.outputCrs() );
projector->setCrs( rasterLayer->crs(), d.outputCrs(), rasterLayer->dataProvider()->transformContext() );
}

if ( !pipe->last() )
@@ -272,7 +272,7 @@ void QgsRasterLayer::draw( QPainter *theQPainter,
// params in QgsRasterProjector
if ( projector )
{
projector->setCrs( rasterViewPort->mSrcCRS, rasterViewPort->mDestCRS, rasterViewPort->mSrcDatumTransform, rasterViewPort->mDestDatumTransform );
projector->setCrs( rasterViewPort->mSrcCRS, rasterViewPort->mDestCRS, rasterViewPort->mTransformContext );
}

// Drawer to pipe?
@@ -163,6 +163,7 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
mRasterViewPort->mDestCRS = rendererContext.coordinateTransform().destinationCrs();
mRasterViewPort->mSrcDatumTransform = rendererContext.coordinateTransform().sourceDatumTransformId();
mRasterViewPort->mDestDatumTransform = rendererContext.coordinateTransform().destinationDatumTransformId();
mRasterViewPort->mTransformContext = rendererContext.transformContext();
}
else
{
@@ -263,7 +264,7 @@ bool QgsRasterLayerRenderer::render()
// params in QgsRasterProjector
if ( projector )
{
projector->setCrs( mRasterViewPort->mSrcCRS, mRasterViewPort->mDestCRS, mRasterViewPort->mSrcDatumTransform, mRasterViewPort->mDestDatumTransform );
projector->setCrs( mRasterViewPort->mSrcCRS, mRasterViewPort->mDestCRS, mRasterViewPort->mTransformContext );
}

// Drawer to pipe?
@@ -39,7 +39,6 @@ QgsRasterProjector *QgsRasterProjector::clone() const
projector->mSrcDatumTransform = mSrcDatumTransform;
projector->mDestDatumTransform = mDestDatumTransform;
projector->mPrecision = mPrecision;
projector->mTransformContext = mTransformContext;
return projector;
}

@@ -70,15 +69,15 @@ void QgsRasterProjector::setCrs( const QgsCoordinateReferenceSystem &srcCRS,
mDestCRS = destCRS;
mSrcDatumTransform = srcDatumTransform;
mDestDatumTransform = destDatumTransform;
mTransformContext = QgsCoordinateTransformContext();
mTransformContext.addSourceDestinationDatumTransform( srcCRS, destCRS, srcDatumTransform, destDatumTransform );
}

void QgsRasterProjector::setCrs( const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, QgsCoordinateTransformContext transformContext )
{
mSrcCRS = srcCRS;
mDestCRS = destCRS;
mTransformContext = transformContext;
const auto ctPair { transformContext.calculateDatumTransforms( srcCRS, destCRS ) };
mSrcDatumTransform = ctPair.sourceTransformId;
mDestDatumTransform = ctPair.destinationTransformId;
}


@@ -767,17 +766,7 @@ QgsRasterBlock *QgsRasterProjector::block( int bandNo, QgsRectangle const &exte
return mInput->block( bandNo, extent, width, height, feedback );
}

QgsCoordinateTransform inverseCt;

if ( mSrcDatumTransform != -1 && mDestDatumTransform != -1 )
{
inverseCt = QgsCoordinateTransform( mDestCRS, mSrcCRS, mDestDatumTransform, mSrcDatumTransform );
}
else
{
inverseCt = QgsCoordinateTransform( mDestCRS, mSrcCRS, mTransformContext );
}

const QgsCoordinateTransform inverseCt { mDestCRS, mSrcCRS, mDestDatumTransform, mSrcDatumTransform };
ProjectorData pd( extent, width, height, mInput, inverseCt, mPrecision );

QgsDebugMsgLevel( QStringLiteral( "srcExtent:\n%1" ).arg( pd.srcExtent().toString() ), 4 );
@@ -874,15 +863,7 @@ bool QgsRasterProjector::destExtentSize( const QgsRectangle &srcExtent, int srcX
{
return false;
}
QgsCoordinateTransform ct;
if ( mSrcDatumTransform != -1 && mDestDatumTransform != -1 )
{
ct = QgsCoordinateTransform( mSrcCRS, mDestCRS, mSrcDatumTransform, mDestDatumTransform );
}
else
{
ct = QgsCoordinateTransform( mSrcCRS, mDestCRS, mTransformContext );
}
const QgsCoordinateTransform ct { mSrcCRS, mDestCRS, mSrcDatumTransform, mDestDatumTransform };
return extentSize( ct, srcExtent, srcXSize, srcYSize, destExtent, destXSize, destYSize );
}

@@ -122,9 +122,6 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
//! Requested precision
Precision mPrecision = Approximate;

//! Transform context
QgsCoordinateTransformContext mTransformContext;

};


@@ -19,6 +19,7 @@

#include "qgspointxy.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransformcontext.h"
#include "qgsrectangle.h"

/**
@@ -68,6 +69,11 @@ struct CORE_EXPORT QgsRasterViewPort

int mSrcDatumTransform;
int mDestDatumTransform;

/**
* Coordinate transform context
*/
QgsCoordinateTransformContext mTransformContext;
};

#endif //QGSRASTERVIEWPORT_H
@@ -201,7 +201,7 @@ namespace QgsWcs
if ( responseCRS != rLayer->crs() )
{
QgsRasterProjector *projector = new QgsRasterProjector;
projector->setCrs( rLayer->crs(), responseCRS );
projector->setCrs( rLayer->crs(), responseCRS, rLayer->dataProvider()->transformContext() );
if ( !pipe.insert( 2, projector ) )
{
throw QgsRequestNotWellFormedException( QStringLiteral( "Cannot set pipe projector" ) );
@@ -159,7 +159,7 @@ bool TestQgsRasterFileWriter::writeTest( const QString &rasterName )

// Reprojection not really done
QgsRasterProjector *projector = new QgsRasterProjector;
projector->setCrs( provider->crs(), provider->crs() );
projector->setCrs( provider->crs(), provider->crs(), provider->transformContext() );
if ( !pipe->insert( 2, projector ) )
{
logError( QStringLiteral( "Cannot set pipe projector" ) );

0 comments on commit 654a78d

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