Skip to content

Commit 0e0909b

Browse files
author
rblazek
committedApr 13, 2011
fall to precise reprojection if thresh wasnt reached
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15697 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
 

‎src/core/qgsrasterprojector.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ QgsRasterProjector::QgsRasterProjector(
8080
if ( myColsOK && myRowsOK )
8181
{
8282
QgsDebugMsg( "CP matrix within tolerance" );
83+
mApproximate = true;
8384
break;
8485
}
8586
// What is the maximum reasonable size of transformatio matrix?
8687
// TODO: consider better when to break - ratio
8788
if ( mCPRows * mCPCols > 0.25 * mDestRows * mDestCols )
8889
{
8990
QgsDebugMsg( "Too large CP matrix" );
91+
mApproximate = false;
9092
break;
9193
}
9294

@@ -292,6 +294,29 @@ void QgsRasterProjector::nextHelper()
292294
}
293295

294296
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 )
295320
{
296321
int myMatrixRow = matrixRow( theDestRow );
297322
int myMatrixCol = matrixCol( theDestCol );

‎src/core/qgsrasterprojector.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ class QgsRasterProjector
6969
/** \brief get destination point for _current_ matrix position */
7070
QgsPoint srcPoint( int theRow, int theCol );
7171

72+
/** \brief Get precise source row and column indexes for current source extent and resolution */
73+
inline void preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
74+
75+
/** \brief Get approximate source row and column indexes for current source extent and resolution */
76+
inline void approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
77+
7278
/** \brief Get source row and column indexes for current source extent and resolution */
7379
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );
7480

@@ -194,6 +200,9 @@ class QgsRasterProjector
194200
/** Maximum source resolution */
195201
double mMaxSrcXRes;
196202
double mMaxSrcYRes;
203+
204+
/** Use approximation */
205+
bool mApproximate;
197206
};
198207

199208
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.