1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
//! Read and write [ASPRS LAS](https://www.asprs.org/committee-general/laser-las-file-format-exchange-activities.html) //! point cloud data. //! //! # Reading //! //! Create a `Reader` from a `Path`: //! //! ``` //! use las::Reader; //! let reader = Reader::from_path("tests/data/autzen.las").unwrap(); //! ``` //! //! Or anything that implements `Read`: //! //! ``` //! use std::io::BufReader; //! use std::fs::File; //! use las::Reader; //! let read = BufReader::new(File::open("tests/data/autzen.las").unwrap()); //! let reader = Reader::new(read).unwrap(); //! ``` //! //! ## Prefer `BufRead` //! //! Your performance will be better if your `Read` is actually a `BufRead`. `Reader::from_path` //! takes care of this for you, but `Reader::new` doesn't. //! //! ## Read points //! //! Read points one-by-one with `Reader::read`: //! //! ``` //! use las::{Read, Reader}; //! let mut reader = Reader::from_path("tests/data/autzen.las").unwrap(); //! let point = reader.read().unwrap().unwrap(); //! ``` //! //! Or iterate over all points with `Reader::points`: //! //! ``` //! use las::{Read, Reader}; //! let mut reader = Reader::from_path("tests/data/autzen.las").unwrap(); //! for wrapped_point in reader.points() { //! let point = wrapped_point.unwrap(); //! println!("Point coordinates: ({}, {}, {})", point.x, point.y, point.z); //! if let Some(color) = point.color { //! println!("Point color: red={}, green={}, blue={}", //! color.red, //! color.green, //! color.blue, //! ); //! } //! } //! ``` //! //! # Writing //! //! Create a `Writer` from a `Write` and a `Header`: //! //! ``` //! use std::io::Cursor; //! use las::{Writer, Header}; //! let write = Cursor::new(Vec::new()); //! let header = Header::default(); //! let writer = Writer::new(write, header).unwrap(); //! ``` //! //! You can also write out to a path (automatically buffered with `BufWriter`): //! //! ``` //! use las::Writer; //! let writer = Writer::from_path("/dev/null", Default::default()); //! ``` //! //! Use a `Builder` to customize the las data: //! //! ``` //! use std::io::Cursor; //! use las::{Writer, Builder}; //! use las::point::Format; //! //! let mut builder = Builder::from((1, 4)); //! builder.point_format = Format::new(2).unwrap(); //! let header = builder.into_header().unwrap(); //! //! let write = Cursor::new(Vec::new()); //! let writer = Writer::new(write, header).unwrap(); //! ``` //! //! If compiled with laz you can compress the data written //! //! ``` //! use std::io::Cursor; //! use las::{Writer, Builder}; //! use las::point::Format; //! //! let mut builder = Builder::from((1, 4)); //! builder.point_format = Format::new(2).unwrap(); //! // asking to compress data //! builder.point_format.is_compressed = true; //! let header = builder.into_header().unwrap(); //! //! let write = Cursor::new(Vec::new()); //! let is_compiled_with_laz = cfg!(feature = "laz"); //! //! //! let result = Writer::new(write, header); //! if is_compiled_with_laz { //! assert_eq!(result.is_ok(), true); //! } else { //! assert_eq!(result.is_err(), true); //! } //! //! ``` //! //! The [from_path](writer/struct.Writer.html#method.from_path) will use the extension of the output //! file to determine wether the data should be compressed or not //! 'laz' => compressed //! 'las' => not compressed //! //! ## Prefer `BufWrite` //! //! Just like the `Reader`, your performance will improve greatly if you use a `BufWrite` instead //! of just a `Write`. //! //! ## Write points //! //! Write points one at a time: //! //! ``` //! use std::io::Cursor; //! use las::{Write, Writer, Point}; //! let mut writer = Writer::default(); //! let point = Point { x: 1., y: 2., z: 3., ..Default::default() }; //! writer.write(point).unwrap(); //! ``` #![deny( missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts, trivial_numeric_casts, unsafe_code, unstable_features, unused_import_braces, unused_qualifications )] #![recursion_limit = "128"] extern crate byteorder; extern crate chrono; extern crate num; extern crate thiserror; extern crate uuid; #[cfg(feature = "laz")] extern crate laz; #[cfg(feature = "laz")] mod compression; pub mod feature; pub mod header; pub mod point; pub mod raw; pub mod reader; pub mod vlr; pub mod writer; mod bounds; mod color; mod error; mod gps_time_type; mod transform; mod utils; mod vector; mod version; pub use bounds::Bounds; pub use color::Color; pub use error::Error; pub use feature::Feature; pub use gps_time_type::GpsTimeType; pub use header::{Builder, Header}; pub use point::Point; pub use reader::{Read, Reader}; pub use transform::Transform; pub use vector::Vector; pub use version::Version; pub use vlr::Vlr; pub use writer::{Write, Writer}; /// Crate-specific result type. pub type Result<T> = std::result::Result<T, Error>;