Skip to content

Commit

Permalink
Merge pull request #53 from nmandery/rasterh3-0.8
Browse files Browse the repository at this point in the history
upgrade to rasterh3 0.8
  • Loading branch information
nmandery authored Jun 27, 2024
2 parents 7f9d548 + d94b513 commit 5e140a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion h3ronpy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ numpy = "0.21"
ordered-float = ">=2.0.1"
py_geo_interface = { version = "0.8", features = ["f64", "wkb"] }
pyo3 = { version = "0.21", features = ["extension-module", "abi3", "abi3-py38"] }
rasterh3 = { version = "^0.7", features = ["rayon"] }
rasterh3 = { version = "^0.8", features = ["rayon"] }
rayon = { workspace = true }
19 changes: 10 additions & 9 deletions h3ronpy/src/raster.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use geo_types::Coord;
use geo_types::Point;
use std::hash::Hash;
use std::iter::repeat;
use std::str::FromStr;
Expand All @@ -8,6 +8,7 @@ use arrow::array::{
UInt32Array, UInt64Array, UInt8Array,
};
use arrow::pyarrow::IntoPyArrow;
use geo::{AffineOps, AffineTransform};
use h3arrow::array::CellIndexArray;
use h3arrow::export::h3o::{CellIndex, Resolution};
use ndarray::ArrayView2;
Expand Down Expand Up @@ -41,21 +42,21 @@ impl FromStr for AxisOrder {
}

fn sanitycheck_wgs84_bounds(
transform: &rasterh3::Transform,
transform: &AffineTransform<f64>,
axis_order: &rasterh3::AxisOrder,
shape: &(usize, usize),
) -> PyResult<()> {
let mn = transform * Coord::from((0.0, 0.0));
let mx = transform
* match axis_order {
rasterh3::AxisOrder::XY => Coord::from((shape.0 as f64, shape.1 as f64)),
rasterh3::AxisOrder::YX => Coord::from((shape.1 as f64, shape.0 as f64)),
};
let mn = Point::from((0.0, 0.0)).affine_transform(transform);
let mx = match axis_order {
rasterh3::AxisOrder::XY => Point::from((shape.0 as f64, shape.1 as f64)),
rasterh3::AxisOrder::YX => Point::from((shape.1 as f64, shape.0 as f64)),
}
.affine_transform(transform);

// note: coordinates itself are not validated as multiple rotations around an axis are
// still perfectly valid.

if mx.x - mn.x > 361.0 || mx.y - mn.y > 181.0 {
if mx.x() - mn.x() > 361.0 || mx.y() - mn.y() > 181.0 {
Err(PyValueError::new_err(
"Input array spans significantly more than the bounds of WGS84 - input needs to be in WGS84 projection with lat/lon coordinates",
))
Expand Down
10 changes: 6 additions & 4 deletions h3ronpy/src/transform.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use geo::AffineTransform;
use pyo3::basic::CompareOp;
use pyo3::exceptions::PyNotImplementedError;
use pyo3::prelude::*;
use rasterh3::transform::{from_gdal, from_rasterio};

/// affine geotransform
#[pyclass]
#[derive(Clone)]
pub struct Transform {
pub(crate) inner: rasterh3::Transform,
pub(crate) inner: AffineTransform<f64>,
}

#[pymethods]
Expand All @@ -15,23 +17,23 @@ impl Transform {
#[new]
pub fn new(a: f64, b: f64, c: f64, d: f64, e: f64, f: f64) -> Self {
Self {
inner: rasterh3::Transform::new(a, b, c, d, e, f),
inner: AffineTransform::new(a, b, c, d, e, f),
}
}

/// construct a Transform from a six-values array as used by GDAL
#[staticmethod]
pub fn from_gdal(gdal_transform: [f64; 6]) -> Self {
Transform {
inner: rasterh3::Transform::from_gdal(&gdal_transform),
inner: from_gdal(&gdal_transform),
}
}

/// construct a Transform from a six-values array as used by rasterio
#[staticmethod]
pub fn from_rasterio(rio_transform: [f64; 6]) -> Self {
Transform {
inner: rasterh3::Transform::from_rasterio(&rio_transform),
inner: from_rasterio(&rio_transform),
}
}

Expand Down

0 comments on commit 5e140a7

Please sign in to comment.