@@ -80,13 +80,15 @@ QgsRasterProjector::QgsRasterProjector(
80
80
if ( myColsOK && myRowsOK )
81
81
{
82
82
QgsDebugMsg ( " CP matrix within tolerance" );
83
+ mApproximate = true ;
83
84
break ;
84
85
}
85
86
// What is the maximum reasonable size of transformatio matrix?
86
87
// TODO: consider better when to break - ratio
87
88
if ( mCPRows * mCPCols > 0.25 * mDestRows * mDestCols )
88
89
{
89
90
QgsDebugMsg ( " Too large CP matrix" );
91
+ mApproximate = false ;
90
92
break ;
91
93
}
92
94
@@ -292,6 +294,29 @@ void QgsRasterProjector::nextHelper()
292
294
}
293
295
294
296
void QgsRasterProjector::srcRowCol ( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
297
+ {
298
+ if ( mApproximate ) approximateSrcRowCol ( theDestRow, theDestCol, theSrcRow, theSrcCol);
299
+ else preciseSrcRowCol ( theDestRow, theDestCol, theSrcRow, theSrcCol);
300
+ }
301
+
302
+ void QgsRasterProjector::preciseSrcRowCol ( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
303
+ {
304
+ // Get coordinate of center of destination cell
305
+ double x = mDestExtent .xMinimum () + ( theDestCol + 0.5 ) * mDestXRes ;
306
+ double y = mDestExtent .yMaximum () - ( theDestRow + 0.5 ) * mDestYRes ;
307
+ double z = 0 ;
308
+
309
+ mCoordinateTransform .transformInPlace ( x, y, z );
310
+
311
+ // Get source row col
312
+ *theSrcRow = ( int ) floor (( mSrcExtent .yMaximum () - y ) / mSrcXRes );
313
+ *theSrcCol = ( int ) floor (( x - mSrcExtent .xMinimum () ) / mSrcYRes );
314
+
315
+ assert ( *theSrcRow < mSrcRows );
316
+ assert ( *theSrcCol < mSrcCols );
317
+ }
318
+
319
+ void QgsRasterProjector::approximateSrcRowCol ( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
295
320
{
296
321
int myMatrixRow = matrixRow ( theDestRow );
297
322
int myMatrixCol = matrixCol ( theDestCol );
0 commit comments