Ticket #859: maptool-way2poi3.diff

File maptool-way2poi3.diff, 32.4 KB (added by https://wiki.navit-project.org/index.php/user:tryagain, 11 months ago)

Suggestions from  http://irclogs.navit.ie/%23navit-2011-07-03.log and sigfpe crash when polygone area <1 should be fixed.

  • navit/maptool/osm.c

     
    351351        { 999,"Unknown"}, 
    352352}; 
    353353 
     354// first char - item type 
     355//   =w - ways 
     356//   =? - used both for nodes and ways 
     357//   otherwise - nodes 
    354358 
    355359static char *attrmap={ 
    356360        "n      *=*                     point_unkn\n" 
    357361//      "n      Annehmlichkeit=Hochsitz poi_hunting_stand\n" 
    358         "n      addr:housenumber=*      house_number\n" 
    359         "n      aeroway=aerodrome       poi_airport\n" 
    360         "n      aeroway=airport         poi_airport\n" 
    361         "n      aeroway=helipad         poi_heliport\n" 
    362         "n      aeroway=terminal        poi_airport\n" 
    363         "n      amenity=atm             poi_bank\n" 
    364         "n      amenity=bank            poi_bank\n" 
    365         "n      amenity=bar             poi_bar\n" 
     362        "?      addr:housenumber=*      house_number\n" 
     363        "?      aeroway=aerodrome       poi_airport\n" 
     364        "?      aeroway=airport         poi_airport\n" 
     365        "?      aeroway=helipad         poi_heliport\n" 
     366        "?      aeroway=terminal        poi_airport\n" 
     367        "?      amenity=atm             poi_bank\n" 
     368        "?      amenity=bank            poi_bank\n" 
     369        "?      amenity=bar             poi_bar\n" 
    366370        "n      amenity=bench           poi_bench\n" 
    367         "n      amenity=biergarten      poi_biergarten\n" 
    368         "n      amenity=bus_station     poi_bus_station\n" 
    369         "n      amenity=cafe            poi_cafe\n" 
    370         "n      amenity=car_wash        poi_car_wash\n" 
    371         "n      amenity=cinema          poi_cinema\n" 
    372         "n      amenity=college         poi_school_college\n" 
    373         "n      amenity=courthouse      poi_justice\n" 
    374         "n      amenity=drinking_water  poi_potable_water\n" 
    375         "n      amenity=fast_food       poi_fastfood\n" 
    376         "n      amenity=fire_station    poi_firebrigade\n" 
    377         "n      amenity=fountain        poi_fountain\n" 
    378         "n      amenity=fuel            poi_fuel\n" 
    379         "n      amenity=grave_yard      poi_cemetery\n" 
    380         "n      amenity=hospital        poi_hospital\n" 
    381         "n      amenity=hunting_stand   poi_hunting_stand\n" 
    382         "n      amenity=kindergarten    poi_kindergarten\n" 
    383         "n      amenity=library         poi_library\n" 
    384         "n      amenity=nightclub       poi_nightclub\n" 
    385         "n      amenity=park_bench      poi_bench\n" 
    386         "n      amenity=parking         poi_car_parking\n" 
    387         "n      amenity=pharmacy        poi_pharmacy\n" 
    388         "n      amenity=place_of_worship,religion=christian     poi_church\n" 
    389         "n      amenity=place_of_worship                        poi_worship\n" 
    390         "n      amenity=police          poi_police\n" 
    391         "n      amenity=post_box        poi_post_box\n" 
    392         "n      amenity=post_office     poi_post_office\n" 
    393         "n      amenity=prison          poi_prison\n" 
    394         "n      amenity=pub             poi_pub\n" 
    395         "n      amenity=public_building poi_public_office\n" 
    396         "n      amenity=recycling       poi_recycling\n" 
    397         "n      amenity=restaurant,cuisine=fine_dining          poi_dining\n" 
    398         "n      amenity=restaurant                              poi_restaurant\n" 
    399         "n      amenity=school          poi_school\n" 
    400         "n      amenity=shelter         poi_shelter\n" 
    401         "n      amenity=taxi            poi_taxi\n" 
    402         "n      amenity=tec_common      tec_common\n" 
    403         "n      amenity=telephone       poi_telephone\n" 
    404         "n      amenity=theatre         poi_theater\n" 
    405         "n      amenity=toilets         poi_restroom\n" 
    406         "n      amenity=townhall        poi_townhall\n" 
    407         "n      amenity=university      poi_school_university\n" 
    408         "n      amenity=vending_machine poi_vending_machine\n" 
     371        "?      amenity=biergarten      poi_biergarten\n" 
     372        "?      amenity=bus_station     poi_bus_station\n" 
     373        "?      amenity=cafe            poi_cafe\n" 
     374        "?      amenity=car_wash        poi_car_wash\n" 
     375        "?      amenity=cinema          poi_cinema\n" 
     376        "?      amenity=college         poi_school_college\n" 
     377        "?      amenity=courthouse      poi_justice\n" 
     378        "?      amenity=drinking_water  poi_potable_water\n" 
     379        "?      amenity=fast_food       poi_fastfood\n" 
     380        "?      amenity=fire_station    poi_firebrigade\n" 
     381        "?      amenity=fountain        poi_fountain\n" 
     382        "?      amenity=fuel            poi_fuel\n" 
     383        "?      amenity=grave_yard      poi_cemetery\n" 
     384        "?      amenity=hospital        poi_hospital\n" 
     385        "?      amenity=hunting_stand   poi_hunting_stand\n" 
     386        "?      amenity=kindergarten    poi_kindergarten\n" 
     387        "?      amenity=library         poi_library\n" 
     388        "?      amenity=nightclub       poi_nightclub\n" 
     389        "?      amenity=park_bench      poi_bench\n" 
     390        "?      amenity=parking         poi_car_parking\n" 
     391        "?      amenity=pharmacy        poi_pharmacy\n" 
     392        "?      amenity=place_of_worship,religion=christian     poi_church\n" 
     393        "?      amenity=place_of_worship                        poi_worship\n" 
     394        "?      amenity=police          poi_police\n" 
     395        "?      amenity=post_box        poi_post_box\n" 
     396        "?      amenity=post_office     poi_post_office\n" 
     397        "?      amenity=prison          poi_prison\n" 
     398        "?      amenity=pub             poi_pub\n" 
     399        "?      amenity=public_building poi_public_office\n" 
     400        "?      amenity=recycling       poi_recycling\n" 
     401        "?      amenity=restaurant,cuisine=fine_dining          poi_dining\n" 
     402        "?      amenity=restaurant                              poi_restaurant\n" 
     403        "?      amenity=school          poi_school\n" 
     404        "?      amenity=shelter         poi_shelter\n" 
     405        "?      amenity=taxi            poi_taxi\n" 
     406        "?      amenity=tec_common      tec_common\n" 
     407        "?      amenity=telephone       poi_telephone\n" 
     408        "?      amenity=theatre         poi_theater\n" 
     409        "?      amenity=toilets         poi_restroom\n" 
     410        "?      amenity=townhall        poi_townhall\n" 
     411        "?      amenity=university      poi_school_university\n" 
     412        "?      amenity=vending_machine poi_vending_machine\n" 
    409413        "n      barrier=bollard         barrier_bollard\n" 
    410414        "n      barrier=cycle_barrier   barrier_cycle\n" 
    411415        "n      barrier=lift_gate       barrier_lift_gate\n" 
    412         "n      car=car_rental          poi_car_rent\n" 
    413         "n      highway=bus_station     poi_bus_station\n" 
    414         "n      highway=bus_stop        poi_bus_stop\n" 
     416        "?      car=car_rental          poi_car_rent\n" 
     417        "?      highway=bus_station     poi_bus_station\n" 
     418        "?      highway=bus_stop        poi_bus_stop\n" 
    415419        "n      highway=mini_roundabout mini_roundabout\n" 
    416420        "n      highway=motorway_junction       highway_exit\n" 
    417421        "n      highway=stop            traffic_sign_stop\n" 
    418422        "n      highway=toll_booth      poi_toll_booth\n" 
    419423        "n      highway=traffic_signals traffic_signals\n" 
    420424        "n      highway=turning_circle  turning_circle\n" 
    421         "n      historic=boundary_stone poi_boundary_stone\n" 
    422         "n      historic=castle         poi_castle\n" 
    423         "n      historic=memorial       poi_memorial\n" 
    424         "n      historic=monument       poi_monument\n" 
    425         "n      historic=ruins          poi_ruins\n" 
    426 //      "n      historic=*              poi_ruins\n" 
    427         "n      landuse=cemetery        poi_cemetery\n" 
    428         "n      leisure=fishing         poi_fish\n" 
    429         "n      leisure=golf_course     poi_golf\n" 
    430         "n      leisure=marina          poi_marine\n" 
    431         "n      leisure=playground      poi_playground\n" 
    432         "n      leisure=slipway         poi_boat_ramp\n" 
    433         "n      leisure=sports_centre   poi_sport\n" 
    434         "n      leisure=stadium         poi_stadium\n" 
    435         "n      man_made=tower          poi_tower\n" 
    436         "n      military=airfield       poi_military\n" 
    437         "n      military=barracks       poi_military\n" 
    438         "n      military=bunker         poi_military\n" 
    439         "n      military=danger_area    poi_danger_area\n" 
    440         "n      military=range          poi_military\n" 
    441         "n      natural=bay             poi_bay\n" 
    442         "n      natural=peak,ele=*              poi_peak\n"     // show only major peaks with elevation 
    443         "n      natural=tree            poi_tree\n" 
     425        "?      historic=boundary_stone poi_boundary_stone\n" 
     426        "?      historic=castle         poi_castle\n" 
     427        "?      historic=memorial       poi_memorial\n" 
     428        "?      historic=monument       poi_monument\n" 
     429        "?      historic=ruins          poi_ruins\n" 
     430//      "?      historic=*              poi_ruins\n" 
     431        "?      landuse=cemetery        poi_cemetery\n" 
     432        "?      leisure=fishing         poi_fish\n" 
     433        "?      leisure=golf_course     poi_golf\n" 
     434        "?      leisure=marina          poi_marine\n" 
     435        "?      leisure=playground      poi_playground\n" 
     436        "?      leisure=slipway         poi_boat_ramp\n" 
     437        "?      leisure=sports_centre   poi_sport\n" 
     438        "?      leisure=stadium         poi_stadium\n" 
     439        "?      man_made=tower          poi_tower\n" 
     440        "?      military=airfield       poi_military\n" 
     441        "?      military=barracks       poi_military\n" 
     442        "?      military=bunker         poi_military\n" 
     443        "?      military=danger_area    poi_danger_area\n" 
     444        "?      military=range          poi_military\n" 
     445        "?      natural=bay             poi_bay\n" 
     446        "?      natural=peak,ele=*              poi_peak\n"     // show only major peaks with elevation 
     447        "?      natural=tree            poi_tree\n" 
    444448        "n      place=city              town_label_2e5\n" 
    445449        "n      place=hamlet            town_label_2e2\n" 
    446450        "n      place=locality          town_label_2e0\n" 
     
    451455        "n      power=sub_station       power_substation\n" 
    452456        "n      railway=halt            poi_rail_halt\n" 
    453457        "n      railway=level_crossing  poi_level_crossing\n" 
    454         "n      railway=station         poi_rail_station\n" 
    455         "n      railway=tram_stop       poi_rail_tram_stop\n" 
    456         "n      shop=baker              poi_shop_baker\n" 
    457         "n      shop=bakery             poi_shop_baker\n" 
    458         "n      shop=beverages          poi_shop_beverages\n" 
    459         "n      shop=bicycle            poi_shop_bicycle\n" 
    460         "n      shop=butcher            poi_shop_butcher\n" 
    461         "n      shop=car                poi_car_dealer_parts\n" 
    462         "n      shop=car_repair         poi_repair_service\n" 
    463         "n      shop=clothes            poi_shop_apparel\n" 
    464         "n      shop=convenience        poi_shop_grocery\n" 
    465         "n      shop=drogist            poi_shop_drugstore\n" 
    466         "n      shop=florist            poi_shop_florist\n" 
    467         "n      shop=fruit              poi_shop_fruit\n" 
    468         "n      shop=furniture          poi_shop_furniture\n" 
    469         "n      shop=garden_centre      poi_shop_handg\n" 
    470         "n      shop=hardware           poi_shop_handg\n" 
    471         "n      shop=hairdresser        poi_hairdresser\n" 
    472         "n      shop=kiosk              poi_shop_kiosk\n" 
    473         "n      shop=optician           poi_shop_optician\n" 
    474         "n      shop=parfum             poi_shop_parfum\n" 
    475         "n      shop=photo              poi_shop_photo\n" 
    476         "n      shop=shoes              poi_shop_shoes\n" 
    477         "n      shop=supermarket        poi_shopping\n" 
    478         "n      sport=10pin             poi_bowling\n" 
    479         "n      sport=baseball          poi_baseball\n" 
    480         "n      sport=basketball        poi_basketball\n" 
    481         "n      sport=climbing          poi_climbing\n" 
    482         "n      sport=golf              poi_golf\n" 
    483         "n      sport=motor_sports      poi_motor_sport\n" 
    484         "n      sport=skiing            poi_skiing\n" 
    485         "n      sport=soccer            poi_soccer\n" 
    486         "n      sport=stadium           poi_stadium\n" 
    487         "n      sport=swimming          poi_swimming\n" 
    488         "n      sport=tennis            poi_tennis\n" 
    489         "n      tourism=attraction      poi_attraction\n" 
    490         "n      tourism=camp_site       poi_camp_rv\n" 
    491         "n      tourism=caravan_site    poi_camp_rv\n" 
    492         "n      tourism=guest_house     poi_guesthouse\n" 
    493         "n      tourism=hostel          poi_hostel\n" 
    494         "n      tourism=hotel           poi_hotel\n" 
    495         "n      tourism=information     poi_information\n" 
    496         "n      tourism=motel           poi_motel\n" 
    497         "n      tourism=museum          poi_museum_history\n" 
    498         "n      tourism=picnic_site     poi_picnic\n" 
    499         "n      tourism=theme_park      poi_resort\n" 
    500         "n      tourism=viewpoint       poi_viewpoint\n" 
    501         "n      tourism=zoo             poi_zoo\n" 
     458        "?      railway=station         poi_rail_station\n" 
     459        "?      railway=tram_stop       poi_rail_tram_stop\n" 
     460        "?      shop=baker              poi_shop_baker\n" 
     461        "?      shop=bakery             poi_shop_baker\n" 
     462        "?      shop=beverages          poi_shop_beverages\n" 
     463        "?      shop=bicycle            poi_shop_bicycle\n" 
     464        "?      shop=butcher            poi_shop_butcher\n" 
     465        "?      shop=car                poi_car_dealer_parts\n" 
     466        "?      shop=car_repair         poi_repair_service\n" 
     467        "?      shop=clothes            poi_shop_apparel\n" 
     468        "?      shop=convenience        poi_shop_grocery\n" 
     469        "?      shop=drogist            poi_shop_drugstore\n" 
     470        "?      shop=florist            poi_shop_florist\n" 
     471        "?      shop=fruit              poi_shop_fruit\n" 
     472        "?      shop=furniture          poi_shop_furniture\n" 
     473        "?      shop=garden_centre      poi_shop_handg\n" 
     474        "?      shop=hardware           poi_shop_handg\n" 
     475        "?      shop=hairdresser        poi_hairdresser\n" 
     476        "?      shop=kiosk              poi_shop_kiosk\n" 
     477        "?      shop=optician           poi_shop_optician\n" 
     478        "?      shop=parfum             poi_shop_parfum\n" 
     479        "?      shop=photo              poi_shop_photo\n" 
     480        "?      shop=shoes              poi_shop_shoes\n" 
     481        "?      shop=supermarket        poi_shopping\n" 
     482        "?      sport=10pin             poi_bowling\n" 
     483        "?      sport=baseball          poi_baseball\n" 
     484        "?      sport=basketball        poi_basketball\n" 
     485        "?      sport=climbing          poi_climbing\n" 
     486        "?      sport=golf              poi_golf\n" 
     487        "?      sport=motor_sports      poi_motor_sport\n" 
     488        "?      sport=skiing            poi_skiing\n" 
     489        "?      sport=soccer            poi_soccer\n" 
     490        "?      sport=stadium           poi_stadium\n" 
     491        "?      sport=swimming          poi_swimming\n" 
     492        "?      sport=tennis            poi_tennis\n" 
     493        "?      tourism=attraction      poi_attraction\n" 
     494        "?      tourism=camp_site       poi_camp_rv\n" 
     495        "?      tourism=caravan_site    poi_camp_rv\n" 
     496        "?      tourism=guest_house     poi_guesthouse\n" 
     497        "?      tourism=hostel          poi_hostel\n" 
     498        "?      tourism=hotel           poi_hotel\n" 
     499        "?      tourism=information     poi_information\n" 
     500        "?      tourism=motel           poi_motel\n" 
     501        "?      tourism=museum          poi_museum_history\n" 
     502        "?      tourism=picnic_site     poi_picnic\n" 
     503        "?      tourism=theme_park      poi_resort\n" 
     504        "?      tourism=viewpoint       poi_viewpoint\n" 
     505        "?      tourism=zoo             poi_zoo\n" 
    502506        "n      traffic_sign=city_limit traffic_sign_city_limit\n" 
    503507        "n      highway=speed_camera    tec_common\n" 
    504508        "w      *=*                     street_unkn\n" 
     
    710714build_attrmap_line(char *line) 
    711715{ 
    712716        char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv; 
    713         struct attr_mapping ***attr_mapping_curr,*attr_mapping=g_malloc0(sizeof(struct attr_mapping)); 
    714         int idx,attr_mapping_count=0,*attr_mapping_curr_count; 
     717        struct attr_mapping *attr_mapping=g_malloc0(sizeof(struct attr_mapping)); 
     718        int idx,attr_mapping_count=0; 
    715719        t=line; 
    716720        p=strchr(t,'\t'); 
    717721        if (p) { 
     
    728732        if (t[0] == 'w') { 
    729733                if (! i) 
    730734                        i="street_unkn"; 
    731                 attr_mapping_curr=&attr_mapping_way; 
    732                 attr_mapping_curr_count=&attr_mapping_way_count; 
    733735        } else { 
    734736                if (! i) 
    735737                        i="point_unkn"; 
    736                 attr_mapping_curr=&attr_mapping_node; 
    737                 attr_mapping_curr_count=&attr_mapping_node_count; 
    738738        } 
    739739        attr_mapping->type=item_from_name(i); 
    740740        while ((kv=strtok(kvl, ","))) { 
     
    747747                attr_mapping->attr_present_idx[attr_mapping_count++]=idx; 
    748748                attr_mapping->attr_present_idx_count=attr_mapping_count; 
    749749        } 
    750         *attr_mapping_curr=g_realloc(*attr_mapping_curr, sizeof(**attr_mapping_curr)*(*attr_mapping_curr_count+1)); 
    751         (*attr_mapping_curr)[(*attr_mapping_curr_count)++]=attr_mapping; 
     750        if (t[0]== 'w' || t[0]== '?') { 
     751                attr_mapping_way=g_realloc(attr_mapping_way, sizeof(*attr_mapping_way)*(attr_mapping_way_count+1)); 
     752                attr_mapping_way[attr_mapping_way_count++]=attr_mapping; 
     753        } 
     754        if (t[0]!= 'w') { 
     755                attr_mapping_node=g_realloc(attr_mapping_node, sizeof(*attr_mapping_node)*(attr_mapping_node_count+1)); 
     756                attr_mapping_node[attr_mapping_node_count++]=attr_mapping; 
     757        } 
     758 
    752759} 
    753760 
    754761static void 
     
    12831290                if (interval > 1) 
    12841291                        interval/=2; 
    12851292        } 
    1286  
    12871293        return &ni[p]; 
    12881294} 
    12891295 
     
    15091515} 
    15101516 
    15111517void 
    1512 osm_end_way(FILE *out) 
     1518osm_end_way(FILE *out, FILE *outwaypoi) 
    15131519{ 
    15141520        int i,count; 
    15151521        int *def_flags,add_flags; 
     
    15421548                        continue; 
    15431549                if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) 
    15441550                        continue; 
     1551                if(!outwaypoi && types[i]<type_line) 
     1552                        continue; 
    15451553                item_bin=init_item(types[i]); 
    15461554                item_bin_add_coord(item_bin, coord_buffer, coord_count); 
    15471555                def_flags=item_get_default_flags(types[i]); 
     
    15511559                                add_flags=1; 
    15521560                } 
    15531561                item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]); 
    1554                 item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]); 
     1562                if(item_bin->type>type_line) { 
     1563                        item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]); 
     1564                } 
    15551565                item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); 
    15561566                if (debug_attr_buffer[0]) 
    15571567                        item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); 
    1558                 if (add_flags) 
    1559                         item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); 
    1560                 if (maxspeed_attr_value) 
    1561                         item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); 
    1562                 item_bin_write(item_bin,out); 
     1568                if(types[i]>=type_line) { 
     1569                        if (add_flags) 
     1570                                item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); 
     1571                        if (maxspeed_attr_value) 
     1572                                item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); 
     1573                        item_bin_write(item_bin,out); 
     1574                } else { 
     1575                        item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); 
     1576                        item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); 
     1577                        item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); 
     1578                        item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); 
     1579                        item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); 
     1580                        item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);  
     1581                        item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); 
     1582 
     1583                        if(outwaypoi) { 
     1584                                item_bin_write(item_bin,outwaypoi); 
     1585                        } 
     1586                } 
    15631587        } 
    15641588} 
    15651589 
     
    19792003        fclose(in); 
    19802004} 
    19812005 
    1982 static void 
    1983 node_ref_way(osmid node) 
     2006struct node_item * 
     2007node_ref_way(osmid node, int countreferences) 
    19842008{ 
    19852009        struct node_item *ni; 
    19862010        ni=node_item_get(node); 
    1987         if (ni) 
     2011        if (ni && countreferences) 
    19882012                ni->ref_way++; 
     2013        return ni; 
    19892014} 
    19902015 
    1991 int 
    1992 resolve_ways(FILE *in, FILE *out) 
    1993 { 
    1994         struct item_bin *ib; 
    1995         struct coord *c; 
    1996         int i; 
    19972016 
    1998         fseek(in, 0, SEEK_SET); 
    1999         while ((ib=read_item(in))) { 
    2000                 c=(struct coord *)(ib+1); 
    2001                 for (i = 0 ; i < ib->clen/2 ; i++) { 
    2002                         node_ref_way(REF(c[i])); 
    2003                 } 
    2004         } 
    2005         return 0; 
    2006 } 
    2007  
    20082017void 
    20092018osm_add_nd(osmid ref) 
    20102019{ 
    20112020        SET_REF(coord_buffer[coord_count], ref); 
    2012         node_ref_way(ref); 
     2021        node_ref_way(ref,1); 
    20132022        coord_count++; 
    20142023        if (coord_count > 65536) { 
    20152024                fprintf(stderr,"ERROR: Overflow\n"); 
     
    20572066} 
    20582067 
    20592068int 
     2069resolve_ways(FILE *in, FILE *out, int countreferences) 
     2070{ 
     2071        struct item_bin *ib; 
     2072        struct coord *c; 
     2073        int i; 
     2074        struct node_item *ni; 
     2075 
     2076        fseek(in, 0, SEEK_SET); 
     2077        while ((ib=read_item(in))) { 
     2078                int unresolved=0; 
     2079                c=(struct coord *)(ib+1); 
     2080                for (i = 0 ; i < ib->clen/2 ; i++) { 
     2081                        if(!IS_REF(c[i])) 
     2082                                continue; 
     2083                        ni=node_ref_way(REF(c[i]), countreferences); 
     2084                        if(ni && out) { 
     2085                                c[i].x=ni->c.x; 
     2086                                c[i].y=ni->c.y; 
     2087                        } 
     2088                        else 
     2089                            unresolved++; 
     2090                } 
     2091                if(out) { 
     2092                        if(unresolved==0 && ib->clen>2 && ib->type<type_line) { 
     2093                                if(ib->clen/2>2) { 
     2094                                        if(!geom_poly_centroid(c,ib->clen/2,c)) { 
     2095                                                // we have poly with zero area 
     2096                                                // Falling back to coordinates of its first vertex... 
     2097                                                osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, area is 0\n"); 
     2098                                        } 
     2099                                } else if (ib->clen/2==2) { 
     2100                                        osm_warning("way",item_bin_get_wayid(ib),0, "Expected polygon, but only two points defined\n"); 
     2101                                        c[0].x=(c[0].x+c[1].x)/2; 
     2102                                        c[0].y=(c[0].y+c[1].y)/2; 
     2103                                } 
     2104                                write_item_part(out, NULL, NULL, ib, 0, 0, NULL); 
     2105                        } else  { 
     2106                                item_bin_write(ib,out); 
     2107                        } 
     2108                } 
     2109        } 
     2110        return 0; 
     2111} 
     2112 
     2113 
     2114int 
    20602115map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final) 
    20612116{ 
    20622117        struct coord *c; 
  • navit/maptool/maptool.c

     
    112112        fprintf(f,"bzcat planet.osm.bz2 | maptool mymap.bin\n"); 
    113113        fprintf(f,"Available switches:\n"); 
    114114        fprintf(f,"-h (--help)              : this screen\n"); 
     115        fprintf(f,"-2 (--doway2poi)           : convert ways and polygons to POIs when applicable\n"); 
    115116        fprintf(f,"-5 (--md5)               : set file where to write md5 sum\n"); 
    116117        fprintf(f,"-6 (--64bit)             : set zip 64 bit compression\n"); 
    117118        fprintf(f,"-a (--attr-debug-level)  : control which data is included in the debug attribute\n"); 
     
    122123        fprintf(f,"-e (--end)               : end at specified phase\n"); 
    123124        fprintf(f,"-i (--input-file)        : specify the input file name (OSM), overrules default stdin\n"); 
    124125        fprintf(f,"-k (--keep-tmpfiles)     : do not delete tmp files after processing. useful to reuse them\n\n"); 
    125         fprintf(f,"-M (--o5m)               : input file os o5m\n"); 
     126        fprintf(f,"-M (--o5m)               : input file os o5m\n"); 
    126127        fprintf(f,"-N (--nodes-only)        : process only nodes\n"); 
    127128        fprintf(f,"-o (--coverage)          : map every street to item coverage\n"); 
    128129        fprintf(f,"-P (--protobuf)          : input file is protobuf\n"); 
     
    139140 
    140141int main(int argc, char **argv) 
    141142{ 
    142         FILE *ways=NULL,*ways_split=NULL,*ways_split_index=NULL,*nodes=NULL,*turn_restrictions=NULL,*graph=NULL,*coastline=NULL,*tilesdir,*coords,*relations=NULL,*boundaries=NULL; 
     143        FILE *ways=NULL, *way2poi=NULL, *ways_split=NULL,*ways_split_index=NULL,*nodes=NULL,*turn_restrictions=NULL,*graph=NULL,*coastline=NULL,*tilesdir,*coords,*relations=NULL,*boundaries=NULL; 
    143144        FILE *files[10]; 
    144145        FILE *references[10]; 
    145146 
     
    159160        int input=0; 
    160161        int protobuf=0; 
    161162        int o5m=0; 
     163        int doway2poi=0; 
    162164        int f,pos; 
    163165        char *result,*optarg_cp,*attr_name,*attr_value; 
    164166        char *protobufdb=NULL,*protobufdb_operation=NULL,*md5file=NULL; 
     
    199201#endif 
    200202                int option_index = 0; 
    201203                static struct option long_options[] = { 
     204                        {"doway2poi", 0, 0, '2'}, 
    202205                        {"md5", 1, 0, '5'}, 
    203206                        {"64bit", 0, 0, '6'}, 
    204207                        {"attr-debug-level", 1, 0, 'a'}, 
     
    228231                        {"unknown-country", 0, 0, 'U'}, 
    229232                        {0, 0, 0, 0} 
    230233                }; 
    231                 c = getopt_long (argc, argv, "5:6B:DMNO:PWS:a:bc" 
     234                c = getopt_long (argc, argv, "25:6B:DMNO:PWS:a:bc" 
    232235#ifdef HAVE_POSTGRESQL 
    233236                                              "d:" 
    234237#endif 
     
    236239                if (c == -1) 
    237240                        break; 
    238241                switch (c) { 
     242                case '2': 
     243                        doway2poi=1; 
     244                        break; 
    239245                case '5': 
    240246                        md5file=optarg; 
    241247                        break; 
     
    386392                        ways=tempfile(suffix,"ways",1); 
    387393                if (process_nodes) 
    388394                        nodes=tempfile(suffix,"nodes",1); 
    389                 if (process_ways && process_nodes) 
     395                if (process_ways && process_nodes) { 
    390396                        turn_restrictions=tempfile(suffix,"turn_restrictions",1); 
     397                        if(doway2poi) 
     398                                way2poi=tempfile(suffix,"way2poi",1); 
     399                } 
    391400                if (process_relations) 
    392401                        boundaries=tempfile(suffix,"boundaries",1); 
    393402                phase=1; 
    394403                fprintf(stderr,"PROGRESS: Phase 1: collecting data\n"); 
    395404#ifdef HAVE_POSTGRESQL 
    396405                if (dbstr) 
    397                         map_collect_data_osm_db(dbstr,ways,nodes,turn_restrictions,boundaries); 
     406                        map_collect_data_osm_db(dbstr,ways,way2poi,nodes,turn_restrictions,boundaries); 
    398407                else 
    399408#endif 
    400409                if (map_handles) { 
     
    407416                        } 
    408417                } 
    409418                else if (protobuf) 
    410                         map_collect_data_osm_protobuf(input_file,ways,nodes,turn_restrictions,boundaries); 
     419                        map_collect_data_osm_protobuf(input_file,ways,way2poi,nodes,turn_restrictions,boundaries); 
    411420                else if (o5m) 
    412                         map_collect_data_osm_o5m(input_file,ways,nodes,turn_restrictions,boundaries); 
     421                        map_collect_data_osm_o5m(input_file,ways,way2poi,nodes,turn_restrictions,boundaries); 
    413422                else 
    414                         map_collect_data_osm(input_file,ways,nodes,turn_restrictions,boundaries); 
     423                        map_collect_data_osm(input_file,ways,way2poi,nodes,turn_restrictions,boundaries); 
    415424                if (slices) { 
    416425                        fprintf(stderr,"%d slices\n",slices); 
    417426                        flush_nodes(1); 
    418427                        for (i = slices-2 ; i>=0 ; i--) { 
    419428                                fprintf(stderr, "slice %d of %d\n",slices-i-1,slices-1); 
    420429                                load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size); 
    421                                 resolve_ways(ways, NULL); 
     430                                resolve_ways(ways, NULL, 1); 
    422431                                save_buffer("coords.tmp",&node_buffer, i*slice_size); 
     432                                if(way2poi) { 
     433                                        FILE *way2poinew=tempfile(suffix,"way2poinew",1); 
     434                                        resolve_ways(way2poi, way2poinew, 0); 
     435                                        fclose(way2poi); 
     436                                        fclose(way2poinew); 
     437                                        tempfile_rename(suffix,"way2poinew","way2poi"); 
     438                                        way2poi=tempfile(suffix,"way2poi",0); 
     439                                } 
    423440                        } 
    424                 } else 
     441                } else { 
    425442                        save_buffer("coords.tmp",&node_buffer, 0); 
     443                        if(way2poi) { 
     444                                FILE *way2poinew=tempfile(suffix,"way2poinew",1); 
     445                                resolve_ways(way2poi, way2poinew, 0); 
     446                                fclose(way2poi); 
     447                                fclose(way2poinew); 
     448                                tempfile_rename(suffix,"way2poinew","way2poi"); 
     449                                way2poi=tempfile(suffix,"way2poi",0); 
     450                        } 
     451                } 
    426452                if (ways) 
    427453                        fclose(ways); 
     454                if (way2poi) { 
     455                        fclose(way2poi); 
     456                        way2poi=tempfile(suffix,"way2poi",0); 
     457                        process_binfile(way2poi, nodes); 
     458                        fclose(way2poi); 
     459                } 
    428460                if (nodes) 
    429461                        fclose(nodes); 
    430462                if (turn_restrictions) 
     
    578610                                        files[1]=tempfile(suffix,"ways_split",0); 
    579611                                if (process_nodes) 
    580612                                        files[2]=tempfile(suffix,"nodes",0); 
     613 
    581614                                phase4(files,3,0,suffix,tilesdir,zip_info); 
    582615                                for (f = 0 ; f < 3 ; f++) { 
    583616                                        if (files[f]) 
     
    628661                                } 
    629662                                if (process_nodes) 
    630663                                        files[2]=tempfile(suffix,"nodes",0); 
     664 
    631665                                fprintf(stderr,"Slice %d\n",i); 
    632666 
    633667                                phase5(files,references,3,0,suffix,zip_info); 
     
    642676                                tempfile_unlink(suffix,"relations"); 
    643677                                tempfile_unlink(suffix,"nodes"); 
    644678                                tempfile_unlink(suffix,"ways_split"); 
     679                                tempfile_unlink(suffix,"way2poi"); 
    645680                                tempfile_unlink(suffix,"ways_split_ref"); 
    646681                                tempfile_unlink(suffix,"coastline"); 
    647682                                tempfile_unlink(suffix,"turn_restrictions"); 
  • navit/maptool/osm_o5m.c

     
    170170} 
    171171 
    172172int 
    173 map_collect_data_osm_o5m(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 
     173map_collect_data_osm_o5m(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 
    174174{ 
    175175        struct o5m o; 
    176176        unsigned char c, *end, *rend; 
     
    304304                                osm_end_node(out_nodes); 
    305305                                break; 
    306306                        case 0x11: 
    307                                 osm_end_way(out_ways); 
     307                                osm_end_way(out_ways, out_way2poi); 
    308308                                break; 
    309309                        case 0x12: 
    310310                                osm_end_relation(out_turn_restrictions, out_boundaries); 
  • navit/maptool/osm_xml.c

     
    178178} 
    179179 
    180180int 
    181 map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 
     181map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 
    182182{ 
    183183        int size=BUFFER_SIZE; 
    184184        char buffer[size]; 
     
    217217                } else if (!strncmp(p, "</node>",7)) { 
    218218                        osm_end_node(out_nodes); 
    219219                } else if (!strncmp(p, "</way>",6)) { 
    220                         osm_end_way(out_ways); 
     220                        osm_end_way(out_ways, out_way2poi); 
    221221                } else if (!strncmp(p, "</relation>",11)) { 
    222222                        osm_end_relation(out_turn_restrictions, out_boundaries); 
    223223                } else if (!strncmp(p, "</osm>",6)) { 
  • navit/maptool/osm_protobuf.c

     
    241241#endif 
    242242 
    243243static void 
    244 process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, FILE *out_ways) 
     244process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, FILE *out_ways, FILE *out_way2poi) 
    245245{ 
    246246        int i; 
    247247        long long ref=0; 
     
    266266#if 0 
    267267        printf("\t</way>\n"); 
    268268#endif 
    269         osm_end_way(out_ways); 
     269        osm_end_way(out_ways, out_way2poi); 
    270270} 
    271271 
    272272static void 
     
    318318} 
    319319 
    320320static void 
    321 process_osmdata(OSMPBF__Blob *blob, unsigned char *data, FILE *out_nodes, FILE *out_ways, FILE *out_turn_restrictions, FILE *out_boundaries) 
     321process_osmdata(OSMPBF__Blob *blob, unsigned char *data, FILE *out_nodes, FILE *out_ways, FILE *out_way2poi, FILE *out_turn_restrictions, FILE *out_boundaries) 
    322322{ 
    323323        int i,j; 
    324324        OSMPBF__PrimitiveBlock *primitive_block; 
     
    327327                OSMPBF__PrimitiveGroup *primitive_group=primitive_block->primitivegroup[i]; 
    328328                process_dense(primitive_block, primitive_group->dense, out_nodes); 
    329329                for (j = 0 ; j < primitive_group->n_ways ; j++) 
    330                         process_way(primitive_block, primitive_group->ways[j], out_ways); 
     330                        process_way(primitive_block, primitive_group->ways[j], out_ways, out_way2poi); 
    331331                for (j = 0 ; j < primitive_group->n_relations ; j++) 
    332332                        process_relation(primitive_block, primitive_group->relations[j], out_turn_restrictions, out_boundaries); 
    333333#if 0 
     
    339339 
    340340 
    341341int 
    342 map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 
     342map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 
    343343{ 
    344344        OSMPBF__BlobHeader *header; 
    345345        OSMPBF__Blob *blob; 
     
    354354                if (!strcmp(header->type,"OSMHeader")) { 
    355355                        process_osmheader(blob, data); 
    356356                } else if (!strcmp(header->type,"OSMData")) { 
    357                         process_osmdata(blob, data, out_nodes, out_ways, out_turn_restrictions, out_boundaries); 
     357                        process_osmdata(blob, data, out_nodes, out_ways, out_way2poi, out_turn_restrictions, out_boundaries); 
    358358                } else { 
    359359                        printf("unknown\n"); 
    360360                        return 0; 
  • navit/maptool/maptool.h

     
    144144void geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse); 
    145145void geom_coord_revert(struct coord *c, int count); 
    146146long long geom_poly_area(struct coord *c, int count); 
     147int geom_poly_centroid(struct coord *c, int count, struct coord *r); 
     148int geom_poly_closest_point(struct coord *pl, int count, struct coord *p, struct coord *c); 
    147149GList *geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third); 
    148150void geom_poly_segment_destroy(struct geom_poly_segment *seg); 
    149151GList *geom_poly_segments_remove(GList *list, struct geom_poly_segment *seg); 
     
    235237void osm_add_relation(osmid id); 
    236238void osm_end_relation(FILE *turn_restrictions, FILE *boundaries); 
    237239void osm_add_member(int type, osmid ref, char *role); 
    238 void osm_end_way(FILE *out); 
     240void osm_end_way(FILE *out, FILE *outwaypoi); 
    239241void osm_end_node(FILE *out); 
    240242void osm_add_nd(osmid ref); 
    241243long long item_bin_get_id(struct item_bin *ib); 
    242244void flush_nodes(int final); 
    243245void sort_countries(int keep_tmpfiles); 
    244246void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out); 
    245 int resolve_ways(FILE *in, FILE *out); 
     247int resolve_ways(FILE *in, FILE *out, int countreferences); 
    246248int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final); 
    247249void write_countrydir(struct zip_info *zip_info); 
    248250void remove_countryfiles(void); 
    249251void osm_init(FILE*); 
    250252 
    251253/* osm_o5m.c */ 
    252 int map_collect_data_osm_o5m(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 
     254int map_collect_data_osm_o5m(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 
    253255 
    254256/* osm_psql.c */ 
    255 int map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 
     257int map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 
    256258 
    257259/* osm_protobuf.c */ 
    258 int map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 
     260int map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 
    259261int osm_protobufdb_load(FILE *in, char *dir); 
    260262 
    261263/* osm_xml.c */ 
    262264int osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size); 
    263265void osm_xml_decode_entities(char *buffer); 
    264 int map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 
     266int map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 
    265267 
    266268 
    267269/* sourcesink.c */ 
  • navit/maptool/geom.c

     
    6060#if 0 
    6161                fprintf(stderr,"(%d+%d)*(%d-%d)=%d*%d="LONGLONG_FMT"\n",c[i].x,c[j].x,c[i].y,c[j].y,c[i].x+c[j].x,c[i].y-c[j].y,(long long)(c[i].x+c[j].x)*(c[i].y-c[j].y)); 
    6262#endif 
    63                 area+=(long long)(c[i].x+c[j].x)*(c[i].y-c[j].y); 
     63                area+=(long long)(c[i].x+c[j].x)*(c[i].y-c[j].y); 
    6464#if 0 
    6565                fprintf(stderr,"area="LONGLONG_FMT"\n",area); 
    6666#endif 
     
    6868        return area/2; 
    6969} 
    7070 
     71/** 
     72  * Get poly centroid coordinates. 
     73  * @param in *p array of poly vertex coordinates 
     74  * @param in count count of poly vertexes 
     75  * @param out *c coordinates of poly centroid 
     76  * @returns 1 on success, 0 if poly area is 0 
     77  */ 
     78int 
     79geom_poly_centroid(struct coord *p, int count, struct coord *c) 
     80{ 
     81        long long area=0/*geom_poly_area(p, count)*/; 
     82        long long sx=0,sy=0,tmp; 
     83        int i,j; 
     84        long long x0=p[0].x, y0=p[0].y, xi, yi, xj, yj; 
     85         
     86        /*fprintf(stderr,"area="LONGLONG_FMT"\n", area );*/ 
     87        for (i=0,j=0; i<count; i++) { 
     88                if (++j == count) 
     89                        j=0; 
     90                xi=p[i].x-x0; 
     91                yi=p[i].y-y0; 
     92                xj=p[j].x-x0; 
     93                yj=p[j].y-y0; 
     94                tmp=(xi*yj-xj*yi); 
     95                sx+=(xi+xj)*tmp; 
     96                sy+=(yi+yj)*tmp; 
     97                area+=xi*yj-xj*yi; 
     98        } 
     99        if(area!=0) { 
     100                c->x=x0+sx/3/area; 
     101                c->y=y0+sy/3/area; 
     102                return 1; 
     103        } 
     104        return 0; 
     105} 
     106 
     107/** 
     108  * Get coordinates of polyline point c most close to given point p. 
     109  * @param in *pl array of polyline vertex coordinates 
     110  * @param in count count of polyline vertexes 
     111  * @param in *p point coordinates  
     112  * @param out *c coordinates of polyline point most close to given point. 
     113  * @returns first vertex number of polyline segment to which c belongs 
     114  */ 
     115int 
     116geom_poly_closest_point(struct coord *pl, int count, struct coord *p, struct coord *c) 
     117{ 
     118        int i,vertex=0; 
     119        long long x, y, xi, xj, yi, yj, u, d, dmin=0; 
     120        if(count<2) { 
     121                c->x=pl->x; 
     122                c->y=pl->y; 
     123                return 0; 
     124        } 
     125        for(i=0;i<count-1;i++) { 
     126                xi=pl[i].x; 
     127                yi=pl[i].y; 
     128                xj=pl[i+1].x; 
     129                yj=pl[i+1].y; 
     130                u=(xj-xi)*(xj-xi)+(yj-yi)*(yj-yi); 
     131                if(u!=0) { 
     132                        u=((p->x-xi)*(xj-xi)+(p->y-yi)*(yj-yi))*1000/u; 
     133                } 
     134                if(u<0)  
     135                        u=0; 
     136                else if (u>1000)  
     137                        u=1000; 
     138                x=xi+u*(xj-xi)/1000; 
     139                y=yi+u*(yj-yi)/1000; 
     140                d=(p->x-x)*(p->x-x)+(p->y-y)*(p->y-y); 
     141                if(i==0 || d<dmin) { 
     142                        dmin=d; 
     143                        c->x=x; 
     144                        c->y=y; 
     145                        vertex=i; 
     146                } 
     147        } 
     148        return vertex; 
     149} 
     150 
     151 
    71152GList * 
    72153geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third) 
    73154{ 
  • navit/maptool/osm_psql.c

     
    2828#include <libpq-fe.h> 
    2929 
    3030int 
    31 map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 
     31map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 
    3232{ 
    3333        PGconn *conn; 
    3434        PGresult *res,*node,*way,*tag; 
     
    169169                                        break; 
    170170                        } 
    171171                        if (tagged) 
    172                                 osm_end_way(out_ways); 
     172                                osm_end_way(out_ways, out_way2poi); 
    173173                } 
    174174                PQclear(tag); 
    175175                PQclear(node);