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
use std::borrow::Borrow;
use geo::algorithm::simplify::Simplify;
use geo_types::{MultiPolygon, Polygon};
use h3ron::collections::H3CellSet;
use h3ron::iter::change_resolution;
use h3ron::{H3Cell, ToLinkedPolygons};
use crate::error::Error;
pub trait CoveredArea {
type Error;
fn covered_area(&self, reduce_resolution_by: u8) -> Result<MultiPolygon<f64>, Self::Error>;
}
pub fn cells_covered_area<I>(
cell_iter: I,
cell_iter_resolution: u8,
reduce_resolution_by: u8,
) -> Result<MultiPolygon<f64>, Error>
where
I: IntoIterator,
I::Item: Borrow<H3Cell>,
{
let t_res = cell_iter_resolution.saturating_sub(reduce_resolution_by);
let mut cells =
change_resolution(cell_iter.into_iter(), t_res).collect::<Result<H3CellSet, _>>()?;
let cell_vec: Vec<_> = cells.drain().collect();
let mp = MultiPolygon::from(
cell_vec
.to_linked_polygons(true)?
.drain(..)
.map(|p| Polygon::new(p.exterior().simplify(&0.000001), vec![]))
.collect::<Vec<_>>(),
);
Ok(mp)
}