QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
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 )
QgsCoordinateReferenceSystem crs() const override
Returns the native coordinate reference system of the terrain provider.
QgsCoordinateReferenceSystem crs
QgsCoordinateReferenceSystem crs() const override
Returns the native coordinate reference system of the terrain provider.
const QVector< QgsMeshVertex > & vertices() const
Returns vertices in map coordinate system.
bool equals(const QgsAbstractTerrainProvider *other) const override
Returns true if the provider is equal to other.
The class is used as a container of context for various read/write operations on other objects.
QgsFlatTerrainProvider * clone() const override
Creates a clone of the provider and returns the new object.
QgsMeshLayer * layer() const
Returns the mesh layer to be used as the terrain source.
QgsMeshTerrainProvider()=default
Constructor for QgsMeshTerrainProvider.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the terrain provider state from a DOM element.
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.
double heightAt(double x, double y) const override
Returns the height at the point (x,y) in the terrain provider's native crs().
QgsRasterDemTerrainProvider * clone() const override
Creates a clone of the provider and returns the new object.
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.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QgsRasterDataProvider * clone() const override=0
Clone itself, create deep copy.
void updateTriangularMesh(const QgsCoordinateTransform &transform=QgsCoordinateTransform())
Gets native mesh and updates (creates if it doesn't exist) the base triangular mesh.
QString layerId
Original layer ID.
virtual QString type() const =0
Returns the unique type ID string for the provider.
void prepare() override
Called on the main thread prior to accessing the provider from a background thread.
QgsCoordinateReferenceSystem crs() const override
Returns the native coordinate reference system of the terrain provider.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString provider
Weak reference to layer provider.
double heightAt(double x, double y) const override
Returns the height at the point (x,y) in the terrain provider's native crs().
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
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.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QString type() const override
Returns the unique type ID string for the provider.
QString name
Weak reference to layer name.
void setLayer(QgsRasterLayer *layer)
Sets the raster layer with elevation model to be used as the terrain source.
Represents a raster layer.
This class represents a coordinate reference system (CRS).
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const override
Returns a DOM element representing the state of the terrain provider.
bool equals(const QgsAbstractTerrainProvider *other) const override
Returns true if the provider is equal to other.
double mScale
Scale factor.
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const override
Returns a DOM element representing the state of the terrain provider.
A class to represent a 2D point.
QgsAbstractTerrainProvider()=default
Constructor for QgsAbstractTerrainProvider.
QgsMeshTerrainProvider * clone() const override
Creates a clone of the provider and returns the new object.
void resolveReferences(const QgsProject *project) override
Resolves reference to layers from stored layer ID (if it has not been resolved already)
void writeCommonProperties(QDomElement &element, const QgsReadWriteContext &context) const
Writes common properties to a DOM element.
QString source
Weak reference to layer public source.
QString type() const override
Returns the unique type ID string for the provider.
QgsRasterDemTerrainProvider()=default
Constructor for QgsRasterDemTerrainProvider.
double heightAt(double x, double y) const override
Returns the height at the point (x,y) in the terrain provider's native crs().
A terrain provider where the terrain source is a raster DEM layer.
virtual ~QgsAbstractTerrainProvider()
void readCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Reads common properties from a DOM element.
void prepare() override
Called on the main thread prior to accessing the provider from a background thread.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the terrain provider state from a DOM element.
bool readXml(const QDomElement &element, const QgsReadWriteContext &context) override
Reads the terrain provider state from a DOM element.
QDomElement writeXml(QDomDocument &document, const QgsReadWriteContext &context) const override
Returns a DOM element representing the state of the terrain provider.
QgsRasterLayer * layer() const
Returns the raster layer with elevation model to be used as the terrain source.
Abstract base class for terrain providers.
virtual void resolveReferences(const QgsProject *project)
Resolves reference to layers from stored layer ID (if it has not been resolved already)
bool equals(const QgsAbstractTerrainProvider *other) const override
Returns true if the provider is equal to other.
void setLayer(QgsMeshLayer *layer)
Sets the mesh layer to be used as the terrain source.
TYPE * resolve(const QgsProject *project)
Resolves the map layer by attempting to find a layer with matching ID within a project.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
QgsFlatTerrainProvider()=default
Constructor for QgsFlatTerrainProvider.
double scale() const
Returns the vertical scale factor, which can be used to exaggerate vertical heights.
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.
double offset() const
Returns the vertical offset value, used for adjusting the heights from the terrain provider.
double mOffset
Offset amount.
void resolveReferences(const QgsProject *project) override
Resolves reference to layers from stored layer ID (if it has not been resolved already)
A terrain provider where the terrain is a simple flat surface.