source: subversion/applications/utils/gary68/streetnames.pl @ 23856

Last change on this file since 23856 was 18052, checked in by gary68, 10 years ago

v1.1 streetnames

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#
2#
3#
4#
5#
6# Copyright (C) 2008, 2009, 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 File::stat;
24use Time::localtime;
25
26
27my $program = "streetnames.pl" ;
28my $version = "1.1" ;
29my $usage = $program . " file.osm out.txt" ;
30
31my $wayId ;
32my $wayId2 ;
33my $wayUser ;
34my @wayNodes ;
35my @wayTags ;
36my $nodeId ;
37my $nodeId2 ;
38my $nodeUser ;
39my $nodeLat ;
40my $nodeLon ;
41my @nodeTags ;
42my $aRef1 ;
43my $aRef2 ;
44my %names = () ;
45my $wayCount = 0 ;
46my $highwayCount = 0 ;
47
48my $time0 = time() ; my $time1 ;
49
50my $osmName ;
51my $outName ;
52
53
54
55###############
56# get parameter
57###############
58$osmName = shift||'';
59if (!$osmName)
60{
61        die (print $usage, "\n");
62}
63
64$outName = shift||'';
65if (!$outName)
66{
67        die (print $usage, "\n");
68}
69
70print "\n$program $version for file $osmName\n\n" ;
71print "\n\n" ;
72
73
74
75
76
77######################
78# get node information
79######################
80print "skip node information...\n" ;
81openOsmFile ($osmName) ;
82
83
84skipNodes() ;
85
86print "get way information...\n" ;
87
88($wayId, $wayUser, $aRef1, $aRef2) = getWay2 () ;
89if ($wayId != -1) {
90        @wayNodes = @$aRef1 ;
91        @wayTags = @$aRef2 ;
92}
93while ($wayId != -1) { 
94        $wayCount++ ;
95        if ($wayCount % 100000 == 0 ) { print "$wayCount ways processed...\n" ; } 
96        my $highway = 0 ;
97        my $name = "" ;
98        foreach my $tag (@wayTags) {
99                if ($tag->[0] eq "highway") { $highway = 1 ; }
100                if ($tag->[0] eq "name") { $name = $tag->[1] ; }
101        }
102
103        if ($highway and ($name ne "") ) { 
104                $highwayCount++ ;
105                $names{$name} = 1 ;
106        }
107
108        # next way
109        ($wayId, $wayUser, $aRef1, $aRef2) = getWay2 () ;
110        if ($wayId != -1) {
111                @wayNodes = @$aRef1 ;
112                @wayTags = @$aRef2 ;
113        }
114}
115
116closeOsmFile () ;
117my $outFile ;
118open ($outFile, ">", $outName) ;
119foreach my $street (sort keys %names) {
120        print $outFile $street, "\n" ;
121}
122close ($outFile) ;
123
124print "$wayCount ways processed.\n" ;
125print "$highwayCount highways processed.\n" ;
126print scalar (keys %names), " different names found.\n" ;
127
128$time1 = time () ;
129print "\nINFO: finished after ", stringTimeSpent ($time1-$time0), "\n\n" ;
130
131
Note: See TracBrowser for help on using the repository browser.