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 1002 - (hide annotations) (download) (as text)
Tue Jun 5 13:17:42 2012 UTC (12 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 32397 byte(s)
Add an option to the visualiser to display segments accessible to each of the
transport types.

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

Properties

Name Value
cvs:description Test program for mmap files.