Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/filedumper.c
Parent Directory
|
Revision Log
Revision 459 -
(show annotations)
(download)
(as text)
Fri Jul 23 14:35:27 2010 UTC (14 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 23013 byte(s)
Fri Jul 23 14:35:27 2010 UTC (14 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 23013 byte(s)
Added slim mode to the router for segments.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/filedumper.c,v 1.46 2010-07-23 14:35:27 amb Exp $ |
3 | |
4 | Memory file dumper. |
5 | |
6 | Part of the Routino routing software. |
7 | ******************/ /****************** |
8 | This file Copyright 2008-2010 Andrew M. Bishop |
9 | |
10 | This program is free software: you can redistribute it and/or modify |
11 | it under the terms of the GNU Affero General Public License as published by |
12 | the Free Software Foundation, either version 3 of the License, or |
13 | (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public License |
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | ***************************************/ |
23 | |
24 | |
25 | #include <stdio.h> |
26 | #include <stdlib.h> |
27 | #include <string.h> |
28 | #include <sys/stat.h> |
29 | #include <sys/time.h> |
30 | #include <time.h> |
31 | |
32 | #include "types.h" |
33 | #include "nodes.h" |
34 | #include "segments.h" |
35 | #include "ways.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 | |
48 | static void print_head_osm(void); |
49 | static void print_node_osm(Nodes* nodes,index_t item); |
50 | static void print_segment_osm(Segments *segments,index_t item,Ways *ways); |
51 | static void print_tail_osm(void); |
52 | |
53 | static char *RFC822Date(time_t t); |
54 | |
55 | static void print_usage(int detail); |
56 | |
57 | |
58 | /*++++++++++++++++++++++++++++++++++++++ |
59 | The main program for the file dumper. |
60 | ++++++++++++++++++++++++++++++++++++++*/ |
61 | |
62 | int main(int argc,char** argv) |
63 | { |
64 | Nodes *OSMNodes; |
65 | Segments *OSMSegments; |
66 | Ways *OSMWays; |
67 | int arg; |
68 | char *dirname=NULL,*prefix=NULL; |
69 | char *nodes_filename,*segments_filename,*ways_filename; |
70 | int option_statistics=0; |
71 | int option_visualiser=0,coordcount=0; |
72 | double latmin=0,latmax=0,lonmin=0,lonmax=0; |
73 | char *option_data=NULL; |
74 | int option_dump=0; |
75 | int option_dump_osm=0,option_no_super=0; |
76 | |
77 | /* Parse the command line arguments */ |
78 | |
79 | for(arg=1;arg<argc;arg++) |
80 | { |
81 | if(!strcmp(argv[arg],"--help")) |
82 | print_usage(1); |
83 | else if(!strncmp(argv[arg],"--dir=",6)) |
84 | dirname=&argv[arg][6]; |
85 | else if(!strncmp(argv[arg],"--prefix=",9)) |
86 | prefix=&argv[arg][9]; |
87 | else if(!strcmp(argv[arg],"--statistics")) |
88 | option_statistics=1; |
89 | else if(!strcmp(argv[arg],"--visualiser")) |
90 | option_visualiser=1; |
91 | else if(!strcmp(argv[arg],"--dump")) |
92 | option_dump=1; |
93 | else if(!strcmp(argv[arg],"--dump-osm")) |
94 | option_dump_osm=1; |
95 | else if(!strncmp(argv[arg],"--latmin",8) && argv[arg][8]=='=') |
96 | {latmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;} |
97 | else if(!strncmp(argv[arg],"--latmax",8) && argv[arg][8]=='=') |
98 | {latmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;} |
99 | else if(!strncmp(argv[arg],"--lonmin",8) && argv[arg][8]=='=') |
100 | {lonmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;} |
101 | else if(!strncmp(argv[arg],"--lonmax",8) && argv[arg][8]=='=') |
102 | {lonmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;} |
103 | else if(!strncmp(argv[arg],"--data",6) && argv[arg][6]=='=') |
104 | option_data=&argv[arg][7]; |
105 | else if(!strcmp(argv[arg],"--no-super")) |
106 | option_no_super=1; |
107 | else if(!strncmp(argv[arg],"--node=",7)) |
108 | ; |
109 | else if(!strncmp(argv[arg],"--segment=",10)) |
110 | ; |
111 | else if(!strncmp(argv[arg],"--way=",6)) |
112 | ; |
113 | else |
114 | print_usage(0); |
115 | } |
116 | |
117 | if(!option_statistics && !option_visualiser && !option_dump && !option_dump_osm) |
118 | print_usage(0); |
119 | |
120 | /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */ |
121 | |
122 | OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem")); |
123 | |
124 | OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem")); |
125 | |
126 | OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem")); |
127 | |
128 | /* Write out the visualiser data */ |
129 | |
130 | if(option_visualiser) |
131 | { |
132 | if(coordcount!=4) |
133 | { |
134 | fprintf(stderr,"The --visualiser option must have --latmin, --latmax, --lonmin, --lonmax.\n"); |
135 | exit(1); |
136 | } |
137 | |
138 | if(!option_data) |
139 | { |
140 | fprintf(stderr,"The --visualiser option must have --data.\n"); |
141 | exit(1); |
142 | } |
143 | |
144 | if(!strcmp(option_data,"junctions")) |
145 | OutputJunctions(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax); |
146 | else if(!strcmp(option_data,"super")) |
147 | OutputSuper(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax); |
148 | else if(!strcmp(option_data,"oneway")) |
149 | OutputOneway(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax); |
150 | else if(!strcmp(option_data,"speed")) |
151 | OutputSpeedLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax); |
152 | else if(!strcmp(option_data,"weight")) |
153 | OutputWeightLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax); |
154 | else if(!strcmp(option_data,"height")) |
155 | OutputHeightLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax); |
156 | else if(!strcmp(option_data,"width")) |
157 | OutputWidthLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax); |
158 | else if(!strcmp(option_data,"length")) |
159 | OutputLengthLimits(OSMNodes,OSMSegments,OSMWays,latmin,latmax,lonmin,lonmax); |
160 | else |
161 | { |
162 | fprintf(stderr,"Unrecognised data option '%s' with --visualiser.\n",option_data); |
163 | exit(1); |
164 | } |
165 | } |
166 | |
167 | /* Print out statistics */ |
168 | |
169 | if(option_statistics) |
170 | { |
171 | struct stat buf; |
172 | |
173 | /* Examine the files */ |
174 | |
175 | printf("Files\n"); |
176 | printf("-----\n"); |
177 | printf("\n"); |
178 | |
179 | stat(nodes_filename,&buf); |
180 | |
181 | printf("'%s%snodes.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size); |
182 | printf("%s\n",RFC822Date(buf.st_mtime)); |
183 | printf("\n"); |
184 | |
185 | stat(segments_filename,&buf); |
186 | |
187 | printf("'%s%ssegments.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size); |
188 | printf("%s\n",RFC822Date(buf.st_mtime)); |
189 | printf("\n"); |
190 | |
191 | stat(ways_filename,&buf); |
192 | |
193 | printf("'%s%sways.mem' - %9lld Bytes\n",prefix?prefix:"",prefix?"-":"",(long long)buf.st_size); |
194 | printf("%s\n",RFC822Date(buf.st_mtime)); |
195 | printf("\n"); |
196 | |
197 | /* Examine the nodes */ |
198 | |
199 | printf("Nodes\n"); |
200 | printf("-----\n"); |
201 | printf("\n"); |
202 | |
203 | printf("sizeof(Node) =%9d Bytes\n",sizeof(Node)); |
204 | printf("Number =%9d\n",OSMNodes->file.number); |
205 | printf("Number(super)=%9d\n",OSMNodes->file.snumber); |
206 | printf("\n"); |
207 | |
208 | printf("Lat bins= %4d\n",OSMNodes->file.latbins); |
209 | printf("Lon bins= %4d\n",OSMNodes->file.lonbins); |
210 | printf("\n"); |
211 | |
212 | printf("Lat zero=%5d (%8.4f deg)\n",OSMNodes->file.latzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.latzero)))); |
213 | printf("Lon zero=%5d (%8.4f deg)\n",OSMNodes->file.lonzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.lonzero)))); |
214 | |
215 | /* Examine the segments */ |
216 | |
217 | printf("\n"); |
218 | printf("Segments\n"); |
219 | printf("--------\n"); |
220 | printf("\n"); |
221 | |
222 | printf("sizeof(Segment)=%9d Bytes\n",sizeof(Segment)); |
223 | printf("Number(total) =%9d\n",OSMSegments->file.number); |
224 | printf("Number(super) =%9d\n",OSMSegments->file.snumber); |
225 | printf("Number(normal) =%9d\n",OSMSegments->file.nnumber); |
226 | |
227 | /* Examine the ways */ |
228 | |
229 | printf("\n"); |
230 | printf("Ways\n"); |
231 | printf("----\n"); |
232 | printf("\n"); |
233 | |
234 | printf("sizeof(Way) =%9d Bytes\n",sizeof(Way)); |
235 | printf("Number(compacted)=%9d\n",OSMWays->number); |
236 | printf("Number(original) =%9d\n",OSMWays->onumber); |
237 | printf("\n"); |
238 | |
239 | printf("Total names =%9ld Bytes\n",(long)buf.st_size-sizeof(Ways)-OSMWays->number*sizeof(Way)); |
240 | printf("\n"); |
241 | |
242 | printf("Included transports: %s\n",AllowedNameList(OSMWays->allow)); |
243 | printf("Included properties: %s\n",PropertiesNameList(OSMWays->props)); |
244 | } |
245 | |
246 | /* Print out internal data */ |
247 | |
248 | if(option_dump) |
249 | { |
250 | index_t item; |
251 | |
252 | for(arg=1;arg<argc;arg++) |
253 | if(!strcmp(argv[arg],"--node=all")) |
254 | { |
255 | for(item=0;item<OSMNodes->file.number;item++) |
256 | print_node(OSMNodes,item); |
257 | } |
258 | else if(!strncmp(argv[arg],"--node=",7)) |
259 | { |
260 | item=atoi(&argv[arg][7]); |
261 | |
262 | if(item>=0 && item<OSMNodes->file.number) |
263 | print_node(OSMNodes,item); |
264 | else |
265 | printf("Invalid node number; minimum=0, maximum=%d.\n",OSMNodes->file.number-1); |
266 | } |
267 | else if(!strcmp(argv[arg],"--segment=all")) |
268 | { |
269 | for(item=0;item<OSMSegments->file.number;item++) |
270 | print_segment(OSMSegments,item); |
271 | } |
272 | else if(!strncmp(argv[arg],"--segment=",10)) |
273 | { |
274 | item=atoi(&argv[arg][10]); |
275 | |
276 | if(item>=0 && item<OSMSegments->file.number) |
277 | print_segment(OSMSegments,item); |
278 | else |
279 | printf("Invalid segment number; minimum=0, maximum=%d.\n",OSMSegments->file.number-1); |
280 | } |
281 | else if(!strcmp(argv[arg],"--way=all")) |
282 | { |
283 | for(item=0;item<OSMWays->number;item++) |
284 | print_way(OSMWays,item); |
285 | } |
286 | else if(!strncmp(argv[arg],"--way=",6)) |
287 | { |
288 | item=atoi(&argv[arg][6]); |
289 | |
290 | if(item>=0 && item<OSMWays->number) |
291 | print_way(OSMWays,item); |
292 | else |
293 | printf("Invalid way number; minimum=0, maximum=%d.\n",OSMWays->number-1); |
294 | } |
295 | } |
296 | |
297 | /* Print out internal data in XML format */ |
298 | |
299 | if(option_dump_osm) |
300 | { |
301 | if(coordcount>0 && coordcount!=4) |
302 | { |
303 | fprintf(stderr,"The --dump-osm option must have all of --latmin, --latmax, --lonmin, --lonmax or none.\n"); |
304 | exit(1); |
305 | } |
306 | |
307 | print_head_osm(); |
308 | |
309 | if(coordcount) |
310 | { |
311 | int32_t latminbin=latlong_to_bin(radians_to_latlong(latmin))-OSMNodes->file.latzero; |
312 | int32_t latmaxbin=latlong_to_bin(radians_to_latlong(latmax))-OSMNodes->file.latzero; |
313 | int32_t lonminbin=latlong_to_bin(radians_to_latlong(lonmin))-OSMNodes->file.lonzero; |
314 | int32_t lonmaxbin=latlong_to_bin(radians_to_latlong(lonmax))-OSMNodes->file.lonzero; |
315 | int latb,lonb,llbin; |
316 | index_t item; |
317 | |
318 | /* Loop through all of the nodes. */ |
319 | |
320 | for(latb=latminbin;latb<=latmaxbin;latb++) |
321 | for(lonb=lonminbin;lonb<=lonmaxbin;lonb++) |
322 | { |
323 | llbin=lonb*OSMNodes->file.latbins+latb; |
324 | |
325 | if(llbin<0 || llbin>(OSMNodes->file.latbins*OSMNodes->file.lonbins)) |
326 | continue; |
327 | |
328 | for(item=OSMNodes->offsets[llbin];item<OSMNodes->offsets[llbin+1];item++) |
329 | { |
330 | Node *node=LookupNode(OSMNodes,item,1); |
331 | double lat=latlong_to_radians(bin_to_latlong(OSMNodes->file.latzero+latb)+off_to_latlong(node->latoffset)); |
332 | double lon=latlong_to_radians(bin_to_latlong(OSMNodes->file.lonzero+lonb)+off_to_latlong(node->lonoffset)); |
333 | |
334 | if(lat>latmin && lat<latmax && lon>lonmin && lon<lonmax) |
335 | { |
336 | Segment *segment; |
337 | |
338 | print_node_osm(OSMNodes,item); |
339 | |
340 | segment=FirstSegment(OSMSegments,OSMNodes,item); |
341 | |
342 | while(segment) |
343 | { |
344 | if(item>OtherNode(segment,item)) |
345 | if(!option_no_super || IsNormalSegment(segment)) |
346 | print_segment_osm(OSMSegments,IndexSegment(OSMSegments,segment),OSMWays); |
347 | |
348 | segment=NextSegment(OSMSegments,segment,item); |
349 | } |
350 | } |
351 | } |
352 | } |
353 | } |
354 | else |
355 | { |
356 | index_t item; |
357 | |
358 | for(item=0;item<OSMNodes->file.number;item++) |
359 | print_node_osm(OSMNodes,item); |
360 | |
361 | for(item=0;item<OSMSegments->file.number;item++) |
362 | if(!option_no_super || IsNormalSegment(LookupSegment(OSMSegments,item,1))) |
363 | print_segment_osm(OSMSegments,item,OSMWays); |
364 | } |
365 | |
366 | print_tail_osm(); |
367 | } |
368 | |
369 | return(0); |
370 | } |
371 | |
372 | |
373 | /*++++++++++++++++++++++++++++++++++++++ |
374 | Print out the contents of a node from the routing database. |
375 | |
376 | Nodes *nodes The set of nodes to use. |
377 | |
378 | index_t item The node index to print. |
379 | ++++++++++++++++++++++++++++++++++++++*/ |
380 | |
381 | static void print_node(Nodes* nodes,index_t item) |
382 | { |
383 | Node *node=LookupNode(nodes,item,1); |
384 | double latitude,longitude; |
385 | |
386 | GetLatLong(nodes,item,&latitude,&longitude); |
387 | |
388 | printf("Node %d\n",item); |
389 | printf(" firstseg=%d\n",SEGMENT(node->firstseg)); |
390 | printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",node->latoffset,node->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
391 | if(IsSuperNode(nodes,item)) |
392 | printf(" Super-Node\n"); |
393 | } |
394 | |
395 | |
396 | /*++++++++++++++++++++++++++++++++++++++ |
397 | Print out the contents of a segment from the routing database. |
398 | |
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 | Segment *segment=LookupSegment(segments,item,1); |
407 | |
408 | printf("Segment %d\n",item); |
409 | printf(" node1=%d node2=%d\n",segment->node1,segment->node2); |
410 | printf(" next2=%d\n",segment->next2); |
411 | printf(" way=%d\n",segment->way); |
412 | printf(" distance=%d (%.3f km)\n",DISTANCE(segment->distance),distance_to_km(DISTANCE(segment->distance))); |
413 | if(IsSuperSegment(segment) && IsNormalSegment(segment)) |
414 | printf(" Super-Segment AND normal Segment\n"); |
415 | else if(IsSuperSegment(segment) && !IsNormalSegment(segment)) |
416 | printf(" Super-Segment\n"); |
417 | if(IsOnewayTo(segment,segment->node1)) |
418 | printf(" One-Way from node2 to node1\n"); |
419 | if(IsOnewayTo(segment,segment->node2)) |
420 | printf(" One-Way from node1 to node2\n"); |
421 | } |
422 | |
423 | |
424 | /*++++++++++++++++++++++++++++++++++++++ |
425 | Print out the contents of a way from the routing database. |
426 | |
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 | Way *way=LookupWay(ways,item); |
435 | |
436 | printf("Way %d\n",item); |
437 | printf(" name=%s\n",WayNameHighway(ways,way)); |
438 | printf(" type=%02x (%s%s%s)\n",way->type,HighwayName(HIGHWAY(way->type)),way->type&Way_OneWay?",One-Way":"",way->type&Way_Roundabout?",Roundabout":""); |
439 | printf(" allow=%02x (%s)\n",way->allow,AllowedNameList(way->allow)); |
440 | if(way->props) |
441 | printf(" props=%02x (%s)\n",way->props,PropertiesNameList(way->props)); |
442 | if(way->speed) |
443 | printf(" speed=%d (%d km/hr)\n",way->speed,speed_to_kph(way->speed)); |
444 | if(way->weight) |
445 | printf(" weight=%d (%.1f tonnes)\n",way->weight,weight_to_tonnes(way->weight)); |
446 | if(way->height) |
447 | printf(" height=%d (%.1f m)\n",way->height,height_to_metres(way->height)); |
448 | if(way->width) |
449 | printf(" width=%d (%.1f m)\n",way->width,width_to_metres(way->width)); |
450 | if(way->length) |
451 | printf(" length=%d (%.1f m)\n",way->length,length_to_metres(way->length)); |
452 | } |
453 | |
454 | |
455 | /*++++++++++++++++++++++++++++++++++++++ |
456 | Print out a header in OSM XML format. |
457 | ++++++++++++++++++++++++++++++++++++++*/ |
458 | |
459 | static void print_head_osm(void) |
460 | { |
461 | printf("<?xml version='1.0' encoding='UTF-8'?>\n"); |
462 | printf("<osm version='0.6' generator='JOSM'>\n"); |
463 | } |
464 | |
465 | |
466 | /*++++++++++++++++++++++++++++++++++++++ |
467 | Print out the contents of a node from the routing database in OSM XML format. |
468 | |
469 | Nodes *nodes The set of nodes to use. |
470 | |
471 | index_t item The node index to print. |
472 | ++++++++++++++++++++++++++++++++++++++*/ |
473 | |
474 | static void print_node_osm(Nodes* nodes,index_t item) |
475 | { |
476 | double latitude,longitude; |
477 | |
478 | GetLatLong(nodes,item,&latitude,&longitude); |
479 | |
480 | if(IsSuperNode(nodes,item)) |
481 | { |
482 | printf(" <node id='%lu' lat='%.7f' lon='%.7f' version='1'>\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
483 | printf(" <tag k='routino:super' v='yes' />\n"); |
484 | printf(" </node>\n"); |
485 | } |
486 | else |
487 | printf(" <node id='%lu' lat='%.7f' lon='%.7f' version='1' />\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
488 | } |
489 | |
490 | |
491 | /*++++++++++++++++++++++++++++++++++++++ |
492 | Print out the contents of a segment from the routing database as a way in OSM XML format. |
493 | |
494 | Segments *segments The set of segments to use. |
495 | |
496 | index_t item The segment index to print. |
497 | |
498 | Ways *ways The set of ways to use. |
499 | ++++++++++++++++++++++++++++++++++++++*/ |
500 | |
501 | static void print_segment_osm(Segments *segments,index_t item,Ways *ways) |
502 | { |
503 | Segment *segment=LookupSegment(segments,item,1); |
504 | Way *way=LookupWay(ways,segment->way); |
505 | int i; |
506 | |
507 | printf(" <way id='%lu' version='1'>\n",(unsigned long)item+1); |
508 | |
509 | if(IsOnewayTo(segment,segment->node1)) |
510 | { |
511 | printf(" <nd ref='%lu' />\n",(unsigned long)segment->node2+1); |
512 | printf(" <nd ref='%lu' />\n",(unsigned long)segment->node1+1); |
513 | } |
514 | else |
515 | { |
516 | printf(" <nd ref='%lu' />\n",(unsigned long)segment->node1+1); |
517 | printf(" <nd ref='%lu' />\n",(unsigned long)segment->node2+1); |
518 | } |
519 | |
520 | if(IsSuperSegment(segment)) |
521 | printf(" <tag k='routino:super' v='yes' />\n"); |
522 | if(IsNormalSegment(segment)) |
523 | printf(" <tag k='routino:normal' v='yes' />\n"); |
524 | |
525 | if(way->type & Way_OneWay) |
526 | printf(" <tag k='oneway' v='yes' />\n"); |
527 | if(way->type & Way_Roundabout) |
528 | printf(" <tag k='junction' v='roundabout' />\n"); |
529 | |
530 | printf(" <tag k='highway' v='%s' />\n",HighwayName(HIGHWAY(way->type))); |
531 | |
532 | if(IsNormalSegment(segment) && WayNamed(ways,way)) |
533 | printf(" <tag k='name' v='%s' />\n",ParseXML_Encode_Safe_XML(WayNameHighway(ways,way))); |
534 | |
535 | for(i=1;i<Transport_Count;i++) |
536 | if(way->allow & ALLOWED(i)) |
537 | printf(" <tag k='%s' v='yes' />\n",TransportName(i)); |
538 | |
539 | for(i=1;i<Property_Count;i++) |
540 | if(way->props & PROPERTIES(i)) |
541 | printf(" <tag k='%s' v='yes' />\n",PropertyName(i)); |
542 | |
543 | if(way->speed) |
544 | printf(" <tag k='maxspeed' v='%d' />\n",speed_to_kph(way->speed)); |
545 | |
546 | if(way->weight) |
547 | printf(" <tag k='maxweight' v='%.1f' />\n",weight_to_tonnes(way->weight)); |
548 | if(way->height) |
549 | printf(" <tag k='maxheight' v='%.1f' />\n",height_to_metres(way->height)); |
550 | if(way->width) |
551 | printf(" <tag k='maxwidth' v='%.1f' />\n",width_to_metres(way->width)); |
552 | if(way->length) |
553 | printf(" <tag k='maxlength' v='%.1f' />\n",length_to_metres(way->length)); |
554 | |
555 | printf(" </way>\n"); |
556 | } |
557 | |
558 | |
559 | /*++++++++++++++++++++++++++++++++++++++ |
560 | Print out a tail in OSM XML format. |
561 | ++++++++++++++++++++++++++++++++++++++*/ |
562 | |
563 | static void print_tail_osm(void) |
564 | { |
565 | printf("</osm>\n"); |
566 | } |
567 | |
568 | |
569 | /*+ Conversion from time_t to date string (day of week). +*/ |
570 | static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; |
571 | |
572 | /*+ Conversion from time_t to date string (month of year). +*/ |
573 | static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; |
574 | |
575 | |
576 | /*++++++++++++++++++++++++++++++++++++++ |
577 | Convert the time into an RFC 822 compliant date. |
578 | |
579 | char *RFC822Date Returns a pointer to a fixed string containing the date. |
580 | |
581 | time_t t The time. |
582 | ++++++++++++++++++++++++++++++++++++++*/ |
583 | |
584 | static char *RFC822Date(time_t t) |
585 | { |
586 | static char value[32]; |
587 | char weekday[4]; |
588 | char month[4]; |
589 | struct tm *tim; |
590 | |
591 | tim=gmtime(&t); |
592 | |
593 | strcpy(weekday,weekdays[tim->tm_wday]); |
594 | strcpy(month,months[tim->tm_mon]); |
595 | |
596 | /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */ |
597 | |
598 | sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s", |
599 | weekday, |
600 | tim->tm_mday, |
601 | month, |
602 | tim->tm_year+1900, |
603 | tim->tm_hour, |
604 | tim->tm_min, |
605 | tim->tm_sec, |
606 | "GMT" |
607 | ); |
608 | |
609 | return(value); |
610 | } |
611 | |
612 | |
613 | /*++++++++++++++++++++++++++++++++++++++ |
614 | Print out the usage information. |
615 | |
616 | int detail The level of detail to use - 0 = low, 1 = high. |
617 | ++++++++++++++++++++++++++++++++++++++*/ |
618 | |
619 | static void print_usage(int detail) |
620 | { |
621 | fprintf(stderr, |
622 | "Usage: filedumper [--help]\n" |
623 | " [--dir=<dirname>] [--prefix=<name>]\n" |
624 | " [--statistics]\n" |
625 | " [--visualiser --latmin=<latmin> --latmax=<latmax>\n" |
626 | " --lonmin=<lonmin> --lonmax=<lonmax>\n" |
627 | " --data=<data-type>]\n" |
628 | " [--dump [--node=<node> ...]\n" |
629 | " [--segment=<segment> ...]\n" |
630 | " [--way=<way> ...]]\n" |
631 | " [--dump-osm [--no-super]\n" |
632 | " [--latmin=<latmin> --latmax=<latmax>\n" |
633 | " --lonmin=<lonmin> --lonmax=<lonmax>]]\n"); |
634 | |
635 | if(detail) |
636 | fprintf(stderr, |
637 | "\n" |
638 | "--help Prints this information.\n" |
639 | "\n" |
640 | "--dir=<dirname> The directory containing the routing database.\n" |
641 | "--prefix=<name> The filename prefix for the routing database.\n" |
642 | "\n" |
643 | "--statistics Print statistics about the routing database.\n" |
644 | "\n" |
645 | "--visualiser Extract selected data from the routing database:\n" |
646 | " --latmin=<latmin> * the minimum latitude (degrees N).\n" |
647 | " --latmax=<latmax> * the maximum latitude (degrees N).\n" |
648 | " --lonmin=<lonmin> * the minimum longitude (degrees E).\n" |
649 | " --lonmax=<lonmax> * the maximum longitude (degrees E).\n" |
650 | " --data=<data-type> * the type of data to select.\n" |
651 | "\n" |
652 | " <data-type> can be selected from:\n" |
653 | " junctions = segment count at each junction.\n" |
654 | " super = super-node and super-segments.\n" |
655 | " oneway = oneway segments.\n" |
656 | " speed = speed limits.\n" |
657 | " weight = weight limits.\n" |
658 | " height = height limits.\n" |
659 | " width = width limits.\n" |
660 | " length = length limits.\n" |
661 | "\n" |
662 | "--dump Dump selected contents of the database.\n" |
663 | " --node=<node> * the node with the selected number.\n" |
664 | " --segment=<segment> * the segment with the selected number.\n" |
665 | " --way=<way> * the way with the selected number.\n" |
666 | " Use 'all' instead of a number to get all of them.\n" |
667 | "\n" |
668 | "--dump-osm Dump all or part of the database as an XML file.\n" |
669 | " --no-super * exclude the super-segments.\n" |
670 | " --latmin=<latmin> * the minimum latitude (degrees N).\n" |
671 | " --latmax=<latmax> * the maximum latitude (degrees N).\n" |
672 | " --lonmin=<lonmin> * the minimum longitude (degrees E).\n" |
673 | " --lonmax=<lonmax> * the maximum longitude (degrees E).\n"); |
674 | |
675 | exit(!detail); |
676 | } |
Properties
Name | Value |
---|---|
cvs:description | Test program for mmap files. |