20#include "moc_qgspointclouddataprovider.cpp"
33#include <QtConcurrent/QtConcurrentMap>
57 return lIndex && lIndex->isValid();
83 static QMap< int, QString > sCodes
85 {0, QStringLiteral(
"Created, Never Classified" )},
86 {1, QStringLiteral(
"Unclassified" )},
87 {2, QStringLiteral(
"Ground" )},
88 {3, QStringLiteral(
"Low Vegetation" )},
89 {4, QStringLiteral(
"Medium Vegetation" )},
90 {5, QStringLiteral(
"High Vegetation" )},
91 {6, QStringLiteral(
"Building" )},
92 {7, QStringLiteral(
"Low Point (Low Noise)" )},
93 {8, QStringLiteral(
"Reserved" )},
94 {9, QStringLiteral(
"Water" )},
95 {10, QStringLiteral(
"Rail" )},
96 {11, QStringLiteral(
"Road Surface" )},
97 {12, QStringLiteral(
"Reserved" )},
98 {13, QStringLiteral(
"Wire - Guard (Shield)" )},
99 {14, QStringLiteral(
"Wire - Conductor (Phase)" )},
100 {15, QStringLiteral(
"Transmission Tower" )},
101 {16, QStringLiteral(
"Wire-Structure Connector (Insulator)" )},
102 {17, QStringLiteral(
"Bridge Deck" )},
103 {18, QStringLiteral(
"High Noise" )},
106 static std::once_flag initialized;
107 std::call_once( initialized, [ = ]( )
109 for (
int i = 19; i <= 63; ++i )
110 sCodes.insert( i, QStringLiteral(
"Reserved" ) );
111 for (
int i = 64; i <= 255; ++i )
112 sCodes.insert( i, QStringLiteral(
"User Definable" ) );
120 static QMap< int, QString > sCodes
122 {0, QObject::tr(
"Created, Never Classified" )},
123 {1, QObject::tr(
"Unclassified" )},
124 {2, QObject::tr(
"Ground" )},
125 {3, QObject::tr(
"Low Vegetation" )},
126 {4, QObject::tr(
"Medium Vegetation" )},
127 {5, QObject::tr(
"High Vegetation" )},
128 {6, QObject::tr(
"Building" )},
129 {7, QObject::tr(
"Low Point (Noise)" )},
130 {8, QObject::tr(
"Reserved" )},
131 {9, QObject::tr(
"Water" )},
132 {10, QObject::tr(
"Rail" )},
133 {11, QObject::tr(
"Road Surface" )},
134 {12, QObject::tr(
"Reserved" )},
135 {13, QObject::tr(
"Wire - Guard (Shield)" )},
136 {14, QObject::tr(
"Wire - Conductor (Phase)" )},
137 {15, QObject::tr(
"Transmission Tower" )},
138 {16, QObject::tr(
"Wire-Structure Connector (Insulator)" )},
139 {17, QObject::tr(
"Bridge Deck" )},
140 {18, QObject::tr(
"High Noise" )},
143 static std::once_flag initialized;
144 std::call_once( initialized, [ = ]( )
146 for (
int i = 19; i <= 63; ++i )
147 sCodes.insert( i, QObject::tr(
"Reserved" ) );
148 for (
int i = 64; i <= 255; ++i )
149 sCodes.insert( i, QObject::tr(
"User Definable" ) );
157 static const QMap< int, QString > sCodes
159 {0, QStringLiteral(
"No color or time stored" )},
160 {1, QStringLiteral(
"Time is stored" )},
161 {2, QStringLiteral(
"Color is stored" )},
162 {3, QStringLiteral(
"Color and time are stored" )},
163 {6, QStringLiteral(
"Time is stored" )},
164 {7, QStringLiteral(
"Time and color are stored)" )},
165 {8, QStringLiteral(
"Time, color and near infrared are stored" )},
173 static const QMap< int, QString > sCodes
175 {0, QObject::tr(
"No color or time stored" )},
176 {1, QObject::tr(
"Time is stored" )},
177 {2, QObject::tr(
"Color is stored" )},
178 {3, QObject::tr(
"Color and time are stored" )},
179 {6, QObject::tr(
"Time is stored" )},
180 {7, QObject::tr(
"Time and color are stored)" )},
181 {8, QObject::tr(
"Time, color and near infrared are stored" )},
194 return pcIndex->metadataStatistics();
206 return tr(
"QGIS expression" );
226 QVector<QVariantMap> acceptedPoints;
230 return acceptedPoints;
232 const char *ptr = block->data();
235 int xOffset = 0, yOffset = 0, zOffset = 0;
240 extentEngine->prepareGeometry();
244 QgsPointCloudAttribute::getPointXYZ( ptr, i, recordSize, xOffset, xType, yOffset, yType, zOffset, zType, block->scale(), block->offset(), x, y, z );
249 pointAttr[ QStringLiteral(
"X" ) ] = x;
250 pointAttr[ QStringLiteral(
"Y" ) ] = y;
251 pointAttr[ QStringLiteral(
"Z" ) ] = z;
254 if (
const QgsCopcPointCloudIndex *copcIndex =
dynamic_cast<QgsCopcPointCloudIndex *
>(
mIndex ) )
256 const QDateTime gpsBaseTime = QDateTime::fromSecsSinceEpoch( 315964809, Qt::UTC );
257 constexpr int numberOfSecsInWeek = 3600 * 24 * 7;
261 if ( copcIndex->gpsTimeFlag() || pointAttr[QStringLiteral(
"GpsTime" )].toDouble() > numberOfSecsInWeek )
263 const QString utcTime = gpsBaseTime.addSecs(
static_cast<qint64
>( pointAttr[QStringLiteral(
"GpsTime" )].toDouble() + 1e9 ) ).toString( Qt::ISODate );
264 pointAttr[ QStringLiteral(
"GpsTime (raw)" )] = pointAttr[QStringLiteral(
"GpsTime" )];
265 pointAttr[ QStringLiteral(
"GpsTime" )] = utcTime;
269 const QString weekTime = gpsBaseTime.addSecs( pointAttr[QStringLiteral(
"GpsTime" )].toLongLong() ).toString(
"ddd hh:mm:ss" );
270 pointAttr[ QStringLiteral(
"GpsTime (raw)" )] = pointAttr[QStringLiteral(
"GpsTime" )];
271 pointAttr[ QStringLiteral(
"GpsTime" )] = weekTime;
275 acceptedPoints.push_back( pointAttr );
278 return acceptedPoints;
296 QVector<QVariantMap> acceptedPoints;
299 for ( QgsPointCloudSubIndex &subidx :
subIndexes() )
304 || ( !subidx.zRange().overlaps( extentZRange ) )
305 || !subidx.polygonBounds().intersects( extentGeometry ) )
307 acceptedPoints.append(
identify( subidx.index(), maxError, extentGeometry, extentZRange, pointsLimit ) );
311 acceptedPoints.append(
identify(
index(), maxError, extentGeometry, extentZRange, pointsLimit ) );
313 return acceptedPoints;
323 QVector<QVariantMap> acceptedPoints;
326 return acceptedPoints;
329 const QVector<QgsPointCloudNodeId> nodes = traverseTree(
index, root, maxError, root.
error(), extentGeometry, extentZRange );
335 acceptedPoints = QtConcurrent::blockingMappedReduced( nodes,
337 qOverload<
const QVector<QMap<QString, QVariant>>&>( &QVector<QMap<QString, QVariant>>::append ),
338 QtConcurrent::UnorderedReduce );
340 return acceptedPoints;
343QVector<QgsPointCloudNodeId> QgsPointCloudDataProvider::traverseTree(
353 QVector<QgsPointCloudNodeId> nodes;
357 if ( !extentZRange.
overlaps( nodeZRange ) )
363 nodes.append( node.
id() );
365 const double childrenError = nodeError / 2.0;
366 if ( childrenError < maxError )
373 nodes += traverseTree( pc, childNode, maxError, childrenError, extentGeometry, extentZRange );
383 Q_UNUSED( updateFeatureCount )
384 const auto i =
index();
388 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.
Abstract base class for spatial data provider implementations.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
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.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
bool intersects(const QgsRectangle &rectangle) const
Returns true if this geometry exactly intersects with a rectangle.
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.
QVector< QgsPointCloudAttribute > attributes() const
Returns all attributes.
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.
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...
virtual QgsPointCloudIndex * index() const
Returns the point cloud index associated with the provider.
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.
Represents a indexed point clouds data in octree.
QgsVector3D offset() const
Returns offset of data from CRS.
QgsVector3D scale() const
Returns scale of data relative to CRS.
virtual bool isValid() const =0
Returns whether index is loaded and valid.
QgsPointCloudNodeId root()
Returns root node of the index.
virtual QgsPointCloudNode getNode(const QgsPointCloudNodeId &id) const
Returns object for a given node.
QgsPointCloudAttributeCollection attributes() const
Returns all attributes that are stored in the file.
virtual std::unique_ptr< QgsPointCloudBlock > nodeData(const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request)=0
Returns node data block.
Represents a indexed point cloud node's position in octree.
Keeps metadata for indexed point cloud node.
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.
Class used to store statistics of a point cloud dataset.
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.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
QVector< QMap< QString, QVariant > > result_type
MapIndexedPointCloudNode(QgsPointCloudRequest &request, const QgsVector3D &indexScale, const QgsVector3D &indexOffset, const QgsGeometry &extentGeometry, const QgsDoubleRange &zRange, QgsPointCloudIndex *index, int pointsLimit)
QVector< QVariantMap > operator()(QgsPointCloudNodeId n)
const QgsGeometry & mExtentGeometry
QgsPointCloudIndex * mIndex
const QgsDoubleRange & mZRange
QgsPointCloudRequest & mRequest
Setting options for creating vector data providers.