Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled non-consuming fallible conversion from GDAL to geo-types Geometry #295

Merged
merged 6 commits into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@

- <https://github.com/georust/gdal/pull/284>

- Added `Geometry::to_geo` method for GDAL to geo-types Geometry conversions.

- <https://github.com/georust/gdal/pull/295>

- Add `Rasterband::set_scale` and `Rasterband::set_offset` methods

- <https://github.com/georust/gdal/pull/294>
Expand Down
11 changes: 9 additions & 2 deletions src/vector/gdal_to_geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use gdal_sys::{self, OGRwkbGeometryType};
use crate::errors::GdalError;
use crate::vector::Geometry;

impl TryFrom<Geometry> for geo_types::Geometry<f64> {
impl TryFrom<&Geometry> for geo_types::Geometry<f64> {
type Error = GdalError;

fn try_from(geo: Geometry) -> Result<geo_types::Geometry<f64>, Self::Error> {
fn try_from(geo: &Geometry) -> Result<geo_types::Geometry<f64>, Self::Error> {
let geometry_type = geo.geometry_type();

let ring = |n: usize| {
Expand Down Expand Up @@ -110,3 +110,10 @@ impl TryFrom<Geometry> for geo_types::Geometry<f64> {
}
}
}

impl TryFrom<Geometry> for geo_types::Geometry<f64> {
type Error = GdalError;
fn try_from(value: Geometry) -> Result<Self, Self::Error> {
TryFrom::<&Geometry>::try_from(&value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TryFrom::<&Geometry>::try_from(&value)
Self::try_from(&value)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is my suggestion somehow wrong?

I'm a bit confused, you 👍ed it, marked it as resolved, but didn't change the code.

Copy link
Contributor Author

@metasim metasim Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lnicola I forgot to push 🤦 . I'm recovering from The Covid, and not only forgot to push, but did the "resolved" in the wrong order. My apologies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, and good luck with your recovery!

}
}
5 changes: 5 additions & 0 deletions src/vector/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ impl Geometry {
gdal_sys::OGR_G_AssignSpatialReference(self.c_geometry(), spatial_ref.to_c_hsrs())
};
}

/// Create a copy of self as a `geo-types` geometry.
pub fn to_geo(&self) -> Result<geo_types::Geometry<f64>> {
self.try_into()
}
}

impl Drop for Geometry {
Expand Down