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

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

new DB programs

  • Property svn:executable set to *
File size: 3.8 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 DBname" ;
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 ;
56my $dbName ;
57
58my $maxK = 0 ;
59my $maxV = 0 ;
60
61###############
62# get parameter
63###############
64$osmName = shift||'';
65if (!$osmName)
66{
67        die (print $usage, "\n");
68}
69$dbName = shift||'';
70if (!$dbName)
71{
72        die (print $usage, "\n");
73}
74
75print "\n$program $version for file $osmName DB:$ dbName\n\n" ;
76print "\n\n" ;
77
78
79
80
81
82dbConnect($dbName) ;
83print "DB $dbName connected\n" ;
84
85initTableNodes() ;
86initTableWays() ;
87initTableRelations() ;
88
89
90
91######################
92# get node information
93######################
94print "\nget node information...\n" ;
95openOsmFile ($osmName) ;
96
97
98($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1) = getNode2 () ;
99while ($nodeId != -1) {
100        $nodeCount++ ;
101        if ($nodeCount % 10000 == 0) { print "node $nodeCount\n" ; }
102
103        storeDBNode ($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1) ;
104
105        # next
106        ($nodeId, $nodeLon, $nodeLat, $nodeUser, $aRef1) = getNode2 () ;
107}
108
109
110$time1 = time () ;
111print "\nINFO: nodes finished after ", stringTimeSpent ($time1-$time0), "\n" ;
112
113my $nps = $nodeCount / ($time1-$time0) ;
114my $nph = int ($nps * 3600) ;
115printf "INFO: %10d nodes/h\n", $nph ;
116
117
118print "\nget way information...\n" ;
119
120($wayId, $wayUser, $aRef1, $aRef2) = getWay2 () ;
121while ($wayId != -1) { 
122        $wayCount++ ;
123
124        if ($wayCount % 10000 == 0) { print "way $wayCount\n" ; }
125
126        storeDBWay ($wayId, $wayUser, $aRef1, $aRef2) ;
127
128        # next way
129        ($wayId, $wayUser, $aRef1, $aRef2) = getWay2 () ;
130}
131
132
133$time2 = time () ;
134print "\nINFO: ways finished after ", stringTimeSpent ($time2-$time1), "\n" ;
135
136my $wps = $wayCount / ($time2-$time1) ;
137my $wph = int ($wps * 3600) ;
138printf "INFO: %10d nodes/h\n", $nph ;
139printf "INFO: %10d ways/h\n", $wph ;
140
141print "\nget relation information...\n" ;
142
143
144($relationId, $relationUser, $aRef1, $aRef2) = getRelation () ;
145
146while ($relationId != -1) {
147        $relationCount++ ;     
148
149        if ($relationCount % 10000 == 0) { print "rel: $relationCount\n" ; }
150
151        storeDBRelation ($relationId, $relationUser, $aRef1, $aRef2) ;
152
153        #next
154        ($relationId, $relationUser, $aRef1, $aRef2) = getRelation () ;
155}
156
157closeOsmFile () ;
158
159
160
161dbDisconnect() ;
162print "DB disconnected\n" ;
163
164my $time3 = time () ;
165print "\nINFO: relations finished after ", stringTimeSpent ($time3-$time2), "\n" ;
166
167my $rps = $relationCount / ($time3-$time2) ;
168my $rph = int ($rps * 3600) ;
169printf "INFO: %10d nodes/h\n", $nph ;
170printf "INFO: %10d ways/h\n", $wph ;
171printf "INFO: %10d relations/h\n", $rph ;
172
173
174printMaxValues() ;
175
176
177print "\nINFO: finished after ", stringTimeSpent ($time3-$time0), "\n\n" ;
178
179
Note: See TracBrowser for help on using the repository browser.