QGIS API Documentation 3.41.0-Master (02257426e5a)
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#include "moc_qgspointcloudlayer.cpp"
23#include "qgspointcloudindex.h"
26#include "qgsrectangle.h"
28#include "qgsproviderregistry.h"
29#include "qgslogger.h"
32#include "qgsruntimeprofiler.h"
33#include "qgsapplication.h"
34#include "qgspainting.h"
37#include "qgsmaplayerlegend.h"
38#include "qgsxmlutils.h"
39#include "qgsmaplayerfactory.h"
42#include "qgsmessagelog.h"
43#include "qgstaskmanager.h"
44#include "qgsthreadingutils.h"
47#ifdef HAVE_COPC
49#endif
50
51#include "qgsvirtualpointcloudprovider.h"
52
53
54#include <QUrl>
55
57 const QString &baseName,
58 const QString &providerLib,
60 : QgsMapLayer( Qgis::LayerType::PointCloud, baseName, uri )
61 , mElevationProperties( new QgsPointCloudLayerElevationProperties( this ) )
62 , mLayerOptions( options )
63{
64 if ( !uri.isEmpty() && !providerLib.isEmpty() )
65 {
66 const QgsDataProvider::ProviderOptions providerOptions { options.transformContext };
67 Qgis::DataProviderReadFlags providerFlags;
68 if ( options.loadDefaultStyle )
69 {
71 }
72 setDataSource( uri, baseName, providerLib, providerOptions, providerFlags );
73 }
74
77 connect( undoStack(), &QUndoStack::indexChanged, this, &QgsMapLayer::layerModified );
78 connect( this, &QgsMapLayer::layerModified, this, [this] { triggerRepaint(); } );
79}
80
82{
83 if ( QgsTask *task = QgsApplication::taskManager()->task( mStatsCalculationTask ) )
84 {
85 mStatsCalculationTask = 0;
86 task->cancel();
87 task->waitForFinished();
88 }
89}
90
92{
94
95 QgsPointCloudLayer *layer = new QgsPointCloudLayer( source(), name(), mProviderKey, mLayerOptions );
96 QgsMapLayer::clone( layer );
97
98 if ( mRenderer )
99 layer->setRenderer( mRenderer->clone() );
100
101 layer->mElevationProperties = mElevationProperties->clone();
102 layer->mElevationProperties->setParent( layer );
103
104 layer->mLayerOptions = mLayerOptions;
105 layer->mSync3DRendererTo2DRenderer = mSync3DRendererTo2DRenderer;
106
107 return layer;
108}
109
111{
113
114 if ( !mDataProvider )
115 return QgsRectangle();
116
117 return mDataProvider->extent();
118}
119
121{
123
124 if ( mRenderer->type() != QLatin1String( "extent" ) )
125 loadIndexesForRenderContext( rendererContext );
126
127 return new QgsPointCloudLayerRenderer( this, rendererContext );
128}
129
136
143
145{
147
148 return mDataProvider.get();
149}
150
151bool QgsPointCloudLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
152{
154
155 // create provider
156 const QDomNode pkeyNode = layerNode.namedItem( QStringLiteral( "provider" ) );
157 mProviderKey = pkeyNode.toElement().text();
158
160 {
161 const QgsDataProvider::ProviderOptions providerOptions { context.transformContext() };
163 // read extent
165 {
166 const QDomNode extentNode = layerNode.namedItem( QStringLiteral( "extent" ) );
167 if ( !extentNode.isNull() )
168 {
169 // get the extent
170 const QgsRectangle mbr = QgsXmlUtils::readRectangle( extentNode.toElement() );
171
172 // store the extent
173 setExtent( mbr );
174 }
175 }
176
178 const QDomNode subset = layerNode.namedItem( QStringLiteral( "subset" ) );
179 const QString subsetText = subset.toElement().text();
180 if ( !subsetText.isEmpty() )
181 setSubsetString( subsetText );
182 }
183
184 if ( !isValid() )
185 {
186 return false;
187 }
188
189 QString errorMsg;
190 if ( !readSymbology( layerNode, errorMsg, context ) )
191 return false;
192
193 readStyleManager( layerNode );
194 return true;
195}
196
197bool QgsPointCloudLayer::writeXml( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const
198{
200
201 QDomElement mapLayerNode = layerNode.toElement();
202 mapLayerNode.setAttribute( QStringLiteral( "type" ), QgsMapLayerFactory::typeToString( Qgis::LayerType::PointCloud ) );
203
204 if ( !subsetString().isEmpty() )
205 {
206 QDomElement subset = doc.createElement( QStringLiteral( "subset" ) );
207 const QDomText subsetText = doc.createTextNode( subsetString() );
208 subset.appendChild( subsetText );
209 layerNode.appendChild( subset );
210 }
211 if ( mDataProvider )
212 {
213 QDomElement provider = doc.createElement( QStringLiteral( "provider" ) );
214 const QDomText providerText = doc.createTextNode( providerType() );
215 provider.appendChild( providerText );
216 layerNode.appendChild( provider );
217 }
218
219 writeStyleManager( layerNode, doc );
220
221 QString errorMsg;
222 return writeSymbology( layerNode, doc, errorMsg, context );
223}
224
225bool QgsPointCloudLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
226{
228
229 const QDomElement elem = node.toElement();
230
231 readCommonStyle( elem, context, categories );
232
233 readStyle( node, errorMessage, context, categories );
234
235 if ( categories.testFlag( CustomProperties ) )
236 readCustomProperties( node, QStringLiteral( "variable" ) );
237
238 return true;
239}
240
241bool QgsPointCloudLayer::readStyle( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
242{
244
245 bool result = true;
246
247 if ( categories.testFlag( Symbology3D ) )
248 {
249 bool ok;
250 bool sync = node.attributes().namedItem( QStringLiteral( "sync3DRendererTo2DRenderer" ) ).nodeValue().toInt( &ok );
251 if ( ok )
253 }
254
255 if ( categories.testFlag( Symbology ) )
256 {
257 QDomElement rendererElement = node.firstChildElement( QStringLiteral( "renderer" ) );
258 if ( !rendererElement.isNull() )
259 {
260 std::unique_ptr< QgsPointCloudRenderer > r( QgsPointCloudRenderer::load( rendererElement, context ) );
261 if ( r )
262 {
263 setRenderer( r.release() );
264 }
265 else
266 {
267 result = false;
268 }
269 }
270 // make sure layer has a renderer - if none exists, fallback to a default renderer
271 if ( !mRenderer )
272 {
274 }
275 }
276
277 if ( categories.testFlag( Symbology ) )
278 {
279 // get and set the blend mode if it exists
280 const QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
281 if ( !blendModeNode.isNull() )
282 {
283 const QDomElement e = blendModeNode.toElement();
284 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
285 }
286 }
287
288 // get and set the layer transparency and scale visibility if they exists
289 if ( categories.testFlag( Rendering ) )
290 {
291 const QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
292 if ( !layerOpacityNode.isNull() )
293 {
294 const QDomElement e = layerOpacityNode.toElement();
295 setOpacity( e.text().toDouble() );
296 }
297
298 const bool hasScaleBasedVisibiliy { node.attributes().namedItem( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).nodeValue() == '1' };
299 setScaleBasedVisibility( hasScaleBasedVisibiliy );
300 bool ok;
301 const double maxScale { node.attributes().namedItem( QStringLiteral( "maxScale" ) ).nodeValue().toDouble( &ok ) };
302 if ( ok )
303 {
304 setMaximumScale( maxScale );
305 }
306 const double minScale { node.attributes().namedItem( QStringLiteral( "minScale" ) ).nodeValue().toDouble( &ok ) };
307 if ( ok )
308 {
309 setMinimumScale( minScale );
310 }
311 }
312 return result;
313}
314
315bool QgsPointCloudLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
316 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
317{
319
320 Q_UNUSED( errorMessage )
321
322 QDomElement elem = node.toElement();
323 writeCommonStyle( elem, doc, context, categories );
324
325 ( void )writeStyle( node, doc, errorMessage, context, categories );
326
327 return true;
328}
329
330bool QgsPointCloudLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
331{
333
334 QDomElement mapLayerNode = node.toElement();
335
336 if ( categories.testFlag( Symbology3D ) )
337 {
338 mapLayerNode.setAttribute( QStringLiteral( "sync3DRendererTo2DRenderer" ), mSync3DRendererTo2DRenderer ? 1 : 0 );
339 }
340
341 if ( categories.testFlag( Symbology ) )
342 {
343 if ( mRenderer )
344 {
345 const QDomElement rendererElement = mRenderer->save( doc, context );
346 node.appendChild( rendererElement );
347 }
348 }
349
350 //save customproperties
351 if ( categories.testFlag( CustomProperties ) )
352 {
353 writeCustomProperties( node, doc );
354 }
355
356 if ( categories.testFlag( Symbology ) )
357 {
358 // add the blend mode field
359 QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
360 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
361 blendModeElem.appendChild( blendModeText );
362 node.appendChild( blendModeElem );
363 }
364
365 // add the layer opacity and scale visibility
366 if ( categories.testFlag( Rendering ) )
367 {
368 QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
369 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
370 layerOpacityElem.appendChild( layerOpacityText );
371 node.appendChild( layerOpacityElem );
372
373 mapLayerNode.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
374 mapLayerNode.setAttribute( QStringLiteral( "maxScale" ), maximumScale() );
375 mapLayerNode.setAttribute( QStringLiteral( "minScale" ), minimumScale() );
376 }
377 return true;
378}
379
381{
383
384 if ( mDataProvider )
385 mDataProvider->setTransformContext( transformContext );
387}
388
389void QgsPointCloudLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
391{
393
394 if ( mDataProvider )
395 {
396 disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
397 disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
398 }
399
400 setName( baseName );
401 mProviderKey = provider;
402 mDataSource = dataSource;
403
404 if ( mPreloadedProvider )
405 {
406 mDataProvider.reset( qobject_cast< QgsPointCloudDataProvider * >( mPreloadedProvider.release() ) );
407 }
408 else
409 {
410 std::unique_ptr< QgsScopedRuntimeProfile > profile;
411 if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
412 profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Create %1 provider" ).arg( provider ), QStringLiteral( "projectload" ) );
413 mDataProvider.reset( qobject_cast<QgsPointCloudDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource, options, flags ) ) );
414 }
415
416 if ( !mDataProvider )
417 {
418 QgsDebugError( QStringLiteral( "Unable to get point cloud data provider" ) );
419 setValid( false );
420 return;
421 }
422
423 mDataProvider->setParent( this );
424 QgsDebugMsgLevel( QStringLiteral( "Instantiated the point cloud data provider plugin" ), 2 );
425
426 setValid( mDataProvider->isValid() );
427 if ( !isValid() )
428 {
429 QgsDebugError( QStringLiteral( "Invalid point cloud provider plugin %1" ).arg( QString( mDataSource.toUtf8() ) ) );
430 setError( mDataProvider->error() );
431 return;
432 }
433
434 connect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
435 connect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
436
437 // Load initial extent, crs and renderer
438 setCrs( mDataProvider->crs() );
440 {
441 setExtent3D( mDataProvider->extent3D() );
442 }
443
444 bool loadDefaultStyleFlag = false;
446 {
447 loadDefaultStyleFlag = true;
448 }
449
450 if ( !mLayerOptions.skipIndexGeneration &&
451 mDataProvider &&
453 mDataProvider->pointCount() > 0 )
454 {
455 mDataProvider->generateIndex();
456 }
457
458 if ( !mLayerOptions.skipStatisticsCalculation &&
459 mDataProvider &&
461 mDataProvider->pointCount() > 0 )
462 {
463 calculateStatistics();
464 }
465
466 if ( !mRenderer || loadDefaultStyleFlag )
467 {
468 std::unique_ptr< QgsScopedRuntimeProfile > profile;
469 if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
470 profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Load layer style" ), QStringLiteral( "projectload" ) );
471
472 bool defaultLoadedFlag = false;
473
474 if ( loadDefaultStyleFlag && isSpatial() && mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
475 {
476 // first try to create a renderer directly from the data provider
477 std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
478 if ( defaultRenderer )
479 {
480 defaultLoadedFlag = true;
481 setRenderer( defaultRenderer.release() );
482 }
483 }
484
485 if ( !defaultLoadedFlag && loadDefaultStyleFlag )
486 {
487 loadDefaultStyle( defaultLoadedFlag );
488 }
489
490 if ( !defaultLoadedFlag )
491 {
492 // all else failed, create default renderer
494 }
495 }
496}
497
498QString QgsPointCloudLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
499{
501
503}
504
505QString QgsPointCloudLayer::decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const
506{
508
510}
511
512void QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged( QgsPointCloudDataProvider::PointCloudIndexGenerationState state )
513{
515
516 switch ( state )
517 {
519 {
520 resetRenderer();
521 break;
522 }
524 {
525 QgsError providerError = mDataProvider->error();
526 if ( !providerError.isEmpty() )
527 {
528 setError( providerError );
529 emit raiseError( providerError.summary() );
530 }
531 break;
532 }
534 break;
535 }
536}
537
538
539QString QgsPointCloudLayer::loadDefaultStyle( bool &resultFlag )
540{
542
543 if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
544 {
545 // first try to create a renderer directly from the data provider
546 std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
547 if ( defaultRenderer )
548 {
549 resultFlag = true;
550 setRenderer( defaultRenderer.release() );
551 return QString();
552 }
553 }
554
555 return QgsMapLayer::loadDefaultStyle( resultFlag );
556}
557
559{
561
562 const QgsLayerMetadataFormatter htmlFormatter( metadata() );
563 QString myMetadata = QStringLiteral( "<html>\n<body>\n" );
564
565 myMetadata += generalHtmlMetadata();
566
567 // Begin Provider section
568 myMetadata += QStringLiteral( "<h1>" ) + tr( "Information from provider" ) + QStringLiteral( "</h1>\n<hr>\n" );
569 myMetadata += QLatin1String( "<table class=\"list-view\">\n" );
570
571 // Extent
572 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );
573
574 // feature count
575 QLocale locale = QLocale();
576 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
577 const qint64 pointCount = mDataProvider ? mDataProvider->pointCount() : -1;
578 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
579 + tr( "Point count" ) + QStringLiteral( "</td><td>" )
580 + ( pointCount < 0 ? tr( "unknown" ) : locale.toString( static_cast<qlonglong>( pointCount ) ) )
581 + QStringLiteral( "</td></tr>\n" );
582
583 if ( const QgsPointCloudDataProvider *provider = dataProvider() )
584 {
585 myMetadata += provider->htmlMetadata();
586 }
587
588 myMetadata += QLatin1String( "</table>\n<br><br>" );
589
590 // CRS
591 myMetadata += crsHtmlMetadata();
592
593 // provider metadata section
594 myMetadata += QStringLiteral( "<h1>" ) + tr( "Metadata" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
595 const QVariantMap originalMetadata = mDataProvider ? mDataProvider->originalMetadata() : QVariantMap();
596
597 if ( originalMetadata.value( QStringLiteral( "creation_year" ) ).toInt() > 0 && originalMetadata.contains( QStringLiteral( "creation_doy" ) ) )
598 {
599 QDate creationDate( originalMetadata.value( QStringLiteral( "creation_year" ) ).toInt(), 1, 1 );
600 creationDate = creationDate.addDays( originalMetadata.value( QStringLiteral( "creation_doy" ) ).toInt() );
601
602 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
603 + tr( "Creation date" ) + QStringLiteral( "</td><td>" )
604 + creationDate.toString( Qt::ISODate )
605 + QStringLiteral( "</td></tr>\n" );
606 }
607 if ( originalMetadata.contains( QStringLiteral( "major_version" ) ) && originalMetadata.contains( QStringLiteral( "minor_version" ) ) )
608 {
609 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
610 + tr( "Version" ) + QStringLiteral( "</td><td>" )
611 + QStringLiteral( "%1.%2" ).arg( originalMetadata.value( QStringLiteral( "major_version" ) ).toString(),
612 originalMetadata.value( QStringLiteral( "minor_version" ) ).toString() )
613 + QStringLiteral( "</td></tr>\n" );
614 }
615
616 if ( !originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toString().isEmpty() )
617 {
618 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
619 + tr( "Data format" ) + QStringLiteral( "</td><td>" )
620 + QStringLiteral( "%1 (%2)" ).arg( QgsPointCloudDataProvider::translatedDataFormatIds().value( originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toInt() ),
621 originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toString() ).trimmed()
622 + QStringLiteral( "</td></tr>\n" );
623 }
624
625 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
626 + tr( "Scale X" ) + QStringLiteral( "</td><td>" )
627 + QString::number( originalMetadata.value( QStringLiteral( "scale_x" ) ).toDouble() )
628 + QStringLiteral( "</td></tr>\n" );
629 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
630 + tr( "Scale Y" ) + QStringLiteral( "</td><td>" )
631 + QString::number( originalMetadata.value( QStringLiteral( "scale_y" ) ).toDouble() )
632 + QStringLiteral( "</td></tr>\n" );
633 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
634 + tr( "Scale Z" ) + QStringLiteral( "</td><td>" )
635 + QString::number( originalMetadata.value( QStringLiteral( "scale_z" ) ).toDouble() )
636 + QStringLiteral( "</td></tr>\n" );
637
638 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
639 + tr( "Offset X" ) + QStringLiteral( "</td><td>" )
640 + QString::number( originalMetadata.value( QStringLiteral( "offset_x" ) ).toDouble() )
641 + QStringLiteral( "</td></tr>\n" );
642 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
643 + tr( "Offset Y" ) + QStringLiteral( "</td><td>" )
644 + QString::number( originalMetadata.value( QStringLiteral( "offset_y" ) ).toDouble() )
645 + QStringLiteral( "</td></tr>\n" );
646 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
647 + tr( "Offset Z" ) + QStringLiteral( "</td><td>" )
648 + QString::number( originalMetadata.value( QStringLiteral( "offset_z" ) ).toDouble() )
649 + QStringLiteral( "</td></tr>\n" );
650
651 if ( !originalMetadata.value( QStringLiteral( "project_id" ) ).toString().isEmpty() )
652 {
653 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
654 + tr( "Project ID" ) + QStringLiteral( "</td><td>" )
655 + originalMetadata.value( QStringLiteral( "project_id" ) ).toString()
656 + QStringLiteral( "</td></tr>\n" );
657 }
658
659 if ( !originalMetadata.value( QStringLiteral( "system_id" ) ).toString().isEmpty() )
660 {
661 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
662 + tr( "System ID" ) + QStringLiteral( "</td><td>" )
663 + originalMetadata.value( QStringLiteral( "system_id" ) ).toString()
664 + QStringLiteral( "</td></tr>\n" );
665 }
666
667 if ( !originalMetadata.value( QStringLiteral( "software_id" ) ).toString().isEmpty() )
668 {
669 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
670 + tr( "Software ID" ) + QStringLiteral( "</td><td>" )
671 + originalMetadata.value( QStringLiteral( "software_id" ) ).toString()
672 + QStringLiteral( "</td></tr>\n" );
673 }
674
675 // End Provider section
676 myMetadata += QLatin1String( "</table>\n<br><br>" );
677
678 // identification section
679 myMetadata += QStringLiteral( "<h1>" ) + tr( "Identification" ) + QStringLiteral( "</h1>\n<hr>\n" );
680 myMetadata += htmlFormatter.identificationSectionHtml( );
681 myMetadata += QLatin1String( "<br><br>\n" );
682
683 // extent section
684 myMetadata += QStringLiteral( "<h1>" ) + tr( "Extent" ) + QStringLiteral( "</h1>\n<hr>\n" );
685 myMetadata += htmlFormatter.extentSectionHtml( isSpatial() );
686 myMetadata += QLatin1String( "<br><br>\n" );
687
688 // Start the Access section
689 myMetadata += QStringLiteral( "<h1>" ) + tr( "Access" ) + QStringLiteral( "</h1>\n<hr>\n" );
690 myMetadata += htmlFormatter.accessSectionHtml( );
691 myMetadata += QLatin1String( "<br><br>\n" );
692
693 // Attributes section
694 myMetadata += QStringLiteral( "<h1>" ) + tr( "Attributes" ) + QStringLiteral( "</h1>\n<hr>\n<table class=\"list-view\">\n" );
695
697
698 // count attributes
699 myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Count" ) + QStringLiteral( "</td><td>" ) + QString::number( attrs.count() ) + QStringLiteral( "</td></tr>\n" );
700
701 myMetadata += QLatin1String( "</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
702 myMetadata += QLatin1String( "<tr><th>" ) + tr( "Attribute" ) + QLatin1String( "</th><th>" ) + tr( "Type" ) + QLatin1String( "</th></tr>\n" );
703
704 for ( int i = 0; i < attrs.count(); ++i )
705 {
706 const QgsPointCloudAttribute attribute = attrs.at( i );
707 QString rowClass;
708 if ( i % 2 )
709 rowClass = QStringLiteral( "class=\"odd-row\"" );
710 myMetadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + attribute.name() + QLatin1String( "</td><td>" ) + attribute.displayType() + QLatin1String( "</td></tr>\n" );
711 }
712
713 //close field list
714 myMetadata += QLatin1String( "</table>\n<br><br>" );
715
716
717 // Start the contacts section
718 myMetadata += QStringLiteral( "<h1>" ) + tr( "Contacts" ) + QStringLiteral( "</h1>\n<hr>\n" );
719 myMetadata += htmlFormatter.contactsSectionHtml( );
720 myMetadata += QLatin1String( "<br><br>\n" );
721
722 // Start the links section
723 myMetadata += QStringLiteral( "<h1>" ) + tr( "Links" ) + QStringLiteral( "</h1>\n<hr>\n" );
724 myMetadata += htmlFormatter.linksSectionHtml( );
725 myMetadata += QLatin1String( "<br><br>\n" );
726
727 // Start the history section
728 myMetadata += QStringLiteral( "<h1>" ) + tr( "History" ) + QStringLiteral( "</h1>\n<hr>\n" );
729 myMetadata += htmlFormatter.historySectionHtml( );
730 myMetadata += QLatin1String( "<br><br>\n" );
731
732 myMetadata += customPropertyHtmlMetadata();
733
734 myMetadata += QLatin1String( "\n</body>\n</html>\n" );
735 return myMetadata;
736}
737
744
746{
748
749 return mDataProvider ? mDataProvider->attributes() : QgsPointCloudAttributeCollection();
750}
751
753{
755
756 return mDataProvider ? mDataProvider->pointCount() : 0;
757}
758
765
767{
769
770 return mRenderer.get();
771}
772
774{
776
777 if ( renderer == mRenderer.get() )
778 return;
779
780 mRenderer.reset( renderer );
781 emit rendererChanged();
783
784 if ( mSync3DRendererTo2DRenderer )
786}
787
788bool QgsPointCloudLayer::setSubsetString( const QString &subset )
789{
791
792 if ( !isValid() || !mDataProvider )
793 {
794 QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
795 setCustomProperty( QStringLiteral( "storedSubsetString" ), subset );
796 return false;
797 }
798 else if ( subset == mDataProvider->subsetString() )
799 return true;
800
801 bool res = mDataProvider->setSubsetString( subset );
802 if ( res )
803 {
804 emit subsetStringChanged();
806 }
807 return res;
808}
809
811{
813
814 if ( !isValid() || !mDataProvider )
815 {
816 QgsDebugMsgLevel( QStringLiteral( "invoked with invalid layer or null mDataProvider" ), 3 );
817 return customProperty( QStringLiteral( "storedSubsetString" ) ).toString();
818 }
819 return mDataProvider->subsetString();
820}
821
823{
825
826 bool result = false;
828 if ( r )
829 {
830 result = r->convertFrom2DRenderer( renderer() );
831 setRenderer3D( r );
833 }
834 return result;
835}
836
838{
840
841 return mSync3DRendererTo2DRenderer;
842}
843
845{
847
848 mSync3DRendererTo2DRenderer = sync;
849 if ( sync )
851}
852
853void QgsPointCloudLayer::calculateStatistics()
854{
856
857 if ( !mDataProvider.get() || !mDataProvider->hasValidIndex() )
858 {
859 QgsMessageLog::logMessage( QObject::tr( "Failed to calculate statistics of the point cloud %1" ).arg( this->name() ) );
860 return;
861 }
862 if ( mStatsCalculationTask )
863 {
864 QgsMessageLog::logMessage( QObject::tr( "A statistics calculation task for the point cloud %1 is already in progress" ).arg( this->name() ) );
865 return;
866 }
867
868 QgsPointCloudStatistics indexStats = mDataProvider->metadataStatistics();
869 QList<QString> indexStatsAttributes = indexStats.statisticsMap().keys();
870 QVector<QgsPointCloudAttribute> attributes = mDataProvider->attributes().attributes();
871 // Do not calculate stats for attributes that the index gives us stats for
872 for ( int i = 0; i < attributes.size(); ++i )
873 {
874 if ( indexStatsAttributes.contains( attributes[i].name() ) )
875 {
876 attributes.remove( i );
877 --i;
878 }
879 }
880
881 // Use the layer statistics for now, until we can calculate complete ones
882 mStatistics = indexStats;
883 if ( attributes.empty() && indexStats.sampledPointsCount() > 0 )
884 {
885 // All attributes are covered by the saved stats, skip calculating anything
887 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
888 resetRenderer();
889 return;
890 }
891
892 QgsPointCloudStatsCalculationTask *task = new QgsPointCloudStatsCalculationTask( mDataProvider->index(), attributes, 1000000 );
893 connect( task, &QgsTask::taskCompleted, this, [this, task, indexStats, indexStatsAttributes]()
894 {
895 mStatistics = task->calculationResults();
896
897 // Fetch what we can directly from the index
898 QMap<QString, QgsPointCloudAttributeStatistics> statsMap = mStatistics.statisticsMap();
899 for ( const QString &attribute : indexStatsAttributes )
900 {
901 statsMap[ attribute ] = indexStats.statisticsOf( attribute );
902 }
903 mStatistics = QgsPointCloudStatistics( mStatistics.sampledPointsCount(), statsMap );
904
906 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
907 resetRenderer();
908 mStatsCalculationTask = 0;
909#ifdef HAVE_COPC
910 if ( mDataProvider && mDataProvider->index() && mDataProvider->index().isValid() && mDataProvider->name() == QLatin1String( "pdal" ) && mStatistics.sampledPointsCount() != 0 )
911 {
912 mDataProvider->index().writeStatistics( mStatistics );
913 }
914#endif
915 } );
916
917 // In case the statistics calculation fails, QgsTask::taskTerminated will be called
918 connect( task, &QgsTask::taskTerminated, this, [this]()
919 {
920 if ( mStatsCalculationTask )
921 {
922 QgsMessageLog::logMessage( QObject::tr( "Failed to calculate statistics of the point cloud %1" ).arg( this->name() ) );
923 mStatsCalculationTask = 0;
924 }
925 } );
926
927 mStatsCalculationTask = QgsApplication::taskManager()->addTask( task );
928
930 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
931}
932
933void QgsPointCloudLayer::resetRenderer()
934{
936
937 mDataProvider->loadIndex();
939 {
940 calculateStatistics();
941 }
942 if ( !mRenderer || mRenderer->type() == QLatin1String( "extent" ) )
943 {
945 }
947
948 emit rendererChanged();
949}
950
951void QgsPointCloudLayer::loadIndexesForRenderContext( QgsRenderContext &rendererContext ) const
952{
953 if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::ContainSubIndexes )
954 {
955 QgsRectangle renderExtent;
956 try
957 {
958 renderExtent = rendererContext.coordinateTransform().transformBoundingBox( rendererContext.mapExtent(), Qgis::TransformDirection::Reverse );
959 }
960 catch ( QgsCsException & )
961 {
962 QgsDebugError( QStringLiteral( "Transformation of extent failed!" ) );
963 }
964
965 const QVector<QgsPointCloudSubIndex> subIndex = mDataProvider->subIndexes();
966 if ( const QgsVirtualPointCloudProvider *vpcProvider = dynamic_cast<QgsVirtualPointCloudProvider *>( mDataProvider.get() ) )
967 {
968 for ( int i = 0; i < subIndex.size(); ++i )
969 {
970 // no need to load as it's there
971 if ( subIndex.at( i ).index() )
972 continue;
973
974 if ( subIndex.at( i ).extent().intersects( renderExtent ) &&
975 ( renderExtent.width() < vpcProvider->averageSubIndexWidth() ||
976 renderExtent.height() < vpcProvider->averageSubIndexHeight() ) )
977 {
978 mDataProvider->loadSubIndex( i );
979 }
980 }
981 }
982 }
983}
984
986{
988 if ( mEditIndex )
989 return false;
990
991 mEditIndex = QgsPointCloudIndex( new QgsPointCloudEditingIndex( this ) );
992
993 if ( !mEditIndex.isValid() )
994 {
995 mEditIndex = QgsPointCloudIndex();
996 return false;
997 }
998
999 emit editingStarted();
1000 return true;
1001}
1002
1004{
1006 if ( !mEditIndex )
1007 return false;
1008
1009 if ( mEditIndex.isModified() )
1010 {
1011 if ( !mEditIndex.commitChanges( &mCommitError ) )
1012 return false;
1013
1014 // emitting layerModified() is not required as that's done automatically
1015 // when undo stack index changes
1016 }
1017
1018 undoStack()->clear();
1019
1020 if ( stopEditing )
1021 {
1022 mEditIndex = QgsPointCloudIndex();
1023 emit editingStopped();
1024 }
1025
1026 return true;
1027}
1028
1030{
1032 return mCommitError;
1033}
1034
1036{
1038 if ( !mEditIndex )
1039 return false;
1040
1041 const QList<QgsPointCloudNodeId> updatedNodes = mEditIndex.updatedNodes();
1042
1043 undoStack()->clear();
1044
1045 mEditIndex = QgsPointCloudIndex();
1046 emit editingStopped();
1047
1048 if ( !updatedNodes.isEmpty() )
1049 {
1050 for ( const QgsPointCloudNodeId &n : updatedNodes )
1052
1053 // emitting layerModified() is not required as that's done automatically
1054 // when undo stack index changes
1055 }
1056
1057 return true;
1058}
1059
1061{
1063 return mDataProvider && mDataProvider->capabilities() & QgsPointCloudDataProvider::Capability::ChangeAttributeValues;
1064}
1065
1067{
1069 if ( mEditIndex )
1070 return true;
1071
1072 return false;
1073}
1074
1076{
1078 if ( !mEditIndex )
1079 return false;
1080
1081 return mEditIndex.isModified();
1082}
1083
1084bool QgsPointCloudLayer::changeAttributeValue( const QgsPointCloudNodeId &n, const QVector<int> &points, const QgsPointCloudAttribute &attribute, double value )
1085{
1087 if ( !mEditIndex )
1088 return false;
1089
1090 // Cannot allow x,y,z editing as points may get moved outside the node extents
1091 if ( attribute.name().compare( QLatin1String( "X" ), Qt::CaseInsensitive ) == 0 ||
1092 attribute.name().compare( QLatin1String( "Y" ), Qt::CaseInsensitive ) == 0 ||
1093 attribute.name().compare( QLatin1String( "Z" ), Qt::CaseInsensitive ) == 0 )
1094 return false;
1095
1096 if ( !n.isValid() || !mEditIndex.hasNode( n ) ) // todo: should not have to check if n.isValid
1097 return false;
1098
1099 if ( points.isEmpty() )
1100 return false;
1101
1102 const QgsPointCloudAttributeCollection attributeCollection = mEditIndex.attributes();
1103
1104 int attributeOffset;
1105 const QgsPointCloudAttribute *at = attributeCollection.find( attribute.name(), attributeOffset );
1106
1107 if ( !at ||
1108 at->size() != attribute.size() ||
1109 at->type() != attribute.type() )
1110 {
1111 return false;
1112 }
1113
1114 if ( !QgsPointCloudLayerEditUtils::isAttributeValueValid( attribute, value ) )
1115 {
1116 return false;
1117 }
1118
1119 QVector<int> sortedPoints( points.constBegin(), points.constEnd() );
1120 std::sort( sortedPoints.begin(), sortedPoints.end() );
1121 sortedPoints.erase( std::unique( sortedPoints.begin(), sortedPoints.end() ), sortedPoints.end() );
1122
1123 if ( sortedPoints.constFirst() < 0 ||
1124 sortedPoints.constLast() >= mEditIndex.getNode( n ).pointCount() )
1125 return false;
1126
1127 undoStack()->push( new QgsPointCloudLayerUndoCommandChangeAttribute( this, n, sortedPoints, attribute, value ) );
1128
1129 return true;
1130}
1131
1133{
1135 if ( mEditIndex )
1136 return mEditIndex;
1137
1138 if ( mDataProvider )
1139 return mDataProvider->index();
1140
1141 return QgsPointCloudIndex();
1142}
The Qgis class provides global constants 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:4657
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 any 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
Class for metadata formatter.
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:76
QString name
Definition qgsmaplayer.h:80
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:82
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:88
@ 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.
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.
The QgsPointCloudEditingIndex class is a QgsPointCloudIndex that is used as an editing buffer when ed...
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 a 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.
Class 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.
The class is used as a container of context for various read/write operations on other 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.