Skip to content

Commit

Permalink
Expose QgsPointCloudIndex to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdkon committed Dec 28, 2024
1 parent 4531093 commit c714c55
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ emits :py:func:`~QgsPointCloudDataProvider.indexGenerationStateChanged`
Gets the current index generation state
%End

virtual QgsPointCloudIndex index() const;
%Docstring
Returns the point cloud index associated with the provider.

Can be None (e.g. the index is being created)
%End



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ emits :py:func:`~QgsPointCloudDataProvider.indexGenerationStateChanged`
Gets the current index generation state
%End

virtual QgsPointCloudIndex index() const;
%Docstring
Returns the point cloud index associated with the provider.

Can be None (e.g. the index is being created)
%End



Expand Down
4 changes: 1 addition & 3 deletions src/core/pointcloud/qgspointclouddataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,8 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
* Returns the point cloud index associated with the provider.
*
* Can be nullptr (e.g. the index is being created)
*
* \note Not available in Python bindings
*/
virtual QgsPointCloudIndex index() const SIP_SKIP {return QgsPointCloudIndex( nullptr );}
virtual QgsPointCloudIndex index() const { return QgsPointCloudIndex( nullptr ); }

/**
* Returns a list of sub indexes available if the provider supports multiple indexes, empty list otherwise.
Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class CORE_EXPORT QgsPointCloudIndex SIP_NODEFAULTCTORS
{
public:
//! Construct wrapper, takes ownership of index
explicit QgsPointCloudIndex( QgsAbstractPointCloudIndex *index ) SIP_SKIP;
explicit QgsPointCloudIndex( QgsAbstractPointCloudIndex *index = nullptr ) SIP_SKIP;

//! Checks if index is non-null
operator bool() const;
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ ADD_PYTHON_TEST(PyQgsPoint test_qgspoint.py)
ADD_PYTHON_TEST(PyQgsPointCloudAttributeByRampRenderer test_qgspointcloudattributebyramprenderer.py)
ADD_PYTHON_TEST(PyQgsPointCloudAttributeModel test_qgspointcloudattributemodel.py)
ADD_PYTHON_TEST(PyQgsPointCloudClassifiedRenderer test_qgspointcloudclassifiedrenderer.py)
ADD_PYTHON_TEST(PyQgsPointCloudIndex test_qgspointcloudindex.py)
ADD_PYTHON_TEST(PyQgsPointCloudDataProvider test_qgspointcloudprovider.py)
ADD_PYTHON_TEST(PyQgsPointCloudElevationProperties test_qgspointcloudelevationproperties.py)
ADD_PYTHON_TEST(PyQgsPointCloudExtentRenderer test_qgspointcloudextentrenderer.py)
Expand Down
57 changes: 57 additions & 0 deletions tests/src/python/test_qgspointcloudindex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
***************************************************************************
test_qgspointcloudindex.py
---------------------
Date : November 2024
Copyright : (C) 2024 by David Koňařík
Email : dvdkon at konarici dot cz
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

from qgis.core import (
Qgis,
QgsPointCloudLayer,
QgsPointCloudNodeId,
QgsProviderRegistry,
)
import unittest
from qgis.testing import start_app, QgisTestCase

from utilities import unitTestDataPath

start_app()


class TestQgsPointCloudIndex(QgisTestCase):

@unittest.skipIf(
"ept" not in QgsProviderRegistry.instance().providerList(),
"EPT provider not available",
)
def testIndex(self):
layer = QgsPointCloudLayer(
unitTestDataPath() + "/point_clouds/ept/sunshine-coast/ept.json",
"test",
"ept",
)
self.assertTrue(layer.isValid())

index = layer.dataProvider().index()
self.assertTrue(bool(index))
self.assertTrue(index.isValid())

self.assertEqual(index.accessType(), Qgis.PointCloudAccessType.Local)

root = index.getNode(index.root())
self.assertEqual(root.id(), QgsPointCloudNodeId(0, 0, 0, 0))


if __name__ == "__main__":
unittest.main()

0 comments on commit c714c55

Please sign in to comment.