Skip to content

Commit 4531c83

Browse files
Merge pull request #167 from developmentseed/patch/allow-antimeridian-crossing-bbox
allow antimeridian crossing bbox
2 parents b3cf3f9 + 8fcadad commit 4531c83

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

77
Note: Minor version `0.X.0` update might break the API, It's recommended to pin geojson-pydantic to minor version: `geojson-pydantic>=0.6,<0.7`
88

9+
## [1.1.2] - 2024-10-22
10+
11+
* relax `bbox` validation and allow antimeridian crossing bboxes
12+
913
## [1.1.1] - 2024-08-29
1014

1115
* add python 3.12 support
@@ -365,7 +369,10 @@ Although the type file was added in `0.2.0` it wasn't included in the distribute
365369
### Added
366370
- Initial Release
367371

368-
[unreleased]: https://github.com/developmentseed/geojson-pydantic/compare/1.0.2...HEAD
372+
[unreleased]: https://github.com/developmentseed/geojson-pydantic/compare/1.1.2...HEAD
373+
[1.1.2]: https://github.com/developmentseed/geojson-pydantic/compare/1.1.1...1.1.2
374+
[1.1.1]: https://github.com/developmentseed/geojson-pydantic/compare/1.1.0...1.1.1
375+
[1.1.0]: https://github.com/developmentseed/geojson-pydantic/compare/1.0.2...1.1.0
369376
[1.0.2]: https://github.com/developmentseed/geojson-pydantic/compare/1.0.1...1.0.2
370377
[1.0.1]: https://github.com/developmentseed/geojson-pydantic/compare/1.0.0...1.0.1
371378
[1.0.0]: https://github.com/developmentseed/geojson-pydantic/compare/0.6.3...1.0.0

geojson_pydantic/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""pydantic BaseModel for GeoJSON objects."""
22
from __future__ import annotations
33

4+
import warnings
45
from typing import Any, Dict, List, Optional, Set
56

67
from pydantic import BaseModel, SerializationInfo, field_validator, model_serializer
@@ -38,10 +39,15 @@ def validate_bbox(cls, bbox: Optional[BBox]) -> Optional[BBox]:
3839

3940
# Check X
4041
if bbox[0] > bbox[offset]:
41-
errors.append(f"Min X ({bbox[0]}) must be <= Max X ({bbox[offset]}).")
42+
warnings.warn(
43+
f"BBOX crossing the Antimeridian line, Min X ({bbox[0]}) > Max X ({bbox[offset]}).",
44+
UserWarning,
45+
)
46+
4247
# Check Y
4348
if bbox[1] > bbox[1 + offset]:
4449
errors.append(f"Min Y ({bbox[1]}) must be <= Max Y ({bbox[1 + offset]}).")
50+
4551
# If 3D, check Z values.
4652
if offset > 2 and bbox[2] > bbox[2 + offset]:
4753
errors.append(f"Min Z ({bbox[2]}) must be <= Max Z ({bbox[2 + offset]}).")

tests/test_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from geojson_pydantic.base import _GeoJsonBase
77

88
BBOXES = (
9-
(100, 0, 0, 0), # Incorrect Order
109
(0, 100, 0, 0),
1110
(0, 0, 100, 0, 0, 0),
1211
(0, "a", 0, 0), # Invalid Type
@@ -20,6 +19,11 @@ def test_bbox_validation(values: Tuple) -> None:
2019
_GeoJsonBase(bbox=values)
2120

2221

22+
def test_bbox_antimeridian() -> None:
23+
with pytest.warns(UserWarning):
24+
_GeoJsonBase(bbox=(100, 0, 0, 0))
25+
26+
2327
@pytest.mark.parametrize("values", BBOXES)
2428
def test_bbox_validation_subclass(values: Tuple) -> None:
2529
# Ensure validation is happening correctly when subclassed

tests/test_features.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,26 @@ def test_feature_validation():
253253

254254
with pytest.raises(ValidationError):
255255
# bad bbox2d
256-
Feature(type="Feature", properties=None, bbox=(100, 100, 0, 0), geometry=None)
256+
Feature(type="Feature", properties=None, bbox=(0, 100, 100, 0), geometry=None)
257257

258258
with pytest.raises(ValidationError):
259259
# bad bbox3d
260260
Feature(
261261
type="Feature",
262262
properties=None,
263-
bbox=(100, 100, 100, 0, 0, 0),
263+
bbox=(0, 100, 100, 100, 0, 0),
264+
geometry=None,
265+
)
266+
267+
# Antimeridian
268+
with pytest.warns(UserWarning):
269+
Feature(type="Feature", properties=None, bbox=(100, 0, 0, 100), geometry=None)
270+
271+
with pytest.warns(UserWarning):
272+
Feature(
273+
type="Feature",
274+
properties=None,
275+
bbox=(100, 0, 0, 0, 100, 100),
264276
geometry=None,
265277
)
266278

0 commit comments

Comments
 (0)