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