Skip to content
Permalink
Browse files
Raster projector constructor cleanup
Marked raster interface as uncopiable (it should have always been uncopiable)
  • Loading branch information
wonder-sk committed Sep 1, 2016
1 parent a5039d6 commit 6bb291f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 216 deletions.
@@ -256,5 +256,10 @@ class QgsRasterInterface
int theStats = QgsRasterBandStats::All,
const QgsRectangle & theExtent = QgsRectangle(),
int theBinCount = 0 );

private:
QgsRasterInterface(const QgsRasterInterface &);
QgsRasterInterface &operator=(const QgsRasterInterface &);

};

@@ -1,6 +1,10 @@

/** Raster projector */

/** \ingroup core
* \brief QgsRasterProjector implements approximate projection support for
* it calculates grid of points in source CRS for target CRS + extent
* which are used to calculate affine transformation matrices.
* \class QgsRasterProjector
*/
class QgsRasterProjector : QgsRasterInterface
{
%TypeHeaderCode
@@ -18,33 +22,6 @@ class QgsRasterProjector : QgsRasterInterface
Exact, //!< Exact, precise but slow
};

/** \brief QgsRasterProjector implements approximate projection support for
* it calculates grid of points in source CRS for target CRS + extent
* which are used to calculate affine transformation matrices.
*/

QgsRasterProjector( const QgsCoordinateReferenceSystem& theSrcCRS,
const QgsCoordinateReferenceSystem& theDestCRS,
int theSrcDatumTransform,
int theDestDatumTransform,
const QgsRectangle& theDestExtent,
int theDestRows, int theDestCols,
double theMaxSrcXRes, double theMaxSrcYRes,
const QgsRectangle& theExtent
);

QgsRasterProjector( const QgsCoordinateReferenceSystem& theSrcCRS,
const QgsCoordinateReferenceSystem& theDestCRS,
const QgsRectangle& theDestExtent,
int theDestRows, int theDestCols,
double theMaxSrcXRes, double theMaxSrcYRes,
const QgsRectangle& theExtent
);
QgsRasterProjector( const QgsCoordinateReferenceSystem& theSrcCRS,
const QgsCoordinateReferenceSystem& theDestCRS,
double theMaxSrcXRes, double theMaxSrcYRes,
const QgsRectangle& theExtent
);
QgsRasterProjector();

/** \brief The destructor */
@@ -270,6 +270,9 @@ class CORE_EXPORT QgsRasterInterface
int theStats = QgsRasterBandStats::All,
const QgsRectangle & theExtent = QgsRectangle(),
int theBinCount = 0 );

private:
Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
};

#endif
@@ -23,98 +23,14 @@
#include "qgscoordinatetransform.h"
#include "qgscsexception.h"

QgsRasterProjector::QgsRasterProjector(
const QgsCoordinateReferenceSystem& theSrcCRS,
const QgsCoordinateReferenceSystem& theDestCRS,
int theSrcDatumTransform,
int theDestDatumTransform,
const QgsRectangle& theDestExtent,
int theDestRows, int theDestCols,
double theMaxSrcXRes, double theMaxSrcYRes,
const QgsRectangle& theExtent )
: QgsRasterInterface( nullptr )
, mSrcCRS( theSrcCRS )
, mDestCRS( theDestCRS )
, mSrcDatumTransform( theSrcDatumTransform )
, mDestDatumTransform( theDestDatumTransform )
, mDestExtent( theDestExtent )
, mExtent( theExtent )
, mDestRows( theDestRows ), mDestCols( theDestCols )
, pHelperTop( nullptr ), pHelperBottom( nullptr )
, mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
, mPrecision( Approximate )
, mApproximate( true )
{
QgsDebugMsgLevel( "Entered", 4 );
QgsDebugMsgLevel( "theDestExtent = " + theDestExtent.toString(), 4 );

calc();
}

QgsRasterProjector::QgsRasterProjector(
const QgsCoordinateReferenceSystem& theSrcCRS,
const QgsCoordinateReferenceSystem& theDestCRS,
const QgsRectangle& theDestExtent,
int theDestRows, int theDestCols,
double theMaxSrcXRes, double theMaxSrcYRes,
const QgsRectangle& theExtent )
: QgsRasterInterface( nullptr )
, mSrcCRS( theSrcCRS )
, mDestCRS( theDestCRS )
, mSrcDatumTransform( -1 )
, mDestDatumTransform( -1 )
, mDestExtent( theDestExtent )
, mExtent( theExtent )
, mDestRows( theDestRows ), mDestCols( theDestCols )
, pHelperTop( nullptr ), pHelperBottom( nullptr )
, mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
, mPrecision( Approximate )
, mApproximate( false )
{
QgsDebugMsgLevel( "Entered", 4 );
QgsDebugMsgLevel( "theDestExtent = " + theDestExtent.toString(), 4 );

calc();
}

QgsRasterProjector::QgsRasterProjector(
const QgsCoordinateReferenceSystem& theSrcCRS,
const QgsCoordinateReferenceSystem& theDestCRS,
double theMaxSrcXRes, double theMaxSrcYRes,
const QgsRectangle& theExtent )
QgsRasterProjector::QgsRasterProjector()
: QgsRasterInterface( nullptr )
, mSrcCRS( theSrcCRS )
, mDestCRS( theDestCRS )
, mSrcDatumTransform( -1 )
, mDestDatumTransform( -1 )
, mExtent( theExtent )
, mDestRows( 0 )
, mDestCols( 0 )
, mDestXRes( 0.0 )
, mDestYRes( 0.0 )
, mSrcRows( 0 )
, mSrcCols( 0 )
, mSrcXRes( 0.0 )
, mSrcYRes( 0.0 )
, mDestRowsPerMatrixRow( 0.0 )
, mDestColsPerMatrixCol( 0.0 )
, pHelperTop( nullptr ), pHelperBottom( nullptr )
, mHelperTopRow( 0 )
, mCPCols( 0 )
, mCPRows( 0 )
, mSqrTolerance( 0.0 )
, mMaxSrcXRes( theMaxSrcXRes )
, mMaxSrcYRes( theMaxSrcYRes )
, mPrecision( Approximate )
, mApproximate( false )
{
QgsDebugMsgLevel( "Entered", 4 );
}

QgsRasterProjector::QgsRasterProjector()
: QgsRasterInterface( nullptr )
, mSrcDatumTransform( -1 )
, mDestDatumTransform( -1 )
, mDestRows( 0 )
, mDestCols( 0 )
, mDestXRes( 0.0 )
@@ -133,64 +49,22 @@ QgsRasterProjector::QgsRasterProjector()
, mSqrTolerance( 0.0 )
, mMaxSrcXRes( 0 )
, mMaxSrcYRes( 0 )
, mPrecision( Approximate )
, mApproximate( false )
{
QgsDebugMsgLevel( "Entered", 4 );
}

QgsRasterProjector::QgsRasterProjector( const QgsRasterProjector &projector )
: QgsRasterInterface( nullptr )
, pHelperTop( nullptr )
, pHelperBottom( nullptr )
, mHelperTopRow( 0 )
, mCPCols( 0 )
, mCPRows( 0 )
, mSqrTolerance( 0 )
, mApproximate( false )
{
mSrcCRS = projector.mSrcCRS;
mDestCRS = projector.mDestCRS;
mSrcDatumTransform = projector.mSrcDatumTransform;
mDestDatumTransform = projector.mDestDatumTransform;
mMaxSrcXRes = projector.mMaxSrcXRes;
mMaxSrcYRes = projector.mMaxSrcYRes;
mExtent = projector.mExtent;
mDestRows = projector.mDestRows;
mDestCols = projector.mDestCols;
mDestXRes = projector.mDestXRes;
mDestYRes = projector.mDestYRes;
mSrcRows = projector.mSrcRows;
mSrcCols = projector.mSrcCols;
mSrcXRes = projector.mSrcXRes;
mSrcYRes = projector.mSrcYRes;
mDestRowsPerMatrixRow = projector.mDestRowsPerMatrixRow;
mDestColsPerMatrixCol = projector.mDestColsPerMatrixCol;
mPrecision = projector.mPrecision;
}

QgsRasterProjector & QgsRasterProjector::operator=( const QgsRasterProjector & projector )
{
if ( &projector != this )
{
mSrcCRS = projector.mSrcCRS;
mDestCRS = projector.mDestCRS;
mSrcDatumTransform = projector.mSrcDatumTransform;
mDestDatumTransform = projector.mDestDatumTransform;
mMaxSrcXRes = projector.mMaxSrcXRes;
mMaxSrcYRes = projector.mMaxSrcYRes;
mExtent = projector.mExtent;
mPrecision = projector.mPrecision;
}
return *this;
}

QgsRasterProjector* QgsRasterProjector::clone() const
{
QgsDebugMsgLevel( "Entered", 4 );
QgsRasterProjector * projector = new QgsRasterProjector( mSrcCRS, mDestCRS, mMaxSrcXRes, mMaxSrcYRes, mExtent );
QgsRasterProjector * projector = new QgsRasterProjector;
projector->mSrcCRS = mSrcCRS;
projector->mDestCRS = mDestCRS;
projector->mSrcDatumTransform = mSrcDatumTransform;
projector->mDestDatumTransform = mDestDatumTransform;
projector->mMaxSrcXRes = mMaxSrcXRes;
projector->mMaxSrcYRes = mMaxSrcYRes;
projector->mExtent = mExtent;
projector->mPrecision = mPrecision;
return projector;
}
@@ -897,17 +771,17 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
mDestCols = width;
calc();

QgsDebugMsgLevel( QString( "srcExtent:\n%1" ).arg( srcExtent().toString() ), 4 );
QgsDebugMsgLevel( QString( "srcCols = %1 srcRows = %2" ).arg( srcCols() ).arg( srcRows() ), 4 );
QgsDebugMsgLevel( QString( "srcExtent:\n%1" ).arg( mSrcExtent.toString() ), 4 );
QgsDebugMsgLevel( QString( "srcCols = %1 srcRows = %2" ).arg( mSrcCols ).arg( mSrcRows ), 4 );

// If we zoom out too much, projector srcRows / srcCols maybe 0, which can cause problems in providers
if ( srcRows() <= 0 || srcCols() <= 0 )
if ( mSrcRows <= 0 || mSrcCols <= 0 )
{
QgsDebugMsgLevel( "Zero srcRows or srcCols", 4 );
return new QgsRasterBlock();
}

QgsRasterBlock *inputBlock = mInput->block( bandNo, srcExtent(), srcCols(), srcRows(), feedback );
QgsRasterBlock *inputBlock = mInput->block( bandNo, mSrcExtent, mSrcCols, mSrcRows, feedback );
if ( !inputBlock || inputBlock->isEmpty() )
{
QgsDebugMsg( "No raster data!" );
@@ -36,6 +36,9 @@ class QgsPoint;
class QgsCoordinateTransform;

/** \ingroup core
* \brief QgsRasterProjector implements approximate projection support for
* it calculates grid of points in source CRS for target CRS + extent
* which are used to calculate affine transformation matrices.
* \class QgsRasterProjector
*/
class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
@@ -50,44 +53,11 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
Exact = 1, //!< Exact, precise but slow
};

/** \brief QgsRasterProjector implements approximate projection support for
* it calculates grid of points in source CRS for target CRS + extent
* which are used to calculate affine transformation matrices.
*/

QgsRasterProjector( const QgsCoordinateReferenceSystem& theSrcCRS,
const QgsCoordinateReferenceSystem& theDestCRS,
int theSrcDatumTransform,
int theDestDatumTransform,
const QgsRectangle& theDestExtent,
int theDestRows, int theDestCols,
double theMaxSrcXRes, double theMaxSrcYRes,
const QgsRectangle& theExtent
);

QgsRasterProjector( const QgsCoordinateReferenceSystem& theSrcCRS,
const QgsCoordinateReferenceSystem& theDestCRS,
const QgsRectangle& theDestExtent,
int theDestRows, int theDestCols,
double theMaxSrcXRes, double theMaxSrcYRes,
const QgsRectangle& theExtent
);
QgsRasterProjector( const QgsCoordinateReferenceSystem& theSrcCRS,
const QgsCoordinateReferenceSystem& theDestCRS,
double theMaxSrcXRes, double theMaxSrcYRes,
const QgsRectangle& theExtent
);
QgsRasterProjector();
/** \brief Copy constructor */
// To avoid synthesized which fails on copy of QgsCoordinateTransform
// (QObject child) in Python bindings
QgsRasterProjector( const QgsRasterProjector &projector );

/** \brief The destructor */
~QgsRasterProjector();

QgsRasterProjector & operator=( const QgsRasterProjector &projector );

QgsRasterProjector *clone() const override;

int bandCount() const override;
@@ -128,24 +98,13 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
QgsRectangle& theDestExtent, int& theDestXSize, int& theDestYSize );

private:
/** Get source extent */
QgsRectangle srcExtent() { return mSrcExtent; }

/** Get/set source width/height */
int srcRows() { return mSrcRows; }
int srcCols() { return mSrcCols; }
void setSrcRows( int theRows ) { mSrcRows = theRows; mSrcXRes = mSrcExtent.height() / mSrcRows; }
void setSrcCols( int theCols ) { mSrcCols = theCols; mSrcYRes = mSrcExtent.width() / mSrcCols; }

/** \brief Get source row and column indexes for current source extent and resolution
If source pixel is outside source extent theSrcRow and theSrcCol are left unchanged.
@return true if inside source
*/
bool srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform& ct );

int dstRows() const { return mDestRows; }
int dstCols() const { return mDestCols; }

/** \brief get destination point for _current_ destination position */
void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );

@@ -215,6 +174,16 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
/** Destination datum transformation id (or -1 if none) */
int mDestDatumTransform;

/** Requested precision */
Precision mPrecision;

/** Use approximation (requested precision is Approximate and it is possible to calculate
* an approximation matrix with a sufficient precision) */
bool mApproximate;




/** Destination extent */
QgsRectangle mDestExtent;

@@ -284,12 +253,6 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
double mMaxSrcXRes;
double mMaxSrcYRes;

/** Requested precision */
Precision mPrecision;

/** Use approximation (requested precision is Approximate and it is possible to calculate
* an approximation matrix with a sufficient precision) */
bool mApproximate;
};

#endif

0 comments on commit 6bb291f

Please sign in to comment.