CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
using XML::Twig and DBI to store a xml-file into a myql-db

 



dilbert
User

May 25, 2014, 9:58 AM

Post #1 of 11 (8600 views)
using XML::Twig and DBI to store a xml-file into a myql-db Can't Post

hello dear perl-fans

i have a xml-file that comes out of a osm-parser - it is formatted in xml:
which method fits if i want to store the output of this request to a mysql database:

http://overpass-turbo.eu

see the output here



Code
<node id="2064639440" lat="49.4873181" lon="8.4710548"> 
<tag k="amenity" v="restaurant"/>
<tag k="cuisine" v="turkish"/>
<tag k="email" v="info@lynso.de"/>
<tag k="name" v="Kilim - Café und Bar Restaurant"/>
<tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/>
<tag k="operator" v="Cengiz Kaya"/>
<tag k="phone" v="06 21 - 43 755 371"/>
<tag k="website" v="http://www.kilim-mannheim.de/"/>
</node>
<node id="2126473801" lat="49.4851170" lon="8.4756295">
<tag k="amenity" v="restaurant"/>
<tag k="cuisine" v="italian"/>
<tag k="email" v="mannheim1@vapiano.de"/>
<tag k="fax" v="+49 621 1259 779"/>
<tag k="name" v="Vapiano"/>
<tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/>
<tag k="operator" v="Vapiano"/>
<tag k="phone" v="+49 621 1259 777"/>
<tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/>
<tag k="wheelchair" v="yes"/>
</node>


how can this be done? note we have the fild names and all the set of the datbase is clear. the question is - how to put the data into the database?




Code
 
#!/usr/bin/perl
use strict ;
use DBI;
use XML::Twig;

# prepare database
my $dbh=dbh(); # connect
init();
$dbh->do('USE db123');
#$dbh->do('DELETE FROM pois');

# sql
my $sql = 'REPLACE INTO pois VALUES (?,?,?,?,?,?)';
my $sth = $dbh->prepare($sql);

# set up handler
my $t = XML::Twig->new(
twig_handlers => { 'node' => \&node }
);

# parse xml
my $xml = do { local $/; <DATA> };
$t->parse($xml);
#$t->parsefile('.osm');

sub node {
my ($t,$elt) = @_;

my %data=(
'id' => $elt->att('id'),
'lat' => $elt->att('lat'),
'lon' => $elt->att('lon'),
);
for my $tag ( $elt->children() ){
$data{$tag->att('k')} = $tag->att('v');
#print $tag->att('k').' = '.$tag->att('v')."\n";
}

# update database
my @f = map{ $data{$_} }('id','lat','lon','name','amenity','operator');
if ($f[3] ne '' && $f[4] ne '' && $f[5] ne ''){
print "-- INSERT --\n".
(join "\n",@f).
"\n\n";
$sth->execute(@f);
}
}


sub init {
$dbh-> do('CREATE DATABASE IF NOT EXISTS db123
DEFAULT CHARACTER SET latin1
COLLATE latin1_german2_ci');
$dbh->do('USE db123');
$dbh->do('CREATE TABLE IF NOT EXISTS pois (
id BIGINT(20) UNSIGNED NOT NULL,
lat FLOAT(10,7) NOT NULL,
lon FLOAT(10,7) NOT NULL,
name VARCHAR(255) COLLATE utf8_bin NOT NULL,
amenity VARCHAR(255) COLLATE utf8_bin NOT NULL,
operator VARCHAR(255) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT
CHARSET=utf8
COLLATE=utf8_bin');
}

sub dbh {
my $dsn = "DBI:mysql:database=;host=localhost";
my $dbh = DBI->connect($dsn, 'user', 'pwd',
{RaiseError => 1, PrintError => 1})
or die (Error connecting " $DBI::errstr");
}


by the way - see the data again :


Code
__DATA__ 
<?xml version='1.0' encoding='UTF-8'?>
<osm>
<node id="2064639440" lat="49.4873181" lon="8.4710548">
<tag k="amenity" v="restaurant"/>
<tag k="cuisine" v="turkish"/>
<tag k="email" v="info@lynso.de"/>
<tag k="name" v="Kilim - Cafe und Bar Restaurant"/>
<tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/>
<tag k="operator" v="Cengiz Kaya"/>
<tag k="phone" v="06 21 - 43 755 371"/>
<tag k="website" v="http://www.kilim-mannheim.de/"/>
</node>
<node id="2126473801" lat="49.4851170" lon="8.4756295">
<tag k="amenity" v="restaurant"/>
<tag k="cuisine" v="italian"/>
<tag k="email" v="mannheim1@vapiano.de"/>
<tag k="fax" v="+49 621 1259 779"/>
<tag k="name" v="Vapiano"/>
<tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/>
<tag k="operator" v="Vapiano"/>
<tag k="phone" v="+49 621 1259 777"/>
<tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/>
<tag k="wheelchair" v="yes"/>
</node>
</osm>



FishMonger
Veteran / Moderator

May 25, 2014, 10:18 AM

Post #2 of 11 (8591 views)
Re: [dilbert] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post


Quote
the question is - how to put the data into the database?


Use an INSERT statement.

If that's not the answer you're looking for, then you'll need to rephrase your question.


dilbert
User

May 25, 2014, 10:44 AM

Post #3 of 11 (8580 views)
Re: [FishMonger] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post

hello dear fishmonger, :)


first of alll many many thanks for the hint. great to hear that.
You helped me alot!!!!


btw - final questions:



if i want to extend the fields of the db - i can extend the following line...


Code
  # update database  
my @f = map{ $data{$_} }('id','lat','lon','name','amenity','operator')



so - in other words. if i need more fields in the database - for the POI (that is the
dataset that i get from the planet-file) then i extend the above mentioned code-line!?



.... and some final questions:

- at which position is the insert-statement?
- and - very important;: how !! do i call the files - the xml-files

note: i have a very very big xml-file.
How to call this?
it is stored in the same folder like the above mentioned script.


dear Fishmonger - i look forward to hear from you:

if you can give some hints and answers to the above mentioned questions - i would be very very glad!


one last and final question: i do lots of work with PHP
therfore i have installed an
Apache
Mysql
PHPMyadmin on my opensuse 13.1

all works great!!
[ and the phpmyadmin is allso available http://localhost/phpMyAdmin/ ]

Question - the allready installed mysql database can be usef for the perl-job too, can ´t it!?



and i will do as adviced :: i will correct the initial posting - do as you adviced and come back to report all the findingsSmile


(This post was edited by dilbert on May 25, 2014, 11:20 AM)


FishMonger
Veteran / Moderator

May 26, 2014, 7:49 AM

Post #4 of 11 (8532 views)
Re: [dilbert] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post

You need to rephrase your questions because most of them don't make much sense.


dilbert
User

May 26, 2014, 11:00 AM

Post #5 of 11 (8460 views)
Re: [FishMonger] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post

hello and good evening dear fishmonger,


many many thanks for your quick reply. great to hear from you.

after re-reading the thread i think i have to make clear what i want to do: well - some final questions are the followings - that reflect the perl-code that you see above.

see the perl-code - note: i am pretty new to Perl.



btw - what bout the fields of the db


Code
# update database   
my @f = map{ $data{$_} }('id','lat','lon','name','amenity','operator')



so - in other words. if i need more fields in the database - for the POI (that is the dataset that i get from the planet-file) then i extend the above mentioned code-line!? is this correct!? Can i do so!? i guess


btw - all the ideas of getting the data out of the planet file are derived from two sites that inspired me.

what i aim is to have a perl sciript that helps me to the data stored that i gatherd out of the request of www.overpass-turbo.eu
(a method to request the openstreetpap). Therefore i have a Perl program that reads XML data and posts it into a MySQL database.



some thougts that are important:

what IS AIMED: aimed is to transform data out of German osm-pbf-files - in order to get the data (not to creat maps again)

see the source (s)= http://download.geofabrik.de/europe/germany.html ranging form 10 MB (Bremen) to 390 MB (Nordrhein Westfalen) the osm.pbf-files are not too big; Question: which method is the best - the most appropiate? - to store the results in a mysql-db or just have big calc-sheets (with csv-data)

- only straightforward from files that
- no backimport of data to OSM from a .csv file


i am inspired by the pages:


first page:

http://oegeo.wordpress.com/2012/03/06/a-self-updating-openstreetmap-database-of-us-bridges-a-step-by-step-guide/


note this guy makes usage of postgis. - perhaps i start with mysql - or postgresql - since i do not need maps in the end- i only need
the text-data - for the pois - no mapping data for rebuilding maps again...


the second inspiration: http://wiki.openstreetmap.org/wiki/User:Brogo/OpenLayers_Datenbankanbindung

see the ideas of database connecting to osm - with perl


Code
CREATE DATABASE `db123` DEFAULT CHARACTER SET latin1 COLLATE latin1_german2_ci; 
USE hans;

CREATE TABLE `pois` (
`id` BIGINT(20) UNSIGNED NOT NULL,
`lat` FLOAT(10,7) NOT NULL,
`lon` FLOAT(10,7) NOT NULL,
`name` VARCHAR(255) COLLATE utf8_bin NOT NULL,
`amenity` VARCHAR(255) COLLATE utf8_bin NOT NULL,
`operator` VARCHAR(255) COLLATE utf8_bin NOT NULL,
`vending` VARCHAR(255) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;


see the code



Code
#!/usr/bin/perl -w 

use strict ;
use OSM::osm ;

my $file ;
my $nodeUser ;
my @nodeTags ;
my $nodeTags ;
my $ref1 ;
my $line ;
my $tag;
my $nodeName;

my $id ="1" ;
my $lat ;
my $lon ;
my $name ;
my $amenity ;
my $operator ;
my $vending;


$file = "c:/osm/planet/pois.osm" ;

openOsmFile ($file) ;
open(AUSGABE, ">c:/osm/planet/mysql.txt");
($id, $lon, $lat, $nodeUser, $ref1) = getNode2 () ;

while ($id != -1 ) {
$name ="" ;
$amenity ="" ;
$operator ="" ;
$vending ="" ;

@nodeTags = @$ref1;
foreach my $tag (@nodeTags) {
if ($tag->[0] eq "name") { $name = scalar ($tag->[1] )};
if ($tag->[0] eq "amenity") { $amenity = scalar ($tag->[1] )};
if ($tag->[0] eq "operator") { $operator = scalar ($tag->[1] )};
if ($tag->[0] eq "vending") { $vending = scalar ($tag->[1] )}
}
if ($name ne "" | $amenity ne "" | $operator ne"" | $vending ne"")
{print AUSGABE "$id^$lat^$lon^$name^$amenity^$operator^$vending\n";}
($id, $lon, $lat, $nodeUser, $ref1) = getNode2 () ;

}
close(AUSGABE);
closeOsmFile () ;




well dear fishmonger - how do you find these ideas.

i want to follow only one goal: what IS AIMED: aimed is to transform data out of German osm-pbf-files - in order to get the data (not to creat maps again)

see the source (s)= http://download.geofabrik.de/europe/germany.html ranging form 10 MB (Bremen) to 390 MB (Nordrhein Westfalen) the osm.pbf-files are not too big; Question: which method is the best - the most appropiate? - to store the results in a mysql-db or just have big calc-sheets (with csv-data)

- only straightforward from files that
- no backimport of data to OSM from a .csv file


so i hope that i am able to spell out what i want to do - and what is aimed.

love to hear from you

greetings
Smile


Laurent_R
Veteran / Moderator

May 27, 2014, 10:36 AM

Post #6 of 11 (7954 views)
Re: [dilbert] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post

Hi,

a couple of stylistic comments on your code. It is good that you have the "use strict;" pragma, it would be good to remove the "-w" flag and replace it by the "use warnings;" pragma. This is much more flexible.

The second thing is that you should probably not declare all your variables at the top of your script, but only within the scope where they are needed. For example, you could have:


Code
my $file = "c:/osm/planet/pois.osm" ;  

openOsmFile ($file) ;
open(AUSGABE, ">c:/osm/planet/mysql.txt");
my ($id, $lon, $lat, $nodeUser, $ref1) = getNode2 () ;

while ($id != -1 ) {
my $name ="" ;
my $amenity ="" ;
my $operator ="" ;
my $vending ="" ;

my @nodeTags = @$ref1;
# ...


An additional remark is that, when you open a file, you should always check whether the opening was successful. Additionally, you should rather use the 3-argument syntax and use lexical filehandlers. So, putting these three points together:


Code
my $outfile = "c:/osm/planet/mysql.txt"; 
open my $AUSGABE, ">", $outfile or die "Could not open file $outfile $!";


You should also probably check the status returned by the openOsmFile() function.


dilbert
User

May 27, 2014, 8:19 PM

Post #7 of 11 (7754 views)
Re: [Laurent_R] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post

hello dear Laurent

many many thanks for all your hints.

i will follow your advices - and try out them

i come back and report all the findings

later the weekend.

greetings

dilbert


dilbert
User

May 29, 2014, 8:02 AM

Post #8 of 11 (7072 views)
Re: [FishMonger] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post

hello dear Fishmonger - and hello dear Laurent,

many many thanks for all your hints!


In Reply To

Quote
the question is - how to put the data into the database?


Use an INSERT statement.

If that's not the answer you're looking for, then you'll need to rephrase your question.



well - very convincing - since i want to put all the data ( that i have in a xml-file) into the mysql db - i need to have a INSERT-Statement.

where to place this INSERT-statement!?


FishMonger
Veteran / Moderator

May 29, 2014, 8:47 AM

Post #9 of 11 (7055 views)
Re: [dilbert] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post


Quote
where to place this INSERT-statement!?


I'm not sure I understand the problem.

I just tested your script and it's inserting/replacing the data correctly as is, so what problem are you having?


(This post was edited by FishMonger on May 29, 2014, 8:47 AM)


dilbert
User

May 30, 2014, 5:17 AM

Post #10 of 11 (6659 views)
Re: [FishMonger] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post

hello dear fishmonger ;-)

many many thanks for the reply - great to hear from you..


some last questions

note; i run linux opensuse 13.1

- mysql is up and running
- the modules i have all

use DBI;
use XML::Twig;



... and i guess that i need furthermore another "library"

this library which is used in this line use OSM::osm ; which is inspired by this page [note German language]: http://wiki.openstreetmap.org/wiki/User:Brogo/OpenLayers_Datenbankanbindung

and this http://svn.openstreetmap.org/applications/utils/gary68/OSM/osm.pm
[This module contains a lot of useful functions for working with osm files and data. it also includes functions for calculation and output.]
http://wiki.openstreetmap.org/wiki/User:Gary68


questions:

where to put this library: http://svn.openstreetmap.org/applications/utils/gary68/OSM/osm.pm should i put it into the folder where i have the following perl scripts:


note: well what i have i have a folder

home/perl where i have the following perl code:

a. osm_to_db.pl
b. create_db.pl


second question: - i am sure that i have to do some corrections;

in the code create_db.pl

a. the first correction:
at the line $file = "c:/osm/planet/pois.osm" ;

b the second correction:
at the line "open(AUSGABE, ">c:/osm/planet/mysql.txt"); "

...since i have no windows but a linux-system....:


below we see the both mentioned script:

a. create_db.pl


Code
  
#!/usr/bin/perl -w

use strict ;
use OSM::osm ;

my $file ;
my $nodeUser ;
my @nodeTags ;
my $nodeTags ;
my $ref1 ;
my $line ;
my $tag;
my $nodeName;

my $id ="1" ;
my $lat ;
my $lon ;
my $name ;
my $amenity ;
my $operator ;
my $vending;

$file = "c:/osm/planet/pois.osm" ;

openOsmFile ($file) ;
open(AUSGABE, ">c:/osm/planet/mysql.txt");
($id, $lon, $lat, $nodeUser, $ref1) = getNode2 () ;

while ($id != -1 ) {
$name ="" ;
$amenity ="" ;
$operator ="" ;
$vending ="" ;

@nodeTags = @$ref1;
foreach my $tag (@nodeTags) {
if ($tag->[0] eq "name") { $name = scalar ($tag->[1] )};
if ($tag->[0] eq "amenity") { $amenity = scalar ($tag->[1] )};
if ($tag->[0] eq "operator") { $operator = scalar ($tag->[1] )};
if ($tag->[0] eq "vending") { $vending = scalar ($tag->[1] )}
}
if ($name ne "" | $amenity ne "" | $operator ne"" | $vending ne"")
{print AUSGABE "$id^$lat^$lon^$name^$amenity^$operator^$vending\n";}
($id, $lon, $lat, $nodeUser, $ref1) = getNode2 () ;

}
close(AUSGABE);
closeOsmFile () ;



and furthermore: b. the code osm_to_db.pl


Code
#!/usr/bin/perl   
use strict ;
use DBI;
use XML::Twig;

# prepare database
my $dbh=dbh(); # connect
init();
$dbh->do('USE db123');
#$dbh->do('DELETE FROM pois');

# sql
my $sql = 'REPLACE INTO pois VALUES (?,?,?,?,?,?)';
my $sth = $dbh->prepare($sql);

# set up handler
my $t = XML::Twig->new(
twig_handlers => { 'node' => \&node }
);

# parse xml
my $xml = do { local $/; <DATA> };
$t->parse($xml);
#$t->parsefile('.osm');

sub node {
my ($t,$elt) = @_;

my %data=(
'id' => $elt->att('id'),
'lat' => $elt->att('lat'),
'lon' => $elt->att('lon'),
);
for my $tag ( $elt->children() ){
$data{$tag->att('k')} = $tag->att('v');
#print $tag->att('k').' = '.$tag->att('v')."\n";
}

# update database
my @f = map{ $data{$_} }('id','lat','lon','name','amenity','operator');
if ($f[3] ne '' && $f[4] ne '' && $f[5] ne ''){
print "-- INSERT --\n".
(join "\n",@f).
"\n\n";
$sth->execute(@f);
}
}


sub init {
$dbh-> do('CREATE DATABASE IF NOT EXISTS db123
DEFAULT CHARACTER SET latin1
COLLATE latin1_german2_ci');
$dbh->do('USE db123');
$dbh->do('CREATE TABLE IF NOT EXISTS pois (
id BIGINT(20) UNSIGNED NOT NULL,
lat FLOAT(10,7) NOT NULL,
lon FLOAT(10,7) NOT NULL,
name VARCHAR(255) COLLATE utf8_bin NOT NULL,
amenity VARCHAR(255) COLLATE utf8_bin NOT NULL,
operator VARCHAR(255) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT
CHARSET=utf8
COLLATE=utf8_bin');
}

sub dbh {
my $dsn = "DBI:mysql:database=;host=localhost";
my $dbh = DBI->connect($dsn, 'user', 'pwd',
{RaiseError => 1, PrintError => 1})
or die (Error connecting " $DBI::errstr");
}


see the dataset; - which is stored in the file mysql.txt

the dataset - it is gathered from the request on the overpass-api which resides here http://www.overpass-turbo.eu

cf. http://overpass-turbo.eu/?q=PCEtLQpUaGlzIHF1ZXJ5IGxvb2vEiGZvciBub2Rlcywgd2F5xIhhbmQgcmVsYXRpb27EiAp3aXRoIMS0ZSBnaXZlbiBrZXkvdmFsxIsgY29tYmluxKvErW4uCkNoxJFzxLh5b3XEl8SoxLrEriDEpMSmxIZ0xLZoxLhSdcS-YnV0dMWfYWJvxLwhCsSCPgp7e8WAeT1hbcS9xLN5fX3FuHvFhMWGZT3EqHN0YcWbxKR0xoMKPG9zbS1zY3JpcMWkxZp0cMWsPSJ4bWwixbcgIDzFqcWQxqnGqsarxIrEjMSOdHlwxokixJnEm8aoCsawxrA8aGFzLWt2xL_Go8W5xbvGgyIgdseIxobFhcSLx4svxq_GvjxixbF4LcayxI0gxbnHmG94xoPHlMa9xr8vx5x5x5XGscSLx53Gtca3xqPEoHnGvMa-xqrHgMeCx4THhmvHj8eKfceMx44ixbnGh8eSx73HpMe0xqvHoMeax6jHnnvIiMejx6o8x6fHrMepx6XHtciKx67GuMSoxKrErMSux7PHtMe2x4PHhceHyIDFusWBx4vHjcePyIJlx5PHqse1yIjHm8iSyIvIjX3Ihcemx6jGr8iQxq3Ersi3cMabbsWkbcSaxrjFsWTHssi0PMSoY8WbxZfEtsa2xrhkb3duIsmGyLzFjci_yYHGo3PFgGxlxa7JksekyJDGlcaXxpnGm8adPg&c=BNJBWRBb1P


you see a request on the left part of the screen

note: to get the output - just press the button in the top-menu called "Ausführen"

after this you press the button called "DATEN" on the top-right -
just below the green button called "flatter this": after pressing this "DATEN"-button you see the data in the right window of the screen.

note - it has got various ids - that means that the osm-file does not give back constantly all the tags...

the last question; does this make any problems to our project - does this has any influence on our db-connection...!?!?

see the output here:


Code
 
<node id="2064639440" lat="49.4873181" lon="8.4710548">
<tag k="amenity" v="restaurant"/>
<tag k="cuisine" v="turkish"/>
<tag k="email" v="info@lynso.de"/>
<tag k="name" v="Kilim - Café und Bar Restaurant"/>
<tag k="opening_hours" v="Su-Th 17:00-1:00; Fr, Sa 17:00-3:00"/>
<tag k="operator" v="Cengiz Kaya"/>
<tag k="phone" v="06 21 - 43 755 371"/>
<tag k="website" v="http://www.kilim-mannheim.de/"/>
</node>
<node id="2126473801" lat="49.4851170" lon="8.4756295">
<tag k="amenity" v="restaurant"/>
<tag k="cuisine" v="italian"/>
<tag k="email" v="mannheim1@vapiano.de"/>
<tag k="fax" v="+49 621 1259 779"/>
<tag k="name" v="Vapiano"/>
<tag k="opening_hours" v="Su-Th 10:00-24:00; Fr-Sa 10:00-01:00"/>
<tag k="operator" v="Vapiano"/>
<tag k="phone" v="+49 621 1259 777"/>
<tag k="website" v="http://www.vapiano.de/newsroom/?store=29"/>
<tag k="wheelchair" v="yes"/>
</node>


<node id="667927886" lat="49.4909673" lon="8.4764904">
<tag k="addr:city" v="Mannheim"/>
<tag k="addr:country" v="DE"/>
<tag k="addr:housenumber" v="5"/>
<tag k="addr:postcode" v="68161"/>
<tag k="addr:street" v="Collinistraße"/>
<tag k="amenity" v="restaurant"/>
<tag k="name" v="Churrascaria Brasil Tropical"/>
<tag k="phone" v="+496211225596"/>
<tag k="wheelchair" v="limited"/>
</node>
<node id="689928440" lat="49.4798794" lon="8.4853418">
<tag k="amenity" v="restaurant"/>
<tag k="cuisine" v="greek"/>
<tag k="email" v="epirus70@hotmail.de"/>
<tag k="fax" v="0621/4407 762"/>
<tag k="name" v="Epirus"/>
<tag k="opening_hours" v="Mo-Sa 12:00-15:00,18:00-24:00"/>
<tag k="phone" v="0621/4407 761"/>
<tag k="smoking" v="separated"/>
<tag k="website" v="http://epirus-ma.blogspot.com/"/>
<tag k="wheelchair" v="no"/>
</node>
<node id="689928445" lat="49.4799409" lon="8.4851357">
<tag k="amenity" v="restaurant"/>
<tag k="cuisine" v="italian"/>
<tag k="email" v="gianlucascurti@ristorante-augusta.de"/>
<tag k="name" v="Ristorante Augusta"/>
<tag k="opening_hours" v="Mo-Fr 12:00-14:00,18:00-23:00;Su 12:00-14:00,18:00-23:00"/>
<tag k="phone" v="0621 449872"/>
<tag k="website" v="ristorante-augusta.com/"/>
<tag k="wheelchair" v="no"/>
</node>



well you see that i have some questions

the first ones are regarding the "port-over-to Linux" and ... how to include the above mentioned osm-library.
the second one is regarding the variations in the mysql.txt - file - i.e. the different number of tags.; How to make the script robust so that it is able to work with this - and does not stopt to work....!?


I look forward to hear from you

many many greetings

dilbert Wink


(This post was edited by dilbert on May 30, 2014, 5:32 AM)


dilbert
User

Jun 1, 2014, 11:19 AM

Post #11 of 11 (6254 views)
Re: [FishMonger] using XML::Twig and DBI to store a xml-file into a myql-db [In reply to] Can't Post

 



btw: since i run linux - i have to rewrite the lines in the create_db.pl -,,,,,,



Code
$file = "c:/osm/planet/pois.osm" ;  

openOsmFile ($file) ;
open(AUSGABE, ">c:/osm/planet/mysql.txt");
($id, $lon, $lat, $nodeUser, $ref1) = getNode2 () ;



well i guess that i just have to change the mentioned lines to


Code
 
$file = "pois.osm" ; open(AUSGABE, ">mysql.txt");
$file = "pois.osm" ;

open(AUSGABE, ">mysql.txt");



subsequently i ought to put the pois.osm file in with create_db.pl.

But i think as long as i am in the early stages of testing, it should be okay to create a folder /home/perl/OSM and put the osm.pm into it!?

BTW: Looks we also need osmDB.pm in there too, don´ t we!?

Guess that we also need to install Compress::Bzip2

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives