/[zanavi_public1]/navit/navit/tools/asc2navit
ZANavi

Contents of /navit/navit/tools/asc2navit

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File size: 4083 byte(s)
import files
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Getopt::Long qw(:config permute);
6 use Data::Dumper;
7 use Benchmark;
8
9 sub show_help;
10 sub preprocess_filelist;
11 sub open_outputhandle;
12 sub process_file;
13 sub run;
14
15 my $amenity = "point_unkn";
16 my $write_osm = 0;
17 my %files = ();
18 my $filename = "onebigfile";
19 my $poicount = 0;
20
21
22 GetOptions ('a|amenity=s' => \$amenity,
23 'x|write-osm!' => \$write_osm,
24 'h|?|help!' => \&show_help,
25 'O|output-file=s' => \$filename,
26 '<>' => \&preprocess_filelist);
27
28
29 # when no file is given...
30 show_help() if (keys %files == 0);
31
32 # determine filename
33 determine_filename();
34
35 # open the pipe for the output...
36 my $pipe = open_outputhandle();
37
38 # ...feed the pipe...
39 run();
40
41 # ...and close it properly
42 close $pipe;
43
44 ###############################################################################
45 ###############################################################################
46 ###############################################################################
47
48 sub show_help {
49 print "parses one (or multiple) .asc-file(s) (mainly used by poiwarner) and\n";
50 print "merges the result into one navit binary mapfile. requires maptool (when -x is not set)\n";
51 print "usage: $0 [OPTION] OUT in1.asc [in2.asc [...]]\n";
52 print " creates one big file called onebigfile\n";
53 print "usage: $0 [OPTION] IN.asc\n";
54 print " creates a file called IN.asc.bin / .osm\n\n";
55 print " -h, --help shows this help\n";
56 print " -x, --write-osm write in osm's xml format instead of navit's\n";
57 print " -a, --amenity=NAME sets the amenity to NAME. default is point_unk\n";
58 print " you can use -a several times for different types of pois\n";
59 print " e.g.: $0 -a tec_common speedcamdb1 speedcamdb2 -a poi_biergarten boozestation1 boozestation2\n";
60 print " -O, --output-file=OUT write the output to OUT. default for multiple files ist onebigfile\n";
61 exit 0;
62 }
63
64 sub preprocess_filelist {
65 my ($filename) = @_;
66 push (@{$files{$amenity}}, @_);
67
68 }
69
70 sub open_outputhandle() {
71 # open the pipe to maptool...
72 if (!$write_osm) {
73 open $pipe, "| maptool $filename" or die $!;
74 } else {
75 # or a filehandle
76 open $pipe, ">$filename" or die $!;
77 }
78 return $pipe;
79 }
80
81 sub process_file {
82 my ($file) = @_;
83 my $filehandle;
84 print "$0 processing $file...\n";
85 open ($filehandle, "<$file") or next $!;
86 # for every line in the file...
87 while (<$filehandle>) {
88 # ...check if it's a valid record...
89 m/([0-9\.\-]*), ([0-9\.\-]*), "\[([0-9]*).*/ or next;
90 my ($lon, $lat, $id) = ($1, $2, $3);
91 # ...and write it into the handle then
92 print $pipe " <node id=\"-$id\" visible=\"true\" lon=\"$lon\" lat=\"$lat\">\n";
93 print $pipe " <tag k=\"name\" v=\"\" />\n";
94 print $pipe " <tag k=\"amenity\" v=\"$amenity\" />\n";
95 print $pipe " </node>\n";
96 $poicount++;
97 }
98 }
99
100 sub determine_filename {
101 my $filecount = 0;
102 foreach my $amenity (keys %files) {
103 $filecount += $#{$files{$amenity}} + 1;
104 }
105
106 # when it's only one file and no output file has been given...
107 if ($filecount == 1 && $filename eq "") {
108 my $onefile = $files{(keys %files)[0]}[0];
109 # ...generate a new one from the given filename
110 $filename = "$onefile.bin";
111 $filename = "$onefile.xml" if ($write_osm);
112 }
113
114 print "$0 writing output to $filename\n";
115 }
116
117 sub run {
118 # write osm header
119 print $pipe '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
120 print $pipe '<osm version="0.5">' . "\n";
121
122 # set the amenity and
123 my @amenities = keys %files;
124 while (my $amenity = shift @amenities) {
125 foreach my $file (@{$files{$amenity}}) {
126 process_file($file);
127 }
128 }
129
130 # close the osm file
131 print $pipe '</osm>';
132 # and show up some stats
133 print "$0 processed $poicount poi's\n";
134 }
135

Properties

Name Value
svn:executable *

   
Visit the ZANavi Wiki