Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/osmparser.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 314 - (hide annotations) (download) (as text)
Tue Dec 15 18:44:28 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 21902 byte(s)
Added wheelchair as type of transport.

1 amb 2 /***************************************
2 amb 314 $Header: /home/amb/CVS/routino/src/osmparser.c,v 1.63 2009-12-15 18:44:28 amb Exp $
3 amb 2
4     OSM XML file parser (either JOSM or planet)
5 amb 151
6     Part of the Routino routing software.
7 amb 2 ******************/ /******************
8 amb 151 This file Copyright 2008,2009 Andrew M. Bishop
9 amb 2
10 amb 151 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 amb 2 ***************************************/
23    
24    
25     #include <stdio.h>
26     #include <stdlib.h>
27     #include <string.h>
28     #include <ctype.h>
29    
30 amb 199 #include "typesx.h"
31     #include "functionsx.h"
32 amb 109 #include "nodesx.h"
33     #include "segmentsx.h"
34     #include "waysx.h"
35 amb 228 #include "ways.h"
36 amb 2
37 amb 26
38 amb 228 /*+ The length of the buffer and the size increment for reading lines from the file. +*/
39 amb 244 #define BUFFSIZE 256
40 amb 2
41 amb 298 #define ISTRUE(xx) (!strcmp(xx,"true") || !strcmp(xx,"yes") || !strcmp(xx,"1"))
42 amb 297
43 amb 298 #define ISALLOWED(xx) (!strcmp(xx,"true") || !strcmp(xx,"yes") || !strcmp(xx,"1") || \
44     !strcmp(xx,"permissive") || !strcmp(xx,"designated") || !strcmp(xx,"destination"))
45    
46 amb 228 /* Local functions */
47    
48 amb 2 static char *fgets_realloc(char *buffer,FILE *file);
49    
50    
51     /*++++++++++++++++++++++++++++++++++++++
52     Parse an OSM XML file (from JOSM or planet download).
53    
54     int ParseXML Returns 0 if OK or something else in case of an error.
55    
56     FILE *file The file to read from.
57 amb 26
58 amb 97 NodesX *OSMNodes The array of nodes to fill in.
59 amb 26
60 amb 97 SegmentsX *OSMSegments The array of segments to fill in.
61 amb 26
62 amb 97 WaysX *OSMWays The arrray of ways to fill in.
63 amb 75
64 amb 228 Profile *profile A profile of the allowed transport types and included/excluded highway types.
65 amb 2 ++++++++++++++++++++++++++++++++++++++*/
66    
67 amb 97 int ParseXML(FILE *file,NodesX *OSMNodes,SegmentsX *OSMSegments,WaysX *OSMWays,Profile *profile)
68 amb 2 {
69     char *line=NULL;
70     long nlines=0;
71     long nnodes=0,nways=0,nrelations=0;
72     int isnode=0,isway=0,isrelation=0;
73 amb 203 way_t way_id=0;
74 amb 298 wayallow_t way_allow_no=0,way_allow_yes=0;
75 amb 6 int way_oneway=0,way_roundabout=0;
76 amb 313 int way_paved=0,way_multilane=0,way_bridge=0,way_tunnel=0;
77 amb 51 speed_t way_maxspeed=0;
78 amb 136 weight_t way_maxweight=0;
79     height_t way_maxheight=0;
80     width_t way_maxwidth=0;
81     length_t way_maxlength=0;
82 amb 51 char *way_highway=NULL,*way_name=NULL,*way_ref=NULL;
83 amb 2 node_t *way_nodes=NULL;
84     int way_nnodes=0,way_nalloc=0;
85    
86 amb 227 printf("\rReading: Lines=0 Nodes=0 Ways=0 Relations=0");
87     fflush(stdout);
88    
89 amb 2 /* Parse the file */
90    
91     while((line=fgets_realloc(line,file)))
92     {
93     char *l=line,*m;
94    
95     nlines++;
96    
97     while(isspace(*l))
98     l++;
99    
100     if(!strncmp(l,"<node",5)) /* The start of a node */
101     {
102     node_t id;
103 amb 219 double latitude,longitude;
104 amb 2
105     nnodes++;
106    
107     isnode=1; isway=0; isrelation=0;
108    
109     m=strstr(l,"id="); m+=4; if(*m=='"' || *m=='\'') m++; id=atoll(m);
110 amb 198 m=strstr(l,"lat="); m+=5; if(*m=='"' || *m=='\'') m++; latitude=degrees_to_radians(atof(m));
111     m=strstr(l,"lon="); m+=4; if(*m=='"' || *m=='\'') m++; longitude=degrees_to_radians(atof(m));
112 amb 2
113 amb 26 AppendNode(OSMNodes,id,latitude,longitude);
114 amb 159
115     if(strstr(l,"/>")) /* The end of a node */
116     {
117     isnode=0; isway=0; isrelation=0;
118     }
119 amb 2 }
120     else if(!strncmp(l,"</node",6)) /* The end of a node */
121     {
122     isnode=0; isway=0; isrelation=0;
123     }
124     else if(!strncmp(l,"<way",4)) /* The start of a way */
125     {
126     nways++;
127    
128     isnode=0; isway=1; isrelation=0;
129    
130 amb 203 m=strstr(l,"id="); m+=4; if(*m=='"' || *m=='\'') m++; way_id=atoll(m);
131    
132 amb 298 way_allow_no=0; way_allow_yes=0;
133 amb 51 way_oneway=0; way_roundabout=0;
134 amb 313 way_paved=0; way_multilane=0; way_bridge=0; way_tunnel=0;
135 amb 136 way_maxspeed=0; way_maxweight=0; way_maxheight=0; way_maxwidth=0;
136     way_maxlength=0;
137 amb 51 way_highway=NULL; way_name=NULL; way_ref=NULL;
138 amb 2 way_nnodes=0;
139     }
140     else if(!strncmp(l,"</way",5)) /* The end of a way */
141     {
142     isnode=0; isway=0; isrelation=0;
143    
144 amb 30 if(way_highway)
145 amb 2 {
146 amb 298 Way way={0};
147 amb 2
148 amb 298 way.type=HighwayType(way_highway);
149 amb 6
150 amb 298 if(profile->highway[way.type])
151 amb 2 {
152 amb 298 switch(way.type)
153 amb 73 {
154 amb 298 case Way_Motorway:
155     way.type|=Way_OneWay;
156     way.allow=Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
157 amb 308 way.props=Properties_Paved|Properties_Multilane;
158 amb 298 break;
159     case Way_Trunk:
160     way.allow=Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
161     way.props=Properties_Paved;
162     break;
163     case Way_Primary:
164     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
165     way.props=Properties_Paved;
166     break;
167     case Way_Secondary:
168     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
169     way.props=Properties_Paved;
170     break;
171     case Way_Tertiary:
172     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
173     way.props=Properties_Paved;
174     break;
175     case Way_Unclassified:
176     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
177     way.props=Properties_Paved;
178     break;
179     case Way_Residential:
180     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
181     way.props=Properties_Paved;
182     break;
183     case Way_Service:
184     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
185     way.props=Properties_Paved;
186     break;
187     case Way_Track:
188     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle;
189     way.props=0;
190     break;
191     case Way_Cycleway:
192     way.allow=Allow_Foot|Allow_Bicycle;
193     way.props=Properties_Paved;
194     break;
195     case Way_Path:
196     if(!strcmp(way_highway,"bridleway"))
197     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle; /* Special case for "bridleway". */
198     else
199     way.allow=Allow_Foot; /* Only allow bicycle and horse if so indicated. */
200     way.props=0;
201     break;
202 amb 306 case Way_Steps:
203     way.allow=Allow_Foot;
204     way.props=0;
205     break;
206 amb 298 default:
207     way.allow=0;
208     way.props=0;
209     break;
210 amb 73 }
211 amb 2
212 amb 314 if(way_allow_yes&Allow_Foot && !(way_allow_no&Allow_Wheelchair)) /* Allow wheelchair if foot allowed and wheelchair not disallowed. */
213     way_allow_yes|=Allow_Wheelchair;
214    
215 amb 298 if(way_allow_no) /* Remove the ones explicitly denied (e.g. private) */
216     way.allow&=~way_allow_no;
217 amb 2
218 amb 298 if(way_allow_yes) /* Add the ones explicitly allowed (e.g. footpath along private) */
219     way.allow|=way_allow_yes;
220 amb 30
221 amb 307 if(way.allow & profile->allow)
222 amb 298 {
223     char *refname;
224     int i;
225 amb 30
226 amb 298 if(way_oneway)
227     way.type|=Way_OneWay;
228 amb 30
229 amb 298 if(way_roundabout)
230     way.type|=Way_Roundabout;
231 amb 30
232 amb 307 if(profile->props_yes[Property_Paved])
233     {
234     if(way_paved>0)
235     way.props|=Properties_Paved;
236     else if(way_paved<0)
237     way.props&=~Properties_Paved;
238     }
239 amb 262
240 amb 308 if(profile->props_yes[Property_Multilane])
241     {
242     if(way_multilane>1)
243     way.props|=Properties_Multilane;
244     else if(way_paved==1)
245     way.props&=~Properties_Multilane;
246     }
247    
248 amb 313 if(profile->props_yes[Property_Bridge])
249     {
250     if(way_bridge)
251     way.props|=Properties_Bridge;
252     }
253    
254     if(profile->props_yes[Property_Tunnel])
255     {
256     if(way_tunnel)
257     way.props|=Properties_Tunnel;
258     }
259    
260 amb 298 if(way_ref && way_name)
261 amb 277 {
262 amb 298 refname=(char*)malloc(strlen(way_ref)+strlen(way_name)+4);
263     sprintf(refname,"%s (%s)",way_name,way_ref);
264 amb 277 }
265 amb 298 else if(way_ref && !way_name && way_roundabout)
266 amb 277 {
267 amb 298 refname=(char*)malloc(strlen(way_ref)+14);
268     sprintf(refname,"%s (roundabout)",way_ref);
269 amb 277 }
270 amb 298 else if(way_ref && !way_name)
271     refname=way_ref;
272     else if(!way_ref && way_name)
273     refname=way_name;
274     else if(way_roundabout)
275 amb 277 {
276 amb 298 refname=(char*)malloc(strlen(way_highway)+14);
277     sprintf(refname,"%s (roundabout)",way_highway);
278 amb 277 }
279 amb 298 else /* if(!way_ref && !way_name && !way_roundabout) */
280     refname=way_highway;
281    
282     way.speed =way_maxspeed;
283     way.weight=way_maxweight;
284     way.height=way_maxheight;
285     way.width =way_maxwidth;
286     way.length=way_maxlength;
287    
288     AppendWay(OSMWays,way_id,&way,refname);
289    
290     if(refname!=way_ref && refname!=way_name && refname!=way_highway)
291     free(refname);
292    
293     for(i=1;i<way_nnodes;i++)
294     {
295     node_t from=way_nodes[i-1];
296     node_t to =way_nodes[i];
297    
298     if(way_oneway>0)
299     {
300     AppendSegment(OSMSegments,way_id,from,to,ONEWAY_1TO2);
301     AppendSegment(OSMSegments,way_id,to,from,ONEWAY_2TO1);
302     }
303     else if(way_oneway<0)
304     {
305     AppendSegment(OSMSegments,way_id,from,to,ONEWAY_2TO1);
306     AppendSegment(OSMSegments,way_id,to,from,ONEWAY_1TO2);
307     }
308     else
309     {
310     AppendSegment(OSMSegments,way_id,from,to,0);
311     AppendSegment(OSMSegments,way_id,to,from,0);
312     }
313     }
314 amb 87 }
315 amb 73 }
316 amb 2 }
317    
318 amb 51 if(way_highway) free(way_highway);
319     if(way_name) free(way_name);
320     if(way_ref) free(way_ref);
321 amb 2 }
322     else if(!strncmp(l,"<relation",9)) /* The start of a relation */
323     {
324     nrelations++;
325    
326     isnode=0; isway=0; isrelation=1;
327     }
328     else if(!strncmp(l,"</relation",10)) /* The end of a relation */
329     {
330     isnode=0; isway=0; isrelation=0;
331     }
332     else if(isnode) /* The middle of a node */
333     {
334     }
335     else if(isway) /* The middle of a way */
336     {
337     node_t id;
338    
339     if(!strncmp(l,"<nd",3)) /* The start of a node specifier */
340     {
341     m=strstr(l,"ref="); m+=4; if(*m=='"' || *m=='\'') m++; id=atoll(m);
342    
343 amb 244 if(way_nnodes==way_nalloc)
344     way_nodes=(node_t*)realloc((void*)way_nodes,(way_nalloc+=256)*sizeof(node_t));
345 amb 2
346     way_nodes[way_nnodes++]=id;
347     }
348    
349     if(!strncmp(l,"<tag",4)) /* The start of a tag specifier */
350     {
351     char delimiter,*k="",*v="";
352    
353     m=strstr(l,"k="); m+=2; delimiter=*m; m++; k=m;
354     while(*m!=delimiter) m++; *m=0; l=m+1;
355    
356     m=strstr(l,"v="); m+=2; delimiter=*m; m++; v=m;
357     while(*m!=delimiter) m++; *m=0;
358    
359 amb 51 switch(*k)
360     {
361     case 'a':
362     if(!strcmp(k,"access"))
363 amb 136 {
364 amb 297 if(ISALLOWED(v))
365 amb 136 ;
366     else
367 amb 302 way_allow_no=Allow_ALL;
368 amb 136 }
369 amb 51 break;
370 amb 2
371 amb 51 case 'b':
372     if(!strcmp(k,"bicycle"))
373     {
374 amb 297 if(ISALLOWED(v))
375 amb 51 way_allow_yes|=Allow_Bicycle;
376     else
377 amb 297 way_allow_no |=Allow_Bicycle;
378 amb 51 }
379 amb 313
380     if(!strcmp(k,"bridge"))
381     way_bridge=ISTRUE(v);
382 amb 51 break;
383 amb 2
384 amb 297 case 'd':
385     if(!strcmp(k,"designation"))
386     {
387     if(!strcmp(v,"bridleway"))
388     way_allow_yes|=Allow_Foot|Allow_Horse|Allow_Bicycle;
389     else if(!strcmp(v,"byway"))
390     way_allow_yes|=Allow_Foot|Allow_Horse|Allow_Bicycle;
391     else if(!strcmp(v,"footpath"))
392     way_allow_yes|=Allow_Foot;
393     }
394     break;
395    
396 amb 51 case 'f':
397     if(!strcmp(k,"foot"))
398     {
399 amb 297 if(ISALLOWED(v))
400 amb 51 way_allow_yes|=Allow_Foot;
401     else
402 amb 297 way_allow_no |=Allow_Foot;
403 amb 51 }
404     break;
405 amb 2
406 amb 51 case 'g':
407     if(!strcmp(k,"goods"))
408     {
409 amb 297 if(ISALLOWED(v))
410 amb 51 way_allow_yes|=Allow_Goods;
411     else
412 amb 297 way_allow_no |=Allow_Goods;
413 amb 51 }
414     break;
415 amb 2
416 amb 51 case 'h':
417     if(!strcmp(k,"highway"))
418 amb 298 way_highway=strcpy((char*)malloc(strlen(v)+1),v);
419 amb 2
420 amb 51 if(!strcmp(k,"horse"))
421     {
422 amb 297 if(ISALLOWED(v))
423 amb 51 way_allow_yes|=Allow_Horse;
424     else
425 amb 297 way_allow_no |=Allow_Horse;
426 amb 51 }
427 amb 298
428 amb 51 if(!strcmp(k,"hgv"))
429     {
430 amb 297 if(ISALLOWED(v))
431 amb 51 way_allow_yes|=Allow_HGV;
432     else
433 amb 297 way_allow_no |=Allow_HGV;
434 amb 51 }
435     break;
436 amb 8
437 amb 51 case 'j':
438     if(!strcmp(k,"junction"))
439     if(!strcmp(v,"roundabout"))
440     {way_oneway=1; way_roundabout=1;}
441     break;
442    
443 amb 308 case 'l':
444     if(!strcmp(k,"lanes"))
445     way_multilane=atoi(v);
446    
447 amb 51 case 'm':
448     if(!strcmp(k,"maxspeed"))
449     {
450     if(strstr(v,"mph"))
451 amb 183 way_maxspeed=kph_to_speed(1.609*atof(v));
452 amb 136 else
453     way_maxspeed=kph_to_speed(atof(v));
454 amb 51 }
455 amb 298
456 amb 183 if(!strcmp(k,"maxspeed:mph"))
457     way_maxspeed=kph_to_speed(1.609*atof(v));
458 amb 298
459 amb 136 if(!strcmp(k,"maxweight"))
460     {
461     if(strstr(v,"kg"))
462     way_maxweight=tonnes_to_weight(atof(v)/1000);
463     else
464     way_maxweight=tonnes_to_weight(atof(v));
465     }
466 amb 298
467 amb 136 if(!strcmp(k,"maxheight"))
468     {
469 amb 183 if(strchr(v,'\''))
470     {
471     int feet,inches;
472    
473     if(sscanf(v,"%d'%d\"",&feet,&inches)==2)
474 amb 219 way_maxheight=metres_to_height((feet+(double)inches/12.0)*0.254);
475 amb 183 else if(sscanf(v,"%d'",&feet)==1)
476 amb 219 way_maxheight=metres_to_height((feet+(double)inches/12.0)*0.254);
477 amb 183 }
478     else if(strstr(v,"ft") || strstr(v,"feet"))
479 amb 136 way_maxheight=metres_to_height(atof(v)*0.254);
480     else
481     way_maxheight=metres_to_height(atof(v));
482     }
483 amb 298
484 amb 136 if(!strcmp(k,"maxwidth"))
485     {
486 amb 183 if(strchr(v,'\''))
487     {
488     int feet,inches;
489    
490     if(sscanf(v,"%d'%d\"",&feet,&inches)==2)
491 amb 219 way_maxwidth=metres_to_height((feet+(double)inches/12.0)*0.254);
492 amb 183 else if(sscanf(v,"%d'",&feet)==1)
493 amb 219 way_maxwidth=metres_to_height((feet+(double)inches/12.0)*0.254);
494 amb 183 }
495     else if(strstr(v,"ft") || strstr(v,"feet"))
496 amb 136 way_maxwidth=metres_to_width(atof(v)*0.254);
497     else
498     way_maxwidth=metres_to_width(atof(v));
499     }
500 amb 298
501 amb 136 if(!strcmp(k,"maxlength"))
502     {
503 amb 183 if(strchr(v,'\''))
504     {
505     int feet,inches;
506    
507     if(sscanf(v,"%d'%d\"",&feet,&inches)==2)
508 amb 219 way_maxlength=metres_to_height((feet+(double)inches/12.0)*0.254);
509 amb 183 else if(sscanf(v,"%d'",&feet)==1)
510 amb 219 way_maxlength=metres_to_height((feet+(double)inches/12.0)*0.254);
511 amb 183 }
512     else if(strstr(v,"ft") || strstr(v,"feet"))
513 amb 136 way_maxlength=metres_to_length(atof(v)*0.254);
514     else
515     way_maxlength=metres_to_length(atof(v));
516     }
517 amb 298
518 amb 296 if(!strcmp(k,"moped"))
519     {
520 amb 297 if(ISALLOWED(v))
521 amb 296 way_allow_yes|=Allow_Moped;
522     else
523 amb 297 way_allow_no |=Allow_Moped;
524 amb 296 }
525 amb 298
526 amb 51 if(!strcmp(k,"motorbike"))
527     {
528 amb 297 if(ISALLOWED(v))
529 amb 51 way_allow_yes|=Allow_Motorbike;
530     else
531 amb 297 way_allow_no |=Allow_Motorbike;
532 amb 51 }
533 amb 298
534 amb 51 if(!strcmp(k,"motorcar"))
535     {
536 amb 297 if(ISALLOWED(v))
537 amb 51 way_allow_yes|=Allow_Motorcar;
538     else
539 amb 297 way_allow_no |=Allow_Motorcar;
540 amb 51 }
541 amb 298
542 amb 196 if(!strcmp(k,"motor_vehicle"))
543     {
544 amb 297 if(ISALLOWED(v))
545 amb 296 way_allow_yes|=Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
546 amb 196 else
547 amb 297 way_allow_no |=Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
548 amb 196 }
549 amb 51 break;
550    
551     case 'n':
552     if(!strcmp(k,"name"))
553     way_name=strcpy((char*)malloc(strlen(v)+1),v);
554     break;
555    
556     case 'o':
557     if(!strcmp(k,"oneway"))
558 amb 117 {
559 amb 298 if(ISTRUE(v))
560 amb 51 way_oneway=1;
561 amb 117 else if(!strcmp(v,"-1"))
562     way_oneway=-1;
563     }
564 amb 51 break;
565    
566     case 'p':
567 amb 299 if(!strcmp(k,"paved"))
568     {
569     if(ISTRUE(v))
570     way_paved=1;
571     else
572     way_paved=-1;
573     }
574    
575 amb 51 if(!strcmp(k,"psv"))
576     {
577 amb 297 if(ISALLOWED(v))
578 amb 51 way_allow_yes|=Allow_PSV;
579     else
580 amb 297 way_allow_no |=Allow_PSV;
581 amb 51 }
582     break;
583    
584     case 'r':
585     if(!strcmp(k,"ref"))
586     way_ref=strcpy((char*)malloc(strlen(v)+1),v);
587     break;
588    
589 amb 298 case 's':
590     if(!strcmp(k,"surface"))
591     {
592     if(!strcmp(v,"paved") || !strcmp(v,"asphalt") || !strcmp(v,"concrete"))
593     way_paved=1;
594     else
595     way_paved=-1;
596     }
597     break;
598    
599 amb 313 case 't':
600     if(!strcmp(k,"tunnel"))
601     way_tunnel=ISTRUE(v);
602     break;
603    
604 amb 196 case 'v':
605     if(!strcmp(k,"vehicle"))
606     {
607 amb 297 if(ISALLOWED(v))
608 amb 296 way_allow_yes|=Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
609 amb 196 else
610 amb 297 way_allow_no |=Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
611 amb 196 }
612     break;
613    
614 amb 314 case 'w':
615     if(!strcmp(k,"wheelchair"))
616     {
617     if(ISALLOWED(v))
618     way_allow_yes|=Allow_Wheelchair;
619     else
620     way_allow_no |=Allow_Wheelchair;
621     }
622     break;
623    
624 amb 51 default:
625     ;
626 amb 2 }
627     }
628     }
629     else if(isrelation) /* The middle of a relation */
630     {
631     }
632    
633     if(!(nlines%10000))
634     {
635     printf("\rReading: Lines=%ld Nodes=%ld Ways=%ld Relations=%ld",nlines,nnodes,nways,nrelations);
636     fflush(stdout);
637     }
638     }
639    
640 amb 35 printf("\rRead: Lines=%ld Nodes=%ld Ways=%ld Relations=%ld \n",nlines,nnodes,nways,nrelations);
641 amb 2 fflush(stdout);
642    
643 amb 97 if(line)
644     free(line);
645    
646 amb 2 if(way_nalloc)
647     free(way_nodes);
648    
649     return(0);
650     }
651    
652    
653     /*++++++++++++++++++++++++++++++++++++++
654     Call fgets and realloc the buffer as needed to get a whole line.
655    
656     char *fgets_realloc Returns the modified buffer (NULL at the end of the file).
657    
658     char *buffer The current buffer.
659    
660     FILE *file The file to read from.
661     ++++++++++++++++++++++++++++++++++++++*/
662    
663     static char *fgets_realloc(char *buffer,FILE *file)
664     {
665     int n=0;
666     char *buf;
667    
668     if(!buffer)
669     buffer=(char*)malloc(BUFFSIZE+1);
670    
671     while((buf=fgets(&buffer[n],BUFFSIZE,file)))
672     {
673     int s=strlen(buf);
674     n+=s;
675    
676     if(buffer[n-1]=='\n')
677     break;
678     else
679     buffer=(char*)realloc(buffer,n+BUFFSIZE+1);
680     }
681    
682     if(!buf)
683     {free(buffer);buffer=NULL;}
684    
685     return(buffer);
686     }

Properties

Name Value
cvs:description OSM XML file parser.