Diese Website existiert nur weil wir Werbung mit AdSense ausliefern.
Bitte den AdBlocker daher auf dieser Website ausschalten! Danke.

transforming data from xml to csv

Software von und für die Welt.
Antworten
sayhello
Geonewbie
Beiträge: 7
Registriert: Mo 28. Apr 2014, 16:05

transforming data from xml to csv

Beitrag von sayhello » Mo 28. Apr 2014, 20:27

dear geoclub-fans and coder, tr

i do not know if this is the right forum here - but it seems to be so. Well dear Geocache-Experts: i have an issue in transforming data: i run the following code in opverpass-api - see here http://overpass-turbo.eu/

i have the options to export of the data to the following formats

to GeoJSON to GPX to KML

and to get the data from

Overpass API loat them to JOSM laden (only for requests, that give back valid OSM-XML with Metadata) GeoJSON to save it as gist

note - i did not install the overpass-api on my opensuse 13.1 yet. but i am willing to do so.

as for now - running the above mentioned code in the oerpass-api - here. how to treat it to get it exported as csv-formated

hope i was able to provide all the necessary things for a clear and concise question. See the output that needs to be transformed:

Code: Alles auswählen

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="Overpass API">
<note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note>
<meta osm_base="2014-04-27T13:49:02Z"/>

  <node id="297489767" lat="49.4085014" lon="8.6941465">
    <tag k="addr:city" v="Heidelberg"/>
    <tag k="addr:housenumber" v="23"/>
    <tag k="addr:postcode" v="69115"/>
    <tag k="addr:street" v="Sofienstraße"/>
    <tag k="name" v="ARLT"/>
    <tag k="phone" v="+49 6221 20229"/>
    <tag k="shop" v="computer"/>
    <tag k="source" v="survey"/>
    <tag k="website" v="http://www.arlt.com"/>
    <tag k="wheelchair" v="yes"/>
  </node>
  <node id="305144906" lat="49.4060012" lon="8.6929652">
    <tag k="addr:city" v="Heidelberg"/>
    <tag k="addr:country" v="DE"/>
    <tag k="addr:housenumber" v="13-15"/>
    <tag k="addr:postcode" v="69115"/>
    <tag k="addr:state" v="Baden-Württemberg"/>
    <tag k="addr:street" v="Rohrbacher Straße"/>
    <tag k="name" v="Heidel-bike"/>
    <tag k="opening_hours" v="Tu-Fr 10:00-18:30; Sa 10:00-14:00"/>
    <tag k="shop" v="bicycle"/>
    <tag k="website" v="http://www.heidelbike.de/"/>
    <tag k="wheelchair" v="yes"/>
  </node>
  <node id="305963167" lat="49.4139877" lon="8.6924247">
    <tag k="addr:city" v="Heidelberg"/>
    <tag k="addr:country" v="DE"/>
    <tag k="addr:housenumber" v="4"/>
    <tag k="addr:postcode" v="69120"/>
    <tag k="addr:street" v="Brückenstraße"/>
    <tag k="name" v="Buchhandlung Schmitt & Hahn"/>
    <tag k="shop" v="books"/>
    <tag k="wheelchair" v="no"/>

can i transform the data into csv?

Werbung:
sayhello
Geonewbie
Beiträge: 7
Registriert: Mo 28. Apr 2014, 16:05

Re: transforming data from xml to csv

Beitrag von sayhello » Di 29. Apr 2014, 12:30

update; perhaps we can do this like so:

to use Perl for text-mangling - so we can use the XML::Simple module. here's an example of a little script to parse your XML:

Code: Alles auswählen


#!/usr/bin/perl
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;

my $xmlfile = shift || die "Usage: $0 <XML_FILE>\n";

my $ref;
eval {
  $ref = XMLin($xmlfile,
    ForceArray    => 0,
    KeyAttr       => [ ],
    SuppressEmpty => '',
  ) or die "Can't read XML from $xmlfile: $!\n";
};
die $@ if($@);
print Dumper $ref;


Explantion: iterating thru the array/hash it creates the file and helps carving up the data into comma separated lines of data than can be redirected to file.

Benutzeravatar
moenk
Geoadmin
Beiträge: 13324
Registriert: Fr 8. Aug 2003, 19:20
Ingress: Enlightened
Wohnort: 12161 Berlin
Kontaktdaten:

Re: transforming data from xml to csv

Beitrag von moenk » Di 29. Apr 2014, 13:22

Maybe you want to check out GPS-Babel to do this: http://www.gpsbabel.org/htmldoc-develop ... t_osm.html
Bild Denkst Du noch selber oder bist Du schon Schwarm?

Antworten

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder