QGIS API Documentation  3.20.0-Odense (decaadbb31)
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"
20 #include "qgspointcloudindex.h"
21 #include "qgsrectangle.h"
23 #include "qgsproviderregistry.h"
24 #include "qgslogger.h"
26 #include "qgspointcloudrenderer.h"
27 #include "qgsruntimeprofiler.h"
28 #include "qgsapplication.h"
29 #include "qgspainting.h"
32 #include "qgsmaplayerlegend.h"
33 #include "qgsxmlutils.h"
34 #include "qgsmaplayerfactory.h"
35 #include <QUrl>
36 
38  const QString &baseName,
39  const QString &providerLib,
40  const QgsPointCloudLayer::LayerOptions &options )
41  : QgsMapLayer( QgsMapLayerType::PointCloudLayer, baseName, uri )
42  , mElevationProperties( new QgsPointCloudLayerElevationProperties( this ) )
43 {
44  if ( !uri.isEmpty() && !providerLib.isEmpty() )
45  {
46  QgsDataProvider::ProviderOptions providerOptions { options.transformContext };
47  QgsDataProvider::ReadFlags providerFlags = QgsDataProvider::ReadFlags();
48  if ( options.loadDefaultStyle )
49  {
51  }
52  setDataSource( uri, baseName, providerLib, providerOptions, providerFlags );
53 
54  if ( !options.skipIndexGeneration && mDataProvider && mDataProvider->isValid() )
55  mDataProvider.get()->generateIndex();
56  }
57 
59 }
60 
62 
64 {
65  LayerOptions options;
66  options.loadDefaultStyle = false;
68  options.skipCrsValidation = true;
69 
70  QgsPointCloudLayer *layer = new QgsPointCloudLayer( source(), name(), mProviderKey, options );
71  QgsMapLayer::clone( layer );
72 
73  if ( mRenderer )
74  layer->setRenderer( mRenderer->clone() );
75 
76  return layer;
77 }
78 
80 {
81  if ( !mDataProvider )
82  return QgsRectangle();
83 
84  return mDataProvider->extent();
85 }
86 
88 {
89  return new QgsPointCloudLayerRenderer( this, rendererContext );
90 }
91 
93 {
94  return mDataProvider.get();
95 }
96 
98 {
99  return mDataProvider.get();
100 }
101 
102 bool QgsPointCloudLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
103 {
104  // create provider
105  QDomNode pkeyNode = layerNode.namedItem( QStringLiteral( "provider" ) );
106  mProviderKey = pkeyNode.toElement().text();
107 
109  {
110  QgsDataProvider::ProviderOptions providerOptions { context.transformContext() };
111  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
112  // read extent
114  {
115  const QDomNode extentNode = layerNode.namedItem( QStringLiteral( "extent" ) );
116  if ( !extentNode.isNull() )
117  {
118  // get the extent
119  const QgsRectangle mbr = QgsXmlUtils::readRectangle( extentNode.toElement() );
120 
121  // store the extent
122  setExtent( mbr );
123 
124  // skip get extent
126  }
127  }
129  {
131  }
132  setDataSource( mDataSource, mLayerName, mProviderKey, providerOptions, flags );
133  }
134 
135  if ( !isValid() )
136  {
137  return false;
138  }
139 
140  QString errorMsg;
141  if ( !readSymbology( layerNode, errorMsg, context ) )
142  return false;
143 
144  readStyleManager( layerNode );
145  return true;
146 }
147 
148 bool QgsPointCloudLayer::writeXml( QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context ) const
149 {
150  QDomElement mapLayerNode = layerNode.toElement();
151  mapLayerNode.setAttribute( QStringLiteral( "type" ), QgsMapLayerFactory::typeToString( QgsMapLayerType::PointCloudLayer ) );
152 
153  if ( mDataProvider )
154  {
155  QDomElement provider = doc.createElement( QStringLiteral( "provider" ) );
156  QDomText providerText = doc.createTextNode( providerType() );
157  provider.appendChild( providerText );
158  layerNode.appendChild( provider );
159  }
160 
161  writeStyleManager( layerNode, doc );
162 
163  QString errorMsg;
164  return writeSymbology( layerNode, doc, errorMsg, context );
165 }
166 
167 bool QgsPointCloudLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
168 {
169  QDomElement elem = node.toElement();
170 
171  readCommonStyle( elem, context, categories );
172 
173  readStyle( node, errorMessage, context, categories );
174 
175  if ( categories.testFlag( CustomProperties ) )
176  readCustomProperties( node, QStringLiteral( "variable" ) );
177 
178  return true;
179 }
180 
181 bool QgsPointCloudLayer::readStyle( const QDomNode &node, QString &, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
182 {
183  bool result = true;
184 
185  if ( categories.testFlag( Symbology ) )
186  {
187  QDomElement rendererElement = node.firstChildElement( QStringLiteral( "renderer" ) );
188  if ( !rendererElement.isNull() )
189  {
190  std::unique_ptr< QgsPointCloudRenderer > r( QgsPointCloudRenderer::load( rendererElement, context ) );
191  if ( r )
192  {
193  setRenderer( r.release() );
194  }
195  else
196  {
197  result = false;
198  }
199  }
200  // make sure layer has a renderer - if none exists, fallback to a default renderer
201  if ( !mRenderer )
202  {
203  setRenderer( QgsApplication::pointCloudRendererRegistry()->defaultRenderer( mDataProvider.get() ) );
204  }
205  }
206 
207  if ( categories.testFlag( Symbology ) )
208  {
209  // get and set the blend mode if it exists
210  QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
211  if ( !blendModeNode.isNull() )
212  {
213  QDomElement e = blendModeNode.toElement();
214  setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( e.text().toInt() ) ) );
215  }
216  }
217 
218  // get and set the layer transparency and scale visibility if they exists
219  if ( categories.testFlag( Rendering ) )
220  {
221  QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
222  if ( !layerOpacityNode.isNull() )
223  {
224  QDomElement e = layerOpacityNode.toElement();
225  setOpacity( e.text().toDouble() );
226  }
227 
228  const bool hasScaleBasedVisibiliy { node.attributes().namedItem( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).nodeValue() == '1' };
229  setScaleBasedVisibility( hasScaleBasedVisibiliy );
230  bool ok;
231  const double maxScale { node.attributes().namedItem( QStringLiteral( "maxScale" ) ).nodeValue().toDouble( &ok ) };
232  if ( ok )
233  {
234  setMaximumScale( maxScale );
235  }
236  const double minScale { node.attributes().namedItem( QStringLiteral( "minScale" ) ).nodeValue().toDouble( &ok ) };
237  if ( ok )
238  {
239  setMinimumScale( minScale );
240  }
241  }
242  return result;
243 }
244 
245 bool QgsPointCloudLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage,
246  const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
247 {
248  Q_UNUSED( errorMessage )
249 
250  QDomElement elem = node.toElement();
251  writeCommonStyle( elem, doc, context, categories );
252 
253  ( void )writeStyle( node, doc, errorMessage, context, categories );
254 
255  return true;
256 }
257 
258 bool QgsPointCloudLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
259 {
260  QDomElement mapLayerNode = node.toElement();
261 
262  if ( categories.testFlag( Symbology ) )
263  {
264  if ( mRenderer )
265  {
266  QDomElement rendererElement = mRenderer->save( doc, context );
267  node.appendChild( rendererElement );
268  }
269  }
270 
271  //save customproperties
272  if ( categories.testFlag( CustomProperties ) )
273  {
274  writeCustomProperties( node, doc );
275  }
276 
277  if ( categories.testFlag( Symbology ) )
278  {
279  // add the blend mode field
280  QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
281  QDomText blendModeText = doc.createTextNode( QString::number( QgsPainting::getBlendModeEnum( blendMode() ) ) );
282  blendModeElem.appendChild( blendModeText );
283  node.appendChild( blendModeElem );
284  }
285 
286  // add the layer opacity and scale visibility
287  if ( categories.testFlag( Rendering ) )
288  {
289  QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
290  QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
291  layerOpacityElem.appendChild( layerOpacityText );
292  node.appendChild( layerOpacityElem );
293 
294  mapLayerNode.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
295  mapLayerNode.setAttribute( QStringLiteral( "maxScale" ), maximumScale() );
296  mapLayerNode.setAttribute( QStringLiteral( "minScale" ), minimumScale() );
297  }
298 
299  return true;
300 }
301 
303 {
304  if ( mDataProvider )
305  mDataProvider->setTransformContext( transformContext );
307 }
308 
309 void QgsPointCloudLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
310  const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
311 {
312  if ( mDataProvider )
313  {
314  disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
315  disconnect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
316  }
317 
318  setName( baseName );
319  mProviderKey = provider;
320  mDataSource = dataSource;
321 
322  mDataProvider.reset( qobject_cast<QgsPointCloudDataProvider *>( QgsProviderRegistry::instance()->createProvider( provider, dataSource, options, flags ) ) );
323  if ( !mDataProvider )
324  {
325  QgsDebugMsg( QStringLiteral( "Unable to get point cloud data provider" ) );
326  setValid( false );
327  return;
328  }
329 
330  mDataProvider->setParent( this );
331  QgsDebugMsgLevel( QStringLiteral( "Instantiated the point cloud data provider plugin" ), 2 );
332 
333  setValid( mDataProvider->isValid() );
334  if ( !isValid() )
335  {
336  QgsDebugMsg( QStringLiteral( "Invalid point cloud provider plugin %1" ).arg( QString( mDataSource.toUtf8() ) ) );
337  return;
338  }
339 
340  connect( mDataProvider.get(), &QgsPointCloudDataProvider::indexGenerationStateChanged, this, &QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged );
341  connect( mDataProvider.get(), &QgsPointCloudDataProvider::dataChanged, this, &QgsPointCloudLayer::dataChanged );
342 
343  // Load initial extent, crs and renderer
344  setCrs( mDataProvider->crs() );
346  {
347  setExtent( mDataProvider->extent() );
348  }
349 
350  bool loadDefaultStyleFlag = false;
352  {
353  loadDefaultStyleFlag = true;
354  }
355 
356  if ( !mRenderer || loadDefaultStyleFlag )
357  {
358  std::unique_ptr< QgsScopedRuntimeProfile > profile;
359  if ( QgsApplication::profiler()->groupIsActive( QStringLiteral( "projectload" ) ) )
360  profile = std::make_unique< QgsScopedRuntimeProfile >( tr( "Load layer style" ), QStringLiteral( "projectload" ) );
361 
362  bool defaultLoadedFlag = false;
363 
364  if ( loadDefaultStyleFlag && isSpatial() && mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
365  {
366  // first try to create a renderer directly from the data provider
367  std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
368  if ( defaultRenderer )
369  {
370  defaultLoadedFlag = true;
371  setRenderer( defaultRenderer.release() );
372  }
373  }
374 
375  if ( !defaultLoadedFlag && loadDefaultStyleFlag )
376  {
377  loadDefaultStyle( defaultLoadedFlag );
378  }
379 
380  if ( !defaultLoadedFlag )
381  {
382  // all else failed, create default renderer
383  setRenderer( QgsApplication::pointCloudRendererRegistry()->defaultRenderer( mDataProvider.get() ) );
384  }
385  }
386 }
387 
388 QString QgsPointCloudLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
389 {
390  QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( providerType(), source );
391  if ( parts.contains( QStringLiteral( "path" ) ) )
392  {
393  parts.insert( QStringLiteral( "path" ), context.pathResolver().writePath( parts.value( QStringLiteral( "path" ) ).toString() ) );
395  }
396  else
397  {
398  return source;
399  }
400 }
401 
402 QString QgsPointCloudLayer::decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const
403 {
404  QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( dataProvider, source );
405  if ( parts.contains( QStringLiteral( "path" ) ) )
406  {
407  parts.insert( QStringLiteral( "path" ), context.pathResolver().readPath( parts.value( QStringLiteral( "path" ) ).toString() ) );
409  }
410  else
411  {
412  return source;
413  }
414 }
415 
416 void QgsPointCloudLayer::onPointCloudIndexGenerationStateChanged( QgsPointCloudDataProvider::PointCloudIndexGenerationState state )
417 {
418  if ( state == QgsPointCloudDataProvider::Indexed )
419  {
420  mDataProvider.get()->loadIndex();
421  if ( mRenderer->type() == QLatin1String( "extent" ) )
422  {
423  setRenderer( QgsApplication::pointCloudRendererRegistry()->defaultRenderer( mDataProvider.get() ) );
424  }
425  triggerRepaint();
426 
427  emit rendererChanged();
428  }
429 }
430 
431 QString QgsPointCloudLayer::loadDefaultStyle( bool &resultFlag )
432 {
433  if ( mDataProvider->capabilities() & QgsPointCloudDataProvider::CreateRenderer )
434  {
435  // first try to create a renderer directly from the data provider
436  std::unique_ptr< QgsPointCloudRenderer > defaultRenderer( mDataProvider->createRenderer() );
437  if ( defaultRenderer )
438  {
439  resultFlag = true;
440  setRenderer( defaultRenderer.release() );
441  return QString();
442  }
443  }
444 
445  return QgsMapLayer::loadDefaultStyle( resultFlag );
446 }
447 
449 {
450  QgsLayerMetadataFormatter htmlFormatter( metadata() );
451  QString myMetadata = QStringLiteral( "<html>\n<body>\n" );
452 
453  // Begin Provider section
454  myMetadata += QStringLiteral( "<h1>" ) + tr( "Information from provider" ) + QStringLiteral( "</h1>\n<hr>\n" );
455  myMetadata += QLatin1String( "<table class=\"list-view\">\n" );
456 
457  // name
458  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );
459 
460  // local path
461  QVariantMap uriComponents = QgsProviderRegistry::instance()->decodeUri( mProviderKey, publicSource() );
462  QString path;
463  if ( uriComponents.contains( QStringLiteral( "path" ) ) )
464  {
465  path = uriComponents[QStringLiteral( "path" )].toString();
466  if ( QFile::exists( path ) )
467  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Path" ) + QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( path ).toString(), QDir::toNativeSeparators( path ) ) ) + QStringLiteral( "</td></tr>\n" );
468  else
469  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "URL" ) + QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl( path ).toString(), path ) ) + QStringLiteral( "</td></tr>\n" );
470  }
471 
472  // data source
473  if ( publicSource() != path )
474  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Source" ) + QStringLiteral( "</td><td>%1" ).arg( publicSource() ) + QStringLiteral( "</td></tr>\n" );
475 
476  // Extent
477  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Extent" ) + QStringLiteral( "</td><td>" ) + extent().toString() + QStringLiteral( "</td></tr>\n" );
478 
479  // feature count
480  QLocale locale = QLocale();
481  locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
482  const qint64 pointCount = mDataProvider ? mDataProvider->pointCount() : -1;
483  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
484  + tr( "Point count" ) + QStringLiteral( "</td><td>" )
485  + ( pointCount < 0 ? tr( "unknown" ) : locale.toString( static_cast<qlonglong>( pointCount ) ) )
486  + QStringLiteral( "</td></tr>\n" );
487  myMetadata += QLatin1String( "</table>\n<br><br>" );
488 
489  // CRS
490  myMetadata += crsHtmlMetadata();
491 
492  // provider metadata section
493  myMetadata += QStringLiteral( "<h1>" ) + tr( "Metadata" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
494  const QVariantMap originalMetadata = mDataProvider ? mDataProvider->originalMetadata() : QVariantMap();
495 
496  if ( originalMetadata.value( QStringLiteral( "creation_year" ) ).toInt() > 0 && originalMetadata.contains( QStringLiteral( "creation_doy" ) ) )
497  {
498  QDate creationDate( originalMetadata.value( QStringLiteral( "creation_year" ) ).toInt(), 1, 1 );
499  creationDate = creationDate.addDays( originalMetadata.value( QStringLiteral( "creation_doy" ) ).toInt() );
500 
501  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
502  + tr( "Creation date" ) + QStringLiteral( "</td><td>" )
503  + creationDate.toString( Qt::ISODate )
504  + QStringLiteral( "</td></tr>\n" );
505  }
506  if ( originalMetadata.contains( QStringLiteral( "major_version" ) ) && originalMetadata.contains( QStringLiteral( "minor_version" ) ) )
507  {
508  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
509  + tr( "Version" ) + QStringLiteral( "</td><td>" )
510  + QStringLiteral( "%1.%2" ).arg( originalMetadata.value( QStringLiteral( "major_version" ) ).toString(),
511  originalMetadata.value( QStringLiteral( "minor_version" ) ).toString() )
512  + QStringLiteral( "</td></tr>\n" );
513  }
514 
515  if ( !originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toString().isEmpty() )
516  {
517  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
518  + tr( "Data format" ) + QStringLiteral( "</td><td>" )
519  + QStringLiteral( "%1 (%2)" ).arg( QgsPointCloudDataProvider::translatedDataFormatIds().value( originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toInt() ),
520  originalMetadata.value( QStringLiteral( "dataformat_id" ) ).toString() ).trimmed()
521  + QStringLiteral( "</td></tr>\n" );
522  }
523 
524  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
525  + tr( "Scale X" ) + QStringLiteral( "</td><td>" )
526  + QString::number( originalMetadata.value( QStringLiteral( "scale_x" ) ).toDouble() )
527  + QStringLiteral( "</td></tr>\n" );
528  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
529  + tr( "Scale Y" ) + QStringLiteral( "</td><td>" )
530  + QString::number( originalMetadata.value( QStringLiteral( "scale_y" ) ).toDouble() )
531  + QStringLiteral( "</td></tr>\n" );
532  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
533  + tr( "Scale Z" ) + QStringLiteral( "</td><td>" )
534  + QString::number( originalMetadata.value( QStringLiteral( "scale_z" ) ).toDouble() )
535  + QStringLiteral( "</td></tr>\n" );
536 
537  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
538  + tr( "Offset X" ) + QStringLiteral( "</td><td>" )
539  + QString::number( originalMetadata.value( QStringLiteral( "offset_x" ) ).toDouble() )
540  + QStringLiteral( "</td></tr>\n" );
541  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
542  + tr( "Offset Y" ) + QStringLiteral( "</td><td>" )
543  + QString::number( originalMetadata.value( QStringLiteral( "offset_y" ) ).toDouble() )
544  + QStringLiteral( "</td></tr>\n" );
545  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
546  + tr( "Offset Z" ) + QStringLiteral( "</td><td>" )
547  + QString::number( originalMetadata.value( QStringLiteral( "offset_z" ) ).toDouble() )
548  + QStringLiteral( "</td></tr>\n" );
549 
550  if ( !originalMetadata.value( QStringLiteral( "project_id" ) ).toString().isEmpty() )
551  {
552  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
553  + tr( "Project ID" ) + QStringLiteral( "</td><td>" )
554  + originalMetadata.value( QStringLiteral( "project_id" ) ).toString()
555  + QStringLiteral( "</td></tr>\n" );
556  }
557 
558  if ( !originalMetadata.value( QStringLiteral( "system_id" ) ).toString().isEmpty() )
559  {
560  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
561  + tr( "System ID" ) + QStringLiteral( "</td><td>" )
562  + originalMetadata.value( QStringLiteral( "system_id" ) ).toString()
563  + QStringLiteral( "</td></tr>\n" );
564  }
565 
566  if ( !originalMetadata.value( QStringLiteral( "software_id" ) ).toString().isEmpty() )
567  {
568  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
569  + tr( "Software ID" ) + QStringLiteral( "</td><td>" )
570  + originalMetadata.value( QStringLiteral( "software_id" ) ).toString()
571  + QStringLiteral( "</td></tr>\n" );
572  }
573 
574  // End Provider section
575  myMetadata += QLatin1String( "</table>\n<br><br>" );
576 
577  // identification section
578  myMetadata += QStringLiteral( "<h1>" ) + tr( "Identification" ) + QStringLiteral( "</h1>\n<hr>\n" );
579  myMetadata += htmlFormatter.identificationSectionHtml( );
580  myMetadata += QLatin1String( "<br><br>\n" );
581 
582  // extent section
583  myMetadata += QStringLiteral( "<h1>" ) + tr( "Extent" ) + QStringLiteral( "</h1>\n<hr>\n" );
584  myMetadata += htmlFormatter.extentSectionHtml( isSpatial() );
585  myMetadata += QLatin1String( "<br><br>\n" );
586 
587  // Start the Access section
588  myMetadata += QStringLiteral( "<h1>" ) + tr( "Access" ) + QStringLiteral( "</h1>\n<hr>\n" );
589  myMetadata += htmlFormatter.accessSectionHtml( );
590  myMetadata += QLatin1String( "<br><br>\n" );
591 
592  // Attributes section
593  myMetadata += QStringLiteral( "<h1>" ) + tr( "Attributes" ) + QStringLiteral( "</h1>\n<hr>\n<table class=\"list-view\">\n" );
594 
596 
597  // count attributes
598  myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Count" ) + QStringLiteral( "</td><td>" ) + QString::number( attrs.count() ) + QStringLiteral( "</td></tr>\n" );
599 
600  myMetadata += QLatin1String( "</table>\n<br><table width=\"100%\" class=\"tabular-view\">\n" );
601  myMetadata += QLatin1String( "<tr><th>" ) + tr( "Attribute" ) + QLatin1String( "</th><th>" ) + tr( "Type" ) + QLatin1String( "</th></tr>\n" );
602 
603  for ( int i = 0; i < attrs.count(); ++i )
604  {
605  const QgsPointCloudAttribute attribute = attrs.at( i );
606  QString rowClass;
607  if ( i % 2 )
608  rowClass = QStringLiteral( "class=\"odd-row\"" );
609  myMetadata += QLatin1String( "<tr " ) + rowClass + QLatin1String( "><td>" ) + attribute.name() + QLatin1String( "</td><td>" ) + attribute.displayType() + QLatin1String( "</td></tr>\n" );
610  }
611 
612  //close field list
613  myMetadata += QLatin1String( "</table>\n<br><br>" );
614 
615 
616  // Start the contacts section
617  myMetadata += QStringLiteral( "<h1>" ) + tr( "Contacts" ) + QStringLiteral( "</h1>\n<hr>\n" );
618  myMetadata += htmlFormatter.contactsSectionHtml( );
619  myMetadata += QLatin1String( "<br><br>\n" );
620 
621  // Start the links section
622  myMetadata += QStringLiteral( "<h1>" ) + tr( "Links" ) + QStringLiteral( "</h1>\n<hr>\n" );
623  myMetadata += htmlFormatter.linksSectionHtml( );
624  myMetadata += QLatin1String( "<br><br>\n" );
625 
626  // Start the history section
627  myMetadata += QStringLiteral( "<h1>" ) + tr( "History" ) + QStringLiteral( "</h1>\n<hr>\n" );
628  myMetadata += htmlFormatter.historySectionHtml( );
629  myMetadata += QLatin1String( "<br><br>\n" );
630 
631  myMetadata += QLatin1String( "\n</body>\n</html>\n" );
632  return myMetadata;
633 }
634 
636 {
637  return mElevationProperties;
638 }
639 
641 {
642  return mDataProvider ? mDataProvider->attributes() : QgsPointCloudAttributeCollection();
643 }
644 
646 {
647  return mDataProvider ? mDataProvider->pointCount() : 0;
648 }
649 
651 {
652  return mRenderer.get();
653 }
654 
656 {
657  return mRenderer.get();
658 }
659 
661 {
662  if ( renderer == mRenderer.get() )
663  return;
664 
665  mRenderer.reset( renderer );
666  emit rendererChanged();
668 }
static QgsPointCloudRendererRegistry * pointCloudRendererRegistry()
Returns the application's point cloud renderer registry, used for managing point cloud layer 2D rende...
static QgsRuntimeProfiler * profiler()
Returns the application runtime profiler.
Contains information about the context in which a coordinate transform is executed.
@ FlagLoadDefaultStyle
Reset the layer's style to the default for the datasource.
@ FlagTrustDataSource
Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load ti...
@ SkipGetExtent
Skip the extent from provider.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
Class for metadata formatter.
QString linksSectionHtml() const
Formats the "Links" section according to a metadata object.
QString extentSectionHtml(const bool showSpatialExtent=true) const
Formats the "Extents" section according to a metadata object (extent and temporal).
QString contactsSectionHtml() const
Formats the "Contacts" section according to a metadata object.
QString identificationSectionHtml() const
Formats the "Identification" section according to a metadata object.
QString historySectionHtml() const
Formats the "History" section according to a metadata object.
QString accessSectionHtml() const
Formats the "Access" section according to a metadata object.
Base class for storage of map layer elevation properties.
static QString typeToString(QgsMapLayerType type)
Converts a map layer type to a string value.
static QgsMapLayerLegend * defaultPointCloudLegend(QgsPointCloudLayer *layer)
Create new legend implementation for a point cloud layer.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for all map layer types.
Definition: qgsmaplayer.h:70
QString name
Definition: qgsmaplayer.h:73
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...
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
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...
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:1668
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:75
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.
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:1711
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
void rendererChanged()
Signal emitted when renderer is changed.
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
void dataChanged()
Data of layer changed.
void setName(const QString &name)
Set the display name of the layer.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
bool isValid
Definition: qgsmaplayer.h:78
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1665
@ FlagReadExtentFromXml
Read extent from xml and skip get extent from provider.
Definition: qgsmaplayer.h:582
@ FlagTrustLayerMetadata
Trust layer metadata. Improves layer load time by skipping expensive checks like primary key unicity,...
Definition: qgsmaplayer.h:581
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
Definition: qgsmaplayer.h:580
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.
Definition: qgsmaplayer.h:1716
void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
double minimumScale() const
Returns the minimum map scale (i.e.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
double opacity
Definition: qgsmaplayer.h:79
@ Symbology
Symbology.
Definition: qgsmaplayer.h:155
@ Rendering
Rendering: scale visibility, simplify method, opacity.
Definition: qgsmaplayer.h:164
@ CustomProperties
Custom properties (by plugins for instance)
Definition: qgsmaplayer.h:165
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 QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Definition: qgspainting.cpp:80
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Definition: qgspainting.cpp:20
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer.
Definition: qgspainting.h:37
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Collection of point cloud attributes.
int count() const
Returns the number of attributes present in the collection.
const QgsPointCloudAttribute & at(int index) const
Returns the attribute at the specified index.
Attribute for point cloud data pair of name and size in bytes.
QString displayType() const
Returns the type to use when displaying this field.
QString name() const
Returns name of the attribute.
Base class for providing data for QgsPointCloudLayer.
@ CreateRenderer
Provider can create 2D renderers using backend-specific formatting information. See QgsPointCloudData...
static QMap< int, QString > translatedDataFormatIds()
Returns the map of LAS data format ID to translated string value.
PointCloudIndexGenerationState
Point cloud index state.
@ Indexed
The index is ready to be used.
void indexGenerationStateChanged(PointCloudIndexGenerationState state)
Emitted when point cloud generation state is changed.
Point cloud layer specific subclass of QgsMapLayerElevationProperties.
Implementation of threaded rendering for point cloud layers.
Represents a map layer supporting display of point clouds.
QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const override
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
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.
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...
QgsPointCloudRenderer * renderer()
Returns the 2D renderer for the point cloud.
qint64 pointCount() const
Returns the total number of points available in the layer.
bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const override
Write the style for the layer into the docment provided.
QgsPointCloudDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
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.
~QgsPointCloudLayer() override
bool readXml(const QDomNode &layerNode, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files.
QgsPointCloudLayer(const QString &uri=QString(), const QString &baseName=QString(), const QString &providerLib=QStringLiteral("pointcloud"), const QgsPointCloudLayer::LayerOptions &options=QgsPointCloudLayer::LayerOptions())
Constructor - creates a point cloud layer.
QgsPointCloudLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) FINAL
Read the style for the current layer from the DOM node supplied.
bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const FINAL
Write just the symbology information for the layer into the document.
void setRenderer(QgsPointCloudRenderer *renderer)
Sets the 2D renderer for the point cloud.
QString loadDefaultStyle(bool &resultFlag) FINAL
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
QgsPointCloudAttributeCollection attributes() const
Returns the attributes available from the layer.
void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
Abstract base class for 2d point cloud renderers.
static QgsPointCloudRenderer * load(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer from an XML element.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString encodeUri(const QString &providerKey, const QVariantMap &parts)
Reassembles a provider data source URI from its component paths (e.g.
The class is used as a container of context for various read/write operations on other objects.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
Contains information about the context of a rendering operation.
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:39
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:46
@ PointCloudLayer
Added in 3.18.
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
Setting options for creating vector data providers.
Setting options for loading point cloud layers.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
bool loadDefaultStyle
Set to true if the default layer style should be loaded.
bool skipIndexGeneration
Set to true if point cloud index generation should be skipped.
QgsCoordinateTransformContext transformContext
Coordinate transform context.