source: subversion/applications/utils/gary68/buildWayNodesList.pl @ 24893

Last change on this file since 24893 was 17266, checked in by gary68, 10 years ago

-

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#
2#
3# buildWayNodesList.pl
4#
5# program takes osm file (preferably a whole planet) and builds a file that contains just lines of wayIds and the number of nodes contained in that way.
6# this information can be used by programs that use only portions of the planet file to determine whether a way was cut of by using bounding boxes
7# or polygons.
8#
9#
10#
11# Copyright (C) 2009, Gerhard Schwanz
12#
13# 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
14# Free Software Foundation; either version 3 of the License, or (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>
20#
21#
22
23
24use strict ;
25use warnings ;
26
27use OSM::osm 5.0 ;
28
29my $usage = "perl buildWayNodesList.pl file.osm out.txt" ;
30my $version = "1.1" ;
31
32my $wayId ;
33my $wayUser ;
34my @wayNodes ;
35my @wayTags ;
36my $nodeId ;
37my $nodeUser ;
38my $nodeLat ;
39my $nodeLon ;
40my @nodeTags ;
41my $aRef1 ;
42my $aRef2 ;
43
44my $osmName ; 
45my $outName ;
46my $outFile ;
47
48my $time0 ; 
49my $wayCount = 0 ;
50
51# get parameter
52
53$osmName = shift||'';
54if (!$osmName)
55{
56        die (print $usage, "\n");
57}
58
59$outName = shift||'';
60if (!$outName)
61{
62        die (print $usage, "\n");
63}
64
65$time0 = time() ;
66
67open ($outFile, ">", $outName) or die ("can't open output file")  ;
68print $outFile "# waynodes file for osm file $osmName\n" ;
69
70print "skipping nodes...\n" ;
71openOsmFile ($osmName) ;
72skipNodes() ;
73print "done.\n" ;
74
75print "parsing and checking ways...\n" ;
76($wayId, $wayUser, $aRef1, $aRef2) = getWay2 () ;
77if ($wayId != -1) {
78        @wayNodes = @$aRef1 ;
79        @wayTags = @$aRef2 ;
80}
81while ($wayId != -1) {
82        $wayCount++ ;
83        if ($wayCount % 100000 == 0) { print "$wayCount ways processed...\n" ; }
84       
85        my ($number) = scalar @wayNodes ;
86
87        print $outFile "$wayId $number\n" ;
88       
89        ($wayId, $wayUser, $aRef1, $aRef2) = getWay2 () ;
90        if ($wayId != -1) {
91                @wayNodes = @$aRef1 ;
92                @wayTags = @$aRef2 ;
93        }
94}
95closeOsmFile() ;
96print "done.\n" ;
97close ($outFile) ;
98
99print "$wayCount ways found.\n" ;
100print "\nfinished after ", stringTimeSpent (time()-$time0), "\n\n" ;
101
102
103
104
Note: See TracBrowser for help on using the repository browser.