Skip to content

Commit 2f1cf5b

Browse files
author
rblazek
committed
fix for epsg 32661 Polar Stereographic
git-svn-id: http://svn.osgeo.org/qgis/trunk@15846 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 84ba7c7 commit 2f1cf5b

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/core/qgsrasterprojector.cpp

+23-17
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ QgsRasterProjector::QgsRasterProjector(
102102
// Calculate source dimensions
103103
calcSrcExtent();
104104
calcSrcRowsCols();
105-
mSrcXRes = mSrcExtent.height() / mSrcRows;
106-
mSrcYRes = mSrcExtent.width() / mSrcCols;
105+
mSrcYRes = mSrcExtent.height() / mSrcRows;
106+
mSrcXRes = mSrcExtent.width() / mSrcCols;
107107

108108
// init helper points
109109
pHelperTop = new QgsPoint[mDestCols];
@@ -121,21 +121,20 @@ QgsRasterProjector::~QgsRasterProjector()
121121
void QgsRasterProjector::calcSrcExtent()
122122
{
123123
/* 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
124129
QgsPoint myPoint = mCPMatrix[0][0];
125130
mSrcExtent = QgsRectangle( myPoint.x(), myPoint.y(), myPoint.x(), myPoint.y() );
126131
for ( int i = 0; i < mCPRows; i++ )
127132
{
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+
}
139138
}
140139
// Expand a bit to avoid possible approx coords falling out because of representation error?
141140

@@ -301,16 +300,23 @@ void QgsRasterProjector::srcRowCol( int theDestRow, int theDestCol, int *theSrcR
301300

302301
void QgsRasterProjector::preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
303302
{
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+
304306
// Get coordinate of center of destination cell
305307
double x = mDestExtent.xMinimum() + ( theDestCol + 0.5 ) * mDestXRes;
306308
double y = mDestExtent.yMaximum() - ( theDestRow + 0.5 ) * mDestYRes;
307309
double z = 0;
308310

311+
//QgsDebugMsg( QString( "x = %1 y = %2" ).arg(x).arg(y) );
309312
mCoordinateTransform.transformInPlace( x, y, z );
313+
//QgsDebugMsg( QString( "x = %1 y = %2" ).arg(x).arg(y) );
310314

311315
// 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) );
314320

315321
// With epsg 32661 (Polar Stereographic) it was happening that *theSrcCol == mSrcCols
316322
// For now silently correct limits to avoid crashes
@@ -362,8 +368,8 @@ void QgsRasterProjector::approximateSrcRowCol( int theDestRow, int theDestCol, i
362368

363369
// TODO: check again cell selection (coor is in the middle)
364370

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

368374
// For now silently correct limits to avoid crashes
369375
// TODO: review

0 commit comments

Comments
 (0)