@@ -698,8 +698,17 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
698
698
int tmpWidth = srcWidth;
699
699
int tmpHeight = srcHeight;
700
700
701
- if ( xRes > srcXRes ) tmpWidth = width;
702
- if ( yRes > srcYRes ) tmpHeight = height;
701
+ if ( xRes > srcXRes )
702
+ {
703
+ tmpWidth = static_cast <int >( qRound ( srcWidth * srcXRes / xRes ) ) ;
704
+ }
705
+ if ( yRes > srcYRes )
706
+ {
707
+ tmpHeight = static_cast <int >( qRound ( -1 .*srcHeight * srcYRes / yRes ) ) ;
708
+ }
709
+ double tmpXMin = mExtent .xMinimum () + srcLeft * srcXRes;
710
+ double tmpYMax = mExtent .yMaximum () + srcTop * srcYRes;
711
+ QgsDebugMsg ( QString ( " tmpXMin = %1 tmpYMax = %2 tmpWidth = %3 tmpHeight = %4" ).arg ( tmpXMin ).arg ( tmpYMax ).arg ( tmpWidth ).arg ( tmpHeight ) );
703
712
704
713
// Allocate temporary block
705
714
char *tmpBlock = ( char * )malloc ( dataSize * tmpWidth * tmpHeight );
@@ -724,13 +733,9 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
724
733
QgsDebugMsg ( QString ( " GDALRasterIO time (ms): %1" ).arg ( time .elapsed () ) );
725
734
time .start ();
726
735
727
- double tmpXMin = mExtent .xMinimum () + srcLeft * srcXRes;
728
- double tmpYMax = mExtent .yMaximum () + srcTop * srcYRes;
729
736
double tmpXRes = srcWidth * srcXRes / tmpWidth;
730
737
double tmpYRes = srcHeight * srcYRes / tmpHeight; // negative
731
738
732
- QgsDebugMsg ( QString ( " tmpXMin = %1 tmpYMax = %2 tmpWidth = %3 tmpHeight = %4" ).arg ( tmpXMin ).arg ( tmpYMax ).arg ( tmpWidth ).arg ( tmpHeight ) );
733
-
734
739
for ( int row = 0 ; row < height; row++ )
735
740
{
736
741
double y = myRasterExtent.yMaximum () - ( row + 0.5 ) * yRes;
@@ -744,8 +749,6 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
744
749
double x = myRasterExtent.xMinimum () + ( col + 0.5 ) * xRes;
745
750
// floor() is quite slow! Use just cast to int.
746
751
int tmpCol = static_cast <int >(( x - tmpXMin ) / tmpXRes ) ;
747
- // QgsDebugMsg( QString( "row = %1 col = %2 tmpRow = %3 tmpCol = %4" ).arg(row).arg(col).arg(tmpRow).arg(tmpCol) );
748
-
749
752
char *src = srcRowBlock + dataSize * tmpCol;
750
753
char *dst = dstRowBlock + dataSize * ( left + col );
751
754
memcpy ( dst, src, dataSize );
0 commit comments