Skip to content

Commit ba97083

Browse files
committed
Add validation for order of bounding boxes
1 parent 96eb472 commit ba97083

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

geojson_pydantic/features.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ class Config:
2727

2828
use_enum_values = True
2929

30+
@validator("bbox", pre=True)
31+
def check_bbox(cls, bbox: BBox) -> BBox:
32+
if len(bbox) == 6:
33+
if bbox[0] > bbox[3] or bbox[1] > bbox[4] or bbox[2] > bbox[5]:
34+
raise ValueError("BBox must be in the form [west, south, bottom, east, north, top]")
35+
elif len(bbox) == 4:
36+
if bbox[0] > bbox[2] or bbox[1] > bbox[3]:
37+
raise ValueError("BBox must be in the form [west, south, east, north]")
38+
else:
39+
raise ValueError("BBox must be in the form [west, south, east, north] or [west, south, bottom, east, north, top]")
40+
return bbox
41+
42+
3043
@validator("geometry", pre=True, always=True)
3144
def set_geometry(cls, geometry: Any) -> Any:
3245
"""set geometry from geo interface or input"""

0 commit comments

Comments
 (0)