Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add framework for calculating the overall elevation/z range of a QgsP…
…roject
- Loading branch information
1 parent
51ae398
commit 0c7df50
Showing
11 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters