Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
When adding a raster layer which we know definitively contains
elevation data, and the project does not currently have any
terrain provider set, then automatically set that raster layer
as the project's terrain provider
  • Loading branch information
nyalldawson committed May 19, 2023
1 parent e036570 commit 928bbf9
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/app/layers/qgsapplayerhandling.cpp
Expand Up @@ -17,13 +17,16 @@

#include "qgsconfig.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerelevationproperties.h"
#include "qgsmeshlayer.h"
#include "qgsproject.h"
#include "qgsprojectelevationproperties.h"
#include "qgsprojecttimesettings.h"
#include "qgspointcloudlayer.h"
#include "qgsmeshlayertemporalproperties.h"
#include "qgisapp.h"
#include "qgsmessagebar.h"
#include "qgsterrainprovider.h"
#ifdef HAVE_3D
#include "qgspointcloudlayer3drenderer.h"
#endif
Expand Down Expand Up @@ -65,8 +68,32 @@ void QgsAppLayerHandling::postProcessAddedLayer( QgsMapLayer *layer )
{
switch ( layer->type() )
{
case Qgis::LayerType::Vector:
case Qgis::LayerType::Raster:
{
bool ok = false;
layer->loadDefaultStyle( ok );
layer->loadDefaultMetadata( ok );

// if there's no (useful) terrain provider for the current project, and we know that this
// layer contains elevation, then automatically set it as the terrain provider
if ( !QgsProject::instance()->elevationProperties()->terrainProvider()
|| ( dynamic_cast< QgsFlatTerrainProvider * >( QgsProject::instance()->elevationProperties()->terrainProvider() )
&& QgsProject::instance()->elevationProperties()->terrainProvider()->offset() == 0
&& QgsProject::instance()->elevationProperties()->terrainProvider()->scale() == 1 ) )
{
if ( layer->elevationProperties()->hasElevation() )
{
std::unique_ptr< QgsRasterDemTerrainProvider > terrain = std::make_unique<QgsRasterDemTerrainProvider>();
terrain->setLayer( qobject_cast< QgsRasterLayer *>( layer ) );
QgsProject::instance()->elevationProperties()->setTerrainProvider(
terrain.release()
);
}
}
break;
}

case Qgis::LayerType::Vector:
{
bool ok = false;
layer->loadDefaultStyle( ok );
Expand Down

0 comments on commit 928bbf9

Please sign in to comment.