From a41420a9e13d0c7c6eda3fb53a0a45c772c8d3e2 Mon Sep 17 00:00:00 2001 From: Benoit Bovy Date: Tue, 4 Feb 2025 15:27:32 +0100 Subject: [PATCH] align GeographyType values with shapely.GeometryType --- src/geography.cpp | 24 ++++++++++++++---------- src/geography.hpp | 2 +- tests/test_geography.py | 10 +++++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/geography.cpp b/src/geography.cpp index ec56d5f..5405137 100644 --- a/src/geography.cpp +++ b/src/geography.cpp @@ -285,15 +285,15 @@ void init_geography(py::module &m) { pygeography_types.value( "LINESTRING", GeographyType::LineString, "Single line geography type (1)."); pygeography_types.value( - "POLYGON", GeographyType::Polygon, "Single polygon geography type (2)."); + "POLYGON", GeographyType::Polygon, "Single polygon geography type (3)."); pygeography_types.value( - "MULTIPOINT", GeographyType::MultiPoint, "Multiple point geography type (3)."); + "MULTIPOINT", GeographyType::MultiPoint, "Multiple point geography type (4)."); pygeography_types.value( - "MULTILINESTRING", GeographyType::MultiLineString, "Multiple line geography type (4)."); + "MULTILINESTRING", GeographyType::MultiLineString, "Multiple line geography type (5)."); pygeography_types.value( - "MULTIPOLYGON", GeographyType::MultiPolygon, "Multiple polygon geography type (5)."); + "MULTIPOLYGON", GeographyType::MultiPolygon, "Multiple polygon geography type (6)."); pygeography_types.value( - "GEOMETRYCOLLECTION", GeographyType::GeometryCollection, "Collection geography type (6)."); + "GEOMETRYCOLLECTION", GeographyType::GeometryCollection, "Collection geography type (7)."); // Geography classes @@ -333,11 +333,15 @@ void init_geography(py::module &m) { - None (missing) is -1 - POINT is 0 - LINESTRING is 1 - - POLYGON is 2 - - MULTIPOINT is 3 - - MULTILINESTRING is 4 - - MULTIPOLYGON is 5 - - GEOMETRYCOLLECTION is 6 + - POLYGON is 3 + - MULTIPOINT is 4 + - MULTILINESTRING is 5 + - MULTIPOLYGON is 6 + - GEOMETRYCOLLECTION is 7 + + Those ID numbers are consistent with Shapely geometry types + (note that Spherely has no LINEARRING type, hence the jump from + 1 to 3 between LINESTRING and POLYGON). Parameters ---------- diff --git a/src/geography.hpp b/src/geography.hpp index ca0c89f..0dfe6c4 100644 --- a/src/geography.hpp +++ b/src/geography.hpp @@ -23,7 +23,7 @@ enum class GeographyType : std::int8_t { None = -1, Point, LineString, - Polygon, + Polygon = 3, MultiPoint, MultiLineString, MultiPolygon, diff --git a/tests/test_geography.py b/tests/test_geography.py index c19fa8f..85e7e71 100644 --- a/tests/test_geography.py +++ b/tests/test_geography.py @@ -10,11 +10,11 @@ def test_geography_type() -> None: assert spherely.GeographyType.NONE.value == -1 assert spherely.GeographyType.POINT.value == 0 assert spherely.GeographyType.LINESTRING.value == 1 - assert spherely.GeographyType.POLYGON.value == 2 - assert spherely.GeographyType.MULTIPOINT.value == 3 - assert spherely.GeographyType.MULTILINESTRING.value == 4 - assert spherely.GeographyType.MULTIPOLYGON.value == 5 - assert spherely.GeographyType.GEOMETRYCOLLECTION.value == 6 + assert spherely.GeographyType.POLYGON.value == 3 + assert spherely.GeographyType.MULTIPOINT.value == 4 + assert spherely.GeographyType.MULTILINESTRING.value == 5 + assert spherely.GeographyType.MULTIPOLYGON.value == 6 + assert spherely.GeographyType.GEOMETRYCOLLECTION.value == 7 def test_is_geography() -> None: