QGIS API Documentation 3.99.0-Master (a8f284845db)
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 <QString>
51#include <QUrl>
52
53#include "moc_qgspointcloudlayer.cpp"
54
55using namespace Qt::StringLiterals;
56
58 const QString &baseName,
59 const QString &providerLib,
61 : QgsMapLayer( Qgis::LayerType::PointCloud, baseName, uri )
62 , mElevationProperties( new QgsPointCloudLayerElevationProperties( this ) )
63 , mLayerOptions( options )
64{
65 if ( !uri.isEmpty() && !providerLib.isEmpty() )
66 {
67 const QgsDataProvider::ProviderOptions providerOptions { options.transformContext };
68 Qgis::DataProviderReadFlags providerFlags;
69 if ( options.loadDefaultStyle )
70 {
71 providerFlags |= Qgis::DataProviderReadFlag::LoadDefaultStyle;
72 }
73 setDataSource( uri, baseName, providerLib, providerOptions, providerFlags );
74 }
75
78 connect( undoStack(), &QUndoStack::indexChanged, this, &QgsMapLayer::layerModified );
79 connect( this, &QgsMapLayer::layerModified, this, [this] { triggerRepaint(); } );
80}
81
83{
84 if ( QgsTask *task = QgsApplication::taskManager()->task( mStatsCalculationTask ) )
85 {
86 mStatsCalculationTask = 0;
87 task->cancel();
88 task->waitForFinished();
89 }
90}
91
93{
95
96 QgsPointCloudLayer *layer = new QgsPointCloudLayer( source(), name(), mProviderKey, mLayerOptions );
97 QgsMapLayer::clone( layer );
98
99 if ( mRenderer )
100 layer->setRenderer( mRenderer->clone() );
101
102 layer->mElevationProperties = mElevationProperties->clone();
103 layer->mElevationProperties->setParent( layer );
104
105 layer->mLayerOptions = mLayerOptions;
106 layer->mSync3DRendererTo2DRenderer = mSync3DRendererTo2DRenderer;
107
108 return layer;
109}
110
112{
114
115 if ( !mDataProvider )
116 return QgsRectangle();
117
118 return mDataProvider->extent();
119}
120
122{
124
125 if ( mRenderer->type() != "extent"_L1 )
126 loadIndexesForRenderContext( rendererContext );
127
128 return new QgsPointCloudLayerRenderer( this, rendererContext );
129}
130
132{
134
135 if ( mElevationProperties && mElevationProperties->type() == Qgis::PointCloudProfileType::TriangulatedSurface )
136 {
137 return new QgsTriangulatedPointCloudLayerProfileGenerator( this, request );
138 }
139
140 return new QgsPointCloudLayerProfileGenerator( this, request );
141}
142
149
151{
153
154 return mDataProvider.get();
155}
156
157bool QgsPointCloudLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
158{
160
161 // create provider
162 const QDomNode pkeyNode = layerNode.namedItem( u"provider"_s );
163 mProviderKey = pkeyNode.toElement().text();
164
166 {
167 const QgsDataProvider::ProviderOptions providerOptions { context.transformContext() };
169 // read extent
171 {
172 const QDomNode extentNode = layerNode.namedItem( u"extent"_s );
173 if ( !extentNode.isNull() )
174 {
175 // get the extent
176 const QgsRectangle mbr = QgsXmlUtils::readRectangle( extentNode.toElement() );
177
178 // store the extent
179 setExtent( mbr );
180 }
181 }
182
184 const QDomNode subset = layerNode.namedItem( u"subset"_s );
185 const QString subsetText = subset.toElement().text();
186 if ( !subsetText.isEmpty() )
187 setSubsetString( subsetText );
188 }
189
190 if ( !isValid() )
191 {
192 return false;
193 }
194
195 QString errorMsg;
196 if ( !readSymbology( layerNode, errorMsg, context ) )
197 return false;
198
199 readStyleManager( layerNode );
200 return true;
201}
202
203bool QgsPointCloudLayer::writeXml( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const
204{
206
207 QDomElement mapLayerNode = layerNode.toElement();
208 mapLayerNode.setAttribute( u"type"_s, QgsMapLayerFactory::typeToString( Qgis::LayerType::PointCloud ) );
209
210 if ( !subsetString().isEmpty() )
211 {
212 QDomElement subset = doc.createElement( u"subset"_s );
213 const QDomText subsetText = doc.createTextNode( subsetString() );
214 subset.appendChild( subsetText );
215 layerNode.appendChild( subset );
216 }
217 if ( mDataProvider )
218 {
219 QDomElement provider = doc.createElement( u"provider"_s );
220 const QDomText providerText = doc.createTextNode( providerType() );
221 provider.appendChild( providerText );
222 layerNode.appendChild( provider );
223 }
224
225 writeStyleManager( layerNode, doc );
226
227 QString errorMsg;
228 return writeSymbology( layerNode, doc, errorMsg, context );
229}
230
231bool QgsPointCloudLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
232{
234
235 const QDomElement elem = node.toElement();
236
237 readCommonStyle( elem, context, categories );
238
239 readStyle( node, errorMessage, context, categories );
240
241 if ( categories.testFlag( CustomProperties ) )
242 readCustomProperties( node, u"variable"_s );
243
244 if ( categories.testFlag( Legend ) )
245 {
246 QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Legend" ) );
247
248 const QDomElement legendElem = node.firstChildElement( u"legend"_s );
249 if ( QgsMapLayerLegend *l = legend(); l && !legendElem.isNull() )
250 {
251 l->readXml( legendElem, context );
252 }
253 }
254
255 return true;
256}
257
258bool QgsPointCloudLayer::readStyle( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
259{
261
262 bool result = true;
263
264 if ( categories.testFlag( Symbology3D ) )
265 {
266 bool ok;
267 bool sync = node.attributes().namedItem( u"sync3DRendererTo2DRenderer"_s ).nodeValue().toInt( &ok );
268 if ( ok )
270 }
271
272 if ( categories.testFlag( Symbology ) )
273 {
274 QDomElement rendererElement = node.firstChildElement( u"renderer"_s );
275 if ( !rendererElement.isNull() )
276 {
277 std::unique_ptr< QgsPointCloudRenderer > r( QgsPointCloudRenderer::load( rendererElement, context ) );
278 if ( r )
279 {
280 setRenderer( r.release() );
281 }
282 else
283 {
284 result = false;
285 }
286 }
287 // make sure layer has a renderer - if none exists, fallback to a default renderer
288 if ( !mRenderer )
289 {
291 }
292 }
293
294 if ( categories.testFlag( Symbology ) )
295 {
296 // get and set the blend mode if it exists
297 const QDomNode blendModeNode = node.namedItem( u"blendMode"_s );
298 if ( !blendModeNode.isNull() )
299 {
300 const QDomElement e = blendModeNode.toElement();
301 setBlendMode( QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( e.text().toInt() ) ) );
302 }
303 }
304
305 // get and set the layer transparency and scale visibility if they exists
306 if ( categories.testFlag( Rendering ) )
307 {
308 const QDomNode layerOpacityNode = node.namedItem( u"layerOpacity"_s );
309 if ( !layerOpacityNode.isNull() )
310 {
311 const QDomElement e = layerOpacityNode.toElement();
312 setOpacity( e.text().toDouble() );
313 }
314
315 const bool hasScaleBasedVisibiliy { node.attributes().namedItem( u"hasScaleBasedVisibilityFlag"_s ).nodeValue() == '1' };
316 setScaleBasedVisibility( hasScaleBasedVisibiliy );
317 bool ok;
318 const double maxScale { node.attributes().namedItem( u"maxScale"_s ).nodeValue().toDouble( &ok ) };
319 if ( ok )
320 {
321 setMaximumScale( maxScale );
322 }
323 const double minScale { node.attributes().namedItem( u"minScale"_s ).nodeValue().toDouble( &ok ) };
324 if ( ok )
325 {
326 setMinimumScale( minScale );
327 }
328 }
329 return result;
330}
331
332bool QgsPointCloudLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
333 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
334{
336
337 Q_UNUSED( errorMessage )
338
339 QDomElement elem = node.toElement();
340 writeCommonStyle( elem, doc, context, categories );
341
342 ( void )writeStyle( node, doc, errorMessage, context, categories );
343
344 if ( categories.testFlag( Legend ) && legend() )
345 {
346 QDomElement legendElement = legend()->writeXml( doc, context );
347 if ( !legendElement.isNull() )
348 node.appendChild( legendElement );
349 }
350
351 return true;
352}
353
354bool QgsPointCloudLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
355{
357
358 QDomElement mapLayerNode = node.toElement();
359
360 if ( categories.testFlag( Symbology3D ) )
361 {
362 mapLayerNode.setAttribute( u"sync3DRendererTo2DRenderer"_s, mSync3DRendererTo2DRenderer ? 1 : 0 );
363 }
364
365 if ( categories.testFlag( Symbology ) )
366 {
367 if ( mRenderer )
368 {
369 const QDomElement rendererElement = mRenderer->save( doc, context );
370 node.appendChild( rendererElement );
371 }
372 }
373
374 //save customproperties
375 if ( categories.testFlag( CustomProperties ) )
376 {
377 writeCustomProperties( node, doc );
378 }
379
380 if ( categories.testFlag( Symbology ) )
381 {
382 // add the blend mode field
383 QDomElement blendModeElem = doc.createElement( u"blendMode"_s );
384 const QDomText blendModeText = doc.createTextNode( QString::number( static_cast< int >( QgsPainting::getBlendModeEnum( blendMode() ) ) ) );
385 blendModeElem.appendChild( blendModeText );
386 node.appendChild( blendModeElem );
387 }
388
389 // add the layer opacity and scale visibility
390 if ( categories.testFlag( Rendering ) )
391 {
392 QDomElement layerOpacityElem = doc.createElement( u"layerOpacity"_s );
393 const QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
394 layerOpacityElem.appendChild( layerOpacityText );
395 node.appendChild( layerOpacityElem );
396
397 mapLayerNode.setAttribute( u"hasScaleBasedVisibilityFlag"_s, hasScaleBasedVisibility() ? 1 : 0 );
398 mapLayerNode.setAttribute( u"maxScale"_s, maximumScale() );
399 mapLayerNode.setAttribute( u"minScale"_s, minimumScale() );
400 }
401 return true;
402}
403
405{
407
408 if ( mDataProvider )
409 mDataProvider->setTransformContext( transformContext );
411}
412
413void QgsPointCloudLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
415{
417
418 if ( mDataProvider )
419 {
420 disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
421 disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
422 }
423
424 setName( baseName );
425 mProviderKey = provider;
426 mDataSource = dataSource;
427
428 if ( mPreloadedProvider )
429 {
430 mDataProvider.reset( qobject_cast< QgsPointCloudDataProvider * >( mPreloadedProvider.release() ) );
431 }
432 else
433 {
434 std::unique_ptr< QgsScopedRuntimeProfile > profile;
435 if ( QgsApplication::profiler()->groupIsActive( u"projectload"_s ) )
436 profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Create %1 provider" ).arg( provider ), u"projectload"_s );
437 mDataProvider.reset( qobject_cast<QgsPointCloudDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource, options, flags ) ) );
438 }
439
440 if ( !mDataProvider )
441 {
442 QgsDebugError( u"Unable to get point cloud data provider"_s );
443 setValid( false );
444 return;
445 }
446
447 mIsVpc = qobject_cast<QgsVirtualPointCloudProvider *>( mDataProvider.get() ) != nullptr;
448
449 mDataProvider->setParent( this );
450 QgsDebugMsgLevel( u"Instantiated the point cloud data provider plugin"_s, 2 );
451
452 setValid( mDataProvider->isValid() );
453 if ( !isValid() )
454 {
455 QgsDebugError( u"Invalid point cloud provider plugin %1"_s.arg( QString( mDataSource.toUtf8() ) ) );
456 setError( mDataProvider->error() );
457 return;
458 }
459
460 connect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
461 connect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
462
463 // Load initial extent, crs and renderer
464 setCrs( mDataProvider->crs() );
466 {
467 setExtent3D( mDataProvider->extent3D() );
468 }
469
470 bool loadDefaultStyleFlag = false;
472 {
473 loadDefaultStyleFlag = true;
474 }
475
476 if ( !mLayerOptions.skipIndexGeneration &&
477 mDataProvider &&
479 mDataProvider->pointCount() > 0 )
480 {
481 mDataProvider->generateIndex();
482 }
483
484 if ( !mLayerOptions.skipStatisticsCalculation &&
485 mDataProvider &&
487 mDataProvider->pointCount() > 0 )
488 {
489 calculateStatistics();
490 }
491
492 if ( !mRenderer || loadDefaultStyleFlag )
493 {
494 std::unique_ptr< QgsScopedRuntimeProfile > profile;
495 if ( QgsApplication::profiler()->groupIsActive( u"projectload"_s ) )
496 profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Load layer style" ), u"projectload"_s );
497
498 bool defaultLoadedFlag = false;
499
500 if ( loadDefaultStyleFlag && isSpatial() && mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
501 {
502 // first try to create a renderer directly from the data provider
503 std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
504 if ( defaultRenderer )
505 {
506 defaultLoadedFlag = true;
507 setRenderer( defaultRenderer.release() );
508 }
509 }
510
511 if ( !defaultLoadedFlag && loadDefaultStyleFlag )
512 {
513 loadDefaultStyle( defaultLoadedFlag );
514 }
515
516 if ( !defaultLoadedFlag )
517 {
518 // all else failed, create default renderer
520 }
521 }
522}
523
530
531QString QgsPointCloudLayer::decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const
532{
534
536}
537
538void QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged( QgsPointCloudDataProvider::PointCloudIndexGenerationState state )
539{
541
542 switch ( state )
543 {
545 {
546 resetRenderer();
547 break;
548 }
550 {
551 QgsError providerError = mDataProvider->error();
552 if ( !providerError.isEmpty() )
553 {
554 setError( providerError );
555 emit raiseError( providerError.summary() );
556 }
557 break;
558 }
560 break;
561 }
562}
563
564
565QString QgsPointCloudLayer::loadDefaultStyle( bool &resultFlag )
566{
568
569 if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
570 {
571 // first try to create a renderer directly from the data provider
572 std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
573 if ( defaultRenderer )
574 {
575 resultFlag = true;
576 setRenderer( defaultRenderer.release() );
577 return QString();
578 }
579 }
580
581 return QgsMapLayer::loadDefaultStyle( resultFlag );
582}
583
585{
587
588 const QgsLayerMetadataFormatter htmlFormatter( metadata() );
589 QString myMetadata = u"<html>\n<body>\n"_s;
590
591 myMetadata += generalHtmlMetadata();
592
593 // Begin Provider section
594 myMetadata += u"<h1>"_s + tr( "Information from provider" ) + u"</h1>\n<hr>\n"_s;
595 myMetadata += "<table class=\"list-view\">\n"_L1;
596
597 // Extent
598 myMetadata += u"<tr><td class=\"highlight\">"_s + tr( "Extent" ) + u"</td><td>"_s + extent().toString() + u"</td></tr>\n"_s;
599
600 // feature count
601 QLocale locale = QLocale();
602 locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
603 const qint64 pointCount = mDataProvider ? mDataProvider->pointCount() : -1;
604 myMetadata += u"<tr><td class=\"highlight\">"_s
605 + tr( "Point count" ) + u"</td><td>"_s
606 + ( pointCount < 0 ? tr( "unknown" ) : locale.toString( static_cast<qlonglong>( pointCount ) ) )
607 + u"</td></tr>\n"_s;
608
609 if ( const QgsPointCloudDataProvider *provider = dataProvider() )
610 {
611 myMetadata += provider->htmlMetadata();
612 }
613
614 myMetadata += "</table>\n<br><br>"_L1;
615
616 // CRS
617 myMetadata += crsHtmlMetadata();
618
619 // provider metadata section
620 myMetadata += u"<h1>"_s + tr( "Metadata" ) + u"</h1>\n<hr>\n"_s + u"<table class=\"list-view\">\n"_s;
621 const QVariantMap originalMetadata = mDataProvider ? mDataProvider->originalMetadata() : QVariantMap();
622
623 if ( originalMetadata.value( u"creation_year"_s ).toInt() > 0 && originalMetadata.contains( u"creation_doy"_s ) )
624 {
625 QDate creationDate( originalMetadata.value( u"creation_year"_s ).toInt(), 1, 1 );
626 creationDate = creationDate.addDays( originalMetadata.value( u"creation_doy"_s ).toInt() );
627
628 myMetadata += u"<tr><td class=\"highlight\">"_s
629 + tr( "Creation date" ) + u"</td><td>"_s
630 + creationDate.toString( Qt::ISODate )
631 + u"</td></tr>\n"_s;
632 }
633 if ( originalMetadata.contains( u"major_version"_s ) && originalMetadata.contains( u"minor_version"_s ) )
634 {
635 myMetadata += u"<tr><td class=\"highlight\">"_s
636 + tr( "Version" ) + u"</td><td>"_s
637 + u"%1.%2"_s.arg( originalMetadata.value( u"major_version"_s ).toString(),
638 originalMetadata.value( u"minor_version"_s ).toString() )
639 + u"</td></tr>\n"_s;
640 }
641
642 if ( !originalMetadata.value( u"dataformat_id"_s ).toString().isEmpty() )
643 {
644 myMetadata += u"<tr><td class=\"highlight\">"_s
645 + tr( "Data format" ) + u"</td><td>"_s
646 + u"%1 (%2)"_s.arg( QgsPointCloudDataProvider::translatedDataFormatIds().value( originalMetadata.value( u"dataformat_id"_s ).toInt() ),
647 originalMetadata.value( u"dataformat_id"_s ).toString() ).trimmed()
648 + u"</td></tr>\n"_s;
649 }
650
651 myMetadata += u"<tr><td class=\"highlight\">"_s
652 + tr( "Scale X" ) + u"</td><td>"_s
653 + QString::number( originalMetadata.value( u"scale_x"_s ).toDouble() )
654 + u"</td></tr>\n"_s;
655 myMetadata += u"<tr><td class=\"highlight\">"_s
656 + tr( "Scale Y" ) + u"</td><td>"_s
657 + QString::number( originalMetadata.value( u"scale_y"_s ).toDouble() )
658 + u"</td></tr>\n"_s;
659 myMetadata += u"<tr><td class=\"highlight\">"_s
660 + tr( "Scale Z" ) + u"</td><td>"_s
661 + QString::number( originalMetadata.value( u"scale_z"_s ).toDouble() )
662 + u"</td></tr>\n"_s;
663
664 myMetadata += u"<tr><td class=\"highlight\">"_s
665 + tr( "Offset X" ) + u"</td><td>"_s
666 + QString::number( originalMetadata.value( u"offset_x"_s ).toDouble() )
667 + u"</td></tr>\n"_s;
668 myMetadata += u"<tr><td class=\"highlight\">"_s
669 + tr( "Offset Y" ) + u"</td><td>"_s
670 + QString::number( originalMetadata.value( u"offset_y"_s ).toDouble() )
671 + u"</td></tr>\n"_s;
672 myMetadata += u"<tr><td class=\"highlight\">"_s
673 + tr( "Offset Z" ) + u"</td><td>"_s
674 + QString::number( originalMetadata.value( u"offset_z"_s ).toDouble() )
675 + u"</td></tr>\n"_s;
676
677 if ( !originalMetadata.value( u"project_id"_s ).toString().isEmpty() )
678 {
679 myMetadata += u"<tr><td class=\"highlight\">"_s
680 + tr( "Project ID" ) + u"</td><td>"_s
681 + originalMetadata.value( u"project_id"_s ).toString()
682 + u"</td></tr>\n"_s;
683 }
684
685 if ( !originalMetadata.value( u"system_id"_s ).toString().isEmpty() )
686 {
687 myMetadata += u"<tr><td class=\"highlight\">"_s
688 + tr( "System ID" ) + u"</td><td>"_s
689 + originalMetadata.value( u"system_id"_s ).toString()
690 + u"</td></tr>\n"_s;
691 }
692
693 if ( !originalMetadata.value( u"software_id"_s ).toString().isEmpty() )
694 {
695 myMetadata += u"<tr><td class=\"highlight\">"_s
696 + tr( "Software ID" ) + u"</td><td>"_s
697 + originalMetadata.value( u"software_id"_s ).toString()
698 + u"</td></tr>\n"_s;
699 }
700
701 // End Provider section
702 myMetadata += "</table>\n<br><br>"_L1;
703
704 // identification section
705 myMetadata += u"<h1>"_s + tr( "Identification" ) + u"</h1>\n<hr>\n"_s;
706 myMetadata += htmlFormatter.identificationSectionHtml( );
707 myMetadata += "<br><br>\n"_L1;
708
709 // extent section
710 myMetadata += u"<h1>"_s + tr( "Extent" ) + u"</h1>\n<hr>\n"_s;
711 myMetadata += htmlFormatter.extentSectionHtml( isSpatial() );
712 myMetadata += "<br><br>\n"_L1;
713
714 // Start the Access section
715 myMetadata += u"<h1>"_s + tr( "Access" ) + u"</h1>\n<hr>\n"_s;
716 myMetadata += htmlFormatter.accessSectionHtml( );
717 myMetadata += "<br><br>\n"_L1;
718
719 // Attributes section
720 myMetadata += u"<h1>"_s + tr( "Attributes" ) + u"</h1>\n<hr>\n<table class=\"list-view\">\n"_s;
721
723
724 // count attributes
725 myMetadata += u"<tr><td class=\"highlight\">"_s + tr( "Count" ) + u"</td><td>"_s + QString::number( attrs.count() ) + u"</td></tr>\n"_s;
726
727 myMetadata += "</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n"_L1;
728 myMetadata += "<tr><th>"_L1 + tr( "Attribute" ) + "</th><th>"_L1 + tr( "Type" ) + "</th></tr>\n"_L1;
729
730 for ( int i = 0; i < attrs.count(); ++i )
731 {
732 const QgsPointCloudAttribute attribute = attrs.at( i );
733 QString rowClass;
734 if ( i % 2 )
735 rowClass = u"class=\"odd-row\""_s;
736 myMetadata += "<tr "_L1 + rowClass + "><td>"_L1 + attribute.name() + "</td><td>"_L1 + attribute.displayType() + "</td></tr>\n"_L1;
737 }
738
739 //close field list
740 myMetadata += "</table>\n<br><br>"_L1;
741
742
743 // Start the contacts section
744 myMetadata += u"<h1>"_s + tr( "Contacts" ) + u"</h1>\n<hr>\n"_s;
745 myMetadata += htmlFormatter.contactsSectionHtml( );
746 myMetadata += "<br><br>\n"_L1;
747
748 // Start the links section
749 myMetadata += u"<h1>"_s + tr( "Links" ) + u"</h1>\n<hr>\n"_s;
750 myMetadata += htmlFormatter.linksSectionHtml( );
751 myMetadata += "<br><br>\n"_L1;
752
753 // Start the history section
754 myMetadata += u"<h1>"_s + tr( "History" ) + u"</h1>\n<hr>\n"_s;
755 myMetadata += htmlFormatter.historySectionHtml( );
756 myMetadata += "<br><br>\n"_L1;
757
758 myMetadata += customPropertyHtmlMetadata();
759
760 myMetadata += "\n</body>\n</html>\n"_L1;
761 return myMetadata;
762}
763
770
772{
774
775 return mDataProvider ? mDataProvider->attributes() : QgsPointCloudAttributeCollection();
776}
777
779{
781
782 return mDataProvider ? mDataProvider->pointCount() : 0;
783}
784
791
793{
795
796 return mRenderer.get();
797}
798
800{
802
803 if ( renderer == mRenderer.get() )
804 return;
805
806 mRenderer.reset( renderer );
807 emit rendererChanged();
809
810 if ( mSync3DRendererTo2DRenderer )
812}
813
814bool QgsPointCloudLayer::setSubsetString( const QString &subset )
815{
817
818 if ( !isValid() || !mDataProvider )
819 {
820 QgsDebugMsgLevel( u"invoked with invalid layer or null mDataProvider"_s, 3 );
821 setCustomProperty( u"storedSubsetString"_s, subset );
822 return false;
823 }
824 else if ( subset == mDataProvider->subsetString() )
825 return true;
826
827 bool res = mDataProvider->setSubsetString( subset );
828 if ( res )
829 {
830 emit subsetStringChanged();
832 }
833 return res;
834}
835
837{
839
840 if ( !isValid() || !mDataProvider )
841 {
842 QgsDebugMsgLevel( u"invoked with invalid layer or null mDataProvider"_s, 3 );
843 return customProperty( u"storedSubsetString"_s ).toString();
844 }
845 return mDataProvider->subsetString();
846}
847
849{
851
852 bool result = false;
854 {
855 std::unique_ptr< QgsAbstractPointCloud3DRenderer > newRenderer( static_cast< QgsAbstractPointCloud3DRenderer * >( r->clone() ) );
856 result = newRenderer->convertFrom2DRenderer( renderer() );
857 setRenderer3D( newRenderer.release() );
859 }
860 return result;
861}
862
864{
866
867 return mSync3DRendererTo2DRenderer;
868}
869
871{
873
874 mSync3DRendererTo2DRenderer = sync;
875 if ( sync )
877}
878
879void QgsPointCloudLayer::calculateStatistics()
880{
882
883 if ( !mDataProvider.get() || !mDataProvider->hasValidIndex() )
884 {
885 QgsMessageLog::logMessage( QObject::tr( "Failed to calculate statistics of the point cloud %1" ).arg( this->name() ) );
886 return;
887 }
888 if ( mStatsCalculationTask )
889 {
890 QgsMessageLog::logMessage( QObject::tr( "A statistics calculation task for the point cloud %1 is already in progress" ).arg( this->name() ) );
891 return;
892 }
893
894 QgsPointCloudStatistics indexStats = mDataProvider->metadataStatistics();
895 QList<QString> indexStatsAttributes = indexStats.statisticsMap().keys();
896 QVector<QgsPointCloudAttribute> attributes = mDataProvider->attributes().attributes();
897 // Do not calculate stats for attributes that the index gives us stats for
898 for ( int i = 0; i < attributes.size(); ++i )
899 {
900 if ( indexStatsAttributes.contains( attributes[i].name() ) )
901 {
902 attributes.remove( i );
903 --i;
904 }
905 }
906
907 // Use the layer statistics for now, until we can calculate complete ones
908 mStatistics = indexStats;
909 if ( attributes.empty() && indexStats.sampledPointsCount() > 0 )
910 {
911 // All attributes are covered by the saved stats, skip calculating anything
913 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
914 resetRenderer();
915 return;
916 }
917
918 QgsPointCloudStatsCalculationTask *task = new QgsPointCloudStatsCalculationTask( mDataProvider->index(), attributes, 1000000 );
919 connect( task, &QgsTask::taskCompleted, this, [this, task, indexStats, indexStatsAttributes]()
920 {
921 mStatistics = task->calculationResults();
922
923 // Fetch what we can directly from the index
924 QMap<QString, QgsPointCloudAttributeStatistics> statsMap = mStatistics.statisticsMap();
925 for ( const QString &attribute : indexStatsAttributes )
926 {
927 statsMap[ attribute ] = indexStats.statisticsOf( attribute );
928 }
929 mStatistics = QgsPointCloudStatistics( mStatistics.sampledPointsCount(), statsMap );
930
932 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
933 resetRenderer();
934 mStatsCalculationTask = 0;
935#ifdef HAVE_COPC
936 if ( mDataProvider && mDataProvider->index() && mDataProvider->index().isValid() && mDataProvider->name() == "pdal"_L1 && mStatistics.sampledPointsCount() != 0 )
937 {
938 mDataProvider->index().writeStatistics( mStatistics );
939 }
940#endif
941 } );
942
943 // In case the statistics calculation fails, QgsTask::taskTerminated will be called
944 connect( task, &QgsTask::taskTerminated, this, [this]()
945 {
946 if ( mStatsCalculationTask )
947 {
948 QgsMessageLog::logMessage( QObject::tr( "Failed to calculate statistics of the point cloud %1" ).arg( this->name() ) );
949 mStatsCalculationTask = 0;
950 }
951 } );
952
953 mStatsCalculationTask = QgsApplication::taskManager()->addTask( task );
954
956 emit statisticsCalculationStateChanged( mStatisticsCalculationState );
957}
958
959void QgsPointCloudLayer::resetRenderer()
960{
962
963 mDataProvider->loadIndex();
965 {
966 calculateStatistics();
967 }
968 if ( !mRenderer || mRenderer->type() == "extent"_L1 )
969 {
971 }
973
974 emit rendererChanged();
975}
976
977void QgsPointCloudLayer::loadIndexesForRenderContext( QgsRenderContext &rendererContext ) const
978{
979 if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::ContainSubIndexes )
980 {
981 QgsRectangle renderExtent;
982 try
983 {
984 renderExtent = rendererContext.coordinateTransform().transformBoundingBox( rendererContext.mapExtent(), Qgis::TransformDirection::Reverse );
985 }
986 catch ( QgsCsException & )
987 {
988 QgsDebugError( u"Transformation of extent failed!"_s );
989 }
990
991 const QVector<QgsPointCloudSubIndex> subIndex = mDataProvider->subIndexes();
992 if ( const QgsVirtualPointCloudProvider *vpcProvider = dynamic_cast<QgsVirtualPointCloudProvider *>( mDataProvider.get() ) )
993 {
994 for ( int i = 0; i < subIndex.size(); ++i )
995 {
996 // no need to load as it's there
997 if ( subIndex.at( i ).index() )
998 continue;
999
1000 const double overviewSwitchingScale = mRenderer ? mRenderer->overviewSwitchingScale() : 1.0;
1001 const double widthThreshold = vpcProvider->averageSubIndexWidth() * overviewSwitchingScale;
1002 const double heightThreshold = vpcProvider->averageSubIndexHeight() * overviewSwitchingScale;
1003
1004 if ( subIndex.at( i ).extent().intersects( renderExtent ) &&
1005 ( renderExtent.width() < widthThreshold ||
1006 renderExtent.height() < heightThreshold ) )
1007 {
1008 mDataProvider->loadSubIndex( i );
1009 }
1010 }
1011 }
1012 }
1013}
1014
1016{
1018 if ( !mDataProvider || mEditable )
1019 return false;
1020
1021 if ( mIsVpc )
1022 {
1023 QgsVirtualPointCloudProvider *vpcProvider = qobject_cast<QgsVirtualPointCloudProvider *>( mDataProvider.get() );
1024 const QVector<QgsPointCloudSubIndex> subIndexes = vpcProvider->subIndexes();
1025
1026 for ( int i = 0; i < subIndexes.size(); ++i )
1027 {
1028 const QgsPointCloudSubIndex &subIndex = subIndexes.at( i );
1029 QgsPointCloudIndex index = subIndex.index();
1030
1031 if ( !index.isValid() )
1032 {
1033 continue;
1034 }
1035
1037 mEditingIndexes[ i ] = editIndex;
1038 }
1039 }
1040 else
1041 {
1042 mEditIndex = QgsPointCloudIndex( new QgsPointCloudEditingIndex( mDataProvider->index() ) );
1043 if ( !mEditIndex.isValid() )
1044 {
1045 mEditIndex = QgsPointCloudIndex();
1046 return false;
1047 }
1048 }
1049
1050 mEditable = true;
1051 emit editingStarted();
1052 return true;
1053}
1054
1056{
1058
1059 if ( mIsVpc )
1060 {
1061 for ( QgsPointCloudIndex &index : mEditingIndexes )
1062 if ( index.isModified() && !index.commitChanges( &mCommitError ) )
1063 return false;
1064 }
1065 else
1066 {
1067 if ( mEditIndex.isModified() && !mEditIndex.commitChanges( &mCommitError ) )
1068 return false;
1069
1070 // emitting layerModified() is not required as that's done automatically
1071 // when undo stack index changes
1072 }
1073
1074 undoStack()->clear();
1075
1076 if ( stopEditing )
1077 {
1078 if ( mIsVpc )
1079 mEditingIndexes.clear();
1080 else
1081 mEditIndex = QgsPointCloudIndex();
1082
1083 mEditable = false;
1084 emit editingStopped();
1085 }
1086
1087 return true;
1088}
1089
1091{
1093 return mCommitError;
1094}
1095
1097{
1099 if ( !mEditable )
1100 return false;
1101
1102 if ( mIsVpc )
1103 {
1104 if ( mEditingIndexes.isEmpty() )
1105 return false;
1106
1107 QVector<QPair<int, QList<QgsPointCloudNodeId>>> queuedUpdates;
1108 queuedUpdates.reserve( mEditingIndexes.size() );
1109 for ( auto [position, index] : mEditingIndexes.asKeyValueRange() )
1110 {
1111 if ( !index.isValid() )
1112 continue;
1113 const QList<QgsPointCloudNodeId> updatedNodes = index.updatedNodes();
1114 if ( !updatedNodes.isEmpty() )
1115 queuedUpdates.push_back( qMakePair( position, updatedNodes ) );
1116 }
1117
1118 undoStack()->clear();
1119 mEditable = false;
1120 mEditingIndexes.clear();
1121 emit editingStopped();
1122
1123 for ( const QPair<int, QList<QgsPointCloudNodeId>> &pair : std::as_const( queuedUpdates ) )
1124 {
1125 const int position = pair.first;
1126 const QList<QgsPointCloudNodeId> &nodes = pair.second;
1127 for ( const QgsPointCloudNodeId &n : nodes )
1128 emit chunkAttributeValuesChanged( n, position );
1129 }
1130 }
1131 else
1132 {
1133 if ( !mEditIndex )
1134 return false;
1135
1136 const QList<QgsPointCloudNodeId> updatedNodes = mEditIndex.updatedNodes();
1137
1138 undoStack()->clear();
1139
1140 mEditIndex = QgsPointCloudIndex();
1141 mEditable = false;
1142 emit editingStopped();
1143
1144 for ( const QgsPointCloudNodeId &n : updatedNodes )
1145 emit chunkAttributeValuesChanged( n, -1 );
1146
1147 // emitting layerModified() is not required as that's done automatically
1148 // when undo stack index changes
1149 }
1150 return true;
1151}
1152
1154{
1156 return mDataProvider && mDataProvider->capabilities() & QgsPointCloudDataProvider::Capability::ChangeAttributeValues;
1157}
1158
1160{
1162
1163 return mEditable;
1164}
1165
1167{
1169 if ( !mEditable )
1170 return false;
1171
1172 if ( mIsVpc )
1173 {
1174 for ( const QgsPointCloudIndex &index : std::as_const( mEditingIndexes ) )
1175 {
1176 if ( index.isModified() )
1177 return true;
1178 }
1179 return false;
1180 }
1181 else
1182 {
1183 if ( !mEditIndex )
1184 return false;
1185 return mEditIndex.isModified();
1186 }
1187}
1188
1189bool QgsPointCloudLayer::changeAttributeValue( const QgsPointCloudNodeId &n, const QVector<int> &points, const QgsPointCloudAttribute &attribute, double value )
1190{
1191 if ( mIsVpc )
1192 return false;
1193
1194 // for regular point clouds, we send -1 for the position parameter
1195 return this->changeAttributeValue( { { -1, { { n, points } } } }, attribute, value );
1196}
1197
1198bool QgsPointCloudLayer::changeAttributeValue( const QHash<int, QHash<QgsPointCloudNodeId, QVector<int>>> &mappedPoints, const QgsPointCloudAttribute &attribute, double value )
1199{
1201
1202 QgsEventTracing::ScopedEvent _trace( u"PointCloud"_s, u"QgsPointCloudLayer::changeAttributeValue"_s );
1203
1204 if ( !mEditable )
1205 return false;
1206
1207 QVector<QgsPointCloudSubIndex> subs = subIndexes();
1208
1209 for ( auto it = mappedPoints.constBegin(); it != mappedPoints.constEnd(); it++ )
1210 {
1211 const int position = it.key();
1212 QHash<QgsPointCloudNodeId, QVector<int>> nodesAndPoints = it.value();
1213 QgsPointCloudIndex editIndex;
1214
1215 // NOLINTBEGIN(bugprone-branch-clone)
1216 if ( mIsVpc )
1217 {
1218 if ( position >= subs.size() || position < 0 )
1219 return false;
1220
1221 QgsPointCloudIndex index = subs.at( position ).index();
1222 if ( !index || !index.isValid() )
1223 return false;
1224
1225 editIndex = index;
1226 }
1227 else
1228 {
1229 editIndex = mEditIndex;
1230 }
1231 // NOLINTEND(bugprone-branch-clone)
1232
1233 // Cannot allow x,y,z editing as points may get moved outside the node extents
1234 if ( attribute.name().compare( 'X'_L1, Qt::CaseInsensitive ) == 0 ||
1235 attribute.name().compare( 'Y'_L1, Qt::CaseInsensitive ) == 0 ||
1236 attribute.name().compare( 'Z'_L1, Qt::CaseInsensitive ) == 0 )
1237 return false;
1238
1239 const QgsPointCloudAttributeCollection attributeCollection = editIndex.attributes();
1240
1241 int attributeOffset;
1242 const QgsPointCloudAttribute *at = attributeCollection.find( attribute.name(), attributeOffset );
1243
1244 if ( !at ||
1245 at->size() != attribute.size() ||
1246 at->type() != attribute.type() )
1247 {
1248 return false;
1249 }
1250
1251 if ( !QgsPointCloudLayerEditUtils::isAttributeValueValid( attribute, value ) )
1252 {
1253 return false;
1254 }
1255
1256 for ( auto it = nodesAndPoints.constBegin(); it != nodesAndPoints.constEnd(); it++ )
1257 {
1258 QgsPointCloudNodeId n = it.key();
1259 QVector<int> points = it.value();
1260
1261 if ( !n.isValid() || !editIndex.hasNode( n ) ) // todo: should not have to check if n.isValid
1262 return false;
1263
1264 if ( points.isEmpty() )
1265 continue;
1266
1267 int pointsMin = std::numeric_limits<int>::max();
1268 int pointsMax = std::numeric_limits<int>::min();
1269 for ( int pt : std::as_const( points ) )
1270 {
1271 if ( pt < pointsMin )
1272 pointsMin = pt;
1273 if ( pt > pointsMax )
1274 pointsMax = pt;
1275 }
1276
1277 if ( pointsMin < 0 || pointsMax >= editIndex.getNode( n ).pointCount() )
1278 return false;
1279 }
1280 }
1281
1282 undoStack()->push( new QgsPointCloudLayerUndoCommandChangeAttribute( this, mappedPoints, attribute, value ) );
1283
1284 return true;
1285}
1286
1288{
1290 if ( mEditIndex )
1291 return mEditIndex;
1292
1293 if ( mDataProvider )
1294 return mDataProvider->index();
1295
1296 return QgsPointCloudIndex();
1297}
1298
1299QVector<QgsPointCloudSubIndex> QgsPointCloudLayer::subIndexes() const
1300{
1302
1303 if ( !mDataProvider )
1304 return QVector<QgsPointCloudSubIndex>();
1305
1306 const QVector<QgsPointCloudSubIndex> subs = mDataProvider->subIndexes();
1307
1308 if ( !mEditable )
1309 {
1310 return subs;
1311 }
1312
1313 QVector<QgsPointCloudSubIndex> indexes;
1314 indexes.reserve( subs.size() );
1315
1316 for ( qsizetype i = 0; i < subs.size(); i++ )
1317 {
1318 QgsPointCloudSubIndex sub = subs.at( i );
1319 QgsPointCloudIndex index = sub.index();
1320
1321 if ( index.isValid() )
1322 {
1323 if ( !mEditingIndexes.contains( i ) )
1324 {
1326 mEditingIndexes[ i ] = editIndex;
1327 }
1328 sub.setIndex( mEditingIndexes[ i ] );
1329 }
1330 indexes.append( sub );
1331 }
1332
1333 return indexes;
1334}
1335
1337{
1338 if ( !mDataProvider || !mIsVpc )
1339 return QgsPointCloudIndex();
1340
1341 const QgsVirtualPointCloudProvider *vpcProvider = dynamic_cast<QgsVirtualPointCloudProvider *>( mDataProvider.get() );
1342 return vpcProvider->overview();
1343}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:5052
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:507
@ TriangulatedSurface
Create a TIN from the point cloud using Delaunay triangulation.
Definition qgis.h:4317
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:211
@ LoadDefaultStyle
Reset the layer's style to the default for the datasource.
Definition qgis.h:491
@ SkipGetExtent
Skip the extent from provider.
Definition qgis.h:492
@ Reverse
Reverse/inverse transform (from destination to source).
Definition qgis.h:2746
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:112
QString summary() const
Short error description, usually the first error in chain, the real error.
Definition qgserror.cpp:133
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:87
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:89
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:99
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:95
@ 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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
A collection of point cloud attributes.
const QgsPointCloudAttribute & at(int index) const
Returns the attribute at the specified index.
const QgsPointCloudAttribute * find(const QString &attributeName, int &offset) const
Finds the attribute with the name.
int count() const
Returns the number of attributes present in the collection.
Attribute for point cloud data pair of name and size in bytes.
QString displayType() const
Returns the type to use when displaying this field.
int size() const
Returns size of the attribute in bytes.
QString name() const
Returns name of the attribute.
DataType type() const
Returns the data type.
Base class for providing data for QgsPointCloudLayer.
@ CreateRenderer
Provider can create 2D renderers using backend-specific formatting information. See QgsPointCloudData...
@ ChangeAttributeValues
Provider can modify the values of point attributes.
@ ContainSubIndexes
Provider can contain multiple indexes. Virtual point cloud files for example.
static QMap< int, QString > translatedDataFormatIds()
Returns the map of LAS data format ID to translated string value.
void indexGenerationStateChanged(QgsPointCloudDataProvider::PointCloudIndexGenerationState state)
Emitted when point cloud generation state is changed.
PointCloudIndexGenerationState
Point cloud index state.
@ NotIndexed
Provider has no index available.
@ Indexing
Provider try to index the source data.
@ Indexed
The index is ready to be used.
A QgsPointCloudIndex that is used as an editing buffer when editing point cloud data.
Smart pointer for QgsAbstractPointCloudIndex.
QgsPointCloudNode getNode(const QgsPointCloudNodeId &id) const
Returns object for a given node.
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.
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.
QgsPointCloudIndex overview() const
Returns the overview point cloud index associated with the layer (only if the layer has a virtual poi...
QgsPointCloudLayer(const QString &uri=QString(), const QString &baseName=QString(), const QString &providerLib=u"pointcloud"_s, const QgsPointCloudLayer::LayerOptions &options=QgsPointCloudLayer::LayerOptions())
Constructor - creates a point cloud layer.
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.
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.
QVector< QgsPointCloudSubIndex > subIndexes() const
Returns point cloud indexes associated with the layer (only if the layer has a virtual point cloud da...
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.
void chunkAttributeValuesChanged(const QgsPointCloudNodeId &n, const int position)
Emitted when a node gets some attribute values of some points changed.
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.
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.
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 rounded to the spec...
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....
Implementation of QgsAbstractProfileGenerator for triangulated point cloud layers.
static QgsRectangle readRectangle(const QDomElement &element)
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:63
#define QgsDebugError(str)
Definition qgslogger.h:59
#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.