Last active
April 18, 2016 13:52
-
-
Save Zia-/3252a5118b9e8c92990cfd4336a0e97d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lxml import etree as et | |
from bz2file import BZ2File | |
from lxml.etree import tostring | |
path = "<path-to-osm.bz2-dir>/planet.osm.bz2" | |
path_nodes = "<path-to-osm.bz2-dir>/planet_nodes.osm" | |
str = ''; | |
with BZ2File(path) as xml_file: | |
with open(path_nodes, 'w') as f: | |
f.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") | |
f.write("<osm>") | |
parser = et.iterparse(xml_file, events=('end',)) | |
for events, elem in parser: | |
if elem.tag == "node": | |
str = str + tostring(elem); | |
f.write(str) | |
f.write("</osm>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write event is taking place, now, only once for all the looped elements.