Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Created February 11, 2022 19:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ThomasG77/ab738ee0d721842fbea501cc96296160 to your computer and use it in GitHub Desktop.
Save ThomasG77/ab738ee0d721842fbea501cc96296160 to your computer and use it in GitHub Desktop.
from qgis.core import QgsProject, QgsPointCloudLayer
# File url from the demo to download and uncompress
# https://wxs.ign.fr/c90xknypoz1flvgojchbphgt/telechargement/prepackage/LIDARHD_PACK_NP_2021$LIDARHD_1-0_LAZ_NP-0808_6307-2021/file/LIDARHD_1-0_LAZ_NP-0808_6307-2021.7z
# Add layer and add index automatically if not present
cl1 = QgsPointCloudLayer('LIDARHD_1-0_LAZ_NP-0808_6307-2021/Semis_2021_0808_6306_LA93_IGN69.laz', 'Semis_2021_0808_6306_LA93_IGN69', 'pdal')
if cl1.isValid():
QgsProject.instance().addMapLayer(cl1)
print('cl1 indexed ?', cl1.dataProvider().indexingState() == QgsPointCloudDataProvider.NotIndexed)
# Set option to not index by default
cl2LayerOptions = QgsPointCloudLayer.LayerOptions();
cl2LayerOptions.skipIndexGeneration = True
cl2 = QgsPointCloudLayer('LIDARHD_1-0_LAZ_NP-0808_6307-2021/Semis_2021_0809_6307_LA93_IGN69.laz', 'Semis_2021_0809_6307_LA93_IGN69', 'pdal', cl2LayerOptions)
QgsProject.instance().addMapLayer(cl2)
print('cl2 indexed ?', cl2.dataProvider().indexingState() == QgsPointCloudDataProvider.NotIndexed)
cl2.dataProvider().generateIndex()
print('cl2 indexed ?', cl2.dataProvider().indexingState() == QgsPointCloudDataProvider.NotIndexed)
print(cl2.dataProvider().polygonBounds()) # QgsGeometry
print(cl2.dataProvider().polygonBounds().asWkt()) # WKT
print(cl2.dataProvider().pointCount()) # Point count via provider
print(cl2.pointCount()) # Point count via layer
print(cl2.crs().authid()) # Empty, not sure why
print(cl2.renderer()) # QgsPointCloudClassifiedRenderer
# For manipulation, see https://github.com/qgis/QGIS/blob/master/tests/src/python/test_qgspointcloudclassifiedrenderer.py for example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment