Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/filedumper.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1950 - (hide annotations) (download) (as text)
Sat Jul 28 16:45:09 2018 UTC (6 years, 7 months ago) by amb
File MIME type: text/x-csrc
File size: 46972 byte(s)
Fix two warnings found by gcc-8.

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

Properties

Name Value
cvs:description Test program for mmap files.