35#include <QElapsedTimer> 
   43  , mMinimalPreviewInterval( 250 )
 
   48void QgsRasterLayerRendererFeedback::onNewData()
 
   50  if ( !renderPartialOutput() )
 
   55  if ( mLastPreview.isValid() && mLastPreview.msecsTo( QTime::currentTime() ) < mMinimalPreviewInterval )
 
   60  QgsDebugMsgLevel( QStringLiteral( 
"new raster preview! %1" ).arg( mLastPreview.msecsTo( QTime::currentTime() ) ), 3 );
 
   68  drawer.draw( *( mR->renderContext() ), mR->mRasterViewPort, &feedback );
 
   69  mR->mReadyToCompose = 
true;
 
   70  QgsDebugMsgLevel( QStringLiteral( 
"total raster preview time: %1 ms" ).arg( t.elapsed() ), 3 );
 
   71  mLastPreview = QTime::currentTime();
 
   78  , mLayerOpacity( layer->opacity() )
 
   79  , mProviderCapabilities( static_cast<
QgsRasterDataProvider::Capability>( layer->dataProvider()->capabilities() ) )
 
   80  , mFeedback( new QgsRasterLayerRendererFeedback( this ) )
 
   91                                static_cast<int>( mapToPixel.
mapWidth() / 2.0 ),
 
   92                                static_cast<int>( mapToPixel.
mapHeight() / 2.0 )
 
  102    QgsDebugMsgLevel( QStringLiteral( 
"coordinateTransform set -> project extents." ), 4 );
 
  103    if ( rendererContext.
extent().
xMinimum() == std::numeric_limits<double>::lowest() &&
 
  104         rendererContext.
extent().
yMinimum() == std::numeric_limits<double>::lowest() &&
 
  105         rendererContext.
extent().
xMaximum() == std::numeric_limits<double>::max() &&
 
  106         rendererContext.
extent().
yMaximum() == std::numeric_limits<double>::max() )
 
  113      myProjectedViewExtent = rendererContext.
extent();
 
  145    myProjectedViewExtent = rendererContext.
extent();
 
  146    myProjectedLayerExtent = layer->
extent();
 
  151  if ( myRasterExtent.
isEmpty() )
 
  153    QgsDebugMsgLevel( QStringLiteral( 
"draw request outside view extent." ), 2 );
 
  211  const double dpi = 25.4 * rendererContext.
scaleFactor();
 
  215    const double dpiScaleFactor = rendererContext.
dpiTarget() / dpi;
 
  216    mRasterViewPort->
mWidth *= dpiScaleFactor;
 
  217    mRasterViewPort->
mHeight *= dpiScaleFactor;
 
  268    switch ( temporalProperties->
mode() )
 
  270      case Qgis::RasterTemporalMode::FixedTemporalRange:
 
  271      case Qgis::RasterTemporalMode::RedrawLayerOnly:
 
  274      case Qgis::RasterTemporalMode::TemporalRangeFromDataProvider:
 
  276        if ( mPipe->provider()->temporalCapabilities() )
 
  278          mPipe->provider()->temporalCapabilities()->setRequestedTemporalRange( rendererContext.
temporalRange() );
 
  279          mPipe->provider()->temporalCapabilities()->setIntervalHandlingMethod( temporalProperties->
intervalHandlingMethod() );
 
  284  else if ( mPipe->provider()->temporalCapabilities() )
 
  286    mPipe->provider()->temporalCapabilities()->setRequestedTemporalRange( QgsDateTimeRange() );
 
  287    mPipe->provider()->temporalCapabilities()->setIntervalHandlingMethod( temporalProperties->
intervalHandlingMethod() );
 
  296    mDrawElevationMap = 
true;
 
  297    mElevationScale = elevProp->
zScale();
 
  298    mElevationOffset = elevProp->
zOffset();
 
  302  mFeedback->setRenderContext( rendererContext );
 
  304  mPipe->moveToThread( 
nullptr );
 
  311  delete mRasterViewPort;
 
  318                             !( mProviderCapabilities &
 
  319                                QgsRasterInterface::Capability::Prefetch ) ) )
 
  322  mPipe->moveToThread( QThread::currentThread() );
 
  334  if ( !mClippingRegions.empty() )
 
  336    bool needsPainterClipPath = 
false;
 
  338    if ( needsPainterClipPath )
 
  343  bool restoreOldResamplingStage = 
false;
 
  355      restoreOldResamplingStage = 
true;
 
  369  if ( mDrawElevationMap )
 
  372  if ( restoreOldResamplingStage )
 
  374    mPipe->setResamplingStage( oldResamplingState );
 
  377  const QStringList 
errors = mFeedback->errors();
 
  378  for ( 
const QString &error : 
errors )
 
  383  QgsDebugMsgLevel( QStringLiteral( 
"total raster draw time (ms):     %1" ).arg( time.elapsed(), 5 ), 4 );
 
  386  mPipe->moveToThread( 
nullptr );
 
  388  return !mFeedback->isCanceled();
 
  398  if ( !mRasterViewPort || !mPipe )
 
  415void QgsRasterLayerRenderer::drawElevationMap()
 
  420    double dpiScalefactor;
 
  425      dpiScalefactor = 1.0;
 
  427    int outputWidth = 
static_cast<int>( 
static_cast<double>( mRasterViewPort->
mWidth )  / dpiScalefactor ) ;
 
  428    int outputHeight =  
static_cast<int>( 
static_cast<double>( mRasterViewPort->
mHeight ) / dpiScalefactor );
 
  431    int viewWidth =  
static_cast<int>( viewSize.width() / dpiScalefactor );
 
  432    int viewHeight =  
static_cast<int>( viewSize.height() / dpiScalefactor );
 
  434    bool canRenderElevation = 
false;
 
  435    std::unique_ptr<QgsRasterBlock> elevationBlock;
 
  438      elevationBlock.reset(
 
  445      canRenderElevation = 
true;
 
  455      if ( viewExtentInLayerCoordinate.
xMinimum() == std::numeric_limits<double>::lowest() &&
 
  456           viewExtentInLayerCoordinate.
yMinimum() == std::numeric_limits<double>::lowest() &&
 
  457           viewExtentInLayerCoordinate.
xMaximum() == std::numeric_limits<double>::max() &&
 
  458           viewExtentInLayerCoordinate.
yMaximum() == std::numeric_limits<double>::max() )
 
  460        viewExtentInLayerCoordinate = dataProvider->
extent();
 
  463      double xLayerResol = viewExtentInLayerCoordinate.
width() / 
static_cast<double>( viewWidth );
 
  464      double yLayerResol = viewExtentInLayerCoordinate.
height() / 
static_cast<double>( viewHeight );
 
  466      double overSampling = 1;
 
  467      if ( mPipe->resampleFilter() )
 
  468        overSampling = mPipe->resampleFilter()->maxOversampling();
 
  473        double providerXResol = dataProvider->
extent().
width() / dataProvider->
xSize();
 
  475        overSampling = ( xLayerResol / providerXResol + yLayerResol / providerYResol ) / 2;
 
  479      if ( overSampling > 1 )
 
  489        int sourceWidth = viewWidth + 4;
 
  490        int sourceHeight = viewHeight + 4;
 
  492                                        viewExtentInLayerCoordinate.
xMinimum() - xLayerResol * 2,
 
  493                                        viewExtentInLayerCoordinate.
yMinimum() - yLayerResol * 2,
 
  494                                        viewExtentInLayerCoordinate.
xMaximum() + xLayerResol * 2,
 
  495                                        viewExtentInLayerCoordinate.
yMaximum() + yLayerResol * 2 );
 
  498        std::unique_ptr<QgsRasterBlock> sourcedata( dataProvider->
block( mElevationBand, viewExtentInLayerCoordinate, sourceWidth, sourceHeight, mFeedback ) );
 
  507        elevationBlock->setNoDataValue( dataProvider->
sourceNoDataValue( mElevationBand ) );
 
  514        QString coordinateOperation;
 
  521        if ( coordinateOperation.isEmpty() )
 
  526                               coordinateOperation.toUtf8().constData() );
 
  530    if ( canRenderElevation )
 
  544        int top = elevMapHeight;
 
  545        int left = elevMapWidth;
 
  548        QList<QgsPointXY> corners;
 
  554        for ( 
const QgsPointXY &corner : std::as_const( corners ) )
 
  557          int x = 
static_cast<int>( std::round( dpt.
x() ) );
 
  558          int y = 
static_cast<int>( std::round( dpt.
y() ) );
 
  578        std::unique_ptr<QgsRasterBlock> rotatedElevationBlock =
 
  579          std::make_unique<QgsRasterBlock>( elevationBlock->dataType(), right - left + 1, bottom - top + 1 );
 
  581        rotatedElevationBlock->setNoDataValue( elevationBlock->noDataValue() );
 
  591          elevationBlock.reset( rotatedElevationBlock.release() );
 
  594        topLeft = QPoint( left, top );
 
  602        elevationBlock.get(),
 
RasterResamplingStage
Stage at which raster resampling occurs.
 
@ Provider
Resampling occurs in Provider.
 
@ InternalLayerOpacityHandling
The renderer internally handles the raster layer's opacity, so the default layer level opacity handli...
 
DataType
Raster data types.
 
@ UnknownDataType
Unknown or unspecified type.
 
@ RenderPreviewJob
Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering.
 
@ RenderPartialOutput
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
 
@ Render3DMap
Render is for a 3D map.
 
@ UseAdvancedEffects
Enable layer opacity and blending effects.
 
This class represents a coordinate reference system (CRS).
 
Contains information about the context in which a coordinate transform is executed.
 
QString calculateCoordinateOperation(const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination) const
Returns the Proj coordinate operation string to use when transforming from the specified source CRS t...
 
bool mustReverseCoordinateOperation(const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination) const
Returns true if the coordinate operation returned by calculateCoordinateOperation() for the source to...
 
Custom exception class for Coordinate Reference System related exceptions.
 
Stores digital elevation model in a raster image which may get updated as a part of map layer renderi...
 
QImage rawElevationImage() const
Returns raw elevation image with elevations encoded as color values.
 
void fillWithRasterBlock(QgsRasterBlock *block, int top, int left, double zScale=1.0, double offset=0.0)
Fills the elevation map with values contains in a raster block starting from position defined by top ...
 
Base class for feedback objects to be used for cancellation of something running in a worker thread.
 
static GDALResampleAlg gdalResamplingAlgorithm(QgsRasterDataProvider::ResamplingMethod method)
Returns the GDAL resampling method corresponding to the QGIS resampling method.
 
static bool resampleSingleBandRaster(GDALDatasetH hSrcDS, GDALDatasetH hDstDS, GDALResampleAlg resampleAlg, const char *pszCoordinateOperation)
Resamples a single band raster to the destination dataset with different resolution (and possibly wit...
 
static gdal::dataset_unique_ptr blockToSingleBandMemoryDataset(int pixelWidth, int pixelHeight, const QgsRectangle &extent, void *block, GDALDataType dataType)
Converts a data block to a single band GDAL memory dataset.
 
static QPainterPath calculatePainterClipRegion(const QList< QgsMapClippingRegion > ®ions, const QgsRenderContext &context, Qgis::LayerType layerType, bool &shouldClip)
Returns a QPainterPath representing the intersection of clipping regions from context which should be...
 
static QList< QgsMapClippingRegion > collectClippingRegionsForLayer(const QgsRenderContext &context, const QgsMapLayer *layer)
Collects the list of map clipping regions from a context which apply to a map layer.
 
double zScale() const
Returns the z scale, which is a scaling factor which should be applied to z values from the layer.
 
virtual bool hasElevation() const
Returns true if the layer has an elevation or z component.
 
double zOffset() const
Returns the z offset, which is a fixed offset amount which should be added to z values from the layer...
 
Base class for utility classes that encapsulate information necessary for rendering of map layers.
 
bool mReadyToCompose
The flag must be set to false in renderer's constructor if wants to use the smarter map redraws funct...
 
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
 
QStringList errors() const
Returns list of errors (problems) that happened during the rendering.
 
virtual QgsRectangle extent() const
Returns the extent of the layer.
 
QgsCoordinateReferenceSystem crs
 
void statusChanged(const QString &status)
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)
 
Perform transforms between map coordinates and device coordinates.
 
int mapHeight() const
Returns current map height in pixels.
 
void setMapRotation(double degrees, double cx, double cy)
Sets map rotation in degrees (clockwise).
 
double mapUnitsPerPixel() const
Returns the current map units per pixel.
 
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
 
int mapWidth() const
Returns the current map width in pixels.
 
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
 
double mapRotation() const
Returns the current map rotation in degrees (clockwise).
 
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
 
A class to represent a 2D point.
 
void setX(double x) SIP_HOLDGIL
Sets the x value of the point.
 
double distance(double x, double y) const SIP_HOLDGIL
Returns the distance between this point and a specified x, y coordinate.
 
void setY(double y) SIP_HOLDGIL
Sets the y value of the point.
 
QPointF toQPointF() const
Converts a point to a QPointF.
 
Feedback object tailored for raster block reading.
 
void setPreviewOnly(bool preview)
set flag whether the block request is for preview purposes only
 
void setRenderPartialOutput(bool enable)
Set whether our painter is drawing to a temporary image used just by this layer.
 
Base class for raster data providers.
 
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
 
ResamplingMethod zoomedOutResamplingMethod() const
Returns resampling method for zoomed-out operations.
 
void setDpi(int dpi)
Sets the output device resolution.
 
QgsRectangle extent() const override=0
Returns the extent of the layer.
 
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
 
@ ProviderHintCanPerformProviderResampling
Provider can perform resampling (to be opposed to post rendering resampling) (since QGIS 3....
 
QgsRasterBlock * block(int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
 
void statusChanged(const QString &) const
Emit a message to be displayed on status bar, usually used by network providers (WMS,...
 
ResamplingMethod zoomedInResamplingMethod() const
Returns resampling method for zoomed-in operations.
 
The drawing pipe for raster layers.
 
void draw(QPainter *p, QgsRasterViewPort *viewPort, const QgsMapToPixel *qgsMapToPixel, QgsRasterBlockFeedback *feedback=nullptr)
Draws raster data.
 
@ Size
Original data source size (and thus resolution) is known, it is not always available,...
 
virtual int xSize() const
Gets raster size.
 
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
 
virtual int ySize() const
 
Iterator for sequentially processing raster cells.
 
Raster layer specific subclass of QgsMapLayerElevationProperties.
 
int bandNumber() const
Returns the band number from which the elevation should be taken.
 
Implementation of threaded rendering for raster layers.
 
bool render() override
Do the rendering (based on data stored in the class).
 
QgsRasterLayerRenderer(QgsRasterLayer *layer, QgsRenderContext &rendererContext)
 
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
 
~QgsRasterLayerRenderer() override
 
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
 
Implementation of map layer temporal properties for raster layers.
 
Qgis::TemporalIntervalMatchMethod intervalHandlingMethod() const
Returns the desired method to use when resolving a temporal interval to matching layers or bands in t...
 
Qgis::RasterTemporalMode mode() const
Returns the temporal properties mode.
 
Represents a raster layer.
 
int height() const
Returns the height of the (unclipped) raster.
 
void refreshRendererIfNeeded(QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent)
Refresh renderer with new extent, if needed.
 
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
 
QgsRasterPipe * pipe()
Returns the raster pipe.
 
bool ignoreExtents() const
If the ignoreExtent flag is set, the layer will also render outside the bounding box reported by the ...
 
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
 
int width() const
Returns the width of the (unclipped) raster.
 
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
 
Contains a pipeline of raster interfaces for sequential raster processing.
 
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
 
Q_DECL_DEPRECATED void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
Sets the source and destination CRS.
 
Raster renderer pipe that applies colors to a raster.
 
A rectangle specified with double values.
 
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
 
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
 
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
 
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
 
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
 
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
 
void set(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Sets the rectangle from two QgsPoints.
 
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
 
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
 
bool isEmpty() const
Returns true if the rectangle is empty.
 
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
 
Contains information about the context of a rendering operation.
 
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
 
QPainter * painter()
Returns the destination QPainter for the render operation.
 
QgsExpressionContext & expressionContext()
Gets the expression context.
 
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
 
QgsElevationMap * elevationMap() const
Returns the destination elevation map for the render operation.
 
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
 
bool testFlag(Qgis::RenderContextFlag flag) const
Check whether a particular flag is enabled.
 
void setDpiTarget(double dpi)
Sets the targeted dpi for rendering.
 
double dpiTarget() const
Returns the targeted DPI for rendering.
 
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
 
QSize deviceOutputSize() const
Returns the device output size of the render.
 
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
 
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
 
Scoped object for saving and restoring a QPainter object's state.
 
bool isActive() const
Returns true if the temporal property is active.
 
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
 
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
 
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
 
#define QgsDebugMsgLevel(str, level)
 
This class provides details of the viewable area that a raster will be rendered into.
 
qgssize mHeight
Height, number of rows to be rendered.
 
QgsCoordinateReferenceSystem mDestCRS
Target coordinate system.
 
QgsPointXY mBottomRightPoint
Coordinate (in output device coordinate system) of bottom right corner of the part of the raster that...
 
QgsPointXY mTopLeftPoint
Coordinate (in output device coordinate system) of top left corner of the part of the raster that is ...
 
QgsCoordinateReferenceSystem mSrcCRS
Source coordinate system.
 
QgsRectangle mDrawnExtent
Intersection of current map extent and layer extent.
 
QgsCoordinateTransformContext mTransformContext
Coordinate transform context.
 
qgssize mWidth
Width, number of columns to be rendered.