mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-04 00:04:03 -04:00
Also add variant which takes a list of layers
This commit is contained in:
parent
9492c69d9f
commit
04665953ed
@ -37,6 +37,15 @@ the values from layers contained by the project.
|
||||
|
||||
These values will be highlighted in elevation related widgets for the project.
|
||||
|
||||
.. versionadded:: 3.38
|
||||
%End
|
||||
|
||||
static QList< double > significantZValuesForLayers( const QList< QgsMapLayer * > &layers );
|
||||
%Docstring
|
||||
Returns a list of significant elevation/z-values for the specified ``layers``.
|
||||
|
||||
These values will be highlighted in elevation related widgets for the project.
|
||||
|
||||
.. versionadded:: 3.38
|
||||
%End
|
||||
|
||||
|
@ -37,6 +37,15 @@ the values from layers contained by the project.
|
||||
|
||||
These values will be highlighted in elevation related widgets for the project.
|
||||
|
||||
.. versionadded:: 3.38
|
||||
%End
|
||||
|
||||
static QList< double > significantZValuesForLayers( const QList< QgsMapLayer * > &layers );
|
||||
%Docstring
|
||||
Returns a list of significant elevation/z-values for the specified ``layers``.
|
||||
|
||||
These values will be highlighted in elevation related widgets for the project.
|
||||
|
||||
.. versionadded:: 3.38
|
||||
%End
|
||||
|
||||
|
@ -57,13 +57,22 @@ QgsDoubleRange QgsElevationUtils::calculateZRangeForProject( QgsProject *project
|
||||
QList<double> QgsElevationUtils::significantZValuesForProject( QgsProject *project )
|
||||
{
|
||||
const QMap<QString, QgsMapLayer *> &mapLayers = project->mapLayers();
|
||||
QSet< double > values;
|
||||
|
||||
QgsMapLayer *currentLayer = nullptr;
|
||||
QList< QgsMapLayer * > layers;
|
||||
for ( QMap<QString, QgsMapLayer *>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
|
||||
{
|
||||
currentLayer = it.value();
|
||||
if ( it.value() )
|
||||
layers << it.value();
|
||||
}
|
||||
|
||||
return significantZValuesForLayers( layers );
|
||||
}
|
||||
|
||||
QList<double> QgsElevationUtils::significantZValuesForLayers( const QList<QgsMapLayer *> &layers )
|
||||
{
|
||||
QSet< double > values;
|
||||
|
||||
for ( QgsMapLayer *currentLayer : layers )
|
||||
{
|
||||
if ( !currentLayer->elevationProperties() || !currentLayer->elevationProperties()->hasElevation() )
|
||||
continue;
|
||||
|
||||
|
@ -51,6 +51,15 @@ class CORE_EXPORT QgsElevationUtils
|
||||
*/
|
||||
static QList< double > significantZValuesForProject( QgsProject *project );
|
||||
|
||||
/**
|
||||
* Returns a list of significant elevation/z-values for the specified \a layers.
|
||||
*
|
||||
* These values will be highlighted in elevation related widgets for the project.
|
||||
*
|
||||
* \since QGIS 3.38
|
||||
*/
|
||||
static QList< double > significantZValuesForLayers( const QList< QgsMapLayer * > &layers );
|
||||
|
||||
/**
|
||||
* Returns TRUE if elevation can be enabled for a map \a layer.
|
||||
*
|
||||
|
@ -78,12 +78,16 @@ class TestQgsElevationUtils(QgisTestCase):
|
||||
project = QgsProject()
|
||||
self.assertFalse(
|
||||
QgsElevationUtils.significantZValuesForProject(project))
|
||||
self.assertFalse(
|
||||
QgsElevationUtils.significantZValuesForLayers([]))
|
||||
|
||||
raster_layer = QgsRasterLayer(os.path.join(unitTestDataPath(), 'landsat_4326.tif'))
|
||||
self.assertTrue(raster_layer.isValid())
|
||||
project.addMapLayer(raster_layer)
|
||||
self.assertFalse(
|
||||
QgsElevationUtils.significantZValuesForProject(project))
|
||||
self.assertFalse(
|
||||
QgsElevationUtils.significantZValuesForLayers([raster_layer]))
|
||||
|
||||
props = raster_layer.elevationProperties()
|
||||
props.setEnabled(True)
|
||||
@ -94,6 +98,9 @@ class TestQgsElevationUtils(QgisTestCase):
|
||||
self.assertEqual(
|
||||
QgsElevationUtils.significantZValuesForProject(project),
|
||||
[103.1, 106.8, 116.8, 126.8])
|
||||
self.assertEqual(
|
||||
QgsElevationUtils.significantZValuesForLayers([raster_layer]),
|
||||
[103.1, 106.8, 116.8, 126.8])
|
||||
|
||||
raster_layer2 = QgsRasterLayer(os.path.join(unitTestDataPath(), 'landsat_4326.tif'))
|
||||
self.assertTrue(raster_layer2.isValid())
|
||||
@ -101,6 +108,10 @@ class TestQgsElevationUtils(QgisTestCase):
|
||||
self.assertEqual(
|
||||
QgsElevationUtils.significantZValuesForProject(project),
|
||||
[103.1, 106.8, 116.8, 126.8])
|
||||
self.assertEqual(
|
||||
QgsElevationUtils.significantZValuesForLayers([raster_layer,
|
||||
raster_layer2]),
|
||||
[103.1, 106.8, 116.8, 126.8])
|
||||
|
||||
props = raster_layer2.elevationProperties()
|
||||
props.setEnabled(True)
|
||||
@ -111,6 +122,10 @@ class TestQgsElevationUtils(QgisTestCase):
|
||||
self.assertEqual(
|
||||
QgsElevationUtils.significantZValuesForProject(project),
|
||||
[103.1, 106.8, 116.8, 126.8, 136.8])
|
||||
self.assertEqual(
|
||||
QgsElevationUtils.significantZValuesForLayers([raster_layer,
|
||||
raster_layer2]),
|
||||
[103.1, 106.8, 116.8, 126.8, 136.8])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user