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]]
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):