Skip to content
Merged
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
11 changes: 6 additions & 5 deletions src/shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __repr__(self) -> str:

class HasGeoInterface(Protocol):
@property
def __geo_interface__(self) -> Any: ...
def __geo_interface__(self) -> GeoJSONHomogeneousGeometryObject: ...


class GeoJSONPoint(TypedDict):
Expand Down Expand Up @@ -3591,17 +3591,18 @@ def __dbfHeader(self) -> None:

def shape(
self,
s: Union[Shape, HasGeoInterface, dict[str, PointsT]],
s: Union[Shape, HasGeoInterface, GeoJSONHomogeneousGeometryObject],
) -> None:
# Balance if already not balanced
if self.autoBalance and self.recNum < self.shpNum:
self.balance()
# Check is shape or import from geojson
if not isinstance(s, Shape):
if hasattr(s, "__geo_interface__"):
shape_dict = cast(GeoJSONHomogeneousGeometryObject, s.__geo_interface__)
if isinstance(s, dict):
shape_dict = cast(GeoJSONHomogeneousGeometryObject, s)
s = cast(HasGeoInterface, s)
shape_dict = s.__geo_interface__
elif isinstance(s, dict): # TypedDict is a dict at runtime
shape_dict = s
else:
raise TypeError(
"Can only write Shape objects, GeoJSON dictionaries, "
Expand Down
Loading