Open jose-lpa opened 1 year ago
I'm going to move your issue to the geozero repository, since it seems to be about geozero.
It is indeed about geozero-shp. I had multiple tabs opened with Rust georust
repos and I opened the issue in the wrong one :man_facepalming: Apologies for the mistake, and thank you very much for moving the issue here @michaelkirk
There is a test for converting Shp to GeoJSON: https://github.com/georust/geozero/blob/f8bcaaabc6bd6b596957b74f84aef3b2518ffee3/geozero-shp/tests/reader.rs#L49
Hey, are there any updates on this? I created a new project, copied the test you mentioned in there and renamed it to fn main
. It results in the same error message.
However, the tests are passing and if I use the test as example
in the geozero-shp
crate it also works.
To reproduce, create a new binary with:
Cargo.toml
[package]
name = "geozero-test"
version = "0.1.0"
edition = "2021"
[dependencies]
geozero-shp = "0.4"
geozero = "0.11"
src/main.rs
use geozero::geojson::GeoJsonWriter;
use std::str::from_utf8;
fn main() -> Result<(), geozero_shp::Error> {
let reader = geozero_shp::Reader::from_path("./tests/data/poly.shp")?;
let mut json: Vec<u8> = Vec::new();
let cnt = reader
.iter_features(&mut GeoJsonWriter::new(&mut json))?
.count();
assert_eq!(cnt, 10);
assert_eq!(
&from_utf8(&json).unwrap()[0..80],
r#"{
"type": "FeatureCollection",
"features": [{"type": "Feature", "properties": {""#
);
assert_eq!(
&from_utf8(&json).unwrap()[json.len()-100..],
"2],[479658.59375,4764670],[479640.09375,4764721],[479735.90625,4764752],[479750.6875,4764702]]]]}}]}"
);
Ok(())
}
Edit: Using Rust 1.74
I just tried it, this is indeed really weird! Debugging... but if anyone has any ideas, please post
Ah, silly me - I think you are copy/pasting test code from a development (unpublished) version. When I added this to cargo.toml, it worked (I have geozero cloned in a parallel dir). I think all this was done by @michaelkirk in https://github.com/georust/geozero/commit/bee32bc983fa8ddd11318743709fee6032a662ac
[patch.crates-io]
geozero = { path = "../../geozero/geozero" }
geozero-shp = { path = "../../geozero/geozero-shp" }
Ah that makes sense, I did not work with patching yet. Thanks for the fast reponse!
Just don't use it for any production code :) Patching is for experiments, and for when you have multiple crates in the same repo that depend on one another, and you need to modify them at the same time.
Ok nice to know. I am now using { path = "" }
instead of the version number until a new release will be uploaded :+1:
Hello, and thank you for this project.
I am trying to do a simple newbie program that, given an ESRI Shapefile as input, it outputs the geometries as GeoJSON.
I have been trying to use the geozero-shp crate, simply following the short example that can be found on its README, without any luck. It seems the example is incorrect, or it might have been outdated by outer changes on its dependencies.
I wrote this program:
and when I run it, it doesn't seem that
GeoJsonWriter
is a valid thing to pass to theprocessor
argument:Is there any documentation or code examples where I can see how this crate is used?
Thank you.