Skip to content

Commit add0ebc

Browse files
committedSep 24, 2012
Merge pull request #246 from homann/CP-legal
A fix for #6396.
2 parents 1190eea + 75452b8 commit add0ebc

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed
 

‎src/core/qgsrasterprojector.cpp

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ void QgsRasterProjector::calc()
132132
{
133133
QgsDebugMsg( "Entered" );
134134
mCPMatrix.clear();
135+
mCPLegalMatrix.clear();
135136
delete[] pHelperTop;
136137
pHelperTop = 0;
137138
delete[] pHelperBottom;
@@ -169,6 +170,12 @@ void QgsRasterProjector::calc()
169170
myRow.append( QgsPoint() );
170171
myRow.append( QgsPoint() );
171172
mCPMatrix.insert( i, myRow );
173+
// And the legal points
174+
QList<bool> myLegalRow;
175+
myLegalRow.append( bool( false ) );
176+
myLegalRow.append( bool( false ) );
177+
myLegalRow.append( bool( false ) );
178+
mCPLegalMatrix.insert( i, myLegalRow );
172179
}
173180
for ( int i = 0; i < mCPRows; i++ )
174181
{
@@ -238,7 +245,10 @@ void QgsRasterProjector::calcSrcExtent()
238245
for ( int j = 0; j < mCPCols ; j++ )
239246
{
240247
myPoint = mCPMatrix[i][j];
241-
mSrcExtent.combineExtentWith( myPoint.x(), myPoint.y() );
248+
if ( mCPLegalMatrix[i][j] )
249+
{
250+
mSrcExtent.combineExtentWith( myPoint.x(), myPoint.y() );
251+
}
242252
}
243253
}
244254
// Expand a bit to avoid possible approx coords falling out because of representation error?
@@ -288,7 +298,14 @@ QString QgsRasterProjector::cpToString()
288298
if ( j > 0 )
289299
myString += " ";
290300
QgsPoint myPoint = mCPMatrix[i][j];
291-
myString += myPoint.toString();
301+
if ( mCPLegalMatrix[i][j] )
302+
{
303+
myString += myPoint.toString();
304+
}
305+
else
306+
{
307+
myString += "(-,-)";
308+
}
292309
}
293310
}
294311
return myString;
@@ -316,13 +333,16 @@ void QgsRasterProjector::calcSrcRowsCols()
316333
QgsPoint myPointA = mCPMatrix[i][j];
317334
QgsPoint myPointB = mCPMatrix[i][j+1];
318335
QgsPoint myPointC = mCPMatrix[i+1][j];
319-
double mySize = sqrt( myPointA.sqrDist( myPointB ) ) / myDestColsPerMatrixCell;
320-
if ( mySize < myMinSize )
321-
myMinSize = mySize;
336+
if ( mCPLegalMatrix[i][j] && mCPLegalMatrix[i][j+1] && mCPLegalMatrix[i+1][j] )
337+
{
338+
double mySize = sqrt( myPointA.sqrDist( myPointB ) ) / myDestColsPerMatrixCell;
339+
if ( mySize < myMinSize )
340+
myMinSize = mySize;
322341

323-
mySize = sqrt( myPointA.sqrDist( myPointC ) ) / myDestRowsPerMatrixCell;
324-
if ( mySize < myMinSize )
325-
myMinSize = mySize;
342+
mySize = sqrt( myPointA.sqrDist( myPointC ) ) / myDestRowsPerMatrixCell;
343+
if ( mySize < myMinSize )
344+
myMinSize = mySize;
345+
}
326346
}
327347
}
328348

@@ -517,12 +537,15 @@ void QgsRasterProjector::insertRows()
517537
for ( int r = 0; r < mCPRows - 1; r++ )
518538
{
519539
QList<QgsPoint> myRow;
540+
QList<bool> myLegalRow;
520541
for ( int c = 0; c < mCPCols; c++ )
521542
{
522543
myRow.append( QgsPoint() );
544+
myLegalRow.append( false );
523545
}
524546
QgsDebugMsgLevel( QString( "insert new row at %1" ).arg( 1 + r*2 ), 3 );
525547
mCPMatrix.insert( 1 + r*2, myRow );
548+
mCPLegalMatrix.insert( 1 + r*2, myLegalRow );
526549
}
527550
mCPRows += mCPRows - 1;
528551
for ( int r = 1; r < mCPRows - 1; r += 2 )
@@ -536,9 +559,11 @@ void QgsRasterProjector::insertCols()
536559
for ( int r = 0; r < mCPRows; r++ )
537560
{
538561
QList<QgsPoint> myRow;
562+
QList<bool> myLegalRow;
539563
for ( int c = 0; c < mCPCols - 1; c++ )
540564
{
541565
mCPMatrix[r].insert( 1 + c*2, QgsPoint() );
566+
mCPLegalMatrix[r].insert( 1 + c*2, false );
542567
}
543568
}
544569
mCPCols += mCPCols - 1;
@@ -554,8 +579,17 @@ void QgsRasterProjector::calcCP( int theRow, int theCol )
554579
double myDestX, myDestY;
555580
destPointOnCPMatrix( theRow, theCol, &myDestX, &myDestY );
556581
QgsPoint myDestPoint( myDestX, myDestY );
557-
558-
mCPMatrix[theRow][theCol] = mCoordinateTransform.transform( myDestPoint );
582+
try
583+
{
584+
mCPMatrix[theRow][theCol] = mCoordinateTransform.transform( myDestPoint );
585+
mCPLegalMatrix[theRow][theCol] = true;
586+
}
587+
catch ( QgsCsException &e )
588+
{
589+
Q_UNUSED( e );
590+
// Caught an error in transform
591+
mCPLegalMatrix[theRow][theCol] = true;
592+
}
559593
}
560594

561595
bool QgsRasterProjector::calcRow( int theRow )
@@ -595,6 +629,11 @@ bool QgsRasterProjector::checkCols()
595629
QgsPoint mySrcPoint3 = mCPMatrix[r+1][c];
596630

597631
QgsPoint mySrcApprox(( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, ( mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
632+
if ( !mCPLegalMatrix[r-1][c] || !mCPLegalMatrix[r][c] || !mCPLegalMatrix[r+1][c] )
633+
{
634+
// There was an error earlier in transform, just abort
635+
return false;
636+
}
598637
try
599638
{
600639
QgsPoint myDestApprox = mCoordinateTransform.transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
@@ -630,6 +669,11 @@ bool QgsRasterProjector::checkRows()
630669
QgsPoint mySrcPoint3 = mCPMatrix[r][c+1];
631670

632671
QgsPoint mySrcApprox(( mySrcPoint1.x() + mySrcPoint3.x() ) / 2, ( mySrcPoint1.y() + mySrcPoint3.y() ) / 2 );
672+
if ( !mCPLegalMatrix[r][c-1] || !mCPLegalMatrix[r][c] || !mCPLegalMatrix[r][c+1] )
673+
{
674+
// There was an error earlier in transform, just abort
675+
return false;
676+
}
633677
try
634678
{
635679
QgsPoint myDestApprox = mCoordinateTransform.transform( mySrcApprox, QgsCoordinateTransform::ReverseTransform );

‎src/core/qgsrasterprojector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
213213
/** Grid of source control points */
214214
QList< QList<QgsPoint> > mCPMatrix;
215215

216+
/** Grid of source control points transformation possible indicator */
217+
/* Same size as mCPMatrix */
218+
QList< QList<bool> > mCPLegalMatrix;
219+
216220
/** Array of source points for each destination column on top of current CPMatrix grid row */
217221
/* Warning: using QList is slow on access */
218222
QgsPoint *pHelperTop;

0 commit comments

Comments
 (0)
Please sign in to comment.