Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/filedumper.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1003 - (show annotations) (download) (as text)
Tue Jun 5 14:14:45 2012 UTC (12 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 32716 byte(s)
Add an option to the visualiser to display segments of each of the highway
types.

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

Properties

Name Value
cvs:description Test program for mmap files.