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 599 - (hide annotations) (download) (as text)
Sat Jan 15 19:28:56 2011 UTC (14 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 28527 byte(s)
Store the 'from' and 'to' segments and not nodes (to handle fake nodes inserted
in segments).

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

Properties

Name Value
cvs:description Test program for mmap files.