You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would be useful to have in geo helper functions to convert arbitrary objects that implement geo-traits to geo objects. That is, vendoring this code from geoarrow-rs somehow.
use geo::CoordNum;use geo_traits::{CoordTrait,GeometryCollectionTrait,GeometryTrait,GeometryType,LineStringTrait,MultiLineStringTrait,MultiPointTrait,MultiPolygonTrait,PointTrait,PolygonTrait,RectTrait,};/// Convert any coordinate to a [`geo::Coord`].////// Only the first two dimensions will be kept.pubfncoord_to_geo<T:CoordNum>(coord:&implCoordTrait<T = T>) -> geo::Coord<T>{
geo::Coord{x: coord.x(),y: coord.y(),}}/// Convert any Point to a [`geo::Point`].////// Only the first two dimensions will be kept.pubfnpoint_to_geo<T:CoordNum>(point:&implPointTrait<T = T>) -> geo::Point<T>{ifletSome(coord) = point.coord(){
geo::Point(coord_to_geo(&coord))}else{todo!("converting empty point to geo not implemented")}}/// Convert any LineString to a [`geo::LineString`].////// Only the first two dimensions will be kept.pubfnline_string_to_geo<T:CoordNum>(line_string:&implLineStringTrait<T = T>,) -> geo::LineString<T>{
geo::LineString::new(
line_string
.coords().map(|coord| coord_to_geo(&coord)).collect(),)}/// Convert any Polygon to a [`geo::Polygon`].////// Only the first two dimensions will be kept.pubfnpolygon_to_geo<T:CoordNum>(polygon:&implPolygonTrait<T = T>) -> geo::Polygon<T>{let exterior = line_string_to_geo(&polygon.exterior().unwrap());let interiors = polygon
.interiors().map(|interior| line_string_to_geo(&interior)).collect();
geo::Polygon::new(exterior, interiors)}/// Convert any MultiPoint to a [`geo::MultiPoint`].////// Only the first two dimensions will be kept.pubfnmulti_point_to_geo<T:CoordNum>(multi_point:&implMultiPointTrait<T = T>,) -> geo::MultiPoint<T>{
geo::MultiPoint::new(
multi_point
.points().map(|point| point_to_geo(&point)).collect(),)}/// Convert any MultiLineString to a [`geo::MultiLineString`].////// Only the first two dimensions will be kept.pubfnmulti_line_string_to_geo<T:CoordNum>(multi_line_string:&implMultiLineStringTrait<T = T>,) -> geo::MultiLineString<T>{
geo::MultiLineString::new(
multi_line_string
.line_strings().map(|line| line_string_to_geo(&line)).collect(),)}/// Convert any MultiPolygon to a [`geo::MultiPolygon`].////// Only the first two dimensions will be kept.pubfnmulti_polygon_to_geo<T:CoordNum>(multi_polygon:&implMultiPolygonTrait<T = T>,) -> geo::MultiPolygon<T>{
geo::MultiPolygon::new(
multi_polygon
.polygons().map(|polygon| polygon_to_geo(&polygon)).collect(),)}/// Convert any Rect to a [`geo::Rect`].////// Only the first two dimensions will be kept.pubfnrect_to_geo<T:CoordNum>(rect:&implRectTrait<T = T>) -> geo::Rect<T>{let c1 = coord_to_geo(&rect.min());let c2 = coord_to_geo(&rect.max());
geo::Rect::new(c1, c2)}/// Convert any Geometry to a [`geo::Geometry`].////// Only the first two dimensions will be kept.pubfngeometry_to_geo<T:CoordNum>(geometry:&implGeometryTrait<T = T>) -> geo::Geometry<T>{useGeometryType::*;match geometry.as_type(){Point(geom) => geo::Geometry::Point(point_to_geo(geom)),LineString(geom) => geo::Geometry::LineString(line_string_to_geo(geom)),Polygon(geom) => geo::Geometry::Polygon(polygon_to_geo(geom)),MultiPoint(geom) => geo::Geometry::MultiPoint(multi_point_to_geo(geom)),MultiLineString(geom) => geo::Geometry::MultiLineString(multi_line_string_to_geo(geom)),MultiPolygon(geom) => geo::Geometry::MultiPolygon(multi_polygon_to_geo(geom)),GeometryCollection(geom) => {
geo::Geometry::GeometryCollection(geometry_collection_to_geo(geom))}Rect(geom) => geo::Geometry::Rect(rect_to_geo(geom)),Line(_) | Triangle(_) => todo!(),}}/// Convert any GeometryCollection to a [`geo::GeometryCollection`].////// Only the first two dimensions will be kept.pubfngeometry_collection_to_geo<T:CoordNum>(geometry_collection:&implGeometryCollectionTrait<T = T>,) -> geo::GeometryCollection<T>{
geo::GeometryCollection::new_from(
geometry_collection
.geometries().map(|geometry| geometry_to_geo(&geometry)).collect(),)}
The text was updated successfully, but these errors were encountered:
I think it would be useful to have in
geo
helper functions to convert arbitrary objects that implement geo-traits togeo
objects. That is, vendoring this code from geoarrow-rs somehow.The text was updated successfully, but these errors were encountered: