Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /branches/destination-access/src/filedumper.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1150 - (hide annotations) (download) (as text)
Sat Nov 17 18:55:38 2012 UTC (12 years, 4 months ago) by amb
Original Path: trunk/src/filedumper.c
File MIME type: text/x-csrc
File size: 33093 byte(s)
Some small changes to match the new filedumperx program.

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

Properties

Name Value
cvs:description Test program for mmap files.