QGIS API Documentation 4.1.0-Master (31622b25bb0)
Loading...
Searching...
No Matches
qgspointcloudrenderer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspointcloudrenderer.cpp
3 --------------------
4 begin : October 2020
5 copyright : (C) 2020 by Peter Petrik
6 email : zilolv at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include "qgsapplication.h"
21#include "qgscircle.h"
22#include "qgselevationmap.h"
23#include "qgsexpression.h"
25#include "qgslogger.h"
26#include "qgspointcloudindex.h"
27#include "qgspointcloudlayer.h"
29#include "qgssymbollayerutils.h"
30#include "qgsunittypes.h"
31
32#include <QPointer>
33#include <QString>
34#include <QThread>
35
36using namespace Qt::StringLiterals;
37
38QgsPropertiesDefinition QgsPointCloudRenderer::sPropertyDefinitions;
39
41 : mRenderContext( context )
42 , mScale( scale )
43 , mOffset( offset )
44 , mZValueScale( zValueScale )
45 , mZValueFixedOffset( zValueFixedOffset )
46 , mFeedback( feedback )
47{}
48
50{
51 return mPointsRendered;
52}
53
55{
56 mPointsRendered += count;
57}
58
60{
61 mAttributes = attributes;
62 mPointRecordSize = mAttributes.pointRecordSize();
63
64 // fetch offset for x/y/z attributes
65 attributes.find( u"X"_s, mXOffset );
66 attributes.find( u"Y"_s, mYOffset );
67 attributes.find( u"Z"_s, mZOffset );
68}
69
71{
73 QgsTextBufferSettings settings;
74 settings.setEnabled( true );
75 settings.setSize( 1 );
76 textFormat.setBuffer( settings );
77 mLabelTextFormat = std::move( textFormat );
78 mElevationShadingRenderer.setActiveEyeDomeLighting( false ); // we explicitly set shader effects to false, in case some are turned on by default
79 mElevationShadingRenderer.setActiveHillshading( false );
80}
81
83{
84 if ( element.isNull() )
85 return nullptr;
86
87 // load renderer
88 const QString rendererType = element.attribute( u"type"_s );
89
91 if ( !m )
92 return nullptr;
93
94 std::unique_ptr< QgsPointCloudRenderer > r( m->createRenderer( element, context ) );
95 return r.release();
96}
97
99{
100 QSet<QString> res;
101 if ( mDataDefinedProperties.hasActiveProperties() )
102 {
103 res = mDataDefinedProperties.referencedVariables();
104 }
105 return res;
106}
107
108std::unique_ptr<QgsPreparedPointCloudRendererData> QgsPointCloudRenderer::prepare()
109{
110 return nullptr;
111}
112
114{
115#ifdef QGISDEBUG
116 if ( !mThread )
117 {
118 mThread = QThread::currentThread();
119 }
120 else
121 {
122 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsPointCloudRenderer::startRender", "startRender called in a different thread - use a cloned renderer instead" );
123 }
124#endif
125
126 mDefaultPainterPenWidth = context.renderContext().convertToPainterUnits( pointSize(), pointSizeUnit(), pointSizeMapUnitScale() );
127
128 switch ( mPointSymbol )
129 {
131 // for square point we always disable antialiasing -- it's not critical here and we benefit from the performance boost disabling it gives
132 context.renderContext().painter()->setRenderHint( QPainter::Antialiasing, false );
133 break;
134
136 break;
137 }
138
139 mDataDefinedProperties.prepare( context.renderContext().expressionContext() );
140
141 if ( mDataDefinedProperties.hasActiveProperties() )
142 {
143 mExpressionContextScope = std::make_unique<QgsExpressionContextScope>();
144 context.renderContext().expressionContext().appendScope( mExpressionContextScope.get() );
145 }
146}
147
149{
150#ifdef QGISDEBUG
151 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsPointCloudRenderer::stopRender", "stopRender called in a different thread - use a cloned renderer instead" );
152#endif
153
154 if ( mExpressionContextScope )
155 {
157 mExpressionContextScope.reset();
158 }
159}
160
162{
163 return false;
164}
165
166void QgsPointCloudRenderer::checkLegendItem( const QString &, bool )
167{}
168
170{
171 return mMaximumScreenError;
172}
173
175{
176 mMaximumScreenError = error;
177}
178
180{
181 mOverviewSwitchingScale = scale;
182}
183
185{
186 return mMaximumScreenErrorUnit;
187}
188
190{
191 mMaximumScreenErrorUnit = unit;
192}
193
194QList<QgsLayerTreeModelLegendNode *> QgsPointCloudRenderer::createLegendNodes( QgsLayerTreeLayer * )
195{
196 return QList<QgsLayerTreeModelLegendNode *>();
197}
198
200{
201 return QStringList();
202}
203
204void QgsPointCloudRenderer::drawPointToElevationMap( double x, double y, double z, QgsPointCloudRenderContext &context ) const
205{
206 drawPointToElevationMap( x, y, z, mDefaultPainterPenWidth, context );
207}
208
209void QgsPointCloudRenderer::drawPointToElevationMap( double x, double y, double z, int width, QgsPointCloudRenderContext &context ) const
210{
211 const QPointF originalXY( x, y );
212 context.renderContext().mapToPixel().transformInPlace( x, y );
213 QPainter *elevationPainter = context.renderContext().elevationMap()->painter();
214
215 QBrush brush( QgsElevationMap::encodeElevation( z ) );
216 switch ( mPointSymbol )
217 {
219 elevationPainter->fillRect( QRectF( x - width * 0.5, y - width * 0.5, width, width ), brush );
220 break;
221
223 elevationPainter->setBrush( brush );
224 elevationPainter->setPen( Qt::NoPen );
225 elevationPainter->drawEllipse( QRectF( x - width * 0.5, y - width * 0.5, width, width ) );
226 break;
227 };
228}
229
231{
232 destination->setPointSize( mPointSize );
233 destination->setPointSizeUnit( mPointSizeUnit );
234 destination->setPointSizeMapUnitScale( mPointSizeMapUnitScale );
235 destination->setMaximumScreenError( mMaximumScreenError );
236 destination->setMaximumScreenErrorUnit( mMaximumScreenErrorUnit );
237 destination->setPointSymbol( mPointSymbol );
238 destination->setDrawOrder2d( mDrawOrder2d );
239
240 destination->setRenderAsTriangles( mRenderAsTriangles );
241 destination->setHorizontalTriangleFilter( mHorizontalTriangleFilter );
242 destination->setHorizontalTriangleFilterThreshold( mHorizontalTriangleFilterThreshold );
243 destination->setHorizontalTriangleFilterUnit( mHorizontalTriangleFilterUnit );
244
245 destination->setShowLabels( mShowLabels );
246 destination->setLabelTextFormat( mLabelTextFormat );
247 destination->setZoomOutBehavior( mZoomOutBehavior );
248 destination->setOverviewSwitchingScale( mOverviewSwitchingScale );
249 destination->setElevationShadingRenderer( mElevationShadingRenderer );
250 destination->setDataDefinedProperties( mDataDefinedProperties );
251}
252
253void QgsPointCloudRenderer::restoreCommonProperties( const QDomElement &element, const QgsReadWriteContext &context )
254{
255 mPointSize = element.attribute( u"pointSize"_s, u"1"_s ).toDouble();
256 mPointSizeUnit = QgsUnitTypes::decodeRenderUnit( element.attribute( u"pointSizeUnit"_s, u"MM"_s ) );
257 mPointSizeMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( element.attribute( u"pointSizeMapUnitScale"_s, QString() ) );
258
259 mMaximumScreenError = element.attribute( u"maximumScreenError"_s, u"0.3"_s ).toDouble();
260 mMaximumScreenErrorUnit = QgsUnitTypes::decodeRenderUnit( element.attribute( u"maximumScreenErrorUnit"_s, u"MM"_s ) );
261 mPointSymbol = static_cast< Qgis::PointCloudSymbol >( element.attribute( u"pointSymbol"_s, u"0"_s ).toInt() );
262 mDrawOrder2d = static_cast< Qgis::PointCloudDrawOrder >( element.attribute( u"drawOrder2d"_s, u"0"_s ).toInt() );
263
264 mRenderAsTriangles = element.attribute( u"renderAsTriangles"_s, u"0"_s ).toInt();
265 mHorizontalTriangleFilter = element.attribute( u"horizontalTriangleFilter"_s, u"0"_s ).toInt();
266 mHorizontalTriangleFilterThreshold = element.attribute( u"horizontalTriangleFilterThreshold"_s, u"5"_s ).toDouble();
267 mHorizontalTriangleFilterUnit = QgsUnitTypes::decodeRenderUnit( element.attribute( u"horizontalTriangleFilterUnit"_s, u"MM"_s ) );
268
269 mShowLabels = element.attribute( u"showLabels"_s, u"0"_s ).toInt();
270 if ( !element.firstChildElement( u"text-style"_s ).isNull() )
271 {
272 mLabelTextFormat = QgsTextFormat();
273 mLabelTextFormat.readXml( element.firstChildElement( u"text-style"_s ), context );
274 }
275 mZoomOutBehavior = qgsEnumKeyToValue( element.attribute( u"zoomOutBehavior"_s ), Qgis::PointCloudZoomOutRenderBehavior::RenderExtents );
276 mOverviewSwitchingScale = element.attribute( u"overviewSwitchingScale"_s, u"1.0"_s ).toDouble();
277
278 const QDomNode elevationShadingNode = element.namedItem( u"elevation-shading-renderer"_s );
279 if ( !elevationShadingNode.isNull() )
280 {
281 mElevationShadingRenderer.readXml( elevationShadingNode.toElement(), context );
282 }
283 const QDomElement ddElem = element.firstChildElement( u"dataDefinedProperties"_s );
284 if ( !ddElem.isNull() )
285 mDataDefinedProperties.readXml( ddElem, propertyDefinitions() );
286}
287
288void QgsPointCloudRenderer::saveCommonProperties( QDomElement &element, const QgsReadWriteContext &context ) const
289{
290 element.setAttribute( u"pointSize"_s, qgsDoubleToString( mPointSize ) );
291 element.setAttribute( u"pointSizeUnit"_s, QgsUnitTypes::encodeUnit( mPointSizeUnit ) );
292 element.setAttribute( u"pointSizeMapUnitScale"_s, QgsSymbolLayerUtils::encodeMapUnitScale( mPointSizeMapUnitScale ) );
293
294 element.setAttribute( u"maximumScreenError"_s, qgsDoubleToString( mMaximumScreenError ) );
295 element.setAttribute( u"maximumScreenErrorUnit"_s, QgsUnitTypes::encodeUnit( mMaximumScreenErrorUnit ) );
296 element.setAttribute( u"pointSymbol"_s, QString::number( static_cast< int >( mPointSymbol ) ) );
297 element.setAttribute( u"drawOrder2d"_s, QString::number( static_cast< int >( mDrawOrder2d ) ) );
298
299 element.setAttribute( u"renderAsTriangles"_s, QString::number( static_cast< int >( mRenderAsTriangles ) ) );
300 element.setAttribute( u"horizontalTriangleFilter"_s, QString::number( static_cast< int >( mHorizontalTriangleFilter ) ) );
301 element.setAttribute( u"horizontalTriangleFilterThreshold"_s, qgsDoubleToString( mHorizontalTriangleFilterThreshold ) );
302 element.setAttribute( u"horizontalTriangleFilterUnit"_s, QgsUnitTypes::encodeUnit( mHorizontalTriangleFilterUnit ) );
303
304 if ( mShowLabels )
305 element.setAttribute( u"showLabels"_s, u"1"_s );
306 if ( mLabelTextFormat.isValid() )
307 {
308 QDomDocument doc = element.ownerDocument();
309 element.appendChild( mLabelTextFormat.writeXml( doc, context ) );
310 }
312 {
313 element.setAttribute( u"zoomOutBehavior"_s, qgsEnumValueToKey( mZoomOutBehavior ) );
314 }
315 if ( mOverviewSwitchingScale != 1.0 )
316 {
317 element.setAttribute( u"overviewSwitchingScale"_s, qgsDoubleToString( mOverviewSwitchingScale ) );
318 }
319
320 QDomDocument doc = element.ownerDocument();
321 QDomElement elevationShadingNode = doc.createElement( u"elevation-shading-renderer"_s );
322 mElevationShadingRenderer.writeXml( elevationShadingNode, context );
323 element.appendChild( elevationShadingNode );
324
325 QDomElement ddElem = doc.createElement( u"dataDefinedProperties"_s );
326 mDataDefinedProperties.writeXml( ddElem, propertyDefinitions() );
327 element.appendChild( ddElem );
328}
329
331{
332 return mPointSymbol;
333}
334
336{
337 mPointSymbol = symbol;
338}
339
341{
342 return mDrawOrder2d;
343}
344
346{
347 mDrawOrder2d = order;
348}
349
350void QgsPointCloudRenderer::initPropertyDefinitions()
351{
352 if ( !sPropertyDefinitions.isEmpty() )
353 return;
354
355 sPropertyDefinitions = {
356 { static_cast<int>( QgsPointCloudRenderer::Property::Color ), QgsPropertyDefinition( "colorExpression", QObject::tr( "Color expression" ), QgsPropertyDefinition::ColorWithAlpha ) },
357 };
358}
359
361{
362 QgsPointCloudRenderer::initPropertyDefinitions();
363 return sPropertyDefinitions;
364}
365
366QVector<QVariantMap> QgsPointCloudRenderer::identify( QgsPointCloudLayer *layer, const QgsRenderContext &renderContext, const QgsGeometry &geometry, double toleranceForPointIdentification )
367{
368 QVector<QVariantMap> selectedPoints;
369
370 const double maxErrorPixels = renderContext.convertToPainterUnits( maximumScreenError(), maximumScreenErrorUnit() ); // in pixels
371
372 const QgsRectangle layerExtentLayerCoords = layer->dataProvider()->extent();
373 QgsRectangle layerExtentMapCoords = layerExtentLayerCoords;
374 if ( !renderContext.coordinateTransform().isShortCircuited() )
375 {
376 try
377 {
378 QgsCoordinateTransform extentTransform = renderContext.coordinateTransform();
379 extentTransform.setBallparkTransformsAreAppropriate( true );
380 layerExtentMapCoords = extentTransform.transformBoundingBox( layerExtentLayerCoords );
381 }
382 catch ( QgsCsException & )
383 {
384 QgsDebugError( u"Could not transform node extent to map CRS"_s );
385 }
386 }
387
388 const double mapUnitsPerPixel = renderContext.mapToPixel().mapUnitsPerPixel();
389 if ( ( mapUnitsPerPixel < 0.0 ) || ( maxErrorPixels < 0.0 ) )
390 {
391 QgsDebugError( u"invalid screen error"_s );
392 return selectedPoints;
393 }
394
395 const double maxErrorInMapCoordinates = maxErrorPixels * mapUnitsPerPixel;
396 const double maxErrorInLayerCoordinates = maxErrorInMapCoordinates * layerExtentLayerCoords.width() / layerExtentMapCoords.width();
397
398 QgsGeometry selectionGeometry = geometry;
399 if ( geometry.type() == Qgis::GeometryType::Point )
400 {
401 const double x = geometry.asPoint().x();
402 const double y = geometry.asPoint().y();
403 const double toleranceInPixels = toleranceForPointIdentification / renderContext.mapToPixel().mapUnitsPerPixel();
404 const double pointSizePixels = renderContext.convertToPainterUnits( mPointSize, mPointSizeUnit, mPointSizeMapUnitScale );
405 switch ( pointSymbol() )
406 {
408 {
409 const QgsPointXY deviceCoords = renderContext.mapToPixel().transform( QgsPointXY( x, y ) );
410 const QgsPointXY point1( deviceCoords.x() - std::max( toleranceInPixels, pointSizePixels / 2.0 ), deviceCoords.y() - std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
411 const QgsPointXY point2( deviceCoords.x() + std::max( toleranceInPixels, pointSizePixels / 2.0 ), deviceCoords.y() + std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
412 const QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
413 const QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
414 const QgsRectangle pointRect( point1MapCoords, point2MapCoords );
415 selectionGeometry = QgsGeometry::fromRect( pointRect );
416 break;
417 }
419 {
420 const QgsPoint centerMapCoords( x, y );
421 const QgsPointXY deviceCoords = renderContext.mapToPixel().transform( centerMapCoords );
422 const QgsPoint point1( deviceCoords.x(), deviceCoords.y() - std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
423 const QgsPoint point2( deviceCoords.x(), deviceCoords.y() + std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
424 const QgsPointXY point1MapCoords = renderContext.mapToPixel().toMapCoordinates( point1.x(), point1.y() );
425 const QgsPointXY point2MapCoords = renderContext.mapToPixel().toMapCoordinates( point2.x(), point2.y() );
426 const QgsCircle circle = QgsCircle::from2Points( QgsPoint( point1MapCoords ), QgsPoint( point2MapCoords ) );
427 std::unique_ptr<QgsPolygon> polygon( circle.toPolygon( 6 ) );
428 const QgsGeometry circleGeometry( std::move( polygon ) );
429 selectionGeometry = circleGeometry;
430 break;
431 }
432 }
433 }
434
435 // selection geometry must be in layer CRS for QgsPointCloudDataProvider::identify
436 try
437 {
438 selectionGeometry.transform( renderContext.coordinateTransform(), Qgis::TransformDirection::Reverse );
439 }
440 catch ( QgsCsException & )
441 {
442 QgsDebugError( u"Could not transform geometry to layer CRS"_s );
443 return selectedPoints;
444 }
445
446 selectedPoints = layer->dataProvider()->identify( maxErrorInLayerCoordinates, selectionGeometry, renderContext.zRange() );
447
448 selectedPoints.erase( std::remove_if( selectedPoints.begin(), selectedPoints.end(), [this]( const QMap<QString, QVariant> &point ) { return !this->willRenderPoint( point ); } ), selectedPoints.end() );
449
450 return selectedPoints;
451}
452
454{
455 return mElevationShadingRenderer;
456}
457
458QColor QgsPointCloudRenderer::colorFromExpression( const QgsPointCloudBlock *block, int pointIndex, const QColor &rendererColor, QgsPointCloudRenderContext &context )
459{
460 const char *ptr = block->data();
461 const auto &request = block->attributes();
462 const std::size_t recordSize = request.pointRecordSize();
463 const char *pointData = ptr + pointIndex * recordSize;
464
466
467 int offset = 0;
468 for ( const QgsPointCloudAttribute &att : request.attributes() )
469 {
470 QVariant value;
471 context.getAttribute( pointData, offset, att.type(), value );
472 mExpressionContextScope->setVariable( att.name(), value, false );
473 offset += att.size();
474 }
475
476 ctx.setOriginalValueVariable( QVariant::fromValue( rendererColor ) );
477
478 return mDataDefinedProperties.valueAsColor( Property::Color, ctx, rendererColor );
479}
480
481//
482// QgsPreparedPointCloudRendererData
483//
PointCloudSymbol
Rendering symbols for point cloud points.
Definition qgis.h:4558
@ Circle
Renders points as circles.
Definition qgis.h:4560
@ Square
Renders points as squares.
Definition qgis.h:4559
@ Point
Points.
Definition qgis.h:380
PointCloudDrawOrder
Pointcloud rendering order for 2d views.
Definition qgis.h:4570
@ RenderExtents
Render only point cloud extents when zoomed out.
Definition qgis.h:6656
RenderUnit
Rendering size units.
Definition qgis.h:5552
@ Reverse
Reverse/inverse transform (from destination to source).
Definition qgis.h:2833
static QgsPointCloudRendererRegistry * pointCloudRendererRegistry()
Returns the application's point cloud renderer registry, used for managing point cloud layer 2D rende...
Circle geometry type.
Definition qgscircle.h:46
static QgsCircle from2Points(const QgsPoint &pt1, const QgsPoint &pt2)
Constructs a circle by 2 points on the circle.
Definition qgscircle.cpp:39
Handles coordinate transforms between two coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
static QRgb encodeElevation(float z)
Converts elevation value to an actual color.
QPainter * painter() const
Returns painter to the underlying QImage with elevations.
Renders elevation shading on an image with different methods (eye dome lighting, hillshading,...
virtual QgsPolygon * toPolygon(unsigned int segments=36) const
Returns a segmented polygon.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
Qgis::GeometryType type
Layer tree node points to a map layer.
double mapUnitsPerPixel() const
Returns the current map units per pixel.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
void transformInPlace(double &x, double &y) const
Transforms map coordinates to device coordinates.
A collection of point cloud attributes.
int pointRecordSize() const
Returns total size of record.
Attribute for point cloud data pair of name and size in bytes.
Base class for storing raw data from point cloud nodes.
const char * data() const
Returns raw pointer to data.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes that are stored in the data block, along with their size.
QVector< QVariantMap > identify(double maxError, const QgsGeometry &extentGeometry, const QgsDoubleRange &extentZRange=QgsDoubleRange(), int pointsLimit=1000)
Returns the list of points of the point cloud according to a zoom level defined by maxError (in layer...
Represents a map layer supporting display of point clouds.
QgsPointCloudDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
Encapsulates the render context for a 2D point cloud rendering operation.
double zValueFixedOffset() const
Returns any constant offset which must be applied to z values taken from the point cloud index.
QgsVector3D offset() const
Returns the offset of the layer's int32 coordinates compared to CRS coords.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
void incrementPointsRendered(long count)
Increments the count of points rendered by the specified amount.
long pointsRendered() const
Returns the total number of points rendered.
static void getAttribute(const char *data, std::size_t offset, QgsPointCloudAttribute::DataType type, T &value)
Retrieves the attribute value from data at the specified offset, where type indicates the original da...
double zValueScale() const
Returns any constant scaling factor which must be applied to z values taken from the point cloud inde...
QgsVector3D scale() const
Returns the scale of the layer's int32 coordinates compared to CRS coords.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes associated with the rendered block.
QgsPointCloudRenderContext(QgsRenderContext &context, const QgsVector3D &scale, const QgsVector3D &offset, double zValueScale, double zValueFixedOffset, QgsFeedback *feedback=nullptr)
Constructor for QgsPointCloudRenderContext.
QgsFeedback * feedback() const
Returns the feedback object used to cancel rendering.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Sets the attributes associated with the rendered block.
Stores metadata about one point cloud renderer class.
virtual QgsPointCloudRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
QgsPointCloudRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
virtual void checkLegendItem(const QString &key, bool state=true)
Called when the check state of the legend item with the specified key is changed.
void setMaximumScreenError(double error)
Sets the maximum screen error allowed when rendering the point cloud.
void drawPointToElevationMap(double x, double y, double z, QgsPointCloudRenderContext &context) const
Draws a point at the elevation z using at the specified x and y (in map coordinates) on the elevation...
void restoreCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Restores common renderer properties (such as point size and screen error) from the specified DOM elem...
void setMaximumScreenErrorUnit(Qgis::RenderUnit unit)
Sets the unit for the maximum screen error allowed when rendering the point cloud.
void saveCommonProperties(QDomElement &element, const QgsReadWriteContext &context) const
Saves common renderer properties (such as point size and screen error) to the specified DOM element.
const QgsMapUnitScale & pointSizeMapUnitScale() const
Returns the map unit scale used for the point size.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the renderer's property collection, used for data defined overrides.
virtual std::unique_ptr< QgsPreparedPointCloudRendererData > prepare()
Returns prepared data container for bulk point color retrieval.
QColor colorFromExpression(const QgsPointCloudBlock *block, int pointIndex, const QColor &rendererColor, QgsPointCloudRenderContext &context)
Computes color from the expression set, uses expression referenced variables and renderer base color.
void setPointSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the point size.
virtual QSet< QString > usedAttributes(const QgsPointCloudRenderContext &context) const
Returns a list of attributes required by this renderer.
virtual bool legendItemChecked(const QString &key)
Returns true if the legend item with the specified key is checked.
void setPointSize(double size)
Sets the point size.
void setHorizontalTriangleFilterThreshold(double threshold)
Sets threshold for filtering of triangles.
static QgsPointCloudRenderer * load(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer from an XML element.
void setHorizontalTriangleFilterUnit(Qgis::RenderUnit unit)
Sets units of the threshold for filtering of triangles.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the property definitions for data defined properties used by the renderer.
Qgis::RenderUnit maximumScreenErrorUnit() const
Returns the unit for the maximum screen error allowed when rendering the point cloud.
void setDrawOrder2d(Qgis::PointCloudDrawOrder order)
Sets the drawing order used by the renderer for drawing points.
virtual QStringList legendRuleKeys() const
Returns a list of all rule keys for legend nodes created by the renderer.
QVector< QVariantMap > identify(QgsPointCloudLayer *layer, const QgsRenderContext &context, const QgsGeometry &geometry, double toleranceForPointIdentification=0)
Returns the list of visible points of the point cloud layer layer and an extent defined by a geometry...
void setPointSizeUnit(const Qgis::RenderUnit units)
Sets the units used for the point size.
QgsElevationShadingRenderer elevationShadingRenderer() const
Returns the shading renderer used to render shading on the layer.
void setRenderAsTriangles(bool asTriangles)
Sets whether points are triangulated to render solid surface.
void copyCommonProperties(QgsPointCloudRenderer *destination) const
Copies common point cloud properties (such as point size and screen error) to the destination rendere...
void setPointSymbol(Qgis::PointCloudSymbol symbol)
Sets the symbol used by the renderer for drawing points.
void setLabelTextFormat(const QgsTextFormat &textFormat)
Sets the text format renderers should use for rendering labels.
double maximumScreenError() const
Returns the maximum screen error allowed when rendering the point cloud.
void setShowLabels(const bool show)
Set whether the renderer should also render file labels inside extent.
Qgis::RenderUnit pointSizeUnit() const
Returns the units used for the point size.
Qgis::PointCloudSymbol pointSymbol() const
Returns the symbol used by the renderer for drawing points.
virtual void startRender(QgsPointCloudRenderContext &context)
Must be called when a new render cycle is started.
virtual void stopRender(QgsPointCloudRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
Qgis::PointCloudDrawOrder drawOrder2d() const
Returns the drawing order used by the renderer for drawing points.
virtual QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer)
Creates a set of legend nodes representing the renderer.
void setHorizontalTriangleFilter(bool enabled)
Sets whether large triangles will get rendered.
double pointSize() const
Returns the point size.
void setZoomOutBehavior(const Qgis::PointCloudZoomOutRenderBehavior behavior)
Sets the renderer behavior when zoomed out.
void setOverviewSwitchingScale(const double value)
Sets the overview switching scale.
void setElevationShadingRenderer(const QgsElevationShadingRenderer &renderer)
Sets the shading renderer used to render shading on the layer.
Represents a 2D point.
Definition qgspointxy.h:62
double y
Definition qgspointxy.h:66
double x
Definition qgspointxy.h:65
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
double x
Definition qgspoint.h:56
double y
Definition qgspoint.h:57
Definition for a property.
Definition qgsproperty.h:47
@ ColorWithAlpha
Color with alpha channel.
Definition qgsproperty.h:63
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsElevationMap * elevationMap() const
Returns the destination elevation map for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsDoubleRange zRange() const
Returns the range of z-values which should be rendered.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
QgsTextFormat defaultTextFormat(QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling) const
Returns the default text format to use for new text based objects in the specified context.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:164
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
Container for settings relating to a text buffer.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void setSize(double size)
Sets the size of the buffer.
Container for all settings relating to text rendering.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:7423
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:7140
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7404
#define QgsDebugError(str)
Definition qgslogger.h:59
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.