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 1630 - (hide annotations) (download) (as text)
Sun Mar 22 15:49:58 2015 UTC (9 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 48019 byte(s)
Dump the destination information from the filedumper, update the
visualiser to use it.

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

Properties

Name Value
cvs:description Test program for mmap files.