33 , mMinimalPreviewInterval( 250 )
38 void QgsRasterLayerRendererFeedback::onNewData()
40 if ( !renderPartialOutput() )
45 if ( mLastPreview.isValid() && mLastPreview.msecsTo( QTime::currentTime() ) < mMinimalPreviewInterval )
50 QgsDebugMsg( QStringLiteral(
"new raster preview! %1" ).arg( mLastPreview.msecsTo( QTime::currentTime() ) ) );
58 drawer.draw( mR->mPainter, mR->mRasterViewPort, mR->mMapToPixel, &feedback );
59 QgsDebugMsg( QStringLiteral(
"total raster preview time: %1 ms" ).arg( t.elapsed() ) );
60 mLastPreview = QTime::currentTime();
67 , mContext( rendererContext )
68 , mFeedback( new QgsRasterLayerRendererFeedback( this ) )
70 mPainter = rendererContext.
painter();
72 mMapToPixel = &qgsMapToPixel;
82 static_cast<int>( mapToPixel.
mapWidth() / 2.0 ),
83 static_cast<int>( mapToPixel.
mapHeight() / 2.0 )
93 QgsDebugMsgLevel( QStringLiteral(
"coordinateTransform set -> project extents." ), 4 );
94 if ( rendererContext.
extent().
xMinimum() == std::numeric_limits<double>::lowest() &&
95 rendererContext.
extent().
yMinimum() == std::numeric_limits<double>::lowest() &&
96 rendererContext.
extent().
xMaximum() == std::numeric_limits<double>::max() &&
97 rendererContext.
extent().
yMaximum() == std::numeric_limits<double>::max() )
104 myProjectedViewExtent = rendererContext.
extent();
132 myProjectedViewExtent = rendererContext.
extent();
133 myProjectedLayerExtent = layer->
extent();
138 if ( myRasterExtent.
isEmpty() )
140 QgsDebugMsg( QStringLiteral(
"draw request outside view extent." ) );
159 mRasterViewPort->mDrawnExtent = myRasterExtent;
162 mRasterViewPort->mSrcCRS = layer->
crs();
182 mRasterViewPort->mTopLeftPoint.
setX( std::floor( mRasterViewPort->mTopLeftPoint.x() ) );
183 mRasterViewPort->mTopLeftPoint.setY( std::floor( mRasterViewPort->mTopLeftPoint.y() ) );
184 mRasterViewPort->mBottomRightPoint.setX( std::ceil( mRasterViewPort->mBottomRightPoint.x() ) );
185 mRasterViewPort->mBottomRightPoint.setY( std::ceil( mRasterViewPort->mBottomRightPoint.y() ) );
189 mRasterViewPort->mBottomRightPoint.y() ),
191 mRasterViewPort->mTopLeftPoint.y() )
195 mRasterViewPort->mWidth =
static_cast<int>( mRasterViewPort->mBottomRightPoint.x() - mRasterViewPort->mTopLeftPoint.x() );
196 mRasterViewPort->mHeight =
static_cast<int>( mRasterViewPort->mBottomRightPoint.y() - mRasterViewPort->mTopLeftPoint.y() );
210 QgsDebugMsgLevel( QStringLiteral(
"mTopLeftPoint.x() = %1" ).arg( mRasterViewPort->mTopLeftPoint.x() ), 3 );
211 QgsDebugMsgLevel( QStringLiteral(
"mBottomRightPoint.x() = %1" ).arg( mRasterViewPort->mBottomRightPoint.x() ), 3 );
212 QgsDebugMsgLevel( QStringLiteral(
"mTopLeftPoint.y() = %1" ).arg( mRasterViewPort->mTopLeftPoint.y() ), 3 );
213 QgsDebugMsgLevel( QStringLiteral(
"mBottomRightPoint.y() = %1" ).arg( mRasterViewPort->mBottomRightPoint.y() ), 3 );
215 QgsDebugMsgLevel( QStringLiteral(
"mWidth = %1" ).arg( mRasterViewPort->mWidth ), 3 );
216 QgsDebugMsgLevel( QStringLiteral(
"mHeight = %1" ).arg( mRasterViewPort->mHeight ), 3 );
237 delete mRasterViewPort;
243 if ( !mRasterViewPort )
269 drawer.draw( mPainter, mRasterViewPort, mMapToPixel, mFeedback );
271 const QStringList
errors = mFeedback->errors();
272 for (
const QString &error : errors )
277 QgsDebugMsgLevel( QStringLiteral(
"total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
int width() const
Returns the width of the (unclipped) raster.
~QgsRasterLayerRenderer() override
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
A rectangle specified with double values.
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
Base class for processing modules.
Iterator for sequentially processing raster cells.
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
QgsRasterRenderer * renderer() const
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QgsRasterPipe * pipe()
Returns the raster pipe.
A class to represent a 2D point.
QgsRasterProjector * projector() const
QgsRasterInterface * last() const
void setRenderPartialOutput(bool enable)
Set whether our painter is drawing to a temporary image used just by this layer.
Flags flags() const
Returns combination of flags used for rendering.
int height() const
Returns the height of the (unclipped) raster.
Implementation of threaded rendering for raster layers.
bool render() override
Do the rendering (based on data stored in the class)
virtual QgsRectangle extent() const
Returns the extent of the layer.
double mapRotation() const
Returns current map rotation in degrees.
QgsCoordinateReferenceSystem mDestCRS
Target coordinate system.
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Perform transforms between map coordinates and device coordinates.
The drawing pipe for raster layers.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
QgsRasterDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
int mapWidth() const
Returns current map width in pixels The information is only known if setRotation was used...
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
int mapHeight() const
Returns current map height in pixels.
void setPreviewOnly(bool preview)
set flag whether the block request is for preview purposes only
#define QgsDebugMsgLevel(str, level)
bool isEmpty() const
Returns true if the rectangle is empty.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
QgsRasterLayerRenderer(QgsRasterLayer *layer, QgsRenderContext &rendererContext)
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
double mapUnitsPerPixel() const
Returns current map units per pixel.
void setX(double x)
Sets the x value of the point.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsCoordinateReferenceSystem mSrcCRS
Source coordinate system.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering...
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsCoordinateTransformContext mTransformContext
Coordinate transform context.
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
This class represents a coordinate reference system (CRS).
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Base class for utility classes that encapsulate information necessary for rendering of map layers...
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QStringList errors() const
Returns list of errors (problems) that happened during the rendering.
void refreshRendererIfNeeded(QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent)
Refresh renderer with new extent, if needed.
Custom exception class for Coordinate Reference System related exceptions.
This class provides details of the viewable area that a raster will be rendered into.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Feedback object tailored for raster block reading.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
Raster renderer pipe that applies colors to a raster.
void setDpi(int dpi)
Sets the output device resolution.
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
QgsCoordinateReferenceSystem crs
Q_DECL_DEPRECATED void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
Sets the source and destination CRS.