source: subversion/applications/utils/gary68/populateDB.pl @ 24837

Last change on this file since 24837 was 24837, checked in by gary68, 9 years ago

DB functions

  • Property svn:executable set to *
File size: 3.7 KB
Line 
1#
2#
3#
4#
5#
6# Copyright (C) 2010, Gerhard Schwanz
7#
8# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
9# Free Software Foundation; either version 3 of the License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>
15#
16
17
18
19use strict ;
20use warnings ;
21
22use OSM::osm ;
23use OSM::osmdb ;
24
25use DBI ;
26
27my $program = "populateDB.pl" ;
28my $version = "1.0 BETA" ;
29my $usage = $program . " file.osm" ;
30
31my $wayId ;
32my $wayId2 ;
33my $wayUser ;
34my @wayNodes ;
35my @wayTags ;
36my $nodeId ;
37my $nodeUser ;
38my $nodeLat ;
39my $nodeLon ;
40my @nodeTags ;
41my $aRef1 ;
42my $aRef2 ;
43my $relationId ;
44my $relationUser ;
45my @relationTags ;
46my @relationMembers ;
47
48
49my $wayCount = 0 ;
50my $nodeCount = 0 ;
51my $relationCount = 0 ;
52
53my $time0 = time() ; my $time1 ; my $time2 ;
54
55my $osmName ;
56
57my $maxK = 0 ;
58my $maxV = 0 ;
59
60###############
61# get parameter
62###############
63$osmName = shift||'';
64if (!$osmName)
65{
66        die (print $usage, "\n");
67}
68
69print "\n$program $version for file $osmName\n\n" ;
70print "\n\n" ;
71
72
73
74
75
76dbConnect() ;
77print "DB connected\n" ;
78
79initTableNodes() ;
80initTableWays() ;
81initTableRelations() ;
82
83
84
85######################
86# get node information
87######################
88print "\nget node information...\n" ;
89openOsmFile ($osmName) ;
90
91
92($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1) = getNode2 () ;
93while ($nodeId != -1) {
94        $nodeCount++ ;
95        if ($nodeCount % 10000 == 0) { print "node $nodeCount\n" ; }
96
97        storeDBNode ($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1) ;
98
99        # next
100        ($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1) = getNode2 () ;
101}
102
103
104$time1 = time () ;
105print "\nINFO: nodes finished after ", stringTimeSpent ($time1-$time0), "\n" ;
106
107my $nps = $nodeCount / ($time1-$time0) ;
108my $nph = int ($nps * 3600) ;
109printf "INFO: %10d nodes/h\n", $nph ;
110
111
112print "\nget way information...\n" ;
113
114($wayId, $wayUser, $aRef1, $aRef2) = getWay2 () ;
115while ($wayId != -1) { 
116        $wayCount++ ;
117
118        if ($wayCount % 10000 == 0) { print "way $wayCount\n" ; }
119
120        storeDBWay ($wayId, $wayUser, $aRef1, $aRef2) ;
121
122        # next way
123        ($wayId, $wayUser, $aRef1, $aRef2) = getWay2 () ;
124}
125
126
127$time2 = time () ;
128print "\nINFO: ways finished after ", stringTimeSpent ($time2-$time1), "\n" ;
129
130my $wps = $wayCount / ($time2-$time1) ;
131my $wph = int ($wps * 3600) ;
132printf "INFO: %10d nodes/h\n", $nph ;
133printf "INFO: %10d ways/h\n", $wph ;
134
135print "\nget relation information...\n" ;
136
137
138($relationId, $relationUser, $aRef1, $aRef2) = getRelation () ;
139
140while ($relationId != -1) {
141        $relationCount++ ;     
142
143        if ($relationCount % 10000 == 0) { print "rel: $relationCount\n" ; }
144
145        storeDBRelation ($relationId, $relationUser, $aRef1, $aRef2) ;
146
147        #next
148        ($relationId, $relationUser, $aRef1, $aRef2) = getRelation () ;
149}
150
151closeOsmFile () ;
152
153
154
155dbDisconnect() ;
156print "DB disconnected\n" ;
157
158my $time3 = time () ;
159print "\nINFO: relations finished after ", stringTimeSpent ($time3-$time2), "\n" ;
160
161my $rps = $relationCount / ($time3-$time2) ;
162my $rph = int ($rps * 3600) ;
163printf "INFO: %10d nodes/h\n", $nph ;
164printf "INFO: %10d ways/h\n", $wph ;
165printf "INFO: %10d relations/h\n", $rph ;
166
167
168printMaxValues() ;
169
170
171print "\nINFO: finished after ", stringTimeSpent ($time3-$time0), "\n\n" ;
172
173
Note: See TracBrowser for help on using the repository browser.