Closed profil closed 1 year ago
I changed the test and now it fails. This is due to that the GeoWriter processor is "overwritten" for each iteration of ShapeIterator.. edit: I see it is the same way when reading a geojson FeatureCollection into GeoWriter. How is this supposed to work?
GeoWriter does only keep one feature geometry, that's normal. But since we can't access the geometry when iterating, this PR is still not enough for doing something with each geometry.
This test works:
let mut geo = GeoWriter::new();
let cnt = reader.iter_features(&mut geo)?.count();
assert_eq!(cnt, 10);
- let first_poly = Polygon::new(LineString::from(vec![
- (479819.8437 ,4765180.5),
- (479690.187 ,4765259.5),
- (479647.0 ,4765369.5),
- (479730.37 ,4765400.5),
- (480039.0312 ,4765539.5),
- (480035.3437 ,4765558.5),
- (480159.7812 ,4765610.5),
- (480202.2812 ,4765482.0),
- (480365.0 ,4765015.5),
- (480389.687 ,4764950.0),
- (480133.9687 ,4764856.5),
- (480080.2812 ,4764979.5),
- (480082.9687 ,4765049.5),
- (480088.812 ,4765139.5),
- (480059.9062 ,4765239.5),
- (480019.7187 ,4765319.5),
- (479980.2187 ,4765409.5),
- (479909.87 ,4765370.0),
- (479859.87 ,4765270.0),
- (479819.8437 ,4765180.5)
- ]), vec![]);
- let last_poly = Polygon::new(LineString::from(vec![
- (479750.6875, 4764702.0),
- (479658.59375, 4764670.0),
- (479640.09375, 4764721.0),
- (479735.90625, 4764752.0),
- (479750.6875, 4764702.0)
- ]), vec![]);
+ let first_poly = Polygon::new(
+ LineString::from(vec![
+ (479819.84375, 4765180.5),
+ (479690.1875, 4765259.5),
+ (479647.0, 4765369.5),
+ (479730.375, 4765400.5),
+ (480039.03125, 4765539.5),
+ (480035.34375, 4765558.5),
+ (480159.78125, 4765610.5),
+ (480202.28125, 4765482.0),
+ (480365.0, 4765015.5),
+ (480389.6875, 4764950.0),
+ (480133.96875, 4764856.5),
+ (480080.28125, 4764979.5),
+ (480082.96875, 4765049.5),
+ (480088.8125, 4765139.5),
+ (480059.90625, 4765239.5),
+ (480019.71875, 4765319.5),
+ (479980.21875, 4765409.5),
+ (479909.875, 4765370.0),
+ (479859.875, 4765270.0),
+ (479819.84375, 4765180.5),
+ ]),
+ vec![],
+ );
+ let last_poly = Polygon::new(
+ LineString::from(vec![
+ (479750.6875, 4764702.0),
+ (479658.59375, 4764670.0),
+ (479640.09375, 4764721.0),
+ (479735.90625, 4764752.0),
+ (479750.6875, 4764702.0),
+ ]),
+ vec![],
+ );
if let Geometry::MultiPolygon(poly) = geo.geometry() {
+ assert_eq!(*poly.iter().nth(0).unwrap(), last_poly);
+ } else {
+ assert!(false);
+ }
+
+ let reader = geozero_shp::Reader::from_path("./tests/data/poly.shp")?;
+ let mut geo = GeoWriter::new();
+ let mut iter = reader.iter_geometries(&mut geo);
+ iter.next();
+ if let Geometry::MultiPolygon(poly) = &geo.geometry() {
assert_eq!(*poly.iter().nth(0).unwrap(), first_poly);
- assert_eq!(*poly.iter().last().unwrap(), last_poly);
} else {
assert!(false);
}
+ // Does not compile:
+ // iter.last();
+ // if let Geometry::MultiPolygon(poly) = &geo.geometry() {
+ // assert_eq!(*poly.iter().nth(0).unwrap(), last_poly);
+ // } else {
+ // assert!(false);
+ // }
Implementing GeometryCollections
for geo_types
wouldn't help, because collections are also per feature.
I think, we have to implement FallibleStreamingIterator
like for FlatGeobuf.
This can be closed in favor of https://github.com/georust/geozero/pull/96
There is some code commented out in the end of reader.rs, maybe that could be used now as well?