Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/router.c
Parent Directory
|
Revision Log
Revision 608 -
(hide annotations)
(download)
(as text)
Sat Jan 29 16:00:10 2011 UTC (14 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 21417 byte(s)
Sat Jan 29 16:00:10 2011 UTC (14 years, 1 month ago) by amb
File MIME type: text/x-csrc
File size: 21417 byte(s)
When finding a normal route check for turn relations (considering previous segment). When finding turn relations convert fake segments into real ones.
1 | amb | 2 | /*************************************** |
2 | OSM router. | ||
3 | amb | 151 | |
4 | Part of the Routino routing software. | ||
5 | amb | 2 | ******************/ /****************** |
6 | amb | 605 | This file Copyright 2008-2011 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 | amb | 31 | #include <string.h> |
25 | amb | 2 | #include <stdlib.h> |
26 | amb | 130 | #include <ctype.h> |
27 | amb | 2 | |
28 | amb | 96 | #include "types.h" |
29 | amb | 115 | #include "nodes.h" |
30 | #include "segments.h" | ||
31 | amb | 109 | #include "ways.h" |
32 | amb | 542 | #include "relations.h" |
33 | amb | 2 | |
34 | amb | 449 | #include "files.h" |
35 | amb | 519 | #include "logging.h" |
36 | amb | 449 | #include "functions.h" |
37 | amb | 532 | #include "fakes.h" |
38 | amb | 449 | #include "translations.h" |
39 | #include "profiles.h" | ||
40 | amb | 2 | |
41 | amb | 449 | |
42 | amb | 303 | /*+ The maximum distance from the specified point to search for a node or segment (in km). +*/ |
43 | amb | 321 | #define MAXSEARCH 1 |
44 | amb | 242 | |
45 | amb | 303 | |
46 | amb | 456 | /*+ A set of waypoint latitudes and longitudes. +*/ |
47 | amb | 303 | static double point_lon[NWAYPOINTS+1],point_lat[NWAYPOINTS+1]; |
48 | |||
49 | amb | 113 | /*+ The option not to print any progress information. +*/ |
50 | amb | 107 | int option_quiet=0; |
51 | |||
52 | amb | 324 | /*+ The options to select the format of the output. +*/ |
53 | amb | 380 | int option_html=0,option_gpx_track=0,option_gpx_route=0,option_text=0,option_text_all=0,option_none=0; |
54 | amb | 324 | |
55 | amb | 113 | /*+ The option to calculate the quickest route insted of the shortest. +*/ |
56 | int option_quickest=0; | ||
57 | amb | 107 | |
58 | amb | 113 | |
59 | amb | 342 | /* Local functions */ |
60 | |||
61 | amb | 490 | static void print_usage(int detail,const char *argerr,const char *err); |
62 | amb | 342 | |
63 | |||
64 | /*++++++++++++++++++++++++++++++++++++++ | ||
65 | The main program for the router. | ||
66 | ++++++++++++++++++++++++++++++++++++++*/ | ||
67 | |||
68 | amb | 2 | int main(int argc,char** argv) |
69 | { | ||
70 | amb | 95 | Nodes *OSMNodes; |
71 | Segments *OSMSegments; | ||
72 | Ways *OSMWays; | ||
73 | amb | 542 | Relations*OSMRelations; |
74 | amb | 242 | Results *results[NWAYPOINTS+1]={NULL}; |
75 | int point_used[NWAYPOINTS+1]={0}; | ||
76 | amb | 342 | int help_profile=0,help_profile_xml=0,help_profile_json=0,help_profile_pl=0; |
77 | amb | 359 | char *dirname=NULL,*prefix=NULL; |
78 | char *profiles=NULL,*profilename=NULL; | ||
79 | char *translations=NULL,*language=NULL; | ||
80 | amb | 315 | int exactnodes=0; |
81 | amb | 82 | Transport transport=Transport_None; |
82 | amb | 342 | Profile *profile=NULL; |
83 | amb | 605 | index_t start_node=NO_NODE,finish_node=NO_NODE; |
84 | index_t join_segment=NO_SEGMENT; | ||
85 | amb | 303 | int arg,point; |
86 | amb | 2 | |
87 | amb | 44 | /* Parse the command line arguments */ |
88 | amb | 2 | |
89 | amb | 145 | if(argc<2) |
90 | amb | 490 | print_usage(0,NULL,NULL); |
91 | amb | 75 | |
92 | amb | 341 | /* Get the non-routing, general program options */ |
93 | amb | 75 | |
94 | amb | 165 | for(arg=1;arg<argc;arg++) |
95 | amb | 44 | { |
96 | amb | 324 | if(!strcmp(argv[arg],"--help")) |
97 | amb | 490 | print_usage(1,NULL,NULL); |
98 | amb | 324 | else if(!strcmp(argv[arg],"--help-profile")) |
99 | help_profile=1; | ||
100 | amb | 336 | else if(!strcmp(argv[arg],"--help-profile-xml")) |
101 | help_profile_xml=1; | ||
102 | amb | 342 | else if(!strcmp(argv[arg],"--help-profile-json")) |
103 | help_profile_json=1; | ||
104 | else if(!strcmp(argv[arg],"--help-profile-perl")) | ||
105 | amb | 324 | help_profile_pl=1; |
106 | else if(!strncmp(argv[arg],"--dir=",6)) | ||
107 | dirname=&argv[arg][6]; | ||
108 | else if(!strncmp(argv[arg],"--prefix=",9)) | ||
109 | prefix=&argv[arg][9]; | ||
110 | amb | 341 | else if(!strncmp(argv[arg],"--profiles=",11)) |
111 | profiles=&argv[arg][11]; | ||
112 | amb | 359 | else if(!strncmp(argv[arg],"--translations=",15)) |
113 | translations=&argv[arg][15]; | ||
114 | amb | 324 | else if(!strcmp(argv[arg],"--exact-nodes-only")) |
115 | exactnodes=1; | ||
116 | else if(!strcmp(argv[arg],"--quiet")) | ||
117 | option_quiet=1; | ||
118 | amb | 519 | else if(!strcmp(argv[arg],"--loggable")) |
119 | option_loggable=1; | ||
120 | amb | 324 | else if(!strcmp(argv[arg],"--output-html")) |
121 | option_html=1; | ||
122 | else if(!strcmp(argv[arg],"--output-gpx-track")) | ||
123 | option_gpx_track=1; | ||
124 | else if(!strcmp(argv[arg],"--output-gpx-route")) | ||
125 | option_gpx_route=1; | ||
126 | else if(!strcmp(argv[arg],"--output-text")) | ||
127 | option_text=1; | ||
128 | else if(!strcmp(argv[arg],"--output-text-all")) | ||
129 | option_text_all=1; | ||
130 | amb | 380 | else if(!strcmp(argv[arg],"--output-none")) |
131 | option_none=1; | ||
132 | amb | 341 | else if(!strncmp(argv[arg],"--profile=",10)) |
133 | profilename=&argv[arg][10]; | ||
134 | amb | 359 | else if(!strncmp(argv[arg],"--language=",11)) |
135 | language=&argv[arg][11]; | ||
136 | amb | 341 | else if(!strncmp(argv[arg],"--transport=",12)) |
137 | { | ||
138 | transport=TransportType(&argv[arg][12]); | ||
139 | |||
140 | if(transport==Transport_None) | ||
141 | amb | 490 | print_usage(0,argv[arg],NULL); |
142 | amb | 341 | } |
143 | else | ||
144 | continue; | ||
145 | |||
146 | argv[arg]=NULL; | ||
147 | } | ||
148 | |||
149 | /* Load in the profiles */ | ||
150 | |||
151 | if(transport==Transport_None) | ||
152 | transport=Transport_Motorcar; | ||
153 | |||
154 | amb | 407 | if(profiles) |
155 | { | ||
156 | if(!ExistsFile(profiles)) | ||
157 | { | ||
158 | fprintf(stderr,"Error: The '--profiles' option specifies a file that does not exist.\n"); | ||
159 | return(1); | ||
160 | } | ||
161 | } | ||
162 | else | ||
163 | { | ||
164 | if(ExistsFile(FileName(dirname,prefix,"profiles.xml"))) | ||
165 | profiles=FileName(dirname,prefix,"profiles.xml"); | ||
166 | amb | 481 | else if(ExistsFile(FileName(DATADIR,NULL,"tagging.xml"))) |
167 | profiles=FileName(DATADIR,NULL,"profiles.xml"); | ||
168 | amb | 407 | else |
169 | { | ||
170 | fprintf(stderr,"Error: The '--profiles' option was not used and the default 'profiles.xml' does not exist.\n"); | ||
171 | return(1); | ||
172 | } | ||
173 | } | ||
174 | amb | 341 | |
175 | amb | 481 | if(ParseXMLProfiles(profiles)) |
176 | amb | 341 | { |
177 | fprintf(stderr,"Error: Cannot read the profiles in the file '%s'.\n",profiles); | ||
178 | return(1); | ||
179 | } | ||
180 | |||
181 | if(profilename) | ||
182 | amb | 342 | { |
183 | amb | 341 | profile=GetProfile(profilename); |
184 | |||
185 | amb | 342 | if(!profile) |
186 | { | ||
187 | fprintf(stderr,"Error: Cannot find a profile called '%s' in '%s'.\n",profilename,profiles); | ||
188 | return(1); | ||
189 | } | ||
190 | } | ||
191 | else | ||
192 | amb | 341 | profile=GetProfile(TransportName(transport)); |
193 | |||
194 | if(!profile) | ||
195 | { | ||
196 | profile=(Profile*)calloc(1,sizeof(Profile)); | ||
197 | profile->transport=transport; | ||
198 | } | ||
199 | |||
200 | /* Parse the other command line arguments */ | ||
201 | |||
202 | for(arg=1;arg<argc;arg++) | ||
203 | { | ||
204 | if(!argv[arg]) | ||
205 | continue; | ||
206 | amb | 325 | else if(!strcmp(argv[arg],"--shortest")) |
207 | option_quickest=0; | ||
208 | else if(!strcmp(argv[arg],"--quickest")) | ||
209 | option_quickest=1; | ||
210 | amb | 324 | else if(isdigit(argv[arg][0]) || |
211 | amb | 165 | ((argv[arg][0]=='-' || argv[arg][0]=='+') && isdigit(argv[arg][1]))) |
212 | amb | 130 | { |
213 | amb | 303 | for(point=1;point<=NWAYPOINTS;point++) |
214 | if(point_used[point]!=3) | ||
215 | amb | 165 | { |
216 | amb | 303 | if(point_used[point]==0) |
217 | amb | 165 | { |
218 | amb | 303 | point_lon[point]=degrees_to_radians(atof(argv[arg])); |
219 | point_used[point]=1; | ||
220 | amb | 165 | } |
221 | amb | 303 | else /* if(point_used[point]==1) */ |
222 | amb | 165 | { |
223 | amb | 303 | point_lat[point]=degrees_to_radians(atof(argv[arg])); |
224 | point_used[point]=3; | ||
225 | amb | 165 | } |
226 | break; | ||
227 | } | ||
228 | } | ||
229 | amb | 242 | else if(!strncmp(argv[arg],"--lon",5) && isdigit(argv[arg][5])) |
230 | { | ||
231 | char *p=&argv[arg][6]; | ||
232 | while(isdigit(*p)) p++; | ||
233 | if(*p++!='=') | ||
234 | amb | 490 | print_usage(0,argv[arg],NULL); |
235 | amb | 242 | |
236 | amb | 303 | point=atoi(&argv[arg][5]); |
237 | if(point>NWAYPOINTS || point_used[point]&1) | ||
238 | amb | 490 | print_usage(0,argv[arg],NULL); |
239 | amb | 242 | |
240 | amb | 303 | point_lon[point]=degrees_to_radians(atof(p)); |
241 | point_used[point]+=1; | ||
242 | amb | 130 | } |
243 | amb | 242 | else if(!strncmp(argv[arg],"--lat",5) && isdigit(argv[arg][5])) |
244 | { | ||
245 | char *p=&argv[arg][6]; | ||
246 | while(isdigit(*p)) p++; | ||
247 | if(*p++!='=') | ||
248 | amb | 490 | print_usage(0,argv[arg],NULL); |
249 | amb | 242 | |
250 | amb | 303 | point=atoi(&argv[arg][5]); |
251 | if(point>NWAYPOINTS || point_used[point]&2) | ||
252 | amb | 490 | print_usage(0,argv[arg],NULL); |
253 | amb | 242 | |
254 | amb | 303 | point_lat[point]=degrees_to_radians(atof(p)); |
255 | point_used[point]+=2; | ||
256 | amb | 165 | } |
257 | else if(!strncmp(argv[arg],"--transport=",12)) | ||
258 | amb | 324 | ; /* Done this already */ |
259 | amb | 165 | else if(!strncmp(argv[arg],"--highway-",10)) |
260 | amb | 75 | { |
261 | amb | 130 | Highway highway; |
262 | amb | 165 | char *equal=strchr(argv[arg],'='); |
263 | amb | 130 | char *string; |
264 | amb | 82 | |
265 | amb | 130 | if(!equal) |
266 | amb | 490 | print_usage(0,argv[arg],NULL); |
267 | amb | 130 | |
268 | amb | 165 | string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+10); |
269 | string[equal-argv[arg]-10]=0; | ||
270 | amb | 130 | |
271 | highway=HighwayType(string); | ||
272 | |||
273 | amb | 300 | if(highway==Way_Count) |
274 | amb | 490 | print_usage(0,argv[arg],NULL); |
275 | amb | 82 | |
276 | amb | 341 | profile->highway[highway]=atof(equal+1); |
277 | amb | 298 | |
278 | free(string); | ||
279 | amb | 75 | } |
280 | amb | 165 | else if(!strncmp(argv[arg],"--speed-",8)) |
281 | amb | 82 | { |
282 | Highway highway; | ||
283 | amb | 165 | char *equal=strchr(argv[arg],'='); |
284 | amb | 82 | char *string; |
285 | |||
286 | if(!equal) | ||
287 | amb | 490 | print_usage(0,argv[arg],NULL); |
288 | amb | 82 | |
289 | amb | 165 | string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+8); |
290 | string[equal-argv[arg]-8]=0; | ||
291 | amb | 82 | |
292 | highway=HighwayType(string); | ||
293 | |||
294 | amb | 300 | if(highway==Way_Count) |
295 | amb | 490 | print_usage(0,argv[arg],NULL); |
296 | amb | 82 | |
297 | amb | 341 | profile->speed[highway]=kph_to_speed(atof(equal+1)); |
298 | amb | 298 | |
299 | free(string); | ||
300 | amb | 82 | } |
301 | amb | 298 | else if(!strncmp(argv[arg],"--property-",11)) |
302 | { | ||
303 | Property property; | ||
304 | char *equal=strchr(argv[arg],'='); | ||
305 | char *string; | ||
306 | |||
307 | if(!equal) | ||
308 | amb | 490 | print_usage(0,argv[arg],NULL); |
309 | amb | 298 | |
310 | string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+11); | ||
311 | string[equal-argv[arg]-11]=0; | ||
312 | |||
313 | property=PropertyType(string); | ||
314 | |||
315 | amb | 300 | if(property==Way_Count) |
316 | amb | 490 | print_usage(0,argv[arg],NULL); |
317 | amb | 298 | |
318 | amb | 341 | profile->props_yes[property]=atof(equal+1); |
319 | amb | 298 | |
320 | free(string); | ||
321 | } | ||
322 | amb | 165 | else if(!strncmp(argv[arg],"--oneway=",9)) |
323 | amb | 341 | profile->oneway=!!atoi(&argv[arg][9]); |
324 | amb | 165 | else if(!strncmp(argv[arg],"--weight=",9)) |
325 | amb | 341 | profile->weight=tonnes_to_weight(atof(&argv[arg][9])); |
326 | amb | 165 | else if(!strncmp(argv[arg],"--height=",9)) |
327 | amb | 341 | profile->height=metres_to_height(atof(&argv[arg][9])); |
328 | amb | 165 | else if(!strncmp(argv[arg],"--width=",8)) |
329 | amb | 341 | profile->width=metres_to_width(atof(&argv[arg][8])); |
330 | amb | 165 | else if(!strncmp(argv[arg],"--length=",9)) |
331 | amb | 341 | profile->length=metres_to_length(atof(&argv[arg][9])); |
332 | amb | 44 | else |
333 | amb | 490 | print_usage(0,argv[arg],NULL); |
334 | amb | 44 | } |
335 | |||
336 | amb | 303 | for(point=1;point<=NWAYPOINTS;point++) |
337 | if(point_used[point]==1 || point_used[point]==2) | ||
338 | amb | 490 | print_usage(0,NULL,"All waypoints must have latitude and longitude."); |
339 | amb | 165 | |
340 | amb | 82 | if(help_profile) |
341 | { | ||
342 | amb | 341 | PrintProfile(profile); |
343 | amb | 82 | |
344 | return(0); | ||
345 | } | ||
346 | amb | 336 | else if(help_profile_xml) |
347 | { | ||
348 | PrintProfilesXML(); | ||
349 | |||
350 | return(0); | ||
351 | } | ||
352 | amb | 342 | else if(help_profile_json) |
353 | amb | 129 | { |
354 | amb | 342 | PrintProfilesJSON(); |
355 | amb | 82 | |
356 | amb | 129 | return(0); |
357 | } | ||
358 | amb | 145 | else if(help_profile_pl) |
359 | { | ||
360 | PrintProfilesPerl(); | ||
361 | amb | 129 | |
362 | amb | 145 | return(0); |
363 | } | ||
364 | |||
365 | amb | 359 | /* Load in the translations */ |
366 | |||
367 | amb | 380 | if(option_html==0 && option_gpx_track==0 && option_gpx_route==0 && option_text==0 && option_text_all==0 && option_none==0) |
368 | option_html=option_gpx_track=option_gpx_route=option_text=option_text_all=1; | ||
369 | amb | 359 | |
370 | amb | 380 | if(option_html || option_gpx_route || option_gpx_track) |
371 | amb | 359 | { |
372 | amb | 481 | if(translations) |
373 | amb | 380 | { |
374 | amb | 481 | if(!ExistsFile(translations)) |
375 | { | ||
376 | fprintf(stderr,"Error: The '--translations' option specifies a file that does not exist.\n"); | ||
377 | return(1); | ||
378 | } | ||
379 | amb | 380 | } |
380 | amb | 481 | else |
381 | { | ||
382 | if(ExistsFile(FileName(dirname,prefix,"translations.xml"))) | ||
383 | translations=FileName(dirname,prefix,"translations.xml"); | ||
384 | else if(ExistsFile(FileName(DATADIR,NULL,"translations.xml"))) | ||
385 | translations=FileName(DATADIR,NULL,"translations.xml"); | ||
386 | else | ||
387 | { | ||
388 | fprintf(stderr,"Error: The '--translations' option was not used and the default 'translations.xml' does not exist.\n"); | ||
389 | return(1); | ||
390 | } | ||
391 | } | ||
392 | amb | 380 | |
393 | amb | 481 | if(ParseXMLTranslations(translations,language)) |
394 | amb | 380 | { |
395 | fprintf(stderr,"Error: Cannot read the translations in the file '%s'.\n",translations); | ||
396 | return(1); | ||
397 | } | ||
398 | amb | 359 | } |
399 | |||
400 | amb | 329 | /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */ |
401 | amb | 2 | |
402 | amb | 329 | OSMNodes=LoadNodeList(FileName(dirname,prefix,"nodes.mem")); |
403 | amb | 95 | |
404 | amb | 329 | OSMSegments=LoadSegmentList(FileName(dirname,prefix,"segments.mem")); |
405 | amb | 100 | |
406 | amb | 329 | OSMWays=LoadWayList(FileName(dirname,prefix,"ways.mem")); |
407 | amb | 66 | |
408 | amb | 542 | OSMRelations=LoadRelationList(FileName(dirname,prefix,"relations.mem")); |
409 | |||
410 | amb | 410 | if(UpdateProfile(profile,OSMWays)) |
411 | amb | 307 | { |
412 | amb | 410 | fprintf(stderr,"Error: Profile is invalid or not compatible with database.\n"); |
413 | amb | 307 | return(1); |
414 | } | ||
415 | |||
416 | amb | 303 | /* Loop through all pairs of points */ |
417 | amb | 99 | |
418 | amb | 303 | for(point=1;point<=NWAYPOINTS;point++) |
419 | amb | 107 | { |
420 | amb | 239 | Results *begin,*end; |
421 | amb | 605 | Result *finish_result; |
422 | amb | 315 | distance_t distmax=km_to_distance(MAXSEARCH); |
423 | distance_t distmin; | ||
424 | amb | 456 | index_t segment=NO_SEGMENT; |
425 | amb | 303 | index_t node1,node2; |
426 | amb | 99 | |
427 | amb | 303 | if(point_used[point]!=3) |
428 | amb | 165 | continue; |
429 | amb | 107 | |
430 | amb | 303 | /* Find the closest point */ |
431 | amb | 107 | |
432 | amb | 605 | start_node=finish_node; |
433 | amb | 165 | |
434 | amb | 315 | if(exactnodes) |
435 | { | ||
436 | amb | 605 | finish_node=FindClosestNode(OSMNodes,OSMSegments,OSMWays,point_lat[point],point_lon[point],distmax,profile,&distmin); |
437 | amb | 315 | } |
438 | else | ||
439 | { | ||
440 | distance_t dist1,dist2; | ||
441 | amb | 165 | |
442 | amb | 456 | segment=FindClosestSegment(OSMNodes,OSMSegments,OSMWays,point_lat[point],point_lon[point],distmax,profile,&distmin,&node1,&node2,&dist1,&dist2); |
443 | |||
444 | if(segment!=NO_SEGMENT) | ||
445 | amb | 608 | finish_node=CreateFakes(OSMNodes,OSMSegments,point,LookupSegment(OSMSegments,segment,1),node1,node2,dist1,dist2); |
446 | amb | 421 | else |
447 | amb | 605 | finish_node=NO_NODE; |
448 | amb | 315 | } |
449 | amb | 303 | |
450 | amb | 605 | if(finish_node==NO_NODE) |
451 | amb | 107 | { |
452 | amb | 303 | fprintf(stderr,"Error: Cannot find node close to specified point %d.\n",point); |
453 | amb | 107 | return(1); |
454 | } | ||
455 | |||
456 | if(!option_quiet) | ||
457 | { | ||
458 | amb | 219 | double lat,lon; |
459 | amb | 107 | |
460 | amb | 605 | if(IsFakeNode(finish_node)) |
461 | GetFakeLatLong(finish_node,&lat,&lon); | ||
462 | amb | 303 | else |
463 | amb | 605 | GetLatLong(OSMNodes,finish_node,&lat,&lon); |
464 | amb | 107 | |
465 | amb | 605 | if(IsFakeNode(finish_node)) |
466 | amb | 456 | printf("Point %d is segment %d (node %d -> %d): %3.6f %4.6f = %2.3f km\n",point,segment,node1,node2, |
467 | amb | 315 | radians_to_degrees(lon),radians_to_degrees(lat),distance_to_km(distmin)); |
468 | amb | 303 | else |
469 | amb | 605 | printf("Point %d is node %d: %3.6f %4.6f = %2.3f km\n",point,finish_node, |
470 | amb | 315 | radians_to_degrees(lon),radians_to_degrees(lat),distance_to_km(distmin)); |
471 | amb | 107 | } |
472 | |||
473 | amb | 605 | if(start_node==NO_NODE) |
474 | amb | 165 | continue; |
475 | |||
476 | amb | 605 | if(start_node==finish_node) |
477 | amb | 431 | continue; |
478 | |||
479 | amb | 239 | /* Calculate the beginning of the route */ |
480 | amb | 165 | |
481 | amb | 605 | begin=FindStartRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,start_node,join_segment,profile); |
482 | amb | 107 | |
483 | amb | 531 | if(!begin) |
484 | amb | 77 | { |
485 | amb | 531 | fprintf(stderr,"Error: Cannot find initial section of route compatible with profile.\n"); |
486 | return(1); | ||
487 | amb | 112 | } |
488 | amb | 239 | |
489 | amb | 605 | if((finish_result=FindResult1(begin,finish_node))) |
490 | amb | 239 | { |
491 | amb | 605 | FixForwardRoute(begin,finish_result); |
492 | amb | 290 | |
493 | amb | 303 | results[point]=begin; |
494 | amb | 305 | |
495 | if(!option_quiet) | ||
496 | { | ||
497 | amb | 519 | printf("Routed: Super-Nodes Checked = %d\n",begin->number); |
498 | amb | 305 | fflush(stdout); |
499 | } | ||
500 | amb | 239 | } |
501 | amb | 34 | else |
502 | { | ||
503 | amb | 239 | Results *superresults; |
504 | amb | 48 | |
505 | amb | 239 | /* Calculate the end of the route */ |
506 | amb | 34 | |
507 | amb | 605 | end=FindFinishRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,finish_node,profile); |
508 | amb | 34 | |
509 | amb | 531 | if(!end) |
510 | amb | 112 | { |
511 | amb | 531 | fprintf(stderr,"Error: Cannot find final section of route compatible with profile.\n"); |
512 | return(1); | ||
513 | amb | 112 | } |
514 | |||
515 | amb | 239 | /* Calculate the middle of the route */ |
516 | |||
517 | amb | 542 | superresults=FindMiddleRoute(OSMNodes,OSMSegments,OSMWays,OSMRelations,begin,end,profile); |
518 | amb | 239 | |
519 | amb | 317 | FreeResultsList(begin); |
520 | FreeResultsList(end); | ||
521 | |||
522 | amb | 239 | if(!superresults) |
523 | amb | 165 | { |
524 | amb | 239 | fprintf(stderr,"Error: Cannot find route compatible with profile.\n"); |
525 | return(1); | ||
526 | amb | 165 | } |
527 | amb | 34 | |
528 | amb | 605 | results[point]=CombineRoutes(OSMNodes,OSMSegments,OSMWays,OSMRelations,superresults,join_segment,profile); |
529 | amb | 317 | |
530 | FreeResultsList(superresults); | ||
531 | amb | 34 | } |
532 | amb | 605 | |
533 | join_segment=results[point]->last_segment; | ||
534 | amb | 31 | } |
535 | |||
536 | amb | 239 | /* Print out the combined route */ |
537 | amb | 164 | |
538 | amb | 380 | if(!option_none) |
539 | PrintRoute(results,NWAYPOINTS,OSMNodes,OSMSegments,OSMWays,profile); | ||
540 | amb | 164 | |
541 | amb | 2 | return(0); |
542 | } | ||
543 | amb | 303 | |
544 | |||
545 | /*++++++++++++++++++++++++++++++++++++++ | ||
546 | amb | 342 | Print out the usage information. |
547 | |||
548 | int detail The level of detail to use - 0 = low, 1 = high. | ||
549 | amb | 490 | |
550 | const char *argerr The argument that gave the error (if there is one). | ||
551 | |||
552 | const char *err Other error message (if there is one). | ||
553 | amb | 342 | ++++++++++++++++++++++++++++++++++++++*/ |
554 | |||
555 | amb | 490 | static void print_usage(int detail,const char *argerr,const char *err) |
556 | amb | 342 | { |
557 | fprintf(stderr, | ||
558 | "Usage: router [--help | --help-profile | --help-profile-xml |\n" | ||
559 | " --help-profile-json | --help-profile-perl ]\n" | ||
560 | amb | 359 | " [--dir=<dirname>] [--prefix=<name>]\n" |
561 | " [--profiles=<filename>] [--translations=<filename>]\n" | ||
562 | amb | 342 | " [--exact-nodes-only]\n" |
563 | amb | 519 | " [--loggable | --quiet]\n" |
564 | amb | 362 | " [--language=<lang>]\n" |
565 | amb | 342 | " [--output-html]\n" |
566 | " [--output-gpx-track] [--output-gpx-route]\n" | ||
567 | " [--output-text] [--output-text-all]\n" | ||
568 | amb | 380 | " [--output-none]\n" |
569 | amb | 342 | " [--profile=<name>]\n" |
570 | " [--transport=<transport>]\n" | ||
571 | " [--shortest | --quickest]\n" | ||
572 | " --lon1=<longitude> --lat1=<latitude>\n" | ||
573 | " --lon2=<longitude> --lon2=<latitude>\n" | ||
574 | " [ ... --lon99=<longitude> --lon99=<latitude>]\n" | ||
575 | " [--highway-<highway>=<preference> ...]\n" | ||
576 | " [--speed-<highway>=<speed> ...]\n" | ||
577 | " [--property-<property>=<preference> ...]\n" | ||
578 | " [--oneway=(0|1)]\n" | ||
579 | " [--weight=<weight>]\n" | ||
580 | " [--height=<height>] [--width=<width>] [--length=<length>]\n"); | ||
581 | |||
582 | amb | 490 | if(argerr) |
583 | fprintf(stderr, | ||
584 | "\n" | ||
585 | "Error with command line parameter: %s\n",argerr); | ||
586 | |||
587 | amb | 491 | if(err) |
588 | amb | 490 | fprintf(stderr, |
589 | "\n" | ||
590 | "Error: %s\n",err); | ||
591 | |||
592 | amb | 342 | if(detail) |
593 | fprintf(stderr, | ||
594 | "\n" | ||
595 | "--help Prints this information.\n" | ||
596 | "--help-profile Prints the information about the selected profile.\n" | ||
597 | "--help-profile-xml Prints all loaded profiles in XML format.\n" | ||
598 | "--help-profile-json Prints all loaded profiles in JSON format.\n" | ||
599 | "--help-profile-perl Prints all loaded profiles in Perl format.\n" | ||
600 | "\n" | ||
601 | "--dir=<dirname> The directory containing the routing database.\n" | ||
602 | "--prefix=<name> The filename prefix for the routing database.\n" | ||
603 | amb | 481 | "--profiles=<filename> The name of the XML file containing the profiles\n" |
604 | amb | 488 | " (defaults to 'profiles.xml' with '--dir' and\n" |
605 | amb | 481 | " '--prefix' options or the file installed in\n" |
606 | " '" DATADIR "').\n" | ||
607 | "--translations=<fname> The name of the XML file containing the translations\n" | ||
608 | amb | 488 | " (defaults to 'translations.xml' with '--dir' and\n" |
609 | amb | 481 | " '--prefix' options or the file installed in\n" |
610 | " '" DATADIR "').\n" | ||
611 | amb | 342 | "\n" |
612 | "--exact-nodes-only Only route between nodes (don't find closest segment).\n" | ||
613 | "\n" | ||
614 | amb | 519 | "--loggable Print progress messages suitable for logging to file.\n" |
615 | amb | 380 | "--quiet Don't print any screen output when running.\n" |
616 | amb | 519 | "\n" |
617 | amb | 362 | "--language=<lang> Use the translations for specified language.\n" |
618 | amb | 342 | "--output-html Write an HTML description of the route.\n" |
619 | "--output-gpx-track Write a GPX track file with all route points.\n" | ||
620 | "--output-gpx-route Write a GPX route file with interesting junctions.\n" | ||
621 | "--output-text Write a plain text file with interesting junctions.\n" | ||
622 | "--output-text-all Write a plain test file with all route points.\n" | ||
623 | amb | 380 | "--output-none Don't write any output files or read any translations.\n" |
624 | amb | 342 | " (If no output option is given then all are written.)\n" |
625 | "\n" | ||
626 | "--profile=<name> Select the loaded profile with this name.\n" | ||
627 | "--transport=<transport> Select the transport to use (selects the profile\n" | ||
628 | " named after the transport if '--profile' is not used.)\n" | ||
629 | "\n" | ||
630 | "--shortest Find the shortest route between the waypoints.\n" | ||
631 | "--quickest Find the quickest route between the waypoints.\n" | ||
632 | "\n" | ||
633 | "--lon<n>=<longitude> Specify the longitude of the n'th waypoint.\n" | ||
634 | "--lat<n>=<latitude> Specify the latitude of the n'th waypoint.\n" | ||
635 | "\n" | ||
636 | " Routing preference options\n" | ||
637 | "--highway-<highway>=<preference> * preference for highway type (%%).\n" | ||
638 | "--speed-<highway>=<speed> * speed for highway type (km/h).\n" | ||
639 | "--property-<property>=<preference> * preference for proprty type (%%).\n" | ||
640 | "--oneway=(0|1) * oneway streets are to be obeyed.\n" | ||
641 | "--weight=<weight> * maximum weight limit (tonnes).\n" | ||
642 | "--height=<height> * maximum height limit (metres).\n" | ||
643 | "--width=<width> * maximum width limit (metres).\n" | ||
644 | "--length=<length> * maximum length limit (metres).\n" | ||
645 | "\n" | ||
646 | "<transport> defaults to motorcar but can be set to:\n" | ||
647 | "%s" | ||
648 | "\n" | ||
649 | "<highway> can be selected from:\n" | ||
650 | "%s" | ||
651 | "\n" | ||
652 | "<property> can be selected from:\n" | ||
653 | "%s", | ||
654 | TransportList(),HighwayList(),PropertyList()); | ||
655 | |||
656 | exit(!detail); | ||
657 | } |
Properties
Name | Value |
---|---|
cvs:description | Router. |