return results
-def parse_googlemap(wikitext):
- """Parses the (unicode) u'<googlemap ...>content</googlemap>' of the googlemap extension
- out of a page. If wikitext does not contain the googlemaps extension text None is returned.
- If the googlemap contains invalid formatted lines, a ParseError is raised.
-
- :param wikitext: wikitext containing the template. Example:
-
- wikitext = '''
- <googlemap version="0.9" lat="47.113291" lon="11.272337" zoom="15">
- (Parkplatz)47.114958,11.266026
- Parkplatz
-
- (Gasthaus) 47.114715, 11.266262, Alt Bärnbad (Gasthaus)
- 6#FF014E9A
- 47.114715,11.266262
- 47.114135,11.268381
- 47.113421,11.269322
- 47.11277,11.269979
- 47.112408,11.271119
- </googlemap>
- '''
+def googlemap_to_wrmap(attributes, coords, paths):
+ """Converts the output of parse_googlemap to the GeoJSON format wrmap uses.
:returns: (GeoJSON as nested Python datatypes)
"""
- center, zoom, coords, paths = wrpylib.mwmarkup.parse_googlemap(wikitext)
json_features = []
# point
for point in coords:
lon, lat, symbol, title = point
- properties = {}
- if symbol is not None: properties['type'] = symbol.lower()
+ properties = {'type': 'punkt' if symbol is None else symbol.lower()}
if title is not None: properties['name'] = title
json_features.append({
'type': 'Feature',
geojson = {
'type': 'FeatureCollection',
'features': json_features,
- 'properties': {'lon': center[0], 'lat': center[1], 'zoom': zoom}}
+ 'properties': attributes}
return geojson
def parse_wrmap(wikitext):
- """Parses the (unicode) u'<wrmap ...>content</wrmap>' of the Winterrodeln wrmap extension
- out of a page. If wikitext does not contain the wrmap extension text None is returned.
- If the wrmap contains invalid formatted lines, a ParseError is raised.
+ """Parses the (unicode) u'<wrmap ...>content</wrmap>' of the Winterrodeln wrmap extension.
+ If wikitext does not contain the <wrmap> tag or if the <wrmap> tag contains
+ invalid formatted lines, a ParseError is raised.
+ Use wrpylib.mwmarkup.find_tag(wikitext, 'wrmap') to find the wrmap tag within an arbitrary
+ wikitext before using this function.
- :param wikitext: wikitext containing the template. Example:
+ :param wikitext: wikitext containing only the template. Example:
wikitext = u'''
<wrmap lat="47.2417134" lon="11.21408895" zoom="14" width="700" height="400">
wrmap_xml = xml.etree.ElementTree.Element('wrmap')
wrmap_xml.text = '\n\n'
for k, v in geojson['properties'].iteritems():
- wrmap_xml.attrib[k] = str(v)
+ if k in ['lon', 'lat']:
+ wrmap_xml.attrib[k] = '{:.6f}'.format(v)
+ else:
+ wrmap_xml.attrib[k] = str(v)
assert geojson['type'] == 'FeatureCollection'
json_features = geojson['features']
feature_xml.text = '\n' + create_wrmap_coordinates(geo['coordinates']) + '\n'
last_json_feature = feature_xml
feature_xml.attrib = json_feature['properties']
+ del feature_xml.attrib['type']
- print last_json_feature.tag
if last_json_feature is not None:
last_json_feature.tail = '\n\n'
- return xml.etree.ElementTree.tostring(wrmap_xml)
+ return xml.etree.ElementTree.tostring(wrmap_xml, encoding='utf-8').decode('utf-8')