22#include <QJsonDocument> 
   35  double delta1 = newMean - 
mean;
 
   37  double delta2 = newMean - stats.
mean;
 
   38  double variance2 = stats.
stDev * stats.
stDev + delta2 * delta2 - 2 * stats.
count * delta2 * stats.
mean;
 
 
   61  : mSampledPointsCount( sampledPointsCount ), mStatisticsMap( stats )
 
 
   68  mStatisticsMap.clear();
 
 
   75    mStatisticsMap.remove( attribute.name() );
 
 
   82  defaultVal.
minimum = std::numeric_limits<double>::max();
 
   83  defaultVal.
maximum = std::numeric_limits<double>::lowest();
 
   85  return mStatisticsMap.value( attribute, defaultVal );
 
 
   90  if ( !mStatisticsMap.contains( attribute ) )
 
 
   98  if ( !mStatisticsMap.contains( attribute ) )
 
   99    return QMap<int, int>();
 
  100  return mStatisticsMap[ attribute ].classCount;
 
 
  105  if ( !mStatisticsMap.contains( attribute ) )
 
  106    return std::numeric_limits<double>::quiet_NaN();
 
  107  return mStatisticsMap[ attribute ].minimum;
 
 
  112  if ( !mStatisticsMap.contains( attribute ) )
 
  113    return std::numeric_limits<double>::quiet_NaN();
 
  114  return mStatisticsMap[ attribute ].maximum;
 
 
  119  if ( !mStatisticsMap.contains( attribute ) )
 
  120    return std::numeric_limits<double>::quiet_NaN();
 
  121  return mStatisticsMap[ attribute ].mean;
 
 
  126  if ( !mStatisticsMap.contains( attribute ) )
 
  127    return std::numeric_limits<double>::quiet_NaN();
 
  128  return mStatisticsMap[ attribute ].stDev;
 
 
  134  for ( 
auto it = stats.mStatisticsMap.constBegin(); it != stats.mStatisticsMap.constEnd(); it++ )
 
  136    const QString attribute = it.key();
 
  138    if ( mStatisticsMap.contains( attribute ) )
 
  142    mStatisticsMap[ attribute ] = s;
 
  144  mSampledPointsCount += stats.mSampledPointsCount;
 
 
  150  obj.insert( QStringLiteral( 
"sampled-points" ), QJsonValue::fromVariant( 
sampledPointsCount() ) );
 
  152  for ( 
auto it = mStatisticsMap.constBegin(); it != mStatisticsMap.constEnd(); it++ )
 
  155    stats.insert( it.key(), attributeStatisticsToJson( stat ) );
 
  157  obj.insert( QStringLiteral( 
"stats" ), stats );
 
  159  QJsonDocument statsDoc( obj );
 
  160  return statsDoc.toJson( QJsonDocument::Compact );
 
 
  165  QJsonParseError error;
 
  166  QJsonDocument document = QJsonDocument::fromJson( statsByteArray, &error );
 
  167  if ( error.error != QJsonParseError::NoError )
 
  169    QgsMessageLog::logMessage( QObject::tr( 
"Failed to load statistics JSON from COPC file, reason: %1" ).arg( error.errorString() ) );
 
  173  QJsonObject statsJson = document.object();
 
  176  stats.mSampledPointsCount = statsJson.value( QStringLiteral( 
"sampled-points" ) ).toInt();
 
  177  if ( statsJson.contains( QStringLiteral( 
"stats" ) ) )
 
  179    QJsonObject statsObj = statsJson.value( QStringLiteral( 
"stats" ) ).toObject();
 
  180    for ( 
const QString &attr : statsObj.keys() )
 
  182      QJsonObject obj = statsObj.value( attr ).toObject();
 
  184      attrStats.
count = stats.mSampledPointsCount;
 
  185      stats.mStatisticsMap.insert( attr, attrStats );
 
 
  194  obj.insert( QStringLiteral( 
"minimum" ), stats.
minimum );
 
  195  obj.insert( QStringLiteral( 
"maximum" ), stats.
maximum );
 
  196  obj.insert( QStringLiteral( 
"mean" ), stats.
mean );
 
  197  if ( !std::isnan( stats.
stDev ) )
 
  199    obj.insert( QStringLiteral( 
"standard-deviation" ), stats.
stDev );
 
  201  QJsonObject classCount;
 
  204    classCount.insert( QString::number( it.key() ), it.value() );
 
  206  obj.insert( QStringLiteral( 
"class-count" ), classCount );
 
  213  QVariantMap m = statsJson.toVariantMap();
 
  214  statsObj.
minimum = m.value( QStringLiteral( 
"minimum" ), std::numeric_limits<double>::max() ).toDouble();
 
  215  statsObj.
maximum = m.value( QStringLiteral( 
"maximum" ), std::numeric_limits<double>::lowest() ).toDouble();
 
  216  statsObj.
mean = m.value( QStringLiteral( 
"mean" ), 0 ).toDouble();
 
  217  statsObj.
stDev = m.value( QStringLiteral( 
"standard-deviation" ), std::numeric_limits<double>::quiet_NaN() ).toDouble();
 
  218  QJsonObject classCountJson = statsJson.value( QStringLiteral( 
"class-count" ) ).toObject();
 
  219  for ( 
const QString &key : classCountJson.keys() )
 
  221    statsObj.
classCount.insert( key.toInt(), classCountJson.value( key ).toInt() );
 
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
 
Attribute for point cloud data pair of name and size in bytes.
 
Class used to store statistics of a point cloud dataset.
 
static QgsPointCloudStatistics fromStatisticsJson(QByteArray stats)
Creates a statistics object from the JSON object stats.
 
double maximum(const QString &attribute) const
Returns the maximum value for the attribute attribute If no matching statistic is available then NaN ...
 
double stDev(const QString &attribute) const
Returns the standard deviation value for the attribute attribute If no matching statistic is availabl...
 
void clear()
Clears the statistics of all attributes.
 
QMap< int, int > availableClasses(const QString &attribute) const
Returns a map containing the count of each class of the attribute attribute If no matching statistic ...
 
QgsPointCloudStatistics()
Constructor.
 
QList< int > classesOf(const QString &attribute) const
Returns a list of existing classes which are present for the specified attribute.
 
double mean(const QString &attribute) const
Returns the mean value for the attribute attribute If no matching statistic is available then NaN wil...
 
void combineWith(const QgsPointCloudStatistics &stats)
Merges the current statistics with the statistics from stats.
 
double minimum(const QString &attribute) const
Returns the minimum value for the attribute attribute If no matching statistic is available then NaN ...
 
int sampledPointsCount() const
Returns the number of points used to calculate the statistics.
 
QByteArray toStatisticsJson() const
Converts the current statistics object into JSON object.
 
QgsPointCloudAttributeStatistics statisticsOf(const QString &attribute) const
Returns the calculated statistics of attribute attribute.
 
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
 
Class used to store statistics of one attribute of a point cloud dataset.
 
void cumulateStatistics(const QgsPointCloudAttributeStatistics &stats)
Updates the current point cloud statistics to hold the cumulation of the current statistics and stats...
 
QMap< int, int > classCount