switch reverse() to new Geometry datatype

Also switches to using bind parameters for recurring parameters.
This commit is contained in:
Sarah Hoffmann
2023-06-25 14:02:00 +02:00
parent 4bb4db0668
commit 6c4c9ec1f2
8 changed files with 127 additions and 100 deletions

View File

@@ -14,6 +14,7 @@ import dataclasses
import enum
import math
from struct import unpack
from binascii import unhexlify
import sqlalchemy as sa
@@ -72,9 +73,11 @@ class Point(NamedTuple):
@staticmethod
def from_wkb(wkb: bytes) -> 'Point':
def from_wkb(wkb: Union[str, bytes]) -> 'Point':
""" Create a point from EWKB as returned from the database.
"""
if isinstance(wkb, str):
wkb = unhexlify(wkb)
if len(wkb) != 25:
raise ValueError("Point wkb has unexpected length")
if wkb[0] == 0:
@@ -192,13 +195,16 @@ class Bbox:
@staticmethod
def from_wkb(wkb: Optional[bytes]) -> 'Optional[Bbox]':
def from_wkb(wkb: Union[None, str, bytes]) -> 'Optional[Bbox]':
""" Create a Bbox from a bounding box polygon as returned by
the database. Return s None if the input value is None.
"""
if wkb is None:
return None
if isinstance(wkb, str):
wkb = unhexlify(wkb)
if len(wkb) != 97:
raise ValueError("WKB must be a bounding box polygon")
if wkb.startswith(WKB_BBOX_HEADER_LE):