Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /branches/destination-access/src/filedumper.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1628 - (hide annotations) (download) (as text)
Sun Mar 22 13:45:29 2015 UTC (9 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 46737 byte(s)
A new branch for access=destination routing at each end.

1 amb 2 /***************************************
2     Memory file dumper.
3 amb 151
4     Part of the Routino routing software.
5 amb 2 ******************/ /******************
6 amb 1559 This file Copyright 2008-2014 Andrew M. Bishop
7 amb 2
8 amb 151 This program is free software: you can redistribute it and/or modify
9     it under the terms of the GNU Affero General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12    
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     GNU Affero General Public License for more details.
17    
18     You should have received a copy of the GNU Affero General Public License
19     along with this program. If not, see <http://www.gnu.org/licenses/>.
20 amb 2 ***************************************/
21    
22    
23     #include <stdio.h>
24     #include <stdlib.h>
25 amb 107 #include <string.h>
26 amb 185 #include <sys/stat.h>
27     #include <sys/time.h>
28     #include <time.h>
29 amb 669 #include <math.h>
30 amb 2
31 amb 97 #include "types.h"
32     #include "nodes.h"
33     #include "segments.h"
34     #include "ways.h"
35 amb 542 #include "relations.h"
36 amb 1321 #include "errorlog.h"
37 amb 449
38     #include "files.h"
39     #include "visualiser.h"
40 amb 405 #include "xmlparse.h"
41 amb 2
42 amb 405
43 amb 185 /* Local functions */
44 amb 2
45 amb 681 static void print_node(Nodes *nodes,index_t item);
46 amb 202 static void print_segment(Segments *segments,index_t item);
47     static void print_way(Ways *ways,index_t item);
48 amb 1150 static void print_turn_relation(Relations *relations,index_t item,Segments *segments,Nodes *nodes);
49 amb 1321 static void print_errorlog(ErrorLogs *errorlogs,index_t item);
50 amb 185
51 amb 917 static void print_head_osm(int coordcount,double latmin,double latmax,double lonmin,double lonmax);
52 amb 918 static void print_region_osm(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,
53     double latmin,double latmax,double lonmin,double lonmax,int option_no_super);
54 amb 681 static void print_node_osm(Nodes *nodes,index_t item);
55 amb 405 static void print_segment_osm(Segments *segments,index_t item,Ways *ways);
56 amb 1150 static void print_turn_relation_osm(Relations *relations,index_t item,Segments *segments,Nodes *nodes);
57 amb 405 static void print_tail_osm(void);
58    
59 amb 1330 static void print_node_visualiser(Nodes *nodes,index_t item);
60     static void print_segment_visualiser(Segments *segments,index_t item,Ways *ways);
61     static void print_turn_relation_visualiser(Relations *relations,index_t item,Segments *segments,Nodes *nodes);
62     static void print_errorlog_visualiser(ErrorLogs *errorlogs,index_t item);
63    
64 amb 405 static char *RFC822Date(time_t t);
65    
66 amb 490 static void print_usage(int detail,const char *argerr,const char *err);
67 amb 342
68    
69     /*++++++++++++++++++++++++++++++++++++++
70 amb 405 The main program for the file dumper.
71 amb 342 ++++++++++++++++++++++++++++++++++++++*/
72    
73 amb 2 int main(int argc,char** argv)
74     {
75 amb 26 Nodes *OSMNodes;
76 amb 66 Segments *OSMSegments;
77 amb 26 Ways *OSMWays;
78 amb 542 Relations*OSMRelations;
79 amb 1321 ErrorLogs*OSMErrorLogs=NULL;
80 amb 405 int arg;
81     char *dirname=NULL,*prefix=NULL;
82 amb 1321 char *nodes_filename,*segments_filename,*ways_filename,*relations_filename,*errorlogs_filename;
83 amb 405 int option_statistics=0;
84     int option_visualiser=0,coordcount=0;
85     double latmin=0,latmax=0,lonmin=0,lonmax=0;
86     char *option_data=NULL;
87     int option_dump=0;
88 amb 413 int option_dump_osm=0,option_no_super=0;
89 amb 1330 int option_dump_visualiser=0;
90 amb 13
91 amb 107 /* Parse the command line arguments */
92    
93 amb 202 for(arg=1;arg<argc;arg++)
94 amb 107 {
95 amb 202 if(!strcmp(argv[arg],"--help"))
96 amb 490 print_usage(1,NULL,NULL);
97 amb 202 else if(!strncmp(argv[arg],"--dir=",6))
98     dirname=&argv[arg][6];
99     else if(!strncmp(argv[arg],"--prefix=",9))
100     prefix=&argv[arg][9];
101 amb 405 else if(!strcmp(argv[arg],"--statistics"))
102 amb 185 option_statistics=1;
103 amb 405 else if(!strcmp(argv[arg],"--visualiser"))
104 amb 185 option_visualiser=1;
105 amb 405 else if(!strcmp(argv[arg],"--dump"))
106 amb 202 option_dump=1;
107 amb 405 else if(!strcmp(argv[arg],"--dump-osm"))
108     option_dump_osm=1;
109 amb 1330 else if(!strcmp(argv[arg],"--dump-visualiser"))
110     option_dump_visualiser=1;
111 amb 202 else if(!strncmp(argv[arg],"--latmin",8) && argv[arg][8]=='=')
112     {latmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
113     else if(!strncmp(argv[arg],"--latmax",8) && argv[arg][8]=='=')
114     {latmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
115     else if(!strncmp(argv[arg],"--lonmin",8) && argv[arg][8]=='=')
116     {lonmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
117     else if(!strncmp(argv[arg],"--lonmax",8) && argv[arg][8]=='=')
118     {lonmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
119     else if(!strncmp(argv[arg],"--data",6) && argv[arg][6]=='=')
120     option_data=&argv[arg][7];
121 amb 413 else if(!strcmp(argv[arg],"--no-super"))
122     option_no_super=1;
123 amb 202 else if(!strncmp(argv[arg],"--node=",7))
124     ;
125     else if(!strncmp(argv[arg],"--segment=",10))
126     ;
127     else if(!strncmp(argv[arg],"--way=",6))
128     ;
129 amb 565 else if(!strncmp(argv[arg],"--turn-relation=",16))
130     ;
131 amb 1321 else if(!strncmp(argv[arg],"--errorlog=",11))
132     ;
133 amb 107 else
134 amb 490 print_usage(0,argv[arg],NULL);
135 amb 107 }
136    
137 amb 1330 if((option_statistics + option_visualiser + option_dump + option_dump_osm + option_dump_visualiser)!=1)
138     print_usage(0,NULL,"Must choose --visualiser, --statistics, --dump, --dump-osm or --dump-visualiser.");
139 amb 2
140 amb 329 /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */
141 amb 2
142 amb 185 OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem"));
143 amb 6
144 amb 185 OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem"));
145 amb 99
146 amb 185 OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem"));
147 amb 66
148 amb 542 OSMRelations=LoadRelationList(relations_filename=FileName(dirname,prefix,"relations.mem"));
149    
150 amb 1321 if(ExistsFile(errorlogs_filename=FileName(dirname,prefix,"errorlogs.mem")))
151     OSMErrorLogs=LoadErrorLogs(errorlogs_filename);
152     else
153     errorlogs_filename=NULL;
154    
155 amb 185 /* Write out the visualiser data */
156 amb 66
157 amb 185 if(option_visualiser)
158     {
159 amb 1003 Highway highway;
160 amb 1002 Transport transport;
161 amb 1248 Property property;
162 amb 1002
163 amb 185 if(coordcount!=4)
164 amb 490 print_usage(0,NULL,"The --visualiser option must have --latmin, --latmax, --lonmin, --lonmax.\n");
165 amb 66
166 amb 185 if(!option_data)
167 amb 490 print_usage(0,NULL,"The --visualiser option must have --data.\n");
168 amb 2
169 amb 185 if(!strcmp(option_data,"junctions"))
170 amb 623 OutputJunctions(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
171 amb 185 else if(!strcmp(option_data,"super"))
172 amb 623 OutputSuper(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
173 amb 1560 else if(!strcmp(option_data,"waytype-oneway"))
174     OutputWaytype(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,Highway_OneWay);
175     else if(!strcmp(option_data,"waytype-cyclebothways"))
176     OutputWaytype(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,Highway_CycleBothWays);
177     else if(!strcmp(option_data,"waytype-roundabout"))
178     OutputWaytype(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,Highway_Roundabout);
179 amb 1174 else if(!strncmp(option_data,"highway",7) && option_data[7]=='-' && (highway=HighwayType(option_data+8))!=Highway_None)
180 amb 1003 OutputHighway(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,highway);
181 amb 1002 else if(!strncmp(option_data,"transport",9) && option_data[9]=='-' && (transport=TransportType(option_data+10))!=Transport_None)
182     OutputTransport(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,transport);
183 amb 1077 else if(!strncmp(option_data,"barrier",7) && option_data[7]=='-' && (transport=TransportType(option_data+8))!=Transport_None)
184     OutputBarrier(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,transport);
185 amb 623 else if(!strcmp(option_data,"turns"))
186     OutputTurnRestrictions(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
187 amb 185 else if(!strcmp(option_data,"speed"))
188 amb 623 OutputSpeedLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
189 amb 185 else if(!strcmp(option_data,"weight"))
190 amb 623 OutputWeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
191 amb 185 else if(!strcmp(option_data,"height"))
192 amb 623 OutputHeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
193 amb 185 else if(!strcmp(option_data,"width"))
194 amb 623 OutputWidthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
195 amb 185 else if(!strcmp(option_data,"length"))
196 amb 623 OutputLengthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
197 amb 1248 else if(!strncmp(option_data,"property",8) && option_data[8]=='-' && (property=PropertyType(option_data+9))!=Property_None)
198     OutputProperty(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,property);
199 amb 1321 else if(!strcmp(option_data,"errorlogs"))
200     OutputErrorLog(OSMErrorLogs,latmin,latmax,lonmin,lonmax);
201 amb 185 else
202 amb 490 print_usage(0,option_data,NULL);
203 amb 185 }
204 amb 6
205 amb 185 /* Print out statistics */
206 amb 6
207 amb 185 if(option_statistics)
208     {
209     struct stat buf;
210 amb 6
211 amb 185 /* Examine the files */
212    
213     printf("Files\n");
214     printf("-----\n");
215     printf("\n");
216    
217     stat(nodes_filename,&buf);
218    
219 amb 1235 printf("'%s%snodes.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size);
220 amb 185 printf("%s\n",RFC822Date(buf.st_mtime));
221     printf("\n");
222    
223     stat(segments_filename,&buf);
224    
225 amb 1235 printf("'%s%ssegments.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size);
226 amb 185 printf("%s\n",RFC822Date(buf.st_mtime));
227     printf("\n");
228    
229     stat(ways_filename,&buf);
230    
231 amb 1235 printf("'%s%sways.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size);
232 amb 185 printf("%s\n",RFC822Date(buf.st_mtime));
233     printf("\n");
234    
235 amb 625 stat(relations_filename,&buf);
236    
237 amb 1235 printf("'%s%srelations.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size);
238 amb 625 printf("%s\n",RFC822Date(buf.st_mtime));
239     printf("\n");
240    
241 amb 1321 if(errorlogs_filename)
242     {
243     stat(errorlogs_filename,&buf);
244    
245     printf("'%s%serrorlogs.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size);
246     printf("%s\n",RFC822Date(buf.st_mtime));
247     printf("\n");
248     }
249    
250 amb 185 /* Examine the nodes */
251    
252     printf("Nodes\n");
253     printf("-----\n");
254     printf("\n");
255    
256 amb 879 printf("sizeof(Node) =%9lu Bytes\n",(unsigned long)sizeof(Node));
257     printf("Number =%9"Pindex_t"\n",OSMNodes->file.number);
258     printf("Number(super)=%9"Pindex_t"\n",OSMNodes->file.snumber);
259 amb 185 printf("\n");
260    
261 amb 879 printf("Lat bins= %4d\n",(int)OSMNodes->file.latbins);
262     printf("Lon bins= %4d\n",(int)OSMNodes->file.lonbins);
263 amb 185 printf("\n");
264    
265 amb 879 printf("Lat zero=%5d (%8.4f deg)\n",(int)OSMNodes->file.latzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.latzero))));
266     printf("Lon zero=%5d (%8.4f deg)\n",(int)OSMNodes->file.lonzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.lonzero))));
267 amb 185
268     /* Examine the segments */
269    
270     printf("\n");
271     printf("Segments\n");
272     printf("--------\n");
273     printf("\n");
274    
275 amb 879 printf("sizeof(Segment)=%9lu Bytes\n",(unsigned long)sizeof(Segment));
276     printf("Number(total) =%9"Pindex_t"\n",OSMSegments->file.number);
277     printf("Number(super) =%9"Pindex_t"\n",OSMSegments->file.snumber);
278     printf("Number(normal) =%9"Pindex_t"\n",OSMSegments->file.nnumber);
279 amb 185
280     /* Examine the ways */
281    
282     printf("\n");
283     printf("Ways\n");
284     printf("----\n");
285     printf("\n");
286    
287 amb 1103 printf("sizeof(Way)=%9lu Bytes\n",(unsigned long)sizeof(Way));
288     printf("Number =%9"Pindex_t"\n",OSMWays->file.number);
289 amb 202 printf("\n");
290    
291 amb 628 stat(ways_filename,&buf);
292 amb 1103 printf("Total names=%9lu Bytes\n",(unsigned long)buf.st_size-(unsigned long)sizeof(Ways)-(unsigned long)OSMWays->file.number*(unsigned long)sizeof(Way));
293 amb 307 printf("\n");
294    
295 amb 526 printf("Included highways : %s\n",HighwaysNameList(OSMWays->file.highways));
296 amb 460 printf("Included transports: %s\n",AllowedNameList(OSMWays->file.allow));
297     printf("Included properties: %s\n",PropertiesNameList(OSMWays->file.props));
298 amb 565
299     /* Examine the relations */
300    
301     printf("\n");
302     printf("Relations\n");
303     printf("---------\n");
304     printf("\n");
305    
306 amb 879 printf("sizeof(TurnRelation)=%9lu Bytes\n",(unsigned long)sizeof(TurnRelation));
307     printf("Number =%9"Pindex_t"\n",OSMRelations->file.trnumber);
308 amb 1321
309     if(errorlogs_filename)
310     {
311     printf("\n");
312     printf("Error Logs\n");
313     printf("----------\n");
314     printf("\n");
315    
316     printf("Number(total) =%9"Pindex_t"\n",OSMErrorLogs->file.number);
317     printf("Number(geographical) =%9"Pindex_t"\n",OSMErrorLogs->file.number_geo);
318     printf("Number(non-geographical)=%9"Pindex_t"\n",OSMErrorLogs->file.number_nongeo);
319    
320     printf("\n");
321     stat(errorlogs_filename,&buf);
322     #if !SLIM
323     printf("Total strings=%9lu Bytes\n",(unsigned long)buf.st_size-(unsigned long)(OSMErrorLogs->strings-(char*)OSMErrorLogs->data));
324     #else
325     printf("Total strings=%9lu Bytes\n",(unsigned long)buf.st_size-(unsigned long)OSMErrorLogs->stringsoffset);
326     #endif
327     }
328 amb 185 }
329    
330 amb 680 /* Print out internal data (in plain text format) */
331 amb 202
332     if(option_dump)
333     {
334     index_t item;
335    
336     for(arg=1;arg<argc;arg++)
337 amb 254 if(!strcmp(argv[arg],"--node=all"))
338 amb 202 {
339 amb 453 for(item=0;item<OSMNodes->file.number;item++)
340 amb 254 print_node(OSMNodes,item);
341     }
342     else if(!strncmp(argv[arg],"--node=",7))
343     {
344 amb 202 item=atoi(&argv[arg][7]);
345    
346 amb 1305 if(item<OSMNodes->file.number)
347 amb 301 print_node(OSMNodes,item);
348     else
349 amb 790 printf("Invalid node number; minimum=0, maximum=%"Pindex_t".\n",OSMNodes->file.number-1);
350 amb 202 }
351 amb 254 else if(!strcmp(argv[arg],"--segment=all"))
352     {
353 amb 459 for(item=0;item<OSMSegments->file.number;item++)
354 amb 254 print_segment(OSMSegments,item);
355     }
356 amb 202 else if(!strncmp(argv[arg],"--segment=",10))
357     {
358     item=atoi(&argv[arg][10]);
359    
360 amb 1305 if(item<OSMSegments->file.number)
361 amb 301 print_segment(OSMSegments,item);
362     else
363 amb 790 printf("Invalid segment number; minimum=0, maximum=%"Pindex_t".\n",OSMSegments->file.number-1);
364 amb 202 }
365 amb 254 else if(!strcmp(argv[arg],"--way=all"))
366     {
367 amb 460 for(item=0;item<OSMWays->file.number;item++)
368 amb 254 print_way(OSMWays,item);
369     }
370 amb 202 else if(!strncmp(argv[arg],"--way=",6))
371     {
372     item=atoi(&argv[arg][6]);
373    
374 amb 1305 if(item<OSMWays->file.number)
375 amb 301 print_way(OSMWays,item);
376     else
377 amb 790 printf("Invalid way number; minimum=0, maximum=%"Pindex_t".\n",OSMWays->file.number-1);
378 amb 202 }
379 amb 565 else if(!strcmp(argv[arg],"--turn-relation=all"))
380     {
381     for(item=0;item<OSMRelations->file.trnumber;item++)
382 amb 1150 print_turn_relation(OSMRelations,item,OSMSegments,OSMNodes);
383 amb 565 }
384     else if(!strncmp(argv[arg],"--turn-relation=",16))
385     {
386 amb 626 item=atoi(&argv[arg][16]);
387 amb 565
388 amb 1305 if(item<OSMRelations->file.trnumber)
389 amb 1150 print_turn_relation(OSMRelations,item,OSMSegments,OSMNodes);
390 amb 565 else
391 amb 790 printf("Invalid turn relation number; minimum=0, maximum=%"Pindex_t".\n",OSMRelations->file.trnumber-1);
392 amb 565 }
393 amb 1321 else if(!strcmp(argv[arg],"--errorlog=all"))
394     {
395     for(item=0;item<OSMErrorLogs->file.number;item++)
396     print_errorlog(OSMErrorLogs,item);
397     }
398     else if(!strncmp(argv[arg],"--errorlog=",11))
399     {
400     item=atoi(&argv[arg][11]);
401    
402     if(item<OSMErrorLogs->file.number)
403     print_errorlog(OSMErrorLogs,item);
404     else
405     printf("Invalid error log number; minimum=0, maximum=%"Pindex_t".\n",OSMErrorLogs->file.number-1);
406     }
407 amb 202 }
408    
409 amb 680 /* Print out internal data (in OSM XML format) */
410 amb 405
411     if(option_dump_osm)
412     {
413 amb 413 if(coordcount>0 && coordcount!=4)
414 amb 490 print_usage(0,NULL,"The --dump-osm option must have all of --latmin, --latmax, --lonmin, --lonmax or none.\n");
415 amb 405
416 amb 917 print_head_osm(coordcount,latmin,latmax,lonmin,lonmax);
417 amb 405
418 amb 413 if(coordcount)
419 amb 918 print_region_osm(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,option_no_super);
420 amb 413 else
421     {
422     index_t item;
423    
424 amb 453 for(item=0;item<OSMNodes->file.number;item++)
425 amb 413 print_node_osm(OSMNodes,item);
426    
427 amb 459 for(item=0;item<OSMSegments->file.number;item++)
428     if(!option_no_super || IsNormalSegment(LookupSegment(OSMSegments,item,1)))
429 amb 413 print_segment_osm(OSMSegments,item,OSMWays);
430 amb 565
431     for(item=0;item<OSMRelations->file.trnumber;item++)
432 amb 1150 print_turn_relation_osm(OSMRelations,item,OSMSegments,OSMNodes);
433 amb 413 }
434    
435 amb 405 print_tail_osm();
436     }
437    
438 amb 1330 /* Print out internal data (in HTML format for the visualiser) */
439    
440     if(option_dump_visualiser)
441     {
442     index_t item;
443    
444     if(!option_data)
445     print_usage(0,NULL,"The --dump-visualiser option must have --data.\n");
446    
447     for(arg=1;arg<argc;arg++)
448     if(!strncmp(argv[arg],"--data=node",11))
449     {
450     item=atoi(&argv[arg][11]);
451    
452     if(item<OSMNodes->file.number)
453     print_node_visualiser(OSMNodes,item);
454     else
455     printf("Invalid node number; minimum=0, maximum=%"Pindex_t".\n",OSMNodes->file.number-1);
456     }
457     else if(!strncmp(argv[arg],"--data=segment",14))
458     {
459     item=atoi(&argv[arg][14]);
460    
461     if(item<OSMSegments->file.number)
462     print_segment_visualiser(OSMSegments,item,OSMWays);
463     else
464     printf("Invalid segment number; minimum=0, maximum=%"Pindex_t".\n",OSMSegments->file.number-1);
465     }
466     else if(!strncmp(argv[arg],"--data=turn-relation",20))
467     {
468     item=atoi(&argv[arg][20]);
469    
470     if(item<OSMRelations->file.trnumber)
471     print_turn_relation_visualiser(OSMRelations,item,OSMSegments,OSMNodes);
472     else
473     printf("Invalid turn relation number; minimum=0, maximum=%"Pindex_t".\n",OSMRelations->file.trnumber-1);
474     }
475     else if(!strncmp(argv[arg],"--data=errorlog",15))
476     {
477     item=atoi(&argv[arg][15]);
478    
479     if(item<OSMErrorLogs->file.number)
480     print_errorlog_visualiser(OSMErrorLogs,item);
481     else
482     printf("Invalid error log number; minimum=0, maximum=%"Pindex_t".\n",OSMErrorLogs->file.number-1);
483     }
484     }
485    
486 amb 1599 exit(EXIT_SUCCESS);
487 amb 2 }
488 amb 185
489    
490 amb 202 /*++++++++++++++++++++++++++++++++++++++
491 amb 680 Print out the contents of a node from the routing database (as plain text).
492 amb 202
493     Nodes *nodes The set of nodes to use.
494    
495     index_t item The node index to print.
496     ++++++++++++++++++++++++++++++++++++++*/
497    
498 amb 681 static void print_node(Nodes *nodes,index_t item)
499 amb 202 {
500 amb 1078 Node *nodep=LookupNode(nodes,item,1);
501 amb 219 double latitude,longitude;
502 amb 202
503 amb 1291 GetLatLong(nodes,item,nodep,&latitude,&longitude);
504 amb 202
505 amb 790 printf("Node %"Pindex_t"\n",item);
506 amb 1078 printf(" firstseg=%"Pindex_t"\n",nodep->firstseg);
507     printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",nodep->latoffset,nodep->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude));
508     printf(" allow=%02x (%s)\n",nodep->allow,AllowedNameList(nodep->allow));
509     if(IsSuperNode(nodep))
510 amb 202 printf(" Super-Node\n");
511 amb 1263 if(nodep->flags & NODE_MINIRNDBT)
512     printf(" Mini-roundabout\n");
513 amb 202 }
514    
515    
516     /*++++++++++++++++++++++++++++++++++++++
517 amb 680 Print out the contents of a segment from the routing database (as plain text).
518 amb 202
519     Segments *segments The set of segments to use.
520    
521     index_t item The segment index to print.
522     ++++++++++++++++++++++++++++++++++++++*/
523    
524     static void print_segment(Segments *segments,index_t item)
525     {
526 amb 1078 Segment *segmentp=LookupSegment(segments,item,1);
527 amb 202
528 amb 790 printf("Segment %"Pindex_t"\n",item);
529 amb 1078 printf(" node1=%"Pindex_t" node2=%"Pindex_t"\n",segmentp->node1,segmentp->node2);
530     printf(" next2=%"Pindex_t"\n",segmentp->next2);
531     printf(" way=%"Pindex_t"\n",segmentp->way);
532 amb 1168 printf(" distance=%d (%.3f km)\n",DISTANCE(segmentp->distance),distance_to_km(DISTANCE(segmentp->distance)));
533 amb 1078 if(IsSuperSegment(segmentp) && IsNormalSegment(segmentp))
534 amb 202 printf(" Super-Segment AND normal Segment\n");
535 amb 1078 else if(IsSuperSegment(segmentp) && !IsNormalSegment(segmentp))
536 amb 202 printf(" Super-Segment\n");
537 amb 1078 if(IsOnewayTo(segmentp,segmentp->node1))
538 amb 202 printf(" One-Way from node2 to node1\n");
539 amb 1078 if(IsOnewayTo(segmentp,segmentp->node2))
540 amb 202 printf(" One-Way from node1 to node2\n");
541     }
542    
543    
544     /*++++++++++++++++++++++++++++++++++++++
545 amb 680 Print out the contents of a way from the routing database (as plain text).
546 amb 202
547     Ways *ways The set of ways to use.
548    
549     index_t item The way index to print.
550     ++++++++++++++++++++++++++++++++++++++*/
551    
552     static void print_way(Ways *ways,index_t item)
553     {
554 amb 1078 Way *wayp=LookupWay(ways,item,1);
555     char *name=WayName(ways,wayp);
556 amb 202
557 amb 790 printf("Way %"Pindex_t"\n",item);
558 amb 705 if(*name)
559     printf(" name=%s\n",name);
560 amb 1559 printf(" type=%02x (%s%s%s%s)\n",wayp->type,
561     HighwayName(HIGHWAY(wayp->type)),
562     wayp->type&Highway_OneWay?",One-Way":"",
563     wayp->type&Highway_CycleBothWays?",Cycle-Both-Ways":"",
564     wayp->type&Highway_Roundabout?",Roundabout":"");
565 amb 1078 printf(" allow=%02x (%s)\n",wayp->allow,AllowedNameList(wayp->allow));
566     if(wayp->props)
567     printf(" props=%02x (%s)\n",wayp->props,PropertiesNameList(wayp->props));
568     if(wayp->speed)
569     printf(" speed=%d (%d km/hr)\n",wayp->speed,speed_to_kph(wayp->speed));
570     if(wayp->weight)
571     printf(" weight=%d (%.1f tonnes)\n",wayp->weight,weight_to_tonnes(wayp->weight));
572     if(wayp->height)
573     printf(" height=%d (%.1f m)\n",wayp->height,height_to_metres(wayp->height));
574     if(wayp->width)
575     printf(" width=%d (%.1f m)\n",wayp->width,width_to_metres(wayp->width));
576     if(wayp->length)
577     printf(" length=%d (%.1f m)\n",wayp->length,length_to_metres(wayp->length));
578 amb 202 }
579    
580    
581 amb 405 /*++++++++++++++++++++++++++++++++++++++
582 amb 680 Print out the contents of a turn relation from the routing database (as plain text).
583 amb 565
584     Relations *relations The set of relations to use.
585    
586     index_t item The turn relation index to print.
587    
588     Segments *segments The set of segments to use.
589    
590     Nodes *nodes The set of nodes to use.
591     ++++++++++++++++++++++++++++++++++++++*/
592    
593 amb 1150 static void print_turn_relation(Relations *relations,index_t item,Segments *segments,Nodes *nodes)
594 amb 565 {
595 amb 1078 Segment *segmentp;
596     TurnRelation *relationp=LookupTurnRelation(relations,item,1);
597     Node *nodep=LookupNode(nodes,relationp->via,1);
598 amb 565 index_t from_way=NO_WAY,to_way=NO_WAY;
599 amb 599 index_t from_node=NO_NODE,to_node=NO_NODE;
600 amb 565
601 amb 1078 segmentp=FirstSegment(segments,nodep,1);
602 amb 565
603     do
604     {
605 amb 1078 index_t seg=IndexSegment(segments,segmentp);
606 amb 565
607 amb 1078 if(seg==relationp->from)
608 amb 599 {
609 amb 1078 from_node=OtherNode(segmentp,relationp->from);
610     from_way=segmentp->way;
611 amb 599 }
612 amb 565
613 amb 1078 if(seg==relationp->to)
614 amb 599 {
615 amb 1078 to_node=OtherNode(segmentp,relationp->to);
616     to_way=segmentp->way;
617 amb 599 }
618    
619 amb 1078 segmentp=NextSegment(segments,segmentp,relationp->via);
620 amb 565 }
621 amb 1078 while(segmentp);
622 amb 565
623 amb 790 printf("Relation %"Pindex_t"\n",item);
624 amb 1078 printf(" from=%"Pindex_t" (segment) = %"Pindex_t" (way) = %"Pindex_t" (node)\n",relationp->from,from_way,from_node);
625     printf(" via=%"Pindex_t" (node)\n",relationp->via);
626     printf(" to=%"Pindex_t" (segment) = %"Pindex_t" (way) = %"Pindex_t" (node)\n",relationp->to,to_way,to_node);
627     if(relationp->except)
628     printf(" except=%02x (%s)\n",relationp->except,AllowedNameList(relationp->except));
629 amb 565 }
630    
631    
632     /*++++++++++++++++++++++++++++++++++++++
633 amb 1321 Print out the contents of an error log from the routing database (as plain text).
634    
635     ErrorLogs *errorlogs The set of error logs to use.
636    
637     index_t item The error log index to print.
638     ++++++++++++++++++++++++++++++++++++++*/
639    
640     static void print_errorlog(ErrorLogs *errorlogs,index_t item)
641     {
642     ErrorLog *errorlogp=LookupErrorLog(errorlogs,item,1);
643    
644     printf("Error Log %"Pindex_t"\n",item);
645    
646     if(item<errorlogs->file.number_geo)
647     {
648     double latitude,longitude;
649    
650     GetErrorLogLatLong(errorlogs,item,errorlogp,&latitude,&longitude);
651    
652     printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",errorlogp->latoffset,errorlogp->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude));
653     }
654     else
655     printf(" No geographical information\n");
656    
657     printf(" '%s'\n",LookupErrorLogString(errorlogs,item));
658     }
659    
660    
661     /*++++++++++++++++++++++++++++++++++++++
662 amb 405 Print out a header in OSM XML format.
663 amb 918
664     int coordcount If true then include a bounding box.
665    
666     double latmin The minimum latitude.
667    
668     double latmax The maximum latitude.
669    
670     double lonmin The minimum longitude.
671    
672     double lonmax The maximum longitude.
673 amb 405 ++++++++++++++++++++++++++++++++++++++*/
674    
675 amb 917 static void print_head_osm(int coordcount,double latmin,double latmax,double lonmin,double lonmax)
676 amb 405 {
677     printf("<?xml version='1.0' encoding='UTF-8'?>\n");
678 amb 847 printf("<osm version='0.6' generator='Routino'>\n");
679 amb 917
680     if(coordcount)
681     printf(" <bounds minlat='%.6f' maxlat='%.6f' minlon='%.6f' maxlon='%.6f' />\n",
682     radians_to_degrees(latmin),radians_to_degrees(latmax),radians_to_degrees(lonmin),radians_to_degrees(lonmax));
683 amb 405 }
684    
685    
686     /*++++++++++++++++++++++++++++++++++++++
687 amb 918 Print a region of the database in OSM XML format.
688    
689     Nodes *nodes The set of nodes to use.
690    
691     Segments *segments The set of segments to use.
692    
693     Ways *ways The set of ways to use.
694    
695     Relations *relations The set of relations to use.
696    
697     double latmin The minimum latitude.
698    
699     double latmax The maximum latitude.
700    
701     double lonmin The minimum longitude.
702    
703     double lonmax The maximum longitude.
704    
705     int option_no_super The option to print no super-segments.
706     ++++++++++++++++++++++++++++++++++++++*/
707    
708     static void print_region_osm(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations,
709     double latmin,double latmax,double lonmin,double lonmax,int option_no_super)
710     {
711     ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(latmin))-nodes->file.latzero;
712     ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(latmax))-nodes->file.latzero;
713     ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(lonmin))-nodes->file.lonzero;
714     ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(lonmax))-nodes->file.lonzero;
715     ll_bin_t latb,lonb;
716     index_t item,index1,index2;
717    
718     if(latminbin<0) latminbin=0;
719     if(latmaxbin>nodes->file.latbins) latmaxbin=nodes->file.latbins-1;
720     if(lonminbin<0) lonminbin=0;
721     if(lonmaxbin>nodes->file.lonbins) lonmaxbin=nodes->file.lonbins-1;
722    
723     /* Loop through all of the nodes. */
724    
725     for(latb=latminbin;latb<=latmaxbin;latb++)
726     for(lonb=lonminbin;lonb<=lonmaxbin;lonb++)
727     {
728     ll_bin2_t llbin=lonb*nodes->file.latbins+latb;
729    
730     if(llbin<0 || llbin>(nodes->file.latbins*nodes->file.lonbins))
731     continue;
732    
733     index1=LookupNodeOffset(nodes,llbin);
734     index2=LookupNodeOffset(nodes,llbin+1);
735    
736     for(item=index1;item<index2;item++)
737     {
738 amb 1078 Node *nodep=LookupNode(nodes,item,1);
739     double lat=latlong_to_radians(bin_to_latlong(nodes->file.latzero+latb)+off_to_latlong(nodep->latoffset));
740     double lon=latlong_to_radians(bin_to_latlong(nodes->file.lonzero+lonb)+off_to_latlong(nodep->lonoffset));
741 amb 918
742     if(lat>latmin && lat<latmax && lon>lonmin && lon<lonmax)
743     {
744 amb 1078 Segment *segmentp;
745 amb 918
746     print_node_osm(nodes,item);
747    
748 amb 1078 segmentp=FirstSegment(segments,nodep,1);
749 amb 918
750 amb 1078 while(segmentp)
751 amb 918 {
752     double olat,olon;
753 amb 1078 index_t oitem=OtherNode(segmentp,item);
754 amb 918
755 amb 1291 GetLatLong(nodes,oitem,NULL,&olat,&olon);
756 amb 918
757     if(olat>latmin && olat<latmax && olon>lonmin && olon<lonmax)
758     if(item>oitem)
759 amb 1078 if(!option_no_super || IsNormalSegment(segmentp))
760     print_segment_osm(segments,IndexSegment(segments,segmentp),ways);
761 amb 918
762 amb 1078 segmentp=NextSegment(segments,segmentp,item);
763 amb 918 }
764    
765 amb 1078 if(IsTurnRestrictedNode(nodep))
766 amb 918 {
767     index_t relindex=FindFirstTurnRelation1(relations,item);
768    
769     while(relindex!=NO_RELATION)
770     {
771 amb 1150 print_turn_relation_osm(relations,relindex,segments,nodes);
772 amb 918
773     relindex=FindNextTurnRelation1(relations,relindex);
774     }
775     }
776     }
777     }
778     }
779     }
780    
781    
782     /*++++++++++++++++++++++++++++++++++++++
783 amb 680 Print out the contents of a node from the routing database (in OSM XML format).
784 amb 405
785     Nodes *nodes The set of nodes to use.
786    
787     index_t item The node index to print.
788     ++++++++++++++++++++++++++++++++++++++*/
789    
790 amb 681 static void print_node_osm(Nodes *nodes,index_t item)
791 amb 405 {
792 amb 1078 Node *nodep=LookupNode(nodes,item,1);
793 amb 405 double latitude,longitude;
794 amb 537 int i;
795 amb 405
796 amb 1291 GetLatLong(nodes,item,nodep,&latitude,&longitude);
797 amb 405
798 amb 1078 if(nodep->allow==Transports_ALL && nodep->flags==0)
799 amb 537 printf(" <node id='%lu' lat='%.7f' lon='%.7f' version='1' />\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude));
800     else
801 amb 405 {
802     printf(" <node id='%lu' lat='%.7f' lon='%.7f' version='1'>\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude));
803 amb 469
804 amb 1078 if(nodep->flags & NODE_SUPER)
805 amb 537 printf(" <tag k='routino:super' v='yes' />\n");
806    
807 amb 1078 if(nodep->flags & NODE_UTURN)
808 amb 667 printf(" <tag k='routino:uturn' v='yes' />\n");
809    
810 amb 1078 if(nodep->flags & NODE_MINIRNDBT)
811 amb 1263 printf(" <tag k='junction' v='roundabout' />\n");
812 amb 537
813 amb 1078 if(nodep->flags & NODE_TURNRSTRCT)
814 amb 667 printf(" <tag k='routino:turnrestriction' v='yes' />\n");
815    
816 amb 469 for(i=1;i<Transport_Count;i++)
817 amb 1078 if(!(nodep->allow & TRANSPORTS(i)))
818 amb 470 printf(" <tag k='%s' v='no' />\n",TransportName(i));
819 amb 469
820 amb 405 printf(" </node>\n");
821     }
822     }
823    
824    
825     /*++++++++++++++++++++++++++++++++++++++
826 amb 680 Print out the contents of a segment from the routing database (as a way in OSM XML format).
827 amb 405
828     Segments *segments The set of segments to use.
829    
830     index_t item The segment index to print.
831    
832     Ways *ways The set of ways to use.
833     ++++++++++++++++++++++++++++++++++++++*/
834    
835     static void print_segment_osm(Segments *segments,index_t item,Ways *ways)
836     {
837 amb 1078 Segment *segmentp=LookupSegment(segments,item,1);
838     Way *wayp=LookupWay(ways,segmentp->way,1);
839     char *name=WayName(ways,wayp);
840 amb 405 int i;
841    
842     printf(" <way id='%lu' version='1'>\n",(unsigned long)item+1);
843    
844 amb 1078 if(IsOnewayTo(segmentp,segmentp->node1))
845 amb 405 {
846 amb 1078 printf(" <nd ref='%lu' />\n",(unsigned long)segmentp->node2+1);
847     printf(" <nd ref='%lu' />\n",(unsigned long)segmentp->node1+1);
848 amb 405 }
849     else
850     {
851 amb 1078 printf(" <nd ref='%lu' />\n",(unsigned long)segmentp->node1+1);
852     printf(" <nd ref='%lu' />\n",(unsigned long)segmentp->node2+1);
853 amb 405 }
854    
855 amb 1078 if(IsSuperSegment(segmentp))
856 amb 405 printf(" <tag k='routino:super' v='yes' />\n");
857 amb 1078 if(IsNormalSegment(segmentp))
858 amb 405 printf(" <tag k='routino:normal' v='yes' />\n");
859    
860 amb 1168 printf(" <tag k='routino:distance' v='%.3f' />\n",distance_to_km(DISTANCE(segmentp->distance)));
861 amb 667
862 amb 1174 if(wayp->type & Highway_OneWay)
863 amb 405 printf(" <tag k='oneway' v='yes' />\n");
864    
865 amb 1559 if(wayp->type & Highway_CycleBothWays)
866     printf(" <tag k='cyclebothways' v='yes' />\n");
867    
868 amb 1174 if(wayp->type & Highway_Roundabout)
869 amb 923 printf(" <tag k='roundabout' v='yes' />\n");
870    
871 amb 1078 printf(" <tag k='highway' v='%s' />\n",HighwayName(HIGHWAY(wayp->type)));
872 amb 405
873 amb 1078 if(IsNormalSegment(segmentp) && *name)
874 amb 705 printf(" <tag k='name' v='%s' />\n",ParseXML_Encode_Safe_XML(name));
875 amb 405
876     for(i=1;i<Transport_Count;i++)
877 amb 1078 if(wayp->allow & TRANSPORTS(i))
878 amb 405 printf(" <tag k='%s' v='yes' />\n",TransportName(i));
879    
880     for(i=1;i<Property_Count;i++)
881 amb 1078 if(wayp->props & PROPERTIES(i))
882 amb 405 printf(" <tag k='%s' v='yes' />\n",PropertyName(i));
883    
884 amb 1078 if(wayp->speed)
885     printf(" <tag k='maxspeed' v='%d' />\n",speed_to_kph(wayp->speed));
886 amb 405
887 amb 1078 if(wayp->weight)
888     printf(" <tag k='maxweight' v='%.1f' />\n",weight_to_tonnes(wayp->weight));
889     if(wayp->height)
890     printf(" <tag k='maxheight' v='%.1f' />\n",height_to_metres(wayp->height));
891     if(wayp->width)
892     printf(" <tag k='maxwidth' v='%.1f' />\n",width_to_metres(wayp->width));
893     if(wayp->length)
894     printf(" <tag k='maxlength' v='%.1f' />\n",length_to_metres(wayp->length));
895 amb 405
896     printf(" </way>\n");
897     }
898    
899    
900     /*++++++++++++++++++++++++++++++++++++++
901 amb 680 Print out the contents of a turn relation from the routing database (in OSM XML format).
902 amb 565
903     Relations *relations The set of relations to use.
904    
905     index_t item The relation index to print.
906    
907     Segments *segments The set of segments to use.
908    
909     Nodes *nodes The set of nodes to use.
910     ++++++++++++++++++++++++++++++++++++++*/
911    
912 amb 1150 static void print_turn_relation_osm(Relations *relations,index_t item,Segments *segments,Nodes *nodes)
913 amb 565 {
914 amb 1078 TurnRelation *relationp=LookupTurnRelation(relations,item,1);
915 amb 565
916 amb 1078 Segment *segmentp_from=LookupSegment(segments,relationp->from,1);
917     Segment *segmentp_to =LookupSegment(segments,relationp->to ,2);
918 amb 618
919 amb 1078 double angle=TurnAngle(nodes,segmentp_from,segmentp_to,relationp->via);
920 amb 618
921     char *restriction;
922    
923     if(angle>150 || angle<-150)
924     restriction="no_u_turn";
925     else if(angle>30)
926     restriction="no_right_turn";
927     else if(angle<-30)
928     restriction="no_left_turn";
929     else
930     restriction="no_straight_on";
931    
932 amb 565 printf(" <relation id='%lu' version='1'>\n",(unsigned long)item+1);
933     printf(" <tag k='type' v='restriction' />\n");
934 amb 618 printf(" <tag k='restriction' v='%s'/>\n",restriction);
935 amb 565
936 amb 1078 if(relationp->except)
937     printf(" <tag k='except' v='%s' />\n",AllowedNameList(relationp->except));
938 amb 565
939 amb 1078 printf(" <member type='way' ref='%lu' role='from' />\n",(unsigned long)relationp->from+1);
940     printf(" <member type='node' ref='%lu' role='via' />\n",(unsigned long)relationp->via+1);
941     printf(" <member type='way' ref='%lu' role='to' />\n",(unsigned long)relationp->to+1);
942 amb 565
943     printf(" </relation>\n");
944     }
945    
946    
947     /*++++++++++++++++++++++++++++++++++++++
948 amb 405 Print out a tail in OSM XML format.
949     ++++++++++++++++++++++++++++++++++++++*/
950    
951     static void print_tail_osm(void)
952     {
953     printf("</osm>\n");
954     }
955    
956    
957 amb 1330 /*++++++++++++++++++++++++++++++++++++++
958     Print out the contents of a node from the routing database (in visualiser format).
959    
960     Nodes *nodes The set of nodes to use.
961    
962     index_t item The node index to print.
963     ++++++++++++++++++++++++++++++++++++++*/
964    
965     static void print_node_visualiser(Nodes *nodes,index_t item)
966     {
967     Node *nodep=LookupNode(nodes,item,1);
968     double latitude,longitude;
969     int i;
970    
971     GetLatLong(nodes,item,nodep,&latitude,&longitude);
972    
973     if(nodep->allow==Transports_ALL && nodep->flags==0)
974 amb 1433 printf("&lt;routino:node id='%lu' lat='%.7f' lon='%.7f' /&gt;\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude));
975 amb 1330 else
976     {
977 amb 1433 printf("&lt;routino:node id='%lu' lat='%.7f' lon='%.7f'&gt;\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude));
978 amb 1330
979     if(nodep->flags & NODE_SUPER)
980     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='routino:super' v='yes' /&gt;\n");
981    
982     if(nodep->flags & NODE_UTURN)
983     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='routino:uturn' v='yes' /&gt;\n");
984    
985     if(nodep->flags & NODE_MINIRNDBT)
986     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='junction' v='roundabout' /&gt;\n");
987    
988     if(nodep->flags & NODE_TURNRSTRCT)
989     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='routino:turnrestriction' v='yes' /&gt;\n");
990    
991     for(i=1;i<Transport_Count;i++)
992     if(!(nodep->allow & TRANSPORTS(i)))
993     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='%s' v='no' /&gt;\n",TransportName(i));
994    
995 amb 1433 printf("&lt;/routino:node&gt;\n");
996 amb 1330 }
997     }
998    
999    
1000     /*++++++++++++++++++++++++++++++++++++++
1001     Print out the contents of a segment from the routing database (as a way in visualiser format).
1002    
1003     Segments *segments The set of segments to use.
1004    
1005     index_t item The segment index to print.
1006    
1007     Ways *ways The set of ways to use.
1008     ++++++++++++++++++++++++++++++++++++++*/
1009    
1010     static void print_segment_visualiser(Segments *segments,index_t item,Ways *ways)
1011     {
1012     Segment *segmentp=LookupSegment(segments,item,1);
1013     Way *wayp=LookupWay(ways,segmentp->way,1);
1014     char *name=WayName(ways,wayp);
1015     int i;
1016    
1017 amb 1433 printf("&lt;routino:way id='%lu'&gt;\n",(unsigned long)item+1);
1018 amb 1330
1019     if(IsOnewayTo(segmentp,segmentp->node1))
1020     {
1021     printf("&nbsp;&nbsp;&nbsp;&lt;nd ref='%lu' /&gt;\n",(unsigned long)segmentp->node2+1);
1022     printf("&nbsp;&nbsp;&nbsp;&lt;nd ref='%lu' /&gt;\n",(unsigned long)segmentp->node1+1);
1023     }
1024     else
1025     {
1026     printf("&nbsp;&nbsp;&nbsp;&lt;nd ref='%lu' /&gt;\n",(unsigned long)segmentp->node1+1);
1027     printf("&nbsp;&nbsp;&nbsp;&lt;nd ref='%lu' /&gt;\n",(unsigned long)segmentp->node2+1);
1028     }
1029    
1030     if(IsSuperSegment(segmentp))
1031     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='routino:super' v='yes' /&gt;\n");
1032     if(IsNormalSegment(segmentp))
1033     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='routino:normal' v='yes' /&gt;\n");
1034    
1035     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='routino:distance' v='%.3f km' /&gt;\n",distance_to_km(DISTANCE(segmentp->distance)));
1036    
1037     if(wayp->type & Highway_OneWay)
1038     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='oneway' v='yes' /&gt;\n");
1039    
1040 amb 1560 if(wayp->type & Highway_CycleBothWays)
1041 amb 1559 printf("&nbsp;&nbsp;&nbsp;&lt;tag k='cyclebothways' v='yes' /&gt;\n");
1042    
1043 amb 1330 if(wayp->type & Highway_Roundabout)
1044     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='roundabout' v='yes' /&gt;\n");
1045    
1046     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='highway' v='%s' /&gt;\n",HighwayName(HIGHWAY(wayp->type)));
1047    
1048     if(IsNormalSegment(segmentp) && *name)
1049     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='name' v='%s' /&gt;\n",ParseXML_Encode_Safe_XML(name));
1050    
1051     for(i=1;i<Transport_Count;i++)
1052     if(wayp->allow & TRANSPORTS(i))
1053     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='%s' v='yes' /&gt;\n",TransportName(i));
1054    
1055     for(i=1;i<Property_Count;i++)
1056     if(wayp->props & PROPERTIES(i))
1057     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='%s' v='yes' /&gt;\n",PropertyName(i));
1058    
1059     if(wayp->speed)
1060     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='maxspeed' v='%d kph' /&gt;\n",speed_to_kph(wayp->speed));
1061    
1062     if(wayp->weight)
1063     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='maxweight' v='%.1f t' /&gt;\n",weight_to_tonnes(wayp->weight));
1064     if(wayp->height)
1065     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='maxheight' v='%.1f m' /&gt;\n",height_to_metres(wayp->height));
1066     if(wayp->width)
1067     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='maxwidth' v='%.1f m' /&gt;\n",width_to_metres(wayp->width));
1068     if(wayp->length)
1069     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='maxlength' v='%.1f m' /&gt;\n",length_to_metres(wayp->length));
1070    
1071 amb 1433 printf("&lt;/routino:way&gt;\n");
1072 amb 1330 }
1073    
1074    
1075     /*++++++++++++++++++++++++++++++++++++++
1076     Print out the contents of a turn relation from the routing database (in visualiser format).
1077    
1078     Relations *relations The set of relations to use.
1079    
1080     index_t item The relation index to print.
1081    
1082     Segments *segments The set of segments to use.
1083    
1084     Nodes *nodes The set of nodes to use.
1085     ++++++++++++++++++++++++++++++++++++++*/
1086    
1087     static void print_turn_relation_visualiser(Relations *relations,index_t item,Segments *segments,Nodes *nodes)
1088     {
1089     TurnRelation *relationp=LookupTurnRelation(relations,item,1);
1090    
1091     Segment *segmentp_from=LookupSegment(segments,relationp->from,1);
1092     Segment *segmentp_to =LookupSegment(segments,relationp->to ,2);
1093    
1094     double angle=TurnAngle(nodes,segmentp_from,segmentp_to,relationp->via);
1095    
1096     char *restriction;
1097    
1098     if(angle>150 || angle<-150)
1099     restriction="no_u_turn";
1100     else if(angle>30)
1101     restriction="no_right_turn";
1102     else if(angle<-30)
1103     restriction="no_left_turn";
1104     else
1105     restriction="no_straight_on";
1106    
1107 amb 1433 printf("&lt;routino:relation id='%lu'&gt;\n",(unsigned long)item+1);
1108 amb 1330 printf("&nbsp;&nbsp;&nbsp;&lt;tag k='type' v='restriction' /&gt;\n");
1109     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='restriction' v='%s'/&gt;\n",restriction);
1110    
1111     if(relationp->except)
1112     printf("&nbsp;&nbsp;&nbsp;&lt;tag k='except' v='%s' /&gt;\n",AllowedNameList(relationp->except));
1113    
1114     printf("&nbsp;&nbsp;&nbsp;&lt;member type='way' ref='%lu' role='from' /&gt;\n",(unsigned long)relationp->from+1);
1115     printf("&nbsp;&nbsp;&nbsp;&lt;member type='node' ref='%lu' role='via' /&gt;\n",(unsigned long)relationp->via+1);
1116     printf("&nbsp;&nbsp;&nbsp;&lt;member type='way' ref='%lu' role='to' /&gt;\n",(unsigned long)relationp->to+1);
1117    
1118 amb 1433 printf("&lt;/routino:relation&gt;\n");
1119 amb 1330 }
1120    
1121    
1122     /*++++++++++++++++++++++++++++++++++++++
1123     Print out an error log entry from the database (in visualiser format).
1124    
1125     ErrorLogs *errorlogs The set of error logs to use.
1126    
1127     index_t item The error log index to print.
1128     ++++++++++++++++++++++++++++++++++++++*/
1129    
1130     static void print_errorlog_visualiser(ErrorLogs *errorlogs,index_t item)
1131     {
1132     char *string=LookupErrorLogString(errorlogs,item);
1133    
1134     printf("%s\n",ParseXML_Encode_Safe_XML(string));
1135     }
1136    
1137    
1138 amb 405 /*+ Conversion from time_t to date string (day of week). +*/
1139 amb 185 static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
1140    
1141 amb 405 /*+ Conversion from time_t to date string (month of year). +*/
1142 amb 185 static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
1143    
1144    
1145     /*++++++++++++++++++++++++++++++++++++++
1146     Convert the time into an RFC 822 compliant date.
1147    
1148     char *RFC822Date Returns a pointer to a fixed string containing the date.
1149    
1150     time_t t The time.
1151     ++++++++++++++++++++++++++++++++++++++*/
1152    
1153     static char *RFC822Date(time_t t)
1154     {
1155     static char value[32];
1156     char weekday[4];
1157     char month[4];
1158     struct tm *tim;
1159    
1160     tim=gmtime(&t);
1161    
1162     strcpy(weekday,weekdays[tim->tm_wday]);
1163     strcpy(month,months[tim->tm_mon]);
1164    
1165     /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */
1166    
1167     sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s",
1168     weekday,
1169     tim->tm_mday,
1170     month,
1171     tim->tm_year+1900,
1172     tim->tm_hour,
1173     tim->tm_min,
1174     tim->tm_sec,
1175     "GMT"
1176     );
1177    
1178     return(value);
1179     }
1180 amb 342
1181    
1182     /*++++++++++++++++++++++++++++++++++++++
1183     Print out the usage information.
1184    
1185     int detail The level of detail to use - 0 = low, 1 = high.
1186 amb 490
1187     const char *argerr The argument that gave the error (if there is one).
1188    
1189     const char *err Other error message (if there is one).
1190 amb 342 ++++++++++++++++++++++++++++++++++++++*/
1191    
1192 amb 490 static void print_usage(int detail,const char *argerr,const char *err)
1193 amb 342 {
1194     fprintf(stderr,
1195     "Usage: filedumper [--help]\n"
1196     " [--dir=<dirname>] [--prefix=<name>]\n"
1197     " [--statistics]\n"
1198     " [--visualiser --latmin=<latmin> --latmax=<latmax>\n"
1199     " --lonmin=<lonmin> --lonmax=<lonmax>\n"
1200     " --data=<data-type>]\n"
1201     " [--dump [--node=<node> ...]\n"
1202     " [--segment=<segment> ...]\n"
1203 amb 1150 " [--way=<way> ...]\n"
1204 amb 1330 " [--turn-relation=<rel> ...]\n"
1205     " [--errorlog=<number> ...]]\n"
1206 amb 413 " [--dump-osm [--no-super]\n"
1207     " [--latmin=<latmin> --latmax=<latmax>\n"
1208 amb 1330 " --lonmin=<lonmin> --lonmax=<lonmax>]]\n"
1209 amb 1458 " [--dump-visualiser [--data=node<node>]\n"
1210     " [--data=segment<segment>]\n"
1211     " [--data=turn-relation<rel>]\n"
1212     " [--data=errorlog<number>]]\n");
1213 amb 342
1214 amb 490 if(argerr)
1215     fprintf(stderr,
1216     "\n"
1217     "Error with command line parameter: %s\n",argerr);
1218    
1219 amb 491 if(err)
1220 amb 490 fprintf(stderr,
1221     "\n"
1222     "Error: %s\n",err);
1223    
1224 amb 342 if(detail)
1225     fprintf(stderr,
1226     "\n"
1227     "--help Prints this information.\n"
1228     "\n"
1229     "--dir=<dirname> The directory containing the routing database.\n"
1230     "--prefix=<name> The filename prefix for the routing database.\n"
1231     "\n"
1232     "--statistics Print statistics about the routing database.\n"
1233     "\n"
1234     "--visualiser Extract selected data from the routing database:\n"
1235     " --latmin=<latmin> * the minimum latitude (degrees N).\n"
1236     " --latmax=<latmax> * the maximum latitude (degrees N).\n"
1237     " --lonmin=<lonmin> * the minimum longitude (degrees E).\n"
1238     " --lonmax=<lonmax> * the maximum longitude (degrees E).\n"
1239     " --data=<data-type> * the type of data to select.\n"
1240     "\n"
1241     " <data-type> can be selected from:\n"
1242 amb 1002 " junctions = segment count at each junction.\n"
1243     " super = super-node and super-segments.\n"
1244 amb 1560 " waytype-* = segments of oneway, cyclebothways or roundabout type.\n"
1245 amb 1003 " highway-* = segments of the specified highway type.\n"
1246 amb 1002 " transport-* = segments allowing the specified transport type.\n"
1247 amb 1077 " barrier-* = nodes disallowing the specified transport type.\n"
1248 amb 1002 " turns = turn restrictions.\n"
1249     " speed = speed limits.\n"
1250     " weight = weight limits.\n"
1251     " height = height limits.\n"
1252     " width = width limits.\n"
1253     " length = length limits.\n"
1254 amb 1248 " property-* = segments with the specified property.\n"
1255 amb 1321 " errorlogs = errors logged during parsing.\n"
1256 amb 342 "\n"
1257     "--dump Dump selected contents of the database.\n"
1258 amb 1330 " --node=<node> * the node with the selected index.\n"
1259     " --segment=<segment> * the segment with the selected index.\n"
1260     " --way=<way> * the way with the selected index.\n"
1261     " --turn-relation=<rel> * the turn relation with the selected index.\n"
1262     " --errorlog=<number> * the error log with the selected index.\n"
1263 amb 405 " Use 'all' instead of a number to get all of them.\n"
1264     "\n"
1265 amb 413 "--dump-osm Dump all or part of the database as an XML file.\n"
1266 amb 1330 " --no-super * exclude the super-segments.\n"
1267     " --latmin=<latmin> * the minimum latitude (degrees N).\n"
1268     " --latmax=<latmax> * the maximum latitude (degrees N).\n"
1269     " --lonmin=<lonmin> * the minimum longitude (degrees E).\n"
1270     " --lonmax=<lonmax> * the maximum longitude (degrees E).\n"
1271     "\n"
1272     "--dump-visualiser Dump selected contents of the database in HTML.\n"
1273     " --data=node<node> * the node with the selected index.\n"
1274     " --data=segment<segment> * the segment with the selected index.\n"
1275     " --data=turn-relation<rel> * the turn relation with the selected index.\n"
1276     " --data=errorlog<number> * the error log with the selected index.\n");
1277 amb 342
1278     exit(!detail);
1279     }

Properties

Name Value
cvs:description Test program for mmap files.