Skip to content

Commit

Permalink
Add framework for calculating the overall elevation/z range of a QgsP…
Browse files Browse the repository at this point in the history
…roject
  • Loading branch information
nyalldawson committed Nov 28, 2020
1 parent 51ae398 commit 0c7df50
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 1 deletion.
Expand Up @@ -36,6 +36,7 @@ Constructor for QgsPointCloudLayerElevationProperties, with the specified ``pare

virtual bool isVisibleInZRange( const QgsDoubleRange &range ) const;

virtual QgsDoubleRange calculateZRange( QgsMapLayer *layer ) const;

};

Expand Down
42 changes: 42 additions & 0 deletions python/core/auto_generated/qgselevationutils.sip.in
@@ -0,0 +1,42 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgselevationutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsElevationUtils
{
%Docstring
Contains utility methods for working with elevation from layers and projects.

.. versionadded:: 3.18
%End

%TypeHeaderCode
#include "qgselevationutils.h"
%End
public:

static QgsDoubleRange calculateZRangeForProject( QgsProject *project );
%Docstring
Calculates the elevation range for a ``project``.

This method considers the elevation (or z) range available from layers contained within the project and
returns the maximal combined elevation range of these layers.
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgselevationutils.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
Expand Up @@ -77,6 +77,14 @@ Returns ``True`` if the layer should be visible and rendered for the specified z
virtual QgsMapLayerElevationProperties::Flags flags() const;
%Docstring
Returns flags associated to the elevation properties.
%End

virtual QgsDoubleRange calculateZRange( QgsMapLayer *layer ) const;
%Docstring
Attempts to calculate the overall elevation or z range for the specified ``layer``, using
the settings defined by this elevation properties object.

May return an infinite range if the extent could not be calculated.
%End

signals:
Expand Down
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -54,6 +54,7 @@
%Include auto_generated/qgsdistancearea.sip
%Include auto_generated/qgseditformconfig.sip
%Include auto_generated/qgseditorwidgetsetup.sip
%Include auto_generated/qgselevationutils.sip
%Include auto_generated/qgsellipsoidutils.sip
%Include auto_generated/qgserror.sip
%Include auto_generated/qgsexpressioncontext.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -279,6 +279,7 @@ set(QGIS_CORE_SRCS
qgsdiagramrenderer.cpp
qgsdistancearea.cpp
qgseditformconfig.cpp
qgselevationutils.cpp
qgsellipsoidutils.cpp
qgserror.cpp
qgseventtracing.cpp
Expand Down Expand Up @@ -865,6 +866,7 @@ set(QGIS_CORE_HDRS
qgsdistancearea.h
qgseditformconfig.h
qgseditorwidgetsetup.h
qgselevationutils.h
qgsellipsoidutils.h
qgserror.h
qgseventtracing.h
Expand Down
6 changes: 6 additions & 0 deletions src/core/pointcloud/qgspointcloudlayerelevationproperties.cpp
Expand Up @@ -43,3 +43,9 @@ bool QgsPointCloudLayerElevationProperties::isVisibleInZRange( const QgsDoubleRa
// TODO -- test actual point cloud z range
return true;
}

QgsDoubleRange QgsPointCloudLayerElevationProperties::calculateZRange( QgsMapLayer * ) const
{
// TODO - retrieve range from point cloud data provider
return QgsDoubleRange();
}
Expand Up @@ -46,7 +46,7 @@ class CORE_EXPORT QgsPointCloudLayerElevationProperties : public QgsMapLayerElev
QDomElement writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) override;
bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
bool isVisibleInZRange( const QgsDoubleRange &range ) const override;

QgsDoubleRange calculateZRange( QgsMapLayer *layer ) const override;
};

#endif // QGSPOINTCLOUDLAYERELEVATIONPROPERTIES_H
56 changes: 56 additions & 0 deletions src/core/qgselevationutils.cpp
@@ -0,0 +1,56 @@
/***************************************************************************
qgselevationutils.cpp
------------------
Date : November 2020
Copyright : (C) 2020 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgselevationutils.h"
#include "qgsproject.h"
#include "qgsmaplayerelevationproperties.h"


QgsDoubleRange QgsElevationUtils::calculateZRangeForProject( QgsProject *project )
{
const QMap<QString, QgsMapLayer *> &mapLayers = project->mapLayers();
QgsMapLayer *currentLayer = nullptr;

double min = std::numeric_limits<double>::quiet_NaN();
double max = std::numeric_limits<double>::quiet_NaN();

for ( QMap<QString, QgsMapLayer *>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
{
currentLayer = it.value();

if ( !currentLayer->elevationProperties() || !currentLayer->elevationProperties()->hasElevation() )
continue;

const QgsDoubleRange layerRange = currentLayer->elevationProperties()->calculateZRange( currentLayer );
if ( layerRange.isInfinite() )
continue;

if ( layerRange.lower() > std::numeric_limits< double >::lowest() )
{
if ( std::isnan( min ) || layerRange.lower() < min )
min = layerRange.lower();
}

if ( layerRange.upper() < std::numeric_limits< double >::max() )
{
if ( std::isnan( max ) || layerRange.upper() > max )
max = layerRange.upper();
}
}

return QgsDoubleRange( std::isnan( min ) ? std::numeric_limits< double >::lowest() : min,
std::isnan( max ) ? std::numeric_limits< double >::max() : max );
}

46 changes: 46 additions & 0 deletions src/core/qgselevationutils.h
@@ -0,0 +1,46 @@
/***************************************************************************
qgselevationutils.h
------------------
Date : November 2020
Copyright : (C) 2020 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSELEVATIONUTILS_H
#define QGSELEVATIONUTILS_H

#include "qgis_core.h"
#include "qgsrange.h"

class QgsProject;

/**
* \ingroup core
* \class QgsElevationUtils
* \brief Contains utility methods for working with elevation from layers and projects.
*
* \since QGIS 3.18
*/
class CORE_EXPORT QgsElevationUtils
{
public:

/**
* Calculates the elevation range for a \a project.
*
* This method considers the elevation (or z) range available from layers contained within the project and
* returns the maximal combined elevation range of these layers.
*/
static QgsDoubleRange calculateZRangeForProject( QgsProject *project );

};


#endif // QGSELEVATIONUTILS_H
5 changes: 5 additions & 0 deletions src/core/qgsmaplayerelevationproperties.cpp
Expand Up @@ -31,3 +31,8 @@ bool QgsMapLayerElevationProperties::isVisibleInZRange( const QgsDoubleRange & )
{
return true;
}

QgsDoubleRange QgsMapLayerElevationProperties::calculateZRange( QgsMapLayer * ) const
{
return QgsDoubleRange();
}
8 changes: 8 additions & 0 deletions src/core/qgsmaplayerelevationproperties.h
Expand Up @@ -103,6 +103,14 @@ class CORE_EXPORT QgsMapLayerElevationProperties : public QObject
*/
virtual QgsMapLayerElevationProperties::Flags flags() const { return QgsMapLayerElevationProperties::Flags(); }

/**
* Attempts to calculate the overall elevation or z range for the specified \a layer, using
* the settings defined by this elevation properties object.
*
* May return an infinite range if the extent could not be calculated.
*/
virtual QgsDoubleRange calculateZRange( QgsMapLayer *layer ) const;

signals:

/**
Expand Down

0 comments on commit 0c7df50

Please sign in to comment.