Skip to content

Commit 46c088d

Browse files
Merge pull request #108 from eseglem/feature/add-bbox-to-geoms
Add BBox to Geometries.
2 parents 23240df + a9b8218 commit 46c088d

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2727
```
2828

2929
- Add has_z function to Geometries (author @eseglem, https://github.com/developmentseed/geojson-pydantic/pull/103)
30+
- Add optional bbox to geometries.
3031

3132
### Changed
3233

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)