QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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 "qgspointcloudlayer.h"
19
21#include "qgsapplication.h"
22#include "qgseventtracing.h"
24#include "qgslogger.h"
25#include "qgsmaplayerfactory.h"
26#include "qgsmaplayerlegend.h"
27#include "qgsmessagelog.h"
28#include "qgspainting.h"
31#include "qgspointcloudindex.h"
42#include "qgsproviderregistry.h"
43#include "qgsrectangle.h"
44#include "qgsruntimeprofiler.h"
45#include "qgstaskmanager.h"
46#include "qgsthreadingutils.h"
47#include "qgsvirtualpointcloudprovider.h"
48#include "qgsxmlutils.h"
49
50#include <QUrl>
51
52#include "moc_qgspointcloudlayer.cpp"
53
55 const QString &baseName,
56 const QString &providerLib,
58 : QgsMapLayer( Qgis::LayerType::PointCloud, baseName, uri )
59 , mElevationProperties( new QgsPointCloudLayerElevationProperties( this ) )
60 , mLayerOptions( options )
61{
62 if ( !uri.isEmpty() && !providerLib.isEmpty() )
63 {
64 const QgsDataProvider::ProviderOptions providerOptions { options.transformContext };
65 Qgis::DataProviderReadFlags providerFlags;
66 if ( options.loadDefaultStyle )
67 {
68 providerFlags |= Qgis::DataProviderReadFlag::LoadDefaultStyle;
69 }
70 setDataSource( uri, baseName, providerLib, providerOptions, providerFlags );
71 }
72
75 connect( undoStack(), &QUndoStack::indexChanged, this, &QgsMapLayer::layerModified );
76 connect( this, &QgsMapLayer::layerModified, this, [this] { triggerRepaint(); } );
77}
78
80{
81 if ( QgsTask *task = QgsApplication::taskManager()->task( mStatsCalculationTask ) )
82 {
83 mStatsCalculationTask = 0;
84 task->cancel();
85 task->waitForFinished();
86 }
87}
88
90{
92
93 QgsPointCloudLayer *layer = new QgsPointCloudLayer( source(), name(), mProviderKey, mLayerOptions );
94 QgsMapLayer::clone( layer );
95
96 if ( mRenderer )
97 layer->setRenderer( mRenderer->clone() );
98
99 layer->mElevationProperties = mElevationProperties->clone();
100 layer->mElevationProperties->setParent( layer );
101
102 layer->mLayerOptions = mLayerOptions;
103 layer->mSync3DRendererTo2DRenderer = mSync3DRendererTo2DRenderer;
104
105 return layer;
106}
107
109{
111
112 if ( !mDataProvider )
113 return QgsRectangle();
114
115 return mDataProvider->extent();
116}
117
119{
121
122 if ( mRenderer->type() != QLatin1String( "extent" ) )
123 loadIndexesForRenderContext( rendererContext );
124
125 return new QgsPointCloudLayerRenderer( this, rendererContext );
126}
127
134
141
143{
145
146 return mDataProvider.get();
147}
148
149bool QgsPointCloudLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
150{
152
153 // create provider
154 const QDomNode pkeyNode = layerNode.namedItem( QStringLiteral( "provider" ) );
155 mProviderKey = pkeyNode.toElement().text();
156
158 {
159 const QgsDataProvider::ProviderOptions providerOptions { context.transformContext() };
161 // read extent
163 {
164 const QDomNode extentNode = layerNode.namedItem( QStringLiteral( "extent" ) );
165 if ( !extentNode.isNull() )
166 {
167 // get the extent
168 const QgsRectangle mbr = QgsXmlUtils::readRectangle( extentNode.toElement() );
169
170 // store the extent
171 setExtent( mbr );
172 }
173 }
174
176 const QDomNode subset = layerNode.namedItem( QStringLiteral( "subset" ) );
177 const QString subsetText = subset.toElement().text();
178 if ( !subsetText.isEmpty() )
179 setSubsetString( subsetText );
180 }
181
182 if ( !isValid() )
183 {
184 return false;
185 }
186
187 QString errorMsg;
188 if ( !readSymbology( layerNode, errorMsg, context ) )
189 return false;
190
191 readStyleManager( layerNode );
192 return true;
193}
194
195bool QgsPointCloudLayer::writeXml( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const
196{
198
199 QDomElement mapLayerNode = layerNode.toElement();
200 mapLayerNode.setAttribute( QStringLiteral( "type" ), QgsMapLayerFactory::typeToString( Qgis::LayerType::PointCloud ) );
201
202 if ( !subsetString().isEmpty() )
203 {
204 QDomElement subset = doc.createElement( QStringLiteral( "subset" ) );
205 const QDomText subsetText = doc.createTextNode( subsetString() );
206 subset.appendChild( subsetText );
207 layerNode.appendChild( subset );
208 }
209 if ( mDataProvider )
210 {
211 QDomElement provider = doc.createElement( QStringLiteral( "provider" ) );
212 const QDomText providerText = doc.createTextNode( providerType() );
213 provider.appendChild( providerText );
214 layerNode.appendChild( provider );
215 }
216
217 writeStyleManager( layerNode, doc );
218
219 QString errorMsg;
220 return writeSymbology( layerNode, doc, errorMsg, context );
221}
222
223bool QgsPointCloudLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
224{
226
227 const QDomElement elem = node.toElement();
228
229 readCommonStyle( elem, context, categories );
230
231 readStyle( node, errorMessage, context, categories );
232
233 if ( categories.testFlag( CustomProperties ) )
234 readCustomProperties( node, QStringLiteral( "variable" ) );
235
236 if ( categories.testFlag( Legend ) )
237 {
238 QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Legend" ) );
239
240 const QDomElement legendElem = node.firstChildElement( QStringLiteral( "legend" ) );
241 if ( QgsMapLayerLegend *l = legend(); !legendElem.isNull() )
242 {
243 l->readXml( legendElem, context );
244 }
245 }
246
247 return true;
248}
249
250bool QgsPointCloudLayer::readStyle( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
251{
253
254 bool result = true;
255
256 if ( categories.testFlag( Symbology3D ) )
257 {
258 bool ok;
259 bool sync = node.attributes().namedItem( QStringLiteral( "sync3DRendererTo2DRenderer" ) ).nodeValue().toInt( &ok );
260 if ( ok )
262 }
263
264 if ( categories.testFlag( Symbology ) )
265 {
266 QDomElement rendererElement = node.firstChildElement( QStringLiteral( "renderer" ) );
267 if ( !rendererElement.isNull() )
268 {
269 std::unique_ptr< QgsPointCloudRenderer > r( QgsPointCloudRenderer::load( rendererElement, context ) );
270 if ( r )
271 {
272 setRenderer( r.release() );
273 }
274 else
275 {
276 result = false;
277 }
278 }
279 // make sure layer has a renderer - if none exists, fallback to a default renderer
280 if ( !mRenderer )
281 {
283 }
284 }
285
286 if ( categories.testFlag( Symbology ) )
287 {
288 // get and set the blend mode if it exists
289 const QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
290 if ( !blendModeNode.isNull() )
291 {
292 const QDomElement e = blendModeNode.toElement();
293 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
294 }
295 }
296
297 // get and set the layer transparency and scale visibility if they exists
298 if ( categories.testFlag( Rendering ) )
299 {
300 const QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
301 if ( !layerOpacityNode.isNull() )
302 {
303 const QDomElement e = layerOpacityNode.toElement();
304 setOpacity( e.text().toDouble() );
305 }
306
307 const bool hasScaleBasedVisibiliy { node.attributes().namedItem( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).nodeValue() == '1' };
308 setScaleBasedVisibility( hasScaleBasedVisibiliy );
309 bool ok;
310 const double maxScale { node.attributes().namedItem( QStringLiteral( "maxScale" ) ).nodeValue().toDouble( &ok ) };
311 if ( ok )
312 {
313 setMaximumScale( maxScale );
314 }
315 const double minScale { node.attributes().namedItem( QStringLiteral( "minScale" ) ).nodeValue().toDouble( &ok ) };
316 if ( ok )
317 {
318 setMinimumScale( minScale );
319 }
320 }
321 return result;
322}
323
324bool QgsPointCloudLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
325 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
326{
328
329 Q_UNUSED( errorMessage )
330
331 QDomElement elem = node.toElement();
332 writeCommonStyle( elem, doc, context, categories );
333
334 ( void )writeStyle( node, doc, errorMessage, context, categories );
335
336 if ( categories.testFlag( Legend ) && legend() )
337 {
338 QDomElement legendElement = legend()->writeXml( doc, context );
339 if ( !legendElement.isNull() )
340 node.appendChild( legendElement );
341 }
342
343 return true;
344}
345
346bool QgsPointCloudLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
347{
349
350 QDomElement mapLayerNode = node.toElement();
351
352 if ( categories.testFlag( Symbology3D ) )
353 {
354 mapLayerNode.setAttribute( QStringLiteral( "sync3DRendererTo2DRenderer" ), mSync3DRendererTo2DRenderer ? 1 : 0 );
355 }
356
357 if ( categories.testFlag( Symbology ) )
358 {
359 if ( mRenderer )
360 {
361 const QDomElement rendererElement = mRenderer->save( doc, context );
362 node.appendChild( rendererElement );
363 }
364 }
365
366 //save customproperties
367 if ( categories.testFlag( CustomProperties ) )
368 {
369 writeCustomProperties( node, doc );
370 }
371
372 if ( categories.testFlag( Symbology ) )
373 {
374 // add the blend mode field
375 QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
376 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
377 blendModeElem.appendChild( blendModeText );
378 node.appendChild( blendModeElem );
379 }
380
381 // add the layer opacity and scale visibility
382 if ( categories.testFlag( Rendering ) )
383 {
384 QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
385 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
386 layerOpacityElem.appendChild( layerOpacityText );
387 node.appendChild( layerOpacityElem );
388
389 mapLayerNode.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
390 mapLayerNode.setAttribute( QStringLiteral( "maxScale" ), maximumScale() );
391 mapLayerNode.setAttribute( QStringLiteral( "minScale" ), minimumScale() );
392 }
393 return true;
394}
395
397{
399
400 if ( mDataProvider )
401 mDataProvider->setTransformContext( transformContext );
403}
404
405void QgsPointCloudLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
407{
409
410 if ( mDataProvider )
411 {
412 disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
413 disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
414 }
415
416 setName( baseName );
417 mProviderKey = provider;
418 mDataSource = dataSource;
419
420 if ( mPreloadedProvider )
421 {
422 mDataProvider.reset( qobject_cast< QgsPointCloudDataProvider * >( mPreloadedProvider.release() ) );
423 }
424 else
425 {
426 std::unique_ptr< QgsScopedRuntimeProfile > profile;
427 if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
428 profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Create %1 provider" ).arg( provider ), QStringLiteral( "projectload" ) );
429 mDataProvider.reset( qobject_cast<QgsPointCloudDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource, options, flags ) ) );
430 }
431
432 if ( !mDataProvider )
433 {
434 QgsDebugError( QStringLiteral( "Unable to get point cloud data provider" ) );
435 setValid( false );
436 return;
437 }
438
439 mDataProvider->setParent( this );
440 QgsDebugMsgLevel( QStringLiteral( "Instantiated the point cloud data provider plugin" ), 2 );
441
442 setValid( mDataProvider->isValid() );
443 if ( !isValid() )
444 {
445 QgsDebugError( QStringLiteral( "Invalid point cloud provider plugin %1" ).arg( QString( mDataSource.toUtf8() ) ) );
446 setError( mDataProvider->error() );
447 return;
448 }
449
450 connect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
451 connect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
452
453 // Load initial extent, crs and renderer
454 setCrs( mDataProvider->crs() );
456 {
457 setExtent3D( mDataProvider->extent3D() );
458 }
459
460 bool loadDefaultStyleFlag = false;
462 {
463 loadDefaultStyleFlag = true;
464 }
465
466 if ( !mLayerOptions.skipIndexGeneration &&
467 mDataProvider &&
469 mDataProvider->pointCount() > 0 )
470 {
471 mDataProvider->generateIndex();
472 }
473
474 if ( !mLayerOptions.skipStatisticsCalculation &&
475 mDataProvider &&
477 mDataProvider->pointCount() > 0 )
478 {
479 calculateStatistics();
480 }
481
482 if ( !mRenderer || loadDefaultStyleFlag )
483 {
484 std::unique_ptr< QgsScopedRuntimeProfile > profile;
485 if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
486 profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Load layer style" ), QStringLiteral( "projectload" ) );
487
488 bool defaultLoadedFlag = false;
489
490 if ( loadDefaultStyleFlag && isSpatial() && mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
491 {
492 // first try to create a renderer directly from the data provider
493 std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
494 if ( defaultRenderer )
495 {
496 defaultLoadedFlag = true;
497 setRenderer( defaultRenderer.release() );
498 }
499 }
500
501 if ( !defaultLoadedFlag && loadDefaultStyleFlag )
502 {
503 loadDefaultStyle( defaultLoadedFlag );
504 }
505
506 if ( !defaultLoadedFlag )
507 {
508 // all else failed, create default renderer
510 }
511 }
512}
513
520
521QString QgsPointCloudLayer::decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const
522{
524
526}
527
528void QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged( QgsPointCloudDataProvider::PointCloudIndexGenerationState state )
529{
531
532 switch ( state )
533 {
535 {
536 resetRenderer();
537 break;
538 }
540 {
541 QgsError providerError = mDataProvider->error();
542 if ( !providerError.isEmpty() )
543 {
544 setError( providerError );
545 emit raiseError( providerError.summary() );
546 }
547 break;
548 }
550 break;
551 }
552}
553
554
555QString QgsPointCloudLayer::loadDefaultStyle( bool &resultFlag )
556{
558
559 if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
560 {
561 // first try to create a renderer directly from the data provider
562 std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
563 if ( defaultRenderer )
564 {
565 resultFlag = true;
566 setRenderer( defaultRenderer.release() );
567 return QString();
568 }
569 }
570
571 return QgsMapLayer::loadDefaultStyle( resultFlag );
572}
573
575{
577
578 const QgsLayerMetadataFormatter htmlFormatter( metadata() );
579 QString myMetadata = QStringLiteral( "<html>\n<body>\n" );
580
581 myMetadata += generalHtmlMetadata();
582
583 // Begin Provider section
584 myMetadata += QStringLiteral( "<h1>" ) + tr( "Information from provider" ) + QStringLiteral( "</h1>\n<hr>\n" );
585 myMetadata += QLatin1String( "<table class=\"list-view\">\n" );
586
587 // Extent
588 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );
589
590 // feature count
591 QLocale locale = QLocale();
592 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
593 const qint64 pointCount = mDataProvider ? mDataProvider->pointCount() : -1;
594 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
595 + tr( "Point count" ) + QStringLiteral( "</td><td>" )
596 + ( pointCount < 0 ? tr( "unknown" ) : locale.toString( static_cast<qlonglong>( pointCount ) ) )
597 + QStringLiteral( "</td></tr>\n" );
598
599 if ( const QgsPointCloudDataProvider *provider = dataProvider() )
600 {
601 myMetadata += provider->htmlMetadata();
602 }
603
604 myMetadata += QLatin1String( "</table>\n<br><br>" );
605
606 // CRS
607 myMetadata += crsHtmlMetadata();
608
609 // provider metadata section
610 myMetadata += QStringLiteral( "<h1>" ) + tr( "Metadata" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
611 const QVariantMap originalMetadata = mDataProvider ? mDataProvider->originalMetadata() : QVariantMap();
612
613 if ( originalMetadata.value( QStringLiteral( "creation_year" ) ).toInt() > 0 && originalMetadata.contains( QStringLiteral( "creation_doy" ) ) )
614 {
615 QDate creationDate( originalMetadata.value( QStringLiteral( "creation_year" ) ).toInt(), 1, 1 );
616 creationDate = creationDate.addDays( originalMetadata.value( QStringLiteral( "creation_doy" ) ).toInt() );
617
618 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
619 + tr( "Creation date" ) + QStringLiteral( "</td><td>" )
620 + creationDate.toString( Qt::ISODate )
621 + QStringLiteral( "</td></tr>\n" );
622 }
623 if ( originalMetadata.contains( QStringLiteral( "major_version" ) ) && originalMetadata.contains( QStringLiteral( "minor_version" ) ) )
624 {
625 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
626 + tr( "Version" ) + QStringLiteral( "</td><td>" )
627 + QStringLiteral( "%1.%2" ).arg( originalMetadata.value( QStringLiteral( "major_version" ) ).toString(),
628 originalMetadata.value( QStringLiteral( "minor_version" ) ).toString() )
629 + QStringLiteral( "</td></tr>\n" );
630 }
631
632 if ( !originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toString().isEmpty() )
633 {
634 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
635 + tr( "Data format" ) + QStringLiteral( "</td><td>" )
636 + QStringLiteral( "%1 (%2)" ).arg( QgsPointCloudDataProvider::translatedDataFormatIds().value( originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toInt() ),
637 originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toString() ).trimmed()
638 + QStringLiteral( "</td></tr>\n" );
639 }
640
641 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
642 + tr( "Scale X" ) + QStringLiteral( "</td><td>" )
643 + QString::number( originalMetadata.value( QStringLiteral( "scale_x" ) ).toDouble() )
644 + QStringLiteral( "</td></tr>\n" );
645 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
646 + tr( "Scale Y" ) + QStringLiteral( "</td><td>" )
647 + QString::number( originalMetadata.value( QStringLiteral( "scale_y" ) ).toDouble() )
648 + QStringLiteral( "</td></tr>\n" );
649 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
650 + tr( "Scale Z" ) + QStringLiteral( "</td><td>" )
651 + QString::number( originalMetadata.value( QStringLiteral( "scale_z" ) ).toDouble() )
652 + QStringLiteral( "</td></tr>\n" );
653
654 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
655 + tr( "Offset X" ) + QStringLiteral( "</td><td>" )
656 + QString::number( originalMetadata.value( QStringLiteral( "offset_x" ) ).toDouble() )
657 + QStringLiteral( "</td></tr>\n" );
658 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
659 + tr( "Offset Y" ) + QStringLiteral( "</td><td>" )
660 + QString::number( originalMetadata.value( QStringLiteral( "offset_y" ) ).toDouble() )
661 + QStringLiteral( "</td></tr>\n" );
662 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
663 + tr( "Offset Z" ) + QStringLiteral( "</td><td>" )
664 + QString::number( originalMetadata.value( QStringLiteral( "offset_z" ) ).toDouble() )
665 + QStringLiteral( "</td></tr>\n" );
666
667 if ( !originalMetadata.value( QStringLiteral( "project_id" ) ).toString().isEmpty() )
668 {
669 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
670 + tr( "Project ID" ) + QStringLiteral( "</td><td>" )
671 + originalMetadata.value( QStringLiteral( "project_id" ) ).toString()
672 + QStringLiteral( "</td></tr>\n" );
673 }
674
675 if ( !originalMetadata.value( QStringLiteral( "system_id" ) ).toString().isEmpty() )
676 {
677 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
678 + tr( "System ID" ) + QStringLiteral( "</td><td>" )
679 + originalMetadata.value( QStringLiteral( "system_id" ) ).toString()
680 + QStringLiteral( "</td></tr>\n" );
681 }
682
683 if ( !originalMetadata.value( QStringLiteral( "software_id" ) ).toString().isEmpty() )
684 {
685 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
686 + tr( "Software ID" ) + QStringLiteral( "</td><td>" )
687 + originalMetadata.value( QStringLiteral( "software_id" ) ).toString()
688 + QStringLiteral( "</td></tr>\n" );
689 }
690
691 // End Provider section
692 myMetadata += QLatin1String( "</table>\n<br><br>" );
693
694 // identification section
695 myMetadata += QStringLiteral( "<h1>" ) + tr( "Identification" ) + QStringLiteral( "</h1>\n<hr>\n" );
696 myMetadata += htmlFormatter.identificationSectionHtml( );
697 myMetadata += QLatin1String( "<br><br>\n" );
698
699 // extent section
700 myMetadata += QStringLiteral( "<h1>" ) + tr( "Extent" ) + QStringLiteral( "</h1>\n<hr>\n" );
701 myMetadata += htmlFormatter.extentSectionHtml( isSpatial() );
702 myMetadata += QLatin1String( "<br><br>\n" );
703
704 // Start the Access section
705 myMetadata += QStringLiteral( "<h1>" ) + tr( "Access" ) + QStringLiteral( "</h1>\n<hr>\n" );
706 myMetadata += htmlFormatter.accessSectionHtml( );
707 myMetadata += QLatin1String( "<br><br>\n" );
708
709 // Attributes section
710 myMetadata += QStringLiteral( "<h1>" ) + tr( "Attributes" ) + QStringLiteral( "</h1>\n<hr>\n<table class=\"list-view\">\n" );
711
713
714 // count attributes
715 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Count" ) + QStringLiteral( "</td><td>" ) + QString::number( attrs.count() ) + QStringLiteral( "</td></tr>\n" );
716
717 myMetadata += QLatin1String( "</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
718 myMetadata += QLatin1String( "<tr><th>" ) + tr( "Attribute" ) + QLatin1String( "</th><th>" ) + tr( "Type" ) + QLatin1String( "</th></tr>\n" );
719
720 for ( int i = 0; i < attrs.count(); ++i )
721 {
722 const QgsPointCloudAttribute attribute = attrs.at( i );
723 QString rowClass;
724 if ( i % 2 )
725 rowClass = QStringLiteral( "class=\"odd-row\"" );
726 myMetadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + attribute.name() + QLatin1String( "</td><td>" ) + attribute.displayType() + QLatin1String( "</td></tr>\n" );
727 }
728
729 //close field list
730 myMetadata += QLatin1String( "</table>\n<br><br>" );
731
732
733 // Start the contacts section
734 myMetadata += QStringLiteral( "<h1>" ) + tr( "Contacts" ) + QStringLiteral( "</h1>\n<hr>\n" );
735 myMetadata += htmlFormatter.contactsSectionHtml( );
736 myMetadata += QLatin1String( "<br><br>\n" );
737
738 // Start the links section
739 myMetadata += QStringLiteral( "<h1>" ) + tr( "Links" ) + QStringLiteral( "</h1>\n<hr>\n" );
740 myMetadata += htmlFormatter.linksSectionHtml( );
741 myMetadata += QLatin1String( "<br><br>\n" );
742
743 // Start the history section
744 myMetadata += QStringLiteral( "<h1>" ) + tr( "History" ) + QStringLiteral( "</h1>\n<hr>\n" );
745 myMetadata += htmlFormatter.historySectionHtml( );
746 myMetadata += QLatin1String( "<br><br>\n" );
747
748 myMetadata += customPropertyHtmlMetadata();
749
750 myMetadata += QLatin1String( "\n</body>\n</html>\n" );
751 return myMetadata;
752}
753
760
762{
764
765 return mDataProvider ? mDataProvider->attributes() : QgsPointCloudAttributeCollection();
766}
767
769{
771
772 return mDataProvider ? mDataProvider->pointCount() : 0;
773}
774
781
783{
785
786 return mRenderer.get();
787}
788
790{
792
793 if ( renderer == mRenderer.get() )
794 return;
795
796 mRenderer.reset( renderer );
797 emit rendererChanged();
799
800 if ( mSync3DRendererTo2DRenderer )
802}
803
804bool QgsPointCloudLayer::setSubsetString( const QString &subset )
805{
807
808 if ( !isValid() || !mDataProvider )
809 {
810 QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
811 setCustomProperty( QStringLiteral( "storedSubsetString" ), subset );
812 return false;
813 }
814 else if ( subset == mDataProvider->subsetString() )
815 return true;
816
817 bool res = mDataProvider->setSubsetString( subset );
818 if ( res )
819 {
820 emit subsetStringChanged();
822 }
823 return res;
824}
825
827{
829
830 if ( !isValid() || !mDataProvider )
831 {
832 QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
833 return customProperty( QStringLiteral( "storedSubsetString" ) ).toString();
834 }
835 return mDataProvider->subsetString();
836}
837
839{
841
842 bool result = false;
844 {
845 std::unique_ptr< QgsAbstractPointCloud3DRenderer > newRenderer( static_cast< QgsAbstractPointCloud3DRenderer * >( r->clone() ) );
846 result = newRenderer->convertFrom2DRenderer( renderer() );
847 setRenderer3D( newRenderer.release() );
849 }
850 return result;
851}
852
854{
856
857 return mSync3DRendererTo2DRenderer;
858}
859
861{
863
864 mSync3DRendererTo2DRenderer = sync;
865 if ( sync )
867}
868
869void QgsPointCloudLayer::calculateStatistics()
870{
872
873 if ( !mDataProvider.get() || !mDataProvider->hasValidIndex() )
874 {
875 QgsMessageLog::logMessage( QObject::tr( "Failed to calculate statistics of the point cloud %1" ).arg( this->name() ) );
876 return;
877 }
878 if ( mStatsCalculationTask )
879 {
880 QgsMessageLog::logMessage( QObject::tr( "A statistics calculation task for the point cloud %1 is already in progress" ).arg( this->name() ) );
881 return;
882 }
883
884 QgsPointCloudStatistics indexStats = mDataProvider->metadataStatistics();
885 QList<QString> indexStatsAttributes = indexStats.statisticsMap().keys();
886 QVector<QgsPointCloudAttribute> attributes = mDataProvider->attributes().attributes();
887 // Do not calculate stats for attributes that the index gives us stats for
888 for ( int i = 0; i < attributes.size(); ++i )
889 {
890 if ( indexStatsAttributes.contains( attributes[i].name() ) )
891 {
892 attributes.remove( i );
893 --i;
894 }
895 }
896
897 // Use the layer statistics for now, until we can calculate complete ones
898 mStatistics = indexStats;
899 if ( attributes.empty() && indexStats.sampledPointsCount() > 0 )
900 {
901 // All attributes are covered by the saved stats, skip calculating anything
903 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
904 resetRenderer();
905 return;
906 }
907
908 QgsPointCloudStatsCalculationTask *task = new QgsPointCloudStatsCalculationTask( mDataProvider->index(), attributes, 1000000 );
909 connect( task, &QgsTask::taskCompleted, this, [this, task, indexStats, indexStatsAttributes]()
910 {
911 mStatistics = task->calculationResults();
912
913 // Fetch what we can directly from the index
914 QMap<QString, QgsPointCloudAttributeStatistics> statsMap = mStatistics.statisticsMap();
915 for ( const QString &attribute : indexStatsAttributes )
916 {
917 statsMap[ attribute ] = indexStats.statisticsOf( attribute );
918 }
919 mStatistics = QgsPointCloudStatistics( mStatistics.sampledPointsCount(), statsMap );
920
922 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
923 resetRenderer();
924 mStatsCalculationTask = 0;
925#ifdef HAVE_COPC
926 if ( mDataProvider && mDataProvider->index() && mDataProvider->index().isValid() && mDataProvider->name() == QLatin1String( "pdal" ) && mStatistics.sampledPointsCount() != 0 )
927 {
928 mDataProvider->index().writeStatistics( mStatistics );
929 }
930#endif
931 } );
932
933 // In case the statistics calculation fails, QgsTask::taskTerminated will be called
934 connect( task, &QgsTask::taskTerminated, this, [this]()
935 {
936 if ( mStatsCalculationTask )
937 {
938 QgsMessageLog::logMessage( QObject::tr( "Failed to calculate statistics of the point cloud %1" ).arg( this->name() ) );
939 mStatsCalculationTask = 0;
940 }
941 } );
942
943 mStatsCalculationTask = QgsApplication::taskManager()->addTask( task );
944
946 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
947}
948
949void QgsPointCloudLayer::resetRenderer()
950{
952
953 mDataProvider->loadIndex();
955 {
956 calculateStatistics();
957 }
958 if ( !mRenderer || mRenderer->type() == QLatin1String( "extent" ) )
959 {
961 }
963
964 emit rendererChanged();
965}
966
967void QgsPointCloudLayer::loadIndexesForRenderContext( QgsRenderContext &rendererContext ) const
968{
969 if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::ContainSubIndexes )
970 {
971 QgsRectangle renderExtent;
972 try
973 {
974 renderExtent = rendererContext.coordinateTransform().transformBoundingBox( rendererContext.mapExtent(), Qgis::TransformDirection::Reverse );
975 }
976 catch ( QgsCsException & )
977 {
978 QgsDebugError( QStringLiteral( "Transformation of extent failed!" ) );
979 }
980
981 const QVector<QgsPointCloudSubIndex> subIndex = mDataProvider->subIndexes();
982 if ( const QgsVirtualPointCloudProvider *vpcProvider = dynamic_cast<QgsVirtualPointCloudProvider *>( mDataProvider.get() ) )
983 {
984 for ( int i = 0; i < subIndex.size(); ++i )
985 {
986 // no need to load as it's there
987 if ( subIndex.at( i ).index() )
988 continue;
989
990 if ( subIndex.at( i ).extent().intersects( renderExtent ) &&
991 ( renderExtent.width() < vpcProvider->averageSubIndexWidth() ||
992 renderExtent.height() < vpcProvider->averageSubIndexHeight() ) )
993 {
994 mDataProvider->loadSubIndex( i );
995 }
996 }
997 }
998 }
999}
1000
1002{
1004 if ( mEditIndex )
1005 return false;
1006
1007 mEditIndex = QgsPointCloudIndex( new QgsPointCloudEditingIndex( this ) );
1008
1009 if ( !mEditIndex.isValid() )
1010 {
1011 mEditIndex = QgsPointCloudIndex();
1012 return false;
1013 }
1014
1015 emit editingStarted();
1016 return true;
1017}
1018
1020{
1022 if ( !mEditIndex )
1023 return false;
1024
1025 if ( mEditIndex.isModified() )
1026 {
1027 if ( !mEditIndex.commitChanges( &mCommitError ) )
1028 return false;
1029
1030 // emitting layerModified() is not required as that's done automatically
1031 // when undo stack index changes
1032 }
1033
1034 undoStack()->clear();
1035
1036 if ( stopEditing )
1037 {
1038 mEditIndex = QgsPointCloudIndex();
1039 emit editingStopped();
1040 }
1041
1042 return true;
1043}
1044
1046{
1048 return mCommitError;
1049}
1050
1052{
1054 if ( !mEditIndex )
1055 return false;
1056
1057 const QList<QgsPointCloudNodeId> updatedNodes = mEditIndex.updatedNodes();
1058
1059 undoStack()->clear();
1060
1061 mEditIndex = QgsPointCloudIndex();
1062 emit editingStopped();
1063
1064 if ( !updatedNodes.isEmpty() )
1065 {
1066 for ( const QgsPointCloudNodeId &n : updatedNodes )
1068
1069 // emitting layerModified() is not required as that's done automatically
1070 // when undo stack index changes
1071 }
1072
1073 return true;
1074}
1075
1077{
1079 return mDataProvider && mDataProvider->capabilities() & QgsPointCloudDataProvider::Capability::ChangeAttributeValues;
1080}
1081
1083{
1085 if ( mEditIndex )
1086 return true;
1087
1088 return false;
1089}
1090
1092{
1094 if ( !mEditIndex )
1095 return false;
1096
1097 return mEditIndex.isModified();
1098}
1099
1100bool QgsPointCloudLayer::changeAttributeValue( const QgsPointCloudNodeId &n, const QVector<int> &points, const QgsPointCloudAttribute &attribute, double value )
1101{
1102 return this->changeAttributeValue( { { n, points } }, attribute, value );
1103}
1104
1105bool QgsPointCloudLayer::changeAttributeValue( const QHash<QgsPointCloudNodeId, QVector<int>> &nodesAndPoints, const QgsPointCloudAttribute &attribute, double value )
1106{
1108
1109 QgsEventTracing::ScopedEvent _trace( QStringLiteral( "PointCloud" ), QStringLiteral( "QgsPointCloudLayer::changeAttributeValue" ) );
1110
1111 if ( !mEditIndex )
1112 return false;
1113
1114 // Cannot allow x,y,z editing as points may get moved outside the node extents
1115 if ( attribute.name().compare( QLatin1String( "X" ), Qt::CaseInsensitive ) == 0 ||
1116 attribute.name().compare( QLatin1String( "Y" ), Qt::CaseInsensitive ) == 0 ||
1117 attribute.name().compare( QLatin1String( "Z" ), Qt::CaseInsensitive ) == 0 )
1118 return false;
1119
1120 const QgsPointCloudAttributeCollection attributeCollection = mEditIndex.attributes();
1121
1122 int attributeOffset;
1123 const QgsPointCloudAttribute *at = attributeCollection.find( attribute.name(), attributeOffset );
1124
1125 if ( !at ||
1126 at->size() != attribute.size() ||
1127 at->type() != attribute.type() )
1128 {
1129 return false;
1130 }
1131
1132 if ( !QgsPointCloudLayerEditUtils::isAttributeValueValid( attribute, value ) )
1133 {
1134 return false;
1135 }
1136
1137 for ( auto it = nodesAndPoints.constBegin(); it != nodesAndPoints.constEnd(); it++ )
1138 {
1139 QgsPointCloudNodeId n = it.key();
1140 QVector<int> points = it.value();
1141
1142 if ( !n.isValid() || !mEditIndex.hasNode( n ) ) // todo: should not have to check if n.isValid
1143 return false;
1144
1145 if ( points.isEmpty() )
1146 continue;
1147
1148 int pointsMin = std::numeric_limits<int>::max();
1149 int pointsMax = std::numeric_limits<int>::min();
1150 for ( int pt : std::as_const( points ) )
1151 {
1152 if ( pt < pointsMin )
1153 pointsMin = pt;
1154 if ( pt > pointsMax )
1155 pointsMax = pt;
1156 }
1157
1158 if ( pointsMin < 0 || pointsMax >= mEditIndex.getNode( n ).pointCount() )
1159 return false;
1160
1161 }
1162
1163 undoStack()->push( new QgsPointCloudLayerUndoCommandChangeAttribute( this, nodesAndPoints, attribute, value ) );
1164
1165 return true;
1166}
1167
1169{
1171 if ( mEditIndex )
1172 return mEditIndex;
1173
1174 if ( mDataProvider )
1175 return mDataProvider->index();
1176
1177 return QgsPointCloudIndex();
1178}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:4930
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:486
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:197
@ LoadDefaultStyle
Reset the layer's style to the default for the datasource.
Definition qgis.h:470
@ SkipGetExtent
Skip the extent from provider.
Definition qgis.h:471
@ Reverse
Reverse/inverse transform (from destination to source).
Definition qgis.h:2673
Base class for point cloud 3D renderers.
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.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
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:130
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.
An abstract interface for implementations of legends for one map layer.
static QgsMapLayerLegend * defaultPointCloudLegend(QgsPointCloudLayer *layer)
Create new legend implementation for a point cloud layer.
virtual QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml().
Base class for utility classes that encapsulate information necessary for rendering of map layers.
QString name
Definition qgsmaplayer.h:84
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.
QgsMapLayerLegend * legend() const
Can be nullptr.
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...
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:86
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
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.
QgsMapLayer::LayerFlags flags
Definition qgsmaplayer.h:96
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.
double opacity
Definition qgsmaplayer.h:92
@ Symbology
Symbology.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
@ Symbology3D
3D symbology
@ CustomProperties
Custom properties (by plugins for instance).
@ Legend
Legend settings.
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.
QVector< QgsPointCloudAttribute > attributes() const
Returns all attributes.
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.
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.
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.
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.
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...
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 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.
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.
void setRenderer(QgsPointCloudRenderer *renderer)
Sets the 2D renderer for the point cloud.
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.
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.
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.
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.
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.
Allows entering a context category and takes care of leaving this category on deletion of the class.
A container for the context for various read/write operations on objects.
QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString()) const
Push a category to the stack.
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:61
#define QgsDebugError(str)
Definition qgslogger.h:57
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Setting options for creating vector data providers.
Setting options for loading point cloud layers.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.