@@ -102,8 +102,8 @@ QgsRasterProjector::QgsRasterProjector(
102
102
// Calculate source dimensions
103
103
calcSrcExtent ();
104
104
calcSrcRowsCols ();
105
- mSrcXRes = mSrcExtent .height () / mSrcRows ;
106
- mSrcYRes = mSrcExtent .width () / mSrcCols ;
105
+ mSrcYRes = mSrcExtent .height () / mSrcRows ;
106
+ mSrcXRes = mSrcExtent .width () / mSrcCols ;
107
107
108
108
// init helper points
109
109
pHelperTop = new QgsPoint[mDestCols ];
@@ -121,21 +121,20 @@ QgsRasterProjector::~QgsRasterProjector()
121
121
void QgsRasterProjector::calcSrcExtent ()
122
122
{
123
123
/* Run around the mCPMatrix and find source extent */
124
+ // Attention, source limits are not necessarily on destination edges, e.g.
125
+ // for destination EPSG:32661 Polar Stereographic and source EPSG:4326,
126
+ // the maximum y may be in the middle of destination extent
127
+ // TODO: How to find extent exactly and quickly?
128
+ // For now, we runt through all matrix
124
129
QgsPoint myPoint = mCPMatrix [0 ][0 ];
125
130
mSrcExtent = QgsRectangle ( myPoint.x (), myPoint.y (), myPoint.x (), myPoint.y () );
126
131
for ( int i = 0 ; i < mCPRows ; i++ )
127
132
{
128
- myPoint = mCPMatrix [i][0 ];
129
- mSrcExtent .combineExtentWith ( myPoint.x (), myPoint.y () );
130
- myPoint = mCPMatrix [i][mCPCols -1 ];
131
- mSrcExtent .combineExtentWith ( myPoint.x (), myPoint.y () );
132
- }
133
- for ( int i = 1 ; i < mCPCols - 1 ; i++ )
134
- {
135
- myPoint = mCPMatrix [0 ][i];
136
- mSrcExtent .combineExtentWith ( myPoint.x (), myPoint.y () );
137
- myPoint = mCPMatrix [mCPRows -1 ][i];
138
- mSrcExtent .combineExtentWith ( myPoint.x (), myPoint.y () );
133
+ for ( int j = 1 ; j < mCPCols - 1 ; j++ )
134
+ {
135
+ myPoint = mCPMatrix [i][j];
136
+ mSrcExtent .combineExtentWith ( myPoint.x (), myPoint.y () );
137
+ }
139
138
}
140
139
// Expand a bit to avoid possible approx coords falling out because of representation error?
141
140
@@ -301,16 +300,23 @@ void QgsRasterProjector::srcRowCol( int theDestRow, int theDestCol, int *theSrcR
301
300
302
301
void QgsRasterProjector::preciseSrcRowCol ( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
303
302
{
303
+ // QgsDebugMsg( QString( "theDestRow = %1" ).arg(theDestRow) );
304
+ // QgsDebugMsg( QString( "theDestRow = %1 mDestExtent.yMaximum() = %2 mDestYRes = %3" ).arg(theDestRow).arg(mDestExtent.yMaximum()).arg(mDestYRes) );
305
+
304
306
// Get coordinate of center of destination cell
305
307
double x = mDestExtent .xMinimum () + ( theDestCol + 0.5 ) * mDestXRes ;
306
308
double y = mDestExtent .yMaximum () - ( theDestRow + 0.5 ) * mDestYRes ;
307
309
double z = 0 ;
308
310
311
+ // QgsDebugMsg( QString( "x = %1 y = %2" ).arg(x).arg(y) );
309
312
mCoordinateTransform .transformInPlace ( x, y, z );
313
+ // QgsDebugMsg( QString( "x = %1 y = %2" ).arg(x).arg(y) );
310
314
311
315
// Get source row col
312
- *theSrcRow = ( int ) floor (( mSrcExtent .yMaximum () - y ) / mSrcXRes );
313
- *theSrcCol = ( int ) floor (( x - mSrcExtent .xMinimum () ) / mSrcYRes );
316
+ *theSrcRow = ( int ) floor (( mSrcExtent .yMaximum () - y ) / mSrcYRes );
317
+ *theSrcCol = ( int ) floor (( x - mSrcExtent .xMinimum () ) / mSrcXRes );
318
+ // QgsDebugMsg( QString( "mSrcExtent.yMaximum() = %1 mSrcYRes = %2" ).arg(mSrcExtent.yMaximum()).arg(mSrcYRes) );
319
+ // QgsDebugMsg( QString( "theSrcRow = %1 theSrcCol = %2" ).arg(*theSrcRow).arg(*theSrcCol) );
314
320
315
321
// With epsg 32661 (Polar Stereographic) it was happening that *theSrcCol == mSrcCols
316
322
// For now silently correct limits to avoid crashes
@@ -362,8 +368,8 @@ void QgsRasterProjector::approximateSrcRowCol( int theDestRow, int theDestCol, i
362
368
363
369
// TODO: check again cell selection (coor is in the middle)
364
370
365
- *theSrcRow = ( int ) floor (( mSrcExtent .yMaximum () - mySrcY ) / mSrcXRes );
366
- *theSrcCol = ( int ) floor (( mySrcX - mSrcExtent .xMinimum () ) / mSrcYRes );
371
+ *theSrcRow = ( int ) floor (( mSrcExtent .yMaximum () - mySrcY ) / mSrcYRes );
372
+ *theSrcCol = ( int ) floor (( mySrcX - mSrcExtent .xMinimum () ) / mSrcXRes );
367
373
368
374
// For now silently correct limits to avoid crashes
369
375
// TODO: review
0 commit comments