RDB 2
rdb-example-05-remove-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-05-remove-points.py
26 
27 This example shows how to open an existing database and delete 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  "Remove", # transaction title
40  "Point Filter v1.0" # software name
41  ) as transaction:
42 
43  # Prepare point attribute buffers
44  buffer_size = 10000 # point block/chunk size
45  buffer_identifier = riegl.rdb.AttributeBuffer(
46  rdb.point_attributes["riegl.id"], buffer_size
47  )
48 
49  # Start new select query to get point ids of points with point class
50  # of 7
51  with rdb.select("riegl.class == 7") as select:
52  select.bind(buffer_identifier)
53 
54  # Start new remove query and define buffers
55  with rdb.remove() as remove:
56  remove.bind(buffer_identifier)
57 
58  # Process all points block-wise
59  point_count = 1 # actual number of points not yet known
60  while point_count > 0:
61  point_count = select.next(buffer_size)
62 
63  # Actually remove points
64  remove.next(point_count)
65 
66  # Finally commit transaction
67  transaction.commit()
riegl::rdb
RDB library components.
Definition: context.hpp:49