29 : mScale( other.mScale )
30 , mOffset( other.mOffset )
43 mOffset = element.attribute( QStringLiteral(
"offset" ) ).toDouble();
44 mScale = element.attribute( QStringLiteral(
"scale" ) ).toDouble();
53 return QStringLiteral(
"flat" );
58 const QDomElement terrainElement = element.firstChildElement( QStringLiteral(
"TerrainProvider" ) );
59 if ( terrainElement.isNull() )
68 QDomElement element = document.createElement( QStringLiteral(
"TerrainProvider" ) );
90 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsFlatTerrainProvider::prepare",
"prepare() must be called from the main thread" );
111 return QStringLiteral(
"raster" );
119 mRasterLayer.
resolve( project );
124 const QDomElement terrainElement = element.firstChildElement( QStringLiteral(
"TerrainProvider" ) );
125 if ( terrainElement.isNull() )
128 QString layerId = terrainElement.attribute( QStringLiteral(
"layer" ) );
129 QString layerName = terrainElement.attribute( QStringLiteral(
"layerName" ) );
130 QString layerSource = terrainElement.attribute( QStringLiteral(
"layerSource" ) );
131 QString layerProvider = terrainElement.attribute( QStringLiteral(
"layerProvider" ) );
140 QDomElement element = document.createElement( QStringLiteral(
"TerrainProvider" ) );
143 element.setAttribute( QStringLiteral(
"layer" ), mRasterLayer.
layerId );
144 element.setAttribute( QStringLiteral(
"layerName" ), mRasterLayer.
name );
145 element.setAttribute( QStringLiteral(
"layerSource" ), mRasterLayer.
source );
146 element.setAttribute( QStringLiteral(
"layerProvider" ), mRasterLayer.
provider );
155 return mRasterProvider ? mRasterProvider->crs()
164 double res = std::numeric_limits<double>::quiet_NaN();
165 if ( mRasterProvider )
167 res = mRasterProvider->sample(
QgsPointXY( x, y ), 1, &ok );
169 else if ( QThread::currentThread() == QCoreApplication::instance()->thread() && mRasterLayer && mRasterLayer->
isValid() )
177 return std::numeric_limits<double>::quiet_NaN();
193 || mRasterLayer.
get() != otherTerrain->
layer() )
201 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsRasterDemTerrainProvider::prepare",
"prepare() must be called from the main thread" );
203 if ( mRasterLayer && mRasterLayer->
isValid() )
214 return mRasterLayer.
get();
219 , mRasterLayer( other.mRasterLayer )
231 return QStringLiteral(
"mesh" );
244 const QDomElement terrainElement = element.firstChildElement( QStringLiteral(
"TerrainProvider" ) );
245 if ( terrainElement.isNull() )
248 QString layerId = terrainElement.attribute( QStringLiteral(
"layer" ) );
249 QString layerName = terrainElement.attribute( QStringLiteral(
"layerName" ) );
250 QString layerSource = terrainElement.attribute( QStringLiteral(
"layerSource" ) );
251 QString layerProvider = terrainElement.attribute( QStringLiteral(
"layerProvider" ) );
260 QDomElement element = document.createElement( QStringLiteral(
"TerrainProvider" ) );
263 element.setAttribute( QStringLiteral(
"layer" ), mMeshLayer.
layerId );
264 element.setAttribute( QStringLiteral(
"layerName" ), mMeshLayer.
name );
265 element.setAttribute( QStringLiteral(
"layerSource" ), mMeshLayer.
source );
266 element.setAttribute( QStringLiteral(
"layerProvider" ), mMeshLayer.
provider );
280 if ( mTriangularMesh.
vertices().empty() && mMeshLayer && QThread::currentThread() == QCoreApplication::instance()->thread() )
283 return QgsMeshLayerUtils::interpolateZForPoint( mTriangularMesh, x, y ) *
mScale +
mOffset;
299 || mMeshLayer.
get() != otherTerrain->
layer() )
307 Q_ASSERT_X( QThread::currentThread() == QCoreApplication::instance()->thread(),
"QgsMeshTerrainProvider::prepare",
"prepare() must be called from the main thread" );
322 return mMeshLayer.
get();
327 , 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
Constructor for QgsAbstractTerrainProvider.
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
Constructor for QgsFlatTerrainProvider.
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
Constructor for QgsMeshTerrainProvider.
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
Constructor for QgsRasterDemTerrainProvider.
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.
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)
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.