33 : mRenderContext( context )
36 , mZValueScale( zValueScale )
37 , mZValueFixedOffset( zValueFixedOffset )
38 , mFeedback( feedback )
45 return mPointsRendered;
50 mPointsRendered += count;
71 mLabelTextFormat = ( textFormat );
76 if ( element.isNull() )
80 const QString rendererType = element.attribute( QStringLiteral(
"type" ) );
86 std::unique_ptr< QgsPointCloudRenderer > r( m->
createRenderer( element, context ) );
92 return QSet< QString >();
105 mThread = QThread::currentThread();
109 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsPointCloudRenderer::startRender",
"startRender called in a different thread - use a cloned renderer instead" );
115 switch ( mPointSymbol )
130 Q_ASSERT_X( mThread == QThread::currentThread(),
"QgsPointCloudRenderer::stopRender",
"stopRender called in a different thread - use a cloned renderer instead" );
146 return mMaximumScreenError;
151 mMaximumScreenError = error;
156 return mMaximumScreenErrorUnit;
161 mMaximumScreenErrorUnit = unit;
166 return QList<QgsLayerTreeModelLegendNode *>();
171 return QStringList();
181 const QPointF originalXY( x, y );
186 switch ( mPointSymbol )
189 elevationPainter->fillRect( QRectF( x - width * 0.5,
191 width, width ), brush );
195 elevationPainter->setBrush( brush );
196 elevationPainter->setPen( Qt::NoPen );
197 elevationPainter->drawEllipse( QRectF( x - width * 0.5,
225 mPointSize = element.attribute( QStringLiteral(
"pointSize" ), QStringLiteral(
"1" ) ).toDouble();
229 mMaximumScreenError = element.attribute( QStringLiteral(
"maximumScreenError" ), QStringLiteral(
"0.3" ) ).toDouble();
230 mMaximumScreenErrorUnit =
QgsUnitTypes::decodeRenderUnit( element.attribute( QStringLiteral(
"maximumScreenErrorUnit" ), QStringLiteral(
"MM" ) ) );
231 mPointSymbol =
static_cast< Qgis::PointCloudSymbol >( element.attribute( QStringLiteral(
"pointSymbol" ), QStringLiteral(
"0" ) ).toInt() );
232 mDrawOrder2d =
static_cast< Qgis::PointCloudDrawOrder >( element.attribute( QStringLiteral(
"drawOrder2d" ), QStringLiteral(
"0" ) ).toInt() );
234 mRenderAsTriangles = element.attribute( QStringLiteral(
"renderAsTriangles" ), QStringLiteral(
"0" ) ).toInt();
235 mHorizontalTriangleFilter = element.attribute( QStringLiteral(
"horizontalTriangleFilter" ), QStringLiteral(
"0" ) ).toInt();
236 mHorizontalTriangleFilterThreshold = element.attribute( QStringLiteral(
"horizontalTriangleFilterThreshold" ), QStringLiteral(
"5" ) ).toDouble();
237 mHorizontalTriangleFilterUnit =
QgsUnitTypes::decodeRenderUnit( element.attribute( QStringLiteral(
"horizontalTriangleFilterUnit" ), QStringLiteral(
"MM" ) ) );
239 mShowLabels = element.attribute( QStringLiteral(
"showLabels" ), QStringLiteral(
"0" ) ).toInt();
240 if ( !element.firstChildElement( QStringLiteral(
"text-style" ) ).isNull() )
243 mLabelTextFormat.
readXml( element.firstChildElement( QStringLiteral(
"text-style" ) ), context );
249 element.setAttribute( QStringLiteral(
"pointSize" ),
qgsDoubleToString( mPointSize ) );
253 element.setAttribute( QStringLiteral(
"maximumScreenError" ),
qgsDoubleToString( mMaximumScreenError ) );
254 element.setAttribute( QStringLiteral(
"maximumScreenErrorUnit" ),
QgsUnitTypes::encodeUnit( mMaximumScreenErrorUnit ) );
255 element.setAttribute( QStringLiteral(
"pointSymbol" ), QString::number(
static_cast< int >( mPointSymbol ) ) );
256 element.setAttribute( QStringLiteral(
"drawOrder2d" ), QString::number(
static_cast< int >( mDrawOrder2d ) ) );
258 element.setAttribute( QStringLiteral(
"renderAsTriangles" ), QString::number(
static_cast< int >( mRenderAsTriangles ) ) );
259 element.setAttribute( QStringLiteral(
"horizontalTriangleFilter" ), QString::number(
static_cast< int >( mHorizontalTriangleFilter ) ) );
260 element.setAttribute( QStringLiteral(
"horizontalTriangleFilterThreshold" ),
qgsDoubleToString( mHorizontalTriangleFilterThreshold ) );
261 element.setAttribute( QStringLiteral(
"horizontalTriangleFilterUnit" ),
QgsUnitTypes::encodeUnit( mHorizontalTriangleFilterUnit ) );
263 element.setAttribute( QStringLiteral(
"showLabels" ), QString::number( mShowLabels ) );
264 if ( mLabelTextFormat.
isValid() )
266 QDomDocument doc = element.ownerDocument();
267 element.appendChild( mLabelTextFormat.
writeXml( doc, context ) );
278 mPointSymbol = symbol;
288 mDrawOrder2d = order;
293 QVector<QVariantMap> selectedPoints;
298 QgsRectangle layerExtentMapCoords = layerExtentLayerCoords;
309 QgsDebugError( QStringLiteral(
"Could not transform node extent to map CRS" ) );
314 if ( ( mapUnitsPerPixel < 0.0 ) || ( maxErrorPixels < 0.0 ) )
317 return selectedPoints;
320 const double maxErrorInMapCoordinates = maxErrorPixels * mapUnitsPerPixel;
321 const double maxErrorInLayerCoordinates = maxErrorInMapCoordinates * layerExtentLayerCoords.
width() / layerExtentMapCoords.
width();
326 const double x = geometry.
asPoint().
x();
327 const double y = geometry.
asPoint().
y();
329 const double pointSizePixels = renderContext.
convertToPainterUnits( mPointSize, mPointSizeUnit, mPointSizeMapUnitScale );
335 const QgsPointXY point1( deviceCoords.
x() - std::max( toleranceInPixels, pointSizePixels / 2.0 ), deviceCoords.
y() - std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
336 const QgsPointXY point2( deviceCoords.
x() + std::max( toleranceInPixels, pointSizePixels / 2.0 ), deviceCoords.
y() + std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
339 const QgsRectangle pointRect( point1MapCoords, point2MapCoords );
345 const QgsPoint centerMapCoords( x, y );
347 const QgsPoint point1( deviceCoords.
x(), deviceCoords.
y() - std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
348 const QgsPoint point2( deviceCoords.
x(), deviceCoords.
y() + std::max( toleranceInPixels, pointSizePixels / 2.0 ) );
352 std::unique_ptr<QgsPolygon> polygon( circle.
toPolygon( 6 ) );
353 const QgsGeometry circleGeometry( std::move( polygon ) );
354 selectionGeometry = circleGeometry;
367 QgsDebugError( QStringLiteral(
"Could not transform geometry to layer CRS" ) );
368 return selectedPoints;
373 selectedPoints.erase( std::remove_if( selectedPoints.begin(), selectedPoints.end(), [
this](
const QMap<QString, QVariant> &point ) { return !this->willRenderPoint( point ); } ), selectedPoints.end() );
375 return selectedPoints;
PointCloudSymbol
Rendering symbols for point cloud points.
@ Circle
Renders points as circles.
@ Square
Renders points as squares.
PointCloudDrawOrder
Pointcloud rendering order for 2d views.
RenderUnit
Rendering size units.
@ Reverse
Reverse/inverse transform (from destination to source)
static QgsPointCloudRendererRegistry * pointCloudRendererRegistry()
Returns the application's point cloud renderer registry, used for managing point cloud layer 2D rende...
static QgsCircle from2Points(const QgsPoint &pt1, const QgsPoint &pt2)
Constructs a circle by 2 points on the circle.
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.
virtual QgsPolygon * toPolygon(unsigned int segments=36) const
Returns a segmented polygon.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
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.
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.
Collection of point cloud attributes.
int pointRecordSize() const
Returns total size of record.
const QgsPointCloudAttribute * find(const QString &attributeName, int &offset) const
Finds the attribute with the name.
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.
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.
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.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Sets the attributes associated with the rendered block.
QgsPointCloudRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
Abstract base class for 2d point cloud renderers.
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.
virtual std::unique_ptr< QgsPreparedPointCloudRendererData > prepare()
Returns prepared data container for bulk point color retrieval.
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.
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.
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.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
virtual ~QgsPreparedPointCloudRendererData()
The class is used as a container of context for various read/write operations on other 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.
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.
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 readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
bool isValid() const
Returns true if the format is valid.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
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.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
#define QgsDebugError(str)