Skip to content

Commit

Permalink
WKT of MultiPoint has parenthesis around individual point coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Dec 3, 2024
1 parent 18f4872 commit d535c7d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
15 changes: 11 additions & 4 deletions pygeoif/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#
# file deepcode ignore inconsistent~equality: Python 3 only
"""Geometries in pure Python."""

import math
import warnings
from itertools import chain
Expand Down Expand Up @@ -598,7 +599,8 @@ def has_z(self) -> Optional[bool]:
def _wkt_coords(self) -> str:
ec = self.exterior._wkt_coords # noqa: SLF001
ic = "".join(
f",({interior._wkt_coords})" for interior in self.interiors # noqa: SLF001
f",({interior._wkt_coords})" # noqa: SLF001
for interior in self.interiors
)
return f"({ec}){ic}"

Expand Down Expand Up @@ -749,7 +751,10 @@ def geoms(self) -> Iterator[Point]:

@property
def _wkt_coords(self) -> str:
return ", ".join(point._wkt_coords for point in self.geoms) # noqa: SLF001
return ", ".join(
f"({point._wkt_coords})" # noqa: SLF001
for point in self.geoms
)

@property
def __geo_interface__(self) -> GeoInterface:
Expand Down Expand Up @@ -828,7 +833,8 @@ def geoms(self) -> Iterator[LineString]:
@property
def _wkt_coords(self) -> str:
return ",".join(
f"({linestring._wkt_coords})" for linestring in self.geoms # noqa: SLF001
f"({linestring._wkt_coords})" # noqa: SLF001
for linestring in self.geoms
)

@property
Expand Down Expand Up @@ -1086,7 +1092,8 @@ def __geo_interface__(self) -> GeoCollectionInterface: # type: ignore [override

def _prepare_hull(self) -> Iterable[Point2D]:
return chain.from_iterable(
geom._prepare_hull() for geom in self.geoms # noqa: SLF001
geom._prepare_hull() # noqa: SLF001
for geom in self.geoms
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def test_multipoint(self) -> None:
assert isinstance(p, geometry.MultiPoint)
assert next(iter(p.geoms)).x == 3.5
assert list(p.geoms)[1].y == 10.5
assert p.wkt == "MULTIPOINT (3.5 5.6, 4.8 10.5)"
assert p.wkt == "MULTIPOINT ((3.5 5.6), (4.8 10.5))"
p = factories.from_wkt("MULTIPOINT ((10 40), (40 30), (20 20), (30 10))")
assert isinstance(p, geometry.MultiPoint)
assert next(iter(p.geoms)).x == 10.0
Expand Down
6 changes: 3 additions & 3 deletions tests/test_geometrycollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_multipoint_wkt() -> None:
multipoint = geometry.MultiPoint([(0, 0), (1, 1), (1, 2), (2, 2)])
gc = geometry.GeometryCollection([multipoint])

assert gc.wkt == "GEOMETRYCOLLECTION (MULTIPOINT (0 0, 1 1, 1 2, 2 2))"
assert gc.wkt == "GEOMETRYCOLLECTION (MULTIPOINT ((0 0), (1 1), (1 2), (2 2)))"


def test_multipoint_repr() -> None:
Expand Down Expand Up @@ -313,8 +313,8 @@ def test_nested_geometry_collection() -> None:

assert gc3.wkt == (
"GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION ("
"POINT (0 0), MULTIPOINT (0 0, 1 1, 1 2, 2 2)), LINESTRING (0 0, 3 1)), "
"POLYGON ((0 0, 1 1, 1 0, 0 0)))"
"POINT (0 0), MULTIPOINT ((0 0), (1 1), (1 2), (2 2))), "
"LINESTRING (0 0, 3 1)), POLYGON ((0 0, 1 1, 1 0, 0 0)))"
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_multipoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_unique() -> None:
def test_wkt() -> None:
multipoint = geometry.MultiPoint([(0, 0), (1, 1), (1, 2), (2, 2)])

assert multipoint.wkt == "MULTIPOINT (0 0, 1 1, 1 2, 2 2)"
assert multipoint.wkt == "MULTIPOINT ((0 0), (1 1), (1 2), (2 2))"


def test_repr() -> None:
Expand Down

0 comments on commit d535c7d

Please sign in to comment.