27 int theSrcDatumTransform,
28 int theDestDatumTransform,
30 int theDestRows,
int theDestCols,
31 double theMaxSrcXRes,
double theMaxSrcYRes,
34 , mSrcCRS( theSrcCRS )
35 , mDestCRS( theDestCRS )
36 , mSrcDatumTransform( theSrcDatumTransform )
37 , mDestDatumTransform( theDestDatumTransform )
38 , mDestExtent( theDestExtent )
39 , mExtent( theExtent )
40 , mDestRows( theDestRows ), mDestCols( theDestCols )
41 , pHelperTop( 0 ), pHelperBottom( 0 )
42 , mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
54 int theDestRows,
int theDestCols,
55 double theMaxSrcXRes,
double theMaxSrcYRes,
58 , mSrcCRS( theSrcCRS )
59 , mDestCRS( theDestCRS )
60 , mSrcDatumTransform( -1 )
61 , mDestDatumTransform( -1 )
62 , mDestExtent( theDestExtent )
63 , mExtent( theExtent )
64 , mDestRows( theDestRows ), mDestCols( theDestCols )
65 , pHelperTop( 0 ), pHelperBottom( 0 )
66 , mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
77 double theMaxSrcXRes,
double theMaxSrcYRes,
80 , mSrcCRS( theSrcCRS )
81 , mDestCRS( theDestCRS )
82 , mSrcDatumTransform( -1 )
83 , mDestDatumTransform( -1 )
84 , mExtent( theExtent )
85 , pHelperTop( 0 ), pHelperBottom( 0 )
86 , mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
92 :
QgsRasterInterface( 0 ), mSrcDatumTransform( -1 ), mDestDatumTransform( -1 ) , pHelperTop( 0 ), pHelperBottom( 0 )
111 if ( &projector !=
this )
203 for (
int i = 0; i <
mCPRows; i++ )
205 QList<QgsPoint> myRow;
211 QList<bool> myLegalRow;
212 myLegalRow.append(
bool(
false ) );
213 myLegalRow.append(
bool(
false ) );
214 myLegalRow.append(
bool(
false ) );
217 for (
int i = 0; i <
mCPRows; i++ )
234 if ( myColsOK && myRowsOK )
249 QgsDebugMsg( QString(
"CPMatrix size: mCPRows = %1 mCPCols = %2" ).arg( mCPRows ).arg(
mCPCols ) );
280 for (
int i = 0; i <
mCPRows; i++ )
282 for (
int j = 0; j <
mCPCols ; j++ )
335 for (
int i = 0; i <
mCPRows; i++ )
339 for (
int j = 0; j <
mCPCols; j++ )
368 QgsDebugMsg( QString(
"myDestColsPerMatrixCell = %1 myDestRowsPerMatrixCell = %2" ).arg( myDestColsPerMatrixCell ).arg( myDestRowsPerMatrixCell ) );
370 double myMinSize = DBL_MAX;
372 for (
int i = 0; i <
mCPRows - 1; i++ )
374 for (
int j = 0; j <
mCPCols - 1; j++ )
381 double mySize = sqrt( myPointA.
sqrDist( myPointB ) ) / myDestColsPerMatrixCell;
382 if ( mySize < myMinSize )
385 mySize = sqrt( myPointA.
sqrDist( myPointC ) ) / myDestRowsPerMatrixCell;
386 if ( mySize < myMinSize )
401 QgsDebugMsg( QString(
"myMinXSize = %1 myMinYSize = %2" ).arg( myMinXSize ).arg( myMinYSize ) );
429 Q_UNUSED( theDestRow );
437 for (
int myDestCol = 0; myDestCol <
mDestCols; myDestCol++ )
441 int myMatrixCol =
matrixCol( myDestCol );
443 double myDestXMin, myDestYMin, myDestXMax, myDestYMax;
448 double xfrac = ( myDestX - myDestXMin ) / ( myDestXMax - myDestXMin );
452 double s = mySrcPoint0.
x() + ( mySrcPoint1.
x() - mySrcPoint0.
x() ) * xfrac;
453 double t = mySrcPoint0.
y() + ( mySrcPoint1.
y() - mySrcPoint0.
y() ) * xfrac;
455 thePoints[myDestCol].
setX( s );
456 thePoints[myDestCol].
setY( t );
478 return preciseSrcRowCol( theDestRow, theDestCol, theSrcRow, theSrcCol, ct );
516 QgsDebugMsgLevel( QString(
"theSrcRow = %1 theSrcCol = %2" ).arg( *theSrcRow ).arg( *theSrcCol ), 5 );
523 if ( *theSrcRow >=
mSrcRows )
return false;
524 if ( *theSrcRow < 0 )
return false;
525 if ( *theSrcCol >=
mSrcCols )
return false;
526 if ( *theSrcCol < 0 )
return false;
533 int myMatrixRow =
matrixRow( theDestRow );
534 int myMatrixCol =
matrixCol( theDestCol );
546 double myDestXMin, myDestYMin, myDestXMax, myDestYMax;
551 double yfrac = ( myDestY - myDestYMin ) / ( myDestYMax - myDestYMin );
560 double tx = myTop.
x();
561 double ty = myTop.
y();
562 double bx = myBot.
x();
563 double by = myBot.
y();
564 double mySrcX = bx + ( tx - bx ) * yfrac;
565 double mySrcY = by + ( ty - by ) * yfrac;
580 if ( *theSrcRow >=
mSrcRows )
return false;
581 if ( *theSrcRow < 0 )
return false;
582 if ( *theSrcCol >=
mSrcCols )
return false;
583 if ( *theSrcCol < 0 )
return false;
590 for (
int r = 0; r <
mCPRows - 1; r++ )
592 QList<QgsPoint> myRow;
593 QList<bool> myLegalRow;
594 for (
int c = 0; c <
mCPCols; c++ )
597 myLegalRow.append(
false );
603 mCPRows += mCPRows - 1;
604 for (
int r = 1; r < mCPRows - 1; r += 2 )
612 for (
int r = 0; r <
mCPRows; r++ )
614 QList<QgsPoint> myRow;
615 QList<bool> myLegalRow;
616 for (
int c = 0; c <
mCPCols - 1; c++ )
623 for (
int c = 1; c <
mCPCols - 1; c += 2 )
632 double myDestX, myDestY;
634 QgsPoint myDestPoint( myDestX, myDestY );
658 for (
int i = 0; i <
mCPCols; i++ )
669 for (
int i = 0; i <
mCPRows; i++ )
684 for (
int c = 0; c <
mCPCols; c++ )
686 for (
int r = 1; r <
mCPRows - 1; r += 2 )
688 double myDestX, myDestY;
690 QgsPoint myDestPoint( myDestX, myDestY );
696 QgsPoint mySrcApprox(( mySrcPoint1.
x() + mySrcPoint3.
x() ) / 2, ( mySrcPoint1.
y() + mySrcPoint3.
y() ) / 2 );
705 double mySqrDist = myDestApprox.
sqrDist( myDestPoint );
729 for (
int r = 0; r <
mCPRows; r++ )
731 for (
int c = 1; c <
mCPCols - 1; c += 2 )
733 double myDestX, myDestY;
736 QgsPoint myDestPoint( myDestX, myDestY );
741 QgsPoint mySrcApprox(( mySrcPoint1.
x() + mySrcPoint3.
x() ) / 2, ( mySrcPoint1.
y() + mySrcPoint3.
y() ) / 2 );
750 double mySqrDist = myDestApprox.
sqrDist( myDestPoint );
770 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
780 return mInput->
block( bandNo, extent, width, height );
799 if ( !inputBlock || inputBlock->
isEmpty() )
817 if ( !outputBlock->isValid() )
845 outputBlock->setIsNoData();
848 for (
int i = 0; i < height; ++i )
850 for (
int j = 0; j < width; ++j )
852 bool inside =
srcRowCol( i, j, &srcRow, &srcCol, ct );
853 if ( !inside )
continue;
856 QgsDebugMsgLevel( QString(
"row = %1 col = %2 srcRow = %3 srcCol = %4" ).arg( i ).arg( j ).arg( srcRow ).arg( srcCol ), 5 );
859 if ( doNoData && inputBlock->
isNoData( srcRow, srcCol ) )
861 outputBlock->setIsNoData( i, j );
866 char *srcBits = inputBlock->
bits( srcIndex );
867 char *destBits = outputBlock->bits( destIndex );
870 QgsDebugMsg( QString(
"Cannot get input block data: row = %1 col = %2" ).arg( i ).arg( j ) );
875 QgsDebugMsg( QString(
"Cannot set output block data: srcRow = %1 srcCol = %2" ).arg( srcRow ).arg( srcCol ) );
878 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.
bool checkRows(const QgsCoordinateTransform *ct)
check error along rows returns true if within threshold
QgsRasterInterface * clone() const
Clone itself, create deep copy.
QString cpToString()
get mCPMatrix as string
bool isEmpty() const
test if rectangle is empty.
void setCRS(const QgsCoordinateReferenceSystem &theSrcCRS, const QgsCoordinateReferenceSystem &theDestCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
set source and destination CRS
double mDestRowsPerMatrixRow
number of destination rows per matrix row
bool preciseSrcRowCol(int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform *ct)
Get precise source row and column indexes for current source extent and resolution.
void setXMaximum(double x)
Set the maximum x value.
double yMaximum() const
Get the y maximum value (top side of rectangle)
static bool typeIsNumeric(QGis::DataType type)
Returns true if data type is numeric.
int mDestDatumTransform
Destination datum transformation id (or -1 if none)
bool mApproximate
Use approximation.
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
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.
QGis::DataType dataType() const
Returns data type.
int mCPRows
Number of mCPMatrix rows.
QgsCoordinateReferenceSystem mDestCRS
Destination CRS.
void insertRows(const QgsCoordinateTransform *ct)
insert rows to matrix
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.
double mSrcYRes
Source y resolution.
void insertCols(const QgsCoordinateTransform *ct)
insert columns to matrix
QList< QList< QgsPoint > > mCPMatrix
Grid of source control points.
void nextHelper()
Calc / switch helper.
void calc()
Calculate matrix.
virtual int ySize() const
bool setIsNoData(int row, int column)
Set no data on pixel.
void combineExtentWith(QgsRectangle *rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
double mSrcXRes
Source x resolution.
~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...
bool approximateSrcRowCol(int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol)
Get approximate source row and column indexes for current source extent and resolution.
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)
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.
bool calcRow(int theRow, const QgsCoordinateTransform *ct)
calculate matrix row
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.
unsigned long long qgssize
qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
bool srcRowCol(int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol, const QgsCoordinateTransform *ct)
Get source row and column indexes for current source extent and resolution If source pixel is outside...
int bandCount() const
Get number of bands.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
bool checkCols(const QgsCoordinateTransform *ct)
check error along columns returns true if within threshold
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)
bool calcCol(int theCol, const QgsCoordinateTransform *ct)
calculate matrix column
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 calcCP(int theRow, int theCol, const QgsCoordinateTransform *ct)
void setYMaximum(double y)
Set the maximum y value.
QgsRectangle mExtent
Source raster extent.
QgsRectangle intersect(const QgsRectangle *rect) const
return the intersection with the given rectangle
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.
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)
int mSrcDatumTransform
Source datum transformation id (or -1 if none)
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.