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 923 - (show annotations) (download) (as text)
Sat Nov 26 15:52:57 2011 UTC (13 years, 3 months ago) by amb
File MIME type: text/x-csrc
File size: 32031 byte(s)
Parse and store information about roundabouts (to improve routing instructions).

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

Properties

Name Value
cvs:description Test program for mmap files.