QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgspointcloudlayerexporter.h
Go to the documentation of this file.
1/***************************************************************************
2 qgspointcloudlayerexporter.h
3 ---------------------
4 begin : July 2022
5 copyright : (C) 2022 by Stefanos Natsis
6 email : uclaros 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
18#ifndef QGSPOINTCLOUDLAYEREXPORTER_H
19#define QGSPOINTCLOUDLAYEREXPORTER_H
20
21#include "qgis_core.h"
22#include "qgspointcloudlayer.h"
23#include "qgstaskmanager.h"
24#include "qgsvectorfilewriter.h"
25#include "qgsvectorlayer.h"
26
27#ifdef HAVE_PDAL_QGIS
28#include <pdal/PointView.hpp>
29#include <pdal/PointTable.hpp>
30#include <pdal/Options.hpp>
31#endif
32
34class QgsGeos;
35
45{
46 public:
50 enum class ExportFormat : int
51 {
52 Memory = 0,
53 Las = 1,
54 Gpkg = 2,
55 Shp = 3,
56 Dxf = 4,
57 Csv = 5,
58 };
59
65 static QList< ExportFormat > supportedFormats() SIP_SKIP
66 {
67 QList< ExportFormat > formats;
68 formats
70#ifdef HAVE_PDAL_QGIS
72#endif
77 return formats;
78 }
79
84 static QString getOgrDriverName( ExportFormat format ) SIP_SKIP;
85
92
94
98 void setFileName( const QString &filename ) { mFilename = filename; }
99
103 QString fileName() const { return mFilename; }
104
108 void setLayerName( const QString &name ) { mName = name; }
109
113 QString layerName() const { return mName; }
114
120 void setFilterExtent( const QgsRectangle extent ) { mExtent = extent; }
121
125 QgsRectangle filterExtent() const { return mExtent; }
126
131 void setFilterGeometry( const QgsAbstractGeometry *geometry );
132
137 void setFilterGeometry( QgsMapLayer *layer, bool selectedFeaturesOnly = false );
138
143 void setZRange( const QgsDoubleRange zRange ) { mZRange = zRange; }
144
148 QgsDoubleRange zRange() const { return mZRange; }
149
155 void setFeedback( QgsFeedback *feedback ) { mFeedback = feedback; }
156
160 QgsFeedback *feedback() const { return mFeedback; }
161
167 void setAttributes( const QStringList &attributes );
168
173 void setNoAttributes() { mRequestedAttributes.clear(); }
174
178 void setAllAttributes();
179
183 QStringList attributes() const { return mRequestedAttributes; }
184
190 {
191 mTargetCrs = crs;
192 mTransformContext = context;
193 }
194
198 QgsCoordinateReferenceSystem crs() const { return mTargetCrs; }
199
205 bool setFormat( const ExportFormat format );
206
210 ExportFormat format() const { return mFormat; }
211
216 void setPointsLimit( qint64 limit ) { mPointsLimit = std::max< qint64 >( limit, 0 ); }
217
221 qint64 pointsLimit() { return mPointsLimit; }
222
227 void setActionOnExistingFile( const QgsVectorFileWriter::ActionOnExistingFile action ) { mActionOnExistingFile = action; }
228
234 void prepareExport();
235
239 void doExport();
240
245 QgsMapLayer *takeExportedLayer() SIP_FACTORY;
246
251 QString lastError() const { return mLastError; }
252
253 private:
254 void exportToSink( QgsFeatureSink * );
255
256 QgsFields outputFields();
257 const QgsPointCloudAttributeCollection requestedAttributeCollection();
258 void setLastError( QString error ) { mLastError = error; }
259
260 const QgsPointCloudAttributeCollection mLayerAttributeCollection;
261
262 QgsPointCloudIndex mIndex = QgsPointCloudIndex( nullptr );
263 QString mName = QObject::tr( "Exported" );
264 ExportFormat mFormat = ExportFormat::Memory;
265 QString mFilename;
266 QString mLastError;
267 QgsRectangle mExtent
268 = QgsRectangle( -std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(), false );
269 std::unique_ptr< QgsGeos > mFilterGeometryEngine;
270 QgsDoubleRange mZRange;
271 QgsFeedback *mFeedback = nullptr;
272 qint64 mPointsLimit = 0;
273 QStringList mRequestedAttributes;
274 QgsCoordinateReferenceSystem mSourceCrs;
275 QgsCoordinateReferenceSystem mTargetCrs;
276 QgsCoordinateTransformContext mTransformContext;
277 int mPointRecordFormat;
279
280 QgsMapLayer *mMemoryLayer = nullptr;
281 QgsFeatureSink *mVectorSink = nullptr;
282 QgsCoordinateTransform *mTransform = nullptr;
283
284
285 class ExporterBase
286 {
287 public:
288 ExporterBase() = default;
289 virtual ~ExporterBase() = default;
290 void run();
291
292 protected:
293 virtual void handlePoint( double x, double y, double z, const QVariantMap &map, const qint64 pointNumber ) = 0;
294 virtual void handleNode() = 0;
295 virtual void handleAll() = 0;
296 QgsPointCloudLayerExporter *mParent = nullptr;
297 };
298
299 class ExporterMemory : public ExporterBase
300 {
301 public:
302 ExporterMemory( QgsPointCloudLayerExporter *exp );
303 ~ExporterMemory() override;
304
305 private:
306 void handlePoint( double x, double y, double z, const QVariantMap &map, const qint64 pointNumber ) override;
307 void handleNode() override;
308 void handleAll() override;
309 QgsFeatureList mFeatures;
310 };
311
312 class ExporterVector : public ExporterBase
313 {
314 public:
315 ExporterVector( QgsPointCloudLayerExporter *exp );
316 ~ExporterVector() override;
317
318 private:
319 void handlePoint( double x, double y, double z, const QVariantMap &map, const qint64 pointNumber ) override;
320 void handleNode() override;
321 void handleAll() override;
322 QgsFeatureList mFeatures;
323 };
324
325#ifdef HAVE_PDAL_QGIS
326 class ExporterPdal : public ExporterBase
327 {
328 public:
329 ExporterPdal( QgsPointCloudLayerExporter *exp );
330
331 private:
332 void handlePoint( double x, double y, double z, const QVariantMap &map, const qint64 pointNumber ) override;
333 void handleNode() override;
334 void handleAll() override;
335 const int mPointFormat;
336 pdal::Options mOptions;
337 pdal::PointTable mTable;
338 pdal::PointViewPtr mView;
339 };
340#endif
341};
342
343
354class CORE_EXPORT QgsPointCloudLayerExporterTask : public QgsTask
355{
356 Q_OBJECT
357
358 public:
363
364 void cancel() override;
365
366 signals:
367
372
373 protected:
374 bool run() override;
375 void finished( bool result ) override;
376
377 private:
378 QgsPointCloudLayerExporter *mExp = nullptr;
379
380 std::unique_ptr< QgsFeedback > mOwnedFeedback;
381};
382#endif // QGSPOINTCLOUDLAYEREXPORTER_H
Abstract base class for all geometries.
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Handles coordinate transforms between two coordinate systems.
QgsRange which stores a range of double values.
Definition qgsrange.h:217
An interface for objects which accept features via addFeature(s) methods.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Container of fields for a vector layer.
Definition qgsfields.h:46
Does vector analysis using the GEOS library and handles import, export, and exception handling.
Definition qgsgeos.h:139
Base class for all map layer types.
Definition qgsmaplayer.h:83
A collection of point cloud attributes.
void cancel() override
Notifies the task that it should terminate.
QgsPointCloudLayerExporterTask(QgsPointCloudLayerExporter *exporter)
Constructor for QgsPointCloudLayerExporterTask.
void exportComplete()
Emitted when exporting the layer is successfully completed.
void finished(bool result) override
If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether ...
bool run() override
Performs the task's operation.
Handles exporting point cloud layers to memory layers, OGR supported files and PDAL supported files.
void setFeedback(QgsFeedback *feedback)
Sets a QgsFeedback object to allow cancellation / progress reporting.
QgsCoordinateReferenceSystem crs() const
Gets the crs for the exported file.
ExportFormat format() const
Returns the format for the exported file or layer.
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context=QgsCoordinateTransformContext())
Sets the crs for the exported file, and the transform context that will be used for reprojection if d...
QgsRectangle filterExtent() const
Gets the filter extent for points to be exported.
QString layerName() const
Gets the name for the new layer.
void setFilterExtent(const QgsRectangle extent)
Sets a filter extent for points to be exported in the target CRS Points that fall outside the extent ...
QgsDoubleRange zRange() const
Gets the inclusive range for Z values to be exported.
void setFileName(const QString &filename)
Sets the filename for the new layer.
void setActionOnExistingFile(const QgsVectorFileWriter::ActionOnExistingFile action)
Sets whether an existing output vector file should be overwritten on appended to.
ExportFormat
Supported export formats for point clouds.
QString lastError() const
Gets the last error that occurred during the exporting operation.
void setLayerName(const QString &name)
Sets the name for the new layer.
QString fileName() const
Gets the filename for the new layer.
void setZRange(const QgsDoubleRange zRange)
Sets an inclusive range for Z values to be exported.
void setPointsLimit(qint64 limit)
Sets the maximum number of points to be exported.
QStringList attributes() const
Gets the list of point cloud attributes that will be exported.
qint64 pointsLimit()
Gets the maximum number of points to be exported.
QgsPointCloudLayerExporter(QgsPointCloudLayer *layer)
Constructor for QgsPointCloudLayerExporter, associated with the specified layer.
void setNoAttributes()
Sets that no attributes will be exported.
static QList< ExportFormat > supportedFormats()
Gets a list of the supported export formats.
QgsFeedback * feedback() const
Gets a pointer to the QgsFeedback object used for cancellation / progress reporting,...
Represents a map layer supporting display of point clouds.
A rectangle specified with double values.
QgsTask(const QString &description=QString(), QgsTask::Flags flags=AllFlags)
Constructor for QgsTask.
ActionOnExistingFile
Enumeration to describe how to handle existing files.
@ CreateOrOverwriteFile
Create or overwrite file.
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_NODEFAULTCTORS
Definition qgis_sip.h:108
QList< QgsFeature > QgsFeatureList