46 mOffset = element.attribute( QStringLiteral(
"offset" ) ).toDouble();
47 mScale = element.attribute( QStringLiteral(
"scale" ) ).toDouble();
56 return QStringLiteral(
"flat" );
61 const QDomElement terrainElement = element.firstChildElement( QStringLiteral(
"TerrainProvider" ) );
62 if ( terrainElement.isNull() )
71 QDomElement element = document.createElement( QStringLiteral(
"TerrainProvider" ) );
93 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsFlatTerrainProvider::prepare",
"prepare() must be called from the main thread" );
114 return QStringLiteral(
"raster" );
122 mRasterLayer.resolve( project );
127 const QDomElement terrainElement = element.firstChildElement( QStringLiteral(
"TerrainProvider" ) );
128 if ( terrainElement.isNull() )
131 QString layerId = terrainElement.attribute( QStringLiteral(
"layer" ) );
132 QString layerName = terrainElement.attribute( QStringLiteral(
"layerName" ) );
133 QString layerSource = terrainElement.attribute( QStringLiteral(
"layerSource" ) );
134 QString layerProvider = terrainElement.attribute( QStringLiteral(
"layerProvider" ) );
143 QDomElement element = document.createElement( QStringLiteral(
"TerrainProvider" ) );
146 element.setAttribute( QStringLiteral(
"layer" ), mRasterLayer.layerId );
147 element.setAttribute( QStringLiteral(
"layerName" ), mRasterLayer.name );
148 element.setAttribute( QStringLiteral(
"layerSource" ), mRasterLayer.source );
149 element.setAttribute( QStringLiteral(
"layerProvider" ), mRasterLayer.provider );
158 return mRasterProvider ? mRasterProvider->crs()
167 double res = std::numeric_limits<double>::quiet_NaN();
168 if ( mRasterProvider )
170 res = mRasterProvider->sample(
QgsPointXY( x, y ), 1, &ok );
172 else if ( QThread::currentThread() == QCoreApplication::instance()->thread() && mRasterLayer && mRasterLayer->isValid() )
174 res = mRasterLayer->dataProvider()->sample(
QgsPointXY( x, y ), 1, &ok );
180 return std::numeric_limits<double>::quiet_NaN();
196 || mRasterLayer.get() != otherTerrain->
layer() )
204 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsRasterDemTerrainProvider::prepare",
"prepare() must be called from the main thread" );
206 if ( mRasterLayer && mRasterLayer->isValid() )
207 mRasterProvider.reset( mRasterLayer->dataProvider()->clone() );
212 mRasterLayer.setLayer(
layer );
217 return mRasterLayer.get();
222 , mRasterLayer( other.mRasterLayer )
223 , mRasterProvider( nullptr )
234 return QStringLiteral(
"mesh" );
242 mMeshLayer.resolve( project );
247 const QDomElement terrainElement = element.firstChildElement( QStringLiteral(
"TerrainProvider" ) );
248 if ( terrainElement.isNull() )
251 QString layerId = terrainElement.attribute( QStringLiteral(
"layer" ) );
252 QString layerName = terrainElement.attribute( QStringLiteral(
"layerName" ) );
253 QString layerSource = terrainElement.attribute( QStringLiteral(
"layerSource" ) );
254 QString layerProvider = terrainElement.attribute( QStringLiteral(
"layerProvider" ) );
263 QDomElement element = document.createElement( QStringLiteral(
"TerrainProvider" ) );
266 element.setAttribute( QStringLiteral(
"layer" ), mMeshLayer.layerId );
267 element.setAttribute( QStringLiteral(
"layerName" ), mMeshLayer.name );
268 element.setAttribute( QStringLiteral(
"layerSource" ), mMeshLayer.source );
269 element.setAttribute( QStringLiteral(
"layerProvider" ), mMeshLayer.provider );
283 if ( mTriangularMesh.vertices().empty() && mMeshLayer && QThread::currentThread() == QCoreApplication::instance()->thread() )
286 return QgsMeshLayerUtils::interpolateZForPoint( mTriangularMesh, x, y ) *
mScale +
mOffset;
302 || mMeshLayer.get() != otherTerrain->
layer() )
310 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsMeshTerrainProvider::prepare",
"prepare() must be called from the main thread" );
313 mMeshLayer->updateTriangularMesh();
314 mTriangularMesh = *mMeshLayer->triangularMesh();
320 mMeshLayer.setLayer(
layer );
325 return mMeshLayer.get();
330 , mMeshLayer( other.mMeshLayer )
Abstract base class for terrain providers.
virtual QString type() const =0
Returns the unique type ID string for the provider.
void readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common properties from a DOM element.
virtual ~QgsAbstractTerrainProvider()
void writeCommonProperties(QDomElement &element, const QgsReadWriteContext &context) const
Writes common properties to a DOM element.
double offset() const
Returns the vertical offset value, used for adjusting the heights from the terrain provider.
double mScale
Scale factor.
double scale() const
Returns the vertical scale factor, which can be used to exaggerate vertical heights.
virtual void resolveReferences(const QgsProject *project)
Resolves reference to layers from stored layer ID (if it has not been resolved already).
QgsAbstractTerrainProvider()=default
double mOffset
Offset amount.
Represents a coordinate reference system (CRS).
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the terrain provider state from a DOM element.
bool equals(const QgsAbstractTerrainProvider *other) const override
Returns true if the provider is equal to other.
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const override
Returns a DOM element representing the state of the terrain provider.
QgsFlatTerrainProvider * clone() const override
Creates a clone of the provider and returns the new object.
QgsCoordinateReferenceSystem crs() const override
Returns the native coordinate reference system of the terrain provider.
QgsFlatTerrainProvider()=default
void prepare() override
Called on the main thread prior to accessing the provider from a background thread.
double heightAt(double x, double y) const override
Returns the height at the point (x,y) in the terrain provider's native crs().
QString type() const override
Returns the unique type ID string for the provider.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
A terrain provider that uses the Z values of a mesh layer to build a terrain surface.
void setLayer(QgsMeshLayer *layer)
Sets the mesh layer to be used as the terrain source.
QgsMeshTerrainProvider()=default
QgsMeshTerrainProvider * clone() const override
Creates a clone of the provider and returns the new object.
bool equals(const QgsAbstractTerrainProvider *other) const override
Returns true if the provider is equal to other.
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const override
Returns a DOM element representing the state of the terrain provider.
void prepare() override
Called on the main thread prior to accessing the provider from a background thread.
QString type() const override
Returns the unique type ID string for the provider.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the terrain provider state from a DOM element.
void resolveReferences(const QgsProject *project) override
Resolves reference to layers from stored layer ID (if it has not been resolved already).
double heightAt(double x, double y) const override
Returns the height at the point (x,y) in the terrain provider's native crs().
QgsMeshLayer * layer() const
Returns the mesh layer to be used as the terrain source.
QgsCoordinateReferenceSystem crs() const override
Returns the native coordinate reference system of the terrain provider.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
A terrain provider where the terrain source is a raster DEM layer.
QgsRasterDemTerrainProvider * clone() const override
Creates a clone of the provider and returns the new object.
void setLayer(QgsRasterLayer *layer)
Sets the raster layer with elevation model to be used as the terrain source.
QgsCoordinateReferenceSystem crs() const override
Returns the native coordinate reference system of the terrain provider.
void prepare() override
Called on the main thread prior to accessing the provider from a background thread.
void resolveReferences(const QgsProject *project) override
Resolves reference to layers from stored layer ID (if it has not been resolved already).
QgsRasterLayer * layer() const
Returns the raster layer with elevation model to be used as the terrain source.
bool equals(const QgsAbstractTerrainProvider *other) const override
Returns true if the provider is equal to other.
double heightAt(double x, double y) const override
Returns the height at the point (x,y) in the terrain provider's native crs().
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const override
Returns a DOM element representing the state of the terrain provider.
QString type() const override
Returns the unique type ID string for the provider.
QgsRasterDemTerrainProvider()=default
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the terrain provider state from a DOM element.
Represents a raster layer.
A container for the context for various read/write operations on objects.
A triangular/derived mesh with vertices in map coordinates.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Internal structure to keep weak pointer to QgsMapLayer or layerId if the layer is not available yet.