| RDB 2

rdb-example-11-meta-data.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-11-meta-data.py
26
27 This example shows how to open an existing database and access the meta data.
28 """
29
30 import json
31
32 import riegl.rdb
33
34 # open existing database:
35 with riegl.rdb.rdb_open("pointcloud.rdbx") as rdb:
36
37 # print list of all meta data item names:
38 print(rdb.meta_data.list())
39
40 # iterate over all meta data items:
41 for name in rdb.meta_data:
42 print(name)
43
44 # check if a meta data item exists:
45 # alternative: if rdb.meta_data.exists("riegl.time_base"):
46 if "riegl.time_base" in rdb.meta_data:
47 print("found riegl.time_base")
48 else:
49 print("missing riegl.time_base")
50
51 # read meta data item by name:
52 print(rdb.meta_data["riegl.time_base"])
53 print(rdb.meta_data.get("riegl.time_base", "default value"))
54 # if the item does not exist, the first variant prints an
55 # empty line and the second variant prints "default value"
56
57 # read meta data item using RIEGL default names (this
58 # is the recommended way as it helps to avoid typos):
59 print(rdb.meta_data[riegl.rdb.RDB_RIEGL_TIME_BASE])
60
61 # meta data modification:
62 with riegl.rdb.Transaction(rdb, "modify meta data", "example 11") as transaction:
63 # set plain text meta data (all three lines are equal):
64 rdb.meta_data["riegl.time_base"] = "plain text"
65 rdb.meta_data[riegl.rdb.RDB_RIEGL_TIME_BASE] = "plain text"
66 rdb.meta_data.set("riegl.time_base", "plain text")
67 # as with regular Python dictionaries, meta data items
68 # are created on demand and existing items are overwritten
69
70 # set dictionary ("object") as JSON:
71 rdb.meta_data[riegl.rdb.RDB_RIEGL_TIME_BASE] = json.dumps({
72 "epoch": "2020-04-15T15:09:10+02:00",
73 "source": "GNSS"
74 })
75
76 # delete meta data (both lines are equal):
77 rdb.meta_data.remove(riegl.rdb.RDB_RIEGL_TIME_BASE)
78 del rdb.meta_data[riegl.rdb.RDB_RIEGL_TIME_BASE]
79
80 # set example meta data:
81 rdb.meta_data[riegl.rdb.RDB_RIEGL_TIME_BASE] = riegl.rdb.RDB_RIEGL_TIME_BASE_EXAMPLE
82
83 # validate meta data:
84 try:
85 rdb.meta_data.validate(riegl.rdb.RDB_RIEGL_TIME_BASE)
86 print("successfully validated")
87 except riegl.rdb.Error as error:
88 print("validation failed:", error)
89
90 # finalize transaction
91 transaction.commit()