Skip to content

Commit 16f6b87

Browse files
committedAug 26, 2020
Support scientific-number format coming from postgis
1 parent ac27fad commit 16f6b87

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎cubedash/summary/_stores.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ def _dataset_to_feature(dataset: Dataset):
10551055

10561056

10571057
_BOX2D_PATTERN = re.compile(
1058-
r"BOX\(([-0-9.]+)\s+([-0-9.]+)\s*,\s*([-0-9.]+)\s+([-0-9.]+)\)"
1058+
r"BOX\(([-0-9.e]+)\s+([-0-9.e]+)\s*,\s*([-0-9.e]+)\s+([-0-9.e]+)\)"
10591059
)
10601060

10611061

@@ -1067,8 +1067,16 @@ def _box2d_to_bbox(pg_box2d: str) -> Tuple[float, float, float, float]:
10671067
... "BOX(134.806923200497 -17.7694714883835,135.769692610214 -16.8412669214876)"
10681068
... )
10691069
(134.806923200497, -17.7694714883835, 135.769692610214, -16.8412669214876)
1070+
>>> # Scientific notation in numbers is sometimes given
1071+
>>> _box2d_to_bbox(
1072+
... "BOX(35.6948526641442 -0.992278901187827,36.3518945675102 -9.03173177994956e-06)"
1073+
... )
1074+
(35.6948526641442, -0.992278901187827, 36.3518945675102, -9.03173177994956e-06)
10701075
"""
10711076
m = _BOX2D_PATTERN.match(pg_box2d)
1077+
if m is None:
1078+
raise RuntimeError(f"Unexpected postgis box syntax {pg_box2d!r}")
1079+
10721080
# We know there's exactly four groups, but type checker doesn't...
10731081
# noinspection PyTypeChecker
10741082
return tuple(float(m) for m in m.groups())

0 commit comments

Comments
 (0)
Please sign in to comment.