Skip to content
Permalink
Browse files
classify pointclouds by attribute
  • Loading branch information
uclaros authored and wonder-sk committed May 13, 2022
1 parent e2a8ebc commit 79738c8e7880af0cdd4aef3cb4f20e40f5b9b0bc
@@ -116,7 +116,7 @@ Renders point clouds by a classification attribute.
%End
public:

QgsPointCloudClassifiedRenderer();
QgsPointCloudClassifiedRenderer( const QString &attributeName = QString(), const QgsPointCloudCategoryList &categories = QgsPointCloudCategoryList() );
%Docstring
Constructor for QgsPointCloudClassifiedRenderer.
%End
@@ -155,11 +155,16 @@ Returns a list of available renderers.

static QgsPointCloudRenderer *defaultRenderer( const QgsPointCloudLayer *layer ) /Factory/;
%Docstring
Returns a new default point cloud renderer for a layer with the specified ``provider``.
Returns a new default point cloud renderer for a specified ``layer``.

Caller takes ownership of the returned renderer.
%End

static QgsPointCloudCategoryList classificationAttributeCategories( const QgsPointCloudLayer *layer );
%Docstring
Returns a list of categories using the available Classification classes of a specified ``layer``, along with
default colors and translated names for the 19 classes (0-18) of point data record formats 6-10
%End
private:
QgsPointCloudRendererRegistry( const QgsPointCloudRendererRegistry &rh );
};
@@ -478,19 +478,7 @@ void QgsPointCloud3DSymbolWidget::onRenderingStyleChanged()
}
else if ( newSymbolType == QLatin1String( "classification" ) )
{
const QgsPointCloudClassifiedRenderer *renderer2d = dynamic_cast< const QgsPointCloudClassifiedRenderer * >( mLayer->renderer() );
mBlockChangedSignals++;
if ( renderer2d )
{
mClassifiedRendererWidget->setFromCategories( renderer2d->categories(), renderer2d->attribute() );
}
else
{
mClassifiedRendererWidget->setFromCategories( QgsPointCloudClassifiedRenderer::defaultCategories(), QString() );
}

( void )( renderer2d );
mBlockChangedSignals--;
mClassifiedRendererWidget->setFromRenderer( mLayer->renderer() );
}
}

@@ -43,8 +43,9 @@ bool QgsPointCloudCategory::operator==( const QgsPointCloudCategory &other ) con
// QgsPointCloudClassifiedRenderer
//

QgsPointCloudClassifiedRenderer::QgsPointCloudClassifiedRenderer()
: mCategories( defaultCategories() )
QgsPointCloudClassifiedRenderer::QgsPointCloudClassifiedRenderer( const QString &attributeName, const QgsPointCloudCategoryList &categories )
: mAttribute( attributeName )
, mCategories( categories )
{
}

@@ -190,7 +191,8 @@ QgsPointCloudRenderer *QgsPointCloudClassifiedRenderer::create( QDomElement &ele

QgsPointCloudCategoryList QgsPointCloudClassifiedRenderer::defaultCategories()
{
return QgsPointCloudCategoryList() << QgsPointCloudCategory( 1, QColor( "#AAAAAA" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 1 ) )
return QgsPointCloudCategoryList() << QgsPointCloudCategory( 0, QColor( "#BABABA" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 0 ) )
<< QgsPointCloudCategory( 1, QColor( "#AAAAAA" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 1 ) )
<< QgsPointCloudCategory( 2, QColor( "#AA5500" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 2 ) )
<< QgsPointCloudCategory( 3, QColor( "#00AAAA" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 3 ) )
<< QgsPointCloudCategory( 4, QColor( "#55FF55" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 4 ) )
@@ -207,7 +209,7 @@ QgsPointCloudCategoryList QgsPointCloudClassifiedRenderer::defaultCategories()
<< QgsPointCloudCategory( 15, QColor( "#FF55FF" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 15 ) )
<< QgsPointCloudCategory( 16, QColor( "#FFFF55" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 16 ) )
<< QgsPointCloudCategory( 17, QColor( "#5555FF" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 17 ) )
<< QgsPointCloudCategory( 18, QColor( 100, 100, 100 ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 18 ) );
<< QgsPointCloudCategory( 18, QColor( "#646464" ), QgsPointCloudDataProvider::translatedLasClassificationCodes().value( 18 ) );
}

QDomElement QgsPointCloudClassifiedRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
@@ -153,7 +153,7 @@ class CORE_EXPORT QgsPointCloudClassifiedRenderer : public QgsPointCloudRenderer
/**
* Constructor for QgsPointCloudClassifiedRenderer.
*/
QgsPointCloudClassifiedRenderer();
QgsPointCloudClassifiedRenderer( const QString &attributeName = QString(), const QgsPointCloudCategoryList &categories = QgsPointCloudCategoryList() );

QString type() const override;
QgsPointCloudRenderer *clone() const override;
@@ -14,6 +14,8 @@
***************************************************************************/
#include "qgspointcloudrendererregistry.h"
#include "qgspointcloudrenderer.h"
#include "qgsapplication.h"
#include "qgscolorschemeregistry.h"

// default renderers
#include "qgspointcloudattributebyramprenderer.h"
@@ -161,8 +163,8 @@ QgsPointCloudRenderer *QgsPointCloudRendererRegistry::defaultRenderer( const Qgs
classes.removeAll( 1 );
if ( !classes.empty() )
{
std::unique_ptr< QgsPointCloudClassifiedRenderer > renderer = std::make_unique< QgsPointCloudClassifiedRenderer >();
renderer->setAttribute( QStringLiteral( "Classification" ) );
const QgsPointCloudCategoryList categories = classificationAttributeCategories( layer );
std::unique_ptr< QgsPointCloudClassifiedRenderer > renderer = std::make_unique< QgsPointCloudClassifiedRenderer >( QLatin1String( "Classification" ), categories );
return renderer.release();
}
}
@@ -188,3 +190,21 @@ QgsPointCloudRenderer *QgsPointCloudRendererRegistry::defaultRenderer( const Qgs
return renderer.release();
}

QgsPointCloudCategoryList QgsPointCloudRendererRegistry::classificationAttributeCategories( const QgsPointCloudLayer *layer )
{
if ( !layer )
return QgsPointCloudCategoryList();

const QgsPointCloudStatistics stats = layer->statistics();
const QList<int> layerClasses = stats.classesOf( QStringLiteral( "Classification" ) );
const QgsPointCloudCategoryList defaultCategories = QgsPointCloudClassifiedRenderer::defaultCategories();

QgsPointCloudCategoryList categories;
for ( const int &layerClass : layerClasses )
{
const QColor color = layerClass < defaultCategories.size() ? defaultCategories.at( layerClass ).color() : QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor();
const QString label = layerClass < defaultCategories.size() ? QgsPointCloudDataProvider::translatedLasClassificationCodes().value( layerClass, QString::number( layerClass ) ) : QString::number( layerClass );
categories.append( QgsPointCloudCategory( layerClass, color, label ) );
}
return categories;
}
@@ -17,6 +17,7 @@

#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgspointcloudclassifiedrenderer.h"
#include <QIcon>
#include <QMap>
#include <QStringList>
@@ -220,12 +221,17 @@ class CORE_EXPORT QgsPointCloudRendererRegistry
QStringList renderersList() const;

/**
* Returns a new default point cloud renderer for a layer with the specified \a provider.
* Returns a new default point cloud renderer for a specified \a layer.
*
* Caller takes ownership of the returned renderer.
*/
static QgsPointCloudRenderer *defaultRenderer( const QgsPointCloudLayer *layer ) SIP_FACTORY;

/**
* Returns a list of categories using the available Classification classes of a specified \a layer, along with
* default colors and translated names for the 19 classes (0-18) of point data record formats 6-10
*/
static QgsPointCloudCategoryList classificationAttributeCategories( const QgsPointCloudLayer *layer );
private:
#ifdef SIP_RUN
QgsPointCloudRendererRegistry( const QgsPointCloudRendererRegistry &rh );
@@ -98,7 +98,13 @@ struct StatsProcessor
int attributeOffset = 0;
attributesCollection.find( attribute.name(), attributeOffset );
attributeOffsetVector.push_back( attributeOffset );
if ( attribute.name() == QStringLiteral( "Classification" ) )
if ( attribute.name() == QLatin1String( "ScannerChannel" ) ||
attribute.name() == QLatin1String( "ReturnNumber" ) ||
attribute.name() == QLatin1String( "NumberOfReturns" ) ||
attribute.name() == QLatin1String( "ScanDirectionFlag" ) ||
attribute.name() == QLatin1String( "Classification" ) ||
attribute.name() == QLatin1String( "EdgeOfFlightLine" ) ||
attribute.name() == QLatin1String( "PointSourceId" ) )
{
classifiableAttributesOffsetSet.insert( attributeOffset );
}

0 comments on commit 79738c8

Please sign in to comment.