Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/osmpbfparse.c
Parent Directory
|
Revision Log
Revision 1726 -
(show annotations)
(download)
(as text)
Wed Jul 1 18:11:36 2015 UTC (9 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 31397 byte(s)
Wed Jul 1 18:11:36 2015 UTC (9 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 31397 byte(s)
Merge changes from MS-Windows branch.
1 | /*************************************** |
2 | A simple osm-specific PBF parser where the structure is hard-coded. |
3 | |
4 | Part of the Routino routing software. |
5 | ******************/ /****************** |
6 | This file Copyright 2012-2015 Andrew M. Bishop |
7 | |
8 | This program is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU Affero General Public License as published by |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public License |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | ***************************************/ |
21 | |
22 | |
23 | #include <stdio.h> |
24 | |
25 | #if defined(_MSC_VER) |
26 | #include <io.h> |
27 | #include <basetsd.h> |
28 | #define read(fd,address,length) _read(fd,address,(unsigned int)(length)) |
29 | #define ssize_t SSIZE_T |
30 | #else |
31 | #include <unistd.h> |
32 | #endif |
33 | |
34 | #include <stdlib.h> |
35 | #include <stdint.h> |
36 | #include <string.h> |
37 | |
38 | #if defined(USE_GZIP) && USE_GZIP |
39 | #include <zlib.h> |
40 | #endif |
41 | |
42 | #include "osmparser.h" |
43 | #include "tagging.h" |
44 | #include "logging.h" |
45 | |
46 | |
47 | /* Inside a BlobHeader message */ |
48 | |
49 | #define PBF_VAL_BLOBHEADER_TYPE 1 |
50 | #define PBF_VAL_BLOBHEADER_SIZE 3 |
51 | |
52 | /* Inside a Blob message */ |
53 | |
54 | #define PBF_VAL_BLOB_RAW_DATA 1 |
55 | #define PBF_VAL_BLOB_RAW_SIZE 2 |
56 | #define PBF_VAL_BLOB_ZLIB_DATA 3 |
57 | |
58 | /* Inside a HeaderBlock message */ |
59 | |
60 | #define PBF_VAL_REQUIRED_FEATURES 4 |
61 | #define PBF_VAL_OPTIONAL_FEATURES 5 |
62 | |
63 | /* Inside a PrimitiveBlock message */ |
64 | |
65 | #define PBF_VAL_STRING_TABLE 1 |
66 | #define PBF_VAL_PRIMITIVE_GROUP 2 |
67 | #define PBF_VAL_GRANULARITY 17 |
68 | #define PBF_VAL_LAT_OFFSET 19 |
69 | #define PBF_VAL_LON_OFFSET 20 |
70 | |
71 | /* Inside a PrimitiveGroup message */ |
72 | |
73 | #define PBF_VAL_NODES 1 |
74 | #define PBF_VAL_DENSE_NODES 2 |
75 | #define PBF_VAL_WAYS 3 |
76 | #define PBF_VAL_RELATIONS 4 |
77 | |
78 | /* Inside a StringTable message */ |
79 | |
80 | #define PBF_VAL_STRING 1 |
81 | |
82 | /* Inside a Node message */ |
83 | |
84 | #define PBF_VAL_NODE_ID 1 |
85 | #define PBF_VAL_NODE_KEYS 2 |
86 | #define PBF_VAL_NODE_VALS 3 |
87 | #define PBF_VAL_NODE_LAT 8 |
88 | #define PBF_VAL_NODE_LON 9 |
89 | |
90 | /* Inside a DenseNode message */ |
91 | |
92 | #define PBF_VAL_DENSE_NODE_ID 1 |
93 | #define PBF_VAL_DENSE_NODE_LAT 8 |
94 | #define PBF_VAL_DENSE_NODE_LON 9 |
95 | #define PBF_VAL_DENSE_NODE_KEYS_VALS 10 |
96 | |
97 | /* Inside a Way message */ |
98 | |
99 | #define PBF_VAL_WAY_ID 1 |
100 | #define PBF_VAL_WAY_KEYS 2 |
101 | #define PBF_VAL_WAY_VALS 3 |
102 | #define PBF_VAL_WAY_REFS 8 |
103 | |
104 | /* Inside a Relation message */ |
105 | |
106 | #define PBF_VAL_RELATION_ID 1 |
107 | #define PBF_VAL_RELATION_KEYS 2 |
108 | #define PBF_VAL_RELATION_VALS 3 |
109 | #define PBF_VAL_RELATION_ROLES 8 |
110 | #define PBF_VAL_RELATION_MEMIDS 9 |
111 | #define PBF_VAL_RELATION_TYPES 10 |
112 | |
113 | /* Errors */ |
114 | |
115 | #define PBF_EOF 0 |
116 | |
117 | #define PBF_ERROR_UNEXP_EOF 100 |
118 | #define PBF_ERROR_BLOB_HEADER_LEN 101 |
119 | #define PBF_ERROR_BLOB_LEN 102 |
120 | #define PBF_ERROR_NOT_OSM 103 |
121 | #define PBF_ERROR_BLOB_BOTH 104 |
122 | #define PBF_ERROR_BLOB_NEITHER 105 |
123 | #define PBF_ERROR_NO_GZIP 106 |
124 | #define PBF_ERROR_GZIP_INIT 107 |
125 | #define PBF_ERROR_GZIP_INFLATE 108 |
126 | #define PBF_ERROR_GZIP_WRONG_LEN 109 |
127 | #define PBF_ERROR_GZIP_END 110 |
128 | #define PBF_ERROR_UNSUPPORTED 111 |
129 | #define PBF_ERROR_TOO_MANY_GROUPS 112 |
130 | |
131 | |
132 | /* Parsing variables and functions */ |
133 | |
134 | static uint64_t byteno=0; |
135 | static uint64_t nnodes=0,nways=0,nrelations=0; |
136 | |
137 | static uint32_t buffer_allocated,zbuffer_allocated; |
138 | static unsigned char *buffer=NULL,*zbuffer=NULL; |
139 | static unsigned char *buffer_ptr,*buffer_end; |
140 | |
141 | static int string_table_length=0,string_table_allocated=0; |
142 | static unsigned char **string_table=NULL; |
143 | static uint32_t *string_table_string_lengths=NULL; |
144 | |
145 | static int32_t granularity=100; |
146 | static int64_t lat_offset=0,lon_offset=0; |
147 | |
148 | #define LENGTH_32M (32*1024*1024) |
149 | |
150 | |
151 | /*++++++++++++++++++++++++++++++++++++++ |
152 | Refill the data buffer and set the pointers. |
153 | |
154 | int buffer_refill Return 0 if everything is OK or 1 for EOF. |
155 | |
156 | int fd The file descriptor to read from. |
157 | |
158 | uint32_t bytes The number of bytes to read. |
159 | ++++++++++++++++++++++++++++++++++++++*/ |
160 | |
161 | static inline int buffer_refill(int fd,uint32_t bytes) |
162 | { |
163 | ssize_t n; |
164 | |
165 | if(bytes>buffer_allocated) |
166 | buffer=(unsigned char *)realloc(buffer,buffer_allocated=bytes); |
167 | |
168 | byteno+=bytes; |
169 | |
170 | buffer_ptr=buffer; |
171 | buffer_end=buffer; |
172 | |
173 | do |
174 | { |
175 | n=read(fd,buffer_end,bytes); |
176 | |
177 | if(n<=0) |
178 | return(1); |
179 | |
180 | buffer_end+=n; |
181 | bytes-=n; |
182 | } |
183 | while(bytes>0); |
184 | |
185 | return(0); |
186 | } |
187 | |
188 | #if defined(USE_GZIP) && USE_GZIP |
189 | static int uncompress_pbf(unsigned char *data,uint32_t compressed,uint32_t uncompressed); |
190 | #endif /* USE_GZIP */ |
191 | |
192 | static void process_string_table(unsigned char *data,uint32_t length); |
193 | static void process_primitive_group(unsigned char *data,uint32_t length); |
194 | static void process_nodes(unsigned char *data,uint32_t length); |
195 | static void process_dense_nodes(unsigned char *data,uint32_t length); |
196 | static void process_ways(unsigned char *data,uint32_t length); |
197 | static void process_relations(unsigned char *data,uint32_t length); |
198 | |
199 | |
200 | /* Macros to simplify the parser (and make it look more like the XML parser) */ |
201 | |
202 | #define BEGIN(xx) do{ state=(xx); goto finish_parsing; } while(0) |
203 | |
204 | #define BUFFER_CHARS_EOF(xx) do{ if(buffer_refill(fd,(xx))) BEGIN(PBF_EOF); } while(0) |
205 | |
206 | #define BUFFER_CHARS(xx) do{ if(buffer_refill(fd,(xx))) BEGIN(PBF_ERROR_UNEXP_EOF); } while(0) |
207 | |
208 | |
209 | /* PBF decoding */ |
210 | |
211 | #define PBF_FIELD(xx) (int)(((xx)&0xFFF8)>>3) |
212 | #define PBF_TYPE(xx) (int)((xx)&0x0007) |
213 | |
214 | #define PBF_LATITUDE(xx) (double)(1E-9*(granularity*(xx)+lat_offset)) |
215 | #define PBF_LONGITUDE(xx) (double)(1E-9*(granularity*(xx)+lon_offset)) |
216 | |
217 | |
218 | /*++++++++++++++++++++++++++++++++++++++ |
219 | Parse a PBF int32 data value. |
220 | |
221 | uint32_t pbf_int32 Returns the integer value. |
222 | |
223 | unsigned char **ptr The pointer to read the data from. |
224 | ++++++++++++++++++++++++++++++++++++++*/ |
225 | |
226 | static inline uint32_t pbf_int32(unsigned char **ptr) |
227 | { |
228 | uint32_t result=(**ptr)&0x7F; |
229 | |
230 | if((**ptr)&0x80) result+=((*++(*ptr))&0x7F)<<7; |
231 | if((**ptr)&0x80) result+=((*++(*ptr))&0x7F)<<14; |
232 | if((**ptr)&0x80) result+=((*++(*ptr))&0x7F)<<21; |
233 | if((**ptr)&0x80) result+=((*++(*ptr))&0x7F)<<28; |
234 | |
235 | (*ptr)++; |
236 | |
237 | return(result); |
238 | } |
239 | |
240 | |
241 | /*++++++++++++++++++++++++++++++++++++++ |
242 | Parse a PBF int64 data value. |
243 | |
244 | int64_t pbf_int64 Returns the integer value. |
245 | |
246 | unsigned char **ptr The pointer to read the data from. |
247 | ++++++++++++++++++++++++++++++++++++++*/ |
248 | |
249 | static inline int64_t pbf_int64(unsigned char **ptr) |
250 | { |
251 | uint64_t result=(**ptr)&0x7F; |
252 | |
253 | if((**ptr)&0x80) result+=(uint64_t)((*++(*ptr))&0x7F)<<7; |
254 | if((**ptr)&0x80) result+=(uint64_t)((*++(*ptr))&0x7F)<<14; |
255 | if((**ptr)&0x80) result+=(uint64_t)((*++(*ptr))&0x7F)<<21; |
256 | if((**ptr)&0x80) result+=(uint64_t)((*++(*ptr))&0x7F)<<28; |
257 | if((**ptr)&0x80) result+=(uint64_t)((*++(*ptr))&0x7F)<<35; |
258 | if((**ptr)&0x80) result+=(uint64_t)((*++(*ptr))&0x7F)<<42; |
259 | if((**ptr)&0x80) result+=(uint64_t)((*++(*ptr))&0x7F)<<49; |
260 | if((**ptr)&0x80) result+=(uint64_t)((*++(*ptr))&0x7F)<<56; |
261 | if((**ptr)&0x80) result+=(uint64_t)((*++(*ptr))&0x7F)<<63; |
262 | |
263 | (*ptr)++; |
264 | |
265 | return(result); |
266 | } |
267 | |
268 | |
269 | /*++++++++++++++++++++++++++++++++++++++ |
270 | Parse a PBF sint64 data value. |
271 | |
272 | int64_t pbf_sint64 Returns the integer value. |
273 | |
274 | unsigned char **ptr The pointer to read the data from. |
275 | ++++++++++++++++++++++++++++++++++++++*/ |
276 | |
277 | static inline int64_t pbf_sint64(unsigned char **ptr) |
278 | { |
279 | int64_t result=((**ptr)&0x7E)>>1; |
280 | int sign=(**ptr)&0x01; |
281 | |
282 | if((**ptr)&0x80) result+=(int64_t)((*++(*ptr))&0x7F)<<6; |
283 | if((**ptr)&0x80) result+=(int64_t)((*++(*ptr))&0x7F)<<13; |
284 | if((**ptr)&0x80) result+=(int64_t)((*++(*ptr))&0x7F)<<20; |
285 | if((**ptr)&0x80) result+=(int64_t)((*++(*ptr))&0x7F)<<27; |
286 | if((**ptr)&0x80) result+=(int64_t)((*++(*ptr))&0x7F)<<34; |
287 | if((**ptr)&0x80) result+=(int64_t)((*++(*ptr))&0x7F)<<41; |
288 | if((**ptr)&0x80) result+=(int64_t)((*++(*ptr))&0x7F)<<48; |
289 | if((**ptr)&0x80) result+=(int64_t)((*++(*ptr))&0x7F)<<55; |
290 | if((**ptr)&0x80) result+=(int64_t)((*++(*ptr))&0x7F)<<62; |
291 | |
292 | (*ptr)++; |
293 | |
294 | if(sign) |
295 | result=-result-1; |
296 | |
297 | return(result); |
298 | } |
299 | |
300 | |
301 | /*++++++++++++++++++++++++++++++++++++++ |
302 | Parse a PBF length delimited data value. |
303 | |
304 | unsigned char *pbf_length_delimited Returns a pointer to the start of the data. |
305 | |
306 | unsigned char **ptr The pointer to read the data from. |
307 | |
308 | uint32_t *length Returns the length of the data. |
309 | ++++++++++++++++++++++++++++++++++++++*/ |
310 | |
311 | static inline unsigned char *pbf_length_delimited(unsigned char **ptr,uint32_t *length) |
312 | { |
313 | uint32_t len=pbf_int32(ptr); |
314 | |
315 | if(length) |
316 | *length=len; |
317 | |
318 | *ptr+=len; |
319 | |
320 | return(*ptr-len); |
321 | } |
322 | |
323 | |
324 | /*++++++++++++++++++++++++++++++++++++++ |
325 | Skip any pbf field from a message. |
326 | |
327 | unsigned char **ptr The pointer to read the data from. |
328 | |
329 | int type The type of the data. |
330 | ++++++++++++++++++++++++++++++++++++++*/ |
331 | |
332 | static inline void pbf_skip(unsigned char **ptr,int type) |
333 | { |
334 | uint32_t length; |
335 | |
336 | switch(type) |
337 | { |
338 | case 0: /* varint */ |
339 | while((**ptr)&0x80) (*ptr)++; |
340 | (*ptr)++; |
341 | break; |
342 | case 1: /* 64-bit */ |
343 | *ptr+=8; |
344 | break; |
345 | case 2: /* length delimited */ |
346 | length=pbf_int32(ptr); |
347 | *ptr+=length; |
348 | break; |
349 | case 3: /* deprecated */ |
350 | break; |
351 | case 4: /* deprecated */ |
352 | break; |
353 | case 5: /* 32-bit */ |
354 | *ptr+=4; |
355 | break; |
356 | } |
357 | } |
358 | |
359 | |
360 | /*++++++++++++++++++++++++++++++++++++++ |
361 | Parse the PBF and call the functions for each OSM item as seen. |
362 | |
363 | int ParsePBF Returns 0 if OK or something else in case of an error. |
364 | |
365 | int fd The file descriptor of the file to parse. |
366 | ++++++++++++++++++++++++++++++++++++++*/ |
367 | |
368 | static int ParsePBF(int fd) |
369 | { |
370 | int state; |
371 | unsigned char *error=NULL; |
372 | |
373 | /* Print the initial message */ |
374 | |
375 | printf_first("Reading: Bytes=0 Nodes=0 Ways=0 Relations=0"); |
376 | |
377 | /* The actual parser. */ |
378 | |
379 | nnodes=0,nways=0,nrelations=0; |
380 | |
381 | string_table_allocated=16384; |
382 | string_table_length=0; |
383 | string_table=(unsigned char **)malloc(string_table_allocated*sizeof(unsigned char *)); |
384 | string_table_string_lengths=(uint32_t *)malloc(string_table_allocated*sizeof(uint32_t)); |
385 | |
386 | zbuffer_allocated=0; |
387 | zbuffer=NULL; |
388 | |
389 | buffer_allocated=65536; |
390 | buffer=(unsigned char*)malloc(buffer_allocated); |
391 | |
392 | buffer_ptr=buffer_end=buffer; |
393 | |
394 | while(1) |
395 | { |
396 | int32_t blob_header_length=0; |
397 | int osm_data=0,osm_header=0; |
398 | int32_t blob_length=0; |
399 | uint32_t raw_size=0,compressed_size=0,uncompressed_size=0; |
400 | unsigned char *raw_data=NULL,*zlib_data=NULL; |
401 | uint32_t length; |
402 | unsigned char *data; |
403 | |
404 | /* ================ Parsing states ================ */ |
405 | |
406 | |
407 | BUFFER_CHARS_EOF(4); |
408 | |
409 | blob_header_length=(256*(256*(256*(int)buffer_ptr[0])+(int)buffer_ptr[1])+(int)buffer_ptr[2])+buffer_ptr[3]; |
410 | buffer_ptr+=4; |
411 | |
412 | if(blob_header_length==0 || blob_header_length>LENGTH_32M) |
413 | BEGIN(PBF_ERROR_BLOB_HEADER_LEN); |
414 | |
415 | |
416 | BUFFER_CHARS(blob_header_length); |
417 | |
418 | osm_header=0; |
419 | osm_data=0; |
420 | |
421 | while(buffer_ptr<buffer_end) |
422 | { |
423 | int fieldtype=pbf_int32(&buffer_ptr); |
424 | int field=PBF_FIELD(fieldtype); |
425 | |
426 | switch(field) |
427 | { |
428 | case PBF_VAL_BLOBHEADER_TYPE: /* string */ |
429 | { |
430 | uint32_t length=0; |
431 | unsigned char *type=NULL; |
432 | |
433 | type=pbf_length_delimited(&buffer_ptr,&length); |
434 | |
435 | if(length==9 && !strncmp((char*)type,"OSMHeader",9)) |
436 | osm_header=1; |
437 | |
438 | if(length==7 && !strncmp((char*)type,"OSMData",7)) |
439 | osm_data=1; |
440 | } |
441 | break; |
442 | |
443 | case PBF_VAL_BLOBHEADER_SIZE: /* int32 */ |
444 | blob_length=pbf_int32(&buffer_ptr); |
445 | break; |
446 | |
447 | default: |
448 | pbf_skip(&buffer_ptr,PBF_TYPE(fieldtype)); |
449 | } |
450 | } |
451 | |
452 | if(blob_length==0 || blob_length>LENGTH_32M) |
453 | BEGIN(PBF_ERROR_BLOB_LEN); |
454 | |
455 | if(!osm_data && !osm_header) |
456 | BEGIN(PBF_ERROR_NOT_OSM); |
457 | |
458 | |
459 | BUFFER_CHARS(blob_length); |
460 | |
461 | while(buffer_ptr<buffer_end) |
462 | { |
463 | int fieldtype=pbf_int32(&buffer_ptr); |
464 | int field=PBF_FIELD(fieldtype); |
465 | |
466 | switch(field) |
467 | { |
468 | case PBF_VAL_BLOB_RAW_DATA: /* bytes */ |
469 | raw_data=pbf_length_delimited(&buffer_ptr,&raw_size); |
470 | break; |
471 | |
472 | case PBF_VAL_BLOB_RAW_SIZE: /* int32 */ |
473 | uncompressed_size=pbf_int32(&buffer_ptr); |
474 | break; |
475 | |
476 | case PBF_VAL_BLOB_ZLIB_DATA: /* bytes */ |
477 | zlib_data=pbf_length_delimited(&buffer_ptr,&compressed_size); |
478 | break; |
479 | |
480 | default: |
481 | pbf_skip(&buffer_ptr,PBF_TYPE(fieldtype)); |
482 | } |
483 | } |
484 | |
485 | if(raw_data && zlib_data) |
486 | BEGIN(PBF_ERROR_BLOB_BOTH); |
487 | |
488 | if(!raw_data && !zlib_data) |
489 | BEGIN(PBF_ERROR_BLOB_NEITHER); |
490 | |
491 | if(zlib_data) |
492 | { |
493 | #if defined(USE_GZIP) && USE_GZIP |
494 | int newstate=uncompress_pbf(zlib_data,compressed_size,uncompressed_size); |
495 | |
496 | if(newstate) |
497 | BEGIN(newstate); |
498 | #else |
499 | BEGIN(PBF_ERROR_NO_GZIP); |
500 | #endif |
501 | } |
502 | else |
503 | { |
504 | buffer_ptr=raw_data; |
505 | buffer_end=raw_data+raw_size; |
506 | } |
507 | |
508 | |
509 | if(osm_header) |
510 | { |
511 | while(buffer_ptr<buffer_end) |
512 | { |
513 | int fieldtype=pbf_int32(&buffer_ptr); |
514 | int field=PBF_FIELD(fieldtype); |
515 | |
516 | switch(field) |
517 | { |
518 | case PBF_VAL_REQUIRED_FEATURES: /* string */ |
519 | { |
520 | uint32_t length=0; |
521 | unsigned char *feature=NULL; |
522 | |
523 | feature=pbf_length_delimited(&buffer_ptr,&length); |
524 | |
525 | if(strncmp((char*)feature,"OsmSchema-V0.6",14) && |
526 | strncmp((char*)feature,"DenseNodes",10)) |
527 | { |
528 | feature[length]=0; |
529 | error=feature; |
530 | BEGIN(PBF_ERROR_UNSUPPORTED); |
531 | } |
532 | } |
533 | break; |
534 | |
535 | case PBF_VAL_OPTIONAL_FEATURES: /* string */ |
536 | pbf_length_delimited(&buffer_ptr,NULL); |
537 | break; |
538 | |
539 | default: |
540 | pbf_skip(&buffer_ptr,PBF_TYPE(fieldtype)); |
541 | } |
542 | } |
543 | } |
544 | |
545 | |
546 | if(osm_data) |
547 | { |
548 | unsigned char *primitive_group[8]={NULL}; |
549 | uint32_t primitive_group_length[8]={0}; |
550 | uint32_t nprimitive_groups=0,i; |
551 | |
552 | granularity=100; |
553 | lat_offset=lon_offset=0; |
554 | |
555 | while(buffer_ptr<buffer_end) |
556 | { |
557 | int fieldtype=pbf_int32(&buffer_ptr); |
558 | int field=PBF_FIELD(fieldtype); |
559 | |
560 | switch(field) |
561 | { |
562 | case PBF_VAL_STRING_TABLE: /* bytes */ |
563 | data=pbf_length_delimited(&buffer_ptr,&length); |
564 | process_string_table(data,length); |
565 | break; |
566 | |
567 | case PBF_VAL_PRIMITIVE_GROUP: /* bytes */ |
568 | primitive_group[nprimitive_groups]=pbf_length_delimited(&buffer_ptr,&primitive_group_length[nprimitive_groups]); |
569 | |
570 | if(++nprimitive_groups>(sizeof(primitive_group)/sizeof(primitive_group[0]))) |
571 | BEGIN(PBF_ERROR_TOO_MANY_GROUPS); |
572 | break; |
573 | |
574 | case PBF_VAL_GRANULARITY: /* int32 */ |
575 | granularity=pbf_int32(&buffer_ptr); |
576 | break; |
577 | |
578 | case PBF_VAL_LAT_OFFSET: /* int64 */ |
579 | lat_offset=pbf_int64(&buffer_ptr); |
580 | break; |
581 | |
582 | case PBF_VAL_LON_OFFSET: /* int64 */ |
583 | lon_offset=pbf_int64(&buffer_ptr); |
584 | break; |
585 | |
586 | default: |
587 | pbf_skip(&buffer_ptr,PBF_TYPE(fieldtype)); |
588 | } |
589 | } |
590 | |
591 | if(nprimitive_groups) |
592 | for(i=0;i<nprimitive_groups;i++) |
593 | process_primitive_group(primitive_group[i],primitive_group_length[i]); |
594 | } |
595 | } |
596 | |
597 | |
598 | finish_parsing: |
599 | |
600 | switch(state) |
601 | { |
602 | /* End of file */ |
603 | |
604 | case PBF_EOF: |
605 | break; |
606 | |
607 | |
608 | /* ================ Error states ================ */ |
609 | |
610 | |
611 | case PBF_ERROR_UNEXP_EOF: |
612 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": unexpected end of file seen.\n",byteno); |
613 | break; |
614 | |
615 | case PBF_ERROR_BLOB_HEADER_LEN: |
616 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": BlobHeader length is wrong (0<x<=32M).\n",byteno); |
617 | break; |
618 | |
619 | case PBF_ERROR_BLOB_LEN: |
620 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": Blob length is wrong (0<x<=32M).\n",byteno); |
621 | break; |
622 | |
623 | case PBF_ERROR_NOT_OSM: |
624 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": BlobHeader is neither 'OSMData' or 'OSMHeader'.\n",byteno); |
625 | break; |
626 | |
627 | case PBF_ERROR_BLOB_BOTH: |
628 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": Blob has both zlib compressed and raw uncompressed data.\n",byteno); |
629 | break; |
630 | |
631 | case PBF_ERROR_BLOB_NEITHER: |
632 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": Blob has neither zlib compressed or raw uncompressed data.\n",byteno); |
633 | break; |
634 | |
635 | case PBF_ERROR_NO_GZIP: |
636 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": Blob is compressed but no gzip support is available.\n",byteno); |
637 | break; |
638 | |
639 | case PBF_ERROR_GZIP_INIT: |
640 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": Blob is compressed but failed to initialise decompression.\n",byteno); |
641 | break; |
642 | |
643 | case PBF_ERROR_GZIP_INFLATE: |
644 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": Blob is compressed but failed to uncompress it.\n",byteno); |
645 | break; |
646 | |
647 | case PBF_ERROR_GZIP_WRONG_LEN: |
648 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": Blob is compressed and wrong size when uncompressed.\n",byteno); |
649 | break; |
650 | |
651 | case PBF_ERROR_GZIP_END: |
652 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": Blob is compressed but failed to finalise decompression.\n",byteno); |
653 | break; |
654 | |
655 | case PBF_ERROR_UNSUPPORTED: |
656 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": Unsupported required feature '%s'.\n",byteno,error); |
657 | break; |
658 | |
659 | case PBF_ERROR_TOO_MANY_GROUPS: |
660 | fprintf(stderr,"PBF Parser: Error at byte %"PRIu64": OsmData message contains too many PrimitiveGroup messages.\n",byteno); |
661 | break; |
662 | } |
663 | |
664 | /* Free the parser variables */ |
665 | |
666 | free(string_table); |
667 | free(string_table_string_lengths); |
668 | |
669 | free(buffer); |
670 | if(zbuffer) |
671 | free(zbuffer); |
672 | |
673 | /* Print the final message */ |
674 | |
675 | printf_last("Read: Bytes=%"PRIu64" Nodes=%"PRIu64" Ways=%"PRIu64" Relations=%"PRIu64,byteno,nnodes,nways,nrelations); |
676 | |
677 | return(state); |
678 | } |
679 | |
680 | |
681 | /*++++++++++++++++++++++++++++++++++++++ |
682 | Process a PBF StringTable message. |
683 | |
684 | unsigned char *data The data to process. |
685 | |
686 | uint32_t length The length of the data. |
687 | ++++++++++++++++++++++++++++++++++++++*/ |
688 | |
689 | static void process_string_table(unsigned char *data,uint32_t length) |
690 | { |
691 | unsigned char *end=data+length; |
692 | unsigned char *string; |
693 | uint32_t string_length; |
694 | |
695 | string_table_length=0; |
696 | |
697 | while(data<end) |
698 | { |
699 | int fieldtype=pbf_int32(&data); |
700 | int field=PBF_FIELD(fieldtype); |
701 | |
702 | switch(field) |
703 | { |
704 | case PBF_VAL_STRING: /* string */ |
705 | string=pbf_length_delimited(&data,&string_length); |
706 | |
707 | if(string_table_length==string_table_allocated) |
708 | { |
709 | string_table_allocated+=8192; |
710 | string_table=(unsigned char **)realloc(string_table,string_table_allocated*sizeof(unsigned char *)); |
711 | string_table_string_lengths=(uint32_t *)realloc(string_table_string_lengths,string_table_allocated*sizeof(uint32_t)); |
712 | } |
713 | |
714 | string_table[string_table_length]=string; |
715 | string_table_string_lengths[string_table_length]=string_length; |
716 | |
717 | string_table_length++; |
718 | break; |
719 | |
720 | default: |
721 | pbf_skip(&data,PBF_TYPE(fieldtype)); |
722 | } |
723 | } |
724 | } |
725 | |
726 | |
727 | /*++++++++++++++++++++++++++++++++++++++ |
728 | Process a PBF PrimitiveGroup message. |
729 | |
730 | unsigned char *data The data to process. |
731 | |
732 | uint32_t length The length of the data. |
733 | ++++++++++++++++++++++++++++++++++++++*/ |
734 | |
735 | static void process_primitive_group(unsigned char *data,uint32_t length) |
736 | { |
737 | unsigned char *end=data+length; |
738 | unsigned char *subdata; |
739 | uint32_t sublength; |
740 | int i; |
741 | |
742 | /* Fixup the strings (not null terminated in buffer) */ |
743 | |
744 | for(i=0;i<string_table_length;i++) |
745 | string_table[i][string_table_string_lengths[i]]=0; |
746 | |
747 | |
748 | while(data<end) |
749 | { |
750 | int fieldtype=pbf_int32(&data); |
751 | int field=PBF_FIELD(fieldtype); |
752 | |
753 | switch(field) |
754 | { |
755 | case PBF_VAL_NODES: /* message */ |
756 | subdata=pbf_length_delimited(&data,&sublength); |
757 | process_nodes(subdata,sublength); |
758 | break; |
759 | |
760 | case PBF_VAL_DENSE_NODES: /* message */ |
761 | subdata=pbf_length_delimited(&data,&sublength); |
762 | process_dense_nodes(subdata,sublength); |
763 | break; |
764 | |
765 | case PBF_VAL_WAYS: /* message */ |
766 | subdata=pbf_length_delimited(&data,&sublength); |
767 | process_ways(subdata,sublength); |
768 | break; |
769 | |
770 | case PBF_VAL_RELATIONS: /* message */ |
771 | subdata=pbf_length_delimited(&data,&sublength); |
772 | process_relations(subdata,sublength); |
773 | break; |
774 | |
775 | default: |
776 | pbf_skip(&data,PBF_TYPE(fieldtype)); |
777 | } |
778 | } |
779 | } |
780 | |
781 | |
782 | /*++++++++++++++++++++++++++++++++++++++ |
783 | Process a PBF Node message. |
784 | |
785 | unsigned char *data The data to process. |
786 | |
787 | uint32_t length The length of the data. |
788 | ++++++++++++++++++++++++++++++++++++++*/ |
789 | |
790 | static void process_nodes(unsigned char *data,uint32_t length) |
791 | { |
792 | unsigned char *end=data+length; |
793 | int64_t id=0; |
794 | unsigned char *keys=NULL,*vals=NULL; |
795 | unsigned char *keys_end=NULL,*vals_end=NULL; |
796 | uint32_t keylen=0,vallen=0; |
797 | int64_t lat=0,lon=0; |
798 | TagList *tags=NULL,*result=NULL; |
799 | |
800 | while(data<end) |
801 | { |
802 | int fieldtype=pbf_int32(&data); |
803 | int field=PBF_FIELD(fieldtype); |
804 | |
805 | switch(field) |
806 | { |
807 | case PBF_VAL_NODE_ID: /* sint64 */ |
808 | id=pbf_sint64(&data); |
809 | break; |
810 | |
811 | case PBF_VAL_NODE_KEYS: /* packed int32 */ |
812 | keys=pbf_length_delimited(&data,&keylen); |
813 | keys_end=keys+keylen; |
814 | break; |
815 | |
816 | case PBF_VAL_NODE_VALS: /* packed int32 */ |
817 | vals=pbf_length_delimited(&data,&vallen); |
818 | vals_end=vals+vallen; |
819 | break; |
820 | |
821 | case PBF_VAL_NODE_LAT: /* sint64 */ |
822 | lat=pbf_sint64(&data); |
823 | break; |
824 | |
825 | case PBF_VAL_NODE_LON: /* sint64 */ |
826 | lon=pbf_sint64(&data); |
827 | break; |
828 | |
829 | default: |
830 | pbf_skip(&data,PBF_TYPE(fieldtype)); |
831 | } |
832 | } |
833 | |
834 | /* Mangle the data and send it to the OSM parser */ |
835 | |
836 | nnodes++; |
837 | |
838 | if(!(nnodes%10000)) |
839 | printf_middle("Reading: Bytes=%"PRIu64" Nodes=%"PRIu64" Ways=%"PRIu64" Relations=%"PRIu64,byteno,nnodes,nways,nrelations); |
840 | |
841 | tags=NewTagList(); |
842 | |
843 | if(keys && vals) |
844 | { |
845 | while(keys<keys_end && vals<vals_end) |
846 | { |
847 | uint32_t key=pbf_int32(&keys); |
848 | uint32_t val=pbf_int32(&vals); |
849 | |
850 | AppendTag(tags,(char*)string_table[key],(char*)string_table[val]); |
851 | } |
852 | } |
853 | |
854 | result=ApplyNodeTaggingRules(tags,id); |
855 | |
856 | ProcessNodeTags(result,id,PBF_LATITUDE(lat),PBF_LONGITUDE(lon),MODE_NORMAL); |
857 | |
858 | DeleteTagList(tags); |
859 | DeleteTagList(result); |
860 | } |
861 | |
862 | |
863 | /*++++++++++++++++++++++++++++++++++++++ |
864 | Process a PBF DenseNode message. |
865 | |
866 | unsigned char *data The data to process. |
867 | |
868 | uint32_t length The length of the data. |
869 | ++++++++++++++++++++++++++++++++++++++*/ |
870 | |
871 | static void process_dense_nodes(unsigned char *data,uint32_t length) |
872 | { |
873 | unsigned char *end=data+length; |
874 | unsigned char *ids=NULL,*keys_vals=NULL,*lats=NULL,*lons=NULL; |
875 | unsigned char *ids_end=NULL; |
876 | uint32_t idlen=0; |
877 | int64_t id=0; |
878 | int64_t lat=0,lon=0; |
879 | TagList *tags=NULL,*result; |
880 | |
881 | while(data<end) |
882 | { |
883 | int fieldtype=pbf_int32(&data); |
884 | int field=PBF_FIELD(fieldtype); |
885 | |
886 | switch(field) |
887 | { |
888 | case PBF_VAL_DENSE_NODE_ID: /* packed sint64 */ |
889 | ids=pbf_length_delimited(&data,&idlen); |
890 | ids_end=ids+idlen; |
891 | break; |
892 | |
893 | case PBF_VAL_DENSE_NODE_LAT: /* packed sint64 */ |
894 | lats=pbf_length_delimited(&data,NULL); |
895 | break; |
896 | |
897 | case PBF_VAL_DENSE_NODE_LON: /* packed sint64 */ |
898 | lons=pbf_length_delimited(&data,NULL); |
899 | break; |
900 | |
901 | case PBF_VAL_DENSE_NODE_KEYS_VALS: /* packed int32 */ |
902 | keys_vals=pbf_length_delimited(&data,NULL); |
903 | break; |
904 | |
905 | default: |
906 | pbf_skip(&data,PBF_TYPE(fieldtype)); |
907 | } |
908 | } |
909 | |
910 | while(ids<ids_end) |
911 | { |
912 | int64_t delta_id; |
913 | int64_t delta_lat,delta_lon; |
914 | |
915 | delta_id=pbf_sint64(&ids); |
916 | delta_lat=pbf_sint64(&lats); |
917 | delta_lon=pbf_sint64(&lons); |
918 | |
919 | id+=delta_id; |
920 | lat+=delta_lat; |
921 | lon+=delta_lon; |
922 | |
923 | /* Mangle the data and send it to the OSM parser */ |
924 | |
925 | nnodes++; |
926 | |
927 | if(!(nnodes%10000)) |
928 | printf_middle("Reading: Bytes=%"PRIu64" Nodes=%"PRIu64" Ways=%"PRIu64" Relations=%"PRIu64,byteno,nnodes,nways,nrelations); |
929 | |
930 | tags=NewTagList(); |
931 | |
932 | if(keys_vals) |
933 | { |
934 | while(1) |
935 | { |
936 | uint32_t key=pbf_int32(&keys_vals),val; |
937 | |
938 | if(key==0) |
939 | break; |
940 | |
941 | val=pbf_int32(&keys_vals); |
942 | |
943 | AppendTag(tags,(char*)string_table[key],(char*)string_table[val]); |
944 | } |
945 | } |
946 | |
947 | result=ApplyNodeTaggingRules(tags,id); |
948 | |
949 | ProcessNodeTags(result,id,PBF_LATITUDE(lat),PBF_LONGITUDE(lon),MODE_NORMAL); |
950 | |
951 | DeleteTagList(tags); |
952 | DeleteTagList(result); |
953 | } |
954 | } |
955 | |
956 | |
957 | /*++++++++++++++++++++++++++++++++++++++ |
958 | Process a PBF Way message. |
959 | |
960 | unsigned char *data The data to process. |
961 | |
962 | uint32_t length The length of the data. |
963 | ++++++++++++++++++++++++++++++++++++++*/ |
964 | |
965 | static void process_ways(unsigned char *data,uint32_t length) |
966 | { |
967 | unsigned char *end=data+length; |
968 | int64_t id=0; |
969 | unsigned char *keys=NULL,*vals=NULL,*refs=NULL; |
970 | unsigned char *keys_end=NULL,*vals_end=NULL,*refs_end=NULL; |
971 | uint32_t keylen=0,vallen=0,reflen=0; |
972 | int64_t ref=0; |
973 | TagList *tags=NULL,*result; |
974 | |
975 | while(data<end) |
976 | { |
977 | int fieldtype=pbf_int32(&data); |
978 | int field=PBF_FIELD(fieldtype); |
979 | |
980 | switch(field) |
981 | { |
982 | case PBF_VAL_WAY_ID: /* int64 */ |
983 | id=pbf_int64(&data); |
984 | break; |
985 | |
986 | case PBF_VAL_WAY_KEYS: /* packed int32 */ |
987 | keys=pbf_length_delimited(&data,&keylen); |
988 | keys_end=keys+keylen; |
989 | break; |
990 | |
991 | case PBF_VAL_WAY_VALS: /* packed int32 */ |
992 | vals=pbf_length_delimited(&data,&vallen); |
993 | vals_end=vals+vallen; |
994 | break; |
995 | |
996 | case PBF_VAL_WAY_REFS: /* packed sint64 */ |
997 | refs=pbf_length_delimited(&data,&reflen); |
998 | refs_end=refs+reflen; |
999 | break; |
1000 | |
1001 | default: |
1002 | pbf_skip(&data,PBF_TYPE(fieldtype)); |
1003 | } |
1004 | } |
1005 | |
1006 | /* Mangle the data and send it to the OSM parser */ |
1007 | |
1008 | nways++; |
1009 | |
1010 | if(!(nways%1000)) |
1011 | printf_middle("Reading: Bytes=%"PRIu64" Nodes=%"PRIu64" Ways=%"PRIu64" Relations=%"PRIu64,byteno,nnodes,nways,nrelations); |
1012 | |
1013 | tags=NewTagList(); |
1014 | |
1015 | if(keys && vals) |
1016 | { |
1017 | while(keys<keys_end && vals<vals_end) |
1018 | { |
1019 | uint32_t key=pbf_int32(&keys); |
1020 | uint32_t val=pbf_int32(&vals); |
1021 | |
1022 | AppendTag(tags,(char*)string_table[key],(char*)string_table[val]); |
1023 | } |
1024 | } |
1025 | |
1026 | AddWayRefs(0); |
1027 | |
1028 | if(refs) |
1029 | while(refs<refs_end) |
1030 | { |
1031 | int64_t delta_ref; |
1032 | |
1033 | delta_ref=pbf_sint64(&refs); |
1034 | |
1035 | ref+=delta_ref; |
1036 | |
1037 | if(ref==0) |
1038 | break; |
1039 | |
1040 | AddWayRefs(ref); |
1041 | } |
1042 | |
1043 | result=ApplyWayTaggingRules(tags,id); |
1044 | |
1045 | ProcessWayTags(result,id,MODE_NORMAL); |
1046 | |
1047 | DeleteTagList(tags); |
1048 | DeleteTagList(result); |
1049 | } |
1050 | |
1051 | |
1052 | /*++++++++++++++++++++++++++++++++++++++ |
1053 | Process a PBF Relation message. |
1054 | |
1055 | unsigned char *data The data to process. |
1056 | |
1057 | uint32_t length The length of the data. |
1058 | ++++++++++++++++++++++++++++++++++++++*/ |
1059 | |
1060 | static void process_relations(unsigned char *data,uint32_t length) |
1061 | { |
1062 | unsigned char *end=data+length; |
1063 | int64_t id=0; |
1064 | unsigned char *keys=NULL,*vals=NULL,*roles=NULL,*memids=NULL,*types=NULL; |
1065 | unsigned char *keys_end=NULL,*vals_end=NULL,*memids_end=NULL,*types_end=NULL; |
1066 | uint32_t keylen=0,vallen=0,rolelen=0,memidlen=0,typelen=0; |
1067 | int64_t memid=0; |
1068 | TagList *tags=NULL,*result; |
1069 | |
1070 | while(data<end) |
1071 | { |
1072 | int fieldtype=pbf_int32(&data); |
1073 | int field=PBF_FIELD(fieldtype); |
1074 | |
1075 | switch(field) |
1076 | { |
1077 | case PBF_VAL_RELATION_ID: /* int64 */ |
1078 | id=pbf_int64(&data); |
1079 | break; |
1080 | |
1081 | case PBF_VAL_RELATION_KEYS: /* packed string */ |
1082 | keys=pbf_length_delimited(&data,&keylen); |
1083 | keys_end=keys+keylen; |
1084 | break; |
1085 | |
1086 | case PBF_VAL_RELATION_VALS: /* packed string */ |
1087 | vals=pbf_length_delimited(&data,&vallen); |
1088 | vals_end=vals+vallen; |
1089 | break; |
1090 | |
1091 | case PBF_VAL_RELATION_ROLES: /* packed int32 */ |
1092 | roles=pbf_length_delimited(&data,&rolelen); |
1093 | break; |
1094 | |
1095 | case PBF_VAL_RELATION_MEMIDS: /* packed sint64 */ |
1096 | memids=pbf_length_delimited(&data,&memidlen); |
1097 | memids_end=memids+memidlen; |
1098 | break; |
1099 | |
1100 | case PBF_VAL_RELATION_TYPES: /* packed enum */ |
1101 | types=pbf_length_delimited(&data,&typelen); |
1102 | types_end=types+typelen; |
1103 | break; |
1104 | |
1105 | default: |
1106 | pbf_skip(&data,PBF_TYPE(fieldtype)); |
1107 | } |
1108 | } |
1109 | |
1110 | /* Mangle the data and send it to the OSM parser */ |
1111 | |
1112 | nrelations++; |
1113 | |
1114 | if(!(nrelations%1000)) |
1115 | printf_middle("Reading: Bytes=%"PRIu64" Nodes=%"PRIu64" Ways=%"PRIu64" Relations=%"PRIu64,byteno,nnodes,nways,nrelations); |
1116 | |
1117 | AddRelationRefs(0,0,0,NULL); |
1118 | |
1119 | tags=NewTagList(); |
1120 | |
1121 | if(keys && vals) |
1122 | { |
1123 | while(keys<keys_end && vals<vals_end) |
1124 | { |
1125 | uint32_t key=pbf_int32(&keys); |
1126 | uint32_t val=pbf_int32(&vals); |
1127 | |
1128 | AppendTag(tags,(char*)string_table[key],(char*)string_table[val]); |
1129 | } |
1130 | } |
1131 | |
1132 | if(memids && types) |
1133 | while(memids<memids_end && types<types_end) |
1134 | { |
1135 | int64_t delta_memid; |
1136 | unsigned char *role=NULL; |
1137 | int type; |
1138 | |
1139 | delta_memid=pbf_sint64(&memids); |
1140 | type=pbf_int32(&types); |
1141 | |
1142 | if(roles) |
1143 | role=string_table[pbf_int32(&roles)]; |
1144 | |
1145 | memid+=delta_memid; |
1146 | |
1147 | if(type==0) |
1148 | AddRelationRefs(memid,0,0,(char*)role); |
1149 | else if(type==1) |
1150 | AddRelationRefs(0,memid,0,(char*)role); |
1151 | else if(type==2) |
1152 | AddRelationRefs(0,0,memid,(char*)role); |
1153 | } |
1154 | |
1155 | result=ApplyRelationTaggingRules(tags,id); |
1156 | |
1157 | ProcessRelationTags(result,id,MODE_NORMAL); |
1158 | |
1159 | DeleteTagList(tags); |
1160 | DeleteTagList(result); |
1161 | } |
1162 | |
1163 | |
1164 | #if defined(USE_GZIP) && USE_GZIP |
1165 | |
1166 | /*++++++++++++++++++++++++++++++++++++++ |
1167 | Uncompress the part of the PBF data that is compressed. |
1168 | |
1169 | int uncompress_pbf Returns the error state or 0 if OK. |
1170 | |
1171 | unsigned char *data The data to uncompress. |
1172 | |
1173 | uint32_t compressed The number of bytes to uncompress. |
1174 | |
1175 | uint32_t uncompressed The number of bytes expected when uncompressed. |
1176 | ++++++++++++++++++++++++++++++++++++++*/ |
1177 | |
1178 | static int uncompress_pbf(unsigned char *data,uint32_t compressed,uint32_t uncompressed) |
1179 | { |
1180 | z_stream z={0}; |
1181 | |
1182 | if(uncompressed>zbuffer_allocated) |
1183 | zbuffer=(unsigned char *)realloc(zbuffer,zbuffer_allocated=uncompressed); |
1184 | |
1185 | if(inflateInit2(&z,15+32)!=Z_OK) |
1186 | return(PBF_ERROR_GZIP_INIT); |
1187 | |
1188 | z.next_in=data; |
1189 | z.avail_in=compressed; |
1190 | |
1191 | z.next_out=zbuffer; |
1192 | z.avail_out=uncompressed; |
1193 | |
1194 | if(inflate(&z,Z_FINISH)!=Z_STREAM_END) |
1195 | return(PBF_ERROR_GZIP_INFLATE); |
1196 | |
1197 | if(z.avail_out!=0) |
1198 | return(PBF_ERROR_GZIP_WRONG_LEN); |
1199 | |
1200 | if(inflateEnd(&z)!=Z_OK) |
1201 | return(PBF_ERROR_GZIP_END); |
1202 | |
1203 | buffer_ptr=zbuffer; |
1204 | buffer_end=zbuffer+uncompressed; |
1205 | |
1206 | return(0); |
1207 | } |
1208 | |
1209 | #endif /* USE_GZIP */ |
1210 | |
1211 | |
1212 | /*++++++++++++++++++++++++++++++++++++++ |
1213 | Parse a PBF format OSM file (from planet download). |
1214 | |
1215 | int ParsePBFFile Returns 0 if OK or something else in case of an error. |
1216 | |
1217 | int fd The file descriptor of the file to read from. |
1218 | |
1219 | NodesX *OSMNodes The data structure of nodes to fill in. |
1220 | |
1221 | WaysX *OSMWays The data structure of ways to fill in. |
1222 | |
1223 | RelationsX *OSMRelations The data structure of relations to fill in. |
1224 | ++++++++++++++++++++++++++++++++++++++*/ |
1225 | |
1226 | int ParsePBFFile(int fd,NodesX *OSMNodes,WaysX *OSMWays,RelationsX *OSMRelations) |
1227 | { |
1228 | int retval; |
1229 | |
1230 | /* Initialise the parser */ |
1231 | |
1232 | InitialiseParser(OSMNodes,OSMWays,OSMRelations); |
1233 | |
1234 | /* Parse the file */ |
1235 | |
1236 | retval=ParsePBF(fd); |
1237 | |
1238 | /* Cleanup the parser */ |
1239 | |
1240 | CleanupParser(); |
1241 | |
1242 | return(retval); |
1243 | } |