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