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 1077 - (hide annotations) (download) (as text)
Wed Sep 26 09:42:00 2012 UTC (12 years, 6 months ago) by amb
File MIME type: text/x-csrc
File size: 33033 byte(s)
Add an option to the visualiser to display nodes that disallow selected
transport type.

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

Properties

Name Value
cvs:description Test program for mmap files.