Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Nov 16, 2024
1 parent 1d0182f commit 0a43ff0
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 40 deletions.
13 changes: 8 additions & 5 deletions rust/geoarrow/src/io/geos/array/geometrycollection.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
use crate::array::{GeometryCollectionArray, GeometryCollectionBuilder};
use crate::datatypes::Dimension;
use crate::error::GeoArrowError;
use crate::io::geos::scalar::GEOSGeometryCollection;

impl TryFrom<Vec<geos::Geometry>> for GeometryCollectionBuilder {
impl TryFrom<(Vec<geos::Geometry>, Dimension)> for GeometryCollectionBuilder {
type Error = GeoArrowError;

fn try_from(value: Vec<geos::Geometry>) -> std::result::Result<Self, Self::Error> {
fn try_from(
(value, dim): (Vec<geos::Geometry>, Dimension),
) -> std::result::Result<Self, Self::Error> {
let geoms: Vec<GEOSGeometryCollection> = value
.into_iter()
.map(GEOSGeometryCollection::new_unchecked)
.collect();
Self::from_geometry_collections(&geoms, Default::default(), Default::default(), false)
Self::from_geometry_collections(&geoms, dim, Default::default(), Default::default(), false)
}
}

impl TryFrom<Vec<geos::Geometry>> for GeometryCollectionArray {
impl TryFrom<(Vec<geos::Geometry>, Dimension)> for GeometryCollectionArray {
type Error = GeoArrowError;

fn try_from(value: Vec<geos::Geometry>) -> std::result::Result<Self, Self::Error> {
fn try_from(value: (Vec<geos::Geometry>, Dimension)) -> std::result::Result<Self, Self::Error> {
let mutable_arr: GeometryCollectionBuilder = value.try_into()?;
Ok(mutable_arr.into())
}
Expand Down
11 changes: 6 additions & 5 deletions rust/geoarrow/src/io/geos/array/linestring.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use crate::array::{LineStringArray, LineStringBuilder};
use crate::datatypes::Dimension;
use crate::error::Result;
use crate::io::geos::scalar::GEOSLineString;

impl LineStringBuilder {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
// TODO: don't use new_unchecked
let geos_objects: Vec<Option<GEOSLineString>> = value
.into_iter()
.map(|geom| geom.map(GEOSLineString::new_unchecked))
.collect();
Ok(geos_objects.into())
Ok((geos_objects, dim).into())
}
}

impl LineStringArray {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
let mutable_arr = LineStringBuilder::from_geos(value)?;
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
let mutable_arr = LineStringBuilder::from_geos(value, dim)?;
Ok(mutable_arr.into())
}
}
Expand All @@ -34,7 +35,7 @@ mod test {
.iter()
.map(|opt_x| opt_x.map(|x| x.to_geos().unwrap()))
.collect();
let round_trip = LineStringArray::from_geos(geos_geoms).unwrap();
let round_trip = LineStringArray::from_geos(geos_geoms, Dimension::XY).unwrap();
assert_eq!(arr, round_trip);
}
}
13 changes: 8 additions & 5 deletions rust/geoarrow/src/io/geos/array/mixed.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use crate::array::{MixedGeometryArray, MixedGeometryBuilder};
use crate::datatypes::Dimension;
use crate::error::GeoArrowError;
use crate::io::geos::scalar::GEOSGeometry;

impl TryFrom<Vec<geos::Geometry>> for MixedGeometryBuilder {
impl TryFrom<(Vec<geos::Geometry>, Dimension)> for MixedGeometryBuilder {
type Error = GeoArrowError;

fn try_from(value: Vec<geos::Geometry>) -> std::result::Result<Self, Self::Error> {
fn try_from(
(value, dim): (Vec<geos::Geometry>, Dimension),
) -> std::result::Result<Self, Self::Error> {
let geoms: Vec<GEOSGeometry> = value.into_iter().map(GEOSGeometry::new).collect();
Self::from_geometries(&geoms, Default::default(), Default::default(), false)
Self::from_geometries(&geoms, dim, Default::default(), Default::default(), false)
}
}

impl TryFrom<Vec<geos::Geometry>> for MixedGeometryArray {
impl TryFrom<(Vec<geos::Geometry>, Dimension)> for MixedGeometryArray {
type Error = GeoArrowError;

fn try_from(value: Vec<geos::Geometry>) -> std::result::Result<Self, Self::Error> {
fn try_from(value: (Vec<geos::Geometry>, Dimension)) -> std::result::Result<Self, Self::Error> {
let mutable_arr: MixedGeometryBuilder = value.try_into()?;
Ok(mutable_arr.into())
}
Expand Down
11 changes: 6 additions & 5 deletions rust/geoarrow/src/io/geos/array/multilinestring.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use crate::array::{MultiLineStringArray, MultiLineStringBuilder};
use crate::datatypes::Dimension;
use crate::error::Result;
use crate::io::geos::scalar::GEOSMultiLineString;

impl MultiLineStringBuilder {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
// TODO: don't use new_unchecked
let geos_objects: Vec<Option<GEOSMultiLineString>> = value
.into_iter()
.map(|geom| geom.map(GEOSMultiLineString::new_unchecked))
.collect();
Ok(geos_objects.into())
Ok((geos_objects, dim).into())
}
}

impl MultiLineStringArray {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
let mutable_arr = MultiLineStringBuilder::from_geos(value)?;
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
let mutable_arr = MultiLineStringBuilder::from_geos(value, dim)?;
Ok(mutable_arr.into())
}
}
Expand All @@ -34,7 +35,7 @@ mod test {
.iter()
.map(|opt_x| opt_x.map(|x| x.to_geos().unwrap()))
.collect();
let round_trip = MultiLineStringArray::<2>::from_geos(geos_geoms).unwrap();
let round_trip = MultiLineStringArray::from_geos(geos_geoms, Dimension::XY).unwrap();
assert_eq!(arr, round_trip);
}
}
11 changes: 6 additions & 5 deletions rust/geoarrow/src/io/geos/array/multipoint.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use crate::array::{MultiPointArray, MultiPointBuilder};
use crate::datatypes::Dimension;
use crate::error::Result;
use crate::io::geos::scalar::GEOSMultiPoint;

impl MultiPointBuilder {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
// TODO: don't use new_unchecked
let geos_objects: Vec<Option<GEOSMultiPoint>> = value
.into_iter()
.map(|geom| geom.map(GEOSMultiPoint::new_unchecked))
.collect();
Ok(geos_objects.into())
Ok((geos_objects, dim).into())
}
}

impl MultiPointArray {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
let mutable_arr = MultiPointBuilder::from_geos(value)?;
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
let mutable_arr = MultiPointBuilder::from_geos(value, dim)?;
Ok(mutable_arr.into())
}
}
Expand All @@ -34,7 +35,7 @@ mod test {
.iter()
.map(|opt_x| opt_x.map(|x| x.to_geos().unwrap()))
.collect();
let round_trip = MultiPointArray::<2>::from_geos(geos_geoms).unwrap();
let round_trip = MultiPointArray::from_geos(geos_geoms, Dimension::XY).unwrap();
assert_eq!(arr, round_trip);
}
}
11 changes: 6 additions & 5 deletions rust/geoarrow/src/io/geos/array/multipolygon.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use crate::array::{MultiPolygonArray, MultiPolygonBuilder};
use crate::datatypes::Dimension;
use crate::error::Result;
use crate::io::geos::scalar::GEOSMultiPolygon;

impl MultiPolygonBuilder {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
// TODO: don't use new_unchecked
let geos_objects: Vec<Option<GEOSMultiPolygon>> = value
.into_iter()
.map(|geom| geom.map(GEOSMultiPolygon::new_unchecked))
.collect();
Ok(geos_objects.into())
Ok((geos_objects, dim).into())
}
}

impl MultiPolygonArray {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
let mutable_arr = MultiPolygonBuilder::from_geos(value)?;
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
let mutable_arr = MultiPolygonBuilder::from_geos(value, dim)?;
Ok(mutable_arr.into())
}
}
Expand All @@ -34,7 +35,7 @@ mod test {
.iter()
.map(|opt_x| opt_x.map(|x| x.to_geos().unwrap()))
.collect();
let round_trip = MultiPolygonArray::<2>::from_geos(geos_geoms).unwrap();
let round_trip = MultiPolygonArray::from_geos(geos_geoms, Dimension::XY).unwrap();
assert_eq!(arr, round_trip);
}
}
11 changes: 6 additions & 5 deletions rust/geoarrow/src/io/geos/array/point.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use crate::array::{PointArray, PointBuilder};
use crate::datatypes::Dimension;
use crate::error::Result;
use crate::io::geos::scalar::GEOSPoint;

impl PointBuilder {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
// TODO: don't use new_unchecked
let geos_linestring_objects: Vec<Option<GEOSPoint>> = value
.into_iter()
.map(|geom| geom.map(GEOSPoint::new_unchecked))
.collect();
Ok(geos_linestring_objects.into())
Ok((geos_linestring_objects, dim).into())
}
}

impl PointArray {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
let mutable_arr = PointBuilder::from_geos(value)?;
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
let mutable_arr = PointBuilder::from_geos(value, dim)?;
Ok(mutable_arr.into())
}
}
Expand All @@ -33,7 +34,7 @@ mod test {
.iter()
.map(|opt_x| opt_x.map(|x| x.to_geos().unwrap()))
.collect();
let round_trip = PointArray::<2>::from_geos(geos_geoms).unwrap();
let round_trip = PointArray::from_geos(geos_geoms, Dimension::XY).unwrap();
assert_eq!(arr, round_trip);
}
}
11 changes: 6 additions & 5 deletions rust/geoarrow/src/io/geos/array/polygon.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
use crate::array::{PolygonArray, PolygonBuilder};
use crate::datatypes::Dimension;
use crate::error::Result;
use crate::io::geos::scalar::GEOSPolygon;

impl PolygonBuilder {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
// TODO: don't use new_unchecked
let geos_objects: Vec<Option<GEOSPolygon>> = value
.into_iter()
.map(|geom| geom.map(GEOSPolygon::new_unchecked))
.collect();

Ok(geos_objects.into())
Ok((geos_objects, dim).into())
}
}

impl PolygonArray {
pub fn from_geos(value: Vec<Option<geos::Geometry>>) -> Result<Self> {
let mutable_arr = PolygonBuilder::from_geos(value)?;
pub fn from_geos(value: Vec<Option<geos::Geometry>>, dim: Dimension) -> Result<Self> {
let mutable_arr = PolygonBuilder::from_geos(value, dim)?;
Ok(mutable_arr.into())
}
}
Expand All @@ -35,7 +36,7 @@ mod test {
.iter()
.map(|opt_x| opt_x.map(|x| x.to_geos().unwrap()))
.collect();
let round_trip = PolygonArray::<2>::from_geos(geos_geoms).unwrap();
let round_trip = PolygonArray::from_geos(geos_geoms, Dimension::XY).unwrap();
assert_eq!(arr, round_trip);
}
}

0 comments on commit 0a43ff0

Please sign in to comment.