diff --git a/.gitignore b/.gitignore index 8eb581d..5da5dc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target /Cargo.lock /.idea +/venv \ No newline at end of file diff --git a/CHANGES.md b/CHANGES.md index 716b31c..5999440 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/src/lib.rs b/src/lib.rs index cda1422..226b249 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 //! @@ -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(); //! @@ -39,7 +39,7 @@ //! "#, None, None).unwrap(); //! //! // create an instance of the class and extract the geometry -//! py.eval(r#"Something()"#, None, None)?.extract::() +//! py.eval(r#"Something()"#, None, None)?.extract::() //! }).unwrap(); //! assert_eq!(geom.0, Geometry::Point(Point::new(5.0_f64, 3.0_f64))); //! ``` @@ -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(); //! @@ -68,9 +68,9 @@ //! }); //! ``` -pub mod datatypes; pub mod from_py; pub mod to_py; +pub mod wrappers; #[cfg(feature = "wkb")] pub mod wkb; @@ -100,4 +100,4 @@ impl> + ExtractFromPyFloat + ExtractFromPyInt + W impl> + ExtractFromPyFloat + ExtractFromPyInt> PyCoordNum for T {} #[cfg(feature = "f64")] -pub use crate::datatypes::f64::GeoInterface; +pub use crate::wrappers::f64::GeometryInterface; diff --git a/src/wkb.rs b/src/wkb.rs index de24310..88fb95f 100644 --- a/src/wkb.rs +++ b/src/wkb.rs @@ -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}; @@ -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(); diff --git a/src/datatypes.rs b/src/wrappers.rs similarity index 82% rename from src/datatypes.rs rename to src/wrappers.rs index 4441aec..6b59c44 100644 --- a/src/datatypes.rs +++ b/src/wrappers.rs @@ -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) @@ -27,13 +27,13 @@ macro_rules! dt_mod { } } - impl<'source> FromPyObject<'source> for GeoInterface { + impl<'source> FromPyObject<'source> for GeometryInterface { fn extract(ob: &'source PyAny) -> PyResult { - Ok(GeoInterface(ob.as_geometry()?)) + Ok(GeometryInterface(ob.as_geometry()?)) } } - impl From> for GeoInterface { + impl From> for GeometryInterface { fn from(geom: geo_types::Geometry<$coord_type>) -> Self { Self(geom) } @@ -41,9 +41,9 @@ macro_rules! dt_mod { 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)) } } }; @@ -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 for geo_types::Geometry<$coord_type> { - fn from(gi: GeoInterface) -> Self { - gi.0 + impl From for geo_types::Geometry<$coord_type> { + fn from(gw: GeometryInterface) -> Self { + gw.0 } } }