Implemented parse_wrmap_coordinates.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 15 Aug 2013 10:47:41 +0000 (10:47 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 15 Aug 2013 10:47:41 +0000 (10:47 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@1517 7aebc617-e5e2-0310-91dc-80fb5f6d2477

tests/test_wrmwmarkup.py
wrpylib/wrmwmarkup.py

index 152212b468adbc9450b7989813e32a392a503141..d467cb0612ea348fa4b03006941b20d6fa9ec6d9 100644 (file)
@@ -121,10 +121,9 @@ def test_parse_wrmap():
     assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
     assert json['features'][3]['properties']['type'] == 'sledrun'
     assert json['features'][3]['geometry']['coordinates'] == [
     assert json['features'][2]['geometry']['coordinates'] == [11.238283, 47.245711]
     assert json['features'][3]['properties']['type'] == 'sledrun'
     assert json['features'][3]['geometry']['coordinates'] == [
-        [47.238587, 11.203360],
-        [47.244951, 11.230868],
-        [47.245470, 11.237853]]
-
+        [11.203360, 47.238587],
+        [11.230868, 47.244951],
+        [11.237853, 47.245470]]
 
 
 def test_create_wrmap():
 
 
 def test_create_wrmap():
index 9dbebe9fd91f2a8bb78df1a6e930728037f95aaf..c968b20d4005453f620b2d32bd33599c74117db4 100644 (file)
@@ -373,20 +373,17 @@ def parse_wrmap_coordinates(coords):
     47.13 N 11.70 E
     ->
     [[11.87, 47.12], [11.70, 47.13]]'''
     47.13 N 11.70 E
     ->
     [[11.87, 47.12], [11.70, 47.13]]'''
-    '''
-        $matches = array();
-        $num_matches = preg_match_all('/\s*(\d+\.?\d*)\s*N?\s+(\d+\.?\d*)\s*E?\s*/', $input, $matches);
-        $result = array();
-        for ($i=0; $i!=$num_matches; ++$i) {
-            $result[] = array(floatval($matches[2][$i]), floatval($matches[1][$i]));
-        }
-        if (implode($matches[0]) != $input) throw new Exception('Falsches Koordinatenformat: ' . $input);
-        return $result;
-    }
-
-    Think of using re.sub(pattern, repl, string, count=0, flags=0)
-    '''
-    return [[0, 0]] # TODO
+    result = []
+    pos = 0
+    for match in re.finditer(r'\s*(\d+\.?\d*)\s*N?\s+(\d+\.?\d*)\s*E?\s*', coords):
+        if match.start() != pos:
+            break
+        result.append([float(match.groups()[1]), float(match.groups()[0])])
+        pos = match.end()
+    else:
+        if pos == len(coords):
+            return result
+    raise RuntimeError('Wrong coordinate format: {}'.format(coords))
 
 
 def parse_wrmap(wikitext):
 
 
 def parse_wrmap(wikitext):