50using namespace Qt::StringLiterals;
63 QVector<QgsGeometry> res;
67 for (
const Feature &feature : it.value() )
69 res.append( feature.geometry );
81 return asIndividualFeatures(
type, feedback );
96 return snapPointToIndividualFeatures( point, context );
107 auto visitFeature = [&ids](
QgsFeatureId featureId ) { ids << featureId; };
109 visitFeaturesInRange( distanceRange, elevationRange, visitFeature );
113 QVector< QVariantMap> idsList;
114 for (
auto it = ids.constBegin(); it != ids.constEnd(); ++it )
115 idsList.append( QVariantMap( { { u
"id"_s, *it } } ) );
122 QHash< QgsFeatureId, QVariantMap >
features;
123 auto visitFeature = [&
features](
QgsFeatureId featureId,
double delta,
double distance,
double elevation ) {
124 auto it =
features.find( featureId );
127 features[featureId] = QVariantMap( { { u
"id"_s, featureId }, { u
"delta"_s, delta }, { u
"distance"_s, distance }, { u
"elevation"_s, elevation } } );
131 const double currentDelta = it.value().value( u
"delta"_s ).toDouble();
132 if ( delta < currentDelta )
134 *it = QVariantMap( { { u
"id"_s, featureId }, { u
"delta"_s, delta }, { u
"distance"_s, distance }, { u
"elevation"_s, elevation } } );
141 QVector< QVariantMap> attributes;
143 attributes.append( *it );
145 QVector<QgsProfileIdentifyResults> res;
147 if ( !attributes.empty() )
153 res.reserve( surfaceResults.size() );
166 double bestSnapDistance = std::numeric_limits< double >::max();
168 auto visitFeature = [&bestSnapDistance, &res](
QgsFeatureId,
double delta,
double distance,
double elevation ) {
169 if ( distance < bestSnapDistance )
171 bestSnapDistance = delta;
181void QgsVectorLayerProfileResults::visitFeaturesAtPoint(
183 double maximumPointDistanceDelta,
184 double maximumPointElevationDelta,
185 double maximumSurfaceElevationDelta,
186 const std::function<
void(
QgsFeatureId,
double delta,
double distance,
double elevation ) > &visitor,
196 for (
const Feature &feature : it.value() )
198 const QgsRectangle featureBounds = feature.crossSectionGeometry.boundingBox();
199 if ( ( featureBounds.
xMinimum() - maximumPointDistanceDelta <= point.
distance() ) && ( featureBounds.
xMaximum() + maximumPointDistanceDelta >= point.
distance() ) )
201 switch ( feature.crossSectionGeometry.type() )
205 for (
auto partIt = feature.crossSectionGeometry.const_parts_begin(); partIt != feature.crossSectionGeometry.const_parts_end(); ++partIt )
209 const double snapDistanceDelta = std::fabs( point.
distance() - candidatePoint->x() );
210 if ( snapDistanceDelta > maximumPointDistanceDelta )
213 const double snapHeightDelta = std::fabs( point.
elevation() - candidatePoint->y() );
214 if ( snapHeightDelta > maximumPointElevationDelta )
217 const double snapDistance = candidatePoint->distance( targetPoint );
218 visitor( feature.featureId, snapDistance, candidatePoint->x(), candidatePoint->y() );
226 for (
auto partIt = feature.crossSectionGeometry.const_parts_begin(); partIt != feature.crossSectionGeometry.const_parts_end(); ++partIt )
233 if ( lineString->numPoints() == 2 &&
qgsDoubleNear( lineString->pointN( 0 ).x(), lineString->pointN( 1 ).x() ) )
235 const double snapDistanceDelta = std::fabs( point.
distance() - lineString->pointN( 0 ).x() );
236 if ( snapDistanceDelta > maximumPointDistanceDelta )
239 const double snapHeightDelta = std::fabs( point.
elevation() - lineString->pointN( 0 ).y() );
240 if ( snapHeightDelta <= maximumPointElevationDelta )
242 const double snapDistanceP1 = lineString->pointN( 0 ).distance( targetPoint );
243 visitor( feature.featureId, snapDistanceP1, lineString->pointN( 0 ).x(), lineString->pointN( 0 ).y() );
246 const double snapHeightDelta2 = std::fabs( point.
elevation() - lineString->pointN( 1 ).y() );
247 if ( snapHeightDelta2 <= maximumPointElevationDelta )
249 const double snapDistanceP2 = lineString->pointN( 1 ).distance( targetPoint );
250 visitor( feature.featureId, snapDistanceP2, lineString->pointN( 1 ).x(), lineString->pointN( 1 ).y() );
255 double elevation1 = lineString->pointN( 0 ).y();
256 double elevation2 = lineString->pointN( 1 ).y();
257 if ( elevation1 > elevation2 )
258 std::swap( elevation1, elevation2 );
262 const double snapDistance = std::fabs( lineString->pointN( 0 ).x() - point.
distance() );
263 visitor( feature.featureId, snapDistance, lineString->pointN( 0 ).x(), point.
elevation() );
270 const QgsRectangle partBounds = ( *partIt )->boundingBox();
277 QgsGeos cutLineGeos( cutLine.constGet() );
279 const QgsGeometry points( cutLineGeos.intersection( line ) );
281 for (
auto vertexIt = points.vertices_begin(); vertexIt != points.vertices_end(); ++vertexIt )
283 const double snapHeightDelta = std::fabs( point.
elevation() - ( *vertexIt ).y() );
284 if ( snapHeightDelta > maximumSurfaceElevationDelta )
287 const double snapDistance = ( *vertexIt ).distance( targetPoint );
288 visitor( feature.featureId, snapDistance, ( *vertexIt ).x(), ( *vertexIt ).y() );
305 for (
auto partIt = feature.crossSectionGeometry.const_parts_begin(); partIt != feature.crossSectionGeometry.const_parts_end(); ++partIt )
309 const QgsRectangle partBounds = ( *partIt )->boundingBox();
316 QgsGeos cutLineGeos( cutLine.constGet() );
318 const QgsGeometry points( cutLineGeos.intersection( exterior ) );
319 for (
auto vertexIt = points.vertices_begin(); vertexIt != points.vertices_end(); ++vertexIt )
321 const double snapHeightDelta = std::fabs( point.
elevation() - ( *vertexIt ).y() );
322 if ( snapHeightDelta > maximumSurfaceElevationDelta )
325 const double snapDistance = ( *vertexIt ).distance( targetPoint );
326 visitor( feature.featureId, snapDistance, ( *vertexIt ).x(), ( *vertexIt ).y() );
344 const QgsRectangle profileRange( distanceRange.
lower(), elevationRange.
lower(), distanceRange.
upper(), elevationRange.
upper() );
346 QgsGeos profileRangeGeos( profileRangeGeometry.
constGet() );
347 profileRangeGeos.prepareGeometry();
351 for (
const Feature &feature : it.value() )
353 if ( feature.crossSectionGeometry.boundingBoxIntersects( profileRange ) )
355 switch ( feature.crossSectionGeometry.type() )
359 for (
auto partIt = feature.crossSectionGeometry.const_parts_begin(); partIt != feature.crossSectionGeometry.const_parts_end(); ++partIt )
363 if ( profileRange.contains( candidatePoint->x(), candidatePoint->y() ) )
365 visitor( feature.featureId );
375 if ( profileRangeGeos.intersects( feature.crossSectionGeometry.constGet() ) )
377 visitor( feature.featureId );
397 renderResultsAsIndividualFeatures( context );
402 renderMarkersOverContinuousSurfacePlot( context );
415 painter->setBrush( Qt::NoBrush );
416 painter->setPen( Qt::NoPen );
423 const QRectF visibleRegion( minDistance,
minZ, maxDistance - minDistance,
maxZ -
minZ );
424 QPainterPath clipPath;
425 clipPath.addPolygon( context.
worldTransform().map( visibleRegion ) );
426 painter->setClipPath( clipPath, Qt::ClipOperation::IntersectClip );
428 const QgsRectangle clipPathRect( clipPath.boundingRect() );
431 if ( profileFeature.crossSectionGeometry.isEmpty() )
434 QgsGeometry transformed = profileFeature.crossSectionGeometry;
441 switch ( transformed.
type() )
447 markerSymbol->renderPoint( QPointF( point->x(), point->y() ),
nullptr, context.
renderContext() );
451 const int numGeometries = multipoint->numGeometries();
452 for (
int i = 0; i < numGeometries; ++i )
454 markerSymbol->renderPoint( QPointF( multipoint->pointN( i )->x(), multipoint->pointN( i )->y() ),
nullptr, context.
renderContext() );
464 lineSymbol->renderPolyline( line->asQPolygonF(),
nullptr, context.
renderContext() );
468 const int numGeometries = multiLinestring->numGeometries();
469 for (
int i = 0; i < numGeometries; ++i )
471 lineSymbol->renderPolyline( multiLinestring->lineStringN( i )->asQPolygonF(),
nullptr, context.
renderContext() );
481 if (
const QgsCurve *exterior = polygon->exteriorRing() )
482 fillSymbol->renderPolygon( exterior->asQPolygonF(),
nullptr,
nullptr, context.
renderContext() );
486 const int numGeometries = multiPolygon->numGeometries();
487 for (
int i = 0; i < numGeometries; ++i )
489 fillSymbol->renderPolygon( multiPolygon->polygonN( i )->exteriorRing()->asQPolygonF(),
nullptr,
nullptr, context.
renderContext() );
501 QgsFeatureRequest req;
506 std::unique_ptr< QgsFeatureRenderer > renderer(
mLayer->renderer()->clone() );
511 QSet<QString> attributes = renderer->usedAttributes( context.
renderContext() );
513 std::unique_ptr< QgsMarkerSymbol > marker(
mMarkerSymbol->clone() );
514 std::unique_ptr< QgsLineSymbol > line(
mLineSymbol->clone() );
515 std::unique_ptr< QgsFillSymbol > fill(
mFillSymbol->clone() );
516 attributes.unite( marker->usedAttributes( context.
renderContext() ) );
517 attributes.unite( line->usedAttributes( context.
renderContext() ) );
518 attributes.unite( fill->usedAttributes( context.
renderContext() ) );
523 QgsFeatureIterator it =
mLayer->getFeatures( req );
528 for ( QgsSymbol *rendererSymbol : rendererSymbols )
530 if ( !rendererSymbol )
533 marker->setColor( rendererSymbol->color() );
534 marker->setOpacity( rendererSymbol->opacity() );
535 line->setColor( rendererSymbol->color() );
536 line->setOpacity( rendererSymbol->opacity() );
537 fill->setColor( rendererSymbol->color() );
538 fill->setOpacity( rendererSymbol->opacity() );
544 const QVector< Feature > profileFeatures =
features.value( feature.
id() );
545 for (
const Feature &profileFeature : profileFeatures )
549 rendererSymbol->type() ==
Qgis::SymbolType::Marker ? qgis::down_cast< QgsMarkerSymbol * >( rendererSymbol ) : marker.get(),
550 rendererSymbol->type() ==
Qgis::SymbolType::Line ? qgis::down_cast< QgsLineSymbol * >( rendererSymbol ) : line.get(),
551 rendererSymbol->type() ==
Qgis::SymbolType::Fill ? qgis::down_cast< QgsFillSymbol * >( rendererSymbol ) : fill.get()
565 QSet<QString> attributes;
576 QgsFeatureIterator it =
mLayer->getFeatures( req );
580 const QVector< Feature > profileFeatures =
features.value( feature.
id() );
581 for (
const Feature &profileFeature : profileFeatures )
598 const QgsScopedQPainterState painterState( painter );
600 painter->setBrush( Qt::NoBrush );
601 painter->setPen( Qt::NoPen );
608 const QRectF visibleRegion( minDistance,
minZ, maxDistance - minDistance,
maxZ -
minZ );
609 QPainterPath clipPath;
610 clipPath.addPolygon( context.
worldTransform().map( visibleRegion ) );
611 painter->setClipPath( clipPath, Qt::ClipOperation::IntersectClip );
617 QHash< QgsFeatureId, QgsFeature > surfaceFeatures;
620 QgsFeatureRequest request;
624 QgsFeatureIterator featIt =
mLayer->getFeatures( request );
627 surfaceFeatures.insert( feature.
id(), feature );
633 if ( std::isnan( pointIt.value() ) )
646 QVector<QgsAbstractProfileResults::Feature> res;
653 for (
const Feature &feature : it.value() )
658 QgsAbstractProfileResults::Feature outFeature;
660 outFeature.
attributes = { { u
"id"_s, feature.featureId } };
668 outFeature.
geometry = feature.crossSectionGeometry;
685 mId = vlGenerator->mId;
688 mMarkerSymbol.reset( vlGenerator->mProfileMarkerSymbol->clone() );
700 , mProfileCurve( request.profileCurve() ? request.profileCurve()->clone() : nullptr )
701 , mTerrainProvider( request.terrainProvider() ? request.terrainProvider()->clone() : nullptr )
702 , mTolerance( request.tolerance() )
703 , mSourceCrs( layer->crs3D() )
704 , mTargetCrs( request.crs() )
705 , mTransformContext( request.transformContext() )
706 , mExtent( layer->extent() )
708 , mOffset( layer->elevationProperties()->zOffset() )
709 , mScale( layer->elevationProperties()->zScale() )
717 , mExpressionContext( request.expressionContext() )
718 , mFields( layer->fields() )
719 , mDataDefinedProperties( layer->elevationProperties()->dataDefinedProperties() )
720 , mWkbType( layer->wkbType() )
726 if ( mTerrainProvider )
727 mTerrainProvider->prepare();
731 mProfileCurve->dropZValue();
754 if ( !mProfileCurve || mFeedback->isCanceled() )
763 std::unique_ptr< QgsCurve > origCurve = std::move( mProfileCurve );
764 std::unique_ptr< QgsVectorLayerProfileResults > totalResults;
765 double distanceProcessed = 0;
767 QVector<QgsLineString *> disjointParts = profileLine->splitToDisjointXYParts();
768 for (
int i = 0; i < disjointParts.size(); i++ )
770 mProfileCurve.reset( disjointParts[i] );
771 if ( !generateProfileInner() )
773 mProfileCurve = std::move( origCurve );
776 for (
int j = i + 1; j < disjointParts.size(); j++ )
777 delete disjointParts[j];
784 totalResults = std::move( mResults );
788 totalResults->mRawPoints.append( mResults->mRawPoints );
789 totalResults->minZ = std::min( totalResults->minZ, mResults->minZ );
790 totalResults->maxZ = std::max( totalResults->maxZ, mResults->maxZ );
791 for (
auto it = mResults->mDistanceToHeightMap.constKeyValueBegin(); it != mResults->mDistanceToHeightMap.constKeyValueEnd(); ++it )
793 totalResults->mDistanceToHeightMap[it->first + distanceProcessed] = it->second;
795 for (
auto it = mResults->mDistanceToFeatureId.constKeyValueBegin(); it != mResults->mDistanceToFeatureId.constKeyValueEnd(); ++it )
797 totalResults->mDistanceToFeatureId[it->first + distanceProcessed] = it->second;
799 for (
auto it = mResults->features.constKeyValueBegin(); it != mResults->features.constKeyValueEnd(); ++it )
804 totalResults->features[it->first].push_back( feature );
809 distanceProcessed += mProfileCurve->length();
812 mProfileCurve = std::move( origCurve );
813 mResults = std::move( totalResults );
817 return generateProfileInner();
825 if ( mTerrainProvider )
826 mTargetToTerrainProviderTransform =
QgsCoordinateTransform( mTargetCrs, mTerrainProvider->crs(), mTransformContext );
832 catch ( QgsCsException & )
834 QgsDebugError( u
"Error transforming profile line to vector CRS"_s );
838 const QgsRectangle profileCurveBoundingBox = mTransformedCurve->boundingBox();
839 if ( !profileCurveBoundingBox.
intersects( mExtent ) )
842 if ( mFeedback->isCanceled() )
845 mResults = std::make_unique< QgsVectorLayerProfileResults >();
846 mResults->mLayer = mLayer;
847 mResults->copyPropertiesFromGenerator(
this );
849 mProfileCurveEngine = std::make_unique<QgsGeos>( mProfileCurve.get() );
850 mProfileCurveEngine->prepareGeometry();
852 if ( tolerance() == 0.0 )
854 mProfileBufferedCurve = std::unique_ptr<QgsAbstractGeometry>( mProfileCurve->clone() );
861 mProfileBufferedCurveEngine = std::make_unique<QgsGeos>( mProfileBufferedCurve.get() );
862 mProfileBufferedCurveEngine->prepareGeometry();
864 mDataDefinedProperties.prepare( mExpressionContext );
866 if ( mFeedback->isCanceled() )
872 if ( !generateProfileForPoints() )
877 if ( !generateProfileForLines() )
882 if ( !generateProfileForPolygons() )
896 return mResults.release();
901 return mFeedback.get();
904bool QgsVectorLayerProfileGenerator::generateProfileForPoints()
919 while ( !mFeedback->isCanceled() && it.
nextFeature( feature ) )
926 if ( mProfileBufferedCurveEngine->intersects( *it ) )
932 return !mFeedback->isCanceled();
935void QgsVectorLayerProfileGenerator::processIntersectionPoint(
const QgsPoint *point,
const QgsFeature &feature )
940 const double height = featureZToHeight( point->
x(), point->
y(), point->
z(), offset );
941 mResults->mRawPoints.append( QgsPoint( point->
x(), point->
y(), height ) );
942 mResults->minZ = std::min( mResults->minZ, height );
943 mResults->maxZ = std::max( mResults->maxZ, height );
945 const double distanceAlongProfileCurve = mProfileCurveEngine->lineLocatePoint( *point, &error );
946 mResults->mDistanceToHeightMap.insert( distanceAlongProfileCurve, height );
947 mResults->mDistanceToFeatureId.insert( distanceAlongProfileCurve, feature.
id() );
949 QgsVectorLayerProfileResults::Feature resultFeature;
951 if ( mExtrusionEnabled )
955 resultFeature.
geometry = QgsGeometry(
new QgsLineString( QgsPoint( point->
x(), point->
y(), height ), QgsPoint( point->
x(), point->
y(), height + extrusion ) ) );
956 resultFeature.
crossSectionGeometry = QgsGeometry(
new QgsLineString( QgsPoint( distanceAlongProfileCurve, height ), QgsPoint( distanceAlongProfileCurve, height + extrusion ) ) );
957 mResults->minZ = std::min( mResults->minZ, height + extrusion );
958 mResults->maxZ = std::max( mResults->maxZ, height + extrusion );
962 resultFeature.
geometry = QgsGeometry(
new QgsPoint( point->
x(), point->
y(), height ) );
963 resultFeature.
crossSectionGeometry = QgsGeometry(
new QgsPoint( distanceAlongProfileCurve, height ) );
966 mResults->features[resultFeature.
featureId].append( resultFeature );
969void QgsVectorLayerProfileGenerator::processIntersectionCurve(
const QgsLineString *intersectionCurve,
const QgsFeature &feature )
973 QgsVectorLayerProfileResults::Feature resultFeature;
975 double maxDistanceAlongProfileCurve = std::numeric_limits<double>::lowest();
980 const int numPoints = intersectionCurve->
numPoints();
981 QVector< double > newX( numPoints );
982 QVector< double > newY( numPoints );
983 QVector< double > newZ( numPoints );
984 QVector< double > newDistance( numPoints );
986 const double *inX = intersectionCurve->
xData();
987 const double *inY = intersectionCurve->
yData();
988 const double *inZ = intersectionCurve->
is3D() ? intersectionCurve->
zData() :
nullptr;
989 double *outX = newX.data();
990 double *outY = newY.data();
991 double *outZ = newZ.data();
992 double *outDistance = newDistance.data();
994 QVector< double > extrudedZ;
995 double *extZOut =
nullptr;
996 if ( mExtrusionEnabled )
998 extrudedZ.resize( numPoints );
999 extZOut = extrudedZ.data();
1002 for (
int i = 0; !mFeedback->isCanceled() && i < numPoints; ++i )
1004 QgsPoint intersectionPoint( *inX, *inY, ( inZ ? *inZ : std::numeric_limits<double>::quiet_NaN() ) );
1006 const double height = featureZToHeight( intersectionPoint.x(), intersectionPoint.y(), intersectionPoint.z(), offset );
1007 const double distanceAlongProfileCurve = mProfileCurveEngine->lineLocatePoint( intersectionPoint, &error );
1009 maxDistanceAlongProfileCurve = std::max( maxDistanceAlongProfileCurve, distanceAlongProfileCurve );
1011 mResults->mRawPoints.append( QgsPoint( intersectionPoint.x(), intersectionPoint.y(), height ) );
1012 mResults->minZ = std::min( mResults->minZ, height );
1013 mResults->maxZ = std::max( mResults->maxZ, height );
1015 mResults->mDistanceToHeightMap.insert( distanceAlongProfileCurve, height );
1016 mResults->mDistanceToFeatureId.insert( distanceAlongProfileCurve, feature.
id() );
1017 *outDistance++ = distanceAlongProfileCurve;
1019 *outX++ = intersectionPoint.x();
1020 *outY++ = intersectionPoint.y();
1023 *extZOut++ = height + extrusion;
1025 if ( mExtrusionEnabled )
1027 mResults->minZ = std::min( mResults->minZ, height + extrusion );
1028 mResults->maxZ = std::max( mResults->maxZ, height + extrusion );
1036 mResults->mDistanceToHeightMap.insert( maxDistanceAlongProfileCurve +
Qgis::DEFAULT_SEGMENT_EPSILON, std::numeric_limits<double>::quiet_NaN() );
1038 if ( mFeedback->isCanceled() )
1042 if ( mExtrusionEnabled )
1044 auto ring = std::make_unique< QgsLineString >( newX, newY, newZ );
1045 auto extrudedRing = std::make_unique< QgsLineString >( newX, newY, extrudedZ );
1046 std::unique_ptr< QgsLineString > reversedExtrusion( extrudedRing->reversed() );
1047 ring->append( reversedExtrusion.get() );
1049 resultFeature.
geometry = QgsGeometry(
new QgsPolygon( ring.release() ) );
1051 auto distanceVHeightRing = std::make_unique< QgsLineString >( newDistance, newZ );
1052 auto extrudedDistanceVHeightRing = std::make_unique< QgsLineString >( newDistance, extrudedZ );
1053 std::unique_ptr< QgsLineString > reversedDistanceVHeightExtrusion( extrudedDistanceVHeightRing->reversed() );
1054 distanceVHeightRing->append( reversedDistanceVHeightExtrusion.get() );
1055 distanceVHeightRing->close();
1056 resultFeature.
crossSectionGeometry = QgsGeometry(
new QgsPolygon( distanceVHeightRing.release() ) );
1060 resultFeature.
geometry = QgsGeometry(
new QgsLineString( newX, newY, newZ ) );
1064 mResults->features[resultFeature.
featureId].append( resultFeature );
1067bool QgsVectorLayerProfileGenerator::generateProfileForLines()
1070 QgsFeatureRequest request;
1072 if ( tolerance() > 0 )
1074 request.
setDistanceWithin( QgsGeometry( mProfileCurve->clone() ), tolerance() );
1080 request.
setSubsetOfAttributes( mDataDefinedProperties.referencedFields( mExpressionContext ), mFields );
1083 auto processCurve = [
this](
const QgsFeature &feature,
const QgsCurve *featGeomPart ) {
1085 std::unique_ptr< QgsAbstractGeometry > intersection( mProfileBufferedCurveEngine->intersection( featGeomPart, &error ) );
1086 if ( !intersection )
1089 if ( mFeedback->isCanceled() )
1094 if ( intersection->isEmpty() )
1096 intersection.reset( featGeomPart->clone() );
1097 for (
auto it = intersection->const_parts_begin(); !mFeedback->isCanceled() && it != intersection->const_parts_end(); ++it )
1100 processIntersectionCurve( intersectionCurve, feature );
1105 QgsGeos featGeomPartGeos( featGeomPart );
1106 featGeomPartGeos.prepareGeometry();
1108 for (
auto it = intersection->const_parts_begin(); !mFeedback->isCanceled() && it != intersection->const_parts_end(); ++it )
1114 const double distance = featGeomPartGeos.lineLocatePoint( *intersectionPoint, &error );
1115 std::unique_ptr< QgsPoint > interpolatedPoint( featGeomPart->interpolatePoint( distance ) );
1117 processIntersectionPoint( interpolatedPoint.get(), feature );
1123 auto lineInterpolated = std::make_unique<QgsLineString>();
1124 for (
int i = 0; i < intersectionCurve->
numPoints(); ++i )
1126 const QgsPoint pt = intersectionCurve->
pointN( i );
1129 const double distance = featGeomPartGeos.lineLocatePoint( pt, &err );
1131 std::unique_ptr<QgsPoint> pointWithInterpolatedZM( featGeomPart->interpolatePoint( distance ) );
1132 lineInterpolated->addVertex( *pointWithInterpolatedZM );
1135 processIntersectionCurve( lineInterpolated.get(), feature );
1141 QgsFeatureIterator it = mSource->getFeatures( request );
1142 while ( !mFeedback->isCanceled() && it.
nextFeature( feature ) )
1144 mExpressionContext.setFeature( feature );
1146 const QgsGeometry g = feature.
geometry();
1149 if ( mProfileBufferedCurveEngine->intersects( *it ) )
1156 return !mFeedback->isCanceled();
1159QgsPoint QgsVectorLayerProfileGenerator::interpolatePointOnTriangle(
const QgsPolygon *triangle,
double x,
double y )
const
1161 QgsPoint p1, p2, p3;
1166 const double z = QgsMeshLayerUtils::interpolateFromVerticesData( p1, p2, p3, p1.
z(), p2.
z(), p3.
z(), QgsPointXY( x, y ) );
1167 return QgsPoint( x, y, z );
1170void QgsVectorLayerProfileGenerator::processTriangleIntersectForPoint(
1171 const QgsPolygon *triangle,
const QgsPoint *p, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts,
const QgsFeatureId featureId
1174 const QgsPoint interpolatedPoint = interpolatePointOnTriangle( triangle, p->
x(), p->
y() );
1175 mResults->mRawPoints.append( interpolatedPoint );
1176 mResults->minZ = std::min( mResults->minZ, interpolatedPoint.
z() );
1177 mResults->maxZ = std::max( mResults->maxZ, interpolatedPoint.
z() );
1180 const double distance = mProfileCurveEngine->lineLocatePoint( *p, &lastError );
1181 mResults->mDistanceToHeightMap.insert( distance, interpolatedPoint.
z() );
1182 mResults->mDistanceToFeatureId.insert( distance, featureId );
1184 if ( mExtrusionEnabled )
1188 transformedParts.append( QgsGeometry(
new QgsLineString( interpolatedPoint, QgsPoint( interpolatedPoint.
x(), interpolatedPoint.
y(), interpolatedPoint.
z() + extrusion ) ) ) );
1189 crossSectionParts.append( QgsGeometry(
new QgsLineString( QgsPoint( distance, interpolatedPoint.
z() ), QgsPoint( distance, interpolatedPoint.
z() + extrusion ) ) ) );
1190 mResults->minZ = std::min( mResults->minZ, interpolatedPoint.
z() + extrusion );
1191 mResults->maxZ = std::max( mResults->maxZ, interpolatedPoint.
z() + extrusion );
1195 transformedParts.append( QgsGeometry(
new QgsPoint( interpolatedPoint ) ) );
1196 crossSectionParts.append( QgsGeometry(
new QgsPoint( distance, interpolatedPoint.
z() ) ) );
1200void QgsVectorLayerProfileGenerator::processTriangleIntersectForLine(
1201 const QgsPolygon *triangle,
const QgsLineString *intersectionLine, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts,
const QgsFeatureId featureId
1207 int numPoints = intersectionLine->
numPoints();
1208 QVector< double > newX( numPoints );
1209 QVector< double > newY( numPoints );
1210 QVector< double > newZ( numPoints );
1211 QVector< double > newDistance( numPoints );
1213 const double *inX = intersectionLine->
xData();
1214 const double *inY = intersectionLine->
yData();
1215 const double *inZ = intersectionLine->
is3D() ? intersectionLine->
zData() :
nullptr;
1216 double *outX = newX.data();
1217 double *outY = newY.data();
1218 double *outZ = newZ.data();
1219 double *outDistance = newDistance.data();
1221 double minDistanceAlongProfileCurve = std::numeric_limits< double >::max();
1222 double maxDistanceAlongProfileCurve = std::numeric_limits< double >::lowest();
1223 QVector< double > extrudedZ;
1224 double *extZOut =
nullptr;
1225 double extrusion = 0;
1227 if ( mExtrusionEnabled )
1229 extrudedZ.resize( numPoints );
1230 extZOut = extrudedZ.data();
1236 QVector< QPair< double, double > > segmentDistanceToHeight;
1237 segmentDistanceToHeight.reserve( numPoints );
1238 for (
int i = 0; !mFeedback->isCanceled() && i < numPoints; ++i )
1242 double z = inZ ? *inZ++ : 0;
1244 QgsPoint interpolatedPoint( x, y, z );
1250 interpolatedPoint = interpolatePointOnTriangle( triangle, x, y );
1252 double tempOutZ = std::isnan( interpolatedPoint.
z() ) ? 0.0 : interpolatedPoint.
z();
1255 if ( mExtrusionEnabled )
1256 *extZOut++ = tempOutZ + extrusion;
1258 mResults->mRawPoints.append( interpolatedPoint );
1259 mResults->minZ = std::min( mResults->minZ, interpolatedPoint.
z() );
1260 mResults->maxZ = std::max( mResults->maxZ, interpolatedPoint.
z() );
1261 if ( mExtrusionEnabled )
1263 mResults->minZ = std::min( mResults->minZ, interpolatedPoint.
z() + extrusion );
1264 mResults->maxZ = std::max( mResults->maxZ, interpolatedPoint.
z() + extrusion );
1267 const double distance = mProfileCurveEngine->lineLocatePoint( interpolatedPoint, &lastError );
1268 *outDistance++ = distance;
1270 segmentDistanceToHeight.append( { distance, interpolatedPoint.
z() } );
1271 minDistanceAlongProfileCurve = std::min( distance, minDistanceAlongProfileCurve );
1272 maxDistanceAlongProfileCurve = std::max( distance, maxDistanceAlongProfileCurve );
1275 if ( numPoints > 0 )
1280 for (
const QPair< double, double > &point : std::as_const( segmentDistanceToHeight ) )
1282 double distance = point.first;
1292 mResults->mDistanceToHeightMap.insert( distance, point.second );
1293 mResults->mDistanceToFeatureId.insert( distance, featureId );
1299 mSurfaceIntervals.append( { minDistanceAlongProfileCurve, maxDistanceAlongProfileCurve } );
1302 if ( mFeedback->isCanceled() )
1305 if ( mExtrusionEnabled )
1307 auto ring = std::make_unique< QgsLineString >( newX, newY, newZ );
1308 auto extrudedRing = std::make_unique< QgsLineString >( newX, newY, extrudedZ );
1309 std::unique_ptr< QgsLineString > reversedExtrusion( extrudedRing->reversed() );
1310 ring->append( reversedExtrusion.get() );
1312 transformedParts.append( QgsGeometry(
new QgsPolygon( ring.release() ) ) );
1314 auto distanceVHeightRing = std::make_unique< QgsLineString >( newDistance, newZ );
1315 auto extrudedDistanceVHeightRing = std::make_unique< QgsLineString >( newDistance, extrudedZ );
1316 std::unique_ptr< QgsLineString > reversedDistanceVHeightExtrusion( extrudedDistanceVHeightRing->reversed() );
1317 distanceVHeightRing->append( reversedDistanceVHeightExtrusion.get() );
1318 distanceVHeightRing->close();
1319 crossSectionParts.append( QgsGeometry(
new QgsPolygon( distanceVHeightRing.release() ) ) );
1323 transformedParts.append( QgsGeometry(
new QgsLineString( newX, newY, newZ ) ) );
1324 crossSectionParts.append( QgsGeometry(
new QgsLineString( newDistance, newZ ) ) );
1328void QgsVectorLayerProfileGenerator::processTriangleIntersectForPolygon(
1329 const QgsPolygon *sourcePolygon,
const QgsPolygon *intersectionPolygon, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts,
const QgsFeatureId featureId
1332 bool oldExtrusion = mExtrusionEnabled;
1365 mExtrusionEnabled =
false;
1366 if ( mProfileBufferedCurveEngine->contains( sourcePolygon ) )
1368 if (
const QgsCurve *exterior = sourcePolygon->
exteriorRing() )
1371 processTriangleIntersectForLine( sourcePolygon, exteriorLine, transformedParts, crossSectionParts, featureId );
1376 processTriangleIntersectForLine( sourcePolygon, interiorLine, transformedParts, crossSectionParts, featureId );
1382 if (
const QgsCurve *exterior = intersectionPolygon->
exteriorRing() )
1386 processTriangleIntersectForLine( sourcePolygon, exteriorLine, transformedParts, crossSectionParts, featureId );
1387 delete exteriorLine;
1392 if ( mProfileBufferedCurveEngine->contains( interiorLine ) )
1394 processTriangleIntersectForLine( sourcePolygon, interiorLine, transformedParts, crossSectionParts, featureId );
1399 newInteriorLine->deleteVertex( QgsVertexId( 0, 0, interiorLine->
numPoints() - 1 ) );
1400 processTriangleIntersectForLine( sourcePolygon, newInteriorLine.get(), transformedParts, crossSectionParts, featureId );
1405 mExtrusionEnabled = oldExtrusion;
1408bool QgsVectorLayerProfileGenerator::generateProfileForPolygons()
1411 QgsFeatureRequest request;
1413 if ( tolerance() > 0 )
1415 request.
setDistanceWithin( QgsGeometry( mProfileCurve->clone() ), tolerance() );
1421 request.
setSubsetOfAttributes( mDataDefinedProperties.referencedFields( mExpressionContext ), mFields );
1424 std::function< void(
const QgsPolygon *triangle,
const QgsAbstractGeometry *intersect, QVector< QgsGeometry > &, QVector< QgsGeometry > &,
const QgsFeatureId ) > processTriangleLineIntersect;
1425 processTriangleLineIntersect =
1426 [
this](
const QgsPolygon *triangle,
const QgsAbstractGeometry *intersection, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts,
const QgsFeatureId featureId ) {
1427 for (
auto it = intersection->const_parts_begin(); !mFeedback->isCanceled() && it != intersection->const_parts_end(); ++it )
1435 processTriangleIntersectForPoint( triangle, p, transformedParts, crossSectionParts, featureId );
1442 processTriangleIntersectForLine( triangle, intersectionLine, transformedParts, crossSectionParts, featureId );
1449 processTriangleIntersectForPolygon( triangle, poly, transformedParts, crossSectionParts, featureId );
1460 auto triangleIsCollinearInXYPlane = [](
const QgsPolygon *polygon ) ->
bool {
1465 auto processPolygon =
1467 &processTriangleLineIntersect,
1468 &triangleIsCollinearInXYPlane](
const QgsCurvePolygon *polygon, QVector< QgsGeometry > &transformedParts, QVector< QgsGeometry > &crossSectionParts,
double offset,
bool &wasCollinear,
const QgsFeatureId featureId ) {
1469 std::unique_ptr< QgsPolygon > clampedPolygon;
1472 clampedPolygon.reset( p->
clone() );
1478 clampAltitudes( clampedPolygon.get(), offset );
1480 if ( mFeedback->isCanceled() )
1483 if ( tolerance() > 0.0 )
1486 if ( mProfileBufferedCurveEngine->intersects( clampedPolygon.get(), &error ) )
1488 std::unique_ptr< QgsAbstractGeometry > intersection;
1489 intersection.reset( mProfileBufferedCurveEngine->intersection( clampedPolygon.get(), &error ) );
1490 if ( error.isEmpty() )
1492 processTriangleLineIntersect( clampedPolygon.get(), intersection.get(), transformedParts, crossSectionParts, featureId );
1501 QVector< double > newX( numPoints );
1502 QVector< double > newY( numPoints );
1503 QVector< double > newZ( numPoints );
1504 double *outX = newX.data();
1505 double *outY = newY.data();
1506 double *outZ = newZ.data();
1508 const double *inX = ring->
xData();
1509 const double *inY = ring->
yData();
1510 const double *inZ = ring->
zData();
1511 for (
int i = 0; !mFeedback->isCanceled() && i < ring->numPoints() - 1; ++i )
1513 *outX++ = inX[i] + i * 1.0e-9;
1514 *outY++ = inY[i] + i * 1.0e-9;
1517 std::unique_ptr< QgsPolygon > shiftedPoly;
1518 shiftedPoly = std::make_unique<QgsPolygon>(
new QgsLineString( newX, newY, newZ ) );
1520 intersection.reset( mProfileBufferedCurveEngine->intersection( shiftedPoly.get(), &error ) );
1522 processTriangleLineIntersect( clampedPolygon.get(), intersection.get(), transformedParts, crossSectionParts, featureId );
1526 QgsDebugMsgLevel( u
"processPolygon after shift bad geom! error: %1"_s.arg( error ), 0 );
1534 QgsGeometry tessellation;
1535 if ( clampedPolygon->numInteriorRings() == 0 && clampedPolygon->exteriorRing() && clampedPolygon->exteriorRing()->numPoints() == 4 && clampedPolygon->exteriorRing()->isClosed() )
1538 auto multiPolygon = std::make_unique< QgsMultiPolygon >();
1539 multiPolygon->addGeometry( clampedPolygon.release() );
1540 tessellation = QgsGeometry( std::move( multiPolygon ) );
1544 const QgsRectangle bounds = clampedPolygon->boundingBox();
1550 if ( mFeedback->isCanceled() )
1558 for (
int i = 0; !mFeedback->isCanceled() && i < numTriangles; ++i )
1562 if ( triangleIsCollinearInXYPlane( triangle ) )
1564 wasCollinear =
true;
1570 for (
int curveSegmentIndex = 0; curveSegmentIndex < mProfileCurve->numPoints() - 1; ++curveSegmentIndex )
1572 const QgsPoint p1 = ls->pointN( curveSegmentIndex );
1573 const QgsPoint p2 = ls->pointN( curveSegmentIndex + 1 );
1575 QgsPoint intersectionPoint;
1576 bool intersectionFound =
false;
1577 double minZ = std::numeric_limits< double >::max();
1578 double maxZ = std::numeric_limits< double >::lowest();
1580 for (
auto vertexPair : std::array<std::pair<int, int>, 3> { { { 0, 1 }, { 1, 2 }, { 2, 0 } } } )
1582 bool isIntersection =
false;
1583 QgsPoint edgeIntersectionPoint;
1586 if ( !edgeIntersectionPoint.
isEmpty() && !intersectionFound )
1588 intersectionPoint = edgeIntersectionPoint;
1589 intersectionFound =
true;
1594 ring->
xAt( vertexPair.first ), ring->
yAt( vertexPair.first ), ring->
xAt( vertexPair.second ), ring->
yAt( vertexPair.second ), edgeIntersectionPoint.
x(), edgeIntersectionPoint.
y()
1596 double intersectionZ = ring->
zAt( vertexPair.first ) + ( ring->
zAt( vertexPair.second ) - ring->
zAt( vertexPair.first ) ) * fraction;
1597 minZ = std::min( minZ, intersectionZ );
1598 maxZ = std::max( maxZ, intersectionZ );
1602 if ( intersectionFound )
1605 mResults->mRawPoints.append( intersectionPoint );
1606 mResults->minZ = std::min( mResults->minZ, minZ );
1607 mResults->maxZ = std::max( mResults->maxZ, maxZ );
1609 const double distance = mProfileCurveEngine->lineLocatePoint( intersectionPoint, &lastError );
1611 crossSectionParts.append( QgsGeometry(
new QgsLineString( QVector< double > { distance, distance }, QVector< double > { minZ, maxZ } ) ) );
1613 mResults->mDistanceToHeightMap.insert( distance, minZ );
1614 mResults->mDistanceToHeightMap.insert( distance, maxZ );
1615 mResults->mDistanceToFeatureId.insert( distance, featureId );
1622 QgsDebugError( u
"Collinear triangles with curved profile lines are not supported yet"_s );
1628 if ( mProfileBufferedCurveEngine->intersects( triangle, &error ) )
1630 std::unique_ptr< QgsAbstractGeometry > intersection( mProfileBufferedCurveEngine->intersection( triangle, &error ) );
1631 processTriangleLineIntersect( triangle, intersection.get(), transformedParts, crossSectionParts, featureId );
1640 QgsFeatureIterator it = mSource->getFeatures( request );
1641 while ( !mFeedback->isCanceled() && it.
nextFeature( feature ) )
1643 if ( !mProfileBufferedCurveEngine->intersects( feature.
geometry().
constGet() ) )
1646 mExpressionContext.setFeature( feature );
1649 const QgsGeometry g = feature.
geometry();
1650 QVector< QgsGeometry > transformedParts;
1651 QVector< QgsGeometry > crossSectionParts;
1652 bool wasCollinear =
false;
1657 if ( mProfileBufferedCurveEngine->intersects( *it ) )
1661 processPolygon( curvePolygon, transformedParts, crossSectionParts, offset, wasCollinear, feature.
id() );
1665 for (
int i = 0; i < polySurface->numPatches(); ++i )
1667 const QgsPolygon *polygon = polySurface->patchN( i );
1668 if ( mProfileBufferedCurveEngine->intersects( polygon ) )
1670 processPolygon( polygon, transformedParts, crossSectionParts, offset, wasCollinear, feature.
id() );
1676 QgsDebugError( u
"Unhandled Geometry type: %1"_s.arg( ( *it )->wktTypeStr() ) );
1681 if ( mFeedback->isCanceled() )
1685 QgsVectorLayerProfileResults::Feature resultFeature;
1688 if ( !crossSectionParts.empty() )
1690 if ( !wasCollinear )
1692 QgsGeometry unioned = QgsGeometry::unaryUnion( crossSectionParts );
1693 if ( unioned.isEmpty() )
1695 resultFeature.crossSectionGeometry = QgsGeometry::collectGeometry( crossSectionParts );
1699 if ( unioned.type() == Qgis::GeometryType::Line )
1701 unioned = unioned.mergeLines();
1703 resultFeature.crossSectionGeometry = unioned;
1708 resultFeature.crossSectionGeometry = QgsGeometry::collectGeometry( crossSectionParts );
1711 mResults->features[resultFeature.
featureId].append( resultFeature );
1714 insertSurfaceSeparators();
1718double QgsVectorLayerProfileGenerator::tolerance()
const
1720 return mCustomToleranceEnabled ? mCustomTolerance : mTolerance;
1723double QgsVectorLayerProfileGenerator::terrainHeight(
double x,
double y )
const
1725 if ( !mTerrainProvider )
1726 return std::numeric_limits<double>::quiet_NaN();
1732 mTargetToTerrainProviderTransform.transformInPlace( x, y, dummyZ );
1734 catch ( QgsCsException & )
1736 return std::numeric_limits<double>::quiet_NaN();
1739 return mTerrainProvider->heightAt( x, y );
1742double QgsVectorLayerProfileGenerator::featureZToHeight(
double x,
double y,
double z,
double offset )
const
1744 switch ( mClamping )
1752 const double terrainZ = terrainHeight( x, y );
1753 if ( !std::isnan( terrainZ ) )
1755 switch ( mClamping )
1758 if ( std::isnan( z ) )
1776 return ( std::isnan( z ) ? 0 : z ) * mScale + offset;
1779void QgsVectorLayerProfileGenerator::clampAltitudes(
QgsLineString *lineString,
const QgsPoint ¢roid,
double offset )
const
1783 if ( mFeedback->isCanceled() )
1786 double terrainZ = 0;
1787 switch ( mClamping )
1796 pt.
setX( lineString->
xAt( i ) );
1797 pt.
setY( lineString->
yAt( i ) );
1801 pt.
set( centroid.
x(), centroid.
y() );
1805 terrainZ = terrainHeight( pt.
x(), pt.
y() );
1815 switch ( mClamping )
1819 geomZ = lineString->
zAt( i );
1826 const double z = ( terrainZ + ( std::isnan( geomZ ) ? 0 : geomZ ) ) * mScale + offset;
1827 lineString->
setZAt( i, z );
1831bool QgsVectorLayerProfileGenerator::clampAltitudes(
QgsPolygon *polygon,
double offset )
const
1833 if ( !polygon->
is3D() )
1847 QgsCurve *curve =
const_cast<QgsCurve *
>( polygon->
exteriorRing() );
1852 clampAltitudes( lineString, centroid, offset );
1856 if ( mFeedback->isCanceled() )
1859 QgsCurve *curve =
const_cast<QgsCurve *
>( polygon->
interiorRing( i ) );
1864 clampAltitudes( lineString, centroid, offset );
1869void QgsVectorLayerProfileGenerator::insertSurfaceSeparators()
1872 if ( mSurfaceIntervals.size() <= 1 )
1874 mSurfaceIntervals.clear();
1878 std::sort( mSurfaceIntervals.begin(), mSurfaceIntervals.end() );
1879 double currentEnd = mSurfaceIntervals[0].second;
1880 for (
auto intervalIt = mSurfaceIntervals.cbegin() + 1; intervalIt != mSurfaceIntervals.cend(); ++intervalIt )
1882 const double newStart = intervalIt->first;
1887 currentEnd = std::max( currentEnd, intervalIt->second );
1890 mSurfaceIntervals.clear();
@ Relative
Elevation is relative to terrain height (final elevation = terrain elevation + feature elevation).
@ Terrain
Elevation is clamped to terrain (final elevation = terrain elevation).
@ Absolute
Elevation is taken directly from feature and is independent of terrain height (final elevation = feat...
VertexType
Types of vertex.
@ Round
Use rounded joins.
@ Centroid
Clamp just centroid of feature.
@ Vertex
Clamp every vertex of feature.
@ Flat
Flat cap (in line with start/end of line).
static const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
@ ContinuousSurface
The features should be treated as representing values on a continuous surface (eg contour lines).
@ IndividualFeatures
Treat each feature as an individual object (eg buildings).
ProfileExportType
Types of export for elevation profiles.
@ Profile2D
Export profiles as 2D profile lines, with elevation stored in exported geometry Y dimension and dista...
@ Features3D
Export profiles as 3D features, with elevation values stored in exported geometry Z values.
@ DistanceVsElevationTable
Export profiles as a table of sampled distance vs elevation values.
@ Reverse
Reverse/inverse transform (from destination to source).
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
virtual bool deleteVertex(QgsVertexId position)
Deletes a vertex within the geometry.
virtual QgsPoint centroid() const
Returns the centroid of the geometry.
Abstract base class for objects which generate elevation profiles.
Abstract base class for storage of elevation profiles.
std::unique_ptr< QgsCurve > mProfileCurve
std::unique_ptr< QgsLineSymbol > mLineSymbol
QgsAbstractProfileSurfaceGenerator(const QgsProfileRequest &request)
Constructor for QgsAbstractProfileSurfaceGenerator.
Qgis::ProfileSurfaceSymbology mSymbology
std::unique_ptr< QgsFillSymbol > mFillSymbol
std::unique_ptr< QgsFillSymbol > mFillSymbol
QMap< double, double > mDistanceToHeightMap
std::unique_ptr< QgsLineSymbol > mLineSymbol
void renderResults(QgsProfileRenderContext &context) override
Renders the results to the specified context.
void copyPropertiesFromGenerator(const QgsAbstractProfileGenerator *generator) override
Copies properties from specified generator to the results object.
QVector< QgsAbstractProfileResults::Feature > asFeatures(Qgis::ProfileExportType type, QgsFeedback *feedback=nullptr) const override
Returns a list of features representing the calculated elevation results.
QVector< QgsProfileIdentifyResults > identify(const QgsProfilePoint &point, const QgsProfileIdentifyContext &context) override
Identify results visible at the specified profile point.
QgsProfileSnapResult snapPoint(const QgsProfilePoint &point, const QgsProfileSnapContext &context) override
Snaps a point to the generated elevation profile.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
virtual int numPoints() const =0
Returns the number of points in the curve.
virtual bool pointAt(int node, QgsPoint &point, Qgis::VertexType &type) const =0
Returns the point and vertex type of a point within the curve.
QgsRange which stores a range of double values.
RAII class to pop scope from an expression context on destruction.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setCoordinateTransform(const QgsCoordinateTransform &transform)
Sets the coordinate transform which will be used to transform the feature's geometries.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets the feature IDs that should be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the iterator to check if it should be cance...
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
QgsFeatureRequest & setDistanceWithin(const QgsGeometry &geometry, double distance)
Sets a reference geometry and a maximum distance from this geometry to retrieve features within.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool isCanceled() const
Tells whether the operation has been canceled already.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
static double pointFractionAlongLine(double x1, double y1, double x2, double y2, double px, double py)
Given the line (x1, y1) to (x2, y2) and a point (px, py) returns the fraction of the line length at w...
static bool pointsAreCollinear(double x1, double y1, double x2, double y2, double x3, double y3, double epsilon)
Given the points (x1, y1), (x2, y2) and (x3, y3) returns true if these points can be considered colli...
static bool segmentIntersection(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint, bool &isIntersection, double tolerance=1e-8, bool acceptImproperIntersection=false)
Compute the intersection between two segments.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QgsAbstractGeometry::const_part_iterator const_parts_begin() const
Returns STL-style const iterator pointing to the first part of the geometry.
Q_INVOKABLE bool boundingBoxIntersects(const QgsRectangle &rectangle) const
Returns true if the bounding box of this geometry intersects with a rectangle.
static QgsGeometry collectGeometry(const QVector< QgsGeometry > &geometries)
Creates a new multipart geometry from a list of QgsGeometry objects.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
QgsAbstractGeometry::const_part_iterator const_parts_end() const
Returns STL-style iterator pointing to the imaginary part after the last part of the geometry.
Qgis::GeometryOperationResult translate(double dx, double dy, double dz=0.0, double dm=0.0)
Translates this geometry by dx, dy, dz and dm.
Line string geometry type, with support for z-dimension and m-values.
A line symbol type, for rendering LineString and MultiLineString geometries.
@ ExtrusionHeight
Extrusion height.
A marker symbol type, for rendering Point and MultiPoint geometries.
void setY(double y)
Sets the y value of the point.
void set(double x, double y)
Sets the x and y value of the point.
void setX(double x)
Sets the x value of the point.
Point geometry type, with support for z-dimension and m-values.
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
bool isEmpty() const override
Returns true if the geometry is empty.
Encapsulates the context in which an elevation profile is to be generated.
Encapsulates the context of identifying profile results.
double maximumPointElevationDelta
Maximum allowed snapping delta for the elevation values when identifying a point.
double maximumPointDistanceDelta
Maximum allowed snapping delta for the distance values when identifying a point.
double maximumSurfaceElevationDelta
Maximum allowed snapping delta for the elevation values when identifying a continuous elevation surfa...
Stores identify results generated by a QgsAbstractProfileResults object.
Encapsulates a point on a distance-elevation profile.
double elevation() const
Returns the elevation of the point.
double distance() const
Returns the distance of the point.
Abstract base class for storage of elevation profiles.
const QTransform & worldTransform() const
Returns the transform from world coordinates to painter coordinates.
QgsDoubleRange elevationRange() const
Returns the range of elevations to include in the render.
QgsDoubleRange distanceRange() const
Returns the range of distances to include in the render.
QgsRenderContext & renderContext()
Returns a reference to the component QgsRenderContext.
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
Encapsulates the context of snapping a profile point.
double maximumPointDistanceDelta
Maximum allowed snapping delta for the distance values when snapping to a point.
double maximumSurfaceElevationDelta
Maximum allowed snapping delta for the elevation values when snapping to a continuous elevation surfa...
double maximumPointElevationDelta
Maximum allowed snapping delta for the elevation values when snapping to a point.
Encapsulates results of snapping a profile point.
QgsProfilePoint snappedPoint
Snapped point.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const final
Returns the set of any fields referenced by the active properties from the collection.
T lower() const
Returns the lower bound of the range.
T upper() const
Returns the upper bound of the range.
A rectangle specified with double values.
bool intersects(const QgsRectangle &rect) const
Returns true when rectangle intersects with other rectangle.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
Scoped object for saving and restoring a QPainter object's state.
double yAt(int index) const override
Returns the y-coordinate of the specified node in the line string.
void setZAt(int index, double z)
Sets the z-coordinate of the specified node in the simple curve.
int numPoints() const override
Returns the number of points in the curve.
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
double xAt(int index) const override
Returns the x-coordinate of the specified node in the line string.
const double * yData() const
Returns a const pointer to the y vertex data.
double zAt(int index) const override
Returns the z-coordinate of the specified node in the simple curve.
QgsPoint pointN(int i) const
Returns the specified point from inside the simple curve.
const double * xData() const
Returns a const pointer to the x vertex data.
const double * zData() const
Returns a const pointer to the z vertex data, or nullptr if the simple curve does not have z values.
std::unique_ptr< QgsMultiPolygon > asMultiPolygon() const
Returns the triangulation as a multipolygon geometry.
void setBounds(const QgsRectangle &bounds)
Sets scaling and the bounds of the input geometry coordinates.
void addPolygon(const QgsPolygon &polygon, float extrusionHeight)
Tessellates a triangle and adds its vertex entries to the output data array.
Vector layer specific subclass of QgsMapLayerElevationProperties.
Partial snapshot of vector layer's state (only the members necessary for access to features).
Implementation of QgsAbstractProfileGenerator for vector layers.
QgsAbstractProfileResults * takeResults() override
Takes results from the generator.
bool generateProfile(const QgsProfileGenerationContext &context=QgsProfileGenerationContext()) override
Generate the profile (based on data stored in the class).
QString sourceId() const override
Returns a unique identifier representing the source of the profile.
QString type() const override
Returns the unique string identifier for the results type.
~QgsVectorLayerProfileGenerator() override
QgsFeedback * feedback() const override
Access to feedback object of the generator (may be nullptr).
QgsVectorLayerProfileGenerator(QgsVectorLayer *layer, const QgsProfileRequest &request)
Constructor for QgsVectorLayerProfileGenerator.
QVector< QgsProfileIdentifyResults > identify(const QgsProfilePoint &point, const QgsProfileIdentifyContext &context) override
Identify results visible at the specified profile point.
Qgis::VectorProfileType profileType
std::unique_ptr< QgsMarkerSymbol > mMarkerSymbol
bool respectLayerSymbology
bool mShowMarkerSymbolInSurfacePlots
QVector< QgsGeometry > asGeometries() const override
Returns a list of geometries representing the calculated elevation results.
QPointer< QgsVectorLayer > mLayer
void renderResults(QgsProfileRenderContext &context) override
Renders the results to the specified context.
QVector< QgsAbstractProfileResults::Feature > asFeatures(Qgis::ProfileExportType type, QgsFeedback *feedback=nullptr) const override
Returns a list of features representing the calculated elevation results.
QgsProfileSnapResult snapPoint(const QgsProfilePoint &point, const QgsProfileSnapContext &context) override
Snaps a point to the generated elevation profile.
QString type() const override
Returns the unique string identifier for the results type.
QHash< QgsFeatureId, QVector< Feature > > features
QMap< double, QgsFeatureId > mDistanceToFeatureId
void copyPropertiesFromGenerator(const QgsAbstractProfileGenerator *generator) override
Copies properties from specified generator to the results object.
Represents a vector layer which manages a vector based dataset.
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
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...
#define BUILTIN_UNREACHABLE
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
QList< QgsSymbol * > QgsSymbolList
QString layerIdentifier
Identifier for grouping output features.
QVariantMap attributes
Exported attributes.
QgsGeometry geometry
Exported geometry.
QgsGeometry crossSectionGeometry
Cross section distance vs height geometry for feature.
QgsFeatureId featureId
Original feature ID.
QgsGeometry geometry
Feature's geometry with any terrain height adjustment and extrusion applied.