diff --git a/docs/LICENSE.rst b/docs/LICENSE.rst index d1fdccef..c769a96c 100644 --- a/docs/LICENSE.rst +++ b/docs/LICENSE.rst @@ -18,4 +18,4 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -.. _LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.0.en.html +.. _LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html diff --git a/pygeoif/geometry.py b/pygeoif/geometry.py index 8ea35cc3..87704207 100644 --- a/pygeoif/geometry.py +++ b/pygeoif/geometry.py @@ -182,7 +182,11 @@ def _wkt_coords(self) -> str: @property def _wkt_inset(self) -> str: """Return Z for 3 dimensional geometry or an empty string for 2 dimensions.""" - return "" + if self.is_empty: + return f"{self._wkt_type} EMPTY" + if self.has_z: + return " Z " + return " " @property def _wkt_type(self) -> str: @@ -307,11 +311,6 @@ def has_z(self) -> bool: def _wkt_coords(self) -> str: return " ".join(str(coordinate) for coordinate in self._geoms) - @property - def _wkt_inset(self) -> str: - """Return Z for 3 dimensional geometry or an empty string for 2 dimensions.""" - return " Z " if len(self._geoms) == 3 else " " # noqa: PLR2004 - @property def __geo_interface__(self) -> GeoInterface: """Return the geo interface.""" @@ -407,10 +406,6 @@ def maybe_valid(self) -> bool: """ return len({p.coords[0] for p in self._geoms}) > 1 - @property - def _wkt_inset(self) -> str: - return self.geoms[0]._wkt_inset # noqa: SLF001 - @property def _wkt_coords(self) -> str: return ", ".join(point._wkt_coords for point in self.geoms) # noqa: SLF001 @@ -648,10 +643,6 @@ def _wkt_coords(self) -> str: ) return f"({ec}){ic}" - @property - def _wkt_inset(self) -> str: - return self.exterior._wkt_inset # noqa: SLF001 - @property def __geo_interface__(self) -> GeoInterface: """Return the geo interface.""" diff --git a/tests/test_base.py b/tests/test_base.py index 862c7f79..af98c21b 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -37,7 +37,8 @@ def test_empty() -> None: def test_wkt_inset() -> None: base_geo = geometry._Geometry() - assert base_geo._wkt_inset == "" + with pytest.raises(NotImplementedError, match="^Must be implemented by subclass$"): + assert base_geo._wkt_inset == "" def test_wkt_coordinates() -> None: diff --git a/tests/test_factories.py b/tests/test_factories.py index 1c29aaa7..96235841 100644 --- a/tests/test_factories.py +++ b/tests/test_factories.py @@ -108,8 +108,8 @@ class TestWKT: (30 20, 20 25, 20 15, 30 20)))""", """MULTIPOLYGON (((30 20, 10 40, 45 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))""", - "MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))", - "GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))", + "MULTIPOLYGON (((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))", + "GEOMETRYCOLLECTION (POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))", ] # these are valid WKTs but not supported @@ -209,7 +209,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 @@ -221,14 +221,14 @@ def test_multipoint(self) -> None: def test_multilinestring(self) -> None: p = factories.from_wkt( - "MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))", + "MULTILINESTRING ((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))", ) assert isinstance(p, geometry.MultiLineString) assert next(iter(p.geoms)).coords == (((3, 4), (10, 50), (20, 25))) assert list(p.geoms)[1].coords == (((-5, -8), (-10, -8), (-15, -4))) assert ( - p.wkt == "MULTILINESTRING((3 4, 10 50, " + p.wkt == "MULTILINESTRING ((3 4, 10 50, " "20 25),(-5 -8, " "-10 -8, -15 -4))" ) @@ -241,12 +241,12 @@ def test_multilinestring_1(self) -> None: assert isinstance(p, geometry.MultiLineString) assert p.wkt == ( - "MULTILINESTRING((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))" + "MULTILINESTRING ((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))" ) def test_multipolygon(self) -> None: p = factories.from_wkt( - "MULTIPOLYGON(((0 0,10 20,30 40,0 0)," + "MULTIPOLYGON (((0 0,10 20,30 40,0 0)," "(1 1,2 2,3 3,1 1))," "((100 100,110 110,120 120,100 100)))", ) @@ -273,7 +273,7 @@ def test_multipolygon(self) -> None: (100.0, 100.0), ) assert ( - p.wkt == "MULTIPOLYGON(((0 0, 10 20, " + p.wkt == "MULTIPOLYGON (((0 0, 10 20, " "30 40, 0 0)," "(1 1, 2 2, 3 3, 1 1))," "((100 100, 110 110," @@ -322,7 +322,7 @@ def test_geometrycollection(self) -> None: assert len(list(gc.geoms)) == 2 assert isinstance(next(iter(gc.geoms)), geometry.Point) assert isinstance(list(gc.geoms)[1], geometry.LineString) - assert gc.wkt == "GEOMETRYCOLLECTION(POINT (4 6), LINESTRING (4 6, 7 10))" + assert gc.wkt == "GEOMETRYCOLLECTION (POINT (4 6), LINESTRING (4 6, 7 10))" def test_wkt_ok(self) -> None: for wkt in self.wkt_ok: diff --git a/tests/test_functions.py b/tests/test_functions.py index 1872d64d..e1441a22 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -126,7 +126,7 @@ def test_signed_area_crescent_ish() -> None: def test_empty_hull() -> None: - assert not convex_hull([]) + assert convex_hull([]) == [] def test_point() -> None: diff --git a/tests/test_geometrycollection.py b/tests/test_geometrycollection.py index 27915bf0..59065667 100644 --- a/tests/test_geometrycollection.py +++ b/tests/test_geometrycollection.py @@ -70,7 +70,7 @@ def test_geo_wkt() -> None: gc = geometry.GeometryCollection([poly1, poly2, p0, p1, ring, line]) assert gc.wkt == ( - "GEOMETRYCOLLECTION" + "GEOMETRYCOLLECTION " "(POLYGON ((0 0, 1 1, 1 0, 0 0)), " "POLYGON ((0 0, 0 2, 2 2, 2 0, 0 0),(1 0, 0.5 0.5, 1 1, 1.5 0.5, 1 0)), " "POINT (0 0), POINT (-1 -1), " @@ -271,7 +271,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: @@ -309,8 +309,8 @@ def test_nested_geometry_collection() -> None: gc3 = geometry.GeometryCollection([gc2, poly1]) assert gc3.wkt == ( - "GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(" - "POINT (0 0), MULTIPOINT(0 0, 1 1, 1 2, 2 2)), LINESTRING (0 0, 3 1)), " + "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)))" ) diff --git a/tests/test_multiline.py b/tests/test_multiline.py index ff189e2b..0aadecae 100644 --- a/tests/test_multiline.py +++ b/tests/test_multiline.py @@ -52,13 +52,13 @@ def test_wkt() -> None: ([(0, 0), (1, 1), (1, 2), (2, 2)], [[0.0, 0.0], [1.0, 2.0]]), ) - assert lines.wkt == "MULTILINESTRING((0 0, 1 1, 1 2, 2 2),(0.0 0.0, 1.0 2.0))" + assert lines.wkt == "MULTILINESTRING ((0 0, 1 1, 1 2, 2 2),(0.0 0.0, 1.0 2.0))" def test_wkt_single_line() -> None: lines = geometry.MultiLineString(([(0, 0), (1, 1), (1, 2), (2, 2)],)) - assert lines.wkt == "MULTILINESTRING((0 0, 1 1, 1 2, 2 2))" + assert lines.wkt == "MULTILINESTRING ((0 0, 1 1, 1 2, 2 2))" def test_repr() -> None: diff --git a/tests/test_multipoint.py b/tests/test_multipoint.py index ba9da565..9b64bef3 100644 --- a/tests/test_multipoint.py +++ b/tests/test_multipoint.py @@ -81,7 +81,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: diff --git a/tests/test_multipolygon.py b/tests/test_multipolygon.py index bd8538ef..4ae637ba 100644 --- a/tests/test_multipolygon.py +++ b/tests/test_multipolygon.py @@ -89,7 +89,7 @@ def test_wkt() -> None: ) assert polys.wkt == ( - "MULTIPOLYGON(((0.0 0.0, 0.0 1.0, 1.0 1.0, 1.0 0.0, 0.0 0.0)," + "MULTIPOLYGON (((0.0 0.0, 0.0 1.0, 1.0 1.0, 1.0 0.0, 0.0 0.0)," "(0.1 0.1, 0.1 0.2, 0.2 0.2, 0.2 0.1, 0.1 0.1))," "((0.0 0.0, 0.0 1.0, 1.0 1.0, 1.0 0.0, 0.0 0.0)))" )