QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
47 : mAttribute( attributeName )
48 , mCategories( categories )
54 return QStringLiteral(
"classified" );
59 std::unique_ptr< QgsPointCloudClassifiedRenderer > res = std::make_unique< QgsPointCloudClassifiedRenderer >();
60 res->mAttribute = mAttribute;
61 res->mCategories = mCategories;
72 const char *ptr = block->
data();
77 int attributeOffset = 0;
91 const bool reproject = ct.
isValid();
93 QHash< int, QColor > colors;
96 if ( !category.renderState() )
99 colors.insert( category.value(), category.color() );
102 for (
int i = 0; i < count; ++i )
112 z =
pointZ( context, ptr, i );
117 int attributeValue = 0;
118 context.
getAttribute( ptr, i * recordSize + attributeOffset, attributeType, attributeValue );
119 const QColor color = colors.value( attributeValue );
120 if ( !color.isValid() )
123 pointXY( context, ptr, i, x, y );
124 if ( visibleExtent.
contains( x, y ) )
147 if ( !pointAttributes.contains( mAttribute ) )
149 bool parsedCorrectly;
150 int attributeInt = pointAttributes[ mAttribute ].toInt( &parsedCorrectly );
151 if ( !parsedCorrectly )
155 if ( category.value() == attributeInt )
156 return category.renderState();
163 std::unique_ptr< QgsPointCloudClassifiedRenderer > r = std::make_unique< QgsPointCloudClassifiedRenderer >();
165 r->setAttribute( element.attribute( QStringLiteral(
"attribute" ), QStringLiteral(
"Classification" ) ) );
168 const QDomElement catsElem = element.firstChildElement( QStringLiteral(
"categories" ) );
169 if ( !catsElem.isNull() )
171 QDomElement catElem = catsElem.firstChildElement();
172 while ( !catElem.isNull() )
174 if ( catElem.tagName() == QLatin1String(
"category" ) )
176 const int value = catElem.attribute( QStringLiteral(
"value" ) ).toInt();
177 const QString label = catElem.attribute( QStringLiteral(
"label" ) );
178 const bool render = catElem.attribute( QStringLiteral(
"render" ) ) != QLatin1String(
"false" );
182 catElem = catElem.nextSiblingElement();
187 r->restoreCommonProperties( element, context );
217 QDomElement rendererElem = doc.createElement( QStringLiteral(
"renderer" ) );
219 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"classified" ) );
220 rendererElem.setAttribute( QStringLiteral(
"attribute" ), mAttribute );
223 QDomElement catsElem = doc.createElement( QStringLiteral(
"categories" ) );
226 QDomElement catElem = doc.createElement( QStringLiteral(
"category" ) );
227 catElem.setAttribute( QStringLiteral(
"value" ), QString::number( category.value() ) );
228 catElem.setAttribute( QStringLiteral(
"label" ), category.label() );
230 catElem.setAttribute( QStringLiteral(
"render" ), category.renderState() ?
"true" :
"false" );
231 catsElem.appendChild( catElem );
233 rendererElem.appendChild( catsElem );
249 QList<QgsLayerTreeModelLegendNode *> nodes;
253 nodes <<
new QgsRasterSymbolLegendNode( nodeLayer, category.color(), category.label(),
nullptr,
true, QString::number( category.value() ) );
264 res << QString::number( category.value() );
272 const int value = key.toInt( &ok );
278 if ( category.value() == value )
279 return category.renderState();
287 const int value = key.toInt( &ok );
291 for (
auto it = mCategories.begin(); it != mCategories.end(); ++it )
293 if ( it->value() == value )
295 it->setRenderState( state );
323 mCategories.append( category );
328 std::unique_ptr< QgsPointCloudClassifiedRendererPreparedData > data = std::make_unique< QgsPointCloudClassifiedRendererPreparedData >();
329 data->attributeName = mAttribute;
333 if ( !category.renderState() )
336 data->colors.insert( category.value(), category.color() );
360 int attributeValue = 0;
362 return colors.value( attributeValue );
QString type() const override
Returns the identifier of the renderer type.
bool legendItemChecked(const QString &key) override
Returns true if the legend item with the specified key is checked.
static QgsPointCloudCategoryList defaultCategories()
Returns the default list of categories.
static QString encodeColor(const QColor &color)
std::unique_ptr< QgsPreparedPointCloudRendererData > prepare() override
Returns prepared data container for bulk point color retrieval.
QString attribute() const
Returns the attribute to use for the renderer.
DataType
Systems of unit measurement.
QColor pointColor(const QgsPointCloudBlock *block, int i, double z) override
An optimised method of retrieving the color of a point from a point cloud block.
The class is used as a container of context for various read/write operations on other objects.
const QgsPointCloudAttribute * find(const QString &attributeName, int &offset) const
Finds the attribute with the name.
bool prepareBlock(const QgsPointCloudBlock *block) override
Prepares the renderer for using the specified block.
QStringList legendRuleKeys() const override
Returns a list of all rule keys for legend nodes created by the renderer.
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.
static QgsPointCloudRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates an RGB renderer from an XML element.
QList< QgsPointCloudCategory > QgsPointCloudCategoryList
bool willRenderPoint(const QVariantMap &pointAttributes) override
Represents an individual category (class) from a QgsPointCloudClassifiedRenderer.
void copyCommonProperties(QgsPointCloudRenderer *destination) const
Copies common point cloud properties (such as point size and screen error) to the destination rendere...
QgsPointCloudCategoryList categories() const
Returns the classification categories used for rendering.
Base class for storing raw data from point cloud nodes.
QColor color() const
Returns the color which will be used to render this category.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
static QColor decodeColor(const QString &str)
QSet< QString > usedAttributes() const override
Returns the set of attributes used by the prepared point cloud renderer.
A rectangle specified with double values.
QgsPointCloudAttribute::DataType attributeType
int pointCount() const
Returns number of points that are stored in the block.
QString label() const
Returns the label for this category, which is used to represent the category within legends and the l...
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...
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QSet< QString > usedAttributes(const QgsPointCloudRenderContext &context) const override
Returns a list of attributes required by this renderer.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Custom exception class for Coordinate Reference System related exceptions.
void drawPoint(double x, double y, const QColor &color, QgsPointCloudRenderContext &context) const
Draws a point using a color at the specified x and y (in map coordinates).
bool renderState() const
Returns true if the category is currently enabled and should be rendered.
Encapsulates the render context for a 2D point cloud rendering operation.
int pointRecordSize() const
Returns total size of record.
void incrementPointsRendered(long count)
Increments the count of points rendered by the specified amount.
Layer tree node points to a map layer.
Collection of point cloud attributes.
bool contains(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle contains other rectangle.
void setCategories(const QgsPointCloudCategoryList &categories)
Sets the classification categories used for rendering.
Attribute for point cloud data pair of name and size in bytes.
static void pointXY(QgsPointCloudRenderContext &context, const char *ptr, int i, double &x, double &y)
Retrieves the x and y coordinate for the point at index i.
QgsPointCloudCategory()=default
Constructor for QgsPointCloudCategory.
bool isInfinite() const
Returns true if the range consists of all possible values.
QgsDoubleRange zRange() const
Returns the range of z-values which should be rendered.
void setAttribute(const QString &attribute)
Sets the attribute to use for the renderer.
void renderBlock(const QgsPointCloudBlock *block, QgsPointCloudRenderContext &context) override
Renders a block of point cloud data using the specified render context.
int pointRecordSize() const
Returns the total size of each individual point record.
QgsRange which stores a range of double values.
void checkLegendItem(const QString &key, bool state=true) override
Called when the check state of the legend item with the specified key is changed.
Abstract base class for 2d point cloud renderers.
int value() const
Returns the value corresponding to this category.
QHash< int, QColor > colors
bool contains(const QgsRange< T > &other) const
Returns true if this range contains another range.
void addCategory(const QgsPointCloudCategory &category)
Adds a category to the renderer.
QgsPointCloudClassifiedRenderer(const QString &attributeName=QString(), const QgsPointCloudCategoryList &categories=QgsPointCloudCategoryList())
Constructor for QgsPointCloudClassifiedRenderer.
QgsPointCloudRenderer * clone() const override
Create a deep copy of this renderer.
bool operator==(const QgsPointCloudCategory &other) const
Equality operator.
Implementation of legend node interface for displaying raster legend entries.
void saveCommonProperties(QDomElement &element, const QgsReadWriteContext &context) const
Saves common renderer properties (such as point size and screen error) to the specified DOM element.
QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer) override
Creates a set of legend nodes representing the renderer.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
static double pointZ(QgsPointCloudRenderContext &context, const char *ptr, int i)
Retrieves the z value for the point at index i.
static QMap< int, QString > translatedLasClassificationCodes()
Returns the map of LAS classification code to translated string value, corresponding to the ASPRS Sta...
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Saves the renderer configuration to an XML element.
DataType type() const
Returns the data type.