/[zanavi_public1]/navit/navit/maptool/osm.c
ZANavi

Diff of /navit/navit/maptool/osm.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 35 Revision 36
21#include <stdlib.h> 21#include <stdlib.h>
22#include <math.h> 22#include <math.h>
23#include "maptool.h" 23#include "maptool.h"
24#include "debug.h" 24#include "debug.h"
25#include "linguistics.h" 25#include "linguistics.h"
26#include "country.h"
26#include "file.h" 27#include "file.h"
28
29#define _FILE_OFFSET_BITS 64
30#define _LARGEFILE_SOURCE
31#define _LARGEFILE64_SOURCE
32
33extern int doway2poi;
27 34
28static int in_way, in_node, in_relation; 35static int in_way, in_node, in_relation;
29static int nodeid,wayid; 36static int nodeid,wayid;
30long long current_id; 37long long current_id;
31 38
60 enum item_type type; 67 enum item_type type;
61 int attr_present_idx_count; 68 int attr_present_idx_count;
62 int attr_present_idx[0]; 69 int attr_present_idx[0];
63}; 70};
64 71
72static void nodes_ref_item_bin(struct item_bin *ib);
73
74
65static struct attr_mapping **attr_mapping_node; 75static struct attr_mapping **attr_mapping_node;
66static int attr_mapping_node_count; 76static int attr_mapping_node_count;
67static struct attr_mapping **attr_mapping_way; 77static struct attr_mapping **attr_mapping_way;
68static int attr_mapping_way_count; 78static int attr_mapping_way_count;
79static struct attr_mapping **attr_mapping_way2poi;
80static int attr_mapping_way2poi_count;
69 81
70static char *attr_present; 82static char *attr_present;
71static int attr_present_count; 83static int attr_present_count;
72 84
73 85
96#define SET_REF(c,ref) do { (c).x = 1 << 30; (c).y = ref ; } while(0) 108#define SET_REF(c,ref) do { (c).x = 1 << 30; (c).y = ref ; } while(0)
97 109
98struct country_table { 110struct country_table {
99 int countryid; 111 int countryid;
100 char *names; 112 char *names;
113 char *admin_levels;
101 FILE *file; 114 FILE *file;
102 int size; 115 int size;
103 struct rect r; 116 struct rect r;
104} country_table[] = { 117} country_table[] = {
105 { 4,"Afghanistan"}, 118 { 4,"Afghanistan"},
183 { 262,"Djibouti"}, 196 { 262,"Djibouti"},
184 { 266,"Gabon"}, 197 { 266,"Gabon"},
185 { 268,"Georgia"}, 198 { 268,"Georgia"},
186 { 270,"Gambia"}, 199 { 270,"Gambia"},
187 { 275,"Palestinian Territory, Occupied"}, 200 { 275,"Palestinian Territory, Occupied"},
188 { 276,"Germany,Deutschland,Bundesrepublik Deutschland"}, 201 { 276,"Germany,Deutschland,Bundesrepublik Deutschland","345c7m"},
189 { 288,"Ghana"}, 202 { 288,"Ghana"},
190 { 292,"Gibraltar"}, 203 { 292,"Gibraltar"},
191 { 296,"Kiribati"}, 204 { 296,"Kiribati"},
192 { 300,"Greece"}, 205 { 300,"Greece"},
193 { 304,"Greenland"}, 206 { 304,"Greenland"},
349 { 887,"Yemen"}, 362 { 887,"Yemen"},
350 { 894,"Zambia"}, 363 { 894,"Zambia"},
351 { 999,"Unknown"}, 364 { 999,"Unknown"},
352}; 365};
353 366
367// first char - item type
368// =w - ways
369// =? - used both for nodes and ways
370// otherwise - nodes
354 371
372
373// for coastline-only map
355static char *attrmap={ 374static char *attrmap_cl={
356 "n *=* point_unkn\n" 375 "n *=* point_unkn\n"
376 "w *=* street_unkn\n"
377 "w natural=coastline water_line\n"
378};
379
380// for border-only map
381static char *attrmap_bo={
382 "n *=* point_unkn\n"
383 "w *=* street_unkn\n"
384 "w boundary=administrative,admin_level=2 border_country\n"
385 "w boundary=territorial,admin_level=2 border_country\n"
386 "w boundary=maritime,admin_level=2 border_country\n"
387 "w administrative=boundary,admin_level=2 border_country\n"
388 "w boundary=administrative,maritime=yes,admin_level=4 border_country\n"
389 "w boundary=administrative,border_type=state,admin_level=4 border_country\n"
390};
391
392// ==========================
393// for USA
394// ==========================
395// admin_level = 4
396// border_type = state
397// boundary = administrative
398// ==========================
399
400
401// for normal map
402static char *attrmap_normal={
403 "n *=* point_unkn\n"
357// "n Annehmlichkeit=Hochsitz poi_hunting_stand\n" 404//// "n Annehmlichkeit=Hochsitz poi_hunting_stand\n"
358 "n addr:housenumber=* house_number\n" 405 "n addr:housenumber=* house_number\n"
359 "n aeroway=aerodrome poi_airport\n" 406 "n aeroway=aerodrome poi_airport\n"
360 "n aeroway=airport poi_airport\n" 407 "n aeroway=airport poi_airport\n"
361 "n aeroway=helipad poi_heliport\n" 408 "n aeroway=helipad poi_heliport\n"
362 "n aeroway=terminal poi_airport\n" 409 "n aeroway=terminal poi_airport\n"
363 "n amenity=atm poi_bank\n" 410 "n amenity=atm poi_bank\n"
364 "n amenity=bank poi_bank\n" 411 "n amenity=bank poi_bank\n"
365 "n amenity=bar poi_bar\n" 412 "n amenity=bar poi_bar\n"
366 "n amenity=bench poi_bench\n" 413 //"n amenity=bench poi_bench\n"
367 "n amenity=biergarten poi_biergarten\n" 414 "n amenity=biergarten poi_biergarten\n"
368 "n amenity=bus_station poi_bus_station\n" 415 "n amenity=bus_station poi_bus_station\n"
369 "n amenity=cafe poi_cafe\n" 416 "n amenity=cafe poi_cafe\n"
370 "n amenity=car_wash poi_car_wash\n" 417 "n amenity=car_wash poi_car_wash\n"
371 "n amenity=cinema poi_cinema\n" 418 "n amenity=cinema poi_cinema\n"
372 "n amenity=college poi_school_college\n" 419 "n amenity=college poi_school_college\n"
373 "n amenity=courthouse poi_justice\n" 420 "n amenity=courthouse poi_justice\n"
374 "n amenity=drinking_water poi_potable_water\n" 421 //"n amenity=drinking_water poi_potable_water\n"
375 "n amenity=fast_food poi_fastfood\n" 422 "n amenity=fast_food poi_fastfood\n"
376 "n amenity=fire_station poi_firebrigade\n" 423 "n amenity=fire_station poi_firebrigade\n"
377 "n amenity=fountain poi_fountain\n" 424 //"n amenity=fountain poi_fountain\n"
378 "n amenity=fuel poi_fuel\n" 425 "n amenity=fuel poi_fuel\n"
379 "n amenity=grave_yard poi_cemetery\n" 426 "n amenity=grave_yard poi_cemetery\n"
380 "n amenity=hospital poi_hospital\n" 427 "n amenity=hospital poi_hospital\n"
381 "n amenity=hunting_stand poi_hunting_stand\n" 428 //"n amenity=hunting_stand poi_hunting_stand\n"
382 "n amenity=kindergarten poi_kindergarten\n" 429 "n amenity=kindergarten poi_kindergarten\n"
383 "n amenity=library poi_library\n" 430 "n amenity=library poi_library\n"
384 "n amenity=nightclub poi_nightclub\n" 431 "n amenity=nightclub poi_nightclub\n"
385 "n amenity=park_bench poi_bench\n" 432 //"n amenity=park_bench poi_bench\n"
386 "n amenity=parking poi_car_parking\n" 433 "n amenity=parking poi_car_parking\n"
387 "n amenity=pharmacy poi_pharmacy\n" 434 "n amenity=pharmacy poi_pharmacy\n"
388 "n amenity=place_of_worship,religion=christian poi_church\n" 435 "n amenity=place_of_worship,religion=christian poi_church\n"
389 "n amenity=place_of_worship poi_worship\n" 436 "n amenity=place_of_worship poi_worship\n"
390 "n amenity=police poi_police\n" 437 "n amenity=police poi_police\n"
391 "n amenity=post_box poi_post_box\n" 438 //"n amenity=post_box poi_post_box\n"
392 "n amenity=post_office poi_post_office\n" 439 "n amenity=post_office poi_post_office\n"
393 "n amenity=prison poi_prison\n" 440 "n amenity=prison poi_prison\n"
394 "n amenity=pub poi_pub\n" 441 "n amenity=pub poi_pub\n"
395 "n amenity=public_building poi_public_office\n" 442 "n amenity=public_building poi_public_office\n"
396 "n amenity=recycling poi_recycling\n" 443 //"n amenity=recycling poi_recycling\n"
397 "n amenity=restaurant,cuisine=fine_dining poi_dining\n" 444 "n amenity=restaurant,cuisine=fine_dining poi_dining\n"
398 "n amenity=restaurant poi_restaurant\n" 445 "n amenity=restaurant poi_restaurant\n"
399 "n amenity=school poi_school\n" 446 "n amenity=school poi_school\n"
400 "n amenity=shelter poi_shelter\n" 447 //"n amenity=shelter poi_shelter\n"
401 "n amenity=taxi poi_taxi\n" 448 "n amenity=taxi poi_taxi\n"
402 "n amenity=tec_common tec_common\n" 449 //"n amenity=tec_common tec_common\n"
403 "n amenity=telephone poi_telephone\n" 450 //"n amenity=telephone poi_telephone\n"
404 "n amenity=theatre poi_theater\n" 451 "n amenity=theatre poi_theater\n"
405 "n amenity=toilets poi_restroom\n" 452 "n amenity=toilets poi_restroom\n"
406 "n amenity=townhall poi_townhall\n" 453 "n amenity=townhall poi_townhall\n"
407 "n amenity=university poi_school_university\n" 454 "n amenity=university poi_school_university\n"
408 "n amenity=vending_machine poi_vending_machine\n" 455 //"n amenity=vending_machine poi_vending_machine\n"
409 "n barrier=bollard barrier_bollard\n" 456 "n barrier=bollard barrier_bollard\n"
410 "n barrier=cycle_barrier barrier_cycle\n" 457 "n barrier=cycle_barrier barrier_cycle\n"
411 "n barrier=lift_gate barrier_lift_gate\n" 458 "n barrier=lift_gate barrier_lift_gate\n"
412 "n car=car_rental poi_car_rent\n" 459 //"n car=car_rental poi_car_rent\n"
413 "n highway=bus_station poi_bus_station\n" 460 "n highway=bus_station poi_bus_station\n"
414 "n highway=bus_stop poi_bus_stop\n" 461 "n highway=bus_stop poi_bus_stop\n"
415 "n highway=mini_roundabout mini_roundabout\n" 462 "n highway=mini_roundabout mini_roundabout\n"
416 "n highway=motorway_junction highway_exit\n" 463 "n highway=motorway_junction highway_exit\n"
417 "n highway=stop traffic_sign_stop\n" 464 "n highway=stop traffic_sign_stop\n"
418 "n highway=toll_booth poi_toll_booth\n" 465 "n highway=toll_booth poi_toll_booth\n"
419 "n highway=traffic_signals traffic_signals\n" 466 "n highway=traffic_signals traffic_signals\n"
420 "n highway=turning_circle turning_circle\n" 467 "n highway=turning_circle turning_circle\n"
421 "n historic=boundary_stone poi_boundary_stone\n" 468 //"n historic=boundary_stone poi_boundary_stone\n"
422 "n historic=castle poi_castle\n" 469 "n historic=castle poi_castle\n"
423 "n historic=memorial poi_memorial\n" 470 "n historic=memorial poi_memorial\n"
424 "n historic=monument poi_monument\n" 471 "n historic=monument poi_monument\n"
425 "n historic=ruins poi_ruins\n" 472 "n historic=ruins poi_ruins\n"
426// "n historic=* poi_ruins\n" 473//// "n historic=* poi_ruins\n"
427 "n landuse=cemetery poi_cemetery\n" 474 "n landuse=cemetery poi_cemetery\n"
428 "n leisure=fishing poi_fish\n" 475 //"n leisure=fishing poi_fish\n"
429 "n leisure=golf_course poi_golf\n" 476 "n leisure=golf_course poi_golf\n"
430 "n leisure=marina poi_marine\n" 477 "n leisure=marina poi_marine\n"
431 "n leisure=playground poi_playground\n" 478 //"n leisure=playground poi_playground\n"
432 "n leisure=slipway poi_boat_ramp\n" 479 //"n leisure=slipway poi_boat_ramp\n"
433 "n leisure=sports_centre poi_sport\n" 480 //"n leisure=sports_centre poi_sport\n"
434 "n leisure=stadium poi_stadium\n" 481 "n leisure=stadium poi_stadium\n"
435 "n man_made=tower poi_tower\n" 482 //"n man_made=tower poi_tower\n"
436 "n military=airfield poi_military\n" 483 "n military=airfield poi_military\n"
437 "n military=barracks poi_military\n" 484 //"n military=barracks poi_military\n"
438 "n military=bunker poi_military\n" 485 //"n military=bunker poi_military\n"
439 "n military=danger_area poi_danger_area\n" 486 "n military=danger_area poi_danger_area\n"
440 "n military=range poi_military\n" 487 "n military=range poi_military\n"
441 "n natural=bay poi_bay\n" 488 "n natural=bay poi_bay\n"
442 "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation 489 "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation
443 "n natural=tree poi_tree\n" 490 //"n natural=tree poi_tree\n"
444 "n place=city town_label_2e5\n" 491 "n place=city town_label_2e5\n"
445 "n place=hamlet town_label_2e2\n" 492 "n place=hamlet town_label_2e2\n"
446 "n place=locality town_label_2e0\n" 493 "n place=locality town_label_2e0\n"
447 "n place=suburb district_label\n" 494 "n place=suburb district_label\n"
448 "n place=town town_label_2e4\n" 495 "n place=town town_label_2e4\n"
449 "n place=village town_label_2e3\n" 496 "n place=village town_label_2e3\n"
450 "n power=tower power_tower\n" 497 //"n power=tower power_tower\n"
451 "n power=sub_station power_substation\n" 498 //"n power=sub_station power_substation\n"
452 "n railway=halt poi_rail_halt\n" 499 "n railway=halt poi_rail_halt\n"
453 "n railway=level_crossing poi_level_crossing\n" 500 "n railway=level_crossing poi_level_crossing\n"
454 "n railway=station poi_rail_station\n" 501 "n railway=station poi_rail_station\n"
455 "n railway=tram_stop poi_rail_tram_stop\n" 502 "n railway=tram_stop poi_rail_tram_stop\n"
456 "n shop=baker poi_shop_baker\n" 503 //"n shop=baker poi_shop_baker\n"
457 "n shop=bakery poi_shop_baker\n" 504 //"n shop=bakery poi_shop_baker\n"
458 "n shop=beverages poi_shop_beverages\n" 505 //"n shop=beverages poi_shop_beverages\n"
459 "n shop=bicycle poi_shop_bicycle\n" 506 //"n shop=bicycle poi_shop_bicycle\n"
460 "n shop=butcher poi_shop_butcher\n" 507 //"n shop=butcher poi_shop_butcher\n"
461 "n shop=car poi_car_dealer_parts\n" 508 "n shop=car poi_car_dealer_parts\n"
462 "n shop=car_repair poi_repair_service\n" 509 "n shop=car_repair poi_repair_service\n"
463 "n shop=clothes poi_shop_apparel\n" 510 //"n shop=clothes poi_shop_apparel\n"
464 "n shop=convenience poi_shop_grocery\n" 511 //"n shop=convenience poi_shop_grocery\n"
465 "n shop=drogist poi_shop_drugstore\n" 512 //"n shop=drogist poi_shop_drugstore\n"
466 "n shop=florist poi_shop_florist\n" 513 //"n shop=florist poi_shop_florist\n"
467 "n shop=fruit poi_shop_fruit\n" 514 //"n shop=fruit poi_shop_fruit\n"
468 "n shop=furniture poi_shop_furniture\n" 515 //"n shop=furniture poi_shop_furniture\n"
469 "n shop=garden_centre poi_shop_handg\n" 516 //"n shop=garden_centre poi_shop_handg\n"
470 "n shop=hardware poi_shop_handg\n" 517 //"n shop=hardware poi_shop_handg\n"
471 "n shop=hairdresser poi_hairdresser\n" 518 //"n shop=hairdresser poi_hairdresser\n"
472 "n shop=kiosk poi_shop_kiosk\n" 519 //"n shop=kiosk poi_shop_kiosk\n"
473 "n shop=optician poi_shop_optician\n" 520 //"n shop=optician poi_shop_optician\n"
474 "n shop=parfum poi_shop_parfum\n" 521 //"n shop=parfum poi_shop_parfum\n"
475 "n shop=photo poi_shop_photo\n" 522 //"n shop=photo poi_shop_photo\n"
476 "n shop=shoes poi_shop_shoes\n" 523 //"n shop=shoes poi_shop_shoes\n"
477 "n shop=supermarket poi_shopping\n" 524 "n shop=supermarket poi_shopping\n"
478 "n sport=10pin poi_bowling\n" 525 //"n sport=10pin poi_bowling\n"
479 "n sport=baseball poi_baseball\n" 526 //"n sport=baseball poi_baseball\n"
480 "n sport=basketball poi_basketball\n" 527 //"n sport=basketball poi_basketball\n"
481 "n sport=climbing poi_climbing\n" 528 //"n sport=climbing poi_climbing\n"
482 "n sport=golf poi_golf\n" 529 //"n sport=golf poi_golf\n"
483 "n sport=motor_sports poi_motor_sport\n" 530 //"n sport=motor_sports poi_motor_sport\n"
484 "n sport=skiing poi_skiing\n" 531 //"n sport=skiing poi_skiing\n"
485 "n sport=soccer poi_soccer\n" 532 //"n sport=soccer poi_soccer\n"
486 "n sport=stadium poi_stadium\n" 533 "n sport=stadium poi_stadium\n"
487 "n sport=swimming poi_swimming\n" 534 "n sport=swimming poi_swimming\n"
488 "n sport=tennis poi_tennis\n" 535 //"n sport=tennis poi_tennis\n"
489 "n tourism=attraction poi_attraction\n" 536 "n tourism=attraction poi_attraction\n"
490 "n tourism=camp_site poi_camp_rv\n" 537 "n tourism=camp_site poi_camp_rv\n"
491 "n tourism=caravan_site poi_camp_rv\n" 538 "n tourism=caravan_site poi_camp_rv\n"
492 "n tourism=guest_house poi_guesthouse\n" 539 "n tourism=guest_house poi_guesthouse\n"
493 "n tourism=hostel poi_hostel\n" 540 "n tourism=hostel poi_hostel\n"
494 "n tourism=hotel poi_hotel\n" 541 "n tourism=hotel poi_hotel\n"
495 "n tourism=information poi_information\n" 542 "n tourism=information poi_information\n"
496 "n tourism=motel poi_motel\n" 543 "n tourism=motel poi_motel\n"
497 "n tourism=museum poi_museum_history\n" 544 "n tourism=museum poi_museum_history\n"
498 "n tourism=picnic_site poi_picnic\n" 545 //"n tourism=picnic_site poi_picnic\n"
499 "n tourism=theme_park poi_resort\n" 546 "n tourism=theme_park poi_resort\n"
500 "n tourism=viewpoint poi_viewpoint\n" 547 //"n tourism=viewpoint poi_viewpoint\n"
501 "n tourism=zoo poi_zoo\n" 548 "n tourism=zoo poi_zoo\n"
502 "n traffic_sign=city_limit traffic_sign_city_limit\n" 549 "n traffic_sign=city_limit traffic_sign_city_limit\n"
503 "n highway=speed_camera tec_common\n" 550 "n highway=speed_camera tec_common\n"
504 "w *=* street_unkn\n" 551 "w *=* street_unkn\n"
505 "w addr:interpolation=even house_number_interpolation_even\n" 552 "w addr:interpolation=even house_number_interpolation_even\n"
506 "w addr:interpolation=odd house_number_interpolation_odd\n" 553 "w addr:interpolation=odd house_number_interpolation_odd\n"
507 "w addr:interpolation=all house_number_interpolation_all\n" 554 "w addr:interpolation=all house_number_interpolation_all\n"
508 "w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n" 555 "w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n"
509 "w aerialway=cable_car lift_cable_car\n" 556 //"w aerialway=cable_car lift_cable_car\n"
510 "w aerialway=chair_lift lift_chair\n" 557 //"w aerialway=chair_lift lift_chair\n"
511 "w aerialway=drag_lift lift_drag\n" 558 //"w aerialway=drag_lift lift_drag\n"
512 "w aeroway=aerodrome poly_airport\n" 559 "w aeroway=aerodrome poly_airport\n"
513 "w aeroway=apron poly_apron\n" 560 "w aeroway=apron poly_apron\n"
514 "w aeroway=runway aeroway_runway\n" 561 "w aeroway=runway aeroway_runway\n"
515 "w aeroway=taxiway aeroway_taxiway\n" 562 "w aeroway=taxiway aeroway_taxiway\n"
516 "w aeroway=terminal poly_terminal\n" 563 "w aeroway=terminal poly_terminal\n"
517 "w amenity=college poly_college\n" 564 "w amenity=college poly_college\n"
518 "w amenity=grave_yard poly_cemetery\n" 565 //"w amenity=grave_yard poly_cemetery\n"
519 "w amenity=parking poly_car_parking\n" 566 "w amenity=parking poly_car_parking\n"
520 "w amenity=place_of_worship poly_building\n" 567 "w amenity=place_of_worship poly_building\n"
521 "w amenity=university poly_university\n" 568 "w amenity=university poly_university\n"
522 "w boundary=administrative,admin_level=2 border_country\n" 569 // "w boundary=administrative,admin_level=2 border_country\n" --> in border map
523 "w boundary=civil border_civil\n" 570 //"w boundary=civil border_civil\n"
524 "w boundary=national_park border_national_park\n" 571 "w boundary=national_park border_national_park\n"
525 "w boundary=political border_political\n" 572 "w boundary=political border_political\n"
526 "w building=* poly_building\n" 573 "w building=* poly_building\n"
527 "w contour_ext=elevation_major height_line_1\n" 574 "w contour_ext=elevation_major height_line_1\n"
528 "w contour_ext=elevation_medium height_line_2\n" 575 "w contour_ext=elevation_medium height_line_2\n"
542 "w highway=path,bicycle=official cycleway\n" 589 "w highway=path,bicycle=official cycleway\n"
543 "w highway=path,foot=designated footway\n" 590 "w highway=path,foot=designated footway\n"
544 "w highway=path,foot=official footway\n" 591 "w highway=path,foot=official footway\n"
545 "w highway=path,horse=designated bridleway\n" 592 "w highway=path,horse=designated bridleway\n"
546 "w highway=path,horse=official bridleway\n" 593 "w highway=path,horse=official bridleway\n"
547 "w highway=path,sac_scale=alpine_hiking hiking_alpine\n" 594 //"w highway=path,sac_scale=alpine_hiking hiking_alpine\n"
548 "w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n" 595 //"w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n"
549 "w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n" 596 //"w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n"
550 "w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n" 597 //"w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n"
551 "w highway=path,sac_scale=hiking hiking\n" 598 //"w highway=path,sac_scale=hiking hiking\n"
552 "w highway=path,sac_scale=mountain_hiking hiking_mountain\n" 599 //"w highway=path,sac_scale=mountain_hiking hiking_mountain\n"
553 "w highway=pedestrian street_pedestrian\n" 600 "w highway=pedestrian street_pedestrian\n"
554 "w highway=pedestrian,area=1 poly_pedestrian\n" 601 "w highway=pedestrian,area=1 poly_pedestrian\n"
555 "w highway=plaza poly_plaza\n" 602 "w highway=plaza poly_plaza\n"
556 "w highway=motorway highway_land\n" 603 "w highway=motorway highway_land\n"
557 "w highway=motorway,rural=0 highway_city\n" 604 "w highway=motorway,rural=0 highway_city\n"
606 "w highway=steps steps\n" 653 "w highway=steps steps\n"
607 "w historic=archaeological_site poly_archaeological_site\n" 654 "w historic=archaeological_site poly_archaeological_site\n"
608 "w historic=battlefield poly_battlefield\n" 655 "w historic=battlefield poly_battlefield\n"
609 "w historic=ruins poly_ruins\n" 656 "w historic=ruins poly_ruins\n"
610 "w historic=town gate poly_building\n" 657 "w historic=town gate poly_building\n"
611 "w landuse=allotments poly_allotments\n" 658 //"w landuse=allotments poly_allotments\n"
612 "w landuse=basin poly_basin\n" 659 //"w landuse=basin poly_basin\n"
613 "w landuse=brownfield poly_brownfield\n" 660 //"w landuse=brownfield poly_brownfield\n"
614 "w landuse=cemetery poly_cemetery\n" 661 "w landuse=cemetery poly_cemetery\n"
615 "w landuse=commercial poly_commercial\n" 662 //"w landuse=commercial poly_commercial\n"
616 "w landuse=construction poly_construction\n" 663 //"w landuse=construction poly_construction\n"
617 "w landuse=farm poly_farm\n" 664 //"w landuse=farm poly_farm\n"
618 "w landuse=farmland poly_farm\n" 665 //"w landuse=farmland poly_farm\n"
619 "w landuse=farmyard poly_town\n" 666 //"w landuse=farmyard poly_town\n"
620 "w landuse=forest poly_wood\n" 667 "w landuse=forest poly_wood\n"
621 "w landuse=greenfield poly_greenfield\n" 668 "w landuse=greenfield poly_greenfield\n"
622 "w landuse=industrial poly_industry\n" 669 //"w landuse=industrial poly_industry\n"
623 "w landuse=landfill poly_landfill\n" 670 //"w landuse=landfill poly_landfill\n"
624 "w landuse=military poly_military\n" 671 "w landuse=military poly_military\n"
625 "w landuse=plaza poly_plaza\n" 672 "w landuse=plaza poly_plaza\n"
626 "w landuse=quarry poly_quarry\n" 673 //"w landuse=quarry poly_quarry\n"
627 "w landuse=railway poly_railway\n" 674 "w landuse=railway poly_railway\n"
628 "w landuse=recreation_ground poly_recreation_ground\n" 675 //"w landuse=recreation_ground poly_recreation_ground\n"
629 "w landuse=reservoir poly_reservoir\n" 676 "w landuse=reservoir poly_reservoir\n"
630 "w landuse=residential poly_town\n" 677 //"w landuse=residential poly_town\n"
631 "w landuse=residential,area=1 poly_town\n" 678 //"w landuse=residential,area=1 poly_town\n"
632 "w landuse=retail poly_retail\n" 679 //"w landuse=retail poly_retail\n"
633 "w landuse=village_green poly_village_green\n" 680 //"w landuse=village_green poly_village_green\n"
634 "w landuse=vineyard poly_farm\n" 681 //"w landuse=vineyard poly_farm\n"
635 "w leisure=common poly_common\n" 682 //"w leisure=common poly_common\n"
636 "w leisure=fishing poly_fishing\n" 683 //"w leisure=fishing poly_fishing\n"
637 "w leisure=garden poly_garden\n" 684 //"w leisure=garden poly_garden\n"
638 "w leisure=golf_course poly_golf_course\n" 685 //"w leisure=golf_course poly_golf_course\n"
639 "w leisure=marina poly_marina\n" 686 //"w leisure=marina poly_marina\n"
640 "w leisure=nature_reserve poly_nature_reserve\n" 687 //"w leisure=nature_reserve poly_nature_reserve\n"
641 "w leisure=park poly_park\n" 688 "w leisure=park poly_park\n"
642 "w leisure=pitch poly_sports_pitch\n" 689 //"w leisure=pitch poly_sports_pitch\n"
643 "w leisure=playground poly_playground\n" 690 "w leisure=playground poly_playground\n"
644 "w leisure=sports_centre poly_sport\n" 691 //"w leisure=sports_centre poly_sport\n"
645 "w leisure=stadium poly_sports_stadium\n" 692 "w leisure=stadium poly_sports_stadium\n"
646 "w leisure=track poly_sports_track\n" 693 //"w leisure=track poly_sports_track\n"
647 "w leisure=water_park poly_water_park\n" 694 "w leisure=water_park poly_water_park\n"
648 "w military=airfield poly_airfield\n" 695 "w military=airfield poly_airfield\n"
649 "w military=barracks poly_barracks\n" 696 //"w military=barracks poly_barracks\n"
650 "w military=danger_area poly_danger_area\n" 697 "w military=danger_area poly_danger_area\n"
651 "w military=naval_base poly_naval_base\n" 698 "w military=naval_base poly_naval_base\n"
652 "w military=range poly_range\n" 699 //"w military=range poly_range\n"
653 "w natural=beach poly_beach\n" 700 "w natural=beach poly_beach\n"
654 "w natural=coastline water_line\n" 701 // "w natural=coastline water_line\n" --> in coastline map
655 "w natural=fell poly_fell\n" 702 "w natural=fell poly_fell\n"
656 "w natural=glacier poly_glacier\n" 703 "w natural=glacier poly_glacier\n"
657 "w natural=heath poly_heath\n" 704 "w natural=heath poly_heath\n"
658 "w natural=land poly_land\n" 705 "w natural=land poly_land\n"
659 "w natural=marsh poly_marsh\n" 706 "w natural=marsh poly_marsh\n"
660 "w natural=mud poly_mud\n" 707 "w natural=mud poly_mud\n"
661 "w natural=scree poly_scree\n" 708 "w natural=scree poly_scree\n"
662 "w natural=scrub poly_scrub\n" 709 "w natural=scrub poly_scrub\n"
663 "w natural=water poly_water\n" 710 "w natural=water poly_water\n"
664 "w natural=wood poly_wood\n" 711 "w natural=wood poly_wood\n"
665 "w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n" 712 //"w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n"
666 "w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n" 713 //"w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n"
667 "w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n" 714 //"w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n"
668 "w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n" 715 //"w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n"
669 "w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n" 716 //"w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n"
670 "w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n" 717 //"w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n"
671 "w piste:type=nordic piste_nordic\n" 718 //"w piste:type=nordic piste_nordic\n"
672 "w place=suburb poly_place1\n" 719 "w place=suburb poly_place1\n"
673 "w place=hamlet poly_place2\n" 720 "w place=hamlet poly_place2\n"
674 "w place=village poly_place3\n" 721 "w place=village poly_place3\n"
675 "w place=municipality poly_place4\n" 722 "w place=municipality poly_place4\n"
676 "w place=town poly_place5\n" 723 "w place=town poly_place5\n"
677 "w place=city poly_place6\n" 724 "w place=city poly_place6\n"
678 "w power=line powerline\n" 725 //"w power=line powerline\n"
679 "w railway=abandoned rail_abandoned\n" 726 //"w railway=abandoned rail_abandoned\n"
680 "w railway=disused rail_disused\n" 727 //"w railway=disused rail_disused\n"
681 "w railway=light_rail rail_light\n" 728 //"w railway=light_rail rail_light\n"
682 "w railway=monorail rail_mono\n" 729 //"w railway=monorail rail_mono\n"
683 "w railway=narrow_gauge rail_narrow_gauge\n" 730 //"w railway=narrow_gauge rail_narrow_gauge\n"
684 "w railway=preserved rail_preserved\n" 731 //"w railway=preserved rail_preserved\n"
685 "w railway=rail rail\n" 732 "w railway=rail rail\n"
686 "w railway=subway rail_subway\n" 733 "w railway=subway rail_subway\n"
687 "w railway=tram rail_tram\n" 734 "w railway=tram rail_tram\n"
688 "w route=ferry ferry\n" 735 "w route=ferry ferry\n"
689 "w route=ski piste_nordic\n" 736 //"w route=ski piste_nordic\n"
690 "w sport=* poly_sport\n" 737 //"w sport=* poly_sport\n"
691 "w tourism=artwork poly_artwork\n" 738 "w tourism=artwork poly_artwork\n"
692 "w tourism=attraction poly_attraction\n" 739 "w tourism=attraction poly_attraction\n"
693 "w tourism=camp_site poly_camp_site\n" 740 "w tourism=camp_site poly_camp_site\n"
694 "w tourism=caravan_site poly_caravan_site\n" 741 "w tourism=caravan_site poly_caravan_site\n"
695 "w tourism=picnic_site poly_picnic_site\n" 742 "w tourism=picnic_site poly_picnic_site\n"
707 "w barrier=retaining_wall retaining_wall\n" 754 "w barrier=retaining_wall retaining_wall\n"
708 "w barrier=city_wall city_wall\n" 755 "w barrier=city_wall city_wall\n"
709}; 756};
710 757
711 758
759
712static void 760static void
713build_attrmap_line(char *line) 761build_attrmap_line(char *line)
714{ 762{
715 char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv; 763 char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv;
716 struct attr_mapping ***attr_mapping_curr,*attr_mapping=g_malloc0(sizeof(struct attr_mapping)); 764 struct attr_mapping *attr_mapping=g_malloc0(sizeof(struct attr_mapping));
717 int idx,attr_mapping_count=0,*attr_mapping_curr_count; 765 int idx,attr_mapping_count=0;
718 t=line; 766 t=line;
719 p=strchr(t,'\t'); 767 p=strchr(t,'\t');
720 if (p) { 768 if (p) {
721 while (*p == '\t') 769 while (*p == '\t')
722 *p++='\0'; 770 *p++='\0';
729 i=p; 777 i=p;
730 } 778 }
731 if (t[0] == 'w') { 779 if (t[0] == 'w') {
732 if (! i) 780 if (! i)
733 i="street_unkn"; 781 i="street_unkn";
734 attr_mapping_curr=&attr_mapping_way;
735 attr_mapping_curr_count=&attr_mapping_way_count;
736 } else { 782 } else {
737 if (! i) 783 if (! i)
738 i="point_unkn"; 784 i="point_unkn";
739 attr_mapping_curr=&attr_mapping_node;
740 attr_mapping_curr_count=&attr_mapping_node_count;
741 } 785 }
742 attr_mapping->type=item_from_name(i); 786 attr_mapping->type=item_from_name(i);
787 if (!attr_mapping->type) {
788 printf("no id found for '%s'\n",i);
789 }
743 while ((kv=strtok(kvl, ","))) { 790 while ((kv=strtok(kvl, ","))) {
744 kvl=NULL; 791 kvl=NULL;
745 if (!(idx=(int)(long)g_hash_table_lookup(attr_hash, kv))) { 792 if (!(idx=(int)(long)g_hash_table_lookup(attr_hash, kv))) {
746 idx=attr_present_count++; 793 idx=attr_present_count++;
747 g_hash_table_insert(attr_hash, kv, (gpointer)(long)idx); 794 g_hash_table_insert(attr_hash, kv, (gpointer)(long)idx);
748 } 795 }
749 attr_mapping=g_realloc(attr_mapping, sizeof(struct attr_mapping)+(attr_mapping_count+1)*sizeof(int)); 796 attr_mapping=g_realloc(attr_mapping, sizeof(struct attr_mapping)+(attr_mapping_count+1)*sizeof(int));
750 attr_mapping->attr_present_idx[attr_mapping_count++]=idx; 797 attr_mapping->attr_present_idx[attr_mapping_count++]=idx;
751 attr_mapping->attr_present_idx_count=attr_mapping_count; 798 attr_mapping->attr_present_idx_count=attr_mapping_count;
752 } 799 }
753 *attr_mapping_curr=g_realloc(*attr_mapping_curr, sizeof(**attr_mapping_curr)*(*attr_mapping_curr_count+1)); 800 if (t[0]== 'w') {
801 attr_mapping_way=g_realloc(attr_mapping_way, sizeof(*attr_mapping_way)*(attr_mapping_way_count+1));
754 (*attr_mapping_curr)[(*attr_mapping_curr_count)++]=attr_mapping; 802 attr_mapping_way[attr_mapping_way_count++]=attr_mapping;
803 }
804 if (t[0]== '?' && doway2poi) {
805 attr_mapping_way2poi=g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi)*(attr_mapping_way2poi_count+1));
806 attr_mapping_way2poi[attr_mapping_way2poi_count++]=attr_mapping;
807 }
808 if (t[0]!= 'w') {
809 attr_mapping_node=g_realloc(attr_mapping_node, sizeof(*attr_mapping_node)*(attr_mapping_node_count+1));
810 attr_mapping_node[attr_mapping_node_count++]=attr_mapping;
811 }
812
755} 813}
756 814
757static void 815static void
758build_attrmap(FILE* rule_file) 816build_attrmap(FILE* rule_file)
759{ 817{
773 fclose( rule_file ); 831 fclose( rule_file );
774 } 832 }
775 // use hardcoded default attributes 833 // use hardcoded default attributes
776 else 834 else
777 { 835 {
778 char *p,*map=g_strdup(attrmap); 836 char *p,*map;
837 if (border_only_map==1)
838 {
839 map=g_strdup(attrmap_bo);
840 }
841 else if (coastline_only_map==1)
842 {
843 map=g_strdup(attrmap_cl);
844 }
845 else
846 {
847 map=g_strdup(attrmap_normal);
848 }
849
779 while (map) { 850 while (map) {
780 p=strchr(map,'\n'); 851 p=strchr(map,'\n');
781 if (p) 852 if (p)
782 *p++='\0'; 853 *p++='\0';
783 if (strlen(map)) 854 if (strlen(map))
802 str=NULL; 873 str=NULL;
803 g_hash_table_insert(country_table_hash, tok, (gpointer)&country_table[i]); 874 g_hash_table_insert(country_table_hash, tok, (gpointer)&country_table[i]);
804 } 875 }
805 } 876 }
806} 877}
807static void 878
879void
808osm_warning(char *type, long long id, int cont, char *fmt, ...) 880osm_warning(char *type, long long id, int cont, char *fmt, ...)
809{ 881{
810 char str[4096]; 882 char str[4096];
811 va_list ap; 883 va_list ap;
812 va_start(ap, fmt); 884 va_start(ap, fmt);
813 vsnprintf(str, sizeof(str), fmt, ap); 885 vsnprintf(str, sizeof(str), fmt, ap);
814 va_end(ap); 886 va_end(ap);
815 fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Warning:",type,id,str); 887 fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Warning:",type,id,str);
816} 888}
817 889
890void
891osm_info(char *type, long long id, int cont, char *fmt, ...)
892{
893 char str[4096];
894 va_list ap;
895 va_start(ap, fmt);
896 vsnprintf(str, sizeof(str), fmt, ap);
897 va_end(ap);
898 fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Info:",type,id,str);
899}
900
818static void 901static void
819attr_strings_clear(void) 902attr_strings_clear(void)
820{ 903{
821 attr_strings_buffer_len=0; 904 attr_strings_buffer_len=0;
822 memset(attr_strings, 0, sizeof(attr_strings)); 905 memset(attr_strings, 0, sizeof(attr_strings));
828 attr_strings[id]=attr_strings_buffer+attr_strings_buffer_len; 911 attr_strings[id]=attr_strings_buffer+attr_strings_buffer_len;
829 strcpy(attr_strings[id], str); 912 strcpy(attr_strings[id], str);
830 attr_strings_buffer_len+=strlen(str)+1; 913 attr_strings_buffer_len+=strlen(str)+1;
831} 914}
832 915
833static long long 916long long
834item_bin_get_nodeid(struct item_bin *ib) 917item_bin_get_nodeid(struct item_bin *ib)
835{ 918{
836 long long *ret=item_bin_get_attr(ib, attr_osm_nodeid, NULL); 919 long long *ret=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
837 if (ret) 920 if (ret)
838 return *ret; 921 return *ret;
839 return 0; 922 return 0;
840} 923}
841 924
842static long long 925long long
843item_bin_get_wayid(struct item_bin *ib) 926item_bin_get_wayid(struct item_bin *ib)
844{ 927{
845 long long *ret=item_bin_get_attr(ib, attr_osm_wayid, NULL); 928 long long *ret=item_bin_get_attr(ib, attr_osm_wayid, NULL);
846 if (ret) 929 if (ret)
847 return *ret; 930 return *ret;
848 return 0; 931 return 0;
849} 932}
850 933
851static long long 934long long
852item_bin_get_relationid(struct item_bin *ib) 935item_bin_get_relationid(struct item_bin *ib)
853{ 936{
854 long long *ret=item_bin_get_attr(ib, attr_osm_relationid, NULL); 937 long long *ret=item_bin_get_attr(ib, attr_osm_relationid, NULL);
855 if (ret) 938 if (ret)
856 return *ret; 939 return *ret;
953 } 1036 }
954 if (maxspeed_attr_value) 1037 if (maxspeed_attr_value)
955 flags[0] |= AF_SPEED_LIMIT; 1038 flags[0] |= AF_SPEED_LIMIT;
956 level=5; 1039 level=5;
957 } 1040 }
1041 if (! strcmp(k,"toll")) {
1042 if (!strcmp(v,"1")) {
1043 flags[0] |= AF_TOLL;
1044 }
1045 }
958 if (! strcmp(k,"access")) { 1046 if (! strcmp(k,"access")) {
959 flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_HORSE|AF_BIKE|AF_PEDESTRIAN; 1047 flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_HORSE|AF_BIKE|AF_PEDESTRIAN;
960 level=5; 1048 level=5;
961 } 1049 }
962 if (! strcmp(k,"vehicle")) { 1050 if (! strcmp(k,"vehicle")) {
1016 level=5; 1104 level=5;
1017 } 1105 }
1018 if (! strcmp(k,"hazmat")) { 1106 if (! strcmp(k,"hazmat")) {
1019 flags[access_value(v)] |= AF_DANGEROUS_GOODS; 1107 flags[access_value(v)] |= AF_DANGEROUS_GOODS;
1020 level=5; 1108 level=5;
1109 }
1110 if (! strcmp(k,"tunnel") && !strcmp(v,"1")) {
1111 flags[0] |= AF_UNDERGROUND;
1021 } 1112 }
1022 if (! strcmp(k,"note")) 1113 if (! strcmp(k,"note"))
1023 level=5; 1114 level=5;
1024 if (! strcmp(k,"name")) { 1115 if (! strcmp(k,"name")) {
1025 attr_strings_save(attr_string_label, v); 1116 attr_strings_save(attr_string_label, v);
1136 attr_present[idx]=4; 1227 attr_present[idx]=4;
1137} 1228}
1138 1229
1139int coord_count; 1230int coord_count;
1140 1231
1141struct node_item {
1142 int id;
1143 char ref_node;
1144 char ref_way;
1145 char ref_ref;
1146 char dummy;
1147 struct coord c;
1148};
1149
1150static void 1232static void
1151extend_buffer(struct buffer *b) 1233extend_buffer(struct buffer *b)
1152{ 1234{
1153 b->malloced+=b->malloced_step; 1235 b->malloced+=b->malloced_step;
1154 b->base=realloc(b->base, b->malloced); 1236 b->base=realloc(b->base, (size_t)b->malloced);
1155 if (b->base == NULL) { 1237 if (b->base == NULL) {
1156 fprintf(stderr,"realloc of %d bytes failed\n",(int)b->malloced); 1238 fprintf(stderr,"realloc of %d bytes failed\n",(int)b->malloced);
1157 exit(1); 1239 exit(1);
1158 } 1240 }
1159 1241
1214 node_buffer.size+=sizeof(struct node_item); 1296 node_buffer.size+=sizeof(struct node_item);
1215 if (! node_hash) { 1297 if (! node_hash) {
1216 if (ni->id > nodeid_last) { 1298 if (ni->id > nodeid_last) {
1217 nodeid_last=ni->id; 1299 nodeid_last=ni->id;
1218 } else { 1300 } else {
1219 fprintf(stderr,"INFO: Nodes out of sequence (new %d vs old %d), adding hash\n", ni->id, nodeid_last); 1301 //fprintf(stderr,"INFO: Nodes out of sequence (new %d vs old %d), adding hash\n", ni->id, nodeid_last);
1220 node_hash=g_hash_table_new(NULL, NULL); 1302 node_hash=g_hash_table_new(NULL, NULL);
1221 node_buffer_to_hash(); 1303 node_buffer_to_hash();
1222 } 1304 }
1223 } else 1305 } else
1224 if (!g_hash_table_lookup(node_hash, (gpointer)(long)(ni->id))) 1306 if (!g_hash_table_lookup(node_hash, (gpointer)(long)(ni->id)))
1226 else { 1308 else {
1227 node_buffer.size-=sizeof(struct node_item); 1309 node_buffer.size-=sizeof(struct node_item);
1228 nodeid=0; 1310 nodeid=0;
1229 } 1311 }
1230 1312
1313}
1314
1315void
1316clear_node_item_buffer(void)
1317{
1318 int j,count=node_buffer.size/sizeof(struct node_item);
1319 struct node_item *ni=(struct node_item *)(node_buffer.base);
1320 for (j = 0 ; j < count ; j++) {
1321 ni[j].ref_way=0;
1322 }
1231} 1323}
1232 1324
1233static struct node_item * 1325static struct node_item *
1234node_item_get(int id) 1326node_item_get(int id)
1235{ 1327{
1279 } 1371 }
1280 } 1372 }
1281 if (interval > 1) 1373 if (interval > 1)
1282 interval/=2; 1374 interval/=2;
1283 } 1375 }
1284
1285 return &ni[p]; 1376 return &ni[p];
1286} 1377}
1287 1378
1288static int 1379static int
1289load_node(FILE *coords, int p, struct node_item *ret) 1380load_node(FILE *coords, int p, struct node_item *ret)
1391int boundary; 1482int boundary;
1392 1483
1393void 1484void
1394osm_add_relation(osmid id) 1485osm_add_relation(osmid id)
1395{ 1486{
1396 struct attr idattr = { attr_type };
1397 current_id=id; 1487 current_id=id;
1398 in_relation=1; 1488 in_relation=1;
1399 debug_attr_buffer[0]='\0'; 1489 debug_attr_buffer[0]='\0';
1400 relation_type[0]='\0'; 1490 relation_type[0]='\0';
1401 iso_code[0]='\0'; 1491 iso_code[0]='\0';
1402 admin_level=-1; 1492 admin_level=-1;
1403 boundary=0; 1493 boundary=0;
1404 item_bin_init(item_bin, type_none); 1494 item_bin_init(item_bin, type_none);
1405 idattr.u.num64=&current_id; 1495 item_bin_add_attr_longlong(item_bin, attr_osm_relationid, current_id);
1406 item_bin_add_attr(item_bin, &idattr);
1407} 1496}
1497
1498static int
1499country_id_from_iso2(char *iso)
1500{
1501 int ret=0;
1502 if (iso)
1503 {
1504 // make lowercase
1505 int i99;
1506 for (i99 = 0; iso[i99]; i99++)
1507 {
1508 iso[i99] = tolower(iso[i99]);
1509 }
1510 struct country_search *search;
1511 struct attr country_iso2,country_id;
1512 struct item *item;
1513 country_iso2.type=attr_country_iso2;
1514 country_iso2.u.str=iso;
1515 search=country_search_new(&country_iso2,0);
1516 if ((item=country_search_get_item(search)) && item_attr_get(item, attr_country_id, &country_id))
1517 {
1518 ret=country_id.u.num;
1519 if (debug_itembin(3))
1520 {
1521 fprintf(stderr,"country id(1)=%d\n", ret);
1522 }
1523 }
1524 else
1525 {
1526 if (debug_itembin(3))
1527 {
1528 fprintf(stderr,"country id(2)=%d\n", ret);
1529 }
1530 }
1531 country_search_destroy(search);
1532 }
1533 return ret;
1534}
1535
1536static struct country_table *
1537country_from_countryid(int id)
1538{
1539 int i;
1540 for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++)
1541 {
1542 //if (debug_itembin(3))
1543 //{
1544 // fprintf(stderr,"== country_from_countryid: %d ==\n", country_table[i].countryid);
1545 //}
1546
1547 if (country_table[i].countryid == id)
1548 {
1549 return &country_table[i];
1550 }
1551 }
1552
1553 //if (debug_itembin(3))
1554 //{
1555 // fprintf(stderr,"== country_from_countryid: return NULL ==\n");
1556 //}
1557
1558 return NULL;
1559}
1560
1561struct country_table *
1562country_from_iso2(char *iso)
1563{
1564 return country_from_countryid(country_id_from_iso2(iso));
1565}
1566
1408 1567
1409void 1568void
1410osm_end_relation(FILE *turn_restrictions, FILE *boundaries) 1569osm_end_relation(struct maptool_osm *osm)
1411{ 1570{
1412 in_relation=0; 1571 in_relation=0;
1413 if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) { 1572 if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) {
1414#if 0 1573#if 0
1415 if (admin_level == 2) { 1574 if (admin_level == 2) {
1419 f=fopen(name,"w"); 1578 f=fopen(name,"w");
1420 item_bin_write(item_bin, f); 1579 item_bin_write(item_bin, f);
1421 fclose(f); 1580 fclose(f);
1422 } 1581 }
1423#endif 1582#endif
1424 item_bin_write(item_bin, boundaries); 1583 item_bin_write(item_bin, osm->boundaries);
1425 } 1584 }
1426 1585
1427 if (!strcmp(relation_type, "restriction") && (item_bin->type == type_street_turn_restriction_no || item_bin->type == type_street_turn_restriction_only)) 1586 if (!strcmp(relation_type, "restriction") && (item_bin->type == type_street_turn_restriction_no || item_bin->type == type_street_turn_restriction_only))
1428 item_bin_write(item_bin, turn_restrictions); 1587 item_bin_write(item_bin, osm->turn_restrictions);
1429} 1588}
1430 1589
1431void 1590void
1432osm_add_member(int type, osmid ref, char *role) 1591osm_add_member(int type, osmid ref, char *role)
1433{ 1592{
1462 osm_warning("relation", current_id, 0, "Unknown restriction %s\n",v); 1621 osm_warning("relation", current_id, 0, "Unknown restriction %s\n",v);
1463 } 1622 }
1464 } else if (!strcmp(k,"admin_level")) { 1623 } else if (!strcmp(k,"admin_level")) {
1465 admin_level=atoi(v); 1624 admin_level=atoi(v);
1466 } else if (!strcmp(k,"boundary")) { 1625 } else if (!strcmp(k,"boundary")) {
1467 if (!strcmp(v,"administrative")) { 1626 if (!strcmp(v,"administrative") || (experimental && !strcmp(v,"postal_code"))) {
1468 boundary=1; 1627 boundary=1;
1469 } 1628 }
1470 } else if (!strcmp(k,"ISO3166-1")) { 1629 } else if (!strcmp(k,"ISO3166-1")) {
1471 strcpy(iso_code, v); 1630 strcpy(iso_code, v);
1472 } 1631 }
1473#if 0
1474 if (add_tag) { 1632 if (add_tag) {
1475 char tag[strlen(k)+strlen(v)+2]; 1633 char tag[strlen(k)+strlen(v)+2];
1476 sprintf(tag,"%s=%s",k,v); 1634 sprintf(tag,"%s=%s",k,v);
1477 item_bin_add_attr_string(item_bin, attr_osm_tag, tag); 1635 item_bin_add_attr_string(item_bin, attr_osm_tag, tag);
1478 } 1636 }
1479#endif
1480} 1637}
1481 1638
1482 1639
1483static int 1640static int
1484attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count) 1641attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count)
1502 ret=0; 1659 ret=0;
1503 } 1660 }
1504 if (sum > 0 && sum == longest && ret < types_count) 1661 if (sum > 0 && sum == longest && ret < types_count)
1505 types[ret++]=curr->type; 1662 types[ret++]=curr->type;
1506 } 1663 }
1664 return ret;
1665}
1666
1667static void
1668attr_longest_match_clear(void)
1669{
1507 memset(attr_present, 0, sizeof(*attr_present)*attr_present_count); 1670 memset(attr_present, 0, sizeof(*attr_present)*attr_present_count);
1508 return ret;
1509} 1671}
1510 1672
1511void 1673void
1512osm_end_way(FILE *out) 1674osm_end_way(struct maptool_osm *osm)
1513{ 1675{
1514 int i,count; 1676 int i,count;
1515 int *def_flags,add_flags; 1677 int *def_flags,add_flags;
1516 enum item_type types[10]; 1678 enum item_type types[10];
1517 struct item_bin *item_bin; 1679 struct item_bin *item_bin;
1680 int count_lines=0, count_areas=0;
1518 1681
1519 in_way=0; 1682 in_way=0;
1520 1683
1521 if (! out) 1684 if (! osm->ways)
1685 {
1522 return; 1686 return;
1687 }
1523 1688
1524 if (dedupe_ways_hash) { 1689 if (dedupe_ways_hash)
1690 {
1525 if (g_hash_table_lookup(dedupe_ways_hash, (gpointer)(long)wayid)) 1691 if (g_hash_table_lookup(dedupe_ways_hash, (gpointer)(long)wayid))
1526 return; 1692 return;
1527 g_hash_table_insert(dedupe_ways_hash, (gpointer)(long)wayid, (gpointer)1); 1693 g_hash_table_insert(dedupe_ways_hash, (gpointer)(long)wayid, (gpointer)1);
1528 } 1694 }
1529 1695
1530 count=attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types)/sizeof(enum item_type)); 1696 count=attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types)/sizeof(enum item_type));
1531 if (!count) { 1697 if (!count)
1698 {
1532 count=1; 1699 count=1;
1533 types[0]=type_street_unkn; 1700 types[0]=type_street_unkn;
1534 } 1701 }
1535 if (count >= 10) { 1702 if (count >= 10)
1703 {
1536 fprintf(stderr,"way id %ld\n",osmid_attr_value); 1704 fprintf(stderr,"way id %ld\n",osmid_attr_value);
1537 dbg_assert(count < 10); 1705 dbg_assert(count < 10);
1538 } 1706 }
1539 for (i = 0 ; i < count ; i++) { 1707 for (i = 0 ; i < count ; i++)
1708 {
1540 add_flags=0; 1709 add_flags=0;
1541 if (types[i] == type_none) 1710 if (types[i] == type_none)
1542 continue; 1711 continue;
1543 if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) 1712 if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
1544 continue; 1713 continue;
1714 if (types[i] != type_street_unkn)
1715 {
1716 if(types[i]<type_area)
1717 count_lines++;
1718 else
1719 count_areas++;
1720 }
1545 item_bin=init_item(types[i]); 1721 item_bin=init_item(types[i]);
1546 item_bin_add_coord(item_bin, coord_buffer, coord_count); 1722 item_bin_add_coord(item_bin, coord_buffer, coord_count);
1723 nodes_ref_item_bin(item_bin);
1547 def_flags=item_get_default_flags(types[i]); 1724 def_flags=item_get_default_flags(types[i]);
1548 if (def_flags) { 1725 if (def_flags)
1726 {
1549 flags_attr_value=(*def_flags | flags[0] | flags[1]) & ~flags[2]; 1727 flags_attr_value=(*def_flags | flags[0] | flags[1]) & ~flags[2];
1550 if (flags_attr_value != *def_flags) 1728 if (flags_attr_value != *def_flags)
1551 add_flags=1; 1729 add_flags=1;
1552 } 1730 }
1553 item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]); 1731 item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]);
1557 item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); 1735 item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer);
1558 if (add_flags) 1736 if (add_flags)
1559 item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); 1737 item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value);
1560 if (maxspeed_attr_value) 1738 if (maxspeed_attr_value)
1561 item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); 1739 item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value);
1740
1741 // with special match
1742 // **buggy** item_bin_write_match(item_bin, attr_street_name, attr_street_name_match, osm->ways);
1743 // just original string
1562 item_bin_write(item_bin,out); 1744 item_bin_write(item_bin,osm->ways);
1745 }
1746
1747 /*
1748 if(osm->line2poi) {
1749 count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type));
1750 dbg_assert(count < 10);
1751 for (i = 0 ; i < count ; i++) {
1752 if (types[i] == type_none || types[i] == type_point_unkn)
1753 continue;
1754 item_bin=init_item(types[i]);
1755 item_bin_add_coord(item_bin, coord_buffer, coord_count);
1756 item_bin_add_attr_string(item_bin, attr_label, attr_strings[attr_string_label]);
1757 item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
1758 item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]);
1759 item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]);
1760 item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]);
1761 item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]);
1762 item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
1763 item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]);
1764 item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value);
1765 item_bin_write(item_bin, count_areas<count_lines?osm->line2poi:osm->poly2poi);
1563 } 1766 }
1767 }
1768 */
1769
1770 attr_longest_match_clear();
1564} 1771}
1565 1772
1566void 1773void
1567osm_end_node(FILE *out) 1774osm_end_node(struct maptool_osm *osm)
1568{ 1775{
1569 int conflict,count,i; 1776 int count,i;
1570 char *postal; 1777 char *postal;
1571 enum item_type types[10]; 1778 enum item_type types[10];
1572 struct country_table *result=NULL, *lookup;
1573 struct item_bin *item_bin; 1779 struct item_bin *item_bin;
1574 in_node=0; 1780 in_node=0;
1575 1781
1576 if (!out || ! node_is_tagged || ! nodeid) 1782 if (!osm->nodes || ! node_is_tagged || ! nodeid)
1577 return; 1783 return;
1578 count=attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types)/sizeof(enum item_type)); 1784 count=attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types)/sizeof(enum item_type));
1579 if (!count) { 1785 if (!count) {
1580 types[0]=type_point_unkn; 1786 types[0]=type_point_unkn;
1581 count=1; 1787 count=1;
1582 } 1788 }
1583 dbg_assert(count < 10); 1789 dbg_assert(count < 10);
1584 for (i = 0 ; i < count ; i++) { 1790 for (i = 0 ; i < count ; i++) {
1585 conflict=0;
1586 if (types[i] == type_none) 1791 if (types[i] == type_none)
1587 continue; 1792 continue;
1588 if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) 1793 if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
1589 continue; 1794 continue;
1590 item_bin=init_item(types[i]); 1795 item_bin=init_item(types[i]);
1796
1797 if (item_is_town(*item_bin) && attr_strings[attr_string_label])
1798 {
1799 if (debug_itembin(ib))
1800 {
1801 fprintf(stderr,"osm_end_node: have town: %s\n", attr_strings[attr_string_label]);
1802 }
1803 }
1804
1591 if (item_is_town(*item_bin) && attr_strings[attr_string_population]) 1805 if (item_is_town(*item_bin) && attr_strings[attr_string_population])
1592 item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population])); 1806 item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population]));
1593 item_bin_add_coord(item_bin, &ni->c, 1); 1807 item_bin_add_coord(item_bin, &ni->c, 1);
1594 item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]); 1808 item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]);
1595 item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); 1809 item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);
1606 char *sep=strchr(postal,','); 1820 char *sep=strchr(postal,',');
1607 if (sep) 1821 if (sep)
1608 *sep='\0'; 1822 *sep='\0';
1609 item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal); 1823 item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal);
1610 } 1824 }
1611 item_bin_write(item_bin,out); 1825 item_bin_write(item_bin,osm->nodes);
1612 if (item_is_town(*item_bin) && attr_strings[attr_string_label]) { 1826 if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) {
1613 char *tok,*buf=is_in_buffer; 1827 item_bin=init_item(item_bin->type);
1614 if (!buf[0]) 1828 item_bin_add_coord(item_bin, &ni->c, 1);
1615 strcpy(is_in_buffer, "Unknown"); 1829 item_bin_add_attr_string(item_bin, attr_osm_is_in, is_in_buffer);
1830 item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value);
1831 item_bin_add_attr_string(item_bin, attr_town_postal, postal);
1832 item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
1833 item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]);
1834 item_bin_write(item_bin, osm->towns);
1835 }
1836 }
1837 processed_nodes_out++;
1838 attr_longest_match_clear();
1839}
1840
1841static struct country_table *
1842osm_process_town_unknown_country(void)
1843{
1844 static struct country_table *unknown;
1845 unknown=country_from_countryid(999);
1846 return unknown;
1847}
1848
1849static struct country_table *
1850osm_process_item_fixed_country(void)
1851{
1852 static struct country_table *fixed;
1853 fixed=country_from_countryid(global_fixed_country_id);
1854 return fixed;
1855}
1856
1857static struct country_table *
1858osm_process_town_by_is_in(struct item_bin *ib,char *is_in)
1859{
1860 struct country_table *result=NULL, *lookup;
1861 char *tok,*dup=g_strdup(is_in),*buf=dup;
1862 int conflict;
1863
1616 while ((tok=strtok(buf, ",;"))) { 1864 while ((tok=strtok(buf, ",;")))
1865 {
1617 while (*tok==' ') 1866 while (*tok==' ')
1867 {
1618 tok++; 1868 tok++;
1869 }
1619 lookup=g_hash_table_lookup(country_table_hash,tok); 1870 lookup=g_hash_table_lookup(country_table_hash,tok);
1620 if (lookup) { 1871 if (lookup)
1872 {
1621 if (result && result->countryid != lookup->countryid) { 1873 if (result && result->countryid != lookup->countryid)
1874 {
1875 char *label=item_bin_get_attr(ib, attr_town_name, NULL);
1622 osm_warning("node",nodeid,0,"conflict for %s %s country %d vs %d\n", attr_strings[attr_string_label], debug_attr_buffer, lookup->countryid, result->countryid); 1876 osm_warning("node",item_bin_get_nodeid(ib),0,"conflict for %s is_in=%s country %d vs %d\n", label, is_in, lookup->countryid, result->countryid);
1623 conflict=1; 1877 conflict=1;
1878 }
1879 result=lookup;
1880 }
1881 buf=NULL;
1882 }
1883 g_free(dup);
1884 return result;
1885}
1886
1887static struct country_table *
1888osm_process_town_by_boundary(GList *bl, struct item_bin *ib, struct coord *c, struct attr *attrs)
1889{
1890 GList *l,*matches=boundary_find_matches(bl, c);
1891 struct boundary *match=NULL;
1892
1893 l=matches;
1894 while (l) {
1895 struct boundary *b=l->data;
1896 if (b->country) {
1897 if (match) {
1898 //osm_warning("node",item_bin_get_nodeid(ib),0,"node (0x%x,0x%x) conflict country ", c->x, c->y);
1899 //osm_warning("relation",boundary_relid(match),1,"country %d vs ",match->country->countryid);
1900 //osm_warning("relation",boundary_relid(b),1,"country %d\n",b->country->countryid);
1901 }
1902 match=b;
1903 }
1904 l=g_list_next(l);
1905 }
1906 if (match) {
1907 if (match && match->country && match->country->admin_levels) {
1908 l=matches;
1909 while (l) {
1910 struct boundary *b=l->data;
1911 char *admin_level=osm_tag_value(b->ib, "admin_level");
1912 char *postal=osm_tag_value(b->ib, "postal_code");
1913 if (admin_level) {
1914 int a=atoi(admin_level);
1915 int end=strlen(match->country->admin_levels)+3;
1916 char *name;
1917 if (a > 2 && a < end) {
1918 enum attr_type attr_type=attr_none;
1919 switch(match->country->admin_levels[a-3]) {
1920 case 's':
1921 attr_type=attr_state_name;
1922 break;
1923 case 'c':
1924 attr_type=attr_county_name;
1925 break;
1926 case 'm':
1927 attr_type=attr_municipality_name;
1928 break;
1929 }
1930 name=osm_tag_value(b->ib, "name");
1931 if (name && attr_type != attr_none) {
1932 attrs[a-2].type=attr_type;
1933 attrs[a-2].u.str=name;
1934 }
1624 } 1935 }
1625 result=lookup;
1626 } 1936 }
1627 buf=NULL; 1937 if (postal) {
1628 } 1938 attrs[0].type=attr_town_postal;
1629 if (result) { 1939 attrs[0].u.str=postal;
1630 if (!result->file) {
1631 char *name=g_strdup_printf("country_%d.bin.unsorted", result->countryid);
1632 result->file=fopen(name,"wb");
1633 g_free(name);
1634 } 1940 }
1635 if (result->file) { 1941 l=g_list_next(l);
1636 item_bin=init_item(item_bin->type); 1942 }
1637 item_bin_add_coord(item_bin, &ni->c, 1); 1943 }
1638 item_bin_add_attr_string(item_bin, attr_town_postal, postal); 1944 return match->country;
1639 item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); 1945 } else
1640 item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]); 1946 return NULL;
1641 item_bin_write_match(item_bin, attr_town_name, attr_town_name_match, result->file); 1947}
1948
1949void
1950osm_process_towns(FILE *in, FILE *boundaries, FILE *ways)
1951{
1952 struct item_bin *ib;
1953 GList *bl=NULL;
1954 struct attr attrs[10];
1955
1956 if (debug_itembin(1))
1957 {
1958 fprintf(stderr,"osm_process_towns == START ==\n");
1959 }
1960
1961 bl=process_boundaries(boundaries, ways);
1962 while ((ib=read_item(in)))
1963 {
1964 struct coord *c=(struct coord *)(ib+1);
1965 struct country_table *result=NULL;
1966 char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL);
1967 int i;
1968
1969 if (debug_itembin(ib))
1970 {
1971 fprintf(stderr,"== item ==\n");
1972 dump_itembin(ib);
1973 }
1974
1975 memset(attrs, 0, sizeof(attrs));
1976 if (debug_itembin(ib))
1977 {
1978 fprintf(stderr,"== osm_process_town_by_boundary ==\n");
1979 }
1980
1981 if (use_global_fixed_country_id == 1)
1982 {
1983 result=osm_process_item_fixed_country();
1984 if (debug_itembin(ib))
1985 {
1986 if (result==NULL)
1987 {
1988 fprintf(stderr,"== osm_process_item_fixed_country == #NULL# ==\n");
1642 } 1989 }
1643 1990 else
1991 {
1992 fprintf(stderr,"== osm_process_item_fixed_country == %d ==\n",result->countryid);
1644 } 1993 }
1645 } 1994 }
1646 } 1995 }
1647 processed_nodes_out++; 1996
1997 if (!result)
1998 {
1999 result=osm_process_town_by_boundary(bl, ib, c, attrs);
2000 }
2001
2002 if (!result)
2003 {
2004 if (debug_itembin(ib))
2005 {
2006 fprintf(stderr,"== osm_process_town_by_is_in == %s ==\n",is_in);
2007 }
2008 result=osm_process_town_by_is_in(ib, is_in);
2009 }
2010
2011 if (!result && unknown_country)
2012 {
2013 if (debug_itembin(ib))
2014 {
2015 fprintf(stderr,"== osm_process_town_unknown_country ==\n");
2016 }
2017 result=osm_process_town_unknown_country();
2018 }
2019
2020 if (result)
2021 {
2022 if (!result->file)
2023 {
2024 char *name=g_strdup_printf("country_%d.unsorted.tmp", result->countryid);
2025 result->file=fopen(name,"wb");
2026
2027 if (debug_itembin(ib))
2028 {
2029 fprintf(stderr,"== create: country_%d.unsorted.tmp == FILEP: %p ==\n", result->countryid, result->file);
2030 }
2031
2032 g_free(name);
2033 }
2034
2035 if (result->file)
2036 {
2037 long long *nodeid;
2038 if (is_in)
2039 item_bin_remove_attr(ib, is_in);
2040 nodeid=item_bin_get_attr(ib, attr_osm_nodeid, NULL);
2041 if (nodeid)
2042 item_bin_remove_attr(ib, nodeid);
2043 if (attrs[0].type != attr_none)
2044 {
2045 char *postal=item_bin_get_attr(ib, attr_town_postal, NULL);
2046 if (postal)
2047 item_bin_remove_attr(ib, postal);
2048 }
2049 for (i = 0 ; i < 10 ; i++)
2050 {
2051 if (attrs[i].type != attr_none)
2052 item_bin_add_attr(ib, &attrs[i]);
2053 }
2054 // ** used until 2011-11-06 seems bad ** item_bin_write_match(ib, attr_town_name, attr_town_name_match, result->file);
2055 item_bin_town_write_match(ib, attr_town_name, attr_town_name_match, result->file);
2056 // ** origname ** item_bin_write(ib,result->file);
2057 }
2058 }
2059 else
2060 {
2061 if (debug_itembin(ib))
2062 {
2063 fprintf(stderr,"== no result ==\n");
2064 }
2065 }
2066 }
2067
2068 if (debug_itembin(1))
2069 {
2070 fprintf(stderr,"osm_process_towns == END ==\n");
2071 }
2072
1648} 2073}
1649 2074
1650void 2075void
1651sort_countries(int keep_tmpfiles) 2076sort_countries(int keep_tmpfiles)
1652{ 2077{
1657 co=&country_table[i]; 2082 co=&country_table[i];
1658 if (co->file) { 2083 if (co->file) {
1659 fclose(co->file); 2084 fclose(co->file);
1660 co->file=NULL; 2085 co->file=NULL;
1661 } 2086 }
1662 name_in=g_strdup_printf("country_%d.bin.unsorted", co->countryid); 2087 name_in=g_strdup_printf("country_%d.unsorted.tmp", co->countryid);
1663 name_out=g_strdup_printf("country_%d.bin", co->countryid); 2088 name_out=g_strdup_printf("country_%d.tmp", co->countryid);
2089
2090 if (debug_itembin(2))
2091 {
2092 fprintf(stderr,"in=country_%d.unsorted.tmp\n", co->countryid);
2093 fprintf(stderr,"out=country_%d.tmp\n", co->countryid);
2094 }
2095
1664 co->r=world_bbox; 2096 co->r=world_bbox;
1665 item_bin_sort_file(name_in, name_out, &co->r, &co->size); 2097 item_bin_sort_file(name_in, name_out, &co->r, &co->size);
1666 if (!keep_tmpfiles) 2098 if (!keep_tmpfiles)
1667 unlink(name_in); 2099 unlink(name_in);
1668 g_free(name_in); 2100 g_free(name_in);
1810 return &ic[0]; 2242 return &ic[0];
1811 } 2243 }
1812 return NULL; 2244 return NULL;
1813} 2245}
1814 2246
2247struct turn_restriction {
2248 osmid relid;
2249 enum item_type type;
2250 struct coord *c[3];
2251 int c_count[3];
2252};
2253
2254static void
2255process_turn_restrictions_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv)
2256{
2257 int count,type=(long)member_priv;
2258 struct turn_restriction *turn_restriction=relation_priv;
2259 struct coord *c=(struct coord *)(member+1);
2260 int ccount=member->clen/2;
2261
2262 if (member->type < type_line)
2263 count=1;
2264 else
2265 count=2;
2266 turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count);
2267 turn_restriction->c[type][turn_restriction->c_count[type]++]=c[0];
2268 if (count > 1)
2269 turn_restriction->c[type][turn_restriction->c_count[type]++]=c[ccount-1];
2270}
2271
2272static void
2273process_turn_restrictions_fromto(struct turn_restriction *t, int type, struct coord **c)
2274{
2275 int i,j;
2276 for (i = 0 ; i < t->c_count[type] ; i+=2) {
2277 for (j = 0 ; j < t->c_count[1] ; j++) {
2278 if (coord_is_equal(t->c[type][i],t->c[1][j])) {
2279 c[0]=&t->c[type][i+1];
2280 c[1]=&t->c[type][i];
2281 return;
2282 }
2283 if (coord_is_equal(t->c[type][i+1],t->c[1][j])) {
2284 c[0]=&t->c[type][i];
2285 c[1]=&t->c[type][i+1];
2286 return;
2287 }
2288 }
2289 }
2290}
2291
2292static void
2293process_turn_restrictions_dump_coord(struct coord *c, int count)
2294{
2295 int i;
2296 for (i = 0 ; i < count ; i++) {
2297 fprintf(stderr,"(0x%x,0x%x)",c[i].x,c[i].y);
2298 }
2299}
2300
2301static void
2302process_turn_restrictions_finish(GList *tr, FILE *out)
2303{
2304 GList *l=tr;
2305 while (l) {
2306 struct turn_restriction *t=l->data;
2307 struct coord *c[4];
2308 struct item_bin *ib=item_bin;
2309
2310 if (!t->c_count[0]) {
2311 //osm_warning("relation",t->relid,0,"turn restriction: from member not found\n");
2312 } else if (!t->c_count[1]) {
2313 //osm_warning("relation",t->relid,0,"turn restriction: via member not found\n");
2314 } else if (!t->c_count[2]) {
2315 //osm_warning("relation",t->relid,0,"turn restriction: to member not found\n");
2316 } else {
2317 process_turn_restrictions_fromto(t, 0, c);
2318 process_turn_restrictions_fromto(t, 2, c+2);
2319 if (!c[0] || !c[2]) {
2320 //osm_warning("relation",t->relid,0,"turn restriction: via (");
2321 //process_turn_restrictions_dump_coord(t->c[1], t->c_count[1]);
2322 //fprintf(stderr,")");
2323 if (!c[0]) {
2324 //fprintf(stderr," failed to connect to from (");
2325 //process_turn_restrictions_dump_coord(t->c[0], t->c_count[0]);
2326 //fprintf(stderr,")");
2327 }
2328 if (!c[2]) {
2329 //fprintf(stderr," failed to connect to to (");
2330 //process_turn_restrictions_dump_coord(t->c[2], t->c_count[2]);
2331 //fprintf(stderr,")");
2332 }
2333 //fprintf(stderr,"\n");
2334 } else {
2335 if (t->c_count[1] <= 2) {
2336 item_bin_init(ib,t->type);
2337 item_bin_add_coord(ib, c[0], 1);
2338 item_bin_add_coord(ib, c[1], 1);
2339 if (t->c_count[1] > 1)
2340 item_bin_add_coord(ib, c[3], 1);
2341 item_bin_add_coord(ib, c[2], 1);
2342 item_bin_write(ib, out);
2343 }
2344
2345 }
2346 }
2347 g_free(t);
2348 l=g_list_next(l);
2349 }
2350 g_list_free(tr);
2351}
2352
2353static GList *
2354process_turn_restrictions_setup(FILE *in, struct relations *relations)
2355{
2356 struct relation_member fromm,tom,viam,tmpm;
2357 long long relid;
2358 struct item_bin *ib;
2359 struct relations_func *relations_func;
2360 int min_count;
2361 GList *turn_restrictions=NULL;
2362
2363 fseek(in, 0, SEEK_SET);
2364 relations_func=relations_func_new(process_turn_restrictions_member, NULL);
2365 while ((ib=read_item(in))) {
2366 struct turn_restriction *turn_restriction=g_new0(struct turn_restriction, 1);
2367 relid=item_bin_get_relationid(ib);
2368 turn_restriction->relid=relid;
2369 turn_restriction->type=ib->type;
2370 min_count=0;
2371 if (!search_relation_member(ib, "from",&fromm,&min_count)) {
2372 //osm_warning("relation",relid,0,"turn restriction: from member missing\n");
2373 continue;
2374 }
2375 if (search_relation_member(ib, "from",&tmpm,&min_count)) {
2376 //osm_warning("relation",relid,0,"turn restriction: multiple from members\n");
2377 continue;
2378 }
2379 min_count=0;
2380 if (!search_relation_member(ib, "to",&tom,&min_count)) {
2381 //osm_warning("relation",relid,0,"turn restriction: to member missing\n");
2382 continue;
2383 }
2384 if (search_relation_member(ib, "to",&tmpm,&min_count)) {
2385 //osm_warning("relation",relid,0,"turn restriction: multiple to members\n");
2386 continue;
2387 }
2388 min_count=0;
2389 if (!search_relation_member(ib, "via",&viam,&min_count)) {
2390 //osm_warning("relation",relid,0,"turn restriction: via member missing\n");
2391 continue;
2392 }
2393 if (search_relation_member(ib, "via",&tmpm,&min_count)) {
2394 //osm_warning("relation",relid,0,"turn restriction: multiple via member\n");
2395 continue;
2396 }
2397 if (fromm.type != 2) {
2398 //osm_warning("relation",relid,0,"turn restriction: wrong type for from member ");
2399 //osm_warning(osm_types[fromm.type],fromm.id,1,"\n");
2400 continue;
2401 }
2402 if (tom.type != 2) {
2403 //osm_warning("relation",relid,0,"turn restriction: wrong type for to member ");
2404 //osm_warning(osm_types[tom.type],tom.id,1,"\n");
2405 continue;
2406 }
2407 if (viam.type != 1 && viam.type != 2) {
2408 //osm_warning("relation",relid,0,"turn restriction: wrong type for via member ");
2409 //osm_warning(osm_types[viam.type],viam.id,1,"\n");
2410 continue;
2411 }
2412 relations_add_func(relations, relations_func, turn_restriction, (gpointer) 0, fromm.type, fromm.id);
2413 relations_add_func(relations, relations_func, turn_restriction, (gpointer) 1, viam.type, viam.id);
2414 relations_add_func(relations, relations_func, turn_restriction, (gpointer) 2, tom.type, tom.id);
2415 turn_restrictions=g_list_append(turn_restrictions, turn_restriction);
2416 }
2417 return turn_restrictions;
2418}
2419
1815void 2420void
1816process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) 2421process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out)
2422{
2423 struct relations *relations=relations_new();
2424 GList *turn_restrictions;
2425 fseek(in, 0, SEEK_SET);
2426 turn_restrictions=process_turn_restrictions_setup(in, relations);
2427 relations_process(relations, coords, ways, NULL);
2428 process_turn_restrictions_finish(turn_restrictions, out);
2429}
2430
2431void
2432process_turn_restrictions_old(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out)
1817{ 2433{
1818 struct relation_member fromm,tom,viam,tmpm; 2434 struct relation_member fromm,tom,viam,tmpm;
1819 struct node_item ni; 2435 struct node_item ni;
1820 long long relid; 2436 long long relid;
1821 char from_buffer[65536],to_buffer[65536],via_buffer[65536]; 2437 char from_buffer[65536],to_buffer[65536],via_buffer[65536];
1822 struct item_bin *ib,*from=(struct item_bin *)from_buffer,*to=(struct item_bin *)to_buffer,*via=(struct item_bin *)via_buffer; 2438 struct item_bin *ib,*from=(struct item_bin *)from_buffer,*to=(struct item_bin *)to_buffer,*via=(struct item_bin *)via_buffer;
1823 struct coord *fromc,*toc,*viafrom,*viato,*tmp; 2439 struct coord *fromc,*toc,*viafrom,*viato,*tmp;
1824 fseek(in, 0, SEEK_SET);
1825 int min_count; 2440 int min_count;
1826 while ((ib=read_item(in))) { 2441 while ((ib=read_item(in))) {
1827 relid=item_bin_get_relationid(ib); 2442 relid=item_bin_get_relationid(ib);
1828 min_count=0; 2443 min_count=0;
1829 if (!search_relation_member(ib, "from",&fromm,&min_count)) { 2444 if (!search_relation_member(ib, "from",&fromm,&min_count)) {
1893 fprintf(stderr,"coord 0x%x,0x%x\n",ni.c.x,ni.c.y); 2508 fprintf(stderr,"coord 0x%x,0x%x\n",ni.c.x,ni.c.y);
1894 fprintf(stderr,"Lookup "LONGLONG_FMT"\n",fromm.id); 2509 fprintf(stderr,"Lookup "LONGLONG_FMT"\n",fromm.id);
1895#endif 2510#endif
1896 if (!(fromc=get_way(ways, ways_index, viafrom, fromm.id, from, 0))) { 2511 if (!(fromc=get_way(ways, ways_index, viafrom, fromm.id, from, 0))) {
1897 if (viam.type == 1 || !(fromc=get_way(ways, ways_index, viato, fromm.id, from, 0))) { 2512 if (viam.type == 1 || !(fromc=get_way(ways, ways_index, viato, fromm.id, from, 0))) {
1898 osm_warning("relation",relid,0,"turn restriction: failed to connect via "); 2513 //osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
1899 osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to from member ",viafrom->x,viafrom->y,viato->x,viato->y); 2514 //osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to from member ",viafrom->x,viafrom->y,viato->x,viato->y);
1900 osm_warning(osm_types[fromm.type],fromm.id,1," ("); 2515 //osm_warning(osm_types[fromm.type],fromm.id,1," (");
1901 get_way(ways, ways_index, viafrom, fromm.id, from, 1); 2516 //get_way(ways, ways_index, viafrom, fromm.id, from, 1);
1902 fprintf(stderr,")\n"); 2517 //fprintf(stderr,")\n");
1903 continue; 2518 continue;
1904 } else { 2519 } else {
1905 tmp=viato; 2520 tmp=viato;
1906 viato=viafrom; 2521 viato=viafrom;
1907 viafrom=tmp; 2522 viafrom=tmp;
1908 } 2523 }
1909 } 2524 }
1910 if (!(toc=get_way(ways, ways_index, viato, tom.id, to, 0))) { 2525 if (!(toc=get_way(ways, ways_index, viato, tom.id, to, 0))) {
1911 osm_warning("relation",relid,0,"turn restriction: failed to connect via "); 2526 //osm_warning("relation",relid,0,"turn restriction: failed to connect via ");
1912 osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to to member ",viafrom->x,viafrom->y,viato->x,viato->y); 2527 //osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to to member ",viafrom->x,viafrom->y,viato->x,viato->y);
1913 osm_warning(osm_types[tom.type],tom.id,1," ("); 2528 //osm_warning(osm_types[tom.type],tom.id,1," (");
1914 get_way(ways, ways_index, viato, tom.id, to, 1); 2529 //get_way(ways, ways_index, viato, tom.id, to, 1);
1915 fprintf(stderr,")\n"); 2530 //fprintf(stderr,")\n");
1916 continue; 2531 continue;
1917 } 2532 }
1918#if 0 2533#if 0
1919 fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x)\n",fromc->x,fromc->y, ni.c.x, ni.c.y, toc->x, toc->y); 2534 fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x)\n",fromc->x,fromc->y, ni.c.x, ni.c.y, toc->x, toc->y);
1920#endif 2535#endif
1926 item_bin_add_coord(ib, toc, 1); 2541 item_bin_add_coord(ib, toc, 1);
1927 item_bin_write(item_bin, out); 2542 item_bin_write(item_bin, out);
1928 } 2543 }
1929} 2544}
1930 2545
2546#if 0
1931static void 2547static void
1932process_countries(FILE *way, FILE *ways_index) 2548process_countries(FILE *way, FILE *ways_index)
1933{ 2549{
1934 FILE *in=fopen("country_de.tmp","r"); 2550 FILE *in=fopen("country_de.tmp","r");
1935 struct item_bin *ib; 2551 struct item_bin *ib;
1976 sort_segments=g_list_next(sort_segments); 2592 sort_segments=g_list_next(sort_segments);
1977 } 2593 }
1978 fclose(tmp); 2594 fclose(tmp);
1979 fclose(in); 2595 fclose(in);
1980} 2596}
2597#endif
1981 2598
1982static void 2599static void
1983node_ref_way(osmid node) 2600node_ref_way(osmid node)
1984{ 2601{
1985 struct node_item *ni; 2602 struct node_item *ni;
1986 ni=node_item_get(node); 2603 ni=node_item_get(node);
1987 if (ni) 2604 if (ni)
1988 ni->ref_way++; 2605 ni->ref_way++;
1989} 2606}
1990 2607
1991int 2608static void
1992resolve_ways(FILE *in, FILE *out) 2609nodes_ref_item_bin(struct item_bin *ib)
1993{ 2610{
1994 struct item_bin *ib;
1995 struct coord *c;
1996 int i; 2611 int i;
1997
1998 fseek(in, 0, SEEK_SET);
1999 while ((ib=read_item(in))) {
2000 c=(struct coord *)(ib+1); 2612 struct coord *c=(struct coord *)(ib+1);
2001 for (i = 0 ; i < ib->clen/2 ; i++) { 2613 for (i = 0 ; i < ib->clen/2 ; i++)
2002 node_ref_way(REF(c[i])); 2614 node_ref_way(REF(c[i]));
2003 }
2004 }
2005 return 0;
2006} 2615}
2616
2007 2617
2008void 2618void
2009osm_add_nd(osmid ref) 2619osm_add_nd(osmid ref)
2010{ 2620{
2011 SET_REF(coord_buffer[coord_count], ref); 2621 SET_REF(coord_buffer[coord_count], ref);
2012 node_ref_way(ref);
2013 coord_count++; 2622 coord_count++;
2014 if (coord_count > 65536) { 2623 if (coord_count > 65536) {
2015 fprintf(stderr,"ERROR: Overflow\n"); 2624 fprintf(stderr,"ERROR: Overflow\n");
2016 exit(1); 2625 exit(1);
2017 } 2626 }
2053 fwrite(&new, sizeof(new), 1, out_graph); 2662 fwrite(&new, sizeof(new), 1, out_graph);
2054 fwrite(c+first, new.clen*4, 1, out_graph); 2663 fwrite(c+first, new.clen*4, 1, out_graph);
2055 fwrite(attr, attr_len*4, 1, out_graph); 2664 fwrite(attr, attr_len*4, 1, out_graph);
2056#endif 2665#endif
2057} 2666}
2667
2668void
2669ref_ways(FILE *in)
2670{
2671 struct item_bin *ib;
2672
2673 fseek(in, 0, SEEK_SET);
2674 while ((ib=read_item(in)))
2675 nodes_ref_item_bin(ib);
2676}
2677
2678void
2679resolve_ways(FILE *in, FILE *out)
2680{
2681 struct item_bin *ib;
2682 struct coord *c;
2683 int i;
2684 struct node_item *ni;
2685
2686 fseek(in, 0, SEEK_SET);
2687 while ((ib=read_item(in))) {
2688 c=(struct coord *)(ib+1);
2689 for (i = 0 ; i < ib->clen/2 ; i++) {
2690 if(!IS_REF(c[i]))
2691 continue;
2692 ni=node_item_get(REF(c[i]));
2693 if(ni) {
2694 c[i].x=ni->c.x;
2695 c[i].y=ni->c.y;
2696 }
2697 }
2698 item_bin_write(ib,out);
2699 }
2700}
2701
2702FILE *
2703resolve_ways_file(FILE *in, char *suffix, char *filename)
2704{
2705 char *newfilename=g_strdup_printf("%s_new",filename);
2706 FILE *new=tempfile(suffix,newfilename,1);
2707 resolve_ways(in, new);
2708 fclose(in);
2709 fclose(new);
2710 tempfile_rename(suffix,newfilename,filename);
2711 g_free(newfilename);
2712 return tempfile(suffix,filename,0);
2713}
2714
2715/**
2716 * Get POI coordinates from area/line coordinates.
2717 * @param in *in input file with area/line coordinates.
2718 * @param in *out output file with POI coordinates
2719 * @param in type input file original contents type: type_line or type_area
2720 * @returns nothing
2721 */
2722void
2723process_way2poi(FILE *in, FILE *out, int type)
2724{
2725 struct item_bin *ib;
2726 while ((ib=read_item(in))) {
2727 int count=ib->clen/2;
2728 if(count>1 && ib->type<type_line) {
2729 struct coord *c=(struct coord *)(ib+1), c1, c2;
2730 int done=0;
2731 if(type==type_area) {
2732 if(count<3) {
2733 osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, less than 3 points defined\n");
2734 } else if(!geom_poly_centroid(c, count, &c1)) {
2735 osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, area is 0\n");
2736 } else {
2737 if(geom_poly_point_inside(c, count, &c1)) {
2738 c[0]=c1;
2739 } else {
2740 geom_poly_closest_point(c, count, &c1, &c2);
2741 c[0]=c2;
2742 }
2743 done=1;
2744 }
2745 }
2746 if(!done) {
2747 geom_line_middle(c,count,&c1);
2748 c[0]=c1;
2749 }
2750 write_item_part(out, NULL, NULL, ib, 0, 0, NULL);
2751 }
2752 }
2753}
2754
2058 2755
2059int 2756int
2060map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final) 2757map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final)
2061{ 2758{
2062 struct coord *c; 2759 struct coord *c;
2086 if (ni->ref_way > 1 && i != 0 && i != ccount-1 && i != last && item_get_default_flags(ib->type)) { 2783 if (ni->ref_way > 1 && i != 0 && i != ccount-1 && i != last && item_get_default_flags(ib->type)) {
2087 write_item_part(out, out_index, out_graph, ib, last, i, &last_id); 2784 write_item_part(out, out_index, out_graph, ib, last, i, &last_id);
2088 last=i; 2785 last=i;
2089 } 2786 }
2090 } else if (final) { 2787 } else if (final) {
2091 osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to "); 2788 //osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to ");
2092 osm_warning("node",ndref,1,"\n"); 2789 //osm_warning("node",ndref,1,"\n");
2093 remaining=(ib->len+1)*4-sizeof(struct item_bin)-i*sizeof(struct coord); 2790 remaining=(ib->len+1)*4-sizeof(struct item_bin)-i*sizeof(struct coord);
2094 memmove(&c[i], &c[i+1], remaining); 2791 memmove(&c[i], &c[i+1], remaining);
2095 ib->clen-=2; 2792 ib->clen-=2;
2096 ib->len-=2; 2793 ib->len-=2;
2097 i--; 2794 i--;
2136 do { 2833 do {
2137 tilename[0]='\0'; 2834 tilename[0]='\0';
2138 sprintf(suffix,"s%d", num); 2835 sprintf(suffix,"s%d", num);
2139 num++; 2836 num++;
2140 tile(&co->r, suffix, tilename, max, overlap, NULL); 2837 tile(&co->r, suffix, tilename, max, overlap, NULL);
2838
2141 sprintf(filename,"country_%d.bin", co->countryid); 2839 sprintf(filename,"country_%d.tmp", co->countryid);
2840 if (debug_itembin(4))
2841 {
2842 fprintf(stderr,"write_countrydir: tilename=%s country_%d.tmp\n", tilename ,co->countryid);
2843 }
2142 zipnum=add_aux_tile(zip_info, tilename, filename, co->size); 2844 zipnum=add_aux_tile(zip_info, tilename, filename, co->size);
2143 } while (zipnum == -1); 2845 } while (zipnum == -1);
2144 index_country_add(zip_info,co->countryid,zipnum); 2846 index_country_add(zip_info,co->countryid,zipnum);
2145 } 2847 }
2146 } 2848 }
2147} 2849}
2148 2850
2149void 2851void
2852load_countries(void)
2853{
2854 char filename[32];
2855 FILE *f;
2856 int i;
2857 struct country_table *co;
2858
2859 for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
2860 co=&country_table[i];
2861 sprintf(filename,"country_%d.tmp", co->countryid);
2862 if (debug_itembin(4))
2863 {
2864 fprintf(stderr,"load_countries: country_%d.tmp\n", co->countryid);
2865 }
2866
2867 f=fopen(filename,"rb");
2868 if (f) {
2869 int i,first=1;
2870 struct item_bin *ib;
2871 while ((ib=read_item(f))) {
2872 struct coord *c=(struct coord *)(ib+1);
2873 co->size+=ib->len*4+4;
2874 for (i = 0 ; i < ib->clen/2 ; i++) {
2875 if (first) {
2876 co->r.l=c[i];
2877 co->r.h=c[i];
2878 first=0;
2879 } else
2880 bbox_extend(&c[i], &co->r);
2881 }
2882 }
2883 fseek(f, 0, SEEK_END);
2884 co->size=ftell(f);
2885 fclose(f);
2886 }
2887 }
2888}
2889
2890void
2150remove_countryfiles(void) 2891remove_countryfiles(void)
2151{ 2892{
2152 int i; 2893 int i;
2153 char filename[32]; 2894 char filename[32];
2154 struct country_table *co; 2895 struct country_table *co;
2155 2896
2156 for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { 2897 for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) {
2157 co=&country_table[i]; 2898 co=&country_table[i];
2158 if (co->size) { 2899 if (co->size) {
2159 sprintf(filename,"country_%d.bin", co->countryid); 2900 sprintf(filename,"country_%d.tmp", co->countryid);
2160 unlink(filename); 2901 unlink(filename);
2161 } 2902 }
2162 } 2903 }
2163} 2904}
2164 2905

Legend:
Removed from v.35  
changed lines
  Added in v.36

   
Visit the ZANavi Wiki