Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/filedumper.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 923 - (hide annotations) (download) (as text)
Sat Nov 26 15:52:57 2011 UTC (13 years, 4 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 amb 2 /***************************************
2     Memory file dumper.
3 amb 151
4     Part of the Routino routing software.
5 amb 2 ******************/ /******************
6 amb 595 This file Copyright 2008-2011 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 449
37     #include "files.h"
38     #include "visualiser.h"
39 amb 405 #include "xmlparse.h"
40 amb 2
41 amb 405
42 amb 185 /* Local functions */
43 amb 2
44 amb 681 static void print_node(Nodes *nodes,index_t item);
45 amb 202 static void print_segment(Segments *segments,index_t item);
46     static void print_way(Ways *ways,index_t item);
47 amb 681 static void print_turnrelation(Relations *relations,index_t item,Segments *segments,Nodes *nodes);
48 amb 185
49 amb 917 static void print_head_osm(int coordcount,double latmin,double latmax,double lonmin,double lonmax);
50 amb 918 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 amb 681 static void print_node_osm(Nodes *nodes,index_t item);
53 amb 405 static void print_segment_osm(Segments *segments,index_t item,Ways *ways);
54 amb 681 static void print_turnrelation_osm(Relations *relations,index_t item,Segments *segments,Nodes *nodes);
55 amb 405 static void print_tail_osm(void);
56    
57     static char *RFC822Date(time_t t);
58    
59 amb 490 static void print_usage(int detail,const char *argerr,const char *err);
60 amb 342
61    
62     /*++++++++++++++++++++++++++++++++++++++
63 amb 405 The main program for the file dumper.
64 amb 342 ++++++++++++++++++++++++++++++++++++++*/
65    
66 amb 2 int main(int argc,char** argv)
67     {
68 amb 26 Nodes *OSMNodes;
69 amb 66 Segments *OSMSegments;
70 amb 26 Ways *OSMWays;
71 amb 542 Relations*OSMRelations;
72 amb 405 int arg;
73     char *dirname=NULL,*prefix=NULL;
74 amb 542 char *nodes_filename,*segments_filename,*ways_filename,*relations_filename;
75 amb 405 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 amb 413 int option_dump_osm=0,option_no_super=0;
81 amb 13
82 amb 107 /* Parse the command line arguments */
83    
84 amb 202 for(arg=1;arg<argc;arg++)
85 amb 107 {
86 amb 202 if(!strcmp(argv[arg],"--help"))
87 amb 490 print_usage(1,NULL,NULL);
88 amb 202 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 amb 405 else if(!strcmp(argv[arg],"--statistics"))
93 amb 185 option_statistics=1;
94 amb 405 else if(!strcmp(argv[arg],"--visualiser"))
95 amb 185 option_visualiser=1;
96 amb 405 else if(!strcmp(argv[arg],"--dump"))
97 amb 202 option_dump=1;
98 amb 405 else if(!strcmp(argv[arg],"--dump-osm"))
99     option_dump_osm=1;
100 amb 202 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 amb 413 else if(!strcmp(argv[arg],"--no-super"))
111     option_no_super=1;
112 amb 202 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 amb 565 else if(!strncmp(argv[arg],"--turn-relation=",16))
119     ;
120 amb 107 else
121 amb 490 print_usage(0,argv[arg],NULL);
122 amb 107 }
123    
124 amb 490 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 amb 2
127 amb 329 /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */
128 amb 2
129 amb 185 OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem"));
130 amb 6
131 amb 185 OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem"));
132 amb 99
133 amb 185 OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem"));
134 amb 66
135 amb 542 OSMRelations=LoadRelationList(relations_filename=FileName(dirname,prefix,"relations.mem"));
136    
137 amb 185 /* Write out the visualiser data */
138 amb 66
139 amb 185 if(option_visualiser)
140     {
141     if(coordcount!=4)
142 amb 490 print_usage(0,NULL,"The --visualiser option must have --latmin, --latmax, --lonmin, --lonmax.\n");
143 amb 66
144 amb 185 if(!option_data)
145 amb 490 print_usage(0,NULL,"The --visualiser option must have --data.\n");
146 amb 2
147 amb 185 if(!strcmp(option_data,"junctions"))
148 amb 623 OutputJunctions(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
149 amb 185 else if(!strcmp(option_data,"super"))
150 amb 623 OutputSuper(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
151 amb 185 else if(!strcmp(option_data,"oneway"))
152 amb 623 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 amb 185 else if(!strcmp(option_data,"speed"))
156 amb 623 OutputSpeedLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
157 amb 185 else if(!strcmp(option_data,"weight"))
158 amb 623 OutputWeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
159 amb 185 else if(!strcmp(option_data,"height"))
160 amb 623 OutputHeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
161 amb 185 else if(!strcmp(option_data,"width"))
162 amb 623 OutputWidthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
163 amb 185 else if(!strcmp(option_data,"length"))
164 amb 623 OutputLengthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax);
165 amb 185 else
166 amb 490 print_usage(0,option_data,NULL);
167 amb 185 }
168 amb 6
169 amb 185 /* Print out statistics */
170 amb 6
171 amb 185 if(option_statistics)
172     {
173     struct stat buf;
174 amb 6
175 amb 185 /* Examine the files */
176    
177     printf("Files\n");
178     printf("-----\n");
179     printf("\n");
180    
181     stat(nodes_filename,&buf);
182    
183 amb 625 printf("'%s%snodes.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size);
184 amb 185 printf("%s\n",RFC822Date(buf.st_mtime));
185     printf("\n");
186    
187     stat(segments_filename,&buf);
188    
189 amb 625 printf("'%s%ssegments.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size);
190 amb 185 printf("%s\n",RFC822Date(buf.st_mtime));
191     printf("\n");
192    
193     stat(ways_filename,&buf);
194    
195 amb 625 printf("'%s%sways.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size);
196 amb 185 printf("%s\n",RFC822Date(buf.st_mtime));
197     printf("\n");
198    
199 amb 625 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 amb 185 /* Examine the nodes */
206    
207     printf("Nodes\n");
208     printf("-----\n");
209     printf("\n");
210    
211 amb 879 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 amb 185 printf("\n");
215    
216 amb 879 printf("Lat bins= %4d\n",(int)OSMNodes->file.latbins);
217     printf("Lon bins= %4d\n",(int)OSMNodes->file.lonbins);
218 amb 185 printf("\n");
219    
220 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))));
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 amb 185
223     /* Examine the segments */
224    
225     printf("\n");
226     printf("Segments\n");
227     printf("--------\n");
228     printf("\n");
229    
230 amb 879 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 amb 185
235     /* Examine the ways */
236    
237     printf("\n");
238     printf("Ways\n");
239     printf("----\n");
240     printf("\n");
241    
242 amb 879 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 amb 202 printf("\n");
246    
247 amb 628 stat(ways_filename,&buf);
248 amb 879 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 amb 307 printf("\n");
250    
251 amb 526 printf("Included highways : %s\n",HighwaysNameList(OSMWays->file.highways));
252 amb 460 printf("Included transports: %s\n",AllowedNameList(OSMWays->file.allow));
253     printf("Included properties: %s\n",PropertiesNameList(OSMWays->file.props));
254 amb 565
255     /* Examine the relations */
256    
257     printf("\n");
258     printf("Relations\n");
259     printf("---------\n");
260     printf("\n");
261    
262 amb 879 printf("sizeof(TurnRelation)=%9lu Bytes\n",(unsigned long)sizeof(TurnRelation));
263     printf("Number =%9"Pindex_t"\n",OSMRelations->file.trnumber);
264 amb 185 }
265    
266 amb 680 /* Print out internal data (in plain text format) */
267 amb 202
268     if(option_dump)
269     {
270     index_t item;
271    
272     for(arg=1;arg<argc;arg++)
273 amb 254 if(!strcmp(argv[arg],"--node=all"))
274 amb 202 {
275 amb 453 for(item=0;item<OSMNodes->file.number;item++)
276 amb 254 print_node(OSMNodes,item);
277     }
278     else if(!strncmp(argv[arg],"--node=",7))
279     {
280 amb 202 item=atoi(&argv[arg][7]);
281    
282 amb 453 if(item>=0 && item<OSMNodes->file.number)
283 amb 301 print_node(OSMNodes,item);
284     else
285 amb 790 printf("Invalid node number; minimum=0, maximum=%"Pindex_t".\n",OSMNodes->file.number-1);
286 amb 202 }
287 amb 254 else if(!strcmp(argv[arg],"--segment=all"))
288     {
289 amb 459 for(item=0;item<OSMSegments->file.number;item++)
290 amb 254 print_segment(OSMSegments,item);
291     }
292 amb 202 else if(!strncmp(argv[arg],"--segment=",10))
293     {
294     item=atoi(&argv[arg][10]);
295    
296 amb 459 if(item>=0 && item<OSMSegments->file.number)
297 amb 301 print_segment(OSMSegments,item);
298     else
299 amb 790 printf("Invalid segment number; minimum=0, maximum=%"Pindex_t".\n",OSMSegments->file.number-1);
300 amb 202 }
301 amb 254 else if(!strcmp(argv[arg],"--way=all"))
302     {
303 amb 460 for(item=0;item<OSMWays->file.number;item++)
304 amb 254 print_way(OSMWays,item);
305     }
306 amb 202 else if(!strncmp(argv[arg],"--way=",6))
307     {
308     item=atoi(&argv[arg][6]);
309    
310 amb 460 if(item>=0 && item<OSMWays->file.number)
311 amb 301 print_way(OSMWays,item);
312     else
313 amb 790 printf("Invalid way number; minimum=0, maximum=%"Pindex_t".\n",OSMWays->file.number-1);
314 amb 202 }
315 amb 565 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 amb 626 item=atoi(&argv[arg][16]);
323 amb 565
324     if(item>=0 && item<OSMRelations->file.trnumber)
325     print_turnrelation(OSMRelations,item,OSMSegments,OSMNodes);
326     else
327 amb 790 printf("Invalid turn relation number; minimum=0, maximum=%"Pindex_t".\n",OSMRelations->file.trnumber-1);
328 amb 565 }
329 amb 202 }
330    
331 amb 680 /* Print out internal data (in OSM XML format) */
332 amb 405
333     if(option_dump_osm)
334     {
335 amb 413 if(coordcount>0 && coordcount!=4)
336 amb 490 print_usage(0,NULL,"The --dump-osm option must have all of --latmin, --latmax, --lonmin, --lonmax or none.\n");
337 amb 405
338 amb 917 print_head_osm(coordcount,latmin,latmax,lonmin,lonmax);
339 amb 405
340 amb 413 if(coordcount)
341 amb 918 print_region_osm(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,option_no_super);
342 amb 413 else
343     {
344     index_t item;
345    
346 amb 453 for(item=0;item<OSMNodes->file.number;item++)
347 amb 413 print_node_osm(OSMNodes,item);
348    
349 amb 459 for(item=0;item<OSMSegments->file.number;item++)
350     if(!option_no_super || IsNormalSegment(LookupSegment(OSMSegments,item,1)))
351 amb 413 print_segment_osm(OSMSegments,item,OSMWays);
352 amb 565
353     for(item=0;item<OSMRelations->file.trnumber;item++)
354     print_turnrelation_osm(OSMRelations,item,OSMSegments,OSMNodes);
355 amb 413 }
356    
357 amb 405 print_tail_osm();
358     }
359    
360 amb 2 return(0);
361     }
362 amb 185
363    
364 amb 202 /*++++++++++++++++++++++++++++++++++++++
365 amb 680 Print out the contents of a node from the routing database (as plain text).
366 amb 202
367     Nodes *nodes The set of nodes to use.
368    
369     index_t item The node index to print.
370     ++++++++++++++++++++++++++++++++++++++*/
371    
372 amb 681 static void print_node(Nodes *nodes,index_t item)
373 amb 202 {
374 amb 453 Node *node=LookupNode(nodes,item,1);
375 amb 219 double latitude,longitude;
376 amb 202
377     GetLatLong(nodes,item,&latitude,&longitude);
378    
379 amb 790 printf("Node %"Pindex_t"\n",item);
380     printf(" firstseg=%"Pindex_t"\n",node->firstseg);
381 amb 227 printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",node->latoffset,node->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude));
382 amb 470 printf(" allow=%02x (%s)\n",node->allow,AllowedNameList(node->allow));
383 amb 595 if(IsSuperNode(node))
384 amb 202 printf(" Super-Node\n");
385     }
386    
387    
388     /*++++++++++++++++++++++++++++++++++++++
389 amb 680 Print out the contents of a segment from the routing database (as plain text).
390 amb 202
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 amb 459 Segment *segment=LookupSegment(segments,item,1);
399 amb 202
400 amb 790 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 amb 202 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 amb 680 Print out the contents of a way from the routing database (as plain text).
418 amb 202
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 amb 460 Way *way=LookupWay(ways,item,1);
427 amb 705 char *name=WayName(ways,way);
428 amb 202
429 amb 790 printf("Way %"Pindex_t"\n",item);
430 amb 705 if(*name)
431     printf(" name=%s\n",name);
432 amb 923 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 amb 298 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 amb 202 if(way->speed)
437     printf(" speed=%d (%d km/hr)\n",way->speed,speed_to_kph(way->speed));
438     if(way->weight)
439 amb 227 printf(" weight=%d (%.1f tonnes)\n",way->weight,weight_to_tonnes(way->weight));
440 amb 202 if(way->height)
441 amb 227 printf(" height=%d (%.1f m)\n",way->height,height_to_metres(way->height));
442 amb 202 if(way->width)
443 amb 227 printf(" width=%d (%.1f m)\n",way->width,width_to_metres(way->width));
444 amb 202 if(way->length)
445 amb 227 printf(" length=%d (%.1f m)\n",way->length,length_to_metres(way->length));
446 amb 202 }
447    
448    
449 amb 405 /*++++++++++++++++++++++++++++++++++++++
450 amb 680 Print out the contents of a turn relation from the routing database (as plain text).
451 amb 565
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 amb 681 static void print_turnrelation(Relations *relations,index_t item,Segments *segments,Nodes *nodes)
462 amb 565 {
463 amb 885 Segment *segment;
464 amb 626 TurnRelation *relation=LookupTurnRelation(relations,item,1);
465 amb 885 Node *node=LookupNode(nodes,relation->via,1);
466 amb 565 index_t from_way=NO_WAY,to_way=NO_WAY;
467 amb 599 index_t from_node=NO_NODE,to_node=NO_NODE;
468 amb 565
469 amb 885 segment=FirstSegment(segments,node,1);
470 amb 565
471     do
472     {
473 amb 599 index_t seg=IndexSegment(segments,segment);
474 amb 565
475 amb 599 if(seg==relation->from)
476     {
477     from_node=OtherNode(segment,relation->from);
478     from_way=segment->way;
479     }
480 amb 565
481 amb 599 if(seg==relation->to)
482     {
483     to_node=OtherNode(segment,relation->to);
484     to_way=segment->way;
485     }
486    
487 amb 565 segment=NextSegment(segments,segment,relation->via);
488     }
489     while(segment);
490    
491 amb 790 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 amb 565 if(relation->except)
496     printf(" except=%02x (%s)\n",relation->except,AllowedNameList(relation->except));
497     }
498    
499    
500     /*++++++++++++++++++++++++++++++++++++++
501 amb 405 Print out a header in OSM XML format.
502 amb 918
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 amb 405 ++++++++++++++++++++++++++++++++++++++*/
513    
514 amb 917 static void print_head_osm(int coordcount,double latmin,double latmax,double lonmin,double lonmax)
515 amb 405 {
516     printf("<?xml version='1.0' encoding='UTF-8'?>\n");
517 amb 847 printf("<osm version='0.6' generator='Routino'>\n");
518 amb 917
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 amb 405 }
523    
524    
525     /*++++++++++++++++++++++++++++++++++++++
526 amb 918 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 amb 680 Print out the contents of a node from the routing database (in OSM XML format).
623 amb 405
624     Nodes *nodes The set of nodes to use.
625    
626     index_t item The node index to print.
627     ++++++++++++++++++++++++++++++++++++++*/
628    
629 amb 681 static void print_node_osm(Nodes *nodes,index_t item)
630 amb 405 {
631 amb 469 Node *node=LookupNode(nodes,item,1);
632 amb 405 double latitude,longitude;
633 amb 537 int i;
634 amb 405
635     GetLatLong(nodes,item,&latitude,&longitude);
636    
637 amb 537 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 amb 405 {
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 amb 469
643 amb 537 if(node->flags & NODE_SUPER)
644     printf(" <tag k='routino:super' v='yes' />\n");
645    
646 amb 667 if(node->flags & NODE_UTURN)
647     printf(" <tag k='routino:uturn' v='yes' />\n");
648    
649 amb 538 if(node->flags & NODE_MINIRNDBT)
650 amb 537 printf(" <tag k='highway' v='mini_roundabout' />\n");
651    
652 amb 667 if(node->flags & NODE_TURNRSTRCT)
653     printf(" <tag k='routino:turnrestriction' v='yes' />\n");
654    
655 amb 469 for(i=1;i<Transport_Count;i++)
656 amb 529 if(!(node->allow & TRANSPORTS(i)))
657 amb 470 printf(" <tag k='%s' v='no' />\n",TransportName(i));
658 amb 469
659 amb 405 printf(" </node>\n");
660     }
661     }
662    
663    
664     /*++++++++++++++++++++++++++++++++++++++
665 amb 680 Print out the contents of a segment from the routing database (as a way in OSM XML format).
666 amb 405
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 amb 459 Segment *segment=LookupSegment(segments,item,1);
677 amb 460 Way *way=LookupWay(ways,segment->way,1);
678 amb 705 char *name=WayName(ways,way);
679 amb 405 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 amb 844 printf(" <tag k='routino:distance' v='%.3f' />\n",distance_to_km(DISTANCE(segment->distance)));
700 amb 667
701 amb 405 if(way->type & Way_OneWay)
702     printf(" <tag k='oneway' v='yes' />\n");
703    
704 amb 923 if(way->type & Way_Roundabout)
705     printf(" <tag k='roundabout' v='yes' />\n");
706    
707 amb 405 printf(" <tag k='highway' v='%s' />\n",HighwayName(HIGHWAY(way->type)));
708    
709 amb 705 if(IsNormalSegment(segment) && *name)
710     printf(" <tag k='name' v='%s' />\n",ParseXML_Encode_Safe_XML(name));
711 amb 405
712     for(i=1;i<Transport_Count;i++)
713 amb 529 if(way->allow & TRANSPORTS(i))
714 amb 405 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 amb 680 Print out the contents of a turn relation from the routing database (in OSM XML format).
738 amb 565
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 amb 681 static void print_turnrelation_osm(Relations *relations,index_t item,Segments *segments,Nodes *nodes)
749 amb 565 {
750 amb 626 TurnRelation *relation=LookupTurnRelation(relations,item,1);
751 amb 565
752 amb 673 Segment *segment_from=LookupSegment(segments,relation->from,1);
753 amb 707 Segment *segment_to =LookupSegment(segments,relation->to ,2);
754 amb 618
755 amb 673 double angle=TurnAngle(nodes,segment_from,segment_to,relation->via);
756 amb 618
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 amb 565 printf(" <relation id='%lu' version='1'>\n",(unsigned long)item+1);
769     printf(" <tag k='type' v='restriction' />\n");
770 amb 618 printf(" <tag k='restriction' v='%s'/>\n",restriction);
771 amb 565
772     if(relation->except)
773     printf(" <tag k='except' v='%s' />\n",AllowedNameList(relation->except));
774    
775 amb 599 printf(" <member type='way' ref='%lu' role='from' />\n",(unsigned long)relation->from+1);
776 amb 565 printf(" <member type='node' ref='%lu' role='via' />\n",(unsigned long)relation->via+1);
777 amb 599 printf(" <member type='way' ref='%lu' role='to' />\n",(unsigned long)relation->to+1);
778 amb 565
779     printf(" </relation>\n");
780     }
781    
782    
783     /*++++++++++++++++++++++++++++++++++++++
784 amb 405 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 amb 185 static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
795    
796 amb 405 /*+ Conversion from time_t to date string (month of year). +*/
797 amb 185 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 amb 342
836    
837     /*++++++++++++++++++++++++++++++++++++++
838     Print out the usage information.
839    
840     int detail The level of detail to use - 0 = low, 1 = high.
841 amb 490
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 amb 342 ++++++++++++++++++++++++++++++++++++++*/
846    
847 amb 490 static void print_usage(int detail,const char *argerr,const char *err)
848 amb 342 {
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 amb 405 " [--way=<way> ...]]\n"
859 amb 599 " [--turn-relation=<rel> ...]]\n"
860 amb 413 " [--dump-osm [--no-super]\n"
861     " [--latmin=<latmin> --latmax=<latmax>\n"
862     " --lonmin=<lonmin> --lonmax=<lonmax>]]\n");
863 amb 342
864 amb 490 if(argerr)
865     fprintf(stderr,
866     "\n"
867     "Error with command line parameter: %s\n",argerr);
868    
869 amb 491 if(err)
870 amb 490 fprintf(stderr,
871     "\n"
872     "Error: %s\n",err);
873    
874 amb 342 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 amb 623 " turns = turn restrictions.\n"
896 amb 342 " 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 amb 599 " --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 amb 405 " Use 'all' instead of a number to get all of them.\n"
908     "\n"
909 amb 413 "--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 amb 342
916     exit(!detail);
917     }

Properties

Name Value
cvs:description Test program for mmap files.