@@ -132,6 +132,7 @@ void QgsRasterProjector::calc()
132
132
{
133
133
QgsDebugMsg ( " Entered" );
134
134
mCPMatrix .clear ();
135
+ mCPLegalMatrix .clear ();
135
136
delete[] pHelperTop;
136
137
pHelperTop = 0 ;
137
138
delete[] pHelperBottom;
@@ -169,6 +170,12 @@ void QgsRasterProjector::calc()
169
170
myRow.append ( QgsPoint () );
170
171
myRow.append ( QgsPoint () );
171
172
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 );
172
179
}
173
180
for ( int i = 0 ; i < mCPRows ; i++ )
174
181
{
@@ -238,7 +245,10 @@ void QgsRasterProjector::calcSrcExtent()
238
245
for ( int j = 0 ; j < mCPCols ; j++ )
239
246
{
240
247
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
+ }
242
252
}
243
253
}
244
254
// Expand a bit to avoid possible approx coords falling out because of representation error?
@@ -288,7 +298,14 @@ QString QgsRasterProjector::cpToString()
288
298
if ( j > 0 )
289
299
myString += " " ;
290
300
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
+ }
292
309
}
293
310
}
294
311
return myString;
@@ -316,13 +333,16 @@ void QgsRasterProjector::calcSrcRowsCols()
316
333
QgsPoint myPointA = mCPMatrix [i][j];
317
334
QgsPoint myPointB = mCPMatrix [i][j+1 ];
318
335
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;
322
341
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
+ }
326
346
}
327
347
}
328
348
@@ -517,12 +537,15 @@ void QgsRasterProjector::insertRows()
517
537
for ( int r = 0 ; r < mCPRows - 1 ; r++ )
518
538
{
519
539
QList<QgsPoint> myRow;
540
+ QList<bool > myLegalRow;
520
541
for ( int c = 0 ; c < mCPCols ; c++ )
521
542
{
522
543
myRow.append ( QgsPoint () );
544
+ myLegalRow.append ( false );
523
545
}
524
546
QgsDebugMsgLevel ( QString ( " insert new row at %1" ).arg ( 1 + r*2 ), 3 );
525
547
mCPMatrix .insert ( 1 + r*2 , myRow );
548
+ mCPLegalMatrix .insert ( 1 + r*2 , myLegalRow );
526
549
}
527
550
mCPRows += mCPRows - 1 ;
528
551
for ( int r = 1 ; r < mCPRows - 1 ; r += 2 )
@@ -536,9 +559,11 @@ void QgsRasterProjector::insertCols()
536
559
for ( int r = 0 ; r < mCPRows ; r++ )
537
560
{
538
561
QList<QgsPoint> myRow;
562
+ QList<bool > myLegalRow;
539
563
for ( int c = 0 ; c < mCPCols - 1 ; c++ )
540
564
{
541
565
mCPMatrix [r].insert ( 1 + c*2 , QgsPoint () );
566
+ mCPLegalMatrix [r].insert ( 1 + c*2 , false );
542
567
}
543
568
}
544
569
mCPCols += mCPCols - 1 ;
@@ -554,8 +579,17 @@ void QgsRasterProjector::calcCP( int theRow, int theCol )
554
579
double myDestX, myDestY;
555
580
destPointOnCPMatrix ( theRow, theCol, &myDestX, &myDestY );
556
581
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
+ }
559
593
}
560
594
561
595
bool QgsRasterProjector::calcRow ( int theRow )
@@ -595,6 +629,11 @@ bool QgsRasterProjector::checkCols()
595
629
QgsPoint mySrcPoint3 = mCPMatrix [r+1 ][c];
596
630
597
631
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
+ }
598
637
try
599
638
{
600
639
QgsPoint myDestApprox = mCoordinateTransform .transform ( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
@@ -630,6 +669,11 @@ bool QgsRasterProjector::checkRows()
630
669
QgsPoint mySrcPoint3 = mCPMatrix [r][c+1 ];
631
670
632
671
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
+ }
633
677
try
634
678
{
635
679
QgsPoint myDestApprox = mCoordinateTransform .transform ( mySrcApprox, QgsCoordinateTransform::ReverseTransform );
0 commit comments