SPlit up
This commit is contained in:
parent
cf39ad754e
commit
f59d01227b
91 changed files with 10370 additions and 7562 deletions
34
server-rs/src/data/property/h3.rs
Normal file
34
server-rs/src/data/property/h3.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//! H3 spatial cell precomputation for property rows.
|
||||
|
||||
use anyhow::Context;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::consts::H3_PRECOMPUTE_MAX;
|
||||
|
||||
/// Precompute H3 cell IDs for all rows at the maximum resolution only.
|
||||
/// Parent cells for lower resolutions are derived on the fly via `CellIndex::parent()`.
|
||||
pub fn precompute_h3(lat: &[f32], lon: &[f32]) -> anyhow::Result<Vec<u64>> {
|
||||
let res = H3_PRECOMPUTE_MAX;
|
||||
tracing::info!("Precomputing H3 cells at resolution {}", res);
|
||||
|
||||
let h3_res =
|
||||
h3o::Resolution::try_from(res).with_context(|| format!("Invalid H3 resolution: {res}"))?;
|
||||
|
||||
let cells: Vec<u64> = lat
|
||||
.par_iter()
|
||||
.zip(lon.par_iter())
|
||||
.enumerate()
|
||||
.map(|(i, (&latitude, &longitude))| {
|
||||
let coord = h3o::LatLng::new(latitude as f64, longitude as f64).unwrap_or_else(|err| {
|
||||
panic!(
|
||||
"Invalid coordinates at row {}: lat={}, lon={}: {}",
|
||||
i, latitude, longitude, err
|
||||
)
|
||||
});
|
||||
u64::from(coord.to_cell(h3_res))
|
||||
})
|
||||
.collect();
|
||||
|
||||
tracing::info!("H3 precomputation complete ({} cells)", cells.len());
|
||||
Ok(cells)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue