Skip to content

Commit

Permalink
fall to precise reprojection if thresh wasnt reached
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15697 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Apr 13, 2011
1 parent 45cbf9f commit 0e0909b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/core/qgsrasterprojector.cpp
Expand Up @@ -80,13 +80,15 @@ QgsRasterProjector::QgsRasterProjector(
if ( myColsOK && myRowsOK )
{
QgsDebugMsg( "CP matrix within tolerance" );
mApproximate = true;
break;
}
// What is the maximum reasonable size of transformatio matrix?
// TODO: consider better when to break - ratio
if ( mCPRows * mCPCols > 0.25 * mDestRows * mDestCols )
{
QgsDebugMsg( "Too large CP matrix" );
mApproximate = false;
break;
}

Expand Down Expand Up @@ -292,6 +294,29 @@ void QgsRasterProjector::nextHelper()
}

void QgsRasterProjector::srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
{
if ( mApproximate ) approximateSrcRowCol( theDestRow, theDestCol, theSrcRow, theSrcCol);
else preciseSrcRowCol( theDestRow, theDestCol, theSrcRow, theSrcCol);
}

void QgsRasterProjector::preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
{
// Get coordinate of center of destination cell
double x = mDestExtent.xMinimum() + ( theDestCol + 0.5 ) * mDestXRes;
double y = mDestExtent.yMaximum() - ( theDestRow + 0.5 ) * mDestYRes;
double z = 0;

mCoordinateTransform.transformInPlace( x, y, z );

// Get source row col
*theSrcRow = ( int ) floor(( mSrcExtent.yMaximum() - y ) / mSrcXRes );
*theSrcCol = ( int ) floor(( x - mSrcExtent.xMinimum() ) / mSrcYRes );

assert( *theSrcRow < mSrcRows );
assert( *theSrcCol < mSrcCols );
}

void QgsRasterProjector::approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
{
int myMatrixRow = matrixRow( theDestRow );
int myMatrixCol = matrixCol( theDestCol );
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgsrasterprojector.h
Expand Up @@ -69,6 +69,12 @@ class QgsRasterProjector
/** \brief get destination point for _current_ matrix position */
QgsPoint srcPoint( int theRow, int theCol );

/** \brief Get precise source row and column indexes for current source extent and resolution */
inline void preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );

/** \brief Get approximate source row and column indexes for current source extent and resolution */
inline void approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );

/** \brief Get source row and column indexes for current source extent and resolution */
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );

Expand Down Expand Up @@ -194,6 +200,9 @@ class QgsRasterProjector
/** Maximum source resolution */
double mMaxSrcXRes;
double mMaxSrcYRes;

/** Use approximation */
bool mApproximate;
};

#endif
Expand Down

0 comments on commit 0e0909b

Please sign in to comment.