Skip to content

Commit

Permalink
Fix: Default SRID is bypassed when using floating point coordinates (#…
Browse files Browse the repository at this point in the history
…509)

* Update elements.py

* Add test

---------

Co-authored-by: Adrien Berchet <adrien.berchet@gmail.com>
  • Loading branch information
aballet and adrien-berchet committed May 1, 2024
1 parent 11dadb4 commit 344cb24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion geoalchemy2/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class WKTElement(_SpatialElement):
"""

_REMOVE_SRID = re.compile("(SRID=([0-9]+); ?)?(.*)")
SPLIT_WKT_PATTERN = re.compile(r"((SRID=\d+) *; *)?([\w ]+) *(\([\d ,\(\)]+\))")
SPLIT_WKT_PATTERN = re.compile(r"((SRID=\d+) *; *)?([\w ]+) *(\([\d\. ,\(\)]+\))")

geom_from: str = "ST_GeomFromText"
geom_from_extended_version: str = "ST_GeomFromEWKT"
Expand Down
16 changes: 14 additions & 2 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,16 @@ def test_insert(self, conn, Lake, setup_tables):
),
],
)
def test_insert_all_geom_types(self, dialect_name, base, conn, metadata, geom_type, wkt):
@pytest.mark.parametrize(
"use_floating_point",
[
pytest.param(True, id="Use floating point"),
pytest.param(False, id="Do not use floating point"),
],
)
def test_insert_all_geom_types(
self, dialect_name, base, conn, metadata, geom_type, wkt, use_floating_point
):
"""Test insertion and selection of all geometry types."""
ndims = 2
if "Z" in geom_type[-2:]:
Expand All @@ -358,6 +367,9 @@ class GeomTypeTable(base):
metadata.drop_all(bind=conn, checkfirst=True)
metadata.create_all(bind=conn)

if use_floating_point:
wkt = wkt.replace("1 2", "1.5 2.5")

inserted_wkt = f"{geom_type}{wkt}"

# Use the DB to generate the corresponding raw WKB
Expand Down Expand Up @@ -401,7 +413,7 @@ class GeomTypeTable(base):
if "MULTIPOINT" in geom_type:
# Some dialects return MULTIPOINT geometries with nested parenthesis and others
# do not so we remove them before checking the results
checked_wkt = re.sub(r"\(([0-9]+)\)", "\\1", checked_wkt)
checked_wkt = re.sub(r"\(([0-9\.]+)\)", "\\1", checked_wkt)
if row_id >= 5 and dialect_name in ["geopackage"] and has_m:
# Currently Shapely does not support geometry types with M dimension
assert checked_wkt != expected_wkt
Expand Down

0 comments on commit 344cb24

Please sign in to comment.