Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to geoarrow 0.3. fixes #56 #59

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/h3arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ spatial_index = ["dep:rstar"]
[dependencies]
ahash = "0.8"
arrow = { workspace = true }
# geoarrow = { package = "geoarrow", version = "0.1.0", optional = true, features = ["geozero"] }
geoarrow = { package = "geoarrow", git = "https://github.com/geoarrow/geoarrow-rs.git", rev = "30c18f7c07432dfb92f9612efa54aec1d9392daf", optional = true, features = ["geozero"] }
geoarrow = { version = "0.3", optional = true, features = ["geozero"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just published 0.4.0-beta.1 if you want to bump all the way up to that. You'll just have to take off the O parameter.

But note there's also now a separation between "native" GeoArrow arrays and "serialized" GeoArrow arrays. WKB is a "serialized" array.

If you get stuck I'm happy to help update this code

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am bit out of the loop on what is happening in the arrow-community. I remember the "native" geoarrow arrays where a bit problematic as there was no way to attach the metadata describing the geometrytype to the array. Is this now possible? Is it feasible to exchange the "native" arrays with other libraries?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's not what I mean. I mean the GeoArrow format has both "Native encoding" and "Serialized encoding" https://geoarrow.org/format.html.

Previously in geoarrow-rs we had a single GeometryArrayTrait that all geoarrow array types implemented, but now we have two:

  • NativeArray, which is implemented by PointArray, LineStringArray, PolygonArray, MultiPointArray, MultiLineStringArray, MultiPolygonArray, MixedGeometryArray, and GeometryCollectionArray.
  • SerializedArray, which is implemented by WKBArray and WKTArray.

I just mean that you'll have to update the code to use these new traits

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, now I got it ;)

BTW: Directly upgrading to geoarrow 0.4.0-beta.1 is not possible for me currently. This requires at least he release of rust-numpy built ontop of pyo3 0.22

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also hoping that will come out very soon. PyO3/rust-numpy#442 (comment) and PyO3/rust-numpy#435 have been merged, which is very promising

geo-types = { workspace = true }
geo = { workspace = true }
geozero = { version = "^0.13", default-features = false, features = ["with-geo", "with-wkb"], optional = true }
Expand Down
12 changes: 6 additions & 6 deletions crates/h3arrow/src/array/from_geoarrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ macro_rules! impl_to_cells {
};
}

impl_to_cells!(geoarrow::array::LineStringArray<O>, O);
impl_to_cells!(geoarrow::array::MultiLineStringArray<O>, O);
impl_to_cells!(geoarrow::array::MultiPointArray<O>, O);
impl_to_cells!(geoarrow::array::MultiPolygonArray<O>, O);
impl_to_cells!(geoarrow::array::PointArray);
impl_to_cells!(geoarrow::array::PolygonArray<O>, O);
impl_to_cells!(geoarrow::array::LineStringArray<O, 2>, O);
impl_to_cells!(geoarrow::array::MultiLineStringArray<O, 2>, O);
impl_to_cells!(geoarrow::array::MultiPointArray<O, 2>, O);
impl_to_cells!(geoarrow::array::MultiPolygonArray<O, 2>, O);
impl_to_cells!(geoarrow::array::PointArray<2>);
impl_to_cells!(geoarrow::array::PolygonArray<O, 2>, O);

impl<O: OffsetSizeTrait> ToCellListArray<O> for WKBArray<O> {
fn to_celllistarray(
Expand Down
16 changes: 9 additions & 7 deletions crates/h3arrow/src/array/to_geoarrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::array::to_geo::{
};
use crate::array::{H3Array, H3IndexArrayValue};
use arrow::array::{Array, OffsetSizeTrait};
use geo::point;
use geo_types::LineString;
use geoarrow::array::{
LineStringArray, PointArray, PolygonArray, WKBArray, WKBBuilder, WKBCapacity,
Expand All @@ -13,7 +14,7 @@ pub trait ToGeoArrowPolygons {
fn to_geoarrow_polygons<O: OffsetSizeTrait>(
&self,
use_degrees: bool,
) -> Result<PolygonArray<O>, Self::Error>;
) -> Result<PolygonArray<O, 2>, Self::Error>;
}

impl<T> ToGeoArrowPolygons for T
Expand All @@ -25,22 +26,22 @@ where
fn to_geoarrow_polygons<O: OffsetSizeTrait>(
&self,
use_degrees: bool,
) -> Result<PolygonArray<O>, Self::Error> {
) -> Result<PolygonArray<O, 2>, Self::Error> {
Ok(self.to_polygons(use_degrees)?.into())
}
}

pub trait ToGeoArrowPoints {
type Error;
fn to_geoarrow_points(&self, use_degrees: bool) -> Result<PointArray, Self::Error>;
fn to_geoarrow_points(&self, use_degrees: bool) -> Result<PointArray<2>, Self::Error>;
}

impl<T> ToGeoArrowPoints for T
where
T: ToPoints,
{
type Error = T::Error;
fn to_geoarrow_points(&self, use_degrees: bool) -> Result<PointArray, Self::Error> {
fn to_geoarrow_points(&self, use_degrees: bool) -> Result<PointArray<2>, Self::Error> {
Ok(self.to_points(use_degrees)?.into())
}
}
Expand All @@ -50,7 +51,7 @@ pub trait ToGeoArrowLineStrings {
fn to_geoarrow_lines<O: OffsetSizeTrait>(
&self,
use_degrees: bool,
) -> Result<LineStringArray<O>, Self::Error>;
) -> Result<LineStringArray<O, 2>, Self::Error>;
}

impl<T> ToGeoArrowLineStrings for T
Expand All @@ -61,7 +62,7 @@ where
fn to_geoarrow_lines<O: OffsetSizeTrait>(
&self,
use_degrees: bool,
) -> Result<LineStringArray<O>, Self::Error> {
) -> Result<LineStringArray<O, 2>, Self::Error> {
Ok(self.to_linestrings(use_degrees)?.into())
}
}
Expand Down Expand Up @@ -197,7 +198,8 @@ where
.is_some()
{
let mut cap = WKBCapacity::new_empty();
cap.add_point(true);
let point = point! {x:0.0f64, y:0.0f64};
cap.add_point(Some(&point));
cap.buffer_capacity()
} else {
0
Expand Down
2 changes: 1 addition & 1 deletion h3ronpy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ ndarray = { version = "0.15", features = ["rayon"] }
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-py39"] }
pyo3 = { version = "^0.21", features = ["extension-module", "abi3", "abi3-py39"] }
rasterh3 = { version = "^0.8", features = ["rayon"] }
rayon = { workspace = true }