RDB 2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rdb-example-04-update-points.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-04-update-points.py
26 
27 This example shows how to open an existing database and modify some points.
28 This example is based on the database of rdb-example-1-create-database.
29 """
30 
31 import riegl.rdb
32 
33 # Access existing database
34 with riegl.rdb.rdb_open("pointcloud.rdbx") as rdb:
35 
36  # Before we can modify the database, we must start a transaction
37  with riegl.rdb.Transaction(
38  rdb, # point cloud object
39  "Update", # transaction title
40  "Point Classifier v1.0" # software name
41  ) as transaction:
42 
43  # Prepare point attribute buffers
44  buffer_size = 10000 # point block/chunk size
45  buffer_point_number = riegl.rdb.AttributeBuffer(
46  rdb.point_attributes["riegl.id"], buffer_size
47  )
48  buffer_point_class = riegl.rdb.AttributeBuffer(
49  rdb.point_attributes["riegl.class"], buffer_size
50  )
51 
52  # Start new select query to get point id of points with reflectance
53  # below -20 dB
54  with rdb.select("riegl.reflectance < -20.0") as select:
55  select.bind(buffer_point_number)
56 
57  # Start new update query and define buffers
58  with rdb.update() as update:
59  update.bind(buffer_point_number)
60  update.bind(buffer_point_class)
61 
62  # Process all points block-wise
63  point_count = 1 # actual number of points not yet known
64  while point_count > 0:
65  point_count = select.next(buffer_size)
66 
67  # Define new point class
68  for i in range(point_count):
69  buffer_point_class[i] = 7
70 
71  # Actually update points
72  update.next(point_count)
73 
74  # Finally commit transaction
75  transaction.commit()