25using namespace Qt::StringLiterals;
49 mOffset = element.attribute( u
"offset"_s ).toDouble();
50 mScale = element.attribute( u
"scale"_s ).toDouble();
64 const QDomElement terrainElement = element.firstChildElement( u
"TerrainProvider"_s );
65 if ( terrainElement.isNull() )
74 QDomElement element = document.createElement( u
"TerrainProvider"_s );
96 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsFlatTerrainProvider::prepare",
"prepare() must be called from the main thread" );
125 mRasterLayer.resolve( project );
130 const QDomElement terrainElement = element.firstChildElement( u
"TerrainProvider"_s );
131 if ( terrainElement.isNull() )
134 QString layerId = terrainElement.attribute( u
"layer"_s );
135 QString layerName = terrainElement.attribute( u
"layerName"_s );
136 QString layerSource = terrainElement.attribute( u
"layerSource"_s );
137 QString layerProvider = terrainElement.attribute( u
"layerProvider"_s );
146 QDomElement element = document.createElement( u
"TerrainProvider"_s );
149 element.setAttribute( u
"layer"_s, mRasterLayer.layerId );
150 element.setAttribute( u
"layerName"_s, mRasterLayer.name );
151 element.setAttribute( u
"layerSource"_s, mRasterLayer.source );
152 element.setAttribute( u
"layerProvider"_s, mRasterLayer.provider );
161 return mRasterProvider ? mRasterProvider->crs()
170 double res = std::numeric_limits<double>::quiet_NaN();
171 if ( mRasterProvider )
173 res = mRasterProvider->sample(
QgsPointXY( x, y ), 1, &ok );
175 else if ( QThread::currentThread() == QCoreApplication::instance()->thread() && mRasterLayer && mRasterLayer->isValid() )
177 res = mRasterLayer->dataProvider()->sample(
QgsPointXY( x, y ), 1, &ok );
183 return std::numeric_limits<double>::quiet_NaN();
199 || mRasterLayer.get() != otherTerrain->
layer() )
207 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsRasterDemTerrainProvider::prepare",
"prepare() must be called from the main thread" );
209 if ( mRasterLayer && mRasterLayer->isValid() )
210 mRasterProvider.reset( mRasterLayer->dataProvider()->clone() );
215 mRasterLayer.setLayer(
layer );
220 return mRasterLayer.get();
225 , mRasterLayer( other.mRasterLayer )
226 , mRasterProvider( nullptr )
245 mMeshLayer.resolve( project );
250 const QDomElement terrainElement = element.firstChildElement( u
"TerrainProvider"_s );
251 if ( terrainElement.isNull() )
254 QString layerId = terrainElement.attribute( u
"layer"_s );
255 QString layerName = terrainElement.attribute( u
"layerName"_s );
256 QString layerSource = terrainElement.attribute( u
"layerSource"_s );
257 QString layerProvider = terrainElement.attribute( u
"layerProvider"_s );
266 QDomElement element = document.createElement( u
"TerrainProvider"_s );
269 element.setAttribute( u
"layer"_s, mMeshLayer.layerId );
270 element.setAttribute( u
"layerName"_s, mMeshLayer.name );
271 element.setAttribute( u
"layerSource"_s, mMeshLayer.source );
272 element.setAttribute( u
"layerProvider"_s, mMeshLayer.provider );
286 if ( mTriangularMesh.vertices().empty() && mMeshLayer && QThread::currentThread() == QCoreApplication::instance()->thread() )
289 return QgsMeshLayerUtils::interpolateZForPoint( mTriangularMesh, x, y ) *
mScale +
mOffset;
305 || mMeshLayer.get() != otherTerrain->
layer() )
313 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsMeshTerrainProvider::prepare",
"prepare() must be called from the main thread" );
316 mMeshLayer->updateTriangularMesh();
317 mTriangularMesh = *mMeshLayer->triangularMesh();
323 mMeshLayer.setLayer(
layer );
328 return mMeshLayer.get();
333 , 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.