georust / proj

Rust bindings for the latest stable release of PROJ
https://docs.rs/proj
Apache License 2.0
137 stars 45 forks source link

Add the possibility to convert all the types from geo-types #101

Closed x4d3 closed 2 years ago

x4d3 commented 2 years ago

It would be great if we could convert/project all the geo-types directly, internaly usingconvert_array (when the feature is eanbled)

For example something like

impl Proj {
    pub fn convert_line_string<'a, T>(&self, line_string: &'a mut geo_types::LineString<T>) -> Result<&'a mut geo_types::LineString<T>, ProjError>
        where
            T: crate::proj::CoordinateType,
    {
        self.convert_array(&mut line_string.0)?;
        Ok(line_string)
    }

    pub fn convert_polygon<T>(&self, polygon: &geo_types::Polygon<T>) -> Result<geo_types::Polygon<T>, ProjError>
        where
            T: crate::proj::CoordinateType,
    {
        let mut exterior = polygon.exterior().clone();
        let mut interiors = polygon.interiors().clone();
        self.convert_line_string(&mut exterior)?;
        for interior in interiors{
            self.convert_line_string(&mut interior.clone())?;
        }
        Ok(geo_types::Polygon::new(exterior, interiors.to_vec()))
    }
}