Skip to content

Commit 341f937

Browse files
authored
Allow null value in bbox property (#252)
1 parent 5532d2d commit 341f937

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
`quick_collection` for conventional naming and simpler docs.
1515
* <https://github.com/georust/geojson/pulls/214>
1616
* Added `GeoJson::to_string_pretty` as convenience wrappers around the same `serde_json` methods.
17+
* The `bbox` property of a `Feature` can now be `null` (returning `None`) when parsing GeoJSON strings in order to facilitate easier processing of GeoJSON "in the wild" (e.g. Copernicus STAC GeoJSON). [The spec](https://datatracker.ietf.org/doc/html/rfc7946#section-5) does not allow this, but implementations appear to disagree.
18+
* <https://github.com/georust/geojson/pull/252>
1719

1820
## 0.24.1
1921

src/feature.rs

+16
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,22 @@ mod tests {
307307
)
308308
}
309309

310+
#[test]
311+
fn null_bbox() {
312+
let geojson_str = r#"{
313+
"geometry": null,
314+
"bbox": null,
315+
"properties":{},
316+
"type":"Feature"
317+
}"#;
318+
let geojson = geojson_str.parse::<GeoJson>().unwrap();
319+
let feature = match geojson {
320+
GeoJson::Feature(feature) => feature,
321+
_ => unimplemented!(),
322+
};
323+
assert!(feature.bbox.is_none());
324+
}
325+
310326
#[test]
311327
fn test_display_feature() {
312328
let f = feature().to_string();

src/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ pub fn get_coords_value(object: &mut JsonObject) -> Result<JsonValue> {
7878
/// Used by FeatureCollection, Feature, Geometry
7979
pub fn get_bbox(object: &mut JsonObject) -> Result<Option<Bbox>> {
8080
let bbox_json = match object.remove("bbox") {
81+
Some(JsonValue::Null) | None => return Ok(None),
8182
Some(b) => b,
82-
None => return Ok(None),
8383
};
8484
let bbox_array = match bbox_json {
8585
JsonValue::Array(a) => a,

0 commit comments

Comments
 (0)