38 , mFeedback( feedback )
39 , mInterpolation( interpolation )
44 delete mTriangulation;
45 delete mTriangleInterpolator;
50 if ( !mIsInitialized )
55 if ( !mTriangleInterpolator )
61 if ( !mTriangleInterpolator->calcPoint( x, y, r ) )
76 mTriangulationSink = sink;
79void QgsTinInterpolator::initialize()
90 mTriangulation = dualEdgeTriangulation;
94 long long nFeatures = 0;
95 long long nProcessedFeatures = 0;
102 nFeatures += layer.source->featureCount();
107 const QgsCoordinateReferenceSystem crs = !
mLayerData.empty() ?
mLayerData.at( 0 ).source->sourceCrs() : QgsCoordinateReferenceSystem();
115 switch ( layer.valueSource )
118 attList.push_back( layer.interpolationAttribute );
126 QgsFeatureIterator fit = layer.source->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( attList ).setDestinationCrs( crs, layer.transformContext ) );
132 if ( mFeedback->isCanceled() )
137 mFeedback->setProgress( 100.0 *
static_cast<double>( nProcessedFeatures ) / nFeatures );
139 insertData( f, layer.valueSource, layer.interpolationAttribute, layer.sourceType );
140 ++nProcessedFeatures;
147 NormVecDecorator *dec =
dynamic_cast<NormVecDecorator *
>( mTriangulation );
150 auto ctInterpolator = std::make_unique<CloughTocherInterpolator>();
152 ctInterpolator->setTriangulation( dec );
153 mTriangleInterpolator = ctInterpolator.release();
159 mTriangleInterpolator =
new LinTriangleInterpolator( dualEdgeTriangulation );
161 mIsInitialized =
true;
164 if ( mTriangulationSink )
179 double attributeValue = 0;
180 bool attributeConversionOk =
false;
185 QVariant attributeVariant = f.
attribute( attr );
190 attributeValue = attributeVariant.toDouble( &attributeConversionOk );
191 if ( !attributeConversionOk || std::isnan( attributeValue ) )
215 if ( addPointsFromGeometry( g, source, attributeValue ) != 0 )
227 if ( addPointsFromGeometry( g, source, attributeValue ) != 0 )
236 std::vector<const QgsCurve *> curves;
239 std::vector<const QgsCurvePolygon *> polygons;
253 for (
const QgsCurvePolygon *polygon : polygons )
258 if ( polygon->exteriorRing() )
259 curves.emplace_back( polygon->exteriorRing() );
261 for (
int i = 0; i < polygon->numInteriorRings(); ++i )
263 curves.emplace_back( polygon->interiorRing( i ) );
274 curves.emplace_back( mc->
curveN( i ) );
283 for (
const QgsCurve *curve : curves )
289 curve->points( linePoints );
290 for ( QgsPoint &point : linePoints )
296 point.setZ( attributeValue );
298 point.addZValue( attributeValue );
303 point.setZ( point.m() );
305 point.addZValue( point.m() );
312 mTriangulation->addLine( linePoints, type );
349 if ( mTriangulation->addPoint( QgsPoint( p.
x(), p.
y(), z ) ) == -100 )
Decorator class which adds the functionality of estimating normals at the data points.
void setTriangleInterpolator(TriangleInterpolator *inter) override
Sets an interpolator.
bool estimateFirstDerivatives(QgsFeedback *feedback=nullptr)
This method adds the functionality of estimating normals at the data points. Return true in the case ...
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
DualEdgeTriangulation is an implementation of a triangulation class based on the dual edge data struc...
bool saveTriangulation(QgsFeatureSink *sink, QgsFeedback *feedback=nullptr) const override
Saves the triangulation features to a feature sink.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
An interface for objects which accept features via addFeature(s) methods.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Container of fields for a vector layer.
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsAbstractGeometry::vertex_iterator vertices_begin() const
Returns STL-style iterator pointing to the first vertex of the geometry.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
QgsAbstractGeometry::vertex_iterator vertices_end() const
Returns STL-style iterator pointing to the imaginary vertex after the last vertex of the geometry.
QgsInterpolator(const QList< QgsInterpolator::LayerData > &layerData)
ValueSource
Source for interpolated values from features.
@ Z
Use feature's geometry Z values for interpolation.
@ M
Use feature's geometry M values for interpolation.
@ Attribute
Take value from feature's attribute.
SourceType
Describes the type of input data.
@ StructureLines
Structure lines.
QList< LayerData > mLayerData
Information about the input vector layers and the attributes (or z-values) that are used for interpol...
QgsCurve * curveN(int index)
Returns the curve with the specified index.
Point geometry type, with support for z-dimension and m-values.
QgsTinInterpolator(const QList< QgsInterpolator::LayerData > &inputData, QgsTinInterpolator::TinInterpolation interpolation=QgsTinInterpolator::TinInterpolation::Linear, QgsFeedback *feedback=nullptr)
Constructor for QgsTinInterpolator.
~QgsTinInterpolator() override
int interpolatePoint(double x, double y, double &result, QgsFeedback *feedback) override
Calculates interpolation value for map coordinates x, y.
static QgsFields triangulationFields()
Returns the fields output by features when saving the triangulation.
void setTriangulationSink(QgsFeatureSink *sink)
Sets the optional sink for saving the triangulation features.
TinInterpolation
Indicates the type of interpolation to be performed.
@ CloughTocher
Clough-Tocher interpolation.
static QgsFields triangulationFields()
Returns the fields output by features when calling saveTriangulation().
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
virtual void addTriangulation(QgsTriangulation *t)
Adds an association to a triangulation.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QVector< QgsPoint > QgsPointSequence
QList< int > QgsAttributeList
A source together with the information about interpolation attribute / z-coordinate interpolation and...