@@ -189,14 +189,13 @@ bool QgsRasterLayerProfileGenerator::generateProfile( const QgsProfileGeneration
189
189
subRegionLeft,
190
190
subRegionTop ) : transformedCurve->boundingBox ();
191
191
192
- if ( mRasterProvider ->xSize () == 0 || mRasterProvider ->ySize () == 0 )
192
+ const bool zeroXYSize = mRasterProvider ->xSize () == 0 || mRasterProvider ->ySize () == 0 ;
193
+ if ( zeroXYSize )
193
194
{
194
- // e.g. XYZ tile source -- this is a rough hack for https://github.com/qgis/QGIS/issues/48806, which results
195
- // in pretty poor curves ;)
196
195
const double curveLengthInPixels = sourceCurve->length () / context.mapUnitsPerDistancePixel ();
197
196
const double conversionFactor = curveLengthInPixels / transformedCurve->length ();
198
- subRegionWidth = 2 * conversionFactor * rasterSubRegion.width ();
199
- subRegionHeight = 2 * conversionFactor * rasterSubRegion.height ();
197
+ subRegionWidth = static_cast < int >( std::floor ( rasterSubRegion.width () * conversionFactor ) );
198
+ subRegionHeight = static_cast < int >( std::floor ( rasterSubRegion.height () * conversionFactor ) );
200
199
}
201
200
202
201
// iterate over the raster blocks, throwing away any which don't intersect the profile curve
@@ -248,8 +247,17 @@ bool QgsRasterLayerProfileGenerator::generateProfile( const QgsProfileGeneration
248
247
// convert point to a pixel and sample, if it's in this block
249
248
if ( blockExtent.contains ( *it ) )
250
249
{
251
- const int row = std::clamp ( static_cast < int >( std::round ( ( blockExtent.yMaximum () - it->y () ) / mRasterUnitsPerPixelY ) ), 0 , blockRows - 1 );
252
- const int col = std::clamp ( static_cast < int >( std::round ( ( it->x () - blockExtent.xMinimum () ) / mRasterUnitsPerPixelX ) ), 0 , blockColumns - 1 );
250
+ int row, col;
251
+ if ( zeroXYSize )
252
+ {
253
+ row = std::clamp ( static_cast < int >( std::round ( ( blockExtent.yMaximum () - it->y () ) * blockRows / blockExtent.height () ) ), 0 , blockRows - 1 );
254
+ col = std::clamp ( static_cast < int >( std::round ( ( it->x () - blockExtent.xMinimum () ) * blockColumns / blockExtent.width () ) ), 0 , blockColumns - 1 );
255
+ }
256
+ else
257
+ {
258
+ row = std::clamp ( static_cast < int >( std::round ( ( blockExtent.yMaximum () - it->y () ) / mRasterUnitsPerPixelY ) ), 0 , blockRows - 1 );
259
+ col = std::clamp ( static_cast < int >( std::round ( ( it->x () - blockExtent.xMinimum () ) / mRasterUnitsPerPixelX ) ), 0 , blockColumns - 1 );
260
+ }
253
261
double val = block->valueAndNoData ( row, col, isNoData );
254
262
if ( !isNoData )
255
263
{
0 commit comments