From fa769914c70ce9249ee0c0b0155334ffa1634ca7 Mon Sep 17 00:00:00 2001 From: PhiBo Date: Sun, 10 May 2015 22:54:09 +0200 Subject: [PATCH] src - Add initial support for osm xml (Ref: #12) --- overpy/format/__init__.py | 0 overpy/format/osm_xml.py | 106 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 overpy/format/__init__.py create mode 100644 overpy/format/osm_xml.py diff --git a/overpy/format/__init__.py b/overpy/format/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/overpy/format/osm_xml.py b/overpy/format/osm_xml.py new file mode 100644 index 0000000..d3a5153 --- /dev/null +++ b/overpy/format/osm_xml.py @@ -0,0 +1,106 @@ +from xml.sax.saxutils import escape + +import overpy + + +def dump(result, fp): + """ + + :param result: + :type result: overpy.Result + :param fp: + :return: + """ + fp.write('\n') + fp.write('\n'.format(overpy.__version__)) + lat_min = result.nodes[0].lat + lat_max = lat_min + lon_min = result.nodes[0].lon + lon_max = lon_min + for node in result.nodes: + if node.lat < lat_min: + lat_min = node.lat + elif node.lat > lat_max: + lat_max = node.lat + + if node.lon < lon_min: + lon_min = node.lon + elif node.lon > lon_max: + lon_max = node.lon + + fp.write( + '\n'.format( + lat_min, + lat_max, + lon_min, + lon_max + ) + ) + + for node in result.nodes: + fp.write( + '\n') + continue + fp.write('>\n') + for k, v in node.tags.items(): + fp.write( + '\n'.format( + escape(k), + escape(v) + ) + ) + fp.write('\n') + + for way in result.ways: + fp.write('\n') + continue + fp.write('>\n') + for node in way.nodes: + fp.write('\n'.format(node.id)) + + for k, v in way.tags.items(): + fp.write( + '\n'.format( + escape(k), + escape(v) + ) + ) + + fp.write('\n') + + for relation in result.relations: + fp.write('\n'.format( + member._type_value, + member.ref, + member.role + ) + ) + + for k, v in relation.tags.items(): + fp.write( + '\n'.format( + escape(k), + escape(v) + ) + ) + + fp.write('\n') + + fp.write('')