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

Could not convert to geojson::Geometry #81

Closed
JorgeMartinezG opened this issue Feb 4, 2021 · 4 comments
Closed

Could not convert to geojson::Geometry #81

JorgeMartinezG opened this issue Feb 4, 2021 · 4 comments

Comments

@JorgeMartinezG
Copy link

First of all, thanks for this library.

I am experimenting an issue converting from geos::Geometry to geojson::Geometry type. It looks like the readme has not been updated since this commit 1614a49 makes use of the std TryFrom trait.

I have this sample code:

    let pt = "POINT(1.0 1.0)";
    let pt = geos::Geometry::new_from_wkt(pt).unwrap();

    let geom: geojson::Geometry = pt.try_into().unwrap();

and the compiler shows this error:

error[E0277]: the trait bound `Value: From<geos::Geometry<'_>>` is not satisfied
  --> src/main.rs:79:38
   |
79 |     let geom: geojson::Geometry = pt.try_into().unwrap();
   |                                      ^^^^^^^^ the trait `From<geos::Geometry<'_>>` is not implemented for `Value`
   |
   = note: required because of the requirements on the impl of `Into<Value>` for `geos::Geometry<'_>`
   = note: required because of the requirements on the impl of `From<geos::Geometry<'_>>` for `geojson::Geometry`
   = note: required because of the requirements on the impl of `Into<geojson::Geometry>` for `geos::Geometry<'_>`
   = note: required because of the requirements on the impl of `TryFrom<geos::Geometry<'_>>` for `geojson::Geometry`
   = note: required because of the requirements on the impl of `TryInto<geojson::Geometry>` for `geos::Geometry<'_>`

I have the geos library with json feature enabled.

[dependencies]
geos = {version = "7.0.0", features = ["json"]}
geojson= {version = "0.20.1"}

Curiously, the code compiles by first doing a conversion to geo_types and then to geojson

    let geotypes_obj: geo_types::Geometry<f64> = pt.try_into().unwrap();
    let geometry = geojson::Geometry::new(geojson::Value::from(&geotypes_obj));

I found here

pub trait TryFrom<T>: Sized {
that the crate has its own TryFrom trait, but I am not sure if it is related.

It looks like the geojson::Geometry type has not implemented the TryFrom crate within to_geojson.rs file.

Let me know your opinion

@frewsxcv
Copy link
Member

frewsxcv commented Feb 4, 2021

Thanks for the bug report! This is likely because of mismatched versions between dependencies. Can you cargo-tree to ensure all your geo-types and geojson dependency versions match?

@JorgeMartinezG
Copy link
Author

@frewsxcv Thank you! Running cargo tree saw a mismatch between geojson (0.20.1) and the geojson crate used in geos (0.19.0). changing the version in Cargo.toml file worked perfectly

@frewsxcv
Copy link
Member

frewsxcv commented Feb 4, 2021

Glad that worked! I created a new issue for tracking the version mismatch: #82

@frewsxcv frewsxcv closed this as completed Feb 4, 2021
@JorgeMartinezG
Copy link
Author

For new users coming into this issue, please check rust-lang/rust#22750

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants