Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/ways.c
Parent Directory
|
Revision Log
Revision 298 -
(show annotations)
(download)
(as text)
Mon Nov 2 19:32:06 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 12099 byte(s)
Mon Nov 2 19:32:06 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 12099 byte(s)
Added the ability to set routing preferences using highway properties. Initially the only choice is either paved or unpaved but the code has been updated to allow any number of properties to be added.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/ways.c,v 1.36 2009-11-02 19:32:06 amb Exp $ |
3 | |
4 | Way data type functions. |
5 | |
6 | Part of the Routino routing software. |
7 | ******************/ /****************** |
8 | This file Copyright 2008,2009 Andrew M. Bishop |
9 | |
10 | This program is free software: you can redistribute it and/or modify |
11 | it under the terms of the GNU Affero General Public License as published by |
12 | the Free Software Foundation, either version 3 of the License, or |
13 | (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public License |
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | ***************************************/ |
23 | |
24 | |
25 | #include <sys/types.h> |
26 | #include <stdlib.h> |
27 | #include <string.h> |
28 | |
29 | #include "functions.h" |
30 | #include "ways.h" |
31 | |
32 | |
33 | /*++++++++++++++++++++++++++++++++++++++ |
34 | Load in a way list from a file. |
35 | |
36 | Ways* LoadWayList Returns the way list. |
37 | |
38 | const char *filename The name of the file to load. |
39 | ++++++++++++++++++++++++++++++++++++++*/ |
40 | |
41 | Ways *LoadWayList(const char *filename) |
42 | { |
43 | void *data; |
44 | Ways *ways; |
45 | |
46 | ways=(Ways*)malloc(sizeof(Ways)); |
47 | |
48 | data=MapFile(filename); |
49 | |
50 | if(!data) |
51 | return(NULL); |
52 | |
53 | /* Copy the Ways structure from the loaded data */ |
54 | |
55 | *ways=*((Ways*)data); |
56 | |
57 | /* Adjust the pointers in the Ways structure. */ |
58 | |
59 | ways->data =data; |
60 | ways->ways =(Way *)(data+(off_t)ways->ways); |
61 | ways->names=(char*)(data+(off_t)ways->names); |
62 | |
63 | return(ways); |
64 | } |
65 | |
66 | |
67 | /*++++++++++++++++++++++++++++++++++++++ |
68 | Decide on the type of a way given the "highway" parameter. |
69 | |
70 | Highway HighwayType Returns the highway type of the way. |
71 | |
72 | const char *highway The string containing the type of the way. |
73 | ++++++++++++++++++++++++++++++++++++++*/ |
74 | |
75 | Highway HighwayType(const char *highway) |
76 | { |
77 | switch(*highway) |
78 | { |
79 | case 'b': |
80 | if(!strcmp(highway,"byway")) return(Way_Track); |
81 | if(!strcmp(highway,"bridleway")) return(Way_Path); |
82 | return(Way_Unknown); |
83 | |
84 | case 'c': |
85 | if(!strcmp(highway,"cycleway")) return(Way_Cycleway); |
86 | return(Way_Unknown); |
87 | |
88 | case 'f': |
89 | if(!strcmp(highway,"footway")) return(Way_Path); |
90 | return(Way_Unknown); |
91 | |
92 | case 'l': |
93 | if(!strcmp(highway,"living_street")) return(Way_Residential); |
94 | return(Way_Unknown); |
95 | |
96 | case 'm': |
97 | if(!strncmp(highway,"motorway",8)) return(Way_Motorway); |
98 | if(!strcmp(highway,"minor")) return(Way_Unclassified); |
99 | return(Way_Unknown); |
100 | |
101 | case 'p': |
102 | if(!strncmp(highway,"primary",7)) return(Way_Primary); |
103 | if(!strcmp(highway,"path")) return(Way_Path); |
104 | if(!strcmp(highway,"pedestrian")) return(Way_Path); |
105 | return(Way_Unknown); |
106 | |
107 | case 'r': |
108 | if(!strcmp(highway,"road")) return(Way_Unclassified); |
109 | if(!strcmp(highway,"residential")) return(Way_Residential); |
110 | return(Way_Unknown); |
111 | |
112 | case 's': |
113 | if(!strncmp(highway,"secondary",9)) return(Way_Secondary); |
114 | if(!strcmp(highway,"service")) return(Way_Service); |
115 | if(!strcmp(highway,"services")) return(Way_Service); |
116 | if(!strcmp(highway,"steps")) return(Way_Path); |
117 | return(Way_Unknown); |
118 | |
119 | case 't': |
120 | if(!strncmp(highway,"trunk",5)) return(Way_Trunk); |
121 | if(!strcmp(highway,"tertiary")) return(Way_Tertiary); |
122 | if(!strcmp(highway,"track")) return(Way_Track); |
123 | return(Way_Unknown); |
124 | |
125 | case 'u': |
126 | if(!strcmp(highway,"unclassified")) return(Way_Unclassified); |
127 | if(!strcmp(highway,"unsurfaced")) return(Way_Track); |
128 | if(!strcmp(highway,"unpaved")) return(Way_Track); |
129 | return(Way_Unknown); |
130 | |
131 | case 'w': |
132 | if(!strcmp(highway,"walkway")) return(Way_Path); |
133 | return(Way_Unknown); |
134 | |
135 | default: |
136 | ; |
137 | } |
138 | |
139 | return(Way_Unknown); |
140 | } |
141 | |
142 | |
143 | /*++++++++++++++++++++++++++++++++++++++ |
144 | Decide on the type of transport given the name of it. |
145 | |
146 | Transport TransportType Returns the type of the transport. |
147 | |
148 | const char *transport The string containing the method of transport. |
149 | ++++++++++++++++++++++++++++++++++++++*/ |
150 | |
151 | Transport TransportType(const char *transport) |
152 | { |
153 | switch(*transport) |
154 | { |
155 | case 'b': |
156 | if(!strcmp(transport,"bicycle")) |
157 | return(Transport_Bicycle); |
158 | break; |
159 | |
160 | case 'f': |
161 | if(!strcmp(transport,"foot")) |
162 | return(Transport_Foot); |
163 | break; |
164 | |
165 | case 'g': |
166 | if(!strcmp(transport,"goods")) |
167 | return(Transport_Goods); |
168 | break; |
169 | |
170 | case 'h': |
171 | if(!strcmp(transport,"horse")) |
172 | return(Transport_Horse); |
173 | if(!strcmp(transport,"hgv")) |
174 | return(Transport_HGV); |
175 | break; |
176 | |
177 | case 'm': |
178 | if(!strcmp(transport,"moped")) |
179 | return(Transport_Moped); |
180 | if(!strcmp(transport,"motorbike")) |
181 | return(Transport_Motorbike); |
182 | if(!strcmp(transport,"motorcar")) |
183 | return(Transport_Motorcar); |
184 | break; |
185 | |
186 | case 'p': |
187 | if(!strcmp(transport,"psv")) |
188 | return(Transport_PSV); |
189 | break; |
190 | |
191 | default: |
192 | return(Transport_None); |
193 | } |
194 | |
195 | return(Transport_None); |
196 | } |
197 | |
198 | |
199 | /*++++++++++++++++++++++++++++++++++++++ |
200 | Decide on the type of property given the name of it. |
201 | |
202 | Property PropertyType Returns the type of the property. |
203 | |
204 | const char *property The string containing the method of property. |
205 | ++++++++++++++++++++++++++++++++++++++*/ |
206 | |
207 | Property PropertyType(const char *property) |
208 | { |
209 | switch(*property) |
210 | { |
211 | case 'p': |
212 | if(!strcmp(property,"paved")) |
213 | return(Property_Paved); |
214 | break; |
215 | |
216 | default: |
217 | return(Property_None); |
218 | } |
219 | |
220 | return(Property_None); |
221 | } |
222 | |
223 | |
224 | /*++++++++++++++++++++++++++++++++++++++ |
225 | A string containing the name of a type of highway. |
226 | |
227 | const char *HighwayName Returns the name. |
228 | |
229 | Highway highway The highway type. |
230 | ++++++++++++++++++++++++++++++++++++++*/ |
231 | |
232 | const char *HighwayName(Highway highway) |
233 | { |
234 | switch(highway) |
235 | { |
236 | case Way_Motorway: |
237 | return("motorway"); |
238 | case Way_Trunk: |
239 | return("trunk"); |
240 | case Way_Primary: |
241 | return("primary"); |
242 | case Way_Secondary: |
243 | return("secondary"); |
244 | case Way_Tertiary: |
245 | return("tertiary"); |
246 | case Way_Unclassified: |
247 | return("unclassified"); |
248 | case Way_Residential: |
249 | return("residential"); |
250 | case Way_Service: |
251 | return("service"); |
252 | case Way_Track: |
253 | return("track"); |
254 | case Way_Cycleway: |
255 | return("cycleway"); |
256 | case Way_Path: |
257 | return("path"); |
258 | |
259 | case Way_Unknown: |
260 | case Way_OneWay: |
261 | case Way_Roundabout: |
262 | ; |
263 | } |
264 | |
265 | return(NULL); |
266 | } |
267 | |
268 | |
269 | /*++++++++++++++++++++++++++++++++++++++ |
270 | A string containing the name of a type of transport. |
271 | |
272 | const char *TransportName Returns the name. |
273 | |
274 | Transport transport The transport type. |
275 | ++++++++++++++++++++++++++++++++++++++*/ |
276 | |
277 | const char *TransportName(Transport transport) |
278 | { |
279 | switch(transport) |
280 | { |
281 | case Transport_None: |
282 | return("NONE"); |
283 | |
284 | case Transport_Foot: |
285 | return("foot"); |
286 | case Transport_Horse: |
287 | return("horse"); |
288 | case Transport_Bicycle: |
289 | return("bicycle"); |
290 | case Transport_Moped: |
291 | return("moped"); |
292 | case Transport_Motorbike: |
293 | return("motorbike"); |
294 | case Transport_Motorcar: |
295 | return("motorcar"); |
296 | case Transport_Goods: |
297 | return("goods"); |
298 | case Transport_HGV: |
299 | return("hgv"); |
300 | case Transport_PSV: |
301 | return("psv"); |
302 | } |
303 | |
304 | return(NULL); |
305 | } |
306 | |
307 | |
308 | /*++++++++++++++++++++++++++++++++++++++ |
309 | A string containing the name of a highway property. |
310 | |
311 | const char *PropertyName Returns the name. |
312 | |
313 | Property property The property type. |
314 | ++++++++++++++++++++++++++++++++++++++*/ |
315 | |
316 | const char *PropertyName(Property property) |
317 | { |
318 | switch(property) |
319 | { |
320 | case Property_None: |
321 | return("NONE"); |
322 | |
323 | case Property_Paved: |
324 | return("paved"); |
325 | |
326 | case Property_Count: |
327 | ; |
328 | } |
329 | |
330 | return(NULL); |
331 | } |
332 | |
333 | |
334 | /*++++++++++++++++++++++++++++++++++++++ |
335 | A string containing the names of allowed transports on a way. |
336 | |
337 | const char *AllowedNameList Returns the list of names. |
338 | |
339 | wayallow_t allowed The allowed type. |
340 | ++++++++++++++++++++++++++++++++++++++*/ |
341 | |
342 | const char *AllowedNameList(wayallow_t allowed) |
343 | { |
344 | static char string[256]; |
345 | |
346 | string[0]=0; |
347 | |
348 | if(allowed & Allow_Foot) |
349 | strcat(string,"foot"); |
350 | |
351 | if(allowed & Allow_Horse) |
352 | { |
353 | if(*string) strcat(string,", "); |
354 | strcat(string,"horse"); |
355 | } |
356 | |
357 | if(allowed & Allow_Bicycle) |
358 | { |
359 | if(*string) strcat(string,", "); |
360 | strcat(string,"bicycle"); |
361 | } |
362 | |
363 | if(allowed & Allow_Moped) |
364 | { |
365 | if(*string) strcat(string,", "); |
366 | strcat(string,"moped"); |
367 | } |
368 | |
369 | if(allowed & Allow_Motorbike) |
370 | { |
371 | if(*string) strcat(string,", "); |
372 | strcat(string,"motorbike"); |
373 | } |
374 | |
375 | if(allowed & Allow_Motorcar) |
376 | { |
377 | if(*string) strcat(string,", "); |
378 | strcat(string,"motorcar"); |
379 | } |
380 | |
381 | if(allowed & Allow_Goods) |
382 | { |
383 | if(*string) strcat(string,", "); |
384 | strcat(string,"goods"); |
385 | } |
386 | |
387 | if(allowed & Allow_HGV) |
388 | { |
389 | if(*string) strcat(string,", "); |
390 | strcat(string,"hgv"); |
391 | } |
392 | |
393 | if(allowed & Allow_PSV) |
394 | { |
395 | if(*string) strcat(string,", "); |
396 | strcat(string,"psv"); |
397 | } |
398 | |
399 | return(string); |
400 | } |
401 | |
402 | |
403 | /*++++++++++++++++++++++++++++++++++++++ |
404 | A string containing the names of the properties of a way. |
405 | |
406 | const char *PropertiesNameList Returns the list of names. |
407 | |
408 | wayprop_t properties The properties of the way. |
409 | ++++++++++++++++++++++++++++++++++++++*/ |
410 | |
411 | const char *PropertiesNameList(wayprop_t properties) |
412 | { |
413 | static char string[256]; |
414 | |
415 | string[0]=0; |
416 | |
417 | if(properties & Properties_Paved) |
418 | { |
419 | if(*string) strcat(string,", "); |
420 | strcat(string,"paved"); |
421 | } |
422 | |
423 | return(string); |
424 | } |
425 | |
426 | |
427 | /*++++++++++++++++++++++++++++++++++++++ |
428 | Returns a list of all the highway types. |
429 | |
430 | const char *HighwayList Return a list of all the highway types. |
431 | ++++++++++++++++++++++++++++++++++++++*/ |
432 | |
433 | const char *HighwayList(void) |
434 | { |
435 | return " motorway = Motorway\n" |
436 | " trunk = Trunk\n" |
437 | " primary = Primary\n" |
438 | " secondary = Secondary\n" |
439 | " tertiary = Tertiary\n" |
440 | " unclassified = Unclassified\n" |
441 | " residential = Residential\n" |
442 | " service = Service\n" |
443 | " track = Track\n" |
444 | " cycleway = Cycleway\n" |
445 | " path = Path\n" |
446 | ; |
447 | } |
448 | |
449 | |
450 | /*++++++++++++++++++++++++++++++++++++++ |
451 | Returns a list of all the transport types. |
452 | |
453 | const char *TransportList Return a list of all the transport types. |
454 | ++++++++++++++++++++++++++++++++++++++*/ |
455 | |
456 | const char *TransportList(void) |
457 | { |
458 | return " foot = Foot\n" |
459 | " bicycle = Bicycle\n" |
460 | " horse = Horse\n" |
461 | " moped = Moped (Small motorbike, limited speed)\n" |
462 | " motorbike = Motorbike\n" |
463 | " motorcar = Motorcar\n" |
464 | " goods = Goods (Small lorry, van)\n" |
465 | " hgv = HGV (Heavy Goods Vehicle - large lorry)\n" |
466 | " psv = PSV (Public Service Vehicle - bus, coach)\n" |
467 | ; |
468 | } |
469 | |
470 | |
471 | /*++++++++++++++++++++++++++++++++++++++ |
472 | Returns a list of all the property types. |
473 | |
474 | const char *PropertyList Return a list of all the highway proprties. |
475 | ++++++++++++++++++++++++++++++++++++++*/ |
476 | |
477 | const char *PropertyList(void) |
478 | { |
479 | return " paved = Paved\n" |
480 | ; |
481 | } |
482 | |
483 | |
484 | /*++++++++++++++++++++++++++++++++++++++ |
485 | Return 0 if the two ways are the same (in respect of their types and limits), |
486 | otherwise return positive or negative to allow sorting. |
487 | |
488 | int WaysCompare Returns a comparison. |
489 | |
490 | Way *way1 The first way. |
491 | |
492 | Way *way2 The second way. |
493 | ++++++++++++++++++++++++++++++++++++++*/ |
494 | |
495 | int WaysCompare(Way *way1,Way *way2) |
496 | { |
497 | if(way1==way2) |
498 | return(0); |
499 | |
500 | if(way1->type!=way2->type) |
501 | return((int)way1->type - (int)way2->type); |
502 | |
503 | if(way1->allow!=way2->allow) |
504 | return((int)way1->allow - (int)way2->allow); |
505 | |
506 | if(way1->props!=way2->props) |
507 | return((int)way1->props - (int)way2->props); |
508 | |
509 | if(way1->speed!=way2->speed) |
510 | return((int)way1->speed - (int)way2->speed); |
511 | |
512 | if(way1->weight!=way2->weight) |
513 | return((int)way1->weight - (int)way2->weight); |
514 | |
515 | if(way1->height!=way2->height) |
516 | return((int)way1->height - (int)way2->height); |
517 | |
518 | if(way1->width!=way2->width) |
519 | return((int)way1->width - (int)way2->width); |
520 | |
521 | if(way1->length!=way2->length) |
522 | return((int)way1->length - (int)way2->length); |
523 | |
524 | return(0); |
525 | } |
Properties
Name | Value |
---|---|
cvs:description | Functions for ways. |