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 780 - (hide annotations) (download) (as text)
Sun Jun 5 18:19:50 2011 UTC (13 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 30003 byte(s)
Replace int with appropriate defined types (mostly index_t, ll_bin_t and
ll_bin2_t).

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

Properties

Name Value
cvs:description Test program for mmap files.