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 565 - (hide annotations) (download) (as text)
Tue Dec 21 18:26:28 2010 UTC (14 years, 2 months ago) by amb
File MIME type: text/x-csrc
File size: 28687 byte(s)
Add turn relations to the statistics and dump outputs.

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

Properties

Name Value
cvs:description Test program for mmap files.