RDB 2
rdb-example-01-create-database.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 #
4 #*******************************************************************************
5 #
6 # Copyright 2023 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 
94 def example_b():
95  """
96  This is a more advanced example, very similar to the C++ API example 1.
97  """
98  print("Example B")
99 
100  # New RDB library context
101  context = riegl.rdb.Context()
102 
103  # New database instance
104  rdb = riegl.rdb.Pointcloud(context)
105 
106  # Create new point cloud database
107  settings = riegl.rdb.CreateSettings(context)
108 
109  # Define primary point attribute, usually the point coordinates
110  # details see class riegl::rdb::pointcloud::PointAttribute
111  settings.primary_attribute.name = "riegl.xyz"
112  settings.primary_attribute.title = "XYZ"
113  settings.primary_attribute.description = "Cartesian point coordinates"
114  settings.primary_attribute.unit_symbol = "m"
115  settings.primary_attribute.length = 3
116  settings.primary_attribute.resolution = 0.00025
117  settings.primary_attribute.minimum_value = -535000.0 # minimum,
118  settings.primary_attribute.maximum_value = +535000.0 # maximum and
119  settings.primary_attribute.default_value = 0.0 # default in m
120  settings.primary_attribute.storage_class = \
121  riegl.rdb.PointAttribute.StorageClass.VARIABLE
122 
123  # Define database settings
124  settings.chunk_size = 50000 # maximum number of points per chunk
125  settings.compression_level = 50 # 50% compression rate
126 
127  # Finally create new database
128  rdb.create("pointcloud.rdbx", settings)
129 
130  # Before we can modify the database, we must start a transaction
131  with riegl.rdb.Transaction(
132  rdb, # point cloud to create transaction for
133  "Initialization", # transaction title
134  "Example program v1.0" # software name
135  ) as transaction:
136  # Define some additional point attributes
137  example_define_point_attributes(rdb)
138 
139  # Finally commit transaction
140  transaction.commit()
141 
142 
143 if __name__ == "__main__":
144  example_a()
145  example_b()
riegl::rdb::Pointcloud
Main point cloud database class.
Definition: pointcloud.hpp:89
riegl::rdb
RDB library components.
Definition: context.hpp:49
riegl::rdb::Context
Library context.
Definition: context.hpp:75