32#include <QtConcurrent/QtConcurrentMap>
35#include "moc_qgspointclouddataprovider.cpp"
59 return lIndex.isValid();
85 static QMap< int, QString > sCodes
87 {0, QStringLiteral(
"Created, Never Classified" )},
88 {1, QStringLiteral(
"Unclassified" )},
89 {2, QStringLiteral(
"Ground" )},
90 {3, QStringLiteral(
"Low Vegetation" )},
91 {4, QStringLiteral(
"Medium Vegetation" )},
92 {5, QStringLiteral(
"High Vegetation" )},
93 {6, QStringLiteral(
"Building" )},
94 {7, QStringLiteral(
"Low Point (Low Noise)" )},
95 {8, QStringLiteral(
"Reserved" )},
96 {9, QStringLiteral(
"Water" )},
97 {10, QStringLiteral(
"Rail" )},
98 {11, QStringLiteral(
"Road Surface" )},
99 {12, QStringLiteral(
"Reserved" )},
100 {13, QStringLiteral(
"Wire - Guard (Shield)" )},
101 {14, QStringLiteral(
"Wire - Conductor (Phase)" )},
102 {15, QStringLiteral(
"Transmission Tower" )},
103 {16, QStringLiteral(
"Wire-Structure Connector (Insulator)" )},
104 {17, QStringLiteral(
"Bridge Deck" )},
105 {18, QStringLiteral(
"High Noise" )},
108 static std::once_flag initialized;
109 std::call_once( initialized, []( )
111 for (
int i = 19; i <= 63; ++i )
112 sCodes.insert( i, QStringLiteral(
"Reserved" ) );
113 for (
int i = 64; i <= 255; ++i )
114 sCodes.insert( i, QStringLiteral(
"User Definable" ) );
122 static QMap< int, QString > sCodes
124 {0, QObject::tr(
"Created, Never Classified" )},
125 {1, QObject::tr(
"Unclassified" )},
126 {2, QObject::tr(
"Ground" )},
127 {3, QObject::tr(
"Low Vegetation" )},
128 {4, QObject::tr(
"Medium Vegetation" )},
129 {5, QObject::tr(
"High Vegetation" )},
130 {6, QObject::tr(
"Building" )},
131 {7, QObject::tr(
"Low Point (Noise)" )},
132 {8, QObject::tr(
"Reserved" )},
133 {9, QObject::tr(
"Water" )},
134 {10, QObject::tr(
"Rail" )},
135 {11, QObject::tr(
"Road Surface" )},
136 {12, QObject::tr(
"Reserved" )},
137 {13, QObject::tr(
"Wire - Guard (Shield)" )},
138 {14, QObject::tr(
"Wire - Conductor (Phase)" )},
139 {15, QObject::tr(
"Transmission Tower" )},
140 {16, QObject::tr(
"Wire-Structure Connector (Insulator)" )},
141 {17, QObject::tr(
"Bridge Deck" )},
142 {18, QObject::tr(
"High Noise" )},
145 static std::once_flag initialized;
146 std::call_once( initialized, []( )
148 for (
int i = 19; i <= 63; ++i )
149 sCodes.insert( i, QObject::tr(
"Reserved" ) );
150 for (
int i = 64; i <= 255; ++i )
151 sCodes.insert( i, QObject::tr(
"User Definable" ) );
159 static const QMap< int, QString > sCodes
161 {0, QStringLiteral(
"No color or time stored" )},
162 {1, QStringLiteral(
"Time is stored" )},
163 {2, QStringLiteral(
"Color is stored" )},
164 {3, QStringLiteral(
"Color and time are stored" )},
165 {6, QStringLiteral(
"Time is stored" )},
166 {7, QStringLiteral(
"Time and color are stored)" )},
167 {8, QStringLiteral(
"Time, color and near infrared are stored" )},
175 static const QMap< int, QString > sCodes
177 {0, QObject::tr(
"No color or time stored" )},
178 {1, QObject::tr(
"Time is stored" )},
179 {2, QObject::tr(
"Color is stored" )},
180 {3, QObject::tr(
"Color and time are stored" )},
181 {6, QObject::tr(
"Time is stored" )},
182 {7, QObject::tr(
"Time and color are stored)" )},
183 {8, QObject::tr(
"Time, color and near infrared are stored" )},
196 return pcIndex.metadataStatistics();
208 return tr(
"QGIS expression" );
228 QVector<QVariantMap> acceptedPoints;
229 std::unique_ptr<QgsPointCloudBlock> block(
mIndex.nodeData( n,
mRequest ) );
232 return acceptedPoints;
234 const char *ptr = block->data();
237 int xOffset = 0, yOffset = 0, zOffset = 0;
241 auto extentEngine = std::make_unique< QgsGeos >(
mExtentGeometry.constGet() );
242 extentEngine->prepareGeometry();
244 std::optional<bool> copcTimeFlag = std::nullopt;
245 QVariantMap extraMetadata =
mIndex.extraMetadata();
246 if ( extraMetadata.contains( QStringLiteral(
"CopcGpsTimeFlag" ) ) )
247 copcTimeFlag = extraMetadata[ QStringLiteral(
"CopcGpsTimeFlag" ) ].toBool();
252 QgsPointCloudAttribute::getPointXYZ( ptr, i, recordSize, xOffset, xType, yOffset, yType, zOffset, zType, block->scale(), block->offset(), x, y, z );
254 if (
mZRange.contains( z ) && extentEngine->contains( x, y ) )
257 pointAttr[ QStringLiteral(
"X" ) ] = x;
258 pointAttr[ QStringLiteral(
"Y" ) ] = y;
259 pointAttr[ QStringLiteral(
"Z" ) ] = z;
262 if ( copcTimeFlag.has_value() )
264 const QDateTime gpsBaseTime = QDateTime::fromSecsSinceEpoch( 315964809, Qt::UTC );
265 constexpr int numberOfSecsInWeek = 3600 * 24 * 7;
269 if ( *copcTimeFlag || pointAttr[QStringLiteral(
"GpsTime" )].toDouble() > numberOfSecsInWeek )
271 const QString utcTime = gpsBaseTime.addSecs(
static_cast<qint64
>( pointAttr[QStringLiteral(
"GpsTime" )].toDouble() + 1e9 ) ).toString( Qt::ISODate );
272 pointAttr[ QStringLiteral(
"GpsTime (raw)" )] = pointAttr[QStringLiteral(
"GpsTime" )];
273 pointAttr[ QStringLiteral(
"GpsTime" )] = utcTime;
277 const QString weekTime = gpsBaseTime.addSecs( pointAttr[QStringLiteral(
"GpsTime" )].toLongLong() ).toString(
"ddd hh:mm:ss" );
278 pointAttr[ QStringLiteral(
"GpsTime (raw)" )] = pointAttr[QStringLiteral(
"GpsTime" )];
279 pointAttr[ QStringLiteral(
"GpsTime" )] = weekTime;
283 acceptedPoints.push_back( pointAttr );
286 return acceptedPoints;
304 QVector<QVariantMap> acceptedPoints;
307 for ( QgsPointCloudSubIndex &subidx :
subIndexes() )
313 || ( !subidx.zRange().overlaps( extentZRange ) )
314 || !subidx.polygonBounds().intersects( extentGeometry ) )
316 acceptedPoints.append(
identify(
index, maxError, extentGeometry, extentZRange, pointsLimit ) );
321 acceptedPoints.append(
identify( mainIndex, maxError, extentGeometry, extentZRange, pointsLimit ) );
323 return acceptedPoints;
333 QVector<QVariantMap> acceptedPoints;
335 if ( !
index.isValid() )
336 return acceptedPoints;
339 const QVector<QgsPointCloudNodeId> nodes = traverseTree(
index, root, maxError, root.
error(), extentGeometry, extentZRange );
345 acceptedPoints = QtConcurrent::blockingMappedReduced( nodes,
347 qOverload<
const QVector<QMap<QString, QVariant>>&>( &QVector<QMap<QString, QVariant>>::append ),
348 QtConcurrent::UnorderedReduce );
350 return acceptedPoints;
353QVector<QgsPointCloudNodeId> QgsPointCloudDataProvider::traverseTree(
363 QVector<QgsPointCloudNodeId> nodes;
367 if ( !extentZRange.
overlaps( nodeZRange ) )
373 nodes.append( node.
id() );
375 const double childrenError = nodeError / 2.0;
376 if ( childrenError < maxError )
383 nodes += traverseTree( pc, childNode, maxError, childrenError, extentGeometry, extentZRange );
393 Q_UNUSED( updateFeatureCount )
398 if ( !i.setSubsetString( subset ) )
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
A 3-dimensional box composed of x, y, z coordinates.
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.
virtual Qgis::DataProviderFlags flags() const
Returns the generic data provider flags.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
QgsDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Create a new dataprovider with the specified in the uri.
QgsDataSourceUri uri() const
Gets the data source specification.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
QgsRange which stores a range of double values.
A geometry is the spatial representation of a feature.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
A collection of point cloud attributes.
int pointRecordSize() const
Returns total size of record.
const QgsPointCloudAttribute * find(const QString &attributeName, int &offset) const
Finds the attribute with the name.
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.
static QVariantMap getAttributeMap(const char *data, std::size_t recordOffset, const QgsPointCloudAttributeCollection &attributeCollection)
Retrieves all the attributes of a point.
DataType type() const
Returns the data type.
QString subsetStringDialect() const override
Returns a user-friendly string describing the dialect which is supported for subset strings by the pr...
@ NoCapabilities
Provider has no capabilities.
bool setSubsetString(const QString &subset, bool updateFeatureCount=false) override
Set the subset string used to create a subset of features in the layer.
~QgsPointCloudDataProvider() override
QgsPointCloudDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions, Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Ctor.
static QMap< int, QString > dataFormatIds()
Returns the map of LAS data format ID to untranslated string value.
bool supportsSubsetString() const override
Returns true if the provider supports setting of subset strings.
virtual QVector< QgsPointCloudSubIndex > subIndexes()
Returns a list of sub indexes available if the provider supports multiple indexes,...
QVector< QVariantMap > identify(double maxError, const QgsGeometry &extentGeometry, const QgsDoubleRange &extentZRange=QgsDoubleRange(), int pointsLimit=1000)
Returns the list of points of the point cloud according to a zoom level defined by maxError (in layer...
QgsPointCloudStatistics metadataStatistics()
Returns the object containing the statistics metadata extracted from the dataset.
virtual QgsPointCloudIndex index() const
Returns the point cloud index associated with the provider.
QString subsetStringHelpUrl() const override
Returns a URL pointing to documentation describing the dialect which is supported for subset strings ...
QString subsetString() const override
Returns the subset definition string currently in use by the layer and used by the provider to limit ...
static QMap< int, QString > translatedDataFormatIds()
Returns the map of LAS data format ID to translated string value.
virtual QgsPointCloudDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities for the data provider.
static QMap< int, QString > translatedLasClassificationCodes()
Returns the map of LAS classification code to translated string value, corresponding to the ASPRS Sta...
QString mSubsetString
String used to define a subset of the layer.
static QMap< int, QString > lasClassificationCodes()
Returns the map of LAS classification code to untranslated string value, corresponding to the ASPRS S...
QFlags< Capability > Capabilities
virtual QgsPointCloudRenderer * createRenderer(const QVariantMap &configuration=QVariantMap()) const
Creates a new 2D point cloud renderer, using provider backend specific information.
bool hasValidIndex() const
Returns whether provider has index which is valid.
virtual QVariantMap originalMetadata() const
Returns a representation of the original metadata included in a point cloud dataset.
virtual QgsGeometry polygonBounds() const
Returns the polygon bounds of the layer.
Smart pointer for QgsAbstractPointCloudIndex.
QgsPointCloudNode getNode(const QgsPointCloudNodeId &id) const
Returns object for a given node.
Represents an indexed point cloud node's position in octree.
Keeps metadata for an indexed point cloud node.
QList< QgsPointCloudNodeId > children() const
Returns IDs of child nodes.
QgsPointCloudNodeId id() const
Returns node's ID (unique in index).
float error() const
Returns node's error in map units (used to determine in whether the node has enough detail for the cu...
QgsBox3D bounds() const
Returns node's bounding cube in CRS coords.
Abstract base class for 2d point cloud renderers.
Point cloud data request.
void setAttributes(const QgsPointCloudAttributeCollection &attributes)
Set attributes filter in the request.
Used to store statistics of a point cloud dataset.
bool overlaps(const QgsRange< T > &other) const
Returns true if this range overlaps another range.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
QVector< QMap< QString, QVariant > > result_type
QVector< QVariantMap > operator()(QgsPointCloudNodeId n)
MapIndexedPointCloudNode(QgsPointCloudRequest &request, const QgsVector3D &indexScale, const QgsVector3D &indexOffset, const QgsGeometry &extentGeometry, const QgsDoubleRange &zRange, QgsPointCloudIndex index, int pointsLimit)
const QgsGeometry & mExtentGeometry
const QgsDoubleRange & mZRange
QgsPointCloudIndex mIndex
QgsPointCloudRequest & mRequest
Setting options for creating vector data providers.