Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/filedumper.c
Parent Directory
|
Revision Log
Revision 1458 -
(hide annotations)
(download)
(as text)
Mon Jul 8 17:24:36 2013 UTC (11 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 45914 byte(s)
Mon Jul 8 17:24:36 2013 UTC (11 years, 9 months ago) by amb
File MIME type: text/x-csrc
File size: 45914 byte(s)
Fix typo in documentation string.
1 | amb | 2 | /*************************************** |
2 | Memory file dumper. | ||
3 | amb | 151 | |
4 | Part of the Routino routing software. | ||
5 | amb | 2 | ******************/ /****************** |
6 | amb | 1263 | This file Copyright 2008-2013 Andrew M. Bishop |
7 | amb | 2 | |
8 | amb | 151 | This program is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU Affero General Public License as published by | ||
10 | the Free Software Foundation, either version 3 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU Affero General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Affero General Public License | ||
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | amb | 2 | ***************************************/ |
21 | |||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | amb | 107 | #include <string.h> |
26 | amb | 185 | #include <sys/stat.h> |
27 | #include <sys/time.h> | ||
28 | #include <time.h> | ||
29 | amb | 669 | #include <math.h> |
30 | amb | 2 | |
31 | amb | 97 | #include "types.h" |
32 | #include "nodes.h" | ||
33 | #include "segments.h" | ||
34 | #include "ways.h" | ||
35 | amb | 542 | #include "relations.h" |
36 | amb | 1321 | #include "errorlog.h" |
37 | amb | 449 | |
38 | #include "files.h" | ||
39 | #include "visualiser.h" | ||
40 | amb | 405 | #include "xmlparse.h" |
41 | amb | 2 | |
42 | amb | 405 | |
43 | amb | 185 | /* Local functions */ |
44 | amb | 2 | |
45 | amb | 681 | static void print_node(Nodes *nodes,index_t item); |
46 | amb | 202 | static void print_segment(Segments *segments,index_t item); |
47 | static void print_way(Ways *ways,index_t item); | ||
48 | amb | 1150 | static void print_turn_relation(Relations *relations,index_t item,Segments *segments,Nodes *nodes); |
49 | amb | 1321 | static void print_errorlog(ErrorLogs *errorlogs,index_t item); |
50 | amb | 185 | |
51 | amb | 917 | static void print_head_osm(int coordcount,double latmin,double latmax,double lonmin,double lonmax); |
52 | amb | 918 | 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 | amb | 681 | static void print_node_osm(Nodes *nodes,index_t item); |
55 | amb | 405 | static void print_segment_osm(Segments *segments,index_t item,Ways *ways); |
56 | amb | 1150 | static void print_turn_relation_osm(Relations *relations,index_t item,Segments *segments,Nodes *nodes); |
57 | amb | 405 | static void print_tail_osm(void); |
58 | |||
59 | amb | 1330 | 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 | amb | 405 | static char *RFC822Date(time_t t); |
65 | |||
66 | amb | 490 | static void print_usage(int detail,const char *argerr,const char *err); |
67 | amb | 342 | |
68 | |||
69 | /*++++++++++++++++++++++++++++++++++++++ | ||
70 | amb | 405 | The main program for the file dumper. |
71 | amb | 342 | ++++++++++++++++++++++++++++++++++++++*/ |
72 | |||
73 | amb | 2 | int main(int argc,char** argv) |
74 | { | ||
75 | amb | 26 | Nodes *OSMNodes; |
76 | amb | 66 | Segments *OSMSegments; |
77 | amb | 26 | Ways *OSMWays; |
78 | amb | 542 | Relations*OSMRelations; |
79 | amb | 1321 | ErrorLogs*OSMErrorLogs=NULL; |
80 | amb | 405 | int arg; |
81 | char *dirname=NULL,*prefix=NULL; | ||
82 | amb | 1321 | char *nodes_filename,*segments_filename,*ways_filename,*relations_filename,*errorlogs_filename; |
83 | amb | 405 | 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 | amb | 413 | int option_dump_osm=0,option_no_super=0; |
89 | amb | 1330 | int option_dump_visualiser=0; |
90 | amb | 13 | |
91 | amb | 107 | /* Parse the command line arguments */ |
92 | |||
93 | amb | 202 | for(arg=1;arg<argc;arg++) |
94 | amb | 107 | { |
95 | amb | 202 | if(!strcmp(argv[arg],"--help")) |
96 | amb | 490 | print_usage(1,NULL,NULL); |
97 | amb | 202 | 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 | amb | 405 | else if(!strcmp(argv[arg],"--statistics")) |
102 | amb | 185 | option_statistics=1; |
103 | amb | 405 | else if(!strcmp(argv[arg],"--visualiser")) |
104 | amb | 185 | option_visualiser=1; |
105 | amb | 405 | else if(!strcmp(argv[arg],"--dump")) |
106 | amb | 202 | option_dump=1; |
107 | amb | 405 | else if(!strcmp(argv[arg],"--dump-osm")) |
108 | option_dump_osm=1; | ||
109 | amb | 1330 | else if(!strcmp(argv[arg],"--dump-visualiser")) |
110 | option_dump_visualiser=1; | ||
111 | amb | 202 | 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 | amb | 413 | else if(!strcmp(argv[arg],"--no-super")) |
122 | option_no_super=1; | ||
123 | amb | 202 | 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 | amb | 565 | else if(!strncmp(argv[arg],"--turn-relation=",16)) |
130 | ; | ||
131 | amb | 1321 | else if(!strncmp(argv[arg],"--errorlog=",11)) |
132 | ; | ||
133 | amb | 107 | else |
134 | amb | 490 | print_usage(0,argv[arg],NULL); |
135 | amb | 107 | } |
136 | |||
137 | amb | 1330 | 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 | amb | 2 | |
140 | amb | 329 | /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */ |
141 | amb | 2 | |
142 | amb | 185 | OSMNodes=LoadNodeList(nodes_filename=FileName(dirname,prefix,"nodes.mem")); |
143 | amb | 6 | |
144 | amb | 185 | OSMSegments=LoadSegmentList(segments_filename=FileName(dirname,prefix,"segments.mem")); |
145 | amb | 99 | |
146 | amb | 185 | OSMWays=LoadWayList(ways_filename=FileName(dirname,prefix,"ways.mem")); |
147 | amb | 66 | |
148 | amb | 542 | OSMRelations=LoadRelationList(relations_filename=FileName(dirname,prefix,"relations.mem")); |
149 | |||
150 | amb | 1321 | if(ExistsFile(errorlogs_filename=FileName(dirname,prefix,"errorlogs.mem"))) |
151 | OSMErrorLogs=LoadErrorLogs(errorlogs_filename); | ||
152 | else | ||
153 | errorlogs_filename=NULL; | ||
154 | |||
155 | amb | 185 | /* Write out the visualiser data */ |
156 | amb | 66 | |
157 | amb | 185 | if(option_visualiser) |
158 | { | ||
159 | amb | 1003 | Highway highway; |
160 | amb | 1002 | Transport transport; |
161 | amb | 1248 | Property property; |
162 | amb | 1002 | |
163 | amb | 185 | if(coordcount!=4) |
164 | amb | 490 | print_usage(0,NULL,"The --visualiser option must have --latmin, --latmax, --lonmin, --lonmax.\n"); |
165 | amb | 66 | |
166 | amb | 185 | if(!option_data) |
167 | amb | 490 | print_usage(0,NULL,"The --visualiser option must have --data.\n"); |
168 | amb | 2 | |
169 | amb | 185 | if(!strcmp(option_data,"junctions")) |
170 | amb | 623 | OutputJunctions(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
171 | amb | 185 | else if(!strcmp(option_data,"super")) |
172 | amb | 623 | OutputSuper(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
173 | amb | 185 | else if(!strcmp(option_data,"oneway")) |
174 | amb | 623 | OutputOneway(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
175 | amb | 1174 | else if(!strncmp(option_data,"highway",7) && option_data[7]=='-' && (highway=HighwayType(option_data+8))!=Highway_None) |
176 | amb | 1003 | OutputHighway(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,highway); |
177 | amb | 1002 | 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 | amb | 1077 | 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 | amb | 623 | else if(!strcmp(option_data,"turns")) |
182 | OutputTurnRestrictions(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); | ||
183 | amb | 185 | else if(!strcmp(option_data,"speed")) |
184 | amb | 623 | OutputSpeedLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
185 | amb | 185 | else if(!strcmp(option_data,"weight")) |
186 | amb | 623 | OutputWeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
187 | amb | 185 | else if(!strcmp(option_data,"height")) |
188 | amb | 623 | OutputHeightLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
189 | amb | 185 | else if(!strcmp(option_data,"width")) |
190 | amb | 623 | OutputWidthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
191 | amb | 185 | else if(!strcmp(option_data,"length")) |
192 | amb | 623 | OutputLengthLimits(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax); |
193 | amb | 1248 | 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 | amb | 1321 | else if(!strcmp(option_data,"errorlogs")) |
196 | OutputErrorLog(OSMErrorLogs,latmin,latmax,lonmin,lonmax); | ||
197 | amb | 185 | else |
198 | amb | 490 | print_usage(0,option_data,NULL); |
199 | amb | 185 | } |
200 | amb | 6 | |
201 | amb | 185 | /* Print out statistics */ |
202 | amb | 6 | |
203 | amb | 185 | if(option_statistics) |
204 | { | ||
205 | struct stat buf; | ||
206 | amb | 6 | |
207 | amb | 185 | /* Examine the files */ |
208 | |||
209 | printf("Files\n"); | ||
210 | printf("-----\n"); | ||
211 | printf("\n"); | ||
212 | |||
213 | stat(nodes_filename,&buf); | ||
214 | |||
215 | amb | 1235 | printf("'%s%snodes.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size); |
216 | amb | 185 | printf("%s\n",RFC822Date(buf.st_mtime)); |
217 | printf("\n"); | ||
218 | |||
219 | stat(segments_filename,&buf); | ||
220 | |||
221 | amb | 1235 | printf("'%s%ssegments.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size); |
222 | amb | 185 | printf("%s\n",RFC822Date(buf.st_mtime)); |
223 | printf("\n"); | ||
224 | |||
225 | stat(ways_filename,&buf); | ||
226 | |||
227 | amb | 1235 | printf("'%s%sways.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size); |
228 | amb | 185 | printf("%s\n",RFC822Date(buf.st_mtime)); |
229 | printf("\n"); | ||
230 | |||
231 | amb | 625 | stat(relations_filename,&buf); |
232 | |||
233 | amb | 1235 | printf("'%s%srelations.mem' - %9"PRIu64" Bytes\n",prefix?prefix:"",prefix?"-":"",(uint64_t)buf.st_size); |
234 | amb | 625 | printf("%s\n",RFC822Date(buf.st_mtime)); |
235 | printf("\n"); | ||
236 | |||
237 | amb | 1321 | 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 | amb | 185 | /* Examine the nodes */ |
247 | |||
248 | printf("Nodes\n"); | ||
249 | printf("-----\n"); | ||
250 | printf("\n"); | ||
251 | |||
252 | amb | 879 | 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 | amb | 185 | printf("\n"); |
256 | |||
257 | amb | 879 | printf("Lat bins= %4d\n",(int)OSMNodes->file.latbins); |
258 | printf("Lon bins= %4d\n",(int)OSMNodes->file.lonbins); | ||
259 | amb | 185 | printf("\n"); |
260 | |||
261 | amb | 879 | printf("Lat zero=%5d (%8.4f deg)\n",(int)OSMNodes->file.latzero,radians_to_degrees(latlong_to_radians(bin_to_latlong(OSMNodes->file.latzero)))); |
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 | amb | 185 | |
264 | /* Examine the segments */ | ||
265 | |||
266 | printf("\n"); | ||
267 | printf("Segments\n"); | ||
268 | printf("--------\n"); | ||
269 | printf("\n"); | ||
270 | |||
271 | amb | 879 | 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 | amb | 185 | |
276 | /* Examine the ways */ | ||
277 | |||
278 | printf("\n"); | ||
279 | printf("Ways\n"); | ||
280 | printf("----\n"); | ||
281 | printf("\n"); | ||
282 | |||
283 | amb | 1103 | printf("sizeof(Way)=%9lu Bytes\n",(unsigned long)sizeof(Way)); |
284 | printf("Number =%9"Pindex_t"\n",OSMWays->file.number); | ||
285 | amb | 202 | printf("\n"); |
286 | |||
287 | amb | 628 | stat(ways_filename,&buf); |
288 | amb | 1103 | printf("Total names=%9lu Bytes\n",(unsigned long)buf.st_size-(unsigned long)sizeof(Ways)-(unsigned long)OSMWays->file.number*(unsigned long)sizeof(Way)); |
289 | amb | 307 | printf("\n"); |
290 | |||
291 | amb | 526 | printf("Included highways : %s\n",HighwaysNameList(OSMWays->file.highways)); |
292 | amb | 460 | printf("Included transports: %s\n",AllowedNameList(OSMWays->file.allow)); |
293 | printf("Included properties: %s\n",PropertiesNameList(OSMWays->file.props)); | ||
294 | amb | 565 | |
295 | /* Examine the relations */ | ||
296 | |||
297 | printf("\n"); | ||
298 | printf("Relations\n"); | ||
299 | printf("---------\n"); | ||
300 | printf("\n"); | ||
301 | |||
302 | amb | 879 | printf("sizeof(TurnRelation)=%9lu Bytes\n",(unsigned long)sizeof(TurnRelation)); |
303 | printf("Number =%9"Pindex_t"\n",OSMRelations->file.trnumber); | ||
304 | amb | 1321 | |
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 | amb | 185 | } |
325 | |||
326 | amb | 680 | /* Print out internal data (in plain text format) */ |
327 | amb | 202 | |
328 | if(option_dump) | ||
329 | { | ||
330 | index_t item; | ||
331 | |||
332 | for(arg=1;arg<argc;arg++) | ||
333 | amb | 254 | if(!strcmp(argv[arg],"--node=all")) |
334 | amb | 202 | { |
335 | amb | 453 | for(item=0;item<OSMNodes->file.number;item++) |
336 | amb | 254 | print_node(OSMNodes,item); |
337 | } | ||
338 | else if(!strncmp(argv[arg],"--node=",7)) | ||
339 | { | ||
340 | amb | 202 | item=atoi(&argv[arg][7]); |
341 | |||
342 | amb | 1305 | if(item<OSMNodes->file.number) |
343 | amb | 301 | print_node(OSMNodes,item); |
344 | else | ||
345 | amb | 790 | printf("Invalid node number; minimum=0, maximum=%"Pindex_t".\n",OSMNodes->file.number-1); |
346 | amb | 202 | } |
347 | amb | 254 | else if(!strcmp(argv[arg],"--segment=all")) |
348 | { | ||
349 | amb | 459 | for(item=0;item<OSMSegments->file.number;item++) |
350 | amb | 254 | print_segment(OSMSegments,item); |
351 | } | ||
352 | amb | 202 | else if(!strncmp(argv[arg],"--segment=",10)) |
353 | { | ||
354 | item=atoi(&argv[arg][10]); | ||
355 | |||
356 | amb | 1305 | if(item<OSMSegments->file.number) |
357 | amb | 301 | print_segment(OSMSegments,item); |
358 | else | ||
359 | amb | 790 | printf("Invalid segment number; minimum=0, maximum=%"Pindex_t".\n",OSMSegments->file.number-1); |
360 | amb | 202 | } |
361 | amb | 254 | else if(!strcmp(argv[arg],"--way=all")) |
362 | { | ||
363 | amb | 460 | for(item=0;item<OSMWays->file.number;item++) |
364 | amb | 254 | print_way(OSMWays,item); |
365 | } | ||
366 | amb | 202 | else if(!strncmp(argv[arg],"--way=",6)) |
367 | { | ||
368 | item=atoi(&argv[arg][6]); | ||
369 | |||
370 | amb | 1305 | if(item<OSMWays->file.number) |
371 | amb | 301 | print_way(OSMWays,item); |
372 | else | ||
373 | amb | 790 | printf("Invalid way number; minimum=0, maximum=%"Pindex_t".\n",OSMWays->file.number-1); |
374 | amb | 202 | } |
375 | amb | 565 | else if(!strcmp(argv[arg],"--turn-relation=all")) |
376 | { | ||
377 | for(item=0;item<OSMRelations->file.trnumber;item++) | ||
378 | amb | 1150 | print_turn_relation(OSMRelations,item,OSMSegments,OSMNodes); |
379 | amb | 565 | } |
380 | else if(!strncmp(argv[arg],"--turn-relation=",16)) | ||
381 | { | ||
382 | amb | 626 | item=atoi(&argv[arg][16]); |
383 | amb | 565 | |
384 | amb | 1305 | if(item<OSMRelations->file.trnumber) |
385 | amb | 1150 | print_turn_relation(OSMRelations,item,OSMSegments,OSMNodes); |
386 | amb | 565 | else |
387 | amb | 790 | printf("Invalid turn relation number; minimum=0, maximum=%"Pindex_t".\n",OSMRelations->file.trnumber-1); |
388 | amb | 565 | } |
389 | amb | 1321 | 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 | amb | 202 | } |
404 | |||
405 | amb | 680 | /* Print out internal data (in OSM XML format) */ |
406 | amb | 405 | |
407 | if(option_dump_osm) | ||
408 | { | ||
409 | amb | 413 | if(coordcount>0 && coordcount!=4) |
410 | amb | 490 | print_usage(0,NULL,"The --dump-osm option must have all of --latmin, --latmax, --lonmin, --lonmax or none.\n"); |
411 | amb | 405 | |
412 | amb | 917 | print_head_osm(coordcount,latmin,latmax,lonmin,lonmax); |
413 | amb | 405 | |
414 | amb | 413 | if(coordcount) |
415 | amb | 918 | print_region_osm(OSMNodes,OSMSegments,OSMWays,OSMRelations,latmin,latmax,lonmin,lonmax,option_no_super); |
416 | amb | 413 | else |
417 | { | ||
418 | index_t item; | ||
419 | |||
420 | amb | 453 | for(item=0;item<OSMNodes->file.number;item++) |
421 | amb | 413 | print_node_osm(OSMNodes,item); |
422 | |||
423 | amb | 459 | for(item=0;item<OSMSegments->file.number;item++) |
424 | if(!option_no_super || IsNormalSegment(LookupSegment(OSMSegments,item,1))) | ||
425 | amb | 413 | print_segment_osm(OSMSegments,item,OSMWays); |
426 | amb | 565 | |
427 | for(item=0;item<OSMRelations->file.trnumber;item++) | ||
428 | amb | 1150 | print_turn_relation_osm(OSMRelations,item,OSMSegments,OSMNodes); |
429 | amb | 413 | } |
430 | |||
431 | amb | 405 | print_tail_osm(); |
432 | } | ||
433 | |||
434 | amb | 1330 | /* 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 | amb | 2 | return(0); |
483 | } | ||
484 | amb | 185 | |
485 | |||
486 | amb | 202 | /*++++++++++++++++++++++++++++++++++++++ |
487 | amb | 680 | Print out the contents of a node from the routing database (as plain text). |
488 | amb | 202 | |
489 | Nodes *nodes The set of nodes to use. | ||
490 | |||
491 | index_t item The node index to print. | ||
492 | ++++++++++++++++++++++++++++++++++++++*/ | ||
493 | |||
494 | amb | 681 | static void print_node(Nodes *nodes,index_t item) |
495 | amb | 202 | { |
496 | amb | 1078 | Node *nodep=LookupNode(nodes,item,1); |
497 | amb | 219 | double latitude,longitude; |
498 | amb | 202 | |
499 | amb | 1291 | GetLatLong(nodes,item,nodep,&latitude,&longitude); |
500 | amb | 202 | |
501 | amb | 790 | printf("Node %"Pindex_t"\n",item); |
502 | amb | 1078 | 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 | amb | 202 | printf(" Super-Node\n"); |
507 | amb | 1263 | if(nodep->flags & NODE_MINIRNDBT) |
508 | printf(" Mini-roundabout\n"); | ||
509 | amb | 202 | } |
510 | |||
511 | |||
512 | /*++++++++++++++++++++++++++++++++++++++ | ||
513 | amb | 680 | Print out the contents of a segment from the routing database (as plain text). |
514 | amb | 202 | |
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 | amb | 1078 | Segment *segmentp=LookupSegment(segments,item,1); |
523 | amb | 202 | |
524 | amb | 790 | printf("Segment %"Pindex_t"\n",item); |
525 | amb | 1078 | 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 | amb | 1168 | printf(" distance=%d (%.3f km)\n",DISTANCE(segmentp->distance),distance_to_km(DISTANCE(segmentp->distance))); |
529 | amb | 1078 | if(IsSuperSegment(segmentp) && IsNormalSegment(segmentp)) |
530 | amb | 202 | printf(" Super-Segment AND normal Segment\n"); |
531 | amb | 1078 | else if(IsSuperSegment(segmentp) && !IsNormalSegment(segmentp)) |
532 | amb | 202 | printf(" Super-Segment\n"); |
533 | amb | 1078 | if(IsOnewayTo(segmentp,segmentp->node1)) |
534 | amb | 202 | printf(" One-Way from node2 to node1\n"); |
535 | amb | 1078 | if(IsOnewayTo(segmentp,segmentp->node2)) |
536 | amb | 202 | printf(" One-Way from node1 to node2\n"); |
537 | } | ||
538 | |||
539 | |||
540 | /*++++++++++++++++++++++++++++++++++++++ | ||
541 | amb | 680 | Print out the contents of a way from the routing database (as plain text). |
542 | amb | 202 | |
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 | amb | 1078 | Way *wayp=LookupWay(ways,item,1); |
551 | char *name=WayName(ways,wayp); | ||
552 | amb | 202 | |
553 | amb | 790 | printf("Way %"Pindex_t"\n",item); |
554 | amb | 705 | if(*name) |
555 | printf(" name=%s\n",name); | ||
556 | amb | 1174 | 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 | amb | 1078 | 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 | amb | 202 | } |
571 | |||
572 | |||
573 | amb | 405 | /*++++++++++++++++++++++++++++++++++++++ |
574 | amb | 680 | Print out the contents of a turn relation from the routing database (as plain text). |
575 | amb | 565 | |
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 | amb | 1150 | static void print_turn_relation(Relations *relations,index_t item,Segments *segments,Nodes *nodes) |
586 | amb | 565 | { |
587 | amb | 1078 | Segment *segmentp; |
588 | TurnRelation *relationp=LookupTurnRelation(relations,item,1); | ||
589 | Node *nodep=LookupNode(nodes,relationp->via,1); | ||
590 | amb | 565 | index_t from_way=NO_WAY,to_way=NO_WAY; |
591 | amb | 599 | index_t from_node=NO_NODE,to_node=NO_NODE; |
592 | amb | 565 | |
593 | amb | 1078 | segmentp=FirstSegment(segments,nodep,1); |
594 | amb | 565 | |
595 | do | ||
596 | { | ||
597 | amb | 1078 | index_t seg=IndexSegment(segments,segmentp); |
598 | amb | 565 | |
599 | amb | 1078 | if(seg==relationp->from) |
600 | amb | 599 | { |
601 | amb | 1078 | from_node=OtherNode(segmentp,relationp->from); |
602 | from_way=segmentp->way; | ||
603 | amb | 599 | } |
604 | amb | 565 | |
605 | amb | 1078 | if(seg==relationp->to) |
606 | amb | 599 | { |
607 | amb | 1078 | to_node=OtherNode(segmentp,relationp->to); |
608 | to_way=segmentp->way; | ||
609 | amb | 599 | } |
610 | |||
611 | amb | 1078 | segmentp=NextSegment(segments,segmentp,relationp->via); |
612 | amb | 565 | } |
613 | amb | 1078 | while(segmentp); |
614 | amb | 565 | |
615 | amb | 790 | printf("Relation %"Pindex_t"\n",item); |
616 | amb | 1078 | 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 | amb | 565 | } |
622 | |||
623 | |||
624 | /*++++++++++++++++++++++++++++++++++++++ | ||
625 | amb | 1321 | 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 | amb | 405 | Print out a header in OSM XML format. |
655 | amb | 918 | |
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 | amb | 405 | ++++++++++++++++++++++++++++++++++++++*/ |
666 | |||
667 | amb | 917 | static void print_head_osm(int coordcount,double latmin,double latmax,double lonmin,double lonmax) |
668 | amb | 405 | { |
669 | printf("<?xml version='1.0' encoding='UTF-8'?>\n"); | ||
670 | amb | 847 | printf("<osm version='0.6' generator='Routino'>\n"); |
671 | amb | 917 | |
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 | amb | 405 | } |
676 | |||
677 | |||
678 | /*++++++++++++++++++++++++++++++++++++++ | ||
679 | amb | 918 | 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 | amb | 1078 | 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 | amb | 918 | |
734 | if(lat>latmin && lat<latmax && lon>lonmin && lon<lonmax) | ||
735 | { | ||
736 | amb | 1078 | Segment *segmentp; |
737 | amb | 918 | |
738 | print_node_osm(nodes,item); | ||
739 | |||
740 | amb | 1078 | segmentp=FirstSegment(segments,nodep,1); |
741 | amb | 918 | |
742 | amb | 1078 | while(segmentp) |
743 | amb | 918 | { |
744 | double olat,olon; | ||
745 | amb | 1078 | index_t oitem=OtherNode(segmentp,item); |
746 | amb | 918 | |
747 | amb | 1291 | GetLatLong(nodes,oitem,NULL,&olat,&olon); |
748 | amb | 918 | |
749 | if(olat>latmin && olat<latmax && olon>lonmin && olon<lonmax) | ||
750 | if(item>oitem) | ||
751 | amb | 1078 | if(!option_no_super || IsNormalSegment(segmentp)) |
752 | print_segment_osm(segments,IndexSegment(segments,segmentp),ways); | ||
753 | amb | 918 | |
754 | amb | 1078 | segmentp=NextSegment(segments,segmentp,item); |
755 | amb | 918 | } |
756 | |||
757 | amb | 1078 | if(IsTurnRestrictedNode(nodep)) |
758 | amb | 918 | { |
759 | index_t relindex=FindFirstTurnRelation1(relations,item); | ||
760 | |||
761 | while(relindex!=NO_RELATION) | ||
762 | { | ||
763 | amb | 1150 | print_turn_relation_osm(relations,relindex,segments,nodes); |
764 | amb | 918 | |
765 | relindex=FindNextTurnRelation1(relations,relindex); | ||
766 | } | ||
767 | } | ||
768 | } | ||
769 | } | ||
770 | } | ||
771 | } | ||
772 | |||
773 | |||
774 | /*++++++++++++++++++++++++++++++++++++++ | ||
775 | amb | 680 | Print out the contents of a node from the routing database (in OSM XML format). |
776 | amb | 405 | |
777 | Nodes *nodes The set of nodes to use. | ||
778 | |||
779 | index_t item The node index to print. | ||
780 | ++++++++++++++++++++++++++++++++++++++*/ | ||
781 | |||
782 | amb | 681 | static void print_node_osm(Nodes *nodes,index_t item) |
783 | amb | 405 | { |
784 | amb | 1078 | Node *nodep=LookupNode(nodes,item,1); |
785 | amb | 405 | double latitude,longitude; |
786 | amb | 537 | int i; |
787 | amb | 405 | |
788 | amb | 1291 | GetLatLong(nodes,item,nodep,&latitude,&longitude); |
789 | amb | 405 | |
790 | amb | 1078 | if(nodep->allow==Transports_ALL && nodep->flags==0) |
791 | amb | 537 | printf(" <node id='%lu' lat='%.7f' lon='%.7f' version='1' />\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
792 | else | ||
793 | amb | 405 | { |
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 | amb | 469 | |
796 | amb | 1078 | if(nodep->flags & NODE_SUPER) |
797 | amb | 537 | printf(" <tag k='routino:super' v='yes' />\n"); |
798 | |||
799 | amb | 1078 | if(nodep->flags & NODE_UTURN) |
800 | amb | 667 | printf(" <tag k='routino:uturn' v='yes' />\n"); |
801 | |||
802 | amb | 1078 | if(nodep->flags & NODE_MINIRNDBT) |
803 | amb | 1263 | printf(" <tag k='junction' v='roundabout' />\n"); |
804 | amb | 537 | |
805 | amb | 1078 | if(nodep->flags & NODE_TURNRSTRCT) |
806 | amb | 667 | printf(" <tag k='routino:turnrestriction' v='yes' />\n"); |
807 | |||
808 | amb | 469 | for(i=1;i<Transport_Count;i++) |
809 | amb | 1078 | if(!(nodep->allow & TRANSPORTS(i))) |
810 | amb | 470 | printf(" <tag k='%s' v='no' />\n",TransportName(i)); |
811 | amb | 469 | |
812 | amb | 405 | printf(" </node>\n"); |
813 | } | ||
814 | } | ||
815 | |||
816 | |||
817 | /*++++++++++++++++++++++++++++++++++++++ | ||
818 | amb | 680 | Print out the contents of a segment from the routing database (as a way in OSM XML format). |
819 | amb | 405 | |
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 | amb | 1078 | Segment *segmentp=LookupSegment(segments,item,1); |
830 | Way *wayp=LookupWay(ways,segmentp->way,1); | ||
831 | char *name=WayName(ways,wayp); | ||
832 | amb | 405 | int i; |
833 | |||
834 | printf(" <way id='%lu' version='1'>\n",(unsigned long)item+1); | ||
835 | |||
836 | amb | 1078 | if(IsOnewayTo(segmentp,segmentp->node1)) |
837 | amb | 405 | { |
838 | amb | 1078 | printf(" <nd ref='%lu' />\n",(unsigned long)segmentp->node2+1); |
839 | printf(" <nd ref='%lu' />\n",(unsigned long)segmentp->node1+1); | ||
840 | amb | 405 | } |
841 | else | ||
842 | { | ||
843 | amb | 1078 | printf(" <nd ref='%lu' />\n",(unsigned long)segmentp->node1+1); |
844 | printf(" <nd ref='%lu' />\n",(unsigned long)segmentp->node2+1); | ||
845 | amb | 405 | } |
846 | |||
847 | amb | 1078 | if(IsSuperSegment(segmentp)) |
848 | amb | 405 | printf(" <tag k='routino:super' v='yes' />\n"); |
849 | amb | 1078 | if(IsNormalSegment(segmentp)) |
850 | amb | 405 | printf(" <tag k='routino:normal' v='yes' />\n"); |
851 | |||
852 | amb | 1168 | printf(" <tag k='routino:distance' v='%.3f' />\n",distance_to_km(DISTANCE(segmentp->distance))); |
853 | amb | 667 | |
854 | amb | 1174 | if(wayp->type & Highway_OneWay) |
855 | amb | 405 | printf(" <tag k='oneway' v='yes' />\n"); |
856 | |||
857 | amb | 1174 | if(wayp->type & Highway_Roundabout) |
858 | amb | 923 | printf(" <tag k='roundabout' v='yes' />\n"); |
859 | |||
860 | amb | 1078 | printf(" <tag k='highway' v='%s' />\n",HighwayName(HIGHWAY(wayp->type))); |
861 | amb | 405 | |
862 | amb | 1078 | if(IsNormalSegment(segmentp) && *name) |
863 | amb | 705 | printf(" <tag k='name' v='%s' />\n",ParseXML_Encode_Safe_XML(name)); |
864 | amb | 405 | |
865 | for(i=1;i<Transport_Count;i++) | ||
866 | amb | 1078 | if(wayp->allow & TRANSPORTS(i)) |
867 | amb | 405 | printf(" <tag k='%s' v='yes' />\n",TransportName(i)); |
868 | |||
869 | for(i=1;i<Property_Count;i++) | ||
870 | amb | 1078 | if(wayp->props & PROPERTIES(i)) |
871 | amb | 405 | printf(" <tag k='%s' v='yes' />\n",PropertyName(i)); |
872 | |||
873 | amb | 1078 | if(wayp->speed) |
874 | printf(" <tag k='maxspeed' v='%d' />\n",speed_to_kph(wayp->speed)); | ||
875 | amb | 405 | |
876 | amb | 1078 | 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 | amb | 405 | |
885 | printf(" </way>\n"); | ||
886 | } | ||
887 | |||
888 | |||
889 | /*++++++++++++++++++++++++++++++++++++++ | ||
890 | amb | 680 | Print out the contents of a turn relation from the routing database (in OSM XML format). |
891 | amb | 565 | |
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 | amb | 1150 | static void print_turn_relation_osm(Relations *relations,index_t item,Segments *segments,Nodes *nodes) |
902 | amb | 565 | { |
903 | amb | 1078 | TurnRelation *relationp=LookupTurnRelation(relations,item,1); |
904 | amb | 565 | |
905 | amb | 1078 | Segment *segmentp_from=LookupSegment(segments,relationp->from,1); |
906 | Segment *segmentp_to =LookupSegment(segments,relationp->to ,2); | ||
907 | amb | 618 | |
908 | amb | 1078 | double angle=TurnAngle(nodes,segmentp_from,segmentp_to,relationp->via); |
909 | amb | 618 | |
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 | amb | 565 | printf(" <relation id='%lu' version='1'>\n",(unsigned long)item+1); |
922 | printf(" <tag k='type' v='restriction' />\n"); | ||
923 | amb | 618 | printf(" <tag k='restriction' v='%s'/>\n",restriction); |
924 | amb | 565 | |
925 | amb | 1078 | if(relationp->except) |
926 | printf(" <tag k='except' v='%s' />\n",AllowedNameList(relationp->except)); | ||
927 | amb | 565 | |
928 | amb | 1078 | 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 | amb | 565 | |
932 | printf(" </relation>\n"); | ||
933 | } | ||
934 | |||
935 | |||
936 | /*++++++++++++++++++++++++++++++++++++++ | ||
937 | amb | 405 | 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 | amb | 1330 | /*++++++++++++++++++++++++++++++++++++++ |
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 | amb | 1433 | printf("<routino:node id='%lu' lat='%.7f' lon='%.7f' />\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
964 | amb | 1330 | else |
965 | { | ||
966 | amb | 1433 | printf("<routino:node id='%lu' lat='%.7f' lon='%.7f'>\n",(unsigned long)item+1,radians_to_degrees(latitude),radians_to_degrees(longitude)); |
967 | amb | 1330 | |
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 | amb | 1433 | printf("</routino:node>\n"); |
985 | amb | 1330 | } |
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 | amb | 1433 | printf("<routino:way id='%lu'>\n",(unsigned long)item+1); |
1007 | amb | 1330 | |
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 | amb | 1433 | printf("</routino:way>\n"); |
1058 | amb | 1330 | } |
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 | amb | 1433 | printf("<routino:relation id='%lu'>\n",(unsigned long)item+1); |
1094 | amb | 1330 | 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 | amb | 1433 | printf("</routino:relation>\n"); |
1105 | amb | 1330 | } |
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 | amb | 405 | /*+ Conversion from time_t to date string (day of week). +*/ |
1125 | amb | 185 | static const char* const weekdays[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; |
1126 | |||
1127 | amb | 405 | /*+ Conversion from time_t to date string (month of year). +*/ |
1128 | amb | 185 | 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 | amb | 342 | |
1167 | |||
1168 | /*++++++++++++++++++++++++++++++++++++++ | ||
1169 | Print out the usage information. | ||
1170 | |||
1171 | int detail The level of detail to use - 0 = low, 1 = high. | ||
1172 | amb | 490 | |
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 | amb | 342 | ++++++++++++++++++++++++++++++++++++++*/ |
1177 | |||
1178 | amb | 490 | static void print_usage(int detail,const char *argerr,const char *err) |
1179 | amb | 342 | { |
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 | amb | 1150 | " [--way=<way> ...]\n" |
1190 | amb | 1330 | " [--turn-relation=<rel> ...]\n" |
1191 | " [--errorlog=<number> ...]]\n" | ||
1192 | amb | 413 | " [--dump-osm [--no-super]\n" |
1193 | " [--latmin=<latmin> --latmax=<latmax>\n" | ||
1194 | amb | 1330 | " --lonmin=<lonmin> --lonmax=<lonmax>]]\n" |
1195 | amb | 1458 | " [--dump-visualiser [--data=node<node>]\n" |
1196 | " [--data=segment<segment>]\n" | ||
1197 | " [--data=turn-relation<rel>]\n" | ||
1198 | " [--data=errorlog<number>]]\n"); | ||
1199 | amb | 342 | |
1200 | amb | 490 | if(argerr) |
1201 | fprintf(stderr, | ||
1202 | "\n" | ||
1203 | "Error with command line parameter: %s\n",argerr); | ||
1204 | |||
1205 | amb | 491 | if(err) |
1206 | amb | 490 | fprintf(stderr, |
1207 | "\n" | ||
1208 | "Error: %s\n",err); | ||
1209 | |||
1210 | amb | 342 | 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 | amb | 1002 | " junctions = segment count at each junction.\n" |
1229 | " super = super-node and super-segments.\n" | ||
1230 | " oneway = oneway segments.\n" | ||
1231 | amb | 1003 | " highway-* = segments of the specified highway type.\n" |
1232 | amb | 1002 | " transport-* = segments allowing the specified transport type.\n" |
1233 | amb | 1077 | " barrier-* = nodes disallowing the specified transport type.\n" |
1234 | amb | 1002 | " 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 | amb | 1248 | " property-* = segments with the specified property.\n" |
1241 | amb | 1321 | " errorlogs = errors logged during parsing.\n" |
1242 | amb | 342 | "\n" |
1243 | "--dump Dump selected contents of the database.\n" | ||
1244 | amb | 1330 | " --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 | amb | 405 | " Use 'all' instead of a number to get all of them.\n" |
1250 | "\n" | ||
1251 | amb | 413 | "--dump-osm Dump all or part of the database as an XML file.\n" |
1252 | amb | 1330 | " --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 | amb | 342 | |
1264 | exit(!detail); | ||
1265 | } |
Properties
Name | Value |
---|---|
cvs:description | Test program for mmap files. |