Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.5.0] - TBD

## Fixed

- Derive WKT type from Geometry's type instead of class name (author @eseglem, https://github.com/developmentseed/geojson-pydantic/pull/81)

### Changed

- Remove `NumType` and use `float` throughout (author @eseglem, https://github.com/developmentseed/geojson-pydantic/pull/83)
Expand Down
7 changes: 4 additions & 3 deletions geojson_pydantic/geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def __geo_interface__(self):
class _GeometryBase(BaseModel, GeoInterfaceMixin, abc.ABC):
"""Base class for geometry models"""

coordinates: Any # will be constrained in child classes
type: str
coordinates: Any

@classmethod
def validate(cls, value):
Expand Down Expand Up @@ -61,7 +62,7 @@ def _wkt_inset(self) -> str:
@property
def _wkt_type(self) -> str:
"""Return the WKT name of the geometry."""
return self.__class__.__name__.upper()
return self.type.upper()

@property
def wkt(self) -> str:
Expand Down Expand Up @@ -234,7 +235,7 @@ def __getitem__(self, index):
@property
def _wkt_type(self) -> str:
"""Return the WKT name of the geometry."""
return self.__class__.__name__.upper()
return self.type.upper()

@property
def _wkt_coordinates(self) -> str:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,14 @@ def test_polygon_from_bounds():
"""Result from `from_bounds` class method should be the same."""
coordinates = [[(1.0, 2.0), (3.0, 2.0), (3.0, 4.0), (1.0, 4.0), (1.0, 2.0)]]
assert Polygon(coordinates=coordinates) == Polygon.from_bounds(1.0, 2.0, 3.0, 4.0)


def test_wkt_name():
"""Make sure WKT name is derived from geometry Type."""

class PointType(Point):
...

assert (
PointType(coordinates=(1.01, 2.01)).wkt == Point(coordinates=(1.01, 2.01)).wkt
)