QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgspointcloudlayerelevationproperties.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspointcloudlayerelevationproperties.cpp
3  ---------------
4  begin : November 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson 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 #include "qgspointcloudlayer.h"
20 
23 {
24 }
25 
27 {
28  return true;
29 }
30 
31 QDomElement QgsPointCloudLayerElevationProperties::writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext & )
32 {
33  QDomElement element = document.createElement( QStringLiteral( "elevation" ) );
34  element.setAttribute( QStringLiteral( "zoffset" ), qgsDoubleToString( mZOffset ) );
35  element.setAttribute( QStringLiteral( "zscale" ), qgsDoubleToString( mZScale ) );
36  parentElement.appendChild( element );
37  return element;
38 }
39 
40 bool QgsPointCloudLayerElevationProperties::readXml( const QDomElement &element, const QgsReadWriteContext & )
41 {
42  const QDomElement elevationElement = element.firstChildElement( QStringLiteral( "elevation" ) ).toElement();
43  mZOffset = elevationElement.attribute( QStringLiteral( "zoffset" ), QStringLiteral( "0" ) ).toDouble();
44  mZScale = elevationElement.attribute( QStringLiteral( "zscale" ), QStringLiteral( "1" ) ).toDouble();
45  return true;
46 }
47 
49 {
50  // TODO -- test actual point cloud z range
51  return true;
52 }
53 
55 {
56  if ( QgsPointCloudLayer *pcLayer = qobject_cast< QgsPointCloudLayer * >( layer ) )
57  {
58  if ( pcLayer->dataProvider() )
59  {
60  // try to fetch z range from provider metadata
61  const QVariant zMin = pcLayer->dataProvider()->metadataStatistic( QStringLiteral( "Z" ), QgsStatisticalSummary::Min );
62  const QVariant zMax = pcLayer->dataProvider()->metadataStatistic( QStringLiteral( "Z" ), QgsStatisticalSummary::Max );
63  if ( zMin.isValid() && zMax.isValid() )
64  {
65  return QgsDoubleRange( zMin.toDouble() * mZScale + mZOffset, zMax.toDouble() * mZScale + mZOffset );
66  }
67  }
68  }
69 
70  return QgsDoubleRange();
71 }
QgsRange which stores a range of double values.
Definition: qgsrange.h:203
Base class for storage of map layer elevation properties.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
bool isVisibleInZRange(const QgsDoubleRange &range) const override
Returns true if the layer should be visible and rendered for the specified z range.
bool hasElevation() const override
Returns true if the layer has an elevation or z component.
QDomElement writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) override
Writes the properties to a DOM element, to be used later with readXml().
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the elevation properties from a DOM element previously written by writeXml().
QgsDoubleRange calculateZRange(QgsMapLayer *layer) const override
Attempts to calculate the overall elevation or z range for the specified layer, using the settings de...
QgsPointCloudLayerElevationProperties(QObject *parent)
Constructor for QgsPointCloudLayerElevationProperties, with the specified parent object.
Represents a map layer supporting display of point clouds.
The class is used as a container of context for various read/write operations on other objects.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:1530