Skip to main content

epoint_io/las/
mod.rs

1use crate::Error;
2use crate::Error::InvalidVersion;
3
4pub mod read;
5mod read_impl;
6pub mod write;
7mod write_impl;
8
9pub const FILE_EXTENSION_LAS_FORMAT: &str = "las";
10pub const FILE_EXTENSION_LAZ_FORMAT: &str = "laz";
11
12#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd)]
13pub enum LasVersion {
14    /// LAS version 1.0 released 2003 by ASPRS.
15    V1_0,
16    /// LAS version 1.1 released 2005 by ASPRS.
17    V1_1,
18    /// LAS version 1.2 released 2008 by ASPRS.
19    V1_2,
20    /// LAS version 1.3 released 2010 by ASPRS.
21    V1_3,
22    /// LAS version 1.4 released 2013 by ASPRS.
23    V1_4,
24}
25
26impl LasVersion {
27    pub fn from(major: u8, minor: u8) -> Result<Self, Error> {
28        match (major, minor) {
29            (1, 0) => Ok(Self::V1_0),
30            (1, 1) => Ok(Self::V1_1),
31            (1, 2) => Ok(Self::V1_2),
32            (1, 3) => Ok(Self::V1_3),
33            (1, 4) => Ok(Self::V1_4),
34            _ => Err(InvalidVersion { major, minor }),
35        }
36    }
37}
38
39/// GPS epoch reference timestamp (Unix time).
40///
41/// GPS time is defined as seconds elapsed since January 6, 1980, 00:00:00 UTC.
42/// This constant represents the Unix timestamp (seconds since January 1, 1970, 00:00:00 UTC)
43/// corresponding to the GPS epoch start date.
44///
45/// # Value
46/// `315964800` seconds = 10 years, 6 days from Unix epoch to GPS epoch
47///
48/// ```
49/// use chrono::Utc;
50/// use chrono::TimeZone;
51/// let base_time = Utc.with_ymd_and_hms(1980, 1, 6, 0, 0, 0).unwrap();
52///
53/// assert_eq!(base_time.timestamp(), 315964800);
54/// ```
55///
56/// # Examples
57/// - GPS epoch (0 GPS seconds) = Unix timestamp 315964800
58/// - Current time in GPS seconds can be obtained by subtracting this constant from the Unix timestamp
59///
60/// # Reference
61/// [GPS Time System](https://en.wikipedia.org/wiki/Global_Positioning_System#Timekeeping)
62const GPS_EPOCH_REFERENCE_TIMESTAMP: i64 = 315964800;
63
64// Adjusted GPS time offset in seconds (see: https://groups.google.com/g/lastools/c/_9TxnjoghGM)
65const ADJUSTED_GPS_TIME_OFFSET: i64 = 1_000_000_000;