35using namespace Qt::StringLiterals;
49 mPointIndex =
nullptr;
56 const std::size_t size =
results.size();
58 for ( std::size_t i = 0; i < size; ++i, ++pointData )
65 GEOSSTRtree_insert_r( geosctxt, mPointIndex, geosPoint.get(), pointData );
72 return u
"pointcloud"_s;
78 QMap< double, double > res;
81 res.insert( point.distanceAlongCurve, point.z );
93 res.append(
QgsPoint( point.x, point.y, point.z ) );
101 QVector< QgsGeometry > res;
112 QVector< QgsAbstractProfileResults::Feature > res;
113 res.reserve(
static_cast< int >(
results.size() ) );
138 f.
geometry =
QgsGeometry( std::make_unique< QgsPoint >( point.distanceAlongCurve, point.z ) );
155 { u
"distance"_s, point.distanceAlongCurve },
156 { u
"elevation"_s, point.z }
181 painter->setBrush( Qt::NoBrush );
182 painter->setPen( Qt::NoPen );
200 const QRectF visibleRegion( minDistance,
minZ, maxDistance - minDistance,
maxZ -
minZ );
201 QPainterPath clipPath;
202 clipPath.addPolygon( context.
worldTransform().map( visibleRegion ) );
203 painter->setClipPath( clipPath, Qt::ClipOperation::IntersectClip );
209 QPointF p = context.
worldTransform().map( QPointF( point.distanceAlongCurve, point.z ) );
212 color.setAlphaF( color.alphaF() * ( 1.0 - std::pow( point.distanceFromCurve /
tolerance, 0.5 ) ) );
217 painter->fillRect( QRectF( p.x() - penWidth * 0.5,
218 p.y() - penWidth * 0.5,
219 penWidth, penWidth ), color );
223 painter->setBrush( QBrush( color ) );
224 painter->setPen( Qt::NoPen );
225 painter->drawEllipse( QRectF( p.x() - penWidth * 0.5,
226 p.y() - penWidth * 0.5,
227 penWidth, penWidth ) );
235 QList< const QgsPointCloudLayerProfileResults::PointResult * > *
list;
253 GEOSCoordSequence *coord = GEOSCoordSeq_create_r( geosctxt, 2, 2 );
254 GEOSCoordSeq_setXY_r( geosctxt, coord, 0, minDistance, minElevation );
255 GEOSCoordSeq_setXY_r( geosctxt, coord, 1, maxDistance, maxElevation );
256 geos::unique_ptr searchDiagonal( GEOSGeom_createLineString_r( geosctxt, coord ) );
258 QList<const PointResult *> items;
260 callbackData.
list = &items;
261 GEOSSTRtree_query_r( geosctxt, mPointIndex, searchDiagonal.get(),
_GEOSQueryCallback, &callbackData );
265 double bestMatchDistance = std::numeric_limits< double >::max();
267 for (
const PointResult *candidate : std::as_const( items ) )
269 const double distance = std::sqrt( std::pow( candidate->distanceAlongCurve - point.
distance(), 2 )
271 if ( distance < bestMatchDistance )
273 bestMatchDistance = distance;
274 bestMatch = candidate;
295 std::unique_ptr< QgsCurve > substring( mProfileCurve->curveSubstring( distanceRange.
lower(), distanceRange.
upper() ) );
296 QgsGeos substringGeos( substring.get() );
298 if ( !searchGeometry )
304 searchGeometry->transform( curveToLayerTransform );
312 const QgsDoubleRange providerElevationRange( ( elevationRange.
lower() - mZOffset ) / mZScale, ( elevationRange.
upper() - mZOffset ) / mZScale );
314 const QgsGeometry pointCloudSearchGeometry( std::move( searchGeometry ) );
315 const QVector<QVariantMap> pointAttributes = mLayer->dataProvider()->identify( mMaxErrorInLayerCoordinates, pointCloudSearchGeometry, providerElevationRange );
316 if ( pointAttributes.empty() )
333 mLayer = pcGenerator->mLayer;
334 mLayerId = pcGenerator->mId;
335 mCurveCrs = pcGenerator->mTargetCrs;
336 mProfileCurve.reset( pcGenerator->mProfileCurve->clone() );
337 mTolerance = pcGenerator->mTolerance;
339 mZOffset = pcGenerator->mZOffset;
340 mZScale = pcGenerator->mZScale;
349 , mIndex( layer->index() )
350 , mSubIndexes( layer->dataProvider()->subIndexes() )
351 , mLayerAttributes( layer->attributes() )
352 , mRenderer( qgis::down_cast<
QgsPointCloudLayerElevationProperties* >( layer->elevationProperties() )->respectLayerColors() && mLayer->renderer() ? mLayer->renderer()->clone() : nullptr )
362 , mProfileCurve( request.profileCurve() ? request.profileCurve()->clone() : nullptr )
363 , mTolerance( request.tolerance() )
364 , mSourceCrs( layer->crs3D() )
365 , mTargetCrs( request.crs() )
366 , mTransformContext( request.transformContext() )
367 , mZOffset( layer->elevationProperties()->zOffset() )
368 , mZScale( layer->elevationProperties()->zScale() )
369 , mStepDistance( request.stepDistance() )
373 mScale = mIndex.scale();
374 mOffset = mIndex.offset();
392 mGatheredPoints.clear();
393 if ( !mLayer || !mProfileCurve || mFeedback->isCanceled() )
396 QVector<QgsPointCloudIndex> indexes;
397 if ( mIndex && mIndex.isValid() )
398 indexes.append( mIndex );
401 const QgsRectangle profileCurveBbox = mProfileCurve->boundingBox();
402 for (
const QgsPointCloudSubIndex &subidx : mSubIndexes )
405 if ( index && index.
isValid() && subidx.polygonBounds().intersects( profileCurveBbox ) )
406 indexes.append( subidx.index() );
409 if ( indexes.empty() )
415 std::unique_ptr< QgsCurve > trimmedCurve;
417 if ( startDistanceOffset > 0 || endDistance < mProfileCurve->length() )
419 trimmedCurve.reset( mProfileCurve->curveSubstring( startDistanceOffset, endDistance ) );
420 sourceCurve = trimmedCurve.get();
424 sourceCurve = mProfileCurve.get();
428 QgsGeos originalCurveGeos( sourceCurve );
439 QgsDebugError( u
"Error transforming profile line to layer CRS"_s );
443 if ( mFeedback->isCanceled() )
446 mSearchGeometryInLayerCrsGeometryEngine = std::make_unique< QgsGeos >( mSearchGeometryInLayerCrs.get() );
447 mSearchGeometryInLayerCrsGeometryEngine->prepareGeometry();
448 mMaxSearchExtentInLayerCrs = mSearchGeometryInLayerCrs->boundingBox();
451 if ( maximumErrorPixels < 0.0 )
462 if ( toleranceInPixels / 4 < maximumErrorPixels )
463 maximumErrorPixels = toleranceInPixels / 4;
473 mPreparedRendererData = mRenderer->prepare();
474 if ( mPreparedRendererData )
476 const QSet< QString > rendererAttributes = mPreparedRendererData->usedAttributes();
477 for (
const QString &attribute : std::as_const( rendererAttributes ) )
479 if ( attributes.
indexOf( attribute ) >= 0 )
482 const int layerIndex = mLayerAttributes.indexOf( attribute );
483 if ( layerIndex < 0 )
485 QgsMessageLog::logMessage( QObject::tr(
"Required attribute %1 not found in layer" ).arg( attribute ), QObject::tr(
"Point Cloud" ) );
489 attributes.
push_back( mLayerAttributes.at( layerIndex ) );
495 mPreparedRendererData.reset();
500 mResults = std::make_unique< QgsPointCloudLayerProfileResults >();
501 mResults->copyPropertiesFromGenerator(
this );
502 mResults->mMaxErrorInLayerCoordinates = 0;
508 if ( mapUnitsPerPixel < 0.0 )
525 QgsDebugError( u
"Could not transform node extent to curve CRS"_s );
526 rootNodeExtentInCurveCrs = rootNodeExtentLayerCoords;
529 const double rootErrorInMapCoordinates = rootNodeExtentInCurveCrs.
width() / pc.span();
530 if ( rootErrorInMapCoordinates < 0.0 )
536 double rootErrorPixels = rootErrorInMapCoordinates / mapUnitsPerPixel;
537 const QVector<QgsPointCloudNodeId> nodes = traverseTree( pc, pc.root(), maximumErrorPixels, rootErrorPixels, context.
elevationRange() );
544 const double rootErrorInLayerCoordinates = rootNodeExtentLayerCoords.
width() / pc.span();
545 const double maxErrorInMapCoordinates = maximumErrorPixels * mapUnitsPerPixel;
547 mResults->mMaxErrorInLayerCoordinates = std::max(
548 mResults->mMaxErrorInLayerCoordinates,
549 maxErrorInMapCoordinates * rootErrorInLayerCoordinates / rootErrorInMapCoordinates );
551 switch ( pc.accessType() )
565 if ( mFeedback->isCanceled() )
569 if ( mGatheredPoints.empty() )
579 const int size = mGatheredPoints.size();
580 mResults->results.resize( size );
582 for (
int i = 0; i < size; ++i, ++pointData, ++destData )
584 if ( mFeedback->isCanceled() )
587 *destData = *pointData;
589 if ( mOpacityByDistanceEffect )
592 mResults->minZ = std::min( destData->
z, mResults->minZ );
593 mResults->maxZ = std::max( destData->
z, mResults->maxZ );
595 mResults->finalize( mFeedback.get() );
602 return mResults.release();
607 return mFeedback.get();
612 QVector<QgsPointCloudNodeId> nodes;
614 if ( mFeedback->isCanceled() )
619 QgsPointCloudNode node = pc.
getNode( n );
620 QgsBox3D nodeBounds = node.
bounds();
621 const QgsDoubleRange nodeZRange( nodeBounds.
zMinimum(), nodeBounds.
zMaximum() );
625 if ( !mMaxSearchExtentInLayerCrs.intersects( nodeBounds.
toRectangle() ) )
629 if ( !mSearchGeometryInLayerCrsGeometryEngine->intersects( nodeMapGeometry.
constGet() ) )
635 double childrenErrorPixels = nodeErrorPixels / 2.0;
636 if ( childrenErrorPixels < maxErrorPixels )
639 for (
const QgsPointCloudNodeId &nn : node.
children() )
641 nodes += traverseTree( pc, nn, maxErrorPixels, childrenErrorPixels, zRange );
650 for (
const QgsPointCloudNodeId &n : nodes )
652 if ( mFeedback->isCanceled() )
655 std::unique_ptr<QgsPointCloudBlock> block( pc.
nodeData( n, request ) );
660 visitBlock( block.get(), zRange );
669 if ( nodes.isEmpty() )
677 QVector<QgsPointCloudBlockRequest *> blockRequests;
681 for (
int i = 0; i < nodes.size(); ++i )
683 const QgsPointCloudNodeId &n = nodes[i];
685 QgsPointCloudBlockRequest *blockRequest = pc.
asyncNodeData( n, request );
686 blockRequests.append( blockRequest );
688 [
this, &nodesDrawn, &loop, &blockRequests, &zRange, nStr, blockRequest ]()
690 blockRequests.removeOne( blockRequest );
693 if ( blockRequests.isEmpty() )
696 std::unique_ptr<QgsPointCloudBlock> block = blockRequest->
takeBlock();
698 blockRequest->deleteLater();
700 if ( mFeedback->isCanceled() )
711 visitBlock( block.get(), zRange );
717 if ( !blockRequests.isEmpty() )
722 for ( QgsPointCloudBlockRequest *blockRequest : std::as_const( blockRequests ) )
724 std::unique_ptr<QgsPointCloudBlock> block = blockRequest->
takeBlock();
726 blockRequest->deleteLater();
734 const char *ptr = block->
data();
737 const QgsPointCloudAttributeCollection request = block->
attributes();
741 const QgsPointCloudAttributeCollection blockAttributes = block->
attributes();
742 int xOffset = 0, yOffset = 0, zOffset = 0;
747 bool useRenderer =
false;
748 if ( mPreparedRendererData )
750 useRenderer = mPreparedRendererData->prepareBlock( block );
754 const bool reproject = !mLayerToTargetTransform.isShortCircuited();
755 for (
int i = 0; i < count; ++i )
757 if ( mFeedback->isCanceled() )
762 QgsPointCloudLayerProfileResults::PointResult res;
763 QgsPointCloudAttribute::getPointXYZ( ptr, i, recordSize, xOffset, xType, yOffset, yType, zOffset, zType, block->
scale(), block->
offset(), res.
x, res.
y, res.
z );
765 res.
z = res.
z * mZScale + mZOffset;
771 color = mPreparedRendererData->pointColor( block, i, res.
z );
772 if ( !color.isValid() )
775 res.
color = color.rgba();
779 res.
color = mPointColor.rgba();
782 if ( mSearchGeometryInLayerCrsGeometryEngine->contains( res.
x, res.
y ) )
788 mLayerToTargetTransform.transformInPlace( res.
x, res.
y, res.
z );
790 catch ( QgsCsException & )
796 mGatheredPoints.append( res );
@ RespectsMaximumErrorMapUnit
Generated profile respects the QgsProfileGenerationContext::maximumErrorMapUnits() property.
@ RespectsDistanceRange
Generated profile respects the QgsProfileGenerationContext::distanceRange() property.
@ Circle
Renders points as circles.
@ Square
Renders points as squares.
QFlags< ProfileGeneratorFlag > ProfileGeneratorFlags
@ Round
Use rounded joins.
@ Flat
Flat cap (in line with start/end of line).
@ Local
Local means the source is a local file on the machine.
@ Remote
Remote means it's loaded through a protocol like HTTP.
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).
Abstract base class for objects which generate elevation profiles.
Abstract base class for storage of elevation profiles.
double zMaximum() const
Returns the maximum z value.
QgsRectangle toRectangle() const
Converts the box to a 2D rectangle.
double zMinimum() const
Returns the minimum z value.
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
Abstract base class for curved geometry type.
QgsRange which stores a range of double values.
bool isInfinite() const
Returns true if the range consists of all possible values.
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.
void canceled()
Internal routines can connect to this signal if they use event loop.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
static GEOSContextHandle_t get()
Returns a thread local instance of a GEOS context, safe for use in the current thread.
Does vector analysis using the GEOS library and handles import, export, and exception handling.
QgsAbstractGeometry * buffer(double distance, int segments, QString *errorMsg=nullptr) const override
double distance(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const override
Calculates the distance between this and geom.
void prepareGeometry() override
Prepares the geometry, so that subsequent calls to spatial relation methods are much faster.
double lineLocatePoint(const QgsPoint &point, QString *errorMsg=nullptr) const
Returns a distance representing the location along this linestring of the closest point on this lines...
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
A collection of point cloud attributes.
void push_back(const QgsPointCloudAttribute &attribute)
Adds extra attribute.
int pointRecordSize() const
Returns total size of record.
const QgsPointCloudAttribute * find(const QString &attributeName, int &offset) const
Finds the attribute with the name.
int indexOf(const QString &name) const
Returns the index of the attribute with the specified name.
Attribute for point cloud data pair of name and size in bytes.
DataType
Systems of unit measurement.
static void getPointXYZ(const char *ptr, int i, std::size_t pointRecordSize, int xOffset, QgsPointCloudAttribute::DataType xType, int yOffset, QgsPointCloudAttribute::DataType yType, int zOffset, QgsPointCloudAttribute::DataType zType, const QgsVector3D &indexScale, const QgsVector3D &indexOffset, double &x, double &y, double &z)
Retrieves the x, y, z values for the point at index i.
DataType type() const
Returns the data type.
QString errorStr() const
Returns the error message string of the request.
void finished()
Emitted when the request processing has finished.
std::unique_ptr< QgsPointCloudBlock > takeBlock()
Returns the requested block.
Base class for storing raw data from point cloud nodes.
QgsVector3D scale() const
Returns the custom scale of the block.
const char * data() const
Returns raw pointer to data.
QgsPointCloudAttributeCollection attributes() const
Returns the attributes that are stored in the data block, along with their size.
int pointCount() const
Returns number of points that are stored in the block.
QgsVector3D offset() const
Returns the custom offset of the block.
Smart pointer for QgsAbstractPointCloudIndex.
QgsPointCloudBlockRequest * asyncNodeData(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request)
Returns a handle responsible for loading a node data block.
bool isValid() const
Returns whether index is loaded and valid.
std::unique_ptr< QgsPointCloudBlock > nodeData(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request)
Returns node data block.
QgsPointCloudNode getNode(const QgsPointCloudNodeId &id) const
Returns object for a given node.
Point cloud layer specific subclass of QgsMapLayerElevationProperties.
Qgis::ProfileGeneratorFlags flags() const override
Returns flags which reflect how the profile generator operates.
QgsPointCloudLayerProfileGenerator(QgsPointCloudLayer *layer, const QgsProfileRequest &request)
Constructor for QgsPointCloudLayerProfileGenerator.
~QgsPointCloudLayerProfileGenerator() override
QString sourceId() const override
Returns a unique identifier representing the source of the profile.
QgsFeedback * feedback() const override
Access to feedback object of the generator (may be nullptr).
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).
Qgis::PointCloudSymbol pointSymbol
QgsProfileSnapResult snapPoint(const QgsProfilePoint &point, const QgsProfileSnapContext &context) override
Snaps a point to the generated elevation profile.
void finalize(QgsFeedback *feedback)
Finalizes results – should be called after last point is added.
QgsPointSequence sampledPoints() const override
Returns a list of sampled points, with their calculated elevation as the point z value.
QgsDoubleRange zRange() const override
Returns the range of the retrieved elevation values.
std::vector< PointResult > results
QMap< double, double > distanceToHeightMap() const override
Returns the map of distance (chainage) to height.
QVector< QgsGeometry > asGeometries() const override
Returns a list of geometries representing the calculated elevation results.
~QgsPointCloudLayerProfileResults() override
void copyPropertiesFromGenerator(const QgsAbstractProfileGenerator *generator) override
Copies properties from specified generator to the results object.
QVector< QgsProfileIdentifyResults > identify(const QgsProfilePoint &point, const QgsProfileIdentifyContext &context) override
Identify results visible at the specified profile point.
friend class QgsPointCloudLayerProfileGenerator
QString type() const override
Returns the unique string identifier for the results type.
bool opacityByDistanceEffect
QgsPointCloudLayerProfileResults()
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.
Qgis::RenderUnit pointSizeUnit
Represents a map layer supporting display of point clouds.
Represents an indexed point cloud node's position in octree.
QString toString() const
Encode node to string.
Keeps metadata for an indexed point cloud node.
QList< QgsPointCloudNodeId > children() const
Returns IDs of child nodes.
qint64 pointCount() const
Returns number of points contained in node data.
QgsBox3D bounds() const
Returns node's bounding cube in CRS coords.
Point cloud data request.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Set attributes filter in the request.
Point geometry type, with support for z-dimension and m-values.
Encapsulates the context in which an elevation profile is to be generated.
double mapUnitsPerDistancePixel() const
Returns the number of map units per pixel in the distance dimension.
QgsDoubleRange elevationRange() const
Returns the range of elevations to include in the generation.
double convertDistanceToPixels(double size, Qgis::RenderUnit unit) const
Converts a distance size from the specified units to pixels.
QgsDoubleRange distanceRange() const
Returns the range of distances to include in the generation.
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.
QgsProject * project
Associated project.
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 maximumPointElevationDelta
Maximum allowed snapping delta for the elevation values when snapping to a point.
double displayRatioElevationVsDistance
Display ratio of elevation vs distance units.
Encapsulates results of snapping a profile point.
QgsProfilePoint snappedPoint
Snapped point.
QgsCoordinateTransformContext transformContext
bool overlaps(const QgsRange< T > &other) const
Returns true if this range overlaps another range.
bool contains(const QgsRange< T > &other) const
Returns true if this range contains another range.
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.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
Scoped object for saving and restoring a QPainter object's state.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
QVector< QgsPoint > QgsPointSequence
#define QgsDebugError(str)
void _GEOSQueryCallback(void *item, void *userdata)
Encapsulates information about a feature exported from the profile results.
QString layerIdentifier
Identifier for grouping output features.
QVariantMap attributes
Exported attributes.
QgsGeometry geometry
Exported geometry.
double distanceAlongCurve
QList< const QgsPointCloudLayerProfileResults::PointResult * > * list