pub struct Hasher { /* private fields */ }Expand description
A structure for creating sortable spatio-temporal hashes with millisecond temporal precision.
Implementations§
Source§impl Hasher
impl Hasher
Sourcepub fn global(
start_datetime: DateTime<Utc>,
end_datetime: DateTime<Utc>,
) -> Result<Self>
pub fn global( start_datetime: DateTime<Utc>, end_datetime: DateTime<Utc>, ) -> Result<Self>
Creates a new hasher for the given datetime and the global extents.
§Examples
use stac_hash::Hasher;
use chrono::{Utc, TimeZone};
let start_datetime = Utc.with_ymd_and_hms(2026, 1, 1, 0, 0, 0).unwrap();
let end_datetime = Utc.with_ymd_and_hms(2027, 1, 1, 0, 0, 0).unwrap();
let hasher = Hasher::global(start_datetime, end_datetime).unwrap();Sourcepub fn new(
start_datetime: DateTime<Utc>,
end_datetime: DateTime<Utc>,
min: impl Into<Point>,
max: impl Into<Point>,
) -> Result<Self>
pub fn new( start_datetime: DateTime<Utc>, end_datetime: DateTime<Utc>, min: impl Into<Point>, max: impl Into<Point>, ) -> Result<Self>
Creates a new hasher for the given datetime and spatial intervals.
§Examples
use stac_hash::Hasher;
use chrono::{Utc, TimeZone};
// CONUS (roughly)
let start_datetime = Utc.with_ymd_and_hms(2026, 1, 1, 0, 0, 0).unwrap();
let end_datetime = Utc.with_ymd_and_hms(2027, 1, 1, 0, 0, 0).unwrap();
let hasher = Hasher::new(start_datetime, end_datetime, (-125., 25.), (-66., 50.)).unwrap();Sourcepub fn hash(
&self,
datetime: DateTime<Utc>,
point: impl Into<Point>,
) -> Result<u64>
pub fn hash( &self, datetime: DateTime<Utc>, point: impl Into<Point>, ) -> Result<u64>
Converts a datetime and a Point into a hash.
Returns an error if the datetime or the point falls outside of this hasher’s extent. Use Hasher::hash_clamped to clamp onto the boundary instead of erroring.
§Examples
use stac_hash::Hasher;
use chrono::{Utc, TimeZone};
let start = Utc.with_ymd_and_hms(2023, 1, 1, 0, 0, 0).unwrap();
let end = Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap();
let hasher = Hasher::global(start, end).unwrap();
let hash = hasher.hash(start, (0., 0.)).unwrap();Sourcepub fn hash_clamped(
&self,
datetime: DateTime<Utc>,
point: impl Into<Point>,
) -> u64
pub fn hash_clamped( &self, datetime: DateTime<Utc>, point: impl Into<Point>, ) -> u64
Converts a datetime and a Point into a hash, clamping anything outside of this hasher’s extent onto its boundary.
This cannot fail. A datetime before start_datetime hashes as
start_datetime, a longitude west of the minimum hashes as that
minimum, and so on. Each clamped value is logged at warn level. Use
Hasher::hash to get an error instead.
§Examples
use stac_hash::Hasher;
use chrono::{Utc, TimeZone};
let start = Utc.with_ymd_and_hms(2026, 1, 1, 0, 0, 0).unwrap();
let end = Utc.with_ymd_and_hms(2027, 1, 1, 0, 0, 0).unwrap();
let hasher = Hasher::new(start, end, (-109., 37.), (-102., 41.)).unwrap();
// Well west of the bounding box, so it hashes as if it were on the edge.
let hash = hasher.hash_clamped(start, (-120., 40.));
assert_eq!(hash, hasher.hash(start, (-109., 40.)).unwrap());