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 667 - (hide annotations) (download) (as text)
Mon Mar 21 19:12:36 2011 UTC (14 years ago) by amb
File MIME type: text/x-csrc
File size: 30417 byte(s)
Include some of the Routino internal information when dumping an OSM format
output.

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

Properties

Name Value
cvs:description Test program for mmap files.