32#include <QtConcurrentMap>
35#include "moc_qgspointclouddataprovider.cpp"
37using namespace Qt::StringLiterals;
61 return lIndex.isValid();
87 static QMap< int, QString > sCodes
89 {0, u
"Created, Never Classified"_s},
90 {1, u
"Unclassified"_s},
92 {3, u
"Low Vegetation"_s},
93 {4, u
"Medium Vegetation"_s},
94 {5, u
"High Vegetation"_s},
96 {7, u
"Low Point (Low Noise)"_s},
100 {11, u
"Road Surface"_s},
102 {13, u
"Wire - Guard (Shield)"_s},
103 {14, u
"Wire - Conductor (Phase)"_s},
104 {15, u
"Transmission Tower"_s},
105 {16, u
"Wire-Structure Connector (Insulator)"_s},
106 {17, u
"Bridge Deck"_s},
107 {18, u
"High Noise"_s},
110 static std::once_flag initialized;
111 std::call_once( initialized, []( )
113 for (
int i = 19; i <= 63; ++i )
114 sCodes.insert( i, u
"Reserved"_s );
115 for (
int i = 64; i <= 255; ++i )
116 sCodes.insert( i, u
"User Definable"_s );
124 static QMap< int, QString > sCodes
126 {0, QObject::tr(
"Created, Never Classified" )},
127 {1, QObject::tr(
"Unclassified" )},
128 {2, QObject::tr(
"Ground" )},
129 {3, QObject::tr(
"Low Vegetation" )},
130 {4, QObject::tr(
"Medium Vegetation" )},
131 {5, QObject::tr(
"High Vegetation" )},
132 {6, QObject::tr(
"Building" )},
133 {7, QObject::tr(
"Low Point (Noise)" )},
134 {8, QObject::tr(
"Reserved" )},
135 {9, QObject::tr(
"Water" )},
136 {10, QObject::tr(
"Rail" )},
137 {11, QObject::tr(
"Road Surface" )},
138 {12, QObject::tr(
"Reserved" )},
139 {13, QObject::tr(
"Wire - Guard (Shield)" )},
140 {14, QObject::tr(
"Wire - Conductor (Phase)" )},
141 {15, QObject::tr(
"Transmission Tower" )},
142 {16, QObject::tr(
"Wire-Structure Connector (Insulator)" )},
143 {17, QObject::tr(
"Bridge Deck" )},
144 {18, QObject::tr(
"High Noise" )},
147 static std::once_flag initialized;
148 std::call_once( initialized, []( )
150 for (
int i = 19; i <= 63; ++i )
151 sCodes.insert( i, QObject::tr(
"Reserved" ) );
152 for (
int i = 64; i <= 255; ++i )
153 sCodes.insert( i, QObject::tr(
"User Definable" ) );
161 static const QMap< int, QString > sCodes
163 {0, u
"No color or time stored"_s},
164 {1, u
"Time is stored"_s},
165 {2, u
"Color is stored"_s},
166 {3, u
"Color and time are stored"_s},
167 {6, u
"Time is stored"_s},
168 {7, u
"Time and color are stored)"_s},
169 {8, u
"Time, color and near infrared are stored"_s},
177 static const QMap< int, QString > sCodes
179 {0, QObject::tr(
"No color or time stored" )},
180 {1, QObject::tr(
"Time is stored" )},
181 {2, QObject::tr(
"Color is stored" )},
182 {3, QObject::tr(
"Color and time are stored" )},
183 {6, QObject::tr(
"Time is stored" )},
184 {7, QObject::tr(
"Time and color are stored)" )},
185 {8, QObject::tr(
"Time, color and near infrared are stored" )},
198 return pcIndex.metadataStatistics();
210 return tr(
"QGIS expression" );
230 QVector<QVariantMap> acceptedPoints;
231 std::unique_ptr<QgsPointCloudBlock> block(
mIndex.nodeData( n,
mRequest ) );
234 return acceptedPoints;
236 const char *ptr = block->data();
239 int xOffset = 0, yOffset = 0, zOffset = 0;
243 auto extentEngine = std::make_unique< QgsGeos >(
mExtentGeometry.constGet() );
244 extentEngine->prepareGeometry();
246 std::optional<bool> copcTimeFlag = std::nullopt;
247 QVariantMap extraMetadata =
mIndex.extraMetadata();
248 if ( extraMetadata.contains( u
"CopcGpsTimeFlag"_s ) )
249 copcTimeFlag = extraMetadata[ u
"CopcGpsTimeFlag"_s ].toBool();
254 QgsPointCloudAttribute::getPointXYZ( ptr, i, recordSize, xOffset, xType, yOffset, yType, zOffset, zType, block->scale(), block->offset(), x, y, z );
256 if (
mZRange.contains( z ) && extentEngine->contains( x, y ) )
259 pointAttr[ u
"X"_s ] = x;
260 pointAttr[ u
"Y"_s ] = y;
261 pointAttr[ u
"Z"_s ] = z;
264 if ( copcTimeFlag.has_value() )
266 const QDateTime gpsBaseTime = QDateTime::fromSecsSinceEpoch( 315964809, Qt::UTC );
267 constexpr int numberOfSecsInWeek = 3600 * 24 * 7;
271 if ( *copcTimeFlag || pointAttr[u
"GpsTime"_s].toDouble() > numberOfSecsInWeek )
273 const QString utcTime = gpsBaseTime.addSecs(
static_cast<qint64
>( pointAttr[u
"GpsTime"_s].toDouble() + 1e9 ) ).toString( Qt::ISODate );
274 pointAttr[ u
"GpsTime (raw)"_s] = pointAttr[u
"GpsTime"_s];
275 pointAttr[ u
"GpsTime"_s] = utcTime;
279 const QString weekTime = gpsBaseTime.addSecs( pointAttr[u
"GpsTime"_s].toLongLong() ).toString(
"ddd hh:mm:ss" );
280 pointAttr[ u
"GpsTime (raw)"_s] = pointAttr[u
"GpsTime"_s];
281 pointAttr[ u
"GpsTime"_s] = weekTime;
285 acceptedPoints.push_back( pointAttr );
288 return acceptedPoints;
306 QVector<QVariantMap> acceptedPoints;
309 for ( QgsPointCloudSubIndex &subidx :
subIndexes() )
315 || ( !subidx.zRange().overlaps( extentZRange ) )
316 || !subidx.polygonBounds().intersects( extentGeometry ) )
318 acceptedPoints.append(
identify(
index, maxError, extentGeometry, extentZRange, pointsLimit ) );
323 acceptedPoints.append(
identify( mainIndex, maxError, extentGeometry, extentZRange, pointsLimit ) );
325 return acceptedPoints;
335 QVector<QVariantMap> acceptedPoints;
337 if ( !
index.isValid() )
338 return acceptedPoints;
341 const QVector<QgsPointCloudNodeId> nodes = traverseTree(
index, root, maxError, root.
error(), extentGeometry, extentZRange );
347 acceptedPoints = QtConcurrent::blockingMappedReduced( nodes,
349 qOverload<
const QVector<QMap<QString, QVariant>>&>( &QVector<QMap<QString, QVariant>>::append ),
350 QtConcurrent::UnorderedReduce );
352 return acceptedPoints;
355QVector<QgsPointCloudNodeId> QgsPointCloudDataProvider::traverseTree(
365 QVector<QgsPointCloudNodeId> nodes;
369 if ( !extentZRange.
overlaps( nodeZRange ) )
375 nodes.append( node.
id() );
377 const double childrenError = nodeError / 2.0;
378 if ( childrenError < maxError )
385 nodes += traverseTree( pc, childNode, maxError, childrenError, extentGeometry, extentZRange );
395 Q_UNUSED( updateFeatureCount )
400 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.