georust / geozero

Zero-Copy reading and writing of geospatial data.
Apache License 2.0
321 stars 30 forks source link

geojson lines writer #193

Closed kylebarron closed 4 months ago

kylebarron commented 5 months ago

This works for features but not geometries because it's hard to know when to insert the \n to end the line.

kylebarron commented 4 months ago

It turns out that passing idx instead of 0 fails the test for the feature, but it also doesn't pass the geometry test. For example, when logging to stdout I see:

failures:

---- geojson::geojson_line_writer::tests::good_geometries stdout ----
a: {"type": "Point", "coordinates": [1.1,1.2]}
b: { "type": "Point", "coordinates": [1.1, 1.2] }
a: ,{"type": "Point", "coordinates": [2.1,2.2]}
b: { "type": "Point", "coordinates": [2.1, 2.2] }
thread 'geojson::geojson_line_writer::tests::good_geometries' panicked at geozero/src/geojson/geojson_line_writer.rs:227:73:
called `Result::unwrap()` on an `Err` value: Error("expected value", line: 1, column: 1)

Because the idx passed into begin_point is >0, a comma gets added here https://github.com/georust/geozero/blob/458f38ccca37f0ac4341593491017220b805ed51/geozero/src/geojson/geojson_writer.rs#L22-L27

kylebarron commented 4 months ago

I found a workaround and added a comment. Let me know if that solution is ok. Also, I don't have merge access.