QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgscopcpointcloudblockrequest.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgscopcpointcloudblockrequest.cpp
3 --------------------
4 begin : March 2022
5 copyright : (C) 2022 by Belgacem Nedjima
6 email : belgacem dot nedjima at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "moc_qgscopcpointcloudblockrequest.cpp"
20
22#include "qgslazdecoder.h"
23#include "qgsapplication.h"
26
27//
28// QgsCopcPointCloudBlockRequest
29//
30
32
34 const QgsPointCloudAttributeCollection &attributes, const QgsPointCloudAttributeCollection &requestedAttributes,
35 const QgsVector3D &scale, const QgsVector3D &offset, const QgsPointCloudExpression &filterExpression, const QgsRectangle &filterRect,
36 uint64_t blockOffset, int32_t blockSize, int pointCount, const QgsLazInfo &lazInfo )
37 : QgsPointCloudBlockRequest( node, uri, attributes, requestedAttributes, scale, offset, filterExpression, filterRect ),
38 mBlockOffset( blockOffset ), mBlockSize( blockSize ), mPointCount( pointCount ), mLazInfo( lazInfo )
39{
40 // an empty block size will create an invalid range, causing a full request to the server
41 Q_ASSERT( mBlockSize > 0 );
42
43 QNetworkRequest nr = QNetworkRequest( QUrl( mUri ) );
44 QgsSetRequestInitiatorClass( nr, QStringLiteral( "QgsCopcPointCloudBlockRequest" ) );
46 nr.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
47 nr.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
48
49 QByteArray queryRange = QStringLiteral( "bytes=%1-%2" ).arg( mBlockOffset ).arg( ( int64_t ) mBlockOffset + mBlockSize - 1 ).toLocal8Bit();
50 nr.setRawHeader( "Range", queryRange );
51
52 mTileDownloadManagerReply.reset( QgsApplication::tileDownloadManager()->get( nr ) );
53 connect( mTileDownloadManagerReply.get(), &QgsTileDownloadManagerReply::finished, this, &QgsCopcPointCloudBlockRequest::blockFinishedLoading );
54}
55
56void QgsCopcPointCloudBlockRequest::blockFinishedLoading()
57{
58 mBlock = nullptr;
59 QString error;
60 if ( mTileDownloadManagerReply->error() == QNetworkReply::NetworkError::NoError )
61 {
62 if ( mBlockSize != mTileDownloadManagerReply->data().size() )
63 {
64 error = QStringLiteral( "Returned HTTP range is incorrect, requested %1 bytes but got %2 bytes" ).arg( mBlockSize ).arg( mTileDownloadManagerReply->data().size() );
65 }
66 else
67 {
68 try
69 {
70 mBlock = QgsLazDecoder::decompressCopc( mTileDownloadManagerReply->data(), mLazInfo, mPointCount, mRequestedAttributes, mFilterExpression, mFilterRect );
75 }
76 catch ( std::exception &e )
77 {
78 error = QStringLiteral( "Decompression error: %1" ).arg( e.what() );
79 }
80 }
81 }
82 else
83 {
84 error = QStringLiteral( "Network request error: %1" ).arg( mTileDownloadManagerReply->errorString() );
85 }
86 if ( !error.isEmpty() )
87 {
88 mErrorStr = QStringLiteral( "Error loading point tile %1: \"%2\"" ).arg( mNode.toString(), error );
89 }
90 emit finished();
91}
92
static QgsTileDownloadManager * tileDownloadManager()
Returns the application's tile download manager, used for download of map tiles when rendering.
QgsCopcPointCloudBlockRequest(const QgsPointCloudNodeId &node, const QString &Uri, const QgsPointCloudAttributeCollection &attributes, const QgsPointCloudAttributeCollection &requestedAttributes, const QgsVector3D &scale, const QgsVector3D &offset, const QgsPointCloudExpression &filterExpression, const QgsRectangle &filterRect, uint64_t blockOffset, int32_t blockSize, int pointCount, const QgsLazInfo &lazInfo)
QgsPointCloudBlockRequest constructor Requests the block data of size blockSize at offset blockOffset...
Class for extracting information contained in LAZ file such as the public header block and variable l...
Definition qgslazinfo.h:39
Collection of point cloud attributes.
Base class for handling loading QgsPointCloudBlock asynchronously.
QgsPointCloudAttributeCollection mRequestedAttributes
std::unique_ptr< QgsTileDownloadManagerReply > mTileDownloadManagerReply
std::unique_ptr< QgsPointCloudBlock > mBlock
QgsPointCloudExpression mFilterExpression
void finished()
Emitted when the request processing has finished.
static void storeNodeDataToCacheStatic(QgsPointCloudBlock *data, const QgsPointCloudNodeId &node, const QgsPointCloudRequest &request, const QgsPointCloudExpression &expression, const QString &uri)
Stores existing data to the cache for the specified node, request, expression and uri.
Represents a indexed point cloud node's position in octree.
QString toString() const
Encode node to string.
Point cloud data request.
void setFilterRect(QgsRectangle extent)
Sets the rectangle from which points will be taken, in point cloud's crs.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Set attributes filter in the request.
A rectangle specified with double values.
void finished()
Emitted when the reply has finished (either with a success or with a failure)
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
#define QgsSetRequestInitiatorClass(request, _class)
#define QgsSetRequestInitiatorId(request, str)