| RDB 2

rdb-example-01-create-database.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 #
4 #*******************************************************************************
5 #
6 # Copyright 2026 RIEGL Laser Measurement Systems
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20 # SPDX-License-Identifier: Apache-2.0
21 #
22 #*******************************************************************************
23 #
24 """
25 rdb-example-01-create-database.py
26
27 This example shows how to create a new RDB point cloud database and define
28 some point attributes.
29 """
30
31 import riegl.rdb
32
33
34 def example_define_point_attributes(pointcloud):
35 """
36 This function shows how to define and add new point attributes
37 and is used by the example functions below. Please note that there
38 is also a shortcut for built-in RIEGL default point attributes
39 which we use to define the "riegl.class" attribute at the end of
40 this function.
41 """
42
43 # Target surface reflectance
44 reflectance = riegl.rdb.PointAttribute(pointcloud)
45 reflectance.name = "riegl.reflectance"
46 reflectance.title = "Reflectance"
47 reflectance.description = "Target surface reflectance"
48 reflectance.unit_symbol = "dB"
49 reflectance.length = 1
50 reflectance.resolution = 0.010
51 reflectance.minimum_value = -100.000 # minimum,
52 reflectance.maximum_value = +100.000 # maximum and
53 reflectance.default_value = 0.000 # default in dB
54 reflectance.storage_class = riegl.rdb.PointAttribute.StorageClass.CONSTANT
55 pointcloud.point_attributes.add(reflectance)
56
57 # Point color
58 point_color = riegl.rdb.PointAttribute(pointcloud)
59 point_color.name = "riegl.rgba"
60 point_color.title = "True Color"
61 point_color.description = "Point color acquired by camera"
62 point_color.unit_symbol = "" # has no unit
63 point_color.length = 4
64 point_color.resolution = 1.000
65 point_color.minimum_value = 0.000
66 point_color.maximum_value = 255.000
67 point_color.default_value = 255.000
68 point_color.storage_class = riegl.rdb.PointAttribute.StorageClass.VARIABLE
69 pointcloud.point_attributes.add(point_color)
70
71 # Point classification - by using a shortcut for built-in RIEGL attributes:
72 pointcloud.point_attributes.add("riegl.class")
73
74
75 def example_a():
76 """
77 This is a very simple example using default values for most options.
78 """
79 print("Example A")
80 with riegl.rdb.rdb_create("pointcloud.rdbx") as rdb:
81 # Before we can modify the database, we must start a transaction
82 with riegl.rdb.Transaction(
83 rdb, # point cloud to create transaction for
84 "Initialization", # transaction title
85 "Example program v1.0" # software name
86 ) as transaction:
87 # Define some additional point attributes
88 example_define_point_attributes(rdb)
89
90 # Finally commit transaction
91 transaction.commit()
92
93 # Alternative: Create database and initialize it with commonly used point attributes and meta data (empty):
94 # with riegl.rdb.rdb_create("pointcloud.rdbx", schema=riegl.rdb.RDB_SCHEMA_RIEGL_RDBX, optionals=True) as rdb:
95
96
97 def example_b():
98 """
99 This is a more advanced example, very similar to the C++ API example 1.
100 """
101 print("Example B")
102
103 # New RDB library context
104 context = riegl.rdb.Context()
105
106 # New database instance
107 rdb = riegl.rdb.Pointcloud(context)
108
109 # Create new point cloud database
110 settings = riegl.rdb.CreateSettings(context)
111
112 # Define primary point attribute, usually the point coordinates
113 # details see class riegl::rdb::pointcloud::PointAttribute
114 settings.primary_attribute.name = "riegl.xyz"
115 settings.primary_attribute.title = "XYZ"
116 settings.primary_attribute.description = "Cartesian point coordinates"
117 settings.primary_attribute.unit_symbol = "m"
118 settings.primary_attribute.length = 3
119 settings.primary_attribute.resolution = 0.00025
120 settings.primary_attribute.minimum_value = -535000.0 # minimum,
121 settings.primary_attribute.maximum_value = +535000.0 # maximum and
122 settings.primary_attribute.default_value = 0.0 # default in m
123 settings.primary_attribute.storage_class = \
124 riegl.rdb.PointAttribute.StorageClass.VARIABLE
125
126 # Define database settings
127 settings.chunk_size = 50000 # maximum number of points per chunk
128 settings.compression_level = 50 # 50% compression rate
129
130 # Finally create new database
131 rdb.create("pointcloud.rdbx", settings)
132
133 # Before we can modify the database, we must start a transaction
134 with riegl.rdb.Transaction(
135 rdb, # point cloud to create transaction for
136 "Initialization", # transaction title
137 "Example program v1.0" # software name
138 ) as transaction:
139 # Define some additional point attributes
140 example_define_point_attributes(rdb)
141
142 # Finally commit transaction
143 transaction.commit()
144
145 # Close the database
146 rdb.close()
147
148 if __name__ == "__main__":
149 example_a()
150 example_b()