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