| RDB 2

rdb-example-07-fill-points.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 #
4 #*******************************************************************************
5 #
6 # Copyright 2025 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-07-fill-points.py
26
27 This example shows how to open an existing database and to fill (set)
28 a point attribute with a constant value for all points. Please note
29 that this could also be accomplished by combining select and update
30 queries as shown in "rdb-example-4-update-points.py", but the fill
31 query might be faster (lower processing time) and easier to use.
32 This example is based on the database of rdb-example-1-create-database.
33 """
34
35 import riegl.rdb
36
37 # Access existing database
38 with riegl.rdb.rdb_open("pointcloud.rdbx") as rdb:
39 # Before we can modify the database, we must start a transaction
40 with riegl.rdb.Transaction(
41 rdb, # point cloud object
42 "Fill", # transaction title
43 "Point Classifier v1.0" # software name
44 ) as transaction:
45
46 # Set point class and color to a fixed value for all points
47 with rdb.fill() as fill:
48 fill.value(rdb.point_attributes["riegl.class"], 0)
49 fill.value(rdb.point_attributes["riegl.rgba"], (255, 255, 255, 255))
50 while fill.next(10000) > 0:
51 print(f"{fill.progress()}% done")
52
53 # Set different class and color for points that have a reflectance of
54 # at least 10 dB. This is actually the same as above but with different
55 # constants and a filter expression supplied to the fill() function.
56 with rdb.fill("riegl.reflectance >= 10") as fill:
57 fill.value(rdb.point_attributes["riegl.class"], 101)
58 fill.value(rdb.point_attributes["riegl.rgba"], (255, 102, 0, 255))
59 while fill.next(10000) > 0:
60 print(f"{fill.progress()}% done")
61
62 # Finally commit transaction
63 transaction.commit()