forum

Home / DeveloperSection / Forums / Send xml file using python

Send xml file using python

Anonymous User249105-Nov-2014

Reading the data from overpass-API, I have no problem getting the basic fields. From the below example, the lat and lon are easily read. What I cannot manage is the read the various tags with K=xxxx, v=yyyyy ; I need to read the one with k="name" so as to build a list of city name, lat, lon.

The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.

<nodeid="31024030"lat="51.0763933"lon="4.7224848">
  <tagk="is_in"v="Antwerpen, Belgium, Europe"/>
  <tagk="is_in:continent"v="Europe"/>
  <tagk="is_in:country"v="Belgium"/>
  <tagk="is_in:province"v="Antwerp"/>
  <tagk="name"v="Heist-op-den-Berg"/>
  <tagk="openGeoDB:auto_update"v="population"/>
  <tagk="openGeoDB:is_in"v="Heist-op-den-Berg,Heist-op-den-Berg,Mechelen,Mechelen,Antwerpen,Antwerpen,Vlaanderen,Vlaanderen,Belgique,Belgique,Europe"/>

Code that I have as yet:
import xml.etree.cElementTree as ET
tree = ET.parse('target.osm')
root = tree.getroot()
allnodes=root.findall('node')
for node in allnodes:
   lat=node.get('lat')
   lon=node.get('lon')
 cityname='' # set default in case proper tag not found
 for tag in node.getiterator():
     print tag.attrib
     # add code here to get the cityname
  print lat,lon,cityname


Updated on 06-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By