5
my $osm_dbi = 'dbi:mysql:user=root:database=osm';
6
my $oqg_dbi = 'dbi:mysql:host=127.0.0.1:port=9306:database=test:user=root';
8
my $osm_dbh = DBI->connect($osm_dbi, undef , undef , { RaiseError => 1});
9
my $oqg_dbh = DBI->connect($oqg_dbi, undef , undef , { RaiseError => 1});
11
my $ways = $osm_dbh->selectcol_arrayref("SELECT DISTINCT id FROM ways");
13
$oqg_dbh->do("CREATE TABLE IF NOT EXISTS osm ( latch SMALLINT UNSIGNED NULL, origid BIGINT UNSIGNED NULL, destid BIGINT UNSIGNED NULL, weight DOUBLE NULL, seq BIGINT UNSIGNED NULL, linkid BIGINT UNSIGNED NULL, KEY (latch, origid, destid) USING HASH, KEY (latch, destid, origid) USING HASH ) ENGINE=OQGRAPH");
15
print "$#$ways found.\n";
17
foreach my $way (@$ways) {
18
my $nodes = $osm_dbh->selectcol_arrayref("SELECT node_id FROM way_nodes WHERE id = $way ORDER BY sequence_id");
19
# print "$#$nodes found for way $way\n";
23
INSERT INTO osm ( origid, destid ) VALUES ".
24
join(', ', map { "( $nodes->[$_] , $nodes->[$_ + 1] )" } (0..($#$nodes-1)))