From OpenStreetMap Wiki
Jump to navigation Jump to search


I tried to extract some data from an .Osm File. -.-you can run a demo-command here at

So I have something like this: [QUOTE]

 "tags": {
   "addr:city": "Barcelona",
   "addr:housenumber": "1",
   "addr:postcode": "08022",
   "addr:street": "Carrer de Torras i Pujalt",
   "amenity": "hospital",
   "contact:email": "",
   "contact:fax": "+34 932124050",
   "contact:phone": "+34 932122300",
   "contact:website": "",
   "name": "Cliníca Sagrada Família"


So, the question is this: how can store all those values I tried to make some kind of foreach without sucess. And definitely I don't know why is suposse we have one Iteration that get all the values and why is not possible to store together.

Well i heard about that we can use SimpleXMLElement::xpath here to get all the values and the corresponding values. For example : [CODE] $raw = <<<EOF <root> {

 "type": "node",
 "id": 583257940,
 "lat": 41.4134446,
 "lon": 2.1426945,
 "tags": {
   "amenity": "hospital",
   "emergency": "yes",
   "name": "Clinica Delfos"

}, {

 "type": "node",
 "id": 618312181,
 "lat": 41.4138593,
 "lon": 2.1970778,
 "tags": {
   "addr:city": "Barcelona",
   "addr:housenumber": "211",
   "addr:postcode": "08020",
   "addr:street": "Carrer de Fluvià",
   "amenity": "hospital",
   "health_facility:type": "health_centre",
   "medical_system:western": "yes",
   "name": "CAP Sant Martí",
   "phone": "+93 307 07 66"

}, {

 "type": "node",
 "id": 876348001,
 "lat": 41.3841883,
 "lon": 2.1952253,
 "tags": {
   "amenity": "hospital",
   "emergency": "yes",
   "name": "Hospital del Mar",
   "website": "",
   "wheelchair": "yes"


</root> EOF; $xml = simplexml_load_string($raw);

foreach($xml->xpath("//way") AS $way){

   $via = $way->xpath("tag[@k='name']/@v")[0];
   foreach($way->nd AS $nd){
       $idnode = $nd["ref"];
       echo $idnode .", ". $via  ."
"; }


how to use SimpleXMLElement::xpath here

btw - you can run a demo-command here at

[CODE] /* This has been generated by the overpass-turbo wizard. The original search was: “hospital in rome”

  • /

[out:json][timeout:25]; // fetch area “” to search in Template:GeocodeArea:rome->.searchArea; // gather results (

 // query part for:rome “hospital”

); // print results out body; >; out skel qt;[/CODE]

then you get lots of results.... question: how to store those results in either excel or mysql?