You are not logged in.

Announcement

*** NOTICE: forum.openstreetmap.org is being retired. Please request a category for your community in the new ones as soon as possible using this process, which will allow you to propose your community moderators.
Please create new topics on the new site at community.openstreetmap.org. We expect the migration of data will take a few weeks, you can follow its progress here.***

#1 2015-09-13 09:24:27

tagtheworld
Banned
Registered: 2012-04-25
Posts: 236

SimpleXMLElement::xpath - Daten einer OSM-Abfrage behandeln

hallo Community,

von einem  .Osm File. das ich hier über die Abfrage bei turbo-overpass-Api abgefragt habe habe ich folgende DATEN erhalten - http://overpass-turbo.eu/

etwa so etwas hier.... .- und das sind schon die DATEN die ich extrahieren & speichern will:

"tags": {
    "addr:city": "Barcelona",
    "addr:housenumber": "1",
    "addr:postcode": "08022",
    "addr:street": "Carrer de Torras i Pujalt",
    "amenity": "hospital",
    "contact:email": "info@clinicasagradafamilia.com",
    "contact:fax": "+34 932124050",
    "contact:phone": "+34 932122300",
    "contact:website": "http://csf.com.es/",
    "name": "Cliníca Sagrada Família"
  }

darüber hinaus sind noch viele andere Daten dabei - in dem xml-file. Die brauch ich nicht.




Ich denk dass das Tool der Wahl hier SimpleXMLElement::xpath ist - um die o.g. Werte zu erhalten:

$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": "http://www.parcdesalutmar.cat/hospitals … index.html",
    "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  ."<br>";
    }
}

Die Frage ist wie genau ich hier SimpleXMLElement::xpath einsetze?

Ein demo-Befehl zeigt eine komplette Ausgabe hier http://overpass-turbo.eu/

/*
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
{{geocodeArea:rome}}->.searchArea;
// gather results
(
  // query part for:rome “hospital”
  node["amenity"="hospital"](area.searchArea);
  way["amenity"="hospital"](area.searchArea);
  relation["amenity"="hospital"](area.searchArea);
);
// print results
out body;
>;
out skel qt;

Dann gibt es die resultate:

Frage; wie speichere ich obiges Datenset in entweder excel oder mysql?


https://wiki.openstreetmap.org/wiki/User:Tagtheworld - interested in all things concerning osm especially those related to the languages Perl, PHP, Python and the databases MySQL and Postgresql.

Offline

#2 2015-09-13 09:32:57

Harald Hartmann
Member
From: 98667 Schönbrunn
Registered: 2014-04-02
Posts: 3,123
Website

Re: SimpleXMLElement::xpath - Daten einer OSM-Abfrage behandeln

Um Gottes willen ... NEIN ... bitte hier nochmal ins Selbststudium gehen und sich in die Thematik XML und JSON einarbeiten!
oder einfach das output von overpass auf xml umstellen, dann kannst du auch gerne mit xpath drauf rumheizen

Nachtrag: hab's mir zwar noch nicht näher angeschaut, aber vielleicht wäre es einfacher, das JSON in eine PHP Variable per json-decode umzuwandeln, dann kannst du objektorientiert auf deine ganzen Tags zugreifen.

Last edited by Harald Hartmann (2015-09-13 09:39:17)


Mein aktives Gebiet: Gemeinde Schleusegrund
Fingerprint meines Schlüssels: 71F7 3CD9 B647 9079 6B88 326E 8B8B 72AE 34F9 5AAD

Offline

#3 2015-09-13 12:46:54

ikonor
Member
Registered: 2010-11-08
Posts: 637
Website

Re: SimpleXMLElement::xpath - Daten einer OSM-Abfrage behandeln

tagtheworld wrote:

Bitte den Link aus "Teilen" (zweiter Menüpunkt oben) zu einer Abfrage verwenden, dieser zeigt nur auf die Startseite, ohne Deine Abfrage.

tagtheworld wrote:

[...] - in dem xml-file.
Ich denk dass das Tool der Wahl hier SimpleXMLElement::xpath ist - um die o.g. Werte zu erhalten:
[...]

[out:json][timeout:25];

Wie Harald schon gesagt hat, ist das Ergebnis bei [out:json] im JSON Format, nicht XML, siehe:
Overpass QL: Output Format (out)
http://overpass-api.de/output_formats.html

Bei http://www.json.org/ gibt es Links für jede Programmiersprache.

Standard ist XML, wenn kein [out:xxx] angegeben ist, oder eben explizit [out:xml].

tagtheworld wrote:

Frage; wie speichere ich obiges Datenset in entweder excel oder mysql?

Am einfachsten wäre dafür vermutlich das CSV Format: CSV output mode

Gruß,
Norbert

Offline

#4 2015-09-13 13:57:30

tagtheworld
Banned
Registered: 2012-04-25
Posts: 236

Re: SimpleXMLElement::xpath - Daten einer OSM-Abfrage behandeln

hallo Harald, hallo Norbert

vielen Dank für die Informationen - das stimmt alles -
hab mir das nochmals angesehen - csv waere das allereinfachste! Ganz sicher!

das hier - http://overpass-turbo.eu/s/bpX geht aber nicht! Leider  - csv geht nur über umwege.

ganz hingegen dies hier http://overpass-turbo.eu/s/bpY  - mit json als ausgabe-Format

ergo muss ich hier noch umdenken .- und den Code irgendwie erweitern - mit den Infos hieraus
http://wiki.openstreetmap.org/wiki/Over … _.28out.29


This has been generated by the overpass-turbo wizard.
The original search was:
“hospital in rome”
*/
[out:csv][timeout:25];
// fetch area “” to search in
{{geocodeArea:rome}}->.searchArea;
// gather results
(
  // query part for:rome “hospital”
  node["amenity"="hospital"](area.searchArea);
  way["amenity"="hospital"](area.searchArea);
  relation["amenity"="hospital"](area.searchArea);
);
// print results
out body;
>;
out skel qt;

geht so nicht - aber ich werde nochmals nachsehen ob ich da noch etwas machen kann.

Danke für Eure Hilfe

viele Grüße

Last edited by tagtheworld (2015-09-13 14:01:51)


https://wiki.openstreetmap.org/wiki/User:Tagtheworld - interested in all things concerning osm especially those related to the languages Perl, PHP, Python and the databases MySQL and Postgresql.

Offline

#5 2015-09-13 14:00:40

ikonor
Member
Registered: 2010-11-08
Posts: 637
Website

Re: SimpleXMLElement::xpath - Daten einer OSM-Abfrage behandeln

Bei csv musst Du noch explizit angeben, welche Felder Du haben willst, siehe Beschreibung unter "CSV output mode" bei obigem Link.

Offline

#6 2015-09-13 14:06:57

tagtheworld
Banned
Registered: 2012-04-25
Posts: 236

Re: SimpleXMLElement::xpath - Daten einer OSM-Abfrage behandeln

hallo Ikonor

danke für deinen Hinweis - ergo so;:

[out:csv(::"id", amenity, name, operator, opening_hours, "contact:website", "contact:phone", brand, dispensing, lastcheck)];

und hier werde ich all die für mich wichtigen Daten / values einfügen

"tags": {
    "addr:city": "Barcelona",
    "addr:housenumber": "1",
    "addr:postcode": "08022",
    "addr:street": "Carrer de Torras i Pujalt",
    "amenity": "hospital",
    "contact:email": "info@clinicasagradafamilia.com",
    "contact:fax": "+34 932124050",
    "contact:phone": "+34 932122300",
    "contact:website": "http://csf.com.es/",
    "name": "Cliníca Sagrada Família"
  }


analog dazu - wie sie das auf der wiki-Beispielseite gemacht haben -zum Beispiel hier: Railway stations in Bonn:


[out:csv(::id,::type,"name")];
area[name="Bonn"]->.a;
( node(area.a)[railway=station];
  way(area.a)[railway=station];
  rel(area.a)[railway=station]; );
out;


werde das mal auf mein Beispiel anzuwenden versuchen......Vielen Dank schonmal.


update:

habe das schon mal an einem beispiel ausprobiert:

mit diesem Beispielcode --...

[out:csv(::id,::type,"name")];
area[name="Paris"]->.a;
( node(area.a)[railway=station];
  way(area.a)[railway=station];
  rel(area.a)[railway=station]; );
out;

das ergebins :

jetzt werde ich das nur noch auf mein oben genanntes Problem anwenden!?


@id    @type    name
21310914    node    Denfert-Rochereau
26721276    node    Pont Cardinet
26824135    node    Gare de Lyon
27362240    node    Argentine
27362249    node    George V
27362251    node    Franklin D. Roosevelt
27362256    node    Concorde
27362258    node    Tuileries
27362259    node    Palais Royal - Musée du Louvre
27362260    node    Louvre — Rivoli
27371862    node    Châtelet
27371864    node    Hôtel de Ville
27371867    node    Saint-Paul
27371876    node    Bastille
27371889    node    Gare de Lyon (métro 1)
27371892    node    Reuilly — Diderot
27371900    node    Porte de Vincennes
34909170    node    La Motte-Picquet - Grenelle
34909171    node    Cambronne
34909187    node    Dupleix
65331500    node    Gare Montparnasse
134305192    node    Porte de Versailles
134305198    node    Convention
154788912    node    Invalides
220289379    node    Porte d'Orléans
220289382    node    Alésia
220289385    node    Mouton-Duvernet
220289387    node    Denfert-Rochereau
220289389    node    Raspail
235369898    node    Saint-Jacques
235370184    node    Glacière
235370505    node    Corvisart
235371392    node    Place d'Italie
235371394    node    Nationale
235371395    node    Chevaleret
235374383    node    Quai de la Gare
235377792    node    Stalingrad
241928557    node    Nation
243357000    node    Buttes Chaumont
243358029    node    Bolivar
243486950    node    Buzenval
243489718    node    Avron
243490761    node    Ménilmontant
243490762    node    Père Lachaise
243490763    node    Philippe Auguste
243490764    node    Alexandre Dumas
243493845    node    Belleville
243493846    node    Couronnes
243493916    node    Colonel Fabien
243496024    node    Pigalle
243496025    node    Blanche
243496027    node    Place de Clichy
243496028    node    Rome
243496029    node    Villiers
243496030    node    Monceau
243496033    node    Charles de Gaulle — Étoile (metro)
243496728    node    Victor Hugo
243496729    node    Porte Dauphine
243507234    node    Porte de Bagnolet
243507235    node    Gambetta
243507789    node    Rue Saint-Maur
243507790    node    Parmentier
243507792    node    Temple
243507793    node    Arts et Métiers
243507794    node    Réaumur - Sébastopol
243510334    node    Bourse
243510335    node    Quatre Septembre
243510336    node    Opéra
243510337    node    Havre - Caumartin
243510678    node    Malesherbes
243510679    node    Wagram
243510680    node    Péreire
243510681    node    Porte de Champerret
244494486    node    Vaugirard
244494489    node    Volontaires
244494496    node    Falguière
245250755    node    Duroc
245250758    node    Saint-François-Xavier
245250759    node    Varenne
245455187    node    Bel-Air
249335596    node    Marx Dormoy
251387813    node    Jacques Bonsergent
256441194    node    Maraîchers
256442276    node    Porte de Montreuil
256443205    node    Rue des Boulets
256443438    node    Charonne
256895321    node    Voltaire
256895609    node    Saint-Ambroise
256896059    node    Oberkampf
256897077    node    Strasbourg - Saint-Denis
256897078    node    Bonne Nouvelle
256897079    node    Grands Boulevards
256897080    node    Richelieu Drouot
256897458    node    Chaussée d'Antin - La Fayette
256897554    node    Saint-Augustin
260040968    node    Jussieu
260078615    node    Cardinal Lemoine
260078619    node    Maubert Mutualité
260078622    node    Cluny - La Sorbonne
260079008    node    Odéon
260079322    node    Mabillon
260231828    node    Balard
260231831    node    Lourmel
260231832    node    Boucicaut
260231833    node    Félix Faure
260762378    node    Dugommier
260762379    node    Daumesnil
260762540    node    Bercy
260763474    node    Edgar Quinet
260764273    node    Pasteur
260765385    node    Kléber
260765387    node    Boissière
260765389    node    Trocadéro
260765390    node    Passy
260767422    node    Iéna
260767423    node    Rue de la Pompe
260767424    node    La Muette
260767425    node    Ranelagh
260767426    node    Jasmin
260767427    node    Michel-Ange - Auteuil
260767428    node    Michel-Ange - Molitor
260767429    node    Exelmans
260767430    node    Porte de Saint-Cloud
260769132    node    Alma-Marceau
260769651    node    Saint-Philippe du Roule
260769652    node    Miromesnil
261162833    node    Sèvres-Babylone
261611873    node    Porte de Clichy
261611884    node    Brochant
261612240    node    La Fourche
261665825    node    Ségur
261666122    node    Avenue Émile Zola
263497271    node    Assemblée Nationale
263497272    node    Solférino
263499468    node    Rennes
263499471    node    Notre-Dame des Champs
263917856    node    Concorde
264117312    node    Madeleine
264469160    node    Commerce
264469541    node    École Militaire
264473011    node    La Tour Maubourg
264473695    node    Invalides
264476971    node    Filles du Calvaire
264479724    node    Saint-Sébastien - Froissart
264479775    node    Chemin Vert
264480619    node    Bastille
264480784    node    Ledru-Rollin
264481019    node    Faidherbe — Chaligny
264481854    node    Montgallet
264482226    node    Michel Bizot
264482297    node    Porte Dorée
264490283    node    Picpus
264491193    node    Olympiades
264491320    node    Porte de Charenton
264494507    node    Pyramides
264495077    node    Trinité d'Estienne d'Orves
264495078    node    Notre-Dame de Lorette
264495553    node    Rue du Bac
264504832    node    Saint-Georges
264505115    node    Abbesses
264505153    node    Lamarck - Caulaincourt
264505450    node    Jules Joffrin
264505930    node    Porte de la Chapelle
264505993    node    Simplon
264507100    node    Château Rouge
264508125    node    Gare du Nord (métro)
264508548    node    Gare de l'Est
264509793    node    Étienne Marcel
264512252    node    Château d'Eau
264513655    node    Les Halles
264514896    node    Cité
264515098    node    Saint-Michel
264519782    node    Saint-Germain-des-Prés
264520061    node    Saint-Placide
264526095    node    Vavin
264534423    node    Charles Michels / 10
264534424    node    Javel - André Citroën
264534683    node    Église d'Auteuil
264535735    node    Porte d'Auteuil
264537727    node    Chardon Lagache
264538576    node    Mirabeau
264591604    node    Goncourt
264592424    node    Rambuteau
264690368    node    Porte des Lilas
264690370    node    Télégraphe
264690372    node    Pyrénées
264692522    node    Jourdain
264704365    node    Gaîté
264712432    node    Plaisance
264712433    node    Pernety
264769296    node    Bréguet-Sabin
264769297    node    Richard Lenoir
264772256    node    Laumière
264772371    node    Ourcq
264772861    node    Porte de Pantin
264775552    node    Louis Blanc
264775805    node    Poissonnière
264776028    node    Riquet
264776029    node    Crimée
264776910    node    Corentin Cariou
264778142    node    Porte de la Villette
264780946    node    Le Peletier
264780947    node    Cadet
264784170    node    Pont Neuf
264785951    node    Sully - Morland
264785952    node    Pont Marie
264786014    node    Place Monge
264789025    node    Censier - Daubenton
264790337    node    Les Gobelins
264794353    node    Pré Saint-Gervais
264794354    node    Danube
264796181    node    Saint-Fargeau
264796182    node    Pelleport
265055434    node    Saint-Marcel
265055750    node    Campo-Formio
265060052    node    Guy Môquet
265060832    node    Porte de Saint-Ouen
267619085    node    Boulainvilliers
268467197    node    Tolbiac
268467526    node    Maison Blanche
268467559    node    Porte d'Italie
282635141    node    Champs-Élysées - Clemenceau
324352448    node    Saint-Sulpice
324363999    node    Montparnasse-Bienvenüe
326309672    node    Château Landon
327432580    node    Port Royal
327432589    node    Luxembourg
327613695    node    Gare du Nord (RER)
329974472    node    Magenta
329974475    node    Haussmann - Saint-Lazare
331514770    node    Liège
338930214    node    Bir-Hakeim
354969611    node    Auber
472985883    node    Porte de Choisy
472985884    node    Porte d'Ivry
473070143    node    Vaneau
838533003    node    Ternes
942695829    node    Gare Montparnasse 3 - Vaugirard
1308998006    node    Gare de Lyon RER D
1309031698    node    Gare de Lyon RER A
1480535477    node    Barbès - Rochechouart
1481147746    node    Marcadet - Poissonniers
1489806669    node    Concorde
1489806675    node    Invalides
1584432760    node    Bastille
1656938775    node    Gare de Lyon
1659843199    node    Sèvres-Lecourbe
1731763792    node    Charles de Gaulle — Étoile (RER)
1731763794    node    Nation (RER)
1780486821    node    Porte de Clignancourt
1805529567    node    Montparnasse-Bienvenüe
1823210835    node    Paris-Bercy
1981222779    node    Europe
1997626380    node    Porte des Lilas
1997722983    node    Botzaris
1997722992    node    Jaurès
2023231831    node    Porte de Vanves
2066461402    node    Place des Fêtes
2066488458    node    Courcelles
2355666875    node    Avenue du Président Kennedy
2379542204    node    Musée d'Orsay
2489972624    node    Javel
2493410447    node    Porte Maillot
2506241285    node    Gare de l'Est
2582044619    node    Philippe Auguste
2656855599    node    Cité Universitaire
3090733718    node    Gare du Nord
3146958064    node    Cour Saint-Émilion
3190883103    node    Châtelet-les-Halles
3197007911    node    République
3325110405    node    Bibliothèque François Mitterrand
3414141478    node    Champ de Mars - Tour Eiffel
3414141480    node    Pont de l'Alma
3417692493    node    Anvers
3417692497    node    Funiculaire Montmartre - Station Inférieure
3417692499    node    Funiculaire Montmartre - Station Supérieure
3417692501    node    La Chapelle
3419908160    node    Paris-Austerlitz
3419908164    node    Quai de la Rapée
3430515272    node    Sentier
3493828493    node    Avenue Foch
3493828593    node    Avenue Henri Martin
3493828793    node    Gare d'Austerlitz
3493829093    node    Péreire Levallois
3530939196    node    Pont Cardinet
3530939197    node    Porte de Clichy
3533789791    node    Gare Saint-Lazare
3542631493    node    Saint-Lazare
3572156993    node    Saint-Michel Notre Dame
3574677130    node    Pont du Garigliano - Hôpital européen Georges-Pompidou
3580789992    node    Neuilly - Porte Maillot
1266299    relation    Bourse
4206259    relation    République

Last edited by tagtheworld (2015-09-13 15:31:32)


https://wiki.openstreetmap.org/wiki/User:Tagtheworld - interested in all things concerning osm especially those related to the languages Perl, PHP, Python and the databases MySQL and Postgresql.

Offline

#7 2015-09-13 15:43:52

tagtheworld
Banned
Registered: 2012-04-25
Posts: 236

Re: SimpleXMLElement::xpath - Daten einer OSM-Abfrage behandeln

hallo liebe Community


also ich hab mal einiges probiert: analog der unten genannten Anleitung -

http://wiki.openstreetmap.org/wiki/DE:P … Healthcare

geht mit dem beispiel hier beies nicht:

healthcare=clinic
healthcare=hospital
replaes amenity = hospital


d,h. wenn ich das umbaue und dann für railway=station folgendes einsetzte
healthcare=clinic oder auch
healthcare=hospital

dann geht das nicht - warum weiß ich im Moment auch noch nicht

also wenn ich ausgehend von dem Beispiel hier


[out:csv(::id,::type,"name")];
area[name="Paris"]->.a;

( node(area.a)[railway=station];
  way(area.a)[railway=station];
  rel(area.a)[railway=station]; );
out;



dann folgendes mache und es so schreibe



[out:csv(::id,::type,"name")];
area[name="Paris"]->.a;

( node(area.a)[healthcare=clinic];
  way(area.a)[healthcare=clinic];
  rel(area.a)[healthcare=clinic]; );
out;


das geht nicht - - auch nicht mit healthcare=hospital


ich denke dass ich hier einen Gedankenfehler aufsitze


https://wiki.openstreetmap.org/wiki/User:Tagtheworld - interested in all things concerning osm especially those related to the languages Perl, PHP, Python and the databases MySQL and Postgresql.

Offline

#8 2015-09-13 16:40:20

kkulach
Member
From: Dortmund
Registered: 2015-09-02
Posts: 9
Website

Re: SimpleXMLElement::xpath - Daten einer OSM-Abfrage behandeln

Huhuuuu,

Wenn du bei XML bleiben willst, ein kleiner Hinweis  / Tipp  :

Das Problem bei simplexml ist, dass du schnell an die Speichergrenze stößt, die dem PHP Interpreter zur Verfügung steht. Bis zu einem gewissen Grad kann man da nachhelfen, aber nicht unendlich.

Bei einfacheren Abfragen gegen Overpass ist das sicher in Ordnung.

Sobald es aber mehr Daten werden (Ob Overpass oder direkt aus einem OSM - File), kann entweder der Speicher knapp oder die Performance grauenhaft werden - da das gesammte XML bei simplexml_load_* geparst und als Objekt im Speicher angelegt wird. Erlaubt zwar den einfachen Zugriff, verbraucht aber mehr Ressourcen.

Du solltest vielleicht darüber nachdenken, einen SAX - Parser zu verwenden, auch wenn du ihn jetzt noch nicht unbedingt brauchst - Wenn dein Projekt wächst, bist du für alles gewappnet smile  .

Ich habe für das Skript, welches die POIs für poiowl.de filtert, auch einen verwendet. Alles übrigens auf einem Raspberry Pi, der Speicherverbrauch vom SAX Parser kann sich sehen lassen (Obschon es nur ein einfacher Anwendungsfall ist, aber ich verarbeite das OSM - File pro Land damit) !  smile

Viele Grüße!

Offline

Board footer

Powered by FluxBB