Skip to content
Permalink
Browse files
fall to precise reprojection if thresh wasnt reached
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 0e0909be375ec6543fa6b45786ca90bedcd9b6f0
Showing with 34 additions and 0 deletions.
  1. +25 −0 src/core/qgsrasterprojector.cpp
  2. +9 −0 src/core/qgsrasterprojector.h
@@ -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;
}

@@ -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 );
@@ -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 );

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

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

#endif

0 comments on commit 0e0909b

Please sign in to comment.