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 1263 - (show annotations) (download) (as text)
Sat Mar 2 14:13:14 2013 UTC (12 years ago) by amb
File MIME type: text/x-csrc
File size: 33522 byte(s)
Recognise mini-roundabouts tagged as junction=roundabout (as well as
highway=mini_roundabout).  Pass them through the parser as roundabout=yes.
Output them from the filedumper as junction=roundabout.  Update the
documentation for mini-roundabouts.

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

Properties

Name Value
cvs:description Test program for mmap files.