Skip to content

Commit

Permalink
Early resampling: fix requests typical of pixel identification
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault authored and nyalldawson committed Jun 19, 2020
1 parent 47da98c commit d2497c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -958,10 +958,10 @@ bool QgsGdalProvider::readBlock( int bandNo, QgsRectangle const &reqExtent, int
sExtraArg.dfXSize = tgtWidth * reqXRes / srcXRes;
sExtraArg.dfYSize = tgtHeight * reqYRes / -srcYRes;
return GDALRasterIOEx( gdalBand, GF_Read,
std::floor( sExtraArg.dfXOff ),
std::floor( sExtraArg.dfYOff ),
std::floor( sExtraArg.dfXSize ),
std::floor( sExtraArg.dfYSize ),
static_cast<int>( std::floor( sExtraArg.dfXOff ) ),
static_cast<int>( std::floor( sExtraArg.dfYOff ) ),
std::max( 1, static_cast<int>( std::floor( sExtraArg.dfXSize ) ) ),
std::max( 1, static_cast<int>( std::floor( sExtraArg.dfYSize ) ) ),
static_cast<char *>( data ) +
( tgtTop * bufferWidthPix + tgtLeft ) * dataSize,
tgtWidth,
Expand Down
18 changes: 18 additions & 0 deletions tests/src/python/test_qgsrasterresampler.py
Expand Up @@ -564,6 +564,24 @@ def testGDALResampling_nominal_resolution_slightly_overlapping_bottom_edge(self)
# The values in the bottom line are not subject to resampling currently
self.checkRawBlockContents(block, [[65, 100], [70, 190]])

def testGDALResampling_less_than_one_pixel(self):

xmin = 100
ymax = 1000
xres = 5
yres = 5

# Extent is less than one pixel. Simulates pixel identification
extent = QgsRectangle(xmin + 2.25 * xres,
ymax - 4.25 * yres,
xmin + 2.5 * xres,
ymax - 4.5 * yres)

with self.setupGDALResampling() as provider:
provider.setZoomedInResamplingMethod(QgsRasterDataProvider.ResamplingMethod.Bilinear)
block = provider.block(1, extent, 1, 1)
self.checkRawBlockContents(block, [[68]])


if __name__ == '__main__':
unittest.main()

0 comments on commit d2497c8

Please sign in to comment.