30 : mScale( other.mScale )
31 , mOffset( other.mOffset )
44 mOffset = element.attribute( QStringLiteral(
"offset" ) ).toDouble();
45 mScale = element.attribute( QStringLiteral(
"scale" ) ).toDouble();
54 return QStringLiteral(
"flat" );
59 const QDomElement terrainElement = element.firstChildElement( QStringLiteral(
"TerrainProvider" ) );
60 if ( terrainElement.isNull() )
69 QDomElement element = document.createElement( QStringLiteral(
"TerrainProvider" ) );
91 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsFlatTerrainProvider::prepare",
"prepare() must be called from the main thread" );
112 return QStringLiteral(
"raster" );
120 mRasterLayer.
resolve( project );
125 const QDomElement terrainElement = element.firstChildElement( QStringLiteral(
"TerrainProvider" ) );
126 if ( terrainElement.isNull() )
129 QString layerId = terrainElement.attribute( QStringLiteral(
"layer" ) );
130 QString layerName = terrainElement.attribute( QStringLiteral(
"layerName" ) );
131 QString layerSource = terrainElement.attribute( QStringLiteral(
"layerSource" ) );
132 QString layerProvider = terrainElement.attribute( QStringLiteral(
"layerProvider" ) );
141 QDomElement element = document.createElement( QStringLiteral(
"TerrainProvider" ) );
144 element.setAttribute( QStringLiteral(
"layer" ), mRasterLayer.
layerId );
145 element.setAttribute( QStringLiteral(
"layerName" ), mRasterLayer.
name );
146 element.setAttribute( QStringLiteral(
"layerSource" ), mRasterLayer.
source );
147 element.setAttribute( QStringLiteral(
"layerProvider" ), mRasterLayer.
provider );
156 return mRasterProvider ? mRasterProvider->crs()
165 double res = std::numeric_limits<double>::quiet_NaN();
166 if ( mRasterProvider )
168 res = mRasterProvider->sample(
QgsPointXY( x, y ), 1, &ok );
170 else if ( QThread::currentThread() == QCoreApplication::instance()->thread() && mRasterLayer && mRasterLayer->
isValid() )
178 return std::numeric_limits<double>::quiet_NaN();
194 || mRasterLayer.
get() != otherTerrain->
layer() )
202 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsRasterDemTerrainProvider::prepare",
"prepare() must be called from the main thread" );
204 if ( mRasterLayer && mRasterLayer->
isValid() )
215 return mRasterLayer.
get();
220 , mRasterLayer( other.mRasterLayer )
221 , mRasterProvider( nullptr )
232 return QStringLiteral(
"mesh" );
245 const QDomElement terrainElement = element.firstChildElement( QStringLiteral(
"TerrainProvider" ) );
246 if ( terrainElement.isNull() )
249 QString layerId = terrainElement.attribute( QStringLiteral(
"layer" ) );
250 QString layerName = terrainElement.attribute( QStringLiteral(
"layerName" ) );
251 QString layerSource = terrainElement.attribute( QStringLiteral(
"layerSource" ) );
252 QString layerProvider = terrainElement.attribute( QStringLiteral(
"layerProvider" ) );
261 QDomElement element = document.createElement( QStringLiteral(
"TerrainProvider" ) );
264 element.setAttribute( QStringLiteral(
"layer" ), mMeshLayer.
layerId );
265 element.setAttribute( QStringLiteral(
"layerName" ), mMeshLayer.
name );
266 element.setAttribute( QStringLiteral(
"layerSource" ), mMeshLayer.
source );
267 element.setAttribute( QStringLiteral(
"layerProvider" ), mMeshLayer.
provider );
281 if ( mTriangularMesh.
vertices().empty() && mMeshLayer && QThread::currentThread() == QCoreApplication::instance()->thread() )
284 return QgsMeshLayerUtils::interpolateZForPoint( mTriangularMesh, x, y ) *
mScale +
mOffset;
300 || mMeshLayer.
get() != otherTerrain->
layer() )
308 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsMeshTerrainProvider::prepare",
"prepare() must be called from the main thread" );
323 return mMeshLayer.
get();
328 , 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.
This class represents a coordinate reference system (CRS).
A terrain provider where the terrain is a simple flat surface.
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.
QgsCoordinateReferenceSystem crs
Represents a mesh layer supporting display of data on structured or unstructured meshes.
void updateTriangularMesh(const QgsCoordinateTransform &transform=QgsCoordinateTransform())
Gets native mesh and updates (creates if it doesn't exist) the base triangular mesh.
QgsTriangularMesh * triangularMesh(double minimumTriangleSize=0) const
Returns triangular mesh (nullptr before rendering or calling to updateMesh).
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.
A class to represent a 2D point.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QgsRasterDataProvider * clone() const override=0
Clone itself, create deep copy.
virtual double sample(const QgsPointXY &point, int band, bool *ok=nullptr, const QgsRectangle &boundingBox=QgsRectangle(), int width=0, int height=0, int dpi=96)
Samples a raster value from the specified band found at the point position.
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.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
The class is used as a container of context for various read/write operations on other objects.
Triangular/Derived Mesh is mesh with vertices in map coordinates.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
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.
QString source
Weak reference to layer public source.
QString name
Weak reference to layer name.
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.
QString provider
Weak reference to layer provider.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString layerId
Original layer ID.