Routino SVN Repository Browser

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

ViewVC logotype

Contents of /trunk/src/filedumper.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 680 - (show annotations) (download) (as text)
Sun Apr 24 15:14:53 2011 UTC (13 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 29976 byte(s)
Update comments throughout the source code.

1 /***************************************
2 Memory file dumper.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2011 Andrew M. Bishop
7
8 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 ***************************************/
21
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/stat.h>
27 #include <sys/time.h>
28 #include <time.h>
29 #include <math.h>
30
31 #include "types.h"
32 #include "nodes.h"
33 #include "segments.h"
34 #include "ways.h"
35 #include "relations.h"
36
37 #include "files.h"
38 #include "visualiser.h"
39 #include "xmlparse.h"
40
41
42 /* Local functions */
43
44 static void print_node(Nodes* nodes,index_t item);
45 static void print_segment(Segments *segments,index_t item);
46 static void print_way(Ways *ways,index_t item);
47 static void print_turnrelation(Relations *relations,index_t item,Segments *segments,Nodes* nodes);
48
49 static void print_head_osm(void);
50 static void print_node_osm(Nodes* nodes,index_t item);
51 static void print_segment_osm(Segments *segments,index_t item,Ways *ways);
52 static void print_turnrelation_osm(Relations* relations,index_t item,Segments *segments,Nodes* nodes);
53 static void print_tail_osm(void);
54
55 static char *RFC822Date(time_t t);
56
57 static void print_usage(int detail,const char *argerr,const char *err);
58
59
60 /*++++++++++++++++++++++++++++++++++++++
61 The main program for the file dumper.
62 ++++++++++++++++++++++++++++++++++++++*/
63
64 int main(int argc,char** argv)
65 {
66 Nodes *OSMNodes;
67 Segments *OSMSegments;
68 Ways *OSMWays;
69 Relations*OSMRelations;
70 int arg;
71 char *dirname=NULL,*prefix=NULL;
72 char *nodes_filename,*segments_filename,*ways_filename,*relations_filename;
73 int option_statistics=0;
74 int option_visualiser=0,coordcount=0;
75 double latmin=0,latmax=0,lonmin=0,lonmax=0;
76 char *option_data=NULL;
77 int option_dump=0;
78 int option_dump_osm=0,option_no_super=0;
79
80 /* Parse the command line arguments */
81
82 for(arg=1;arg<argc;arg++)
83 {
84 if(!strcmp(argv[arg],"--help"))
85 print_usage(1,NULL,NULL);
86 else if(!strncmp(argv[arg],"--dir=",6))
87 dirname=&argv[arg][6];
88 else if(!strncmp(argv[arg],"--prefix=",9))
89 prefix=&argv[arg][9];
90 else if(!strcmp(argv[arg],"--statistics"))
91 option_statistics=1;
92 else if(!strcmp(argv[arg],"--visualiser"))
93 option_visualiser=1;
94 else if(!strcmp(argv[arg],"--dump"))
95 option_dump=1;
96 else if(!strcmp(argv[arg],"--dump-osm"))
97 option_dump_osm=1;
98 else if(!strncmp(argv[arg],"--latmin",8) && argv[arg][8]=='=')
99 {latmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
100 else if(!strncmp(argv[arg],"--latmax",8) && argv[arg][8]=='=')
101 {latmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
102 else if(!strncmp(argv[arg],"--lonmin",8) && argv[arg][8]=='=')
103 {lonmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
104 else if(!strncmp(argv[arg],"--lonmax",8) && argv[arg][8]=='=')
105 {lonmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;}
106 else if(!strncmp(argv[arg],"--data",6) && argv[arg][6]=='=')
107 option_data=&argv[arg][7];
108 else if(!strcmp(argv[arg],"--no-super"))
109 option_no_super=1;
110 else if(!strncmp(argv[arg],"--node=",7))
111 ;
112 else if(!strncmp(argv[arg],"--segment=",10))
113 ;
114 else if(!strncmp(argv[arg],"--way=",6))
115 ;
116 else if(!strncmp(argv[arg],"--turn-relation=",16))
117 ;
118 else
119 print_usage(0,argv[arg],NULL);
120 }
121
122 if((option_statistics + option_visualiser + option_dump + option_dump_osm)!=1)
123 print_usage(0,NULL,"Must choose --visualiser, --statistics, --dump or --dump-osm.");
124
125 /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */
126
127 OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem"));
128
129 OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem"));
130
131 OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem"));
132
133 OSMRelations=LoadRelationList(relations_filename=FileName(dirname,prefix,"relations.mem"));
134
135 /* Write out the visualiser data */
136
137 if(option_visualiser)
138 {
139 if(coordcount!=4)
140 print_usage(0,NULL,"The --visualiser option must have --latmin, --latmax, --lonmin, --lonmax.\n");
141
142 if(!option_data)
143 print_usage(0,NULL,"The --visualiser option must have --data.\n");
144
145 if(!strcmp(option_data,"junctions"))
146 OutputJunctions(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
147 else if(!strcmp(option_data,"super"))
148 OutputSuper(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
149 else if(!strcmp(option_data,"oneway"))
150 OutputOneway(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
151 else if(!strcmp(option_data,"turns"))
152 OutputTurnRestrictions(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
153 else if(!strcmp(option_data,"speed"))
154 OutputSpeedLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
155 else if(!strcmp(option_data,"weight"))
156 OutputWeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
157 else if(!strcmp(option_data,"height"))
158 OutputHeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
159 else if(!strcmp(option_data,"width"))
160 OutputWidthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
161 else if(!strcmp(option_data,"length"))
162 OutputLengthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
163 else
164 print_usage(0,option_data,NULL);
165 }
166
167 /* Print out statistics */
168
169 if(option_statistics)
170 {
171 struct stat buf;
172
173 /* Examine the files */
174
175 printf("Files\n");
176 printf("-----\n");
177 printf("\n");
178
179 stat(nodes_filename,&buf);
180
181 printf("'%s%snodes.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size);
182 printf("%s\n",RFC822Date(buf.st_mtime));
183 printf("\n");
184
185 stat(segments_filename,&buf);
186
187 printf("'%s%ssegments.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size);
188 printf("%s\n",RFC822Date(buf.st_mtime));
189 printf("\n");
190
191 stat(ways_filename,&buf);
192
193 printf("'%s%sways.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size);
194 printf("%s\n",RFC822Date(buf.st_mtime));
195 printf("\n");
196
197 stat(relations_filename,&buf);
198
199 printf("'%s%srelations.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size);
200 printf("%s\n",RFC822Date(buf.st_mtime));
201 printf("\n");
202
203 /* Examine the nodes */
204
205 printf("Nodes\n");
206 printf("-----\n");
207 printf("\n");
208
209 printf("sizeof(Node) =%9d Bytes\n",sizeof(Node));
210 printf("Number =%9d\n",OSMNodes->file.number);
211 printf("Number(super)=%9d\n",OSMNodes->file.snumber);
212 printf("\n");
213
214 printf("Lat bins= %4d\n",OSMNodes->file.latbins);
215 printf("Lon bins= %4d\n",OSMNodes->file.lonbins);
216 printf("\n");
217
218 printf("Lat zero=%5d (%8.4f deg)\n",OSMNodes->file.latzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.latzero))));
219 printf("Lon zero=%5d (%8.4f deg)\n",OSMNodes->file.lonzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.lonzero))));
220
221 /* Examine the segments */
222
223 printf("\n");
224 printf("Segments\n");
225 printf("--------\n");
226 printf("\n");
227
228 printf("sizeof(Segment)=%9d Bytes\n",sizeof(Segment));
229 printf("Number(total) =%9d\n",OSMSegments->file.number);
230 printf("Number(super) =%9d\n",OSMSegments->file.snumber);
231 printf("Number(normal) =%9d\n",OSMSegments->file.nnumber);
232
233 /* Examine the ways */
234
235 printf("\n");
236 printf("Ways\n");
237 printf("----\n");
238 printf("\n");
239
240 printf("sizeof(Way) =%9d Bytes\n",sizeof(Way));
241 printf("Number(compacted)=%9d\n",OSMWays->file.number);
242 printf("Number(original) =%9d\n",OSMWays->file.onumber);
243 printf("\n");
244
245 stat(ways_filename,&buf);
246 printf("Total names =%9ld Bytes\n",(long)buf.st_size-sizeof(Ways)-OSMWays->file.number*sizeof(Way));
247 printf("\n");
248
249 printf("Included highways : %s\n",HighwaysNameList(OSMWays->file.highways));
250 printf("Included transports: %s\n",AllowedNameList(OSMWays->file.allow));
251 printf("Included properties: %s\n",PropertiesNameList(OSMWays->file.props));
252
253 /* Examine the relations */
254
255 printf("\n");
256 printf("Relations\n");
257 printf("---------\n");
258 printf("\n");
259
260 printf("sizeof(TurnRelation)=%9d Bytes\n",sizeof(TurnRelation));
261 printf("Number =%9d\n",OSMRelations->file.trnumber);
262 }
263
264 /* Print out internal data (in plain text format) */
265
266 if(option_dump)
267 {
268 index_t item;
269
270 for(arg=1;arg<argc;arg++)
271 if(!strcmp(argv[arg],"--node=all"))
272 {
273 for(item=0;item<OSMNodes->file.number;item++)
274 print_node(OSMNodes,item);
275 }
276 else if(!strncmp(argv[arg],"--node=",7))
277 {
278 item=atoi(&argv[arg][7]);
279
280 if(item>=0 && item<OSMNodes->file.number)
281 print_node(OSMNodes,item);
282 else
283 printf("Invalid node number; minimum=0, maximum=%d.\n",OSMNodes->file.number-1);
284 }
285 else if(!strcmp(argv[arg],"--segment=all"))
286 {
287 for(item=0;item<OSMSegments->file.number;item++)
288 print_segment(OSMSegments,item);
289 }
290 else if(!strncmp(argv[arg],"--segment=",10))
291 {
292 item=atoi(&argv[arg][10]);
293
294 if(item>=0 && item<OSMSegments->file.number)
295 print_segment(OSMSegments,item);
296 else
297 printf("Invalid segment number; minimum=0, maximum=%d.\n",OSMSegments->file.number-1);
298 }
299 else if(!strcmp(argv[arg],"--way=all"))
300 {
301 for(item=0;item<OSMWays->file.number;item++)
302 print_way(OSMWays,item);
303 }
304 else if(!strncmp(argv[arg],"--way=",6))
305 {
306 item=atoi(&argv[arg][6]);
307
308 if(item>=0 && item<OSMWays->file.number)
309 print_way(OSMWays,item);
310 else
311 printf("Invalid way number; minimum=0, maximum=%d.\n",OSMWays->file.number-1);
312 }
313 else if(!strcmp(argv[arg],"--turn-relation=all"))
314 {
315 for(item=0;item<OSMRelations->file.trnumber;item++)
316 print_turnrelation(OSMRelations,item,OSMSegments,OSMNodes);
317 }
318 else if(!strncmp(argv[arg],"--turn-relation=",16))
319 {
320 item=atoi(&argv[arg][16]);
321
322 if(item>=0 && item<OSMRelations->file.trnumber)
323 print_turnrelation(OSMRelations,item,OSMSegments,OSMNodes);
324 else
325 printf("Invalid turn relation number; minimum=0, maximum=%d.\n",OSMRelations->file.trnumber-1);
326 }
327 }
328
329 /* Print out internal data (in OSM XML format) */
330
331 if(option_dump_osm)
332 {
333 if(coordcount>0 && coordcount!=4)
334 print_usage(0,NULL,"The --dump-osm option must have all of --latmin, --latmax, --lonmin, --lonmax or none.\n");
335
336 print_head_osm();
337
338 if(coordcount)
339 {
340 int32_t latminbin=latlong_to_bin(radians_to_latlong(latmin))-OSMNodes->file.latzero;
341 int32_t latmaxbin=latlong_to_bin(radians_to_latlong(latmax))-OSMNodes->file.latzero;
342 int32_t lonminbin=latlong_to_bin(radians_to_latlong(lonmin))-OSMNodes->file.lonzero;
343 int32_t lonmaxbin=latlong_to_bin(radians_to_latlong(lonmax))-OSMNodes->file.lonzero;
344 int latb,lonb,llbin;
345 index_t item,index1,index2;
346
347 if(latminbin<0) latminbin=0;
348 if(latmaxbin>OSMNodes->file.latbins) latmaxbin=OSMNodes->file.latbins-1;
349 if(lonminbin<0) lonminbin=0;
350 if(lonmaxbin>OSMNodes->file.lonbins) lonmaxbin=OSMNodes->file.lonbins-1;
351
352 /* Loop through all of the nodes. */
353
354 for(latb=latminbin;latb<=latmaxbin;latb++)
355 for(lonb=lonminbin;lonb<=lonmaxbin;lonb++)
356 {
357 llbin=lonb*OSMNodes->file.latbins+latb;
358
359 if(llbin<0 || llbin>(OSMNodes->file.latbins*OSMNodes->file.lonbins))
360 continue;
361
362 index1=LookupNodeOffset(OSMNodes,llbin);
363 index2=LookupNodeOffset(OSMNodes,llbin+1);
364
365 for(item=index1;item<index2;item++)
366 {
367 Node *node=LookupNode(OSMNodes,item,1);
368 double lat=latlong_to_radians(bin_to_latlong(OSMNodes->file.latzero+latb)+off_to_latlong(node->latoffset));
369 double lon=latlong_to_radians(bin_to_latlong(OSMNodes->file.lonzero+lonb)+off_to_latlong(node->lonoffset));
370
371 if(lat>latmin && lat<latmax && lon>lonmin && lon<lonmax)
372 {
373 Segment *segment;
374
375 print_node_osm(OSMNodes,item);
376
377 segment=FirstSegment(OSMSegments,OSMNodes,item);
378
379 while(segment)
380 {
381 if(item>OtherNode(segment,item))
382 if(!option_no_super || IsNormalSegment(segment))
383 print_segment_osm(OSMSegments,IndexSegment(OSMSegments,segment),OSMWays);
384
385 segment=NextSegment(OSMSegments,segment,item);
386 }
387
388 if(node->flags&NODE_TURNRSTRCT)
389 {
390 index_t relindex=FindFirstTurnRelation1(OSMRelations,item);
391
392 while(relindex!=NO_RELATION)
393 {
394 print_turnrelation_osm(OSMRelations,relindex,OSMSegments,OSMNodes);
395
396 relindex=FindNextTurnRelation1(OSMRelations,relindex);
397 }
398 }
399 }
400 }
401 }
402 }
403 else
404 {
405 index_t item;
406
407 for(item=0;item<OSMNodes->file.number;item++)
408 print_node_osm(OSMNodes,item);
409
410 for(item=0;item<OSMSegments->file.number;item++)
411 if(!option_no_super || IsNormalSegment(LookupSegment(OSMSegments,item,1)))
412 print_segment_osm(OSMSegments,item,OSMWays);
413
414 for(item=0;item<OSMRelations->file.trnumber;item++)
415 print_turnrelation_osm(OSMRelations,item,OSMSegments,OSMNodes);
416 }
417
418 print_tail_osm();
419 }
420
421 return(0);
422 }
423
424
425 /*++++++++++++++++++++++++++++++++++++++
426 Print out the contents of a node from the routing database (as plain text).
427
428 Nodes *nodes The set of nodes to use.
429
430 index_t item The node index to print.
431 ++++++++++++++++++++++++++++++++++++++*/
432
433 static void print_node(Nodes* nodes,index_t item)
434 {
435 Node *node=LookupNode(nodes,item,1);
436 double latitude,longitude;
437
438 GetLatLong(nodes,item,&latitude,&longitude);
439
440 printf("Node %d\n",item);
441 printf(" firstseg=%d\n",node->firstseg);
442 printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",node->latoffset,node->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude));
443 printf(" allow=%02x (%s)\n",node->allow,AllowedNameList(node->allow));
444 if(IsSuperNode(node))
445 printf(" Super-Node\n");
446 }
447
448
449 /*++++++++++++++++++++++++++++++++++++++
450 Print out the contents of a segment from the routing database (as plain text).
451
452 Segments *segments The set of segments to use.
453
454 index_t item The segment index to print.
455 ++++++++++++++++++++++++++++++++++++++*/
456
457 static void print_segment(Segments *segments,index_t item)
458 {
459 Segment *segment=LookupSegment(segments,item,1);
460
461 printf("Segment %d\n",item);
462 printf(" node1=%d node2=%d\n",segment->node1,segment->node2);
463 printf(" next2=%d\n",segment->next2);
464 printf(" way=%d\n",segment->way);
465 printf(" distance=%d (%.3f km)\n",DISTANCE(segment->distance),distance_to_km(DISTANCE(segment->distance)));
466 if(IsSuperSegment(segment) && IsNormalSegment(segment))
467 printf(" Super-Segment AND normal Segment\n");
468 else if(IsSuperSegment(segment) && !IsNormalSegment(segment))
469 printf(" Super-Segment\n");
470 if(IsOnewayTo(segment,segment->node1))
471 printf(" One-Way from node2 to node1\n");
472 if(IsOnewayTo(segment,segment->node2))
473 printf(" One-Way from node1 to node2\n");
474 }
475
476
477 /*++++++++++++++++++++++++++++++++++++++
478 Print out the contents of a way from the routing database (as plain text).
479
480 Ways *ways The set of ways to use.
481
482 index_t item The way index to print.
483 ++++++++++++++++++++++++++++++++++++++*/
484
485 static void print_way(Ways *ways,index_t item)
486 {
487 Way *way=LookupWay(ways,item,1);
488
489 printf("Way %d\n",item);
490 if(*WayName(ways,way))
491 printf(" name=%s\n",WayName(ways,way));
492 printf(" type=%02x (%s%s)\n",way->type,HighwayName(HIGHWAY(way->type)),way->type&Way_OneWay?",One-Way":"");
493 printf(" allow=%02x (%s)\n",way->allow,AllowedNameList(way->allow));
494 if(way->props)
495 printf(" props=%02x (%s)\n",way->props,PropertiesNameList(way->props));
496 if(way->speed)
497 printf(" speed=%d (%d km/hr)\n",way->speed,speed_to_kph(way->speed));
498 if(way->weight)
499 printf(" weight=%d (%.1f tonnes)\n",way->weight,weight_to_tonnes(way->weight));
500 if(way->height)
501 printf(" height=%d (%.1f m)\n",way->height,height_to_metres(way->height));
502 if(way->width)
503 printf(" width=%d (%.1f m)\n",way->width,width_to_metres(way->width));
504 if(way->length)
505 printf(" length=%d (%.1f m)\n",way->length,length_to_metres(way->length));
506 }
507
508
509 /*++++++++++++++++++++++++++++++++++++++
510 Print out the contents of a turn relation from the routing database (as plain text).
511
512 Relations *relations The set of relations to use.
513
514 index_t item The turn relation index to print.
515
516 Segments *segments The set of segments to use.
517
518 Nodes *nodes The set of nodes to use.
519 ++++++++++++++++++++++++++++++++++++++*/
520
521 static void print_turnrelation(Relations *relations,index_t item,Segments *segments,Nodes* nodes)
522 {
523 TurnRelation *relation=LookupTurnRelation(relations,item,1);
524 Segment *segment;
525 index_t from_way=NO_WAY,to_way=NO_WAY;
526 index_t from_node=NO_NODE,to_node=NO_NODE;
527
528 segment=FirstSegment(segments,nodes,relation->via);
529
530 do
531 {
532 index_t seg=IndexSegment(segments,segment);
533
534 if(seg==relation->from)
535 {
536 from_node=OtherNode(segment,relation->from);
537 from_way=segment->way;
538 }
539
540 if(seg==relation->to)
541 {
542 to_node=OtherNode(segment,relation->to);
543 to_way=segment->way;
544 }
545
546 segment=NextSegment(segments,segment,relation->via);
547 }
548 while(segment);
549
550 printf("Relation %d\n",item);
551 printf(" from=%d (segment) = %d (way) = %d (node)\n",relation->from,from_way,from_node);
552 printf(" via=%d (node)\n",relation->via);
553 printf(" to=%d (segment) = %d (way) = %d (node)\n",relation->to,to_way,to_node);
554 if(relation->except)
555 printf(" except=%02x (%s)\n",relation->except,AllowedNameList(relation->except));
556 }
557
558
559 /*++++++++++++++++++++++++++++++++++++++
560 Print out a header in OSM XML format.
561 ++++++++++++++++++++++++++++++++++++++*/
562
563 static void print_head_osm(void)
564 {
565 printf("<?xml version='1.0' encoding='UTF-8'?>\n");
566 printf("<osm version='0.6' generator='JOSM'>\n");
567 }
568
569
570 /*++++++++++++++++++++++++++++++++++++++
571 Print out the contents of a node from the routing database (in OSM XML format).
572
573 Nodes *nodes The set of nodes to use.
574
575 index_t item The node index to print.
576 ++++++++++++++++++++++++++++++++++++++*/
577
578 static void print_node_osm(Nodes* nodes,index_t item)
579 {
580 Node *node=LookupNode(nodes,item,1);
581 double latitude,longitude;
582 int i;
583
584 GetLatLong(nodes,item,&latitude,&longitude);
585
586 if(node->allow==Transports_ALL && node->flags==0)
587 printf(" <node id='%lu' lat='%.7f' lon='%.7f' version='1' />\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude));
588 else
589 {
590 printf(" <node id='%lu' lat='%.7f' lon='%.7f' version='1'>\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude));
591
592 if(node->flags & NODE_SUPER)
593 printf(" <tag k='routino:super' v='yes' />\n");
594
595 if(node->flags & NODE_UTURN)
596 printf(" <tag k='routino:uturn' v='yes' />\n");
597
598 if(node->flags & NODE_MINIRNDBT)
599 printf(" <tag k='highway' v='mini_roundabout' />\n");
600
601 if(node->flags & NODE_TURNRSTRCT)
602 printf(" <tag k='routino:turnrestriction' v='yes' />\n");
603
604 for(i=1;i<Transport_Count;i++)
605 if(!(node->allow & TRANSPORTS(i)))
606 printf(" <tag k='%s' v='no' />\n",TransportName(i));
607
608 printf(" </node>\n");
609 }
610 }
611
612
613 /*++++++++++++++++++++++++++++++++++++++
614 Print out the contents of a segment from the routing database (as a way in OSM XML format).
615
616 Segments *segments The set of segments to use.
617
618 index_t item The segment index to print.
619
620 Ways *ways The set of ways to use.
621 ++++++++++++++++++++++++++++++++++++++*/
622
623 static void print_segment_osm(Segments *segments,index_t item,Ways *ways)
624 {
625 Segment *segment=LookupSegment(segments,item,1);
626 Way *way=LookupWay(ways,segment->way,1);
627 int i;
628
629 printf(" <way id='%lu' version='1'>\n",(unsigned long)item+1);
630
631 if(IsOnewayTo(segment,segment->node1))
632 {
633 printf(" <nd ref='%lu' />\n",(unsigned long)segment->node2+1);
634 printf(" <nd ref='%lu' />\n",(unsigned long)segment->node1+1);
635 }
636 else
637 {
638 printf(" <nd ref='%lu' />\n",(unsigned long)segment->node1+1);
639 printf(" <nd ref='%lu' />\n",(unsigned long)segment->node2+1);
640 }
641
642 if(IsSuperSegment(segment))
643 printf(" <tag k='routino:super' v='yes' />\n");
644 if(IsNormalSegment(segment))
645 printf(" <tag k='routino:normal' v='yes' />\n");
646
647 printf(" <tag k='routino:distance' v='%.3f' />\n",distance_to_km(DISTANCE(segment->distance)));
648
649 if(way->type & Way_OneWay)
650 printf(" <tag k='oneway' v='yes' />\n");
651
652 printf(" <tag k='highway' v='%s' />\n",HighwayName(HIGHWAY(way->type)));
653
654 if(IsNormalSegment(segment) && *WayName(ways,way))
655 printf(" <tag k='name' v='%s' />\n",ParseXML_Encode_Safe_XML(WayName(ways,way)));
656
657 for(i=1;i<Transport_Count;i++)
658 if(way->allow & TRANSPORTS(i))
659 printf(" <tag k='%s' v='yes' />\n",TransportName(i));
660
661 for(i=1;i<Property_Count;i++)
662 if(way->props & PROPERTIES(i))
663 printf(" <tag k='%s' v='yes' />\n",PropertyName(i));
664
665 if(way->speed)
666 printf(" <tag k='maxspeed' v='%d' />\n",speed_to_kph(way->speed));
667
668 if(way->weight)
669 printf(" <tag k='maxweight' v='%.1f' />\n",weight_to_tonnes(way->weight));
670 if(way->height)
671 printf(" <tag k='maxheight' v='%.1f' />\n",height_to_metres(way->height));
672 if(way->width)
673 printf(" <tag k='maxwidth' v='%.1f' />\n",width_to_metres(way->width));
674 if(way->length)
675 printf(" <tag k='maxlength' v='%.1f' />\n",length_to_metres(way->length));
676
677 printf(" </way>\n");
678 }
679
680
681 /*++++++++++++++++++++++++++++++++++++++
682 Print out the contents of a turn relation from the routing database (in OSM XML format).
683
684 Relations *relations The set of relations to use.
685
686 index_t item The relation index to print.
687
688 Segments *segments The set of segments to use.
689
690 Nodes *nodes The set of nodes to use.
691 ++++++++++++++++++++++++++++++++++++++*/
692
693 static void print_turnrelation_osm(Relations* relations,index_t item,Segments *segments,Nodes* nodes)
694 {
695 TurnRelation *relation=LookupTurnRelation(relations,item,1);
696
697 Segment *segment_from=LookupSegment(segments,relation->from,1);
698 Segment *segment_to =LookupSegment(segments,relation->to ,1);
699
700 double angle=TurnAngle(nodes,segment_from,segment_to,relation->via);
701
702 char *restriction;
703
704 if(angle>150 || angle<-150)
705 restriction="no_u_turn";
706 else if(angle>30)
707 restriction="no_right_turn";
708 else if(angle<-30)
709 restriction="no_left_turn";
710 else
711 restriction="no_straight_on";
712
713 printf(" <relation id='%lu' version='1'>\n",(unsigned long)item+1);
714 printf(" <tag k='type' v='restriction' />\n");
715 printf(" <tag k='restriction' v='%s'/>\n",restriction);
716
717 if(relation->except)
718 printf(" <tag k='except' v='%s' />\n",AllowedNameList(relation->except));
719
720 printf(" <member type='way' ref='%lu' role='from' />\n",(unsigned long)relation->from+1);
721 printf(" <member type='node' ref='%lu' role='via' />\n",(unsigned long)relation->via+1);
722 printf(" <member type='way' ref='%lu' role='to' />\n",(unsigned long)relation->to+1);
723
724 printf(" </relation>\n");
725 }
726
727
728 /*++++++++++++++++++++++++++++++++++++++
729 Print out a tail in OSM XML format.
730 ++++++++++++++++++++++++++++++++++++++*/
731
732 static void print_tail_osm(void)
733 {
734 printf("</osm>\n");
735 }
736
737
738 /*+ Conversion from time_t to date string (day of week). +*/
739 static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
740
741 /*+ Conversion from time_t to date string (month of year). +*/
742 static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
743
744
745 /*++++++++++++++++++++++++++++++++++++++
746 Convert the time into an RFC 822 compliant date.
747
748 char *RFC822Date Returns a pointer to a fixed string containing the date.
749
750 time_t t The time.
751 ++++++++++++++++++++++++++++++++++++++*/
752
753 static char *RFC822Date(time_t t)
754 {
755 static char value[32];
756 char weekday[4];
757 char month[4];
758 struct tm *tim;
759
760 tim=gmtime(&t);
761
762 strcpy(weekday,weekdays[tim->tm_wday]);
763 strcpy(month,months[tim->tm_mon]);
764
765 /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */
766
767 sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s",
768 weekday,
769 tim->tm_mday,
770 month,
771 tim->tm_year+1900,
772 tim->tm_hour,
773 tim->tm_min,
774 tim->tm_sec,
775 "GMT"
776 );
777
778 return(value);
779 }
780
781
782 /*++++++++++++++++++++++++++++++++++++++
783 Print out the usage information.
784
785 int detail The level of detail to use - 0 = low, 1 = high.
786
787 const char *argerr The argument that gave the error (if there is one).
788
789 const char *err Other error message (if there is one).
790 ++++++++++++++++++++++++++++++++++++++*/
791
792 static void print_usage(int detail,const char *argerr,const char *err)
793 {
794 fprintf(stderr,
795 "Usage: filedumper [--help]\n"
796 " [--dir=<dirname>] [--prefix=<name>]\n"
797 " [--statistics]\n"
798 " [--visualiser --latmin=<latmin> --latmax=<latmax>\n"
799 " --lonmin=<lonmin> --lonmax=<lonmax>\n"
800 " --data=<data-type>]\n"
801 " [--dump [--node=<node> ...]\n"
802 " [--segment=<segment> ...]\n"
803 " [--way=<way> ...]]\n"
804 " [--turn-relation=<rel> ...]]\n"
805 " [--dump-osm [--no-super]\n"
806 " [--latmin=<latmin> --latmax=<latmax>\n"
807 " --lonmin=<lonmin> --lonmax=<lonmax>]]\n");
808
809 if(argerr)
810 fprintf(stderr,
811 "\n"
812 "Error with command line parameter: %s\n",argerr);
813
814 if(err)
815 fprintf(stderr,
816 "\n"
817 "Error: %s\n",err);
818
819 if(detail)
820 fprintf(stderr,
821 "\n"
822 "--help Prints this information.\n"
823 "\n"
824 "--dir=<dirname> The directory containing the routing database.\n"
825 "--prefix=<name> The filename prefix for the routing database.\n"
826 "\n"
827 "--statistics Print statistics about the routing database.\n"
828 "\n"
829 "--visualiser Extract selected data from the routing database:\n"
830 " --latmin=<latmin> * the minimum latitude (degrees N).\n"
831 " --latmax=<latmax> * the maximum latitude (degrees N).\n"
832 " --lonmin=<lonmin> * the minimum longitude (degrees E).\n"
833 " --lonmax=<lonmax> * the maximum longitude (degrees E).\n"
834 " --data=<data-type> * the type of data to select.\n"
835 "\n"
836 " <data-type> can be selected from:\n"
837 " junctions = segment count at each junction.\n"
838 " super = super-node and super-segments.\n"
839 " oneway = oneway segments.\n"
840 " turns = turn restrictions.\n"
841 " speed = speed limits.\n"
842 " weight = weight limits.\n"
843 " height = height limits.\n"
844 " width = width limits.\n"
845 " length = length limits.\n"
846 "\n"
847 "--dump Dump selected contents of the database.\n"
848 " --node=<node> * the node with the selected index.\n"
849 " --segment=<segment> * the segment with the selected index.\n"
850 " --way=<way> * the way with the selected index.\n"
851 " --turn-relation=<rel> * the turn relation with the selected index.\n"
852 " Use 'all' instead of a number to get all of them.\n"
853 "\n"
854 "--dump-osm Dump all or part of the database as an XML file.\n"
855 " --no-super * exclude the super-segments.\n"
856 " --latmin=<latmin> * the minimum latitude (degrees N).\n"
857 " --latmax=<latmax> * the maximum latitude (degrees N).\n"
858 " --lonmin=<lonmin> * the minimum longitude (degrees E).\n"
859 " --lonmax=<lonmax> * the maximum longitude (degrees E).\n");
860
861 exit(!detail);
862 }

Properties

Name Value
cvs:description Test program for mmap files.