georust / geojson

Library for serializing the GeoJSON vector GIS file format
https://crates.io/crates/geojson
Apache License 2.0
280 stars 60 forks source link

Make FeatureIterator more robust #207

Open michaelkirk opened 2 years ago

michaelkirk commented 2 years ago

FeatureIterator is intended to be an efficient way to iterate through individual Features in a FeatureCollection without ever having to parse the entire FeatureCollection into memory at once.

To do so, it seeks through the input stream until it finds the features array, and then starts parsing the individual features one by one.

Currently however, the way we seek to the "start of the features" array is looking for any occurrence of [. This would fail with a document like:

{ 
  "type": "FeatureCollection",
  "bbox": [100.0, 0.0, 105.0, 1.0],
  "features": [
    ...
  ] 
}

or more complicated ones like this:

{ 
  "type": "FeatureCollection"
  "some_foreign_member": { "a": [1], "b" : { "foo": [2, 3] } },
  "features": [
    ...
  ],
}

We should update FeatureIterator to be more robust in how it parses a FeatureCollection.