Skip to content

Commit 605142e

Browse files
committed
Fix coordinate parsing #237
1 parent a919365 commit 605142e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

pycaching/geo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def from_string(cls, string):
6666
coords = string.replace("N", " ").replace("S", " ").replace("E", " ").replace("W", " ").replace("+", " ")
6767

6868
try:
69-
m = re.match(r"\s*(-?\s*\d+)\D+(\d+[\.,]\d+)\D?\s*(-?\s*\d+)\D+(\d+[\.,]\d+)", coords)
69+
m = re.match(r"\s*(-?\s*\d+)\D+(\d+[\.,]\d+)\D+(-?\s*\d+)\D+(\d+[\.,]\d+)", coords)
7070

7171
latDeg, latMin, lonDeg, lonMin = [float(part.replace(" ", "").replace(",", ".")) for part in m.groups()]
7272

test/test_geo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def test_from_string(self):
5353
with self.subTest("comma between lat and lon"):
5454
self.assertEqual(Point.from_string("N 49 45.123, E 013 22.123"), Point(49.75205, 13.36872))
5555

56+
with self.subTest("comma and space between lat and lon"):
57+
self.assertEqual(Point.from_string("N 44° 25.845 , W 72° 02.485"), Point(44.43075, -72.04142))
58+
5659
with self.subTest("marginal values: zeroes"):
5760
self.assertEqual(Point.from_string("N 49 45.000 E 13 0.0"), Point(49.75, 13.0))
5861

0 commit comments

Comments
 (0)