Skip to content

Commit 0b23059

Browse files
committed
Add BBox to Geometries.
1 parent 23240df commit 0b23059

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

geojson_pydantic/geometries.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""pydantic models for GeoJSON Geometry objects."""
22

33
import abc
4-
from typing import Any, Iterator, List, Literal, Union
4+
from typing import Any, Iterator, List, Literal, Optional, Union
55

66
from pydantic import BaseModel, Field, ValidationError, validator
77
from pydantic.error_wrappers import ErrorWrapper
88
from typing_extensions import Annotated
99

1010
from geojson_pydantic.geo_interface import GeoInterfaceMixin
1111
from geojson_pydantic.types import (
12+
BBox,
1213
LinearRing,
1314
LineStringCoords,
1415
MultiLineStringCoords,
@@ -55,6 +56,7 @@ class _GeometryBase(BaseModel, abc.ABC, GeoInterfaceMixin):
5556

5657
type: str
5758
coordinates: Any
59+
bbox: Optional[BBox] = None
5860

5961
@property
6062
@abc.abstractmethod
@@ -238,6 +240,7 @@ class GeometryCollection(BaseModel, GeoInterfaceMixin):
238240

239241
type: Literal["GeometryCollection"]
240242
geometries: List[Geometry]
243+
bbox: Optional[BBox] = None
241244

242245
def __iter__(self) -> Iterator[Geometry]: # type: ignore [override]
243246
"""iterate over geometries"""

tests/test_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class Pointy:
168168
__geo_interface__ = {"type": "Point", "coordinates": (0.0, 0.0)}
169169

170170
feat = Feature(type="Feature", geometry=Pointy(), properties={})
171-
assert feat.geometry.dict() == Pointy.__geo_interface__
171+
assert feat.geometry.dict(exclude_unset=True) == Pointy.__geo_interface__
172172

173173

174174
def test_feature_with_null_geometry():

0 commit comments

Comments
 (0)