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 885 - (show annotations) (download) (as text)
Sat Oct 29 15:20:30 2011 UTC (13 years, 5 months ago) by amb
File MIME type: text/x-csrc
File size: 30417 byte(s)
Rationalise and reduce the usage of LookUpNode() function.

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) =%9lu Bytes\n",(unsigned long)sizeof(Node));
210 printf("Number =%9"Pindex_t"\n",OSMNodes->file.number);
211 printf("Number(super)=%9"Pindex_t"\n",OSMNodes->file.snumber);
212 printf("\n");
213
214 printf("Lat bins= %4d\n",(int)OSMNodes->file.latbins);
215 printf("Lon bins= %4d\n",(int)OSMNodes->file.lonbins);
216 printf("\n");
217
218 printf("Lat zero=%5d (%8.4f deg)\n",(int)OSMNodes->file.latzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.latzero))));
219 printf("Lon zero=%5d (%8.4f deg)\n",(int)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)=%9lu Bytes\n",(unsigned long)sizeof(Segment));
229 printf("Number(total) =%9"Pindex_t"\n",OSMSegments->file.number);
230 printf("Number(super) =%9"Pindex_t"\n",OSMSegments->file.snumber);
231 printf("Number(normal) =%9"Pindex_t"\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) =%9lu Bytes\n",(unsigned long)sizeof(Way));
241 printf("Number(compacted)=%9"Pindex_t"\n",OSMWays->file.number);
242 printf("Number(original) =%9"Pindex_t"\n",OSMWays->file.onumber);
243 printf("\n");
244
245 stat(ways_filename,&buf);
246 printf("Total names =%9lu Bytes\n",(unsigned long)buf.st_size-(unsigned long)sizeof(Ways)-(unsigned long)OSMWays->file.number*(unsigned long)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)=%9lu Bytes\n",(unsigned long)sizeof(TurnRelation));
261 printf("Number =%9"Pindex_t"\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=%"Pindex_t".\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=%"Pindex_t".\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=%"Pindex_t".\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=%"Pindex_t".\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 ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(latmin))-OSMNodes->file.latzero;
341 ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(latmax))-OSMNodes->file.latzero;
342 ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(lonmin))-OSMNodes->file.lonzero;
343 ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(lonmax))-OSMNodes->file.lonzero;
344 ll_bin_t latb,lonb;
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 ll_bin2_t 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,node,1);
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(IsTurnRestrictedNode(node))
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 %"Pindex_t"\n",item);
441 printf(" firstseg=%"Pindex_t"\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 %"Pindex_t"\n",item);
462 printf(" node1=%"Pindex_t" node2=%"Pindex_t"\n",segment->node1,segment->node2);
463 printf(" next2=%"Pindex_t"\n",segment->next2);
464 printf(" way=%"Pindex_t"\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 char *name=WayName(ways,way);
489
490 printf("Way %"Pindex_t"\n",item);
491 if(*name)
492 printf(" name=%s\n",name);
493 printf(" type=%02x (%s%s)\n",way->type,HighwayName(HIGHWAY(way->type)),way->type&Way_OneWay?",One-Way":"");
494 printf(" allow=%02x (%s)\n",way->allow,AllowedNameList(way->allow));
495 if(way->props)
496 printf(" props=%02x (%s)\n",way->props,PropertiesNameList(way->props));
497 if(way->speed)
498 printf(" speed=%d (%d km/hr)\n",way->speed,speed_to_kph(way->speed));
499 if(way->weight)
500 printf(" weight=%d (%.1f tonnes)\n",way->weight,weight_to_tonnes(way->weight));
501 if(way->height)
502 printf(" height=%d (%.1f m)\n",way->height,height_to_metres(way->height));
503 if(way->width)
504 printf(" width=%d (%.1f m)\n",way->width,width_to_metres(way->width));
505 if(way->length)
506 printf(" length=%d (%.1f m)\n",way->length,length_to_metres(way->length));
507 }
508
509
510 /*++++++++++++++++++++++++++++++++++++++
511 Print out the contents of a turn relation from the routing database (as plain text).
512
513 Relations *relations The set of relations to use.
514
515 index_t item The turn relation index to print.
516
517 Segments *segments The set of segments to use.
518
519 Nodes *nodes The set of nodes to use.
520 ++++++++++++++++++++++++++++++++++++++*/
521
522 static void print_turnrelation(Relations *relations,index_t item,Segments *segments,Nodes *nodes)
523 {
524 Segment *segment;
525 TurnRelation *relation=LookupTurnRelation(relations,item,1);
526 Node *node=LookupNode(nodes,relation->via,1);
527 index_t from_way=NO_WAY,to_way=NO_WAY;
528 index_t from_node=NO_NODE,to_node=NO_NODE;
529
530 segment=FirstSegment(segments,node,1);
531
532 do
533 {
534 index_t seg=IndexSegment(segments,segment);
535
536 if(seg==relation->from)
537 {
538 from_node=OtherNode(segment,relation->from);
539 from_way=segment->way;
540 }
541
542 if(seg==relation->to)
543 {
544 to_node=OtherNode(segment,relation->to);
545 to_way=segment->way;
546 }
547
548 segment=NextSegment(segments,segment,relation->via);
549 }
550 while(segment);
551
552 printf("Relation %"Pindex_t"\n",item);
553 printf(" from=%"Pindex_t" (segment) = %"Pindex_t" (way) = %"Pindex_t" (node)\n",relation->from,from_way,from_node);
554 printf(" via=%"Pindex_t" (node)\n",relation->via);
555 printf(" to=%"Pindex_t" (segment) = %"Pindex_t" (way) = %"Pindex_t" (node)\n",relation->to,to_way,to_node);
556 if(relation->except)
557 printf(" except=%02x (%s)\n",relation->except,AllowedNameList(relation->except));
558 }
559
560
561 /*++++++++++++++++++++++++++++++++++++++
562 Print out a header in OSM XML format.
563 ++++++++++++++++++++++++++++++++++++++*/
564
565 static void print_head_osm(void)
566 {
567 printf("<?xml version='1.0' encoding='UTF-8'?>\n");
568 printf("<osm version='0.6' generator='Routino'>\n");
569 }
570
571
572 /*++++++++++++++++++++++++++++++++++++++
573 Print out the contents of a node from the routing database (in OSM XML format).
574
575 Nodes *nodes The set of nodes to use.
576
577 index_t item The node index to print.
578 ++++++++++++++++++++++++++++++++++++++*/
579
580 static void print_node_osm(Nodes *nodes,index_t item)
581 {
582 Node *node=LookupNode(nodes,item,1);
583 double latitude,longitude;
584 int i;
585
586 GetLatLong(nodes,item,&latitude,&longitude);
587
588 if(node->allow==Transports_ALL && node->flags==0)
589 printf(" <node id='%lu' lat='%.7f' lon='%.7f' version='1' />\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude));
590 else
591 {
592 printf(" <node id='%lu' lat='%.7f' lon='%.7f' version='1'>\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude));
593
594 if(node->flags & NODE_SUPER)
595 printf(" <tag k='routino:super' v='yes' />\n");
596
597 if(node->flags & NODE_UTURN)
598 printf(" <tag k='routino:uturn' v='yes' />\n");
599
600 if(node->flags & NODE_MINIRNDBT)
601 printf(" <tag k='highway' v='mini_roundabout' />\n");
602
603 if(node->flags & NODE_TURNRSTRCT)
604 printf(" <tag k='routino:turnrestriction' v='yes' />\n");
605
606 for(i=1;i<Transport_Count;i++)
607 if(!(node->allow & TRANSPORTS(i)))
608 printf(" <tag k='%s' v='no' />\n",TransportName(i));
609
610 printf(" </node>\n");
611 }
612 }
613
614
615 /*++++++++++++++++++++++++++++++++++++++
616 Print out the contents of a segment from the routing database (as a way in OSM XML format).
617
618 Segments *segments The set of segments to use.
619
620 index_t item The segment index to print.
621
622 Ways *ways The set of ways to use.
623 ++++++++++++++++++++++++++++++++++++++*/
624
625 static void print_segment_osm(Segments *segments,index_t item,Ways *ways)
626 {
627 Segment *segment=LookupSegment(segments,item,1);
628 Way *way=LookupWay(ways,segment->way,1);
629 char *name=WayName(ways,way);
630 int i;
631
632 printf(" <way id='%lu' version='1'>\n",(unsigned long)item+1);
633
634 if(IsOnewayTo(segment,segment->node1))
635 {
636 printf(" <nd ref='%lu' />\n",(unsigned long)segment->node2+1);
637 printf(" <nd ref='%lu' />\n",(unsigned long)segment->node1+1);
638 }
639 else
640 {
641 printf(" <nd ref='%lu' />\n",(unsigned long)segment->node1+1);
642 printf(" <nd ref='%lu' />\n",(unsigned long)segment->node2+1);
643 }
644
645 if(IsSuperSegment(segment))
646 printf(" <tag k='routino:super' v='yes' />\n");
647 if(IsNormalSegment(segment))
648 printf(" <tag k='routino:normal' v='yes' />\n");
649
650 printf(" <tag k='routino:distance' v='%.3f' />\n",distance_to_km(DISTANCE(segment->distance)));
651
652 if(way->type & Way_OneWay)
653 printf(" <tag k='oneway' v='yes' />\n");
654
655 printf(" <tag k='highway' v='%s' />\n",HighwayName(HIGHWAY(way->type)));
656
657 if(IsNormalSegment(segment) && *name)
658 printf(" <tag k='name' v='%s' />\n",ParseXML_Encode_Safe_XML(name));
659
660 for(i=1;i<Transport_Count;i++)
661 if(way->allow & TRANSPORTS(i))
662 printf(" <tag k='%s' v='yes' />\n",TransportName(i));
663
664 for(i=1;i<Property_Count;i++)
665 if(way->props & PROPERTIES(i))
666 printf(" <tag k='%s' v='yes' />\n",PropertyName(i));
667
668 if(way->speed)
669 printf(" <tag k='maxspeed' v='%d' />\n",speed_to_kph(way->speed));
670
671 if(way->weight)
672 printf(" <tag k='maxweight' v='%.1f' />\n",weight_to_tonnes(way->weight));
673 if(way->height)
674 printf(" <tag k='maxheight' v='%.1f' />\n",height_to_metres(way->height));
675 if(way->width)
676 printf(" <tag k='maxwidth' v='%.1f' />\n",width_to_metres(way->width));
677 if(way->length)
678 printf(" <tag k='maxlength' v='%.1f' />\n",length_to_metres(way->length));
679
680 printf(" </way>\n");
681 }
682
683
684 /*++++++++++++++++++++++++++++++++++++++
685 Print out the contents of a turn relation from the routing database (in OSM XML format).
686
687 Relations *relations The set of relations to use.
688
689 index_t item The relation index to print.
690
691 Segments *segments The set of segments to use.
692
693 Nodes *nodes The set of nodes to use.
694 ++++++++++++++++++++++++++++++++++++++*/
695
696 static void print_turnrelation_osm(Relations *relations,index_t item,Segments *segments,Nodes *nodes)
697 {
698 TurnRelation *relation=LookupTurnRelation(relations,item,1);
699
700 Segment *segment_from=LookupSegment(segments,relation->from,1);
701 Segment *segment_to =LookupSegment(segments,relation->to ,2);
702
703 double angle=TurnAngle(nodes,segment_from,segment_to,relation->via);
704
705 char *restriction;
706
707 if(angle>150 || angle<-150)
708 restriction="no_u_turn";
709 else if(angle>30)
710 restriction="no_right_turn";
711 else if(angle<-30)
712 restriction="no_left_turn";
713 else
714 restriction="no_straight_on";
715
716 printf(" <relation id='%lu' version='1'>\n",(unsigned long)item+1);
717 printf(" <tag k='type' v='restriction' />\n");
718 printf(" <tag k='restriction' v='%s'/>\n",restriction);
719
720 if(relation->except)
721 printf(" <tag k='except' v='%s' />\n",AllowedNameList(relation->except));
722
723 printf(" <member type='way' ref='%lu' role='from' />\n",(unsigned long)relation->from+1);
724 printf(" <member type='node' ref='%lu' role='via' />\n",(unsigned long)relation->via+1);
725 printf(" <member type='way' ref='%lu' role='to' />\n",(unsigned long)relation->to+1);
726
727 printf(" </relation>\n");
728 }
729
730
731 /*++++++++++++++++++++++++++++++++++++++
732 Print out a tail in OSM XML format.
733 ++++++++++++++++++++++++++++++++++++++*/
734
735 static void print_tail_osm(void)
736 {
737 printf("</osm>\n");
738 }
739
740
741 /*+ Conversion from time_t to date string (day of week). +*/
742 static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
743
744 /*+ Conversion from time_t to date string (month of year). +*/
745 static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
746
747
748 /*++++++++++++++++++++++++++++++++++++++
749 Convert the time into an RFC 822 compliant date.
750
751 char *RFC822Date Returns a pointer to a fixed string containing the date.
752
753 time_t t The time.
754 ++++++++++++++++++++++++++++++++++++++*/
755
756 static char *RFC822Date(time_t t)
757 {
758 static char value[32];
759 char weekday[4];
760 char month[4];
761 struct tm *tim;
762
763 tim=gmtime(&t);
764
765 strcpy(weekday,weekdays[tim->tm_wday]);
766 strcpy(month,months[tim->tm_mon]);
767
768 /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */
769
770 sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s",
771 weekday,
772 tim->tm_mday,
773 month,
774 tim->tm_year+1900,
775 tim->tm_hour,
776 tim->tm_min,
777 tim->tm_sec,
778 "GMT"
779 );
780
781 return(value);
782 }
783
784
785 /*++++++++++++++++++++++++++++++++++++++
786 Print out the usage information.
787
788 int detail The level of detail to use - 0 = low, 1 = high.
789
790 const char *argerr The argument that gave the error (if there is one).
791
792 const char *err Other error message (if there is one).
793 ++++++++++++++++++++++++++++++++++++++*/
794
795 static void print_usage(int detail,const char *argerr,const char *err)
796 {
797 fprintf(stderr,
798 "Usage: filedumper [--help]\n"
799 " [--dir=<dirname>] [--prefix=<name>]\n"
800 " [--statistics]\n"
801 " [--visualiser --latmin=<latmin> --latmax=<latmax>\n"
802 " --lonmin=<lonmin> --lonmax=<lonmax>\n"
803 " --data=<data-type>]\n"
804 " [--dump [--node=<node> ...]\n"
805 " [--segment=<segment> ...]\n"
806 " [--way=<way> ...]]\n"
807 " [--turn-relation=<rel> ...]]\n"
808 " [--dump-osm [--no-super]\n"
809 " [--latmin=<latmin> --latmax=<latmax>\n"
810 " --lonmin=<lonmin> --lonmax=<lonmax>]]\n");
811
812 if(argerr)
813 fprintf(stderr,
814 "\n"
815 "Error with command line parameter: %s\n",argerr);
816
817 if(err)
818 fprintf(stderr,
819 "\n"
820 "Error: %s\n",err);
821
822 if(detail)
823 fprintf(stderr,
824 "\n"
825 "--help Prints this information.\n"
826 "\n"
827 "--dir=<dirname> The directory containing the routing database.\n"
828 "--prefix=<name> The filename prefix for the routing database.\n"
829 "\n"
830 "--statistics Print statistics about the routing database.\n"
831 "\n"
832 "--visualiser Extract selected data from the routing database:\n"
833 " --latmin=<latmin> * the minimum latitude (degrees N).\n"
834 " --latmax=<latmax> * the maximum latitude (degrees N).\n"
835 " --lonmin=<lonmin> * the minimum longitude (degrees E).\n"
836 " --lonmax=<lonmax> * the maximum longitude (degrees E).\n"
837 " --data=<data-type> * the type of data to select.\n"
838 "\n"
839 " <data-type> can be selected from:\n"
840 " junctions = segment count at each junction.\n"
841 " super = super-node and super-segments.\n"
842 " oneway = oneway segments.\n"
843 " turns = turn restrictions.\n"
844 " speed = speed limits.\n"
845 " weight = weight limits.\n"
846 " height = height limits.\n"
847 " width = width limits.\n"
848 " length = length limits.\n"
849 "\n"
850 "--dump Dump selected contents of the database.\n"
851 " --node=<node> * the node with the selected index.\n"
852 " --segment=<segment> * the segment with the selected index.\n"
853 " --way=<way> * the way with the selected index.\n"
854 " --turn-relation=<rel> * the turn relation with the selected index.\n"
855 " Use 'all' instead of a number to get all of them.\n"
856 "\n"
857 "--dump-osm Dump all or part of the database as an XML file.\n"
858 " --no-super * exclude the super-segments.\n"
859 " --latmin=<latmin> * the minimum latitude (degrees N).\n"
860 " --latmax=<latmax> * the maximum latitude (degrees N).\n"
861 " --lonmin=<lonmin> * the minimum longitude (degrees E).\n"
862 " --lonmax=<lonmax> * the maximum longitude (degrees E).\n");
863
864 exit(!detail);
865 }

Properties

Name Value
cvs:description Test program for mmap files.