38 , mIsInitialized( false )
39 , mFeedback( feedback )
40 , mInterpolation( interpolation )
46 delete mTriangulation;
47 delete mTriangleInterpolator;
52 if ( !mIsInitialized )
57 if ( !mTriangleInterpolator )
63 if ( !mTriangleInterpolator->calcPoint( x, y, r ) )
78 mTriangulationSink = sink;
81void QgsTinInterpolator::initialize()
92 mTriangulation = dualEdgeTriangulation;
96 long long nFeatures = 0;
97 long long nProcessedFeatures = 0;
104 nFeatures += layer.source->featureCount();
109 const QgsCoordinateReferenceSystem crs = !
mLayerData.empty() ?
mLayerData.at( 0 ).source->sourceCrs() : QgsCoordinateReferenceSystem();
117 switch ( layer.valueSource )
120 attList.push_back( layer.interpolationAttribute );
128 QgsFeatureIterator fit = layer.source->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( attList ).setDestinationCrs( crs, layer.transformContext ) );
134 if ( mFeedback->isCanceled() )
139 mFeedback->setProgress( 100.0 *
static_cast<double>( nProcessedFeatures ) / nFeatures );
141 insertData( f, layer.valueSource, layer.interpolationAttribute, layer.sourceType );
142 ++nProcessedFeatures;
149 NormVecDecorator *dec =
dynamic_cast<NormVecDecorator *
>( mTriangulation );
152 auto ctInterpolator = std::make_unique<CloughTocherInterpolator>();
154 ctInterpolator->setTriangulation( dec );
155 mTriangleInterpolator = ctInterpolator.release();
161 mTriangleInterpolator =
new LinTriangleInterpolator( dualEdgeTriangulation );
163 mIsInitialized =
true;
166 if ( mTriangulationSink )
181 double attributeValue = 0;
182 bool attributeConversionOk =
false;
187 QVariant attributeVariant = f.
attribute( attr );
192 attributeValue = attributeVariant.toDouble( &attributeConversionOk );
193 if ( !attributeConversionOk || std::isnan( attributeValue ) )
217 if ( addPointsFromGeometry( g, source, attributeValue ) != 0 )
229 if ( addPointsFromGeometry( g, source, attributeValue ) != 0 )
238 std::vector<const QgsCurve *> curves;
241 std::vector<const QgsCurvePolygon *> polygons;
255 for (
const QgsCurvePolygon *polygon : polygons )
260 if ( polygon->exteriorRing() )
261 curves.emplace_back( polygon->exteriorRing() );
263 for (
int i = 0; i < polygon->numInteriorRings(); ++i )
265 curves.emplace_back( polygon->interiorRing( i ) );
276 curves.emplace_back( mc->
curveN( i ) );
285 for (
const QgsCurve *curve : curves )
291 curve->points( linePoints );
292 for ( QgsPoint &point : linePoints )
298 point.setZ( attributeValue );
300 point.addZValue( attributeValue );
305 point.setZ( point.m() );
307 point.addZValue( point.m() );
314 mTriangulation->addLine( linePoints, type );
351 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...