Updated function update_wrmapcache to work with <wrmap> instead of <googlemap>.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 12 Sep 2013 21:07:36 +0000 (21:07 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 12 Sep 2013 21:07:36 +0000 (21:07 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@1575 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrpylib/wrmwcache.py

index b946d7475081f969f40611bb7973f77146006f46..ba384b517ec466c0c6018936f71fa29a183ec582 100644 (file)
@@ -167,29 +167,36 @@ def update_wrmapcache(connection):
     # Refill wrmappointcache and wrmappathcache tables
     for sledrun_page in sledrun_pages:
         try: 
-            result = mwmarkup.parse_googlemap(sledrun_page.old_text)
-            if not result is None:
-                center, zoom, coords, paths = result
+            start, content, endtag, end = mwmarkup.find_tag(sledrun_page.old_text, 'wrmap')
+            if content is None:
+                continue
+            geojson = wrmwmarkup.parse_wrmap(sledrun_page.old_text[start:end])
+
+            for feature in geojson['features']:
+                properties = feature['properties']
+                coordinates = feature['geometry']['coordinates']
+
                 # Points
-                for coord in coords:
-                    lon, lat, point_type, label = coord
-                    point_types = {u'Gasthaus': u'hut', u'Haltestelle': u'busstop', u'Parkplatz': u'carpark', u'Achtung': u'warning'}
-                    if not point_type is None:
-                        if not point_types.has_key(point_type): raise RuntimeError(u'Unknown point type {0}'.format(point_type))
-                        point_type = point_types[point_type]
-                        sql = u'insert into wrmappointcache (page_id, type, point, label) values (%s, %s, POINT(%s, %s), %s)'
-                        connection.execute(sql, (sledrun_page.page_id, point_type, lon, lat, label))
+                if properties['type'] in wrmwmarkup.WRMAP_POINT_TYPES:
+                    lon, lat = coordinates
+                    label = properties.get('name')
+                    point_types = {u'gasthaus': u'hut', u'haltestelle': u'busstop', u'parkplatz': u'carpark', u'achtung': u'warning', u'punkt': u'point'}
+                    point_type = point_types[properties['type']]
+                    sql = u'insert into wrmappointcache (page_id, type, point, label) values (%s, %s, POINT(%s, %s), %s)'
+                    connection.execute(sql, (sledrun_page.page_id, point_type, lon, lat, label))
+
                 # Paths
-                for path_type, coords in paths:
-                    path_type = path_type.lower()
-                    path_types = {u'6#ff014e9a': u'sledrun', u'6#ffe98401': u'walkup', u'6#ff7f7fff': u'alternative', u'3#ff000000': u'lift', u'3#ffe1e100': u'recommendedcarroute'}
-                    if not path_types.has_key(path_type): raise RuntimeError(u'Unknown path type {0}'.format(path_type))
-                    path_type = path_types[path_type]
-                    path = u", ".join(["{0} {1}".format(lon, lat) for lon, lat, symbol, title in coords])
+                elif properties['type'] in wrmwmarkup.WRMAP_LINE_TYPES:
+                    path_types = {u'rodelbahn': u'sledrun', u'gehweg': u'walkup', u'alternative': u'alternative', u'lift': u'lift', u'anfahrt': u'recommendedcarroute', u'linie': u'line'}
+                    path_type = path_types[properties['type']]
+                    path = u", ".join(["{0} {1}".format(lon, lat) for lon, lat in coordinates])
                     path = u'LineString({0})'.format(path)
                     if path_type == u'recommendedcarroute': continue
                     sql = u'insert into wrmappathcache (path, page_id, type) values (GeomFromText(%s), %s, %s)'
                     connection.execute(sql, (path, sledrun_page.page_id, path_type))
+
+                else:
+                    raise RuntimeError(u'Unknown feature type {0}'.format(properties['type']))
         except RuntimeError as e:
             error_msg = u"Error at sledrun '{0}': {1}".format(sledrun_page.page_title, unicode(e))
             transaction.rollback()