Skip to content

Commit

Permalink
rename GeoInterface struct to GeometryInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
nmandery authored Jun 14, 2022
1 parent 42efbea commit c38d9bb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/Cargo.lock
/.idea
/venv
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
## Unreleased

* Support exchanging geometries using Well-Known-Binary format. The `wkb`-property of `shapely`
geometries will be used. Additionally, the `GeoInterface`-type exposed to python will have a `wkb`-property
geometries will be used. Additionally, the `GeometryInterface`-type exposed to python will have a `wkb`-property
itself. This is only supported for the `f64` variant of the `GeoInterface`.
* Rename `GeoInterface` struct to `GeometryInterface` to distinguish the provided geometry support from geo_interface features and featurecollections.

## 0.2.0

Expand Down
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
//!
//! The `__geo_interface__` protocol is implemented by most popular geospatial python modules like `shapely`, `geojson`, `geopandas`, ....
//!
//! The main struct of this crate is [`GeoInterface`]. This the docs there for usage examples.
//! The main struct of this crate is [`GeometryInterface`]. This the docs there for usage examples.
//!
//! ## Features
//!
//! As rust types exposed to python may not have generic type parameters, there are multiple implementations of the `GeoInterface` type based
//! As rust types exposed to python may not have generic type parameters, there are multiple implementations of the `GeometryInterface` type based
//! on different types for the coordinate values. The default is `f64`, other types can be enabled using the `f32`, `u8`, `u16`, `u32`, `u64`,
//! `i8`, `i16`, `i32` and `i64` feature gates. The implementation are then available as `py_geo_interface::datatypes::[datatype]::GeoInterface`.
//! The default and probably most common used `f64`-variant is also available as `py_geo_interface::GeoInterface`.
//! `i8`, `i16`, `i32` and `i64` feature gates. The implementation are then available as `py_geo_interface::wrappers::[datatype]::GeometryInterface`.
//! The default and probably most common used `f64`-variant is also available as `py_geo_interface::GeometryInterface`.
//!
//! The `wkb` feature adds support for exchanging geometries using the Well-Known-Binary format. The `wkb`-property of `shapely`
//! geometries will be used when found. Additionally, the `GeoInterface`-type exposed to python will have a `wkb`-property
//! itself. WKB is only supported for the `f64`-variant of the `GeoInterface`, the feature is disabled per default.
//! geometries will be used when found. Additionally, the `GeometryInterface`-type exposed to python will have a `wkb`-property
//! itself. WKB is only supported for the `f64`-variant of the `GeometryInterface`, the feature is disabled per default.
//!
//! ## Examples
//!
Expand All @@ -23,7 +23,7 @@
//! ```rust
//! use geo_types::{Geometry, Point};
//! use pyo3::{prepare_freethreaded_python, Python};
//! use py_geo_interface::GeoInterface;
//! use py_geo_interface::GeometryInterface;
//!
//! prepare_freethreaded_python();
//!
Expand All @@ -39,7 +39,7 @@
//! "#, None, None).unwrap();
//!
//! // create an instance of the class and extract the geometry
//! py.eval(r#"Something()"#, None, None)?.extract::<GeoInterface>()
//! py.eval(r#"Something()"#, None, None)?.extract::<GeometryInterface>()
//! }).unwrap();
//! assert_eq!(geom.0, Geometry::Point(Point::new(5.0_f64, 3.0_f64)));
//! ```
Expand All @@ -51,13 +51,13 @@
//! use pyo3::{prepare_freethreaded_python, Python};
//! use pyo3::types::{PyDict, PyTuple};
//! use pyo3::IntoPy;
//! use py_geo_interface::GeoInterface;
//! use py_geo_interface::GeometryInterface;
//!
//! prepare_freethreaded_python();
//!
//! Python::with_gil(|py| {
//!
//! let geom: GeoInterface = Point::new(10.6_f64, 23.3_f64).into();
//! let geom: GeometryInterface = Point::new(10.6_f64, 23.3_f64).into();
//! let mut locals = PyDict::new(py);
//! locals.set_item("geom", geom.into_py(py)).unwrap();
//!
Expand All @@ -68,9 +68,9 @@
//! });
//! ```
pub mod datatypes;
pub mod from_py;
pub mod to_py;
pub mod wrappers;

#[cfg(feature = "wkb")]
pub mod wkb;
Expand Down Expand Up @@ -100,4 +100,4 @@ impl<T: CoordNum + IntoPy<Py<PyAny>> + ExtractFromPyFloat + ExtractFromPyInt + W
impl<T: CoordNum + IntoPy<Py<PyAny>> + ExtractFromPyFloat + ExtractFromPyInt> PyCoordNum for T {}

#[cfg(feature = "f64")]
pub use crate::datatypes::f64::GeoInterface;
pub use crate::wrappers::f64::GeometryInterface;
6 changes: 3 additions & 3 deletions src/wkb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl WKBSupport for f64 {
#[cfg(all(test, feature = "f64"))]
mod tests {
use crate::from_py::AsGeometry;
use crate::GeoInterface;
use crate::GeometryInterface;
use geo_types::{Geometry, Point};
use pyo3::types::PyDict;
use pyo3::{prepare_freethreaded_python, IntoPy, Python};
Expand Down Expand Up @@ -121,11 +121,11 @@ class Something:
}

#[test]
fn geointerface_wkb_property() {
fn geometryinterface_wkb_property() {
prepare_freethreaded_python();

Python::with_gil(|py| {
let geom: GeoInterface = Point::new(2.0_f64, 4.0_f64).into();
let geom: GeometryInterface = Point::new(2.0_f64, 4.0_f64).into();
let locals = PyDict::new(py);
locals.set_item("geom", geom.into_py(py)).unwrap();

Expand Down
20 changes: 10 additions & 10 deletions src/datatypes.rs → src/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ macro_rules! dt_mod {
/// Exchanges vector geometries between Rust and Python using [pyo3](https://pyo3.rs) and [Pythons `__geo_interface__` protocol](https://gist.github.com/sgillies/2217756).
#[derive(Debug)]
#[pyclass]
pub struct GeoInterface(pub geo_types::Geometry<$coord_type>);
pub struct GeometryInterface(pub geo_types::Geometry<$coord_type>);

#[pymethods]
impl GeoInterface {
impl GeometryInterface {
#[getter]
fn __geo_interface__<'py>(&self, py: Python<'py>) -> PyResult<&'py PyDict> {
self.0.as_geointerface_pydict(py)
Expand All @@ -27,23 +27,23 @@ macro_rules! dt_mod {
}
}

impl<'source> FromPyObject<'source> for GeoInterface {
impl<'source> FromPyObject<'source> for GeometryInterface {
fn extract(ob: &'source PyAny) -> PyResult<Self> {
Ok(GeoInterface(ob.as_geometry()?))
Ok(GeometryInterface(ob.as_geometry()?))
}
}

impl From<geo_types::Geometry<$coord_type>> for GeoInterface {
impl From<geo_types::Geometry<$coord_type>> for GeometryInterface {
fn from(geom: geo_types::Geometry<$coord_type>) -> Self {
Self(geom)
}
}

macro_rules! geometry_enum_from_impl {
($geom_type:ty, $enum_variant_name:ident) => {
impl From<$geom_type> for GeoInterface {
impl From<$geom_type> for GeometryInterface {
fn from(g: $geom_type) -> Self {
GeoInterface(geo_types::Geometry::$enum_variant_name(g))
GeometryInterface(geo_types::Geometry::$enum_variant_name(g))
}
}
};
Expand All @@ -62,9 +62,9 @@ macro_rules! dt_mod {
geometry_enum_from_impl!(geo_types::Line<$coord_type>, Line);
geometry_enum_from_impl!(geo_types::Triangle<$coord_type>, Triangle);

impl From<GeoInterface> for geo_types::Geometry<$coord_type> {
fn from(gi: GeoInterface) -> Self {
gi.0
impl From<GeometryInterface> for geo_types::Geometry<$coord_type> {
fn from(gw: GeometryInterface) -> Self {
gw.0
}
}
}
Expand Down

0 comments on commit c38d9bb

Please sign in to comment.