QGIS API Documentation 3.43.0-Master (b60ef06885e)
qgspointcloudlayer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspointcloudlayer.cpp
3 --------------------
4 begin : October 2020
5 copyright : (C) 2020 by Peter Petrik
6 email : zilolv 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#include "qgseventtracing.h"
19#include "qgspointcloudlayer.h"
20#include "moc_qgspointcloudlayer.cpp"
24#include "qgspointcloudindex.h"
27#include "qgsrectangle.h"
29#include "qgsproviderregistry.h"
30#include "qgslogger.h"
33#include "qgsruntimeprofiler.h"
34#include "qgsapplication.h"
35#include "qgspainting.h"
38#include "qgsmaplayerlegend.h"
39#include "qgsxmlutils.h"
40#include "qgsmaplayerfactory.h"
43#include "qgsmessagelog.h"
44#include "qgstaskmanager.h"
45#include "qgsthreadingutils.h"
48#include "qgsvirtualpointcloudprovider.h"
49
50
51#include <QUrl>
52
54 const QString &baseName,
55 const QString &providerLib,
57 : QgsMapLayer( Qgis::LayerType::PointCloud, baseName, uri )
58 , mElevationProperties( new QgsPointCloudLayerElevationProperties( this ) )
59 , mLayerOptions( options )
60{
61 if ( !uri.isEmpty() && !providerLib.isEmpty() )
62 {
63 const QgsDataProvider::ProviderOptions providerOptions { options.transformContext };
64 Qgis::DataProviderReadFlags providerFlags;
65 if ( options.loadDefaultStyle )
66 {
68 }
69 setDataSource( uri, baseName, providerLib, providerOptions, providerFlags );
70 }
71
74 connect( undoStack(), &QUndoStack::indexChanged, this, &QgsMapLayer::layerModified );
75 connect( this, &QgsMapLayer::layerModified, this, [this] { triggerRepaint(); } );
76}
77
79{
80 if ( QgsTask *task = QgsApplication::taskManager()->task( mStatsCalculationTask ) )
81 {
82 mStatsCalculationTask = 0;
83 task->cancel();
84 task->waitForFinished();
85 }
86}
87
89{
91
92 QgsPointCloudLayer *layer = new QgsPointCloudLayer( source(), name(), mProviderKey, mLayerOptions );
93 QgsMapLayer::clone( layer );
94
95 if ( mRenderer )
96 layer->setRenderer( mRenderer->clone() );
97
98 layer->mElevationProperties = mElevationProperties->clone();
99 layer->mElevationProperties->setParent( layer );
100
101 layer->mLayerOptions = mLayerOptions;
102 layer->mSync3DRendererTo2DRenderer = mSync3DRendererTo2DRenderer;
103
104 return layer;
105}
106
108{
110
111 if ( !mDataProvider )
112 return QgsRectangle();
113
114 return mDataProvider->extent();
115}
116
118{
120
121 if ( mRenderer->type() != QLatin1String( "extent" ) )
122 loadIndexesForRenderContext( rendererContext );
123
124 return new QgsPointCloudLayerRenderer( this, rendererContext );
125}
126
133
140
142{
144
145 return mDataProvider.get();
146}
147
148bool QgsPointCloudLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
149{
151
152 // create provider
153 const QDomNode pkeyNode = layerNode.namedItem( QStringLiteral( "provider" ) );
154 mProviderKey = pkeyNode.toElement().text();
155
157 {
158 const QgsDataProvider::ProviderOptions providerOptions { context.transformContext() };
160 // read extent
162 {
163 const QDomNode extentNode = layerNode.namedItem( QStringLiteral( "extent" ) );
164 if ( !extentNode.isNull() )
165 {
166 // get the extent
167 const QgsRectangle mbr = QgsXmlUtils::readRectangle( extentNode.toElement() );
168
169 // store the extent
170 setExtent( mbr );
171 }
172 }
173
175 const QDomNode subset = layerNode.namedItem( QStringLiteral( "subset" ) );
176 const QString subsetText = subset.toElement().text();
177 if ( !subsetText.isEmpty() )
178 setSubsetString( subsetText );
179 }
180
181 if ( !isValid() )
182 {
183 return false;
184 }
185
186 QString errorMsg;
187 if ( !readSymbology( layerNode, errorMsg, context ) )
188 return false;
189
190 readStyleManager( layerNode );
191 return true;
192}
193
194bool QgsPointCloudLayer::writeXml( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const
195{
197
198 QDomElement mapLayerNode = layerNode.toElement();
199 mapLayerNode.setAttribute( QStringLiteral( "type" ), QgsMapLayerFactory::typeToString( Qgis::LayerType::PointCloud ) );
200
201 if ( !subsetString().isEmpty() )
202 {
203 QDomElement subset = doc.createElement( QStringLiteral( "subset" ) );
204 const QDomText subsetText = doc.createTextNode( subsetString() );
205 subset.appendChild( subsetText );
206 layerNode.appendChild( subset );
207 }
208 if ( mDataProvider )
209 {
210 QDomElement provider = doc.createElement( QStringLiteral( "provider" ) );
211 const QDomText providerText = doc.createTextNode( providerType() );
212 provider.appendChild( providerText );
213 layerNode.appendChild( provider );
214 }
215
216 writeStyleManager( layerNode, doc );
217
218 QString errorMsg;
219 return writeSymbology( layerNode, doc, errorMsg, context );
220}
221
222bool QgsPointCloudLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
223{
225
226 const QDomElement elem = node.toElement();
227
228 readCommonStyle( elem, context, categories );
229
230 readStyle( node, errorMessage, context, categories );
231
232 if ( categories.testFlag( CustomProperties ) )
233 readCustomProperties( node, QStringLiteral( "variable" ) );
234
235 return true;
236}
237
238bool QgsPointCloudLayer::readStyle( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
239{
241
242 bool result = true;
243
244 if ( categories.testFlag( Symbology3D ) )
245 {
246 bool ok;
247 bool sync = node.attributes().namedItem( QStringLiteral( "sync3DRendererTo2DRenderer" ) ).nodeValue().toInt( &ok );
248 if ( ok )
250 }
251
252 if ( categories.testFlag( Symbology ) )
253 {
254 QDomElement rendererElement = node.firstChildElement( QStringLiteral( "renderer" ) );
255 if ( !rendererElement.isNull() )
256 {
257 std::unique_ptr< QgsPointCloudRenderer > r( QgsPointCloudRenderer::load( rendererElement, context ) );
258 if ( r )
259 {
260 setRenderer( r.release() );
261 }
262 else
263 {
264 result = false;
265 }
266 }
267 // make sure layer has a renderer - if none exists, fallback to a default renderer
268 if ( !mRenderer )
269 {
271 }
272 }
273
274 if ( categories.testFlag( Symbology ) )
275 {
276 // get and set the blend mode if it exists
277 const QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
278 if ( !blendModeNode.isNull() )
279 {
280 const QDomElement e = blendModeNode.toElement();
281 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
282 }
283 }
284
285 // get and set the layer transparency and scale visibility if they exists
286 if ( categories.testFlag( Rendering ) )
287 {
288 const QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
289 if ( !layerOpacityNode.isNull() )
290 {
291 const QDomElement e = layerOpacityNode.toElement();
292 setOpacity( e.text().toDouble() );
293 }
294
295 const bool hasScaleBasedVisibiliy { node.attributes().namedItem( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).nodeValue() == '1' };
296 setScaleBasedVisibility( hasScaleBasedVisibiliy );
297 bool ok;
298 const double maxScale { node.attributes().namedItem( QStringLiteral( "maxScale" ) ).nodeValue().toDouble( &ok ) };
299 if ( ok )
300 {
301 setMaximumScale( maxScale );
302 }
303 const double minScale { node.attributes().namedItem( QStringLiteral( "minScale" ) ).nodeValue().toDouble( &ok ) };
304 if ( ok )
305 {
306 setMinimumScale( minScale );
307 }
308 }
309 return result;
310}
311
312bool QgsPointCloudLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
313 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
314{
316
317 Q_UNUSED( errorMessage )
318
319 QDomElement elem = node.toElement();
320 writeCommonStyle( elem, doc, context, categories );
321
322 ( void )writeStyle( node, doc, errorMessage, context, categories );
323
324 return true;
325}
326
327bool QgsPointCloudLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
328{
330
331 QDomElement mapLayerNode = node.toElement();
332
333 if ( categories.testFlag( Symbology3D ) )
334 {
335 mapLayerNode.setAttribute( QStringLiteral( "sync3DRendererTo2DRenderer" ), mSync3DRendererTo2DRenderer ? 1 : 0 );
336 }
337
338 if ( categories.testFlag( Symbology ) )
339 {
340 if ( mRenderer )
341 {
342 const QDomElement rendererElement = mRenderer->save( doc, context );
343 node.appendChild( rendererElement );
344 }
345 }
346
347 //save customproperties
348 if ( categories.testFlag( CustomProperties ) )
349 {
350 writeCustomProperties( node, doc );
351 }
352
353 if ( categories.testFlag( Symbology ) )
354 {
355 // add the blend mode field
356 QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
357 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
358 blendModeElem.appendChild( blendModeText );
359 node.appendChild( blendModeElem );
360 }
361
362 // add the layer opacity and scale visibility
363 if ( categories.testFlag( Rendering ) )
364 {
365 QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
366 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
367 layerOpacityElem.appendChild( layerOpacityText );
368 node.appendChild( layerOpacityElem );
369
370 mapLayerNode.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
371 mapLayerNode.setAttribute( QStringLiteral( "maxScale" ), maximumScale() );
372 mapLayerNode.setAttribute( QStringLiteral( "minScale" ), minimumScale() );
373 }
374 return true;
375}
376
378{
380
381 if ( mDataProvider )
382 mDataProvider->setTransformContext( transformContext );
384}
385
386void QgsPointCloudLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
388{
390
391 if ( mDataProvider )
392 {
393 disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
394 disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
395 }
396
397 setName( baseName );
398 mProviderKey = provider;
399 mDataSource = dataSource;
400
401 if ( mPreloadedProvider )
402 {
403 mDataProvider.reset( qobject_cast< QgsPointCloudDataProvider * >( mPreloadedProvider.release() ) );
404 }
405 else
406 {
407 std::unique_ptr< QgsScopedRuntimeProfile > profile;
408 if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
409 profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Create %1 provider" ).arg( provider ), QStringLiteral( "projectload" ) );
410 mDataProvider.reset( qobject_cast<QgsPointCloudDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource, options, flags ) ) );
411 }
412
413 if ( !mDataProvider )
414 {
415 QgsDebugError( QStringLiteral( "Unable to get point cloud data provider" ) );
416 setValid( false );
417 return;
418 }
419
420 mDataProvider->setParent( this );
421 QgsDebugMsgLevel( QStringLiteral( "Instantiated the point cloud data provider plugin" ), 2 );
422
423 setValid( mDataProvider->isValid() );
424 if ( !isValid() )
425 {
426 QgsDebugError( QStringLiteral( "Invalid point cloud provider plugin %1" ).arg( QString( mDataSource.toUtf8() ) ) );
427 setError( mDataProvider->error() );
428 return;
429 }
430
431 connect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
432 connect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
433
434 // Load initial extent, crs and renderer
435 setCrs( mDataProvider->crs() );
437 {
438 setExtent3D( mDataProvider->extent3D() );
439 }
440
441 bool loadDefaultStyleFlag = false;
443 {
444 loadDefaultStyleFlag = true;
445 }
446
447 if ( !mLayerOptions.skipIndexGeneration &&
448 mDataProvider &&
450 mDataProvider->pointCount() > 0 )
451 {
452 mDataProvider->generateIndex();
453 }
454
455 if ( !mLayerOptions.skipStatisticsCalculation &&
456 mDataProvider &&
458 mDataProvider->pointCount() > 0 )
459 {
460 calculateStatistics();
461 }
462
463 if ( !mRenderer || loadDefaultStyleFlag )
464 {
465 std::unique_ptr< QgsScopedRuntimeProfile > profile;
466 if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
467 profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Load layer style" ), QStringLiteral( "projectload" ) );
468
469 bool defaultLoadedFlag = false;
470
471 if ( loadDefaultStyleFlag && isSpatial() && mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
472 {
473 // first try to create a renderer directly from the data provider
474 std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
475 if ( defaultRenderer )
476 {
477 defaultLoadedFlag = true;
478 setRenderer( defaultRenderer.release() );
479 }
480 }
481
482 if ( !defaultLoadedFlag && loadDefaultStyleFlag )
483 {
484 loadDefaultStyle( defaultLoadedFlag );
485 }
486
487 if ( !defaultLoadedFlag )
488 {
489 // all else failed, create default renderer
491 }
492 }
493}
494
495QString QgsPointCloudLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
496{
498
500}
501
502QString QgsPointCloudLayer::decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const
503{
505
507}
508
509void QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged( QgsPointCloudDataProvider::PointCloudIndexGenerationState state )
510{
512
513 switch ( state )
514 {
516 {
517 resetRenderer();
518 break;
519 }
521 {
522 QgsError providerError = mDataProvider->error();
523 if ( !providerError.isEmpty() )
524 {
525 setError( providerError );
526 emit raiseError( providerError.summary() );
527 }
528 break;
529 }
531 break;
532 }
533}
534
535
536QString QgsPointCloudLayer::loadDefaultStyle( bool &resultFlag )
537{
539
540 if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
541 {
542 // first try to create a renderer directly from the data provider
543 std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
544 if ( defaultRenderer )
545 {
546 resultFlag = true;
547 setRenderer( defaultRenderer.release() );
548 return QString();
549 }
550 }
551
552 return QgsMapLayer::loadDefaultStyle( resultFlag );
553}
554
556{
558
559 const QgsLayerMetadataFormatter htmlFormatter( metadata() );
560 QString myMetadata = QStringLiteral( "<html>\n<body>\n" );
561
562 myMetadata += generalHtmlMetadata();
563
564 // Begin Provider section
565 myMetadata += QStringLiteral( "<h1>" ) + tr( "Information from provider" ) + QStringLiteral( "</h1>\n<hr>\n" );
566 myMetadata += QLatin1String( "<table class=\"list-view\">\n" );
567
568 // Extent
569 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );
570
571 // feature count
572 QLocale locale = QLocale();
573 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
574 const qint64 pointCount = mDataProvider ? mDataProvider->pointCount() : -1;
575 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
576 + tr( "Point count" ) + QStringLiteral( "</td><td>" )
577 + ( pointCount < 0 ? tr( "unknown" ) : locale.toString( static_cast<qlonglong>( pointCount ) ) )
578 + QStringLiteral( "</td></tr>\n" );
579
580 if ( const QgsPointCloudDataProvider *provider = dataProvider() )
581 {
582 myMetadata += provider->htmlMetadata();
583 }
584
585 myMetadata += QLatin1String( "</table>\n<br><br>" );
586
587 // CRS
588 myMetadata += crsHtmlMetadata();
589
590 // provider metadata section
591 myMetadata += QStringLiteral( "<h1>" ) + tr( "Metadata" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
592 const QVariantMap originalMetadata = mDataProvider ? mDataProvider->originalMetadata() : QVariantMap();
593
594 if ( originalMetadata.value( QStringLiteral( "creation_year" ) ).toInt() > 0 && originalMetadata.contains( QStringLiteral( "creation_doy" ) ) )
595 {
596 QDate creationDate( originalMetadata.value( QStringLiteral( "creation_year" ) ).toInt(), 1, 1 );
597 creationDate = creationDate.addDays( originalMetadata.value( QStringLiteral( "creation_doy" ) ).toInt() );
598
599 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
600 + tr( "Creation date" ) + QStringLiteral( "</td><td>" )
601 + creationDate.toString( Qt::ISODate )
602 + QStringLiteral( "</td></tr>\n" );
603 }
604 if ( originalMetadata.contains( QStringLiteral( "major_version" ) ) && originalMetadata.contains( QStringLiteral( "minor_version" ) ) )
605 {
606 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
607 + tr( "Version" ) + QStringLiteral( "</td><td>" )
608 + QStringLiteral( "%1.%2" ).arg( originalMetadata.value( QStringLiteral( "major_version" ) ).toString(),
609 originalMetadata.value( QStringLiteral( "minor_version" ) ).toString() )
610 + QStringLiteral( "</td></tr>\n" );
611 }
612
613 if ( !originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toString().isEmpty() )
614 {
615 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
616 + tr( "Data format" ) + QStringLiteral( "</td><td>" )
617 + QStringLiteral( "%1 (%2)" ).arg( QgsPointCloudDataProvider::translatedDataFormatIds().value( originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toInt() ),
618 originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toString() ).trimmed()
619 + QStringLiteral( "</td></tr>\n" );
620 }
621
622 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
623 + tr( "Scale X" ) + QStringLiteral( "</td><td>" )
624 + QString::number( originalMetadata.value( QStringLiteral( "scale_x" ) ).toDouble() )
625 + QStringLiteral( "</td></tr>\n" );
626 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
627 + tr( "Scale Y" ) + QStringLiteral( "</td><td>" )
628 + QString::number( originalMetadata.value( QStringLiteral( "scale_y" ) ).toDouble() )
629 + QStringLiteral( "</td></tr>\n" );
630 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
631 + tr( "Scale Z" ) + QStringLiteral( "</td><td>" )
632 + QString::number( originalMetadata.value( QStringLiteral( "scale_z" ) ).toDouble() )
633 + QStringLiteral( "</td></tr>\n" );
634
635 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
636 + tr( "Offset X" ) + QStringLiteral( "</td><td>" )
637 + QString::number( originalMetadata.value( QStringLiteral( "offset_x" ) ).toDouble() )
638 + QStringLiteral( "</td></tr>\n" );
639 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
640 + tr( "Offset Y" ) + QStringLiteral( "</td><td>" )
641 + QString::number( originalMetadata.value( QStringLiteral( "offset_y" ) ).toDouble() )
642 + QStringLiteral( "</td></tr>\n" );
643 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
644 + tr( "Offset Z" ) + QStringLiteral( "</td><td>" )
645 + QString::number( originalMetadata.value( QStringLiteral( "offset_z" ) ).toDouble() )
646 + QStringLiteral( "</td></tr>\n" );
647
648 if ( !originalMetadata.value( QStringLiteral( "project_id" ) ).toString().isEmpty() )
649 {
650 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
651 + tr( "Project ID" ) + QStringLiteral( "</td><td>" )
652 + originalMetadata.value( QStringLiteral( "project_id" ) ).toString()
653 + QStringLiteral( "</td></tr>\n" );
654 }
655
656 if ( !originalMetadata.value( QStringLiteral( "system_id" ) ).toString().isEmpty() )
657 {
658 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
659 + tr( "System ID" ) + QStringLiteral( "</td><td>" )
660 + originalMetadata.value( QStringLiteral( "system_id" ) ).toString()
661 + QStringLiteral( "</td></tr>\n" );
662 }
663
664 if ( !originalMetadata.value( QStringLiteral( "software_id" ) ).toString().isEmpty() )
665 {
666 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
667 + tr( "Software ID" ) + QStringLiteral( "</td><td>" )
668 + originalMetadata.value( QStringLiteral( "software_id" ) ).toString()
669 + QStringLiteral( "</td></tr>\n" );
670 }
671
672 // End Provider section
673 myMetadata += QLatin1String( "</table>\n<br><br>" );
674
675 // identification section
676 myMetadata += QStringLiteral( "<h1>" ) + tr( "Identification" ) + QStringLiteral( "</h1>\n<hr>\n" );
677 myMetadata += htmlFormatter.identificationSectionHtml( );
678 myMetadata += QLatin1String( "<br><br>\n" );
679
680 // extent section
681 myMetadata += QStringLiteral( "<h1>" ) + tr( "Extent" ) + QStringLiteral( "</h1>\n<hr>\n" );
682 myMetadata += htmlFormatter.extentSectionHtml( isSpatial() );
683 myMetadata += QLatin1String( "<br><br>\n" );
684
685 // Start the Access section
686 myMetadata += QStringLiteral( "<h1>" ) + tr( "Access" ) + QStringLiteral( "</h1>\n<hr>\n" );
687 myMetadata += htmlFormatter.accessSectionHtml( );
688 myMetadata += QLatin1String( "<br><br>\n" );
689
690 // Attributes section
691 myMetadata += QStringLiteral( "<h1>" ) + tr( "Attributes" ) + QStringLiteral( "</h1>\n<hr>\n<table class=\"list-view\">\n" );
692
694
695 // count attributes
696 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Count" ) + QStringLiteral( "</td><td>" ) + QString::number( attrs.count() ) + QStringLiteral( "</td></tr>\n" );
697
698 myMetadata += QLatin1String( "</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
699 myMetadata += QLatin1String( "<tr><th>" ) + tr( "Attribute" ) + QLatin1String( "</th><th>" ) + tr( "Type" ) + QLatin1String( "</th></tr>\n" );
700
701 for ( int i = 0; i < attrs.count(); ++i )
702 {
703 const QgsPointCloudAttribute attribute = attrs.at( i );
704 QString rowClass;
705 if ( i % 2 )
706 rowClass = QStringLiteral( "class=\"odd-row\"" );
707 myMetadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + attribute.name() + QLatin1String( "</td><td>" ) + attribute.displayType() + QLatin1String( "</td></tr>\n" );
708 }
709
710 //close field list
711 myMetadata += QLatin1String( "</table>\n<br><br>" );
712
713
714 // Start the contacts section
715 myMetadata += QStringLiteral( "<h1>" ) + tr( "Contacts" ) + QStringLiteral( "</h1>\n<hr>\n" );
716 myMetadata += htmlFormatter.contactsSectionHtml( );
717 myMetadata += QLatin1String( "<br><br>\n" );
718
719 // Start the links section
720 myMetadata += QStringLiteral( "<h1>" ) + tr( "Links" ) + QStringLiteral( "</h1>\n<hr>\n" );
721 myMetadata += htmlFormatter.linksSectionHtml( );
722 myMetadata += QLatin1String( "<br><br>\n" );
723
724 // Start the history section
725 myMetadata += QStringLiteral( "<h1>" ) + tr( "History" ) + QStringLiteral( "</h1>\n<hr>\n" );
726 myMetadata += htmlFormatter.historySectionHtml( );
727 myMetadata += QLatin1String( "<br><br>\n" );
728
729 myMetadata += customPropertyHtmlMetadata();
730
731 myMetadata += QLatin1String( "\n</body>\n</html>\n" );
732 return myMetadata;
733}
734
741
743{
745
746 return mDataProvider ? mDataProvider->attributes() : QgsPointCloudAttributeCollection();
747}
748
750{
752
753 return mDataProvider ? mDataProvider->pointCount() : 0;
754}
755
762
764{
766
767 return mRenderer.get();
768}
769
771{
773
774 if ( renderer == mRenderer.get() )
775 return;
776
777 mRenderer.reset( renderer );
778 emit rendererChanged();
780
781 if ( mSync3DRendererTo2DRenderer )
783}
784
785bool QgsPointCloudLayer::setSubsetString( const QString &subset )
786{
788
789 if ( !isValid() || !mDataProvider )
790 {
791 QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
792 setCustomProperty( QStringLiteral( "storedSubsetString" ), subset );
793 return false;
794 }
795 else if ( subset == mDataProvider->subsetString() )
796 return true;
797
798 bool res = mDataProvider->setSubsetString( subset );
799 if ( res )
800 {
801 emit subsetStringChanged();
803 }
804 return res;
805}
806
808{
810
811 if ( !isValid() || !mDataProvider )
812 {
813 QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
814 return customProperty( QStringLiteral( "storedSubsetString" ) ).toString();
815 }
816 return mDataProvider->subsetString();
817}
818
820{
822
823 bool result = false;
825 if ( r )
826 {
827 result = r->convertFrom2DRenderer( renderer() );
828 setRenderer3D( r );
830 }
831 return result;
832}
833
835{
837
838 return mSync3DRendererTo2DRenderer;
839}
840
842{
844
845 mSync3DRendererTo2DRenderer = sync;
846 if ( sync )
848}
849
850void QgsPointCloudLayer::calculateStatistics()
851{
853
854 if ( !mDataProvider.get() || !mDataProvider->hasValidIndex() )
855 {
856 QgsMessageLog::logMessage( QObject::tr( "Failed to calculate statistics of the point cloud %1" ).arg( this->name() ) );
857 return;
858 }
859 if ( mStatsCalculationTask )
860 {
861 QgsMessageLog::logMessage( QObject::tr( "A statistics calculation task for the point cloud %1 is already in progress" ).arg( this->name() ) );
862 return;
863 }
864
865 QgsPointCloudStatistics indexStats = mDataProvider->metadataStatistics();
866 QList<QString> indexStatsAttributes = indexStats.statisticsMap().keys();
867 QVector<QgsPointCloudAttribute> attributes = mDataProvider->attributes().attributes();
868 // Do not calculate stats for attributes that the index gives us stats for
869 for ( int i = 0; i < attributes.size(); ++i )
870 {
871 if ( indexStatsAttributes.contains( attributes[i].name() ) )
872 {
873 attributes.remove( i );
874 --i;
875 }
876 }
877
878 // Use the layer statistics for now, until we can calculate complete ones
879 mStatistics = indexStats;
880 if ( attributes.empty() && indexStats.sampledPointsCount() > 0 )
881 {
882 // All attributes are covered by the saved stats, skip calculating anything
884 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
885 resetRenderer();
886 return;
887 }
888
889 QgsPointCloudStatsCalculationTask *task = new QgsPointCloudStatsCalculationTask( mDataProvider->index(), attributes, 1000000 );
890 connect( task, &QgsTask::taskCompleted, this, [this, task, indexStats, indexStatsAttributes]()
891 {
892 mStatistics = task->calculationResults();
893
894 // Fetch what we can directly from the index
895 QMap<QString, QgsPointCloudAttributeStatistics> statsMap = mStatistics.statisticsMap();
896 for ( const QString &attribute : indexStatsAttributes )
897 {
898 statsMap[ attribute ] = indexStats.statisticsOf( attribute );
899 }
900 mStatistics = QgsPointCloudStatistics( mStatistics.sampledPointsCount(), statsMap );
901
903 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
904 resetRenderer();
905 mStatsCalculationTask = 0;
906#ifdef HAVE_COPC
907 if ( mDataProvider && mDataProvider->index() && mDataProvider->index().isValid() && mDataProvider->name() == QLatin1String( "pdal" ) && mStatistics.sampledPointsCount() != 0 )
908 {
909 mDataProvider->index().writeStatistics( mStatistics );
910 }
911#endif
912 } );
913
914 // In case the statistics calculation fails, QgsTask::taskTerminated will be called
915 connect( task, &QgsTask::taskTerminated, this, [this]()
916 {
917 if ( mStatsCalculationTask )
918 {
919 QgsMessageLog::logMessage( QObject::tr( "Failed to calculate statistics of the point cloud %1" ).arg( this->name() ) );
920 mStatsCalculationTask = 0;
921 }
922 } );
923
924 mStatsCalculationTask = QgsApplication::taskManager()->addTask( task );
925
927 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
928}
929
930void QgsPointCloudLayer::resetRenderer()
931{
933
934 mDataProvider->loadIndex();
936 {
937 calculateStatistics();
938 }
939 if ( !mRenderer || mRenderer->type() == QLatin1String( "extent" ) )
940 {
942 }
944
945 emit rendererChanged();
946}
947
948void QgsPointCloudLayer::loadIndexesForRenderContext( QgsRenderContext &rendererContext ) const
949{
950 if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::ContainSubIndexes )
951 {
952 QgsRectangle renderExtent;
953 try
954 {
955 renderExtent = rendererContext.coordinateTransform().transformBoundingBox( rendererContext.mapExtent(), Qgis::TransformDirection::Reverse );
956 }
957 catch ( QgsCsException & )
958 {
959 QgsDebugError( QStringLiteral( "Transformation of extent failed!" ) );
960 }
961
962 const QVector<QgsPointCloudSubIndex> subIndex = mDataProvider->subIndexes();
963 if ( const QgsVirtualPointCloudProvider *vpcProvider = dynamic_cast<QgsVirtualPointCloudProvider *>( mDataProvider.get() ) )
964 {
965 for ( int i = 0; i < subIndex.size(); ++i )
966 {
967 // no need to load as it's there
968 if ( subIndex.at( i ).index() )
969 continue;
970
971 if ( subIndex.at( i ).extent().intersects( renderExtent ) &&
972 ( renderExtent.width() < vpcProvider->averageSubIndexWidth() ||
973 renderExtent.height() < vpcProvider->averageSubIndexHeight() ) )
974 {
975 mDataProvider->loadSubIndex( i );
976 }
977 }
978 }
979 }
980}
981
983{
985 if ( mEditIndex )
986 return false;
987
988 mEditIndex = QgsPointCloudIndex( new QgsPointCloudEditingIndex( this ) );
989
990 if ( !mEditIndex.isValid() )
991 {
992 mEditIndex = QgsPointCloudIndex();
993 return false;
994 }
995
996 emit editingStarted();
997 return true;
998}
999
1001{
1003 if ( !mEditIndex )
1004 return false;
1005
1006 if ( mEditIndex.isModified() )
1007 {
1008 if ( !mEditIndex.commitChanges( &mCommitError ) )
1009 return false;
1010
1011 // emitting layerModified() is not required as that's done automatically
1012 // when undo stack index changes
1013 }
1014
1015 undoStack()->clear();
1016
1017 if ( stopEditing )
1018 {
1019 mEditIndex = QgsPointCloudIndex();
1020 emit editingStopped();
1021 }
1022
1023 return true;
1024}
1025
1027{
1029 return mCommitError;
1030}
1031
1033{
1035 if ( !mEditIndex )
1036 return false;
1037
1038 const QList<QgsPointCloudNodeId> updatedNodes = mEditIndex.updatedNodes();
1039
1040 undoStack()->clear();
1041
1042 mEditIndex = QgsPointCloudIndex();
1043 emit editingStopped();
1044
1045 if ( !updatedNodes.isEmpty() )
1046 {
1047 for ( const QgsPointCloudNodeId &n : updatedNodes )
1049
1050 // emitting layerModified() is not required as that's done automatically
1051 // when undo stack index changes
1052 }
1053
1054 return true;
1055}
1056
1058{
1060 return mDataProvider && mDataProvider->capabilities() & QgsPointCloudDataProvider::Capability::ChangeAttributeValues;
1061}
1062
1064{
1066 if ( mEditIndex )
1067 return true;
1068
1069 return false;
1070}
1071
1073{
1075 if ( !mEditIndex )
1076 return false;
1077
1078 return mEditIndex.isModified();
1079}
1080
1081bool QgsPointCloudLayer::changeAttributeValue( const QgsPointCloudNodeId &n, const QVector<int> &points, const QgsPointCloudAttribute &attribute, double value )
1082{
1083 return this->changeAttributeValue( { { n, points } }, attribute, value );
1084}
1085
1086bool QgsPointCloudLayer::changeAttributeValue( const QHash<QgsPointCloudNodeId, QVector<int>> &nodesAndPoints, const QgsPointCloudAttribute &attribute, double value )
1087{
1089
1090 QgsEventTracing::ScopedEvent _trace( QStringLiteral( "PointCloud" ), QStringLiteral( "QgsPointCloudLayer::changeAttributeValue" ) );
1091
1092 if ( !mEditIndex )
1093 return false;
1094
1095 // Cannot allow x,y,z editing as points may get moved outside the node extents
1096 if ( attribute.name().compare( QLatin1String( "X" ), Qt::CaseInsensitive ) == 0 ||
1097 attribute.name().compare( QLatin1String( "Y" ), Qt::CaseInsensitive ) == 0 ||
1098 attribute.name().compare( QLatin1String( "Z" ), Qt::CaseInsensitive ) == 0 )
1099 return false;
1100
1101 const QgsPointCloudAttributeCollection attributeCollection = mEditIndex.attributes();
1102
1103 int attributeOffset;
1104 const QgsPointCloudAttribute *at = attributeCollection.find( attribute.name(), attributeOffset );
1105
1106 if ( !at ||
1107 at->size() != attribute.size() ||
1108 at->type() != attribute.type() )
1109 {
1110 return false;
1111 }
1112
1113 if ( !QgsPointCloudLayerEditUtils::isAttributeValueValid( attribute, value ) )
1114 {
1115 return false;
1116 }
1117
1118 for ( auto it = nodesAndPoints.constBegin(); it != nodesAndPoints.constEnd(); it++ )
1119 {
1120 QgsPointCloudNodeId n = it.key();
1121 QVector<int> points = it.value();
1122
1123 if ( !n.isValid() || !mEditIndex.hasNode( n ) ) // todo: should not have to check if n.isValid
1124 return false;
1125
1126 if ( points.isEmpty() )
1127 continue;
1128
1129 int pointsMin = std::numeric_limits<int>::max();
1130 int pointsMax = std::numeric_limits<int>::min();
1131 for ( int pt : std::as_const( points ) )
1132 {
1133 if ( pt < pointsMin )
1134 pointsMin = pt;
1135 if ( pt > pointsMax )
1136 pointsMax = pt;
1137 }
1138
1139 if ( pointsMin < 0 || pointsMax >= mEditIndex.getNode( n ).pointCount() )
1140 return false;
1141
1142 }
1143
1144 undoStack()->push( new QgsPointCloudLayerUndoCommandChangeAttribute( this, nodesAndPoints, attribute, value ) );
1145
1146 return true;
1147}
1148
1150{
1152 if ( mEditIndex )
1153 return mEditIndex;
1154
1155 if ( mDataProvider )
1156 return mDataProvider->index();
1157
1158 return QgsPointCloudIndex();
1159}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:4760
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
@ LoadDefaultStyle
Reset the layer's style to the default for the datasource.
@ SkipGetExtent
Skip the extent from provider.
@ Reverse
Reverse/inverse transform (from destination to source)
Base class for point cloud 3D renderers.
virtual bool convertFrom2DRenderer(QgsPointCloudRenderer *renderer)=0
Updates the 3D renderer's symbol to match that of a given QgsPointCloudRenderer.
Abstract base class for objects which generate elevation profiles.
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
Contains information about the context in which a coordinate transform is executed.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
A container for error messages.
Definition qgserror.h:81
bool isEmpty() const
Test if no error is set.
Definition qgserror.h:110
QString summary() const
Short error description, usually the first error in chain, the real error.
Definition qgserror.cpp:129
Formats layer metadata into HTML.
Base class for storage of map layer elevation properties.
static QString typeToString(Qgis::LayerType type)
Converts a map layer type to a string value.
static QgsMapLayerLegend * defaultPointCloudLegend(QgsPointCloudLayer *layer)
Create new legend implementation for a point cloud layer.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for all map layer types.
Definition qgsmaplayer.h:77
QString name
Definition qgsmaplayer.h:81
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
void setError(const QgsError &error)
Sets error message.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
QString source() const
Returns the source for the layer.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
virtual void setExtent3D(const QgsBox3D &box)
Sets the extent.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void configChanged()
Emitted whenever the configuration is changed.
void trigger3DUpdate()
Will advise any 3D maps that this layer requires to be updated in the scene.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
static Qgis::DataProviderReadFlags providerReadFlags(const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags)
Returns provider read flag deduced from layer read flags layerReadFlags and a dom node layerNode that...
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
void editingStarted()
Emitted when editing on this layer has started.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
void setDataSource(const QString &dataSource, const QString &baseName=QString(), const QString &provider=QString(), bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
QString mLayerName
Name of the layer - used for display.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
QString crsHtmlMetadata() const
Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
QgsLayerMetadata metadata
Definition qgsmaplayer.h:83
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
QFlags< StyleCategory > StyleCategories
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
QString mProviderKey
Data provider key (name of the data provider)
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
std::unique_ptr< QgsDataProvider > mPreloadedProvider
Optionally used when loading a project, it is released when the layer is effectively created.
void rendererChanged()
Signal emitted when renderer is changed.
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
void dataChanged()
Data of layer changed.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void setName(const QString &name)
Set the display name of the layer.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
QString mDataSource
Data source description string, varies by layer type.
@ FlagReadExtentFromXml
Read extent from xml and skip get extent from provider.
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
void setValid(bool valid)
Sets whether layer is valid or not.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
double minimumScale() const
Returns the minimum map scale (i.e.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
double opacity
Definition qgsmaplayer.h:89
@ Symbology
Symbology.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
@ Symbology3D
3D symbology
@ CustomProperties
Custom properties (by plugins for instance)
void layerModified()
Emitted when modifications has been done on layer.
void setRenderer3D(QgsAbstract3DRenderer *renderer)
Sets 3D renderer for the layer.
QString customPropertyHtmlMetadata() const
Returns an HTML fragment containing custom property information, for use in the htmlMetadata() method...
QString generalHtmlMetadata() const
Returns an HTML fragment containing general metadata information, for use in the htmlMetadata() metho...
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
double maximumScale() const
Returns the maximum map scale (i.e.
void invalidateWgs84Extent()
Invalidates the WGS84 extent.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
A collection of point cloud attributes.
const QgsPointCloudAttribute & at(int index) const
Returns the attribute at the specified index.
const QgsPointCloudAttribute * find(const QString &attributeName, int &offset) const
Finds the attribute with the name.
int count() const
Returns the number of attributes present in the collection.
Attribute for point cloud data pair of name and size in bytes.
QString displayType() const
Returns the type to use when displaying this field.
int size() const
Returns size of the attribute in bytes.
QString name() const
Returns name of the attribute.
DataType type() const
Returns the data type.
Base class for providing data for QgsPointCloudLayer.
@ CreateRenderer
Provider can create 2D renderers using backend-specific formatting information. See QgsPointCloudData...
@ ChangeAttributeValues
Provider can modify the values of point attributes.
@ ContainSubIndexes
Provider can contain multiple indexes. Virtual point cloud files for example.
static QMap< int, QString > translatedDataFormatIds()
Returns the map of LAS data format ID to translated string value.
void indexGenerationStateChanged(QgsPointCloudDataProvider::PointCloudIndexGenerationState state)
Emitted when point cloud generation state is changed.
PointCloudIndexGenerationState
Point cloud index state.
@ NotIndexed
Provider has no index available.
@ Indexing
Provider try to index the source data.
@ Indexed
The index is ready to be used.
A QgsPointCloudIndex that is used as an editing buffer when editing point cloud data.
Smart pointer for QgsAbstractPointCloudIndex.
bool isModified() const
Returns true if there are uncommitted changes, false otherwise.
bool isValid() const
Returns whether index is loaded and valid.
bool commitChanges(QString *errorMessage=nullptr)
Tries to store pending changes to the data provider.
QgsPointCloudNode getNode(const QgsPointCloudNodeId &id) const
Returns object for a given node.
QList< QgsPointCloudNodeId > updatedNodes() const
Returns a list of node IDs that have been modified.
bool hasNode(const QgsPointCloudNodeId &id) const
Returns whether the octree contain given node.
QgsPointCloudAttributeCollection attributes() const
Returns all attributes that are stored in the file.
static bool isAttributeValueValid(const QgsPointCloudAttribute &attribute, double value)
Check if value is within proper range for the attribute.
Point cloud layer specific subclass of QgsMapLayerElevationProperties.
QgsPointCloudLayerElevationProperties * clone() const override
Creates a clone of the properties.
Implementation of QgsAbstractProfileGenerator for point cloud layers.
Implementation of threaded rendering for point cloud layers.
An undo command subclass for changing point attribute values in a point cloud index.
Represents a map layer supporting display of point clouds.
QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const override
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
void setSync3DRendererTo2DRenderer(bool sync)
Sets whether this layer's 3D renderer should be automatically updated with changes applied to the lay...
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
@ Calculated
The statistics calculation task is done and statistics are available.
@ NotStarted
The statistics calculation task has not been started.
@ Calculating
The statistics calculation task is running.
bool sync3DRendererTo2DRenderer() const
Returns whether this layer's 3D renderer should be automatically updated with changes applied to the ...
bool writeXml(QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by children to write state specific to them to project files.
QgsRectangle extent() const override
Returns the extent of the layer.
bool isModified() const override
Returns true if the layer has been modified since last commit/save.
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
bool changeAttributeValue(const QgsPointCloudNodeId &n, const QVector< int > &points, const QgsPointCloudAttribute &attribute, double value)
Attempts to modify attribute values for specific points in the editing buffer.
QgsPointCloudRenderer * renderer()
Returns the 2D renderer for the point cloud.
bool convertRenderer3DFromRenderer2D()
Updates the layer's 3D renderer's symbol to match that of the layer's 2D renderer.
qint64 pointCount() const
Returns the total number of points available in the layer.
QgsPointCloudIndex index() const
Returns the point cloud index associated with the layer.
bool commitChanges(bool stopEditing=true)
Attempts to commit to the underlying data provider any buffered changes made since the last to call t...
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const override
Write the style for the layer into the document provided.
void raiseError(const QString &msg)
Signals an error related to this point cloud layer.
PointCloudStatisticsCalculationState statisticsCalculationState() const
Returns the status of point cloud statistics calculation.
QgsPointCloudDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
bool isEditable() const override
Returns true if the layer can be edited.
void statisticsCalculationStateChanged(QgsPointCloudLayer::PointCloudStatisticsCalculationState state)
Emitted when statistics calculation state has changed.
bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) override
Read the symbology for the current layer from the DOM node supplied.
bool rollBack()
Stops a current editing operation and discards any uncommitted edits.
bool readXml(const QDomNode &layerNode, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files.
QString subsetString() const
Returns the string used to define a subset of the layer.
void chunkAttributeValuesChanged(const QgsPointCloudNodeId &n)
Emitted when a node gets some attribute values of some points changed.
QgsPointCloudLayer(const QString &uri=QString(), const QString &baseName=QString(), const QString &providerLib=QStringLiteral("pointcloud"), const QgsPointCloudLayer::LayerOptions &options=QgsPointCloudLayer::LayerOptions())
Constructor - creates a point cloud layer.
bool setSubsetString(const QString &subset)
Sets the string used to define a subset of the layer.
QString commitError() const
Returns the last error message generated when attempting to commit changes to the layer.
QgsPointCloudLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) FINAL
Read the style for the current layer from the DOM node supplied.
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const FINAL
Write just the symbology information for the layer into the document.
void setRenderer(QgsPointCloudRenderer *renderer)
Sets the 2D renderer for the point cloud.
QString loadDefaultStyle(bool &resultFlag) FINAL
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
QgsPointCloudAttributeCollection attributes() const
Returns the attributes available from the layer.
void subsetStringChanged()
Emitted when the layer's subset string has changed.
void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
bool startEditing()
Makes the layer editable.
bool supportsEditing() const override
Returns whether the layer supports editing or not.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
QgsAbstractProfileGenerator * createProfileGenerator(const QgsProfileRequest &request) override
Given a profile request, returns a new profile generator ready for generating elevation profiles.
Represents an indexed point cloud node's position in octree.
bool isValid() const
Returns whether node is valid.
qint64 pointCount() const
Returns number of points contained in node data.
static QgsPointCloudRenderer * defaultRenderer(const QgsPointCloudLayer *layer)
Returns a new default point cloud renderer for a specified layer.
Abstract base class for 2d point cloud renderers.
static QgsPointCloudRenderer * load(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer from an XML element.
Used to store statistics of a point cloud dataset.
int sampledPointsCount() const
Returns the number of points used to calculate the statistics.
QMap< QString, QgsPointCloudAttributeStatistics > statisticsMap() const
Returns a map object containing all the statistics.
QgsPointCloudAttributeStatistics statisticsOf(const QString &attribute) const
Returns the calculated statistics of attribute attribute.
Encapsulates properties and constraints relating to fetching elevation profiles from different source...
QString absoluteToRelativeUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts absolute path(s) to relative path(s) in the given provider-specific URI.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString relativeToAbsoluteUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts relative path(s) to absolute path(s) in the given provider-specific URI.
A container for the context for various read/write operations on objects.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
A rectangle specified with double values.
Q_INVOKABLE QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
Contains information about the context of a rendering operation.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Abstract base class for long running background tasks.
void taskCompleted()
Will be emitted by task to indicate its successful completion.
void taskTerminated()
Will be emitted by task if it has terminated for any reason other then completion (e....
static QgsRectangle readRectangle(const QDomElement &element)
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:41
#define QgsDebugError(str)
Definition qgslogger.h:40
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Setting options for creating vector data providers.
Setting options for loading point cloud layers.
bool skipStatisticsCalculation
Set to true if the statistics calculation for this point cloud is disabled.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
bool skipIndexGeneration
Set to true if point cloud index generation should be skipped.
QgsCoordinateTransformContext transformContext
Coordinate transform context.