|
3 | 3 | [](https://crates.io/crates/copc-rs)
|
4 | 4 | [](https://docs.rs/copc-rs)
|
5 | 5 |
|
| 6 | +copc-rs is a rust library for reading and writing Cloud Optimized Point Cloud ([COPC](https://copc.io/)) data. |
| 7 | +It utilizes the las and laz crates heavily and tries to offer a similiar API to las. |
6 | 8 |
|
7 |
| -copc-rs is a library for reading Cloud Optimized Point Cloud ([COPC](https://copc.io/)) data. |
| 9 | +## Usage examples |
8 | 10 |
|
9 |
| - |
10 |
| -## Usage example |
| 11 | +### Reader |
11 | 12 |
|
12 | 13 | ```rust
|
13 |
| -let laz_file = BufReader::new(File::open("autzen-classified.copc.laz")?); |
14 |
| -let mut copc_reader = CopcReader::open(laz_file)?; |
| 14 | +let mut copc_reader = CopcReader::from_path("autzen-classified.copc.laz")?; |
15 | 15 | for point in copc_reader.points(LodSelection::Level(0), BoundsSelection::All)?.take(5) {
|
16 | 16 | println!("Point coordinates: ({}, {}, {})", point.x, point.y, point.z);
|
17 | 17 | }
|
18 | 18 | ```
|
19 | 19 |
|
| 20 | +Full example with bounds selection: |
| 21 | +```rust |
| 22 | +use copc_rs::{Bounds, BoundsSelection, CopcReader, LodSelection, Vector}; |
| 23 | + |
| 24 | +fn main() { |
| 25 | + let mut copc_reader = CopcReader::from_path("./lidar.copc.laz").unwrap(); |
| 26 | + |
| 27 | + let bounds = Bounds { |
| 28 | + min: Vector { |
| 29 | + x: 698_100., |
| 30 | + y: 6_508_100., |
| 31 | + z: 0., |
| 32 | + }, |
| 33 | + max: Vector { |
| 34 | + x: 698_230., |
| 35 | + y: 6_508_189., |
| 36 | + z: 2_000., |
| 37 | + }, |
| 38 | + }; |
| 39 | + |
| 40 | + for point in copc_reader |
| 41 | + .points(LodSelection::Resolution(1.), BoundsSelection::Within(bounds)) |
| 42 | + .unwrap() |
| 43 | + { |
| 44 | + // do something with the points |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
20 | 49 | Run an example:
|
21 | 50 | ```
|
22 | 51 | cargo run --example copc_http
|
23 | 52 | ```
|
24 | 53 |
|
| 54 | +### Writer [[*]](#writing-is-still-a-wip) |
| 55 | + |
| 56 | +```rust |
| 57 | +use copc_rs::CopcWriter; |
| 58 | +use las::Reader; |
| 59 | + |
| 60 | +fn main() { |
| 61 | + let mut las_reader = Reader::from_path("./lidar.las").unwrap(); |
| 62 | + |
| 63 | + let header = las_reader.header().clone(); |
| 64 | + let num_points = header.number_of_points() as i32; |
| 65 | + let points = las_reader.points().filter_map(las::Result::ok); |
| 66 | + |
| 67 | + let mut copc_writer = CopcWriter::from_path("./lidar.copc.laz", header, -1, -1).unwrap(); |
| 68 | + |
| 69 | + copc_writer.write(points, num_points).unwrap(); |
| 70 | + |
| 71 | + println!("{:#?}", copc_writer.copc_info()); |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +## Writing is still a WIP |
| 76 | + |
| 77 | +Writing of the octree structure seem to work, so spatial queries in full resolution on copc-rs written files should be good. |
| 78 | +BUT the octree levels does not yet contain a similar point distribution as the whole cloud so results from resolution queries on copc-rs written files are wrong. |
| 79 | +This means the written files will look bad in viewers. |
| 80 | + |
| 81 | + |
| 82 | +I will look into it when I find time, for now I only need full resolution spatial queries in my current project anyway. |
| 83 | + |
| 84 | +-oyhj1801 |
25 | 85 |
|
26 | 86 | ## Credits
|
27 | 87 |
|
28 |
| -This library depends heavily on the work of Thomas Montaigu (@tmontaigu) and Pete Gadomski (@gadomski). |
| 88 | +This library depends heavily on the work of Thomas Montaigu (@tmontaigu) and Pete Gadomski (@gadomski), the authors of the laz and las crates. |
0 commit comments