Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /branches/destination-access/src/filedumper.c
Parent Directory
|
Revision Log
Revision 1654 -
(show annotations)
(download)
(as text)
Thu May 14 17:32:16 2015 UTC (9 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 47717 byte(s)
Thu May 14 17:32:16 2015 UTC (9 years, 10 months ago) by amb
File MIME type: text/x-csrc
File size: 47717 byte(s)
Merge changes from trunk related to compiler warnings, portability and pedantic compilation flags.
1 | /*************************************** |
2 | Memory file dumper. |
3 | |
4 | Part of the Routino routing software. |
5 | ******************/ /****************** |
6 | This file Copyright 2008-2015 Andrew M. Bishop |
7 | |
8 | This program is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU Affero General Public License as published by |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public License |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | ***************************************/ |
21 | |
22 | |
23 | #include <stdio.h> |
24 | #include <stdlib.h> |
25 | #include <string.h> |
26 | #include <sys/stat.h> |
27 | #include <sys/time.h> |
28 | #include <time.h> |
29 | #include <math.h> |
30 | |
31 | #include "types.h" |
32 | #include "nodes.h" |
33 | #include "segments.h" |
34 | #include "ways.h" |
35 | #include "relations.h" |
36 | #include "errorlog.h" |
37 | |
38 | #include "files.h" |
39 | #include "visualiser.h" |
40 | #include "xmlparse.h" |
41 | |
42 | |
43 | /* Local functions */ |
44 | |
45 | static void print_node(Nodes *nodes,index_t item); |
46 | static void print_segment(Segments *segments,index_t item); |
47 | static void print_way(Ways *ways,index_t item); |
48 | static void print_turn_relation(Relations *relations,index_t item,Segments *segments,Nodes *nodes); |
49 | static void print_errorlog(ErrorLogs *errorlogs,index_t item); |
50 | |
51 | static void print_head_osm(int coordcount,double latmin,double latmax,double lonmin,double lonmax); |
52 | static void print_region_osm(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations, |
53 | double latmin,double latmax,double lonmin,double lonmax,int option_no_super); |
54 | static void print_node_osm(Nodes *nodes,index_t item); |
55 | static void print_segment_osm(Segments *segments,index_t item,Ways *ways); |
56 | static void print_turn_relation_osm(Relations *relations,index_t item,Segments *segments,Nodes *nodes); |
57 | static void print_tail_osm(void); |
58 | |
59 | static void print_node_visualiser(Nodes *nodes,index_t item); |
60 | static void print_segment_visualiser(Segments *segments,index_t item,Ways *ways); |
61 | static void print_turn_relation_visualiser(Relations *relations,index_t item,Segments *segments,Nodes *nodes); |
62 | static void print_errorlog_visualiser(ErrorLogs *errorlogs,index_t item); |
63 | |
64 | static char *RFC822Date(time_t t); |
65 | |
66 | static void print_usage(int detail,const char *argerr,const char *err); |
67 | |
68 | |
69 | /*++++++++++++++++++++++++++++++++++++++ |
70 | The main program for the file dumper. |
71 | ++++++++++++++++++++++++++++++++++++++*/ |
72 | |
73 | int main(int argc,char** argv) |
74 | { |
75 | Nodes *OSMNodes; |
76 | Segments *OSMSegments; |
77 | Ways *OSMWays; |
78 | Relations*OSMRelations; |
79 | ErrorLogs*OSMErrorLogs=NULL; |
80 | int arg; |
81 | char *dirname=NULL,*prefix=NULL; |
82 | char *nodes_filename,*segments_filename,*ways_filename,*relations_filename,*errorlogs_filename; |
83 | int option_statistics=0; |
84 | int option_visualiser=0,coordcount=0; |
85 | double latmin=0,latmax=0,lonmin=0,lonmax=0; |
86 | char *option_data=NULL; |
87 | int option_dump=0; |
88 | int option_dump_osm=0,option_no_super=0; |
89 | int option_dump_visualiser=0; |
90 | |
91 | /* Parse the command line arguments */ |
92 | |
93 | for(arg=1;arg<argc;arg++) |
94 | { |
95 | if(!strcmp(argv[arg],"--help")) |
96 | print_usage(1,NULL,NULL); |
97 | else if(!strncmp(argv[arg],"--dir=",6)) |
98 | dirname=&argv[arg][6]; |
99 | else if(!strncmp(argv[arg],"--prefix=",9)) |
100 | prefix=&argv[arg][9]; |
101 | else if(!strcmp(argv[arg],"--statistics")) |
102 | option_statistics=1; |
103 | else if(!strcmp(argv[arg],"--visualiser")) |
104 | option_visualiser=1; |
105 | else if(!strcmp(argv[arg],"--dump")) |
106 | option_dump=1; |
107 | else if(!strcmp(argv[arg],"--dump-osm")) |
108 | option_dump_osm=1; |
109 | else if(!strcmp(argv[arg],"--dump-visualiser")) |
110 | option_dump_visualiser=1; |
111 | else if(!strncmp(argv[arg],"--latmin",8) && argv[arg][8]=='=') |
112 | {latmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;} |
113 | else if(!strncmp(argv[arg],"--latmax",8) && argv[arg][8]=='=') |
114 | {latmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;} |
115 | else if(!strncmp(argv[arg],"--lonmin",8) && argv[arg][8]=='=') |
116 | {lonmin=degrees_to_radians(atof(&argv[arg][9]));coordcount++;} |
117 | else if(!strncmp(argv[arg],"--lonmax",8) && argv[arg][8]=='=') |
118 | {lonmax=degrees_to_radians(atof(&argv[arg][9]));coordcount++;} |
119 | else if(!strncmp(argv[arg],"--data",6) && argv[arg][6]=='=') |
120 | option_data=&argv[arg][7]; |
121 | else if(!strcmp(argv[arg],"--no-super")) |
122 | option_no_super=1; |
123 | else if(!strncmp(argv[arg],"--node=",7)) |
124 | ; |
125 | else if(!strncmp(argv[arg],"--segment=",10)) |
126 | ; |
127 | else if(!strncmp(argv[arg],"--way=",6)) |
128 | ; |
129 | else if(!strncmp(argv[arg],"--turn-relation=",16)) |
130 | ; |
131 | else if(!strncmp(argv[arg],"--errorlog=",11)) |
132 | ; |
133 | else |
134 | print_usage(0,argv[arg],NULL); |
135 | } |
136 | |
137 | if((option_statistics + option_visualiser + option_dump + option_dump_osm + option_dump_visualiser)!=1) |
138 | print_usage(0,NULL,"Must choose --visualiser, --statistics, --dump, --dump-osm or --dump-visualiser."); |
139 | |
140 | /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */ |
141 | |
142 | OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem")); |
143 | |
144 | OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem")); |
145 | |
146 | OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem")); |
147 | |
148 | OSMRelations=LoadRelationList(relations_filename=FileName(dirname,prefix,"relations.mem")); |
149 | |
150 | if(ExistsFile(errorlogs_filename=FileName(dirname,prefix,"errorlogs.mem"))) |
151 | OSMErrorLogs=LoadErrorLogs(errorlogs_filename); |
152 | else |
153 | errorlogs_filename=NULL; |
154 | |
155 | /* Write out the visualiser data */ |
156 | |
157 | if(option_visualiser) |
158 | { |
159 | Highway highway; |
160 | Transport transport; |
161 | Property property; |
162 | |
163 | if(coordcount!=4) |
164 | print_usage(0,NULL,"The --visualiser option must have --latmin, --latmax, --lonmin, --lonmax.\n"); |
165 | |
166 | if(!option_data) |
167 | print_usage(0,NULL,"The --visualiser option must have --data.\n"); |
168 | |
169 | if(!strcmp(option_data,"junctions")) |
170 | OutputJunctions(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
171 | else if(!strcmp(option_data,"super")) |
172 | OutputSuper(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
173 | else if(!strcmp(option_data,"waytype-oneway")) |
174 | OutputWaytype(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,Highway_OneWay); |
175 | else if(!strcmp(option_data,"waytype-cyclebothways")) |
176 | OutputWaytype(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,Highway_CycleBothWays); |
177 | else if(!strcmp(option_data,"waytype-roundabout")) |
178 | OutputWaytype(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,Highway_Roundabout); |
179 | else if(!strncmp(option_data,"highway",7) && option_data[7]=='-' && (highway=HighwayType(option_data+8))!=Highway_None) |
180 | OutputHighway(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,highway); |
181 | else if(!strncmp(option_data,"transport",9) && option_data[9]=='-' && (transport=TransportType(option_data+10))!=Transport_None) |
182 | OutputTransport(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,transport); |
183 | else if(!strncmp(option_data,"destination",11) && option_data[11]=='-' && (transport=TransportType(option_data+12))!=Transport_None) |
184 | OutputDestination(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,transport); |
185 | else if(!strncmp(option_data,"barrier",7) && option_data[7]=='-' && (transport=TransportType(option_data+8))!=Transport_None) |
186 | OutputBarrier(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,transport); |
187 | else if(!strcmp(option_data,"turns")) |
188 | OutputTurnRestrictions(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
189 | else if(!strcmp(option_data,"speed")) |
190 | OutputSpeedLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
191 | else if(!strcmp(option_data,"weight")) |
192 | OutputWeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
193 | else if(!strcmp(option_data,"height")) |
194 | OutputHeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
195 | else if(!strcmp(option_data,"width")) |
196 | OutputWidthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
197 | else if(!strcmp(option_data,"length")) |
198 | OutputLengthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
199 | else if(!strncmp(option_data,"property",8) && option_data[8]=='-' && (property=PropertyType(option_data+9))!=Property_None) |
200 | OutputProperty(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,property); |
201 | else if(!strcmp(option_data,"errorlogs")) |
202 | OutputErrorLog(OSMErrorLogs,latmin,latmax,lonmin,lonmax); |
203 | else |
204 | print_usage(0,option_data,NULL); |
205 | } |
206 | |
207 | /* Print out statistics */ |
208 | |
209 | if(option_statistics) |
210 | { |
211 | struct stat buf; |
212 | |
213 | /* Examine the files */ |
214 | |
215 | printf("Files\n"); |
216 | printf("-----\n"); |
217 | printf("\n"); |
218 | |
219 | stat(nodes_filename,&buf); |
220 | |
221 | printf("'%s%snodes.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size); |
222 | printf("%s\n",RFC822Date(buf.st_mtime)); |
223 | printf("\n"); |
224 | |
225 | stat(segments_filename,&buf); |
226 | |
227 | printf("'%s%ssegments.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size); |
228 | printf("%s\n",RFC822Date(buf.st_mtime)); |
229 | printf("\n"); |
230 | |
231 | stat(ways_filename,&buf); |
232 | |
233 | printf("'%s%sways.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size); |
234 | printf("%s\n",RFC822Date(buf.st_mtime)); |
235 | printf("\n"); |
236 | |
237 | stat(relations_filename,&buf); |
238 | |
239 | printf("'%s%srelations.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size); |
240 | printf("%s\n",RFC822Date(buf.st_mtime)); |
241 | printf("\n"); |
242 | |
243 | if(errorlogs_filename) |
244 | { |
245 | stat(errorlogs_filename,&buf); |
246 | |
247 | printf("'%s%serrorlogs.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size); |
248 | printf("%s\n",RFC822Date(buf.st_mtime)); |
249 | printf("\n"); |
250 | } |
251 | |
252 | /* Examine the nodes */ |
253 | |
254 | printf("Nodes\n"); |
255 | printf("-----\n"); |
256 | printf("\n"); |
257 | |
258 | printf("sizeof(Node) =%9zu Bytes\n",sizeof(Node)); |
259 | printf("Number =%9"Pindex_t"\n",OSMNodes->file.number); |
260 | printf("Number(super)=%9"Pindex_t"\n",OSMNodes->file.snumber); |
261 | printf("\n"); |
262 | |
263 | printf("Lat bins= %4d\n",(int)OSMNodes->file.latbins); |
264 | printf("Lon bins= %4d\n",(int)OSMNodes->file.lonbins); |
265 | printf("\n"); |
266 | |
267 | printf("Lat zero=%5d (%8.4f deg)\n",(int)OSMNodes->file.latzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.latzero)))); |
268 | printf("Lon zero=%5d (%8.4f deg)\n",(int)OSMNodes->file.lonzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.lonzero)))); |
269 | |
270 | /* Examine the segments */ |
271 | |
272 | printf("\n"); |
273 | printf("Segments\n"); |
274 | printf("--------\n"); |
275 | printf("\n"); |
276 | |
277 | printf("sizeof(Segment)=%9zu Bytes\n",sizeof(Segment)); |
278 | printf("Number(total) =%9"Pindex_t"\n",OSMSegments->file.number); |
279 | printf("Number(super) =%9"Pindex_t"\n",OSMSegments->file.snumber); |
280 | printf("Number(normal) =%9"Pindex_t"\n",OSMSegments->file.nnumber); |
281 | |
282 | /* Examine the ways */ |
283 | |
284 | printf("\n"); |
285 | printf("Ways\n"); |
286 | printf("----\n"); |
287 | printf("\n"); |
288 | |
289 | printf("sizeof(Way)=%9zu Bytes\n",sizeof(Way)); |
290 | printf("Number =%9"Pindex_t"\n",OSMWays->file.number); |
291 | printf("\n"); |
292 | |
293 | stat(ways_filename,&buf); |
294 | printf("Total names=%9zu Bytes\n",(size_t)buf.st_size-sizeof(Ways)-OSMWays->file.number*sizeof(Way)); |
295 | printf("\n"); |
296 | |
297 | printf("Included highways : %s\n",HighwaysNameList(OSMWays->file.highways)); |
298 | printf("Included transports: %s\n",AllowedNameList(OSMWays->file.allow)); |
299 | printf("Included properties: %s\n",PropertiesNameList(OSMWays->file.props)); |
300 | |
301 | /* Examine the relations */ |
302 | |
303 | printf("\n"); |
304 | printf("Relations\n"); |
305 | printf("---------\n"); |
306 | printf("\n"); |
307 | |
308 | printf("sizeof(TurnRelation)=%9zu Bytes\n",sizeof(TurnRelation)); |
309 | printf("Number =%9"Pindex_t"\n",OSMRelations->file.trnumber); |
310 | |
311 | if(errorlogs_filename) |
312 | { |
313 | printf("\n"); |
314 | printf("Error Logs\n"); |
315 | printf("----------\n"); |
316 | printf("\n"); |
317 | |
318 | printf("Number(total) =%9"Pindex_t"\n",OSMErrorLogs->file.number); |
319 | printf("Number(geographical) =%9"Pindex_t"\n",OSMErrorLogs->file.number_geo); |
320 | printf("Number(non-geographical)=%9"Pindex_t"\n",OSMErrorLogs->file.number_nongeo); |
321 | |
322 | printf("\n"); |
323 | stat(errorlogs_filename,&buf); |
324 | #if !SLIM |
325 | printf("Total strings=%9zu Bytes\n",(size_t)buf.st_size-(OSMErrorLogs->strings-(char*)OSMErrorLogs->data)); |
326 | #else |
327 | printf("Total strings=%9zu Bytes\n",(size_t)buf.st_size-(size_t)OSMErrorLogs->stringsoffset); |
328 | #endif |
329 | } |
330 | } |
331 | |
332 | /* Print out internal data (in plain text format) */ |
333 | |
334 | if(option_dump) |
335 | { |
336 | index_t item; |
337 | |
338 | for(arg=1;arg<argc;arg++) |
339 | if(!strcmp(argv[arg],"--node=all")) |
340 | { |
341 | for(item=0;item<OSMNodes->file.number;item++) |
342 | print_node(OSMNodes,item); |
343 | } |
344 | else if(!strncmp(argv[arg],"--node=",7)) |
345 | { |
346 | item=atoi(&argv[arg][7]); |
347 | |
348 | if(item<OSMNodes->file.number) |
349 | print_node(OSMNodes,item); |
350 | else |
351 | printf("Invalid node number; minimum=0, maximum=%"Pindex_t".\n",OSMNodes->file.number-1); |
352 | } |
353 | else if(!strcmp(argv[arg],"--segment=all")) |
354 | { |
355 | for(item=0;item<OSMSegments->file.number;item++) |
356 | print_segment(OSMSegments,item); |
357 | } |
358 | else if(!strncmp(argv[arg],"--segment=",10)) |
359 | { |
360 | item=atoi(&argv[arg][10]); |
361 | |
362 | if(item<OSMSegments->file.number) |
363 | print_segment(OSMSegments,item); |
364 | else |
365 | printf("Invalid segment number; minimum=0, maximum=%"Pindex_t".\n",OSMSegments->file.number-1); |
366 | } |
367 | else if(!strcmp(argv[arg],"--way=all")) |
368 | { |
369 | for(item=0;item<OSMWays->file.number;item++) |
370 | print_way(OSMWays,item); |
371 | } |
372 | else if(!strncmp(argv[arg],"--way=",6)) |
373 | { |
374 | item=atoi(&argv[arg][6]); |
375 | |
376 | if(item<OSMWays->file.number) |
377 | print_way(OSMWays,item); |
378 | else |
379 | printf("Invalid way number; minimum=0, maximum=%"Pindex_t".\n",OSMWays->file.number-1); |
380 | } |
381 | else if(!strcmp(argv[arg],"--turn-relation=all")) |
382 | { |
383 | for(item=0;item<OSMRelations->file.trnumber;item++) |
384 | print_turn_relation(OSMRelations,item,OSMSegments,OSMNodes); |
385 | } |
386 | else if(!strncmp(argv[arg],"--turn-relation=",16)) |
387 | { |
388 | item=atoi(&argv[arg][16]); |
389 | |
390 | if(item<OSMRelations->file.trnumber) |
391 | print_turn_relation(OSMRelations,item,OSMSegments,OSMNodes); |
392 | else |
393 | printf("Invalid turn relation number; minimum=0, maximum=%"Pindex_t".\n",OSMRelations->file.trnumber-1); |
394 | } |
395 | else if(!strcmp(argv[arg],"--errorlog=all")) |
396 | { |
397 | for(item=0;item<OSMErrorLogs->file.number;item++) |
398 | print_errorlog(OSMErrorLogs,item); |
399 | } |
400 | else if(!strncmp(argv[arg],"--errorlog=",11)) |
401 | { |
402 | item=atoi(&argv[arg][11]); |
403 | |
404 | if(item<OSMErrorLogs->file.number) |
405 | print_errorlog(OSMErrorLogs,item); |
406 | else |
407 | printf("Invalid error log number; minimum=0, maximum=%"Pindex_t".\n",OSMErrorLogs->file.number-1); |
408 | } |
409 | } |
410 | |
411 | /* Print out internal data (in OSM XML format) */ |
412 | |
413 | if(option_dump_osm) |
414 | { |
415 | if(coordcount>0 && coordcount!=4) |
416 | print_usage(0,NULL,"The --dump-osm option must have all of --latmin, --latmax, --lonmin, --lonmax or none.\n"); |
417 | |
418 | print_head_osm(coordcount,latmin,latmax,lonmin,lonmax); |
419 | |
420 | if(coordcount) |
421 | print_region_osm(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,option_no_super); |
422 | else |
423 | { |
424 | index_t item; |
425 | |
426 | for(item=0;item<OSMNodes->file.number;item++) |
427 | print_node_osm(OSMNodes,item); |
428 | |
429 | for(item=0;item<OSMSegments->file.number;item++) |
430 | if(!option_no_super || IsNormalSegment(LookupSegment(OSMSegments,item,1))) |
431 | print_segment_osm(OSMSegments,item,OSMWays); |
432 | |
433 | for(item=0;item<OSMRelations->file.trnumber;item++) |
434 | print_turn_relation_osm(OSMRelations,item,OSMSegments,OSMNodes); |
435 | } |
436 | |
437 | print_tail_osm(); |
438 | } |
439 | |
440 | /* Print out internal data (in HTML format for the visualiser) */ |
441 | |
442 | if(option_dump_visualiser) |
443 | { |
444 | index_t item; |
445 | |
446 | if(!option_data) |
447 | print_usage(0,NULL,"The --dump-visualiser option must have --data.\n"); |
448 | |
449 | for(arg=1;arg<argc;arg++) |
450 | if(!strncmp(argv[arg],"--data=node",11)) |
451 | { |
452 | item=atoi(&argv[arg][11]); |
453 | |
454 | if(item<OSMNodes->file.number) |
455 | print_node_visualiser(OSMNodes,item); |
456 | else |
457 | printf("Invalid node number; minimum=0, maximum=%"Pindex_t".\n",OSMNodes->file.number-1); |
458 | } |
459 | else if(!strncmp(argv[arg],"--data=segment",14)) |
460 | { |
461 | item=atoi(&argv[arg][14]); |
462 | |
463 | if(item<OSMSegments->file.number) |
464 | print_segment_visualiser(OSMSegments,item,OSMWays); |
465 | else |
466 | printf("Invalid segment number; minimum=0, maximum=%"Pindex_t".\n",OSMSegments->file.number-1); |
467 | } |
468 | else if(!strncmp(argv[arg],"--data=turn-relation",20)) |
469 | { |
470 | item=atoi(&argv[arg][20]); |
471 | |
472 | if(item<OSMRelations->file.trnumber) |
473 | print_turn_relation_visualiser(OSMRelations,item,OSMSegments,OSMNodes); |
474 | else |
475 | printf("Invalid turn relation number; minimum=0, maximum=%"Pindex_t".\n",OSMRelations->file.trnumber-1); |
476 | } |
477 | else if(!strncmp(argv[arg],"--data=errorlog",15)) |
478 | { |
479 | item=atoi(&argv[arg][15]); |
480 | |
481 | if(item<OSMErrorLogs->file.number) |
482 | print_errorlog_visualiser(OSMErrorLogs,item); |
483 | else |
484 | printf("Invalid error log number; minimum=0, maximum=%"Pindex_t".\n",OSMErrorLogs->file.number-1); |
485 | } |
486 | } |
487 | |
488 | exit(EXIT_SUCCESS); |
489 | } |
490 | |
491 | |
492 | /*++++++++++++++++++++++++++++++++++++++ |
493 | Print out the contents of a node from the routing database (as plain text). |
494 | |
495 | Nodes *nodes The set of nodes to use. |
496 | |
497 | index_t item The node index to print. |
498 | ++++++++++++++++++++++++++++++++++++++*/ |
499 | |
500 | static void print_node(Nodes *nodes,index_t item) |
501 | { |
502 | Node *nodep=LookupNode(nodes,item,1); |
503 | double latitude,longitude; |
504 | |
505 | GetLatLong(nodes,item,nodep,&latitude,&longitude); |
506 | |
507 | printf("Node %"Pindex_t"\n",item); |
508 | printf(" firstseg=%"Pindex_t"\n",nodep->firstseg); |
509 | printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",nodep->latoffset,nodep->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
510 | printf(" allow=%02x (%s)\n",nodep->allow,AllowedNameList(nodep->allow)); |
511 | printf(" destination=%02x (%s)\n",nodep->destination,AllowedNameList(nodep->destination)); |
512 | if(IsSuperNode(nodep)) |
513 | printf(" Super-Node\n"); |
514 | if(nodep->flags & NODE_MINIRNDBT) |
515 | printf(" Mini-roundabout\n"); |
516 | } |
517 | |
518 | |
519 | /*++++++++++++++++++++++++++++++++++++++ |
520 | Print out the contents of a segment from the routing database (as plain text). |
521 | |
522 | Segments *segments The set of segments to use. |
523 | |
524 | index_t item The segment index to print. |
525 | ++++++++++++++++++++++++++++++++++++++*/ |
526 | |
527 | static void print_segment(Segments *segments,index_t item) |
528 | { |
529 | Segment *segmentp=LookupSegment(segments,item,1); |
530 | |
531 | printf("Segment %"Pindex_t"\n",item); |
532 | printf(" node1=%"Pindex_t" node2=%"Pindex_t"\n",segmentp->node1,segmentp->node2); |
533 | printf(" next2=%"Pindex_t"\n",segmentp->next2); |
534 | printf(" way=%"Pindex_t"\n",segmentp->way); |
535 | printf(" distance=%d (%.3f km)\n",DISTANCE(segmentp->distance),distance_to_km(DISTANCE(segmentp->distance))); |
536 | if(IsSuperSegment(segmentp) && IsNormalSegment(segmentp)) |
537 | printf(" Super-Segment AND normal Segment\n"); |
538 | else if(IsSuperSegment(segmentp) && !IsNormalSegment(segmentp)) |
539 | printf(" Super-Segment\n"); |
540 | if(IsOnewayTo(segmentp,segmentp->node1)) |
541 | printf(" One-Way from node2 to node1\n"); |
542 | if(IsOnewayTo(segmentp,segmentp->node2)) |
543 | printf(" One-Way from node1 to node2\n"); |
544 | } |
545 | |
546 | |
547 | /*++++++++++++++++++++++++++++++++++++++ |
548 | Print out the contents of a way from the routing database (as plain text). |
549 | |
550 | Ways *ways The set of ways to use. |
551 | |
552 | index_t item The way index to print. |
553 | ++++++++++++++++++++++++++++++++++++++*/ |
554 | |
555 | static void print_way(Ways *ways,index_t item) |
556 | { |
557 | Way *wayp=LookupWay(ways,item,1); |
558 | char *name=WayName(ways,wayp); |
559 | |
560 | printf("Way %"Pindex_t"\n",item); |
561 | if(*name) |
562 | printf(" name=%s\n",name); |
563 | printf(" type=%02x (%s%s%s%s)\n",wayp->type, |
564 | HighwayName(HIGHWAY(wayp->type)), |
565 | wayp->type&Highway_OneWay?",One-Way":"", |
566 | wayp->type&Highway_CycleBothWays?",Cycle-Both-Ways":"", |
567 | wayp->type&Highway_Roundabout?",Roundabout":""); |
568 | printf(" allow=%02x (%s)\n",wayp->allow,AllowedNameList(wayp->allow)); |
569 | printf(" destination=%02x (%s)\n",wayp->destination,AllowedNameList(wayp->destination)); |
570 | if(wayp->props) |
571 | printf(" props=%02x (%s)\n",wayp->props,PropertiesNameList(wayp->props)); |
572 | if(wayp->speed) |
573 | printf(" speed=%d (%d km/hr)\n",wayp->speed,speed_to_kph(wayp->speed)); |
574 | if(wayp->weight) |
575 | printf(" weight=%d (%.1f tonnes)\n",wayp->weight,weight_to_tonnes(wayp->weight)); |
576 | if(wayp->height) |
577 | printf(" height=%d (%.1f m)\n",wayp->height,height_to_metres(wayp->height)); |
578 | if(wayp->width) |
579 | printf(" width=%d (%.1f m)\n",wayp->width,width_to_metres(wayp->width)); |
580 | if(wayp->length) |
581 | printf(" length=%d (%.1f m)\n",wayp->length,length_to_metres(wayp->length)); |
582 | } |
583 | |
584 | |
585 | /*++++++++++++++++++++++++++++++++++++++ |
586 | Print out the contents of a turn relation from the routing database (as plain text). |
587 | |
588 | Relations *relations The set of relations to use. |
589 | |
590 | index_t item The turn relation index to print. |
591 | |
592 | Segments *segments The set of segments to use. |
593 | |
594 | Nodes *nodes The set of nodes to use. |
595 | ++++++++++++++++++++++++++++++++++++++*/ |
596 | |
597 | static void print_turn_relation(Relations *relations,index_t item,Segments *segments,Nodes *nodes) |
598 | { |
599 | Segment *segmentp; |
600 | TurnRelation *relationp=LookupTurnRelation(relations,item,1); |
601 | Node *nodep=LookupNode(nodes,relationp->via,1); |
602 | index_t from_way=NO_WAY,to_way=NO_WAY; |
603 | index_t from_node=NO_NODE,to_node=NO_NODE; |
604 | |
605 | segmentp=FirstSegment(segments,nodep,1); |
606 | |
607 | do |
608 | { |
609 | index_t seg=IndexSegment(segments,segmentp); |
610 | |
611 | if(seg==relationp->from) |
612 | { |
613 | from_node=OtherNode(segmentp,relationp->from); |
614 | from_way=segmentp->way; |
615 | } |
616 | |
617 | if(seg==relationp->to) |
618 | { |
619 | to_node=OtherNode(segmentp,relationp->to); |
620 | to_way=segmentp->way; |
621 | } |
622 | |
623 | segmentp=NextSegment(segments,segmentp,relationp->via); |
624 | } |
625 | while(segmentp); |
626 | |
627 | printf("Relation %"Pindex_t"\n",item); |
628 | printf(" from=%"Pindex_t" (segment) = %"Pindex_t" (way) = %"Pindex_t" (node)\n",relationp->from,from_way,from_node); |
629 | printf(" via=%"Pindex_t" (node)\n",relationp->via); |
630 | printf(" to=%"Pindex_t" (segment) = %"Pindex_t" (way) = %"Pindex_t" (node)\n",relationp->to,to_way,to_node); |
631 | if(relationp->except) |
632 | printf(" except=%02x (%s)\n",relationp->except,AllowedNameList(relationp->except)); |
633 | } |
634 | |
635 | |
636 | /*++++++++++++++++++++++++++++++++++++++ |
637 | Print out the contents of an error log from the routing database (as plain text). |
638 | |
639 | ErrorLogs *errorlogs The set of error logs to use. |
640 | |
641 | index_t item The error log index to print. |
642 | ++++++++++++++++++++++++++++++++++++++*/ |
643 | |
644 | static void print_errorlog(ErrorLogs *errorlogs,index_t item) |
645 | { |
646 | ErrorLog *errorlogp=LookupErrorLog(errorlogs,item,1); |
647 | |
648 | printf("Error Log %"Pindex_t"\n",item); |
649 | |
650 | if(item<errorlogs->file.number_geo) |
651 | { |
652 | double latitude,longitude; |
653 | |
654 | GetErrorLogLatLong(errorlogs,item,errorlogp,&latitude,&longitude); |
655 | |
656 | printf(" latoffset=%d lonoffset=%d (latitude=%.6f longitude=%.6f)\n",errorlogp->latoffset,errorlogp->lonoffset,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
657 | } |
658 | else |
659 | printf(" No geographical information\n"); |
660 | |
661 | printf(" '%s'\n",LookupErrorLogString(errorlogs,item)); |
662 | } |
663 | |
664 | |
665 | /*++++++++++++++++++++++++++++++++++++++ |
666 | Print out a header in OSM XML format. |
667 | |
668 | int coordcount If true then include a bounding box. |
669 | |
670 | double latmin The minimum latitude. |
671 | |
672 | double latmax The maximum latitude. |
673 | |
674 | double lonmin The minimum longitude. |
675 | |
676 | double lonmax The maximum longitude. |
677 | ++++++++++++++++++++++++++++++++++++++*/ |
678 | |
679 | static void print_head_osm(int coordcount,double latmin,double latmax,double lonmin,double lonmax) |
680 | { |
681 | printf("<?xml version='1.0' encoding='UTF-8'?>\n"); |
682 | printf("<osm version='0.6' generator='Routino'>\n"); |
683 | |
684 | if(coordcount) |
685 | printf(" <bounds minlat='%.6f' maxlat='%.6f' minlon='%.6f' maxlon='%.6f' />\n", |
686 | radians_to_degrees(latmin),radians_to_degrees(latmax),radians_to_degrees(lonmin),radians_to_degrees(lonmax)); |
687 | } |
688 | |
689 | |
690 | /*++++++++++++++++++++++++++++++++++++++ |
691 | Print a region of the database in OSM XML format. |
692 | |
693 | Nodes *nodes The set of nodes to use. |
694 | |
695 | Segments *segments The set of segments to use. |
696 | |
697 | Ways *ways The set of ways to use. |
698 | |
699 | Relations *relations The set of relations to use. |
700 | |
701 | double latmin The minimum latitude. |
702 | |
703 | double latmax The maximum latitude. |
704 | |
705 | double lonmin The minimum longitude. |
706 | |
707 | double lonmax The maximum longitude. |
708 | |
709 | int option_no_super The option to print no super-segments. |
710 | ++++++++++++++++++++++++++++++++++++++*/ |
711 | |
712 | static void print_region_osm(Nodes *nodes,Segments *segments,Ways *ways,Relations *relations, |
713 | double latmin,double latmax,double lonmin,double lonmax,int option_no_super) |
714 | { |
715 | ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(latmin))-nodes->file.latzero; |
716 | ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(latmax))-nodes->file.latzero; |
717 | ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(lonmin))-nodes->file.lonzero; |
718 | ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(lonmax))-nodes->file.lonzero; |
719 | ll_bin_t latb,lonb; |
720 | index_t item,index1,index2; |
721 | |
722 | if(latminbin<0) latminbin=0; |
723 | if(latmaxbin>nodes->file.latbins) latmaxbin=nodes->file.latbins-1; |
724 | if(lonminbin<0) lonminbin=0; |
725 | if(lonmaxbin>nodes->file.lonbins) lonmaxbin=nodes->file.lonbins-1; |
726 | |
727 | /* Loop through all of the nodes. */ |
728 | |
729 | for(latb=latminbin;latb<=latmaxbin;latb++) |
730 | for(lonb=lonminbin;lonb<=lonmaxbin;lonb++) |
731 | { |
732 | ll_bin2_t llbin=lonb*nodes->file.latbins+latb; |
733 | |
734 | if(llbin<0 || llbin>(nodes->file.latbins*nodes->file.lonbins)) |
735 | continue; |
736 | |
737 | index1=LookupNodeOffset(nodes,llbin); |
738 | index2=LookupNodeOffset(nodes,llbin+1); |
739 | |
740 | for(item=index1;item<index2;item++) |
741 | { |
742 | Node *nodep=LookupNode(nodes,item,1); |
743 | double lat=latlong_to_radians(bin_to_latlong(nodes->file.latzero+latb)+off_to_latlong(nodep->latoffset)); |
744 | double lon=latlong_to_radians(bin_to_latlong(nodes->file.lonzero+lonb)+off_to_latlong(nodep->lonoffset)); |
745 | |
746 | if(lat>latmin && lat<latmax && lon>lonmin && lon<lonmax) |
747 | { |
748 | Segment *segmentp; |
749 | |
750 | print_node_osm(nodes,item); |
751 | |
752 | segmentp=FirstSegment(segments,nodep,1); |
753 | |
754 | while(segmentp) |
755 | { |
756 | double olat,olon; |
757 | index_t oitem=OtherNode(segmentp,item); |
758 | |
759 | GetLatLong(nodes,oitem,NULL,&olat,&olon); |
760 | |
761 | if(olat>latmin && olat<latmax && olon>lonmin && olon<lonmax) |
762 | if(item>oitem) |
763 | if(!option_no_super || IsNormalSegment(segmentp)) |
764 | print_segment_osm(segments,IndexSegment(segments,segmentp),ways); |
765 | |
766 | segmentp=NextSegment(segments,segmentp,item); |
767 | } |
768 | |
769 | if(IsTurnRestrictedNode(nodep)) |
770 | { |
771 | index_t relindex=FindFirstTurnRelation1(relations,item); |
772 | |
773 | while(relindex!=NO_RELATION) |
774 | { |
775 | print_turn_relation_osm(relations,relindex,segments,nodes); |
776 | |
777 | relindex=FindNextTurnRelation1(relations,relindex); |
778 | } |
779 | } |
780 | } |
781 | } |
782 | } |
783 | } |
784 | |
785 | |
786 | /*++++++++++++++++++++++++++++++++++++++ |
787 | Print out the contents of a node from the routing database (in OSM XML format). |
788 | |
789 | Nodes *nodes The set of nodes to use. |
790 | |
791 | index_t item The node index to print. |
792 | ++++++++++++++++++++++++++++++++++++++*/ |
793 | |
794 | static void print_node_osm(Nodes *nodes,index_t item) |
795 | { |
796 | Node *nodep=LookupNode(nodes,item,1); |
797 | double latitude,longitude; |
798 | int i; |
799 | |
800 | GetLatLong(nodes,item,nodep,&latitude,&longitude); |
801 | |
802 | if(nodep->allow==Transports_ALL && nodep->destination==Transports_None && nodep->flags==0) |
803 | printf(" <node id='%"Pindex_t"' lat='%.7f' lon='%.7f' version='1' />\n",item+1,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
804 | else |
805 | { |
806 | printf(" <node id='%"Pindex_t"' lat='%.7f' lon='%.7f' version='1'>\n",item+1,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
807 | |
808 | if(nodep->flags & NODE_SUPER) |
809 | printf(" <tag k='routino:super' v='yes' />\n"); |
810 | |
811 | if(nodep->flags & NODE_UTURN) |
812 | printf(" <tag k='routino:uturn' v='yes' />\n"); |
813 | |
814 | if(nodep->flags & NODE_MINIRNDBT) |
815 | printf(" <tag k='junction' v='roundabout' />\n"); |
816 | |
817 | if(nodep->flags & NODE_TURNRSTRCT) |
818 | printf(" <tag k='routino:turnrestriction' v='yes' />\n"); |
819 | |
820 | for(i=1;i<Transport_Count;i++) |
821 | { |
822 | if(nodep->destination & TRANSPORTS(i)) |
823 | printf(" <tag k='%s' v='destination' />\n",TransportName(i)); |
824 | else if(!(nodep->allow & TRANSPORTS(i))) |
825 | printf(" <tag k='%s' v='no' />\n",TransportName(i)); |
826 | } |
827 | |
828 | printf(" </node>\n"); |
829 | } |
830 | } |
831 | |
832 | |
833 | /*++++++++++++++++++++++++++++++++++++++ |
834 | Print out the contents of a segment from the routing database (as a way in OSM XML format). |
835 | |
836 | Segments *segments The set of segments to use. |
837 | |
838 | index_t item The segment index to print. |
839 | |
840 | Ways *ways The set of ways to use. |
841 | ++++++++++++++++++++++++++++++++++++++*/ |
842 | |
843 | static void print_segment_osm(Segments *segments,index_t item,Ways *ways) |
844 | { |
845 | Segment *segmentp=LookupSegment(segments,item,1); |
846 | Way *wayp=LookupWay(ways,segmentp->way,1); |
847 | char *name=WayName(ways,wayp); |
848 | int i; |
849 | |
850 | printf(" <way id='%"Pindex_t"' version='1'>\n",item+1); |
851 | |
852 | if(IsOnewayTo(segmentp,segmentp->node1)) |
853 | { |
854 | printf(" <nd ref='%"Pindex_t"' />\n",segmentp->node2+1); |
855 | printf(" <nd ref='%"Pindex_t"' />\n",segmentp->node1+1); |
856 | } |
857 | else |
858 | { |
859 | printf(" <nd ref='%"Pindex_t"' />\n",segmentp->node1+1); |
860 | printf(" <nd ref='%"Pindex_t"' />\n",segmentp->node2+1); |
861 | } |
862 | |
863 | if(IsSuperSegment(segmentp)) |
864 | printf(" <tag k='routino:super' v='yes' />\n"); |
865 | if(IsNormalSegment(segmentp)) |
866 | printf(" <tag k='routino:normal' v='yes' />\n"); |
867 | |
868 | printf(" <tag k='routino:distance' v='%.3f' />\n",distance_to_km(DISTANCE(segmentp->distance))); |
869 | |
870 | if(wayp->type & Highway_OneWay) |
871 | printf(" <tag k='oneway' v='yes' />\n"); |
872 | |
873 | if(wayp->type & Highway_CycleBothWays) |
874 | printf(" <tag k='cyclebothways' v='yes' />\n"); |
875 | |
876 | if(wayp->type & Highway_Roundabout) |
877 | printf(" <tag k='roundabout' v='yes' />\n"); |
878 | |
879 | printf(" <tag k='highway' v='%s' />\n",HighwayName(HIGHWAY(wayp->type))); |
880 | |
881 | if(IsNormalSegment(segmentp) && *name) |
882 | printf(" <tag k='name' v='%s' />\n",ParseXML_Encode_Safe_XML(name)); |
883 | |
884 | for(i=1;i<Transport_Count;i++) |
885 | { |
886 | if(wayp->destination & TRANSPORTS(i)) |
887 | printf(" <tag k='%s' v='destination' />\n",TransportName(i)); |
888 | else if(wayp->allow & TRANSPORTS(i)) |
889 | printf(" <tag k='%s' v='yes' />\n",TransportName(i)); |
890 | } |
891 | |
892 | for(i=1;i<Property_Count;i++) |
893 | if(wayp->props & PROPERTIES(i)) |
894 | printf(" <tag k='%s' v='yes' />\n",PropertyName(i)); |
895 | |
896 | if(wayp->speed) |
897 | printf(" <tag k='maxspeed' v='%d' />\n",speed_to_kph(wayp->speed)); |
898 | |
899 | if(wayp->weight) |
900 | printf(" <tag k='maxweight' v='%.1f' />\n",weight_to_tonnes(wayp->weight)); |
901 | if(wayp->height) |
902 | printf(" <tag k='maxheight' v='%.1f' />\n",height_to_metres(wayp->height)); |
903 | if(wayp->width) |
904 | printf(" <tag k='maxwidth' v='%.1f' />\n",width_to_metres(wayp->width)); |
905 | if(wayp->length) |
906 | printf(" <tag k='maxlength' v='%.1f' />\n",length_to_metres(wayp->length)); |
907 | |
908 | printf(" </way>\n"); |
909 | } |
910 | |
911 | |
912 | /*++++++++++++++++++++++++++++++++++++++ |
913 | Print out the contents of a turn relation from the routing database (in OSM XML format). |
914 | |
915 | Relations *relations The set of relations to use. |
916 | |
917 | index_t item The relation index to print. |
918 | |
919 | Segments *segments The set of segments to use. |
920 | |
921 | Nodes *nodes The set of nodes to use. |
922 | ++++++++++++++++++++++++++++++++++++++*/ |
923 | |
924 | static void print_turn_relation_osm(Relations *relations,index_t item,Segments *segments,Nodes *nodes) |
925 | { |
926 | TurnRelation *relationp=LookupTurnRelation(relations,item,1); |
927 | |
928 | Segment *segmentp_from=LookupSegment(segments,relationp->from,1); |
929 | Segment *segmentp_to =LookupSegment(segments,relationp->to ,2); |
930 | |
931 | double angle=TurnAngle(nodes,segmentp_from,segmentp_to,relationp->via); |
932 | |
933 | char *restriction; |
934 | |
935 | if(angle>150 || angle<-150) |
936 | restriction="no_u_turn"; |
937 | else if(angle>30) |
938 | restriction="no_right_turn"; |
939 | else if(angle<-30) |
940 | restriction="no_left_turn"; |
941 | else |
942 | restriction="no_straight_on"; |
943 | |
944 | printf(" <relation id='%"Pindex_t"' version='1'>\n",item+1); |
945 | printf(" <tag k='type' v='restriction' />\n"); |
946 | printf(" <tag k='restriction' v='%s'/>\n",restriction); |
947 | |
948 | if(relationp->except) |
949 | printf(" <tag k='except' v='%s' />\n",AllowedNameList(relationp->except)); |
950 | |
951 | printf(" <member type='way' ref='%"Pindex_t"' role='from' />\n",relationp->from+1); |
952 | printf(" <member type='node' ref='%"Pindex_t"' role='via' />\n",relationp->via+1); |
953 | printf(" <member type='way' ref='%"Pindex_t"' role='to' />\n",relationp->to+1); |
954 | |
955 | printf(" </relation>\n"); |
956 | } |
957 | |
958 | |
959 | /*++++++++++++++++++++++++++++++++++++++ |
960 | Print out a tail in OSM XML format. |
961 | ++++++++++++++++++++++++++++++++++++++*/ |
962 | |
963 | static void print_tail_osm(void) |
964 | { |
965 | printf("</osm>\n"); |
966 | } |
967 | |
968 | |
969 | /*++++++++++++++++++++++++++++++++++++++ |
970 | Print out the contents of a node from the routing database (in visualiser format). |
971 | |
972 | Nodes *nodes The set of nodes to use. |
973 | |
974 | index_t item The node index to print. |
975 | ++++++++++++++++++++++++++++++++++++++*/ |
976 | |
977 | static void print_node_visualiser(Nodes *nodes,index_t item) |
978 | { |
979 | Node *nodep=LookupNode(nodes,item,1); |
980 | double latitude,longitude; |
981 | int i; |
982 | |
983 | GetLatLong(nodes,item,nodep,&latitude,&longitude); |
984 | |
985 | if(nodep->allow==Transports_ALL && nodep->destination==Transports_None && nodep->flags==0) |
986 | printf("<routino:node id='%"Pindex_t"' lat='%.7f' lon='%.7f' />\n",item+1,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
987 | else |
988 | { |
989 | printf("<routino:node id='%"Pindex_t"' lat='%.7f' lon='%.7f'>\n",item+1,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
990 | |
991 | if(nodep->flags & NODE_SUPER) |
992 | printf(" <tag k='routino:super' v='yes' />\n"); |
993 | |
994 | if(nodep->flags & NODE_UTURN) |
995 | printf(" <tag k='routino:uturn' v='yes' />\n"); |
996 | |
997 | if(nodep->flags & NODE_MINIRNDBT) |
998 | printf(" <tag k='junction' v='roundabout' />\n"); |
999 | |
1000 | if(nodep->flags & NODE_TURNRSTRCT) |
1001 | printf(" <tag k='routino:turnrestriction' v='yes' />\n"); |
1002 | |
1003 | for(i=1;i<Transport_Count;i++) |
1004 | { |
1005 | if(nodep->destination & TRANSPORTS(i)) |
1006 | printf(" <tag k='%s' v='destination' />\n",TransportName(i)); |
1007 | else if(!(nodep->allow & TRANSPORTS(i))) |
1008 | printf(" <tag k='%s' v='no' />\n",TransportName(i)); |
1009 | } |
1010 | |
1011 | printf("</routino:node>\n"); |
1012 | } |
1013 | } |
1014 | |
1015 | |
1016 | /*++++++++++++++++++++++++++++++++++++++ |
1017 | Print out the contents of a segment from the routing database (as a way in visualiser format). |
1018 | |
1019 | Segments *segments The set of segments to use. |
1020 | |
1021 | index_t item The segment index to print. |
1022 | |
1023 | Ways *ways The set of ways to use. |
1024 | ++++++++++++++++++++++++++++++++++++++*/ |
1025 | |
1026 | static void print_segment_visualiser(Segments *segments,index_t item,Ways *ways) |
1027 | { |
1028 | Segment *segmentp=LookupSegment(segments,item,1); |
1029 | Way *wayp=LookupWay(ways,segmentp->way,1); |
1030 | char *name=WayName(ways,wayp); |
1031 | int i; |
1032 | |
1033 | printf("<routino:way id='%"Pindex_t"'>\n",item+1); |
1034 | |
1035 | if(IsOnewayTo(segmentp,segmentp->node1)) |
1036 | { |
1037 | printf(" <nd ref='%"Pindex_t"' />\n",segmentp->node2+1); |
1038 | printf(" <nd ref='%"Pindex_t"' />\n",segmentp->node1+1); |
1039 | } |
1040 | else |
1041 | { |
1042 | printf(" <nd ref='%"Pindex_t"' />\n",segmentp->node1+1); |
1043 | printf(" <nd ref='%"Pindex_t"' />\n",segmentp->node2+1); |
1044 | } |
1045 | |
1046 | if(IsSuperSegment(segmentp)) |
1047 | printf(" <tag k='routino:super' v='yes' />\n"); |
1048 | if(IsNormalSegment(segmentp)) |
1049 | printf(" <tag k='routino:normal' v='yes' />\n"); |
1050 | |
1051 | printf(" <tag k='routino:distance' v='%.3f km' />\n",distance_to_km(DISTANCE(segmentp->distance))); |
1052 | |
1053 | if(wayp->type & Highway_OneWay) |
1054 | printf(" <tag k='oneway' v='yes' />\n"); |
1055 | |
1056 | if(wayp->type & Highway_CycleBothWays) |
1057 | printf(" <tag k='cyclebothways' v='yes' />\n"); |
1058 | |
1059 | if(wayp->type & Highway_Roundabout) |
1060 | printf(" <tag k='roundabout' v='yes' />\n"); |
1061 | |
1062 | printf(" <tag k='highway' v='%s' />\n",HighwayName(HIGHWAY(wayp->type))); |
1063 | |
1064 | if(IsNormalSegment(segmentp) && *name) |
1065 | printf(" <tag k='name' v='%s' />\n",ParseXML_Encode_Safe_XML(name)); |
1066 | |
1067 | for(i=1;i<Transport_Count;i++) |
1068 | if(wayp->destination & TRANSPORTS(i)) |
1069 | printf(" <tag k='%s' v='destination' />\n",TransportName(i)); |
1070 | else if(wayp->allow & TRANSPORTS(i)) |
1071 | printf(" <tag k='%s' v='yes' />\n",TransportName(i)); |
1072 | |
1073 | for(i=1;i<Property_Count;i++) |
1074 | if(wayp->props & PROPERTIES(i)) |
1075 | printf(" <tag k='%s' v='yes' />\n",PropertyName(i)); |
1076 | |
1077 | if(wayp->speed) |
1078 | printf(" <tag k='maxspeed' v='%d kph' />\n",speed_to_kph(wayp->speed)); |
1079 | |
1080 | if(wayp->weight) |
1081 | printf(" <tag k='maxweight' v='%.1f t' />\n",weight_to_tonnes(wayp->weight)); |
1082 | if(wayp->height) |
1083 | printf(" <tag k='maxheight' v='%.1f m' />\n",height_to_metres(wayp->height)); |
1084 | if(wayp->width) |
1085 | printf(" <tag k='maxwidth' v='%.1f m' />\n",width_to_metres(wayp->width)); |
1086 | if(wayp->length) |
1087 | printf(" <tag k='maxlength' v='%.1f m' />\n",length_to_metres(wayp->length)); |
1088 | |
1089 | printf("</routino:way>\n"); |
1090 | } |
1091 | |
1092 | |
1093 | /*++++++++++++++++++++++++++++++++++++++ |
1094 | Print out the contents of a turn relation from the routing database (in visualiser format). |
1095 | |
1096 | Relations *relations The set of relations to use. |
1097 | |
1098 | index_t item The relation index to print. |
1099 | |
1100 | Segments *segments The set of segments to use. |
1101 | |
1102 | Nodes *nodes The set of nodes to use. |
1103 | ++++++++++++++++++++++++++++++++++++++*/ |
1104 | |
1105 | static void print_turn_relation_visualiser(Relations *relations,index_t item,Segments *segments,Nodes *nodes) |
1106 | { |
1107 | TurnRelation *relationp=LookupTurnRelation(relations,item,1); |
1108 | |
1109 | Segment *segmentp_from=LookupSegment(segments,relationp->from,1); |
1110 | Segment *segmentp_to =LookupSegment(segments,relationp->to ,2); |
1111 | |
1112 | double angle=TurnAngle(nodes,segmentp_from,segmentp_to,relationp->via); |
1113 | |
1114 | char *restriction; |
1115 | |
1116 | if(angle>150 || angle<-150) |
1117 | restriction="no_u_turn"; |
1118 | else if(angle>30) |
1119 | restriction="no_right_turn"; |
1120 | else if(angle<-30) |
1121 | restriction="no_left_turn"; |
1122 | else |
1123 | restriction="no_straight_on"; |
1124 | |
1125 | printf("<routino:relation id='%"Pindex_t"'>\n",item+1); |
1126 | printf(" <tag k='type' v='restriction' />\n"); |
1127 | printf(" <tag k='restriction' v='%s'/>\n",restriction); |
1128 | |
1129 | if(relationp->except) |
1130 | printf(" <tag k='except' v='%s' />\n",AllowedNameList(relationp->except)); |
1131 | |
1132 | printf(" <member type='way' ref='%"Pindex_t"' role='from' />\n",relationp->from+1); |
1133 | printf(" <member type='node' ref='%"Pindex_t"' role='via' />\n",relationp->via+1); |
1134 | printf(" <member type='way' ref='%"Pindex_t"' role='to' />\n",relationp->to+1); |
1135 | |
1136 | printf("</routino:relation>\n"); |
1137 | } |
1138 | |
1139 | |
1140 | /*++++++++++++++++++++++++++++++++++++++ |
1141 | Print out an error log entry from the database (in visualiser format). |
1142 | |
1143 | ErrorLogs *errorlogs The set of error logs to use. |
1144 | |
1145 | index_t item The error log index to print. |
1146 | ++++++++++++++++++++++++++++++++++++++*/ |
1147 | |
1148 | static void print_errorlog_visualiser(ErrorLogs *errorlogs,index_t item) |
1149 | { |
1150 | char *string=LookupErrorLogString(errorlogs,item); |
1151 | |
1152 | printf("%s\n",ParseXML_Encode_Safe_XML(string)); |
1153 | } |
1154 | |
1155 | |
1156 | /*+ Conversion from time_t to date string (day of week). +*/ |
1157 | static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; |
1158 | |
1159 | /*+ Conversion from time_t to date string (month of year). +*/ |
1160 | static const char* const months[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; |
1161 | |
1162 | |
1163 | /*++++++++++++++++++++++++++++++++++++++ |
1164 | Convert the time into an RFC 822 compliant date. |
1165 | |
1166 | char *RFC822Date Returns a pointer to a fixed string containing the date. |
1167 | |
1168 | time_t t The time. |
1169 | ++++++++++++++++++++++++++++++++++++++*/ |
1170 | |
1171 | static char *RFC822Date(time_t t) |
1172 | { |
1173 | static char value[32]; |
1174 | char weekday[4]; |
1175 | char month[4]; |
1176 | struct tm *tim; |
1177 | |
1178 | tim=gmtime(&t); |
1179 | |
1180 | strcpy(weekday,weekdays[tim->tm_wday]); |
1181 | strcpy(month,months[tim->tm_mon]); |
1182 | |
1183 | /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */ |
1184 | |
1185 | sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s", |
1186 | weekday, |
1187 | tim->tm_mday, |
1188 | month, |
1189 | tim->tm_year+1900, |
1190 | tim->tm_hour, |
1191 | tim->tm_min, |
1192 | tim->tm_sec, |
1193 | "GMT" |
1194 | ); |
1195 | |
1196 | return(value); |
1197 | } |
1198 | |
1199 | |
1200 | /*++++++++++++++++++++++++++++++++++++++ |
1201 | Print out the usage information. |
1202 | |
1203 | int detail The level of detail to use - 0 = low, 1 = high. |
1204 | |
1205 | const char *argerr The argument that gave the error (if there is one). |
1206 | |
1207 | const char *err Other error message (if there is one). |
1208 | ++++++++++++++++++++++++++++++++++++++*/ |
1209 | |
1210 | static void print_usage(int detail,const char *argerr,const char *err) |
1211 | { |
1212 | fprintf(stderr, |
1213 | "Usage: filedumper [--help]\n" |
1214 | " [--dir=<dirname>] [--prefix=<name>]\n" |
1215 | " [--statistics]\n" |
1216 | " [--visualiser --latmin=<latmin> --latmax=<latmax>\n" |
1217 | " --lonmin=<lonmin> --lonmax=<lonmax>\n" |
1218 | " --data=<data-type>]\n" |
1219 | " [--dump [--node=<node> ...]\n" |
1220 | " [--segment=<segment> ...]\n" |
1221 | " [--way=<way> ...]\n" |
1222 | " [--turn-relation=<rel> ...]\n" |
1223 | " [--errorlog=<number> ...]]\n" |
1224 | " [--dump-osm [--no-super]\n" |
1225 | " [--latmin=<latmin> --latmax=<latmax>\n" |
1226 | " --lonmin=<lonmin> --lonmax=<lonmax>]]\n" |
1227 | " [--dump-visualiser [--data=node<node>]\n" |
1228 | " [--data=segment<segment>]\n" |
1229 | " [--data=turn-relation<rel>]\n" |
1230 | " [--data=errorlog<number>]]\n"); |
1231 | |
1232 | if(argerr) |
1233 | fprintf(stderr, |
1234 | "\n" |
1235 | "Error with command line parameter: %s\n",argerr); |
1236 | |
1237 | if(err) |
1238 | fprintf(stderr, |
1239 | "\n" |
1240 | "Error: %s\n",err); |
1241 | |
1242 | if(detail) |
1243 | fprintf(stderr, |
1244 | "\n" |
1245 | "--help Prints this information.\n" |
1246 | "\n" |
1247 | "--dir=<dirname> The directory containing the routing database.\n" |
1248 | "--prefix=<name> The filename prefix for the routing database.\n" |
1249 | "\n" |
1250 | "--statistics Print statistics about the routing database.\n" |
1251 | "\n" |
1252 | "--visualiser Extract selected data from the routing database:\n" |
1253 | " --latmin=<latmin> * the minimum latitude (degrees N).\n" |
1254 | " --latmax=<latmax> * the maximum latitude (degrees N).\n" |
1255 | " --lonmin=<lonmin> * the minimum longitude (degrees E).\n" |
1256 | " --lonmax=<lonmax> * the maximum longitude (degrees E).\n" |
1257 | " --data=<data-type> * the type of data to select.\n" |
1258 | "\n" |
1259 | " <data-type> can be selected from:\n" |
1260 | " junctions = segment count at each junction.\n" |
1261 | " super = super-node and super-segments.\n" |
1262 | " waytype-* = segments of oneway, cyclebothways or roundabout type.\n" |
1263 | " highway-* = segments of the specified highway type.\n" |
1264 | " transport-* = segments allowing the specified transport type.\n" |
1265 | " destination-* = segments allowing the specified transport type to\n" |
1266 | " destinations only (i.e. first and last waypoint).\n" |
1267 | " barrier-* = nodes disallowing the specified transport type.\n" |
1268 | " turns = turn restrictions.\n" |
1269 | " speed = speed limits.\n" |
1270 | " weight = weight limits.\n" |
1271 | " height = height limits.\n" |
1272 | " width = width limits.\n" |
1273 | " length = length limits.\n" |
1274 | " property-* = segments with the specified property.\n" |
1275 | " errorlogs = errors logged during parsing.\n" |
1276 | "\n" |
1277 | "--dump Dump selected contents of the database.\n" |
1278 | " --node=<node> * the node with the selected index.\n" |
1279 | " --segment=<segment> * the segment with the selected index.\n" |
1280 | " --way=<way> * the way with the selected index.\n" |
1281 | " --turn-relation=<rel> * the turn relation with the selected index.\n" |
1282 | " --errorlog=<number> * the error log with the selected index.\n" |
1283 | " Use 'all' instead of a number to get all of them.\n" |
1284 | "\n" |
1285 | "--dump-osm Dump all or part of the database as an XML file.\n" |
1286 | " --no-super * exclude the super-segments.\n" |
1287 | " --latmin=<latmin> * the minimum latitude (degrees N).\n" |
1288 | " --latmax=<latmax> * the maximum latitude (degrees N).\n" |
1289 | " --lonmin=<lonmin> * the minimum longitude (degrees E).\n" |
1290 | " --lonmax=<lonmax> * the maximum longitude (degrees E).\n" |
1291 | "\n" |
1292 | "--dump-visualiser Dump selected contents of the database in HTML.\n" |
1293 | " --data=node<node> * the node with the selected index.\n" |
1294 | " --data=segment<segment> * the segment with the selected index.\n" |
1295 | " --data=turn-relation<rel> * the turn relation with the selected index.\n" |
1296 | " --data=errorlog<number> * the error log with the selected index.\n"); |
1297 | |
1298 | exit(!detail); |
1299 | } |
Properties
Name | Value |
---|---|
cvs:description | Test program for mmap files. |