Skip to content

Commit

Permalink
Improve QgsRasterProjector handling of transform context
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 31, 2019
1 parent c61fb85 commit 823d28b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
31 changes: 25 additions & 6 deletions src/core/raster/qgsrasterprojector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
#include "qgscoordinatetransform.h"
#include "qgsexception.h"


Q_NOWARN_DEPRECATED_PUSH // because of deprecated members
QgsRasterProjector::QgsRasterProjector()
: QgsRasterInterface( nullptr )
{
QgsDebugMsgLevel( QStringLiteral( "Entered" ), 4 );
}
Q_NOWARN_DEPRECATED_POP


QgsRasterProjector *QgsRasterProjector::clone() const
Expand All @@ -36,8 +37,13 @@ QgsRasterProjector *QgsRasterProjector::clone() const
QgsRasterProjector *projector = new QgsRasterProjector;
projector->mSrcCRS = mSrcCRS;
projector->mDestCRS = mDestCRS;
projector->mTransformContext = mTransformContext;

Q_NOWARN_DEPRECATED_PUSH
projector->mSrcDatumTransform = mSrcDatumTransform;
projector->mDestDatumTransform = mDestDatumTransform;
Q_NOWARN_DEPRECATED_POP

projector->mPrecision = mPrecision;
return projector;
}
Expand Down Expand Up @@ -66,17 +72,21 @@ void QgsRasterProjector::setCrs( const QgsCoordinateReferenceSystem &srcCRS,
{
mSrcCRS = srcCRS;
mDestCRS = destCRS;
Q_NOWARN_DEPRECATED_PUSH
mSrcDatumTransform = srcDatumTransform;
mDestDatumTransform = destDatumTransform;
Q_NOWARN_DEPRECATED_POP
}

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


Expand Down Expand Up @@ -764,7 +774,11 @@ QgsRasterBlock *QgsRasterProjector::block( int bandNo, QgsRectangle const &exte
return mInput->block( bandNo, extent, width, height, feedback );
}

const QgsCoordinateTransform inverseCt { mDestCRS, mSrcCRS, mDestDatumTransform, mSrcDatumTransform };
Q_NOWARN_DEPRECATED_PUSH
const QgsCoordinateTransform inverseCt = mSrcDatumTransform != -1 || mDestDatumTransform != -1 ?
QgsCoordinateTransform( mDestCRS, mSrcCRS, mDestDatumTransform, mSrcDatumTransform ) : QgsCoordinateTransform( mDestCRS, mSrcCRS, mTransformContext ) ;
Q_NOWARN_DEPRECATED_POP

ProjectorData pd( extent, width, height, mInput, inverseCt, mPrecision );

QgsDebugMsgLevel( QStringLiteral( "srcExtent:\n%1" ).arg( pd.srcExtent().toString() ), 4 );
Expand Down Expand Up @@ -861,7 +875,12 @@ bool QgsRasterProjector::destExtentSize( const QgsRectangle &srcExtent, int srcX
{
return false;
}
const QgsCoordinateTransform ct { mSrcCRS, mDestCRS, mSrcDatumTransform, mDestDatumTransform };

Q_NOWARN_DEPRECATED_PUSH
const QgsCoordinateTransform ct = mSrcDatumTransform != -1 || mDestDatumTransform != -1 ?
QgsCoordinateTransform( mSrcCRS, mDestCRS, mSrcDatumTransform, mDestDatumTransform ) : QgsCoordinateTransform( mSrcCRS, mDestCRS, mTransformContext ) ;
Q_NOWARN_DEPRECATED_POP

return extentSize( ct, srcExtent, srcXSize, srcYSize, destExtent, destXSize, destYSize );
}

Expand Down
6 changes: 4 additions & 2 deletions src/core/raster/qgsrasterprojector.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,16 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
QgsCoordinateReferenceSystem mDestCRS;

//! Source datum transformation id (or -1 if none)
int mSrcDatumTransform = -1;
Q_DECL_DEPRECATED int mSrcDatumTransform = -1;

//! Destination datum transformation id (or -1 if none)
int mDestDatumTransform = -1;
Q_DECL_DEPRECATED int mDestDatumTransform = -1;

//! Requested precision
Precision mPrecision = Approximate;

QgsCoordinateTransformContext mTransformContext;

};


Expand Down

0 comments on commit 823d28b

Please sign in to comment.