27 int theDestRows,
int theDestCols,
28 double theMaxSrcXRes,
double theMaxSrcYRes,
31 , mSrcCRS( theSrcCRS )
32 , mDestCRS( theDestCRS )
33 , mCoordinateTransform( theDestCRS, theSrcCRS )
34 , mDestExtent( theDestExtent )
35 , mExtent( theExtent )
36 , mDestRows( theDestRows ), mDestCols( theDestCols )
37 , pHelperTop( 0 ), pHelperBottom( 0 )
38 , mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
49 double theMaxSrcXRes,
double theMaxSrcYRes,
52 , mSrcCRS( theSrcCRS )
53 , mDestCRS( theDestCRS )
54 , mCoordinateTransform( theDestCRS, theSrcCRS )
55 , mExtent( theExtent )
56 , pHelperTop( 0 ), pHelperBottom( 0 )
57 , mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
64 , pHelperTop( 0 ), pHelperBottom( 0 )
83 if ( &projector !=
this )
171 for (
int i = 0; i <
mCPRows; i++ )
173 QList<QgsPoint> myRow;
179 QList<bool> myLegalRow;
180 myLegalRow.append(
bool(
false ) );
181 myLegalRow.append(
bool(
false ) );
182 myLegalRow.append(
bool(
false ) );
185 for (
int i = 0; i <
mCPRows; i++ )
202 if ( myColsOK && myRowsOK )
217 QgsDebugMsg( QString(
"CPMatrix size: mCPRows = %1 mCPCols = %2" ).arg( mCPRows ).arg(
mCPCols ) );
248 for (
int i = 0; i <
mCPRows; i++ )
250 for (
int j = 0; j <
mCPCols ; j++ )
300 for (
int i = 0; i <
mCPRows; i++ )
304 for (
int j = 0; j <
mCPCols; j++ )
333 QgsDebugMsg( QString(
"myDestColsPerMatrixCell = %1 myDestRowsPerMatrixCell = %2" ).arg( myDestColsPerMatrixCell ).arg( myDestRowsPerMatrixCell ) );
335 double myMinSize = DBL_MAX;
337 for (
int i = 0; i <
mCPRows - 1; i++ )
339 for (
int j = 0; j <
mCPCols - 1; j++ )
346 double mySize = sqrt( myPointA.
sqrDist( myPointB ) ) / myDestColsPerMatrixCell;
347 if ( mySize < myMinSize )
350 mySize = sqrt( myPointA.
sqrDist( myPointC ) ) / myDestRowsPerMatrixCell;
351 if ( mySize < myMinSize )
366 QgsDebugMsg( QString(
"myMinXSize = %1 myMinYSize = %2" ).arg( myMinXSize ).arg( myMinYSize ) );
394 Q_UNUSED( theDestRow );
402 for (
int myDestCol = 0; myDestCol <
mDestCols; myDestCol++ )
406 int myMatrixCol =
matrixCol( myDestCol );
408 double myDestXMin, myDestYMin, myDestXMax, myDestYMax;
413 double xfrac = ( myDestX - myDestXMin ) / ( myDestXMax - myDestXMin );
417 double s = mySrcPoint0.
x() + ( mySrcPoint1.
x() - mySrcPoint0.
x() ) * xfrac;
418 double t = mySrcPoint0.
y() + ( mySrcPoint1.
y() - mySrcPoint0.
y() ) * xfrac;
420 thePoints[myDestCol].
setX( s );
421 thePoints[myDestCol].
setY( t );
474 QgsDebugMsgLevel( QString(
"theSrcRow = %1 theSrcCol = %2" ).arg( *theSrcRow ).arg( *theSrcCol ), 5 );
482 if ( *theSrcRow < 0 )
486 if ( *theSrcCol < 0 )
495 int myMatrixRow =
matrixRow( theDestRow );
496 int myMatrixCol =
matrixCol( theDestCol );
508 double myDestXMin, myDestYMin, myDestXMax, myDestYMax;
513 double yfrac = ( myDestY - myDestYMin ) / ( myDestYMax - myDestYMin );
522 double tx = myTop.
x();
523 double ty = myTop.
y();
524 double bx = myBot.
x();
525 double by = myBot.
y();
526 double mySrcX = bx + ( tx - bx ) * yfrac;
527 double mySrcY = by + ( ty - by ) * yfrac;
538 if ( *theSrcRow < 0 )
542 if ( *theSrcCol < 0 )
550 for (
int r = 0; r <
mCPRows - 1; r++ )
552 QList<QgsPoint> myRow;
553 QList<bool> myLegalRow;
554 for (
int c = 0; c <
mCPCols; c++ )
557 myLegalRow.append(
false );
563 mCPRows += mCPRows - 1;
564 for (
int r = 1; r < mCPRows - 1; r += 2 )
572 for (
int r = 0; r <
mCPRows; r++ )
574 QList<QgsPoint> myRow;
575 QList<bool> myLegalRow;
576 for (
int c = 0; c <
mCPCols - 1; c++ )
583 for (
int c = 1; c <
mCPCols - 1; c += 2 )
592 double myDestX, myDestY;
594 QgsPoint myDestPoint( myDestX, myDestY );
611 for (
int i = 0; i <
mCPCols; i++ )
622 for (
int i = 0; i <
mCPRows; i++ )
632 for (
int c = 0; c <
mCPCols; c++ )
634 for (
int r = 1; r <
mCPRows - 1; r += 2 )
636 double myDestX, myDestY;
638 QgsPoint myDestPoint( myDestX, myDestY );
644 QgsPoint mySrcApprox(( mySrcPoint1.
x() + mySrcPoint3.
x() ) / 2, ( mySrcPoint1.
y() + mySrcPoint3.
y() ) / 2 );
653 double mySqrDist = myDestApprox.
sqrDist( myDestPoint );
672 for (
int r = 0; r <
mCPRows; r++ )
674 for (
int c = 1; c <
mCPCols - 1; c += 2 )
676 double myDestX, myDestY;
679 QgsPoint myDestPoint( myDestX, myDestY );
684 QgsPoint mySrcApprox(( mySrcPoint1.
x() + mySrcPoint3.
x() ) / 2, ( mySrcPoint1.
y() + mySrcPoint3.
y() ) / 2 );
693 double mySqrDist = myDestApprox.
sqrDist( myDestPoint );
713 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
723 return mInput->
block( bandNo, extent, width, height );
742 if ( !inputBlock || inputBlock->
isEmpty() )
760 if ( !outputBlock->isValid() )
779 for (
int i = 0; i < height; ++i )
781 for (
int j = 0; j < width; ++j )
784 size_t srcIndex = ( size_t )srcRow *
mSrcCols + srcCol;
785 QgsDebugMsgLevel( QString(
"row = %1 col = %2 srcRow = %3 srcCol = %4" ).arg( i ).arg( j ).arg( srcRow ).arg( srcCol ), 5 );
788 if ( doNoData && inputBlock->
isNoData( srcRow, srcCol ) )
790 outputBlock->setIsNoData( srcRow, srcCol );
794 size_t destIndex = ( size_t )i * width + j;
795 char *srcBits = inputBlock->
bits( srcIndex );
796 char *destBits = outputBlock->bits( destIndex );
799 QgsDebugMsg( QString(
"Cannot get input block data: row = %1 col = %2" ).arg( i ).arg( j ) );
804 QgsDebugMsg( QString(
"Cannot set output block data: srcRow = %1 srcCol = %2" ).arg( srcRow ).arg( srcCol ) );
807 memcpy( destBits, srcBits, pixelSize );
virtual int bandCount() const =0
Get number of bands.
QgsPoint * pHelperTop
Array of source points for each destination column on top of current CPMatrix grid row...
QgsPoint srcPoint(int theRow, int theCol)
get destination point for current matrix position
A rectangle specified with double values.
QgsRasterInterface * clone() const
Clone itself, create deep copy.
QString cpToString()
get mCPMatrix as string
bool isEmpty() const
test if rectangle is empty
void approximateSrcRowCol(int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol)
Get approximate source row and column indexes for current source extent and resolution.
bool checkRows()
check error along rows returns true if within threshold
double mDestRowsPerMatrixRow
number of destination rows per matrix row
void setXMaximum(double x)
Set the maximum x value.
QgsCoordinateTransform mCoordinateTransform
Reverse coordinate transform (from destination to source)
double yMaximum() const
Get the y maximum value (top side of rectangle)
bool mApproximate
Use approximation.
virtual const QgsRasterInterface * srcInput() const
Get source / raw input, the first in pipe, usually provider.
double noDataValue() const
Return no data value.
double mSqrTolerance
Maximum tolerance in destination units.
void destPointOnCPMatrix(int theRow, int theCol, double *theX, double *theY)
get destination point for current destination position
int mDestRows
Number of destination rows.
void insertCols()
insert columns to matrix
QGis::DataType dataType() const
Returns data type.
int mCPRows
Number of mCPMatrix rows.
QgsCoordinateReferenceSystem mDestCRS
Destination CRS.
int mSrcCols
Number of source columns.
double sqrDist(double x, double y) const
Returns the squared distance between this point and x,y.
bool isNoData(int row, int column)
Check if value at position is no data.
int mHelperTopRow
Current mHelperTop matrix row.
bool calcCol(int theCol)
calculate matrix column
double mSrcYRes
Source y resolution.
QList< QList< QgsPoint > > mCPMatrix
Grid of source control points.
void nextHelper()
Calc / switch helper.
void calc()
Calculate matrix.
virtual int ySize() const
void calcCP(int theRow, int theCol)
void setCRS(const QgsCoordinateReferenceSystem &theSrcCRS, const QgsCoordinateReferenceSystem &theDestCRS)
set source and destination CRS
void insertRows()
insert rows to matrix
void combineExtentWith(QgsRectangle *rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
double mSrcXRes
Source x resolution.
bool calcRow(int theRow)
calculate matrix row
~QgsRasterProjector()
The destructor.
bool hasNoData() const
Returns true if the block may contain no data.
double mMaxSrcXRes
Maximum source resolution.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
#define QgsDebugMsgLevel(str, level)
virtual QgsRectangle extent()=0
Get the extent of the data source.
void setYMinimum(double y)
Set the minimum y value.
QgsPoint * pHelperBottom
Array of source points for each destination column on bottom of current CPMatrix grid row...
int srcRows()
get/set source width/height
double mDestColsPerMatrixCol
number of destination cols per matrix col
QString toString() const
String representation of the point (x,y)
bool checkCols()
check error along columns returns true if within threshold
static int typeSize(int dataType)
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
double mDestXRes
Destination x resolution.
void calcSrcRowsCols()
calculate minimum source width and height
Base class for processing filters like renderers, reprojector, resampler etc.
A class to represent a point geometry.
int bandCount() const
Get number of bands.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
void srcRowCol(int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol)
Get source row and column indexes for current source extent and resolution.
virtual QgsRectangle extent()
Get the extent of the interface.
int mCPCols
Number of mCPMatrix columns.
bool hasNoDataValue() const
True if the block has no data value.
int matrixCol(int theDestCol)
QList< QList< bool > > mCPLegalMatrix
Grid of source control points transformation possible indicator.
char * bits(int row, int column)
Get pointer to data.
int mSrcRows
Number of source rows.
void calcSrcExtent()
calculate source extent
virtual int xSize() const
Get raster size.
QGis::DataType dataType(int bandNo) const
Returns data type for the band specified by number.
void setYMaximum(double y)
Set the maximum y value.
QgsRectangle mExtent
Source raster extent.
void calcHelper(int theMatrixRow, QgsPoint *thePoints)
Calculate array of src helper points.
Class for storing a coordinate reference system (CRS)
DataType
Raster data types.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
QgsRectangle srcExtent()
get source extent
double mDestYRes
Destination y resolution.
void preciseSrcRowCol(int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol)
Get precise source row and column indexes for current source extent and resolution.
QgsRectangle mSrcExtent
Source extent.
Custom exception class for Coordinate Reference System related exceptions.
QgsRectangle mDestExtent
Destination extent.
double width() const
Width of the rectangle.
QgsRasterInterface * mInput
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)
Read block of data using given extent and size.
int mDestCols
Number of destination columns.
QgsRasterProjector & operator=(const QgsRasterProjector &projector)
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
double xMinimum() const
Get the x minimum value (left side of rectangle)
QgsCoordinateReferenceSystem mSrcCRS
Source CRS.
int matrixRow(int theDestRow)
Get matrix upper left row/col indexes for destination row/col.
void setXMinimum(double x)
Set the minimum x value.
double height() const
Height of the rectangle.
bool isEmpty() const
Returns true if block is empty, i.e.
Base class for raster data providers.