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) |
|---|
-
navit/maptool/osm.c
351 351 { 999,"Unknown"}, 352 352 }; 353 353 354 // first char - item type 355 // =w - ways 356 // =? - used both for nodes and ways 357 // otherwise - nodes 354 358 355 359 static char *attrmap={ 356 360 "n *=* point_unkn\n" 357 361 // "n Annehmlichkeit=Hochsitz poi_hunting_stand\n" 358 " naddr:housenumber=* house_number\n"359 " naeroway=aerodrome poi_airport\n"360 " naeroway=airport poi_airport\n"361 " naeroway=helipad poi_heliport\n"362 " naeroway=terminal poi_airport\n"363 " namenity=atm poi_bank\n"364 " namenity=bank poi_bank\n"365 " namenity=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" 366 370 "n amenity=bench poi_bench\n" 367 " namenity=biergarten poi_biergarten\n"368 " namenity=bus_station poi_bus_station\n"369 " namenity=cafe poi_cafe\n"370 " namenity=car_wash poi_car_wash\n"371 " namenity=cinema poi_cinema\n"372 " namenity=college poi_school_college\n"373 " namenity=courthouse poi_justice\n"374 " namenity=drinking_water poi_potable_water\n"375 " namenity=fast_food poi_fastfood\n"376 " namenity=fire_station poi_firebrigade\n"377 " namenity=fountain poi_fountain\n"378 " namenity=fuel poi_fuel\n"379 " namenity=grave_yard poi_cemetery\n"380 " namenity=hospital poi_hospital\n"381 " namenity=hunting_stand poi_hunting_stand\n"382 " namenity=kindergarten poi_kindergarten\n"383 " namenity=library poi_library\n"384 " namenity=nightclub poi_nightclub\n"385 " namenity=park_bench poi_bench\n"386 " namenity=parking poi_car_parking\n"387 " namenity=pharmacy poi_pharmacy\n"388 " namenity=place_of_worship,religion=christian poi_church\n"389 " namenity=place_of_worship poi_worship\n"390 " namenity=police poi_police\n"391 " namenity=post_box poi_post_box\n"392 " namenity=post_office poi_post_office\n"393 " namenity=prison poi_prison\n"394 " namenity=pub poi_pub\n"395 " namenity=public_building poi_public_office\n"396 " namenity=recycling poi_recycling\n"397 " namenity=restaurant,cuisine=fine_dining poi_dining\n"398 " namenity=restaurant poi_restaurant\n"399 " namenity=school poi_school\n"400 " namenity=shelter poi_shelter\n"401 " namenity=taxi poi_taxi\n"402 " namenity=tec_common tec_common\n"403 " namenity=telephone poi_telephone\n"404 " namenity=theatre poi_theater\n"405 " namenity=toilets poi_restroom\n"406 " namenity=townhall poi_townhall\n"407 " namenity=university poi_school_university\n"408 " namenity=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" 409 413 "n barrier=bollard barrier_bollard\n" 410 414 "n barrier=cycle_barrier barrier_cycle\n" 411 415 "n barrier=lift_gate barrier_lift_gate\n" 412 " ncar=car_rental poi_car_rent\n"413 " nhighway=bus_station poi_bus_station\n"414 " nhighway=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" 415 419 "n highway=mini_roundabout mini_roundabout\n" 416 420 "n highway=motorway_junction highway_exit\n" 417 421 "n highway=stop traffic_sign_stop\n" 418 422 "n highway=toll_booth poi_toll_booth\n" 419 423 "n highway=traffic_signals traffic_signals\n" 420 424 "n highway=turning_circle turning_circle\n" 421 " nhistoric=boundary_stone poi_boundary_stone\n"422 " nhistoric=castle poi_castle\n"423 " nhistoric=memorial poi_memorial\n"424 " nhistoric=monument poi_monument\n"425 " nhistoric=ruins poi_ruins\n"426 // " nhistoric=* poi_ruins\n"427 " nlanduse=cemetery poi_cemetery\n"428 " nleisure=fishing poi_fish\n"429 " nleisure=golf_course poi_golf\n"430 " nleisure=marina poi_marine\n"431 " nleisure=playground poi_playground\n"432 " nleisure=slipway poi_boat_ramp\n"433 " nleisure=sports_centre poi_sport\n"434 " nleisure=stadium poi_stadium\n"435 " nman_made=tower poi_tower\n"436 " nmilitary=airfield poi_military\n"437 " nmilitary=barracks poi_military\n"438 " nmilitary=bunker poi_military\n"439 " nmilitary=danger_area poi_danger_area\n"440 " nmilitary=range poi_military\n"441 " nnatural=bay poi_bay\n"442 " nnatural=peak,ele=* poi_peak\n" // show only major peaks with elevation443 " nnatural=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" 444 448 "n place=city town_label_2e5\n" 445 449 "n place=hamlet town_label_2e2\n" 446 450 "n place=locality town_label_2e0\n" … … 451 455 "n power=sub_station power_substation\n" 452 456 "n railway=halt poi_rail_halt\n" 453 457 "n railway=level_crossing poi_level_crossing\n" 454 " nrailway=station poi_rail_station\n"455 " nrailway=tram_stop poi_rail_tram_stop\n"456 " nshop=baker poi_shop_baker\n"457 " nshop=bakery poi_shop_baker\n"458 " nshop=beverages poi_shop_beverages\n"459 " nshop=bicycle poi_shop_bicycle\n"460 " nshop=butcher poi_shop_butcher\n"461 " nshop=car poi_car_dealer_parts\n"462 " nshop=car_repair poi_repair_service\n"463 " nshop=clothes poi_shop_apparel\n"464 " nshop=convenience poi_shop_grocery\n"465 " nshop=drogist poi_shop_drugstore\n"466 " nshop=florist poi_shop_florist\n"467 " nshop=fruit poi_shop_fruit\n"468 " nshop=furniture poi_shop_furniture\n"469 " nshop=garden_centre poi_shop_handg\n"470 " nshop=hardware poi_shop_handg\n"471 " nshop=hairdresser poi_hairdresser\n"472 " nshop=kiosk poi_shop_kiosk\n"473 " nshop=optician poi_shop_optician\n"474 " nshop=parfum poi_shop_parfum\n"475 " nshop=photo poi_shop_photo\n"476 " nshop=shoes poi_shop_shoes\n"477 " nshop=supermarket poi_shopping\n"478 " nsport=10pin poi_bowling\n"479 " nsport=baseball poi_baseball\n"480 " nsport=basketball poi_basketball\n"481 " nsport=climbing poi_climbing\n"482 " nsport=golf poi_golf\n"483 " nsport=motor_sports poi_motor_sport\n"484 " nsport=skiing poi_skiing\n"485 " nsport=soccer poi_soccer\n"486 " nsport=stadium poi_stadium\n"487 " nsport=swimming poi_swimming\n"488 " nsport=tennis poi_tennis\n"489 " ntourism=attraction poi_attraction\n"490 " ntourism=camp_site poi_camp_rv\n"491 " ntourism=caravan_site poi_camp_rv\n"492 " ntourism=guest_house poi_guesthouse\n"493 " ntourism=hostel poi_hostel\n"494 " ntourism=hotel poi_hotel\n"495 " ntourism=information poi_information\n"496 " ntourism=motel poi_motel\n"497 " ntourism=museum poi_museum_history\n"498 " ntourism=picnic_site poi_picnic\n"499 " ntourism=theme_park poi_resort\n"500 " ntourism=viewpoint poi_viewpoint\n"501 " ntourism=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" 502 506 "n traffic_sign=city_limit traffic_sign_city_limit\n" 503 507 "n highway=speed_camera tec_common\n" 504 508 "w *=* street_unkn\n" … … 710 714 build_attrmap_line(char *line) 711 715 { 712 716 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; 715 719 t=line; 716 720 p=strchr(t,'\t'); 717 721 if (p) { … … 728 732 if (t[0] == 'w') { 729 733 if (! i) 730 734 i="street_unkn"; 731 attr_mapping_curr=&attr_mapping_way;732 attr_mapping_curr_count=&attr_mapping_way_count;733 735 } else { 734 736 if (! i) 735 737 i="point_unkn"; 736 attr_mapping_curr=&attr_mapping_node;737 attr_mapping_curr_count=&attr_mapping_node_count;738 738 } 739 739 attr_mapping->type=item_from_name(i); 740 740 while ((kv=strtok(kvl, ","))) { … … 747 747 attr_mapping->attr_present_idx[attr_mapping_count++]=idx; 748 748 attr_mapping->attr_present_idx_count=attr_mapping_count; 749 749 } 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 752 759 } 753 760 754 761 static void … … 1283 1290 if (interval > 1) 1284 1291 interval/=2; 1285 1292 } 1286 1287 1293 return &ni[p]; 1288 1294 } 1289 1295 … … 1509 1515 } 1510 1516 1511 1517 void 1512 osm_end_way(FILE *out )1518 osm_end_way(FILE *out, FILE *outwaypoi) 1513 1519 { 1514 1520 int i,count; 1515 1521 int *def_flags,add_flags; … … 1542 1548 continue; 1543 1549 if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) 1544 1550 continue; 1551 if(!outwaypoi && types[i]<type_line) 1552 continue; 1545 1553 item_bin=init_item(types[i]); 1546 1554 item_bin_add_coord(item_bin, coord_buffer, coord_count); 1547 1555 def_flags=item_get_default_flags(types[i]); … … 1551 1559 add_flags=1; 1552 1560 } 1553 1561 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 } 1555 1565 item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); 1556 1566 if (debug_attr_buffer[0]) 1557 1567 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 } 1563 1587 } 1564 1588 } 1565 1589 … … 1979 2003 fclose(in); 1980 2004 } 1981 2005 1982 st atic void1983 node_ref_way(osmid node )2006 struct node_item * 2007 node_ref_way(osmid node, int countreferences) 1984 2008 { 1985 2009 struct node_item *ni; 1986 2010 ni=node_item_get(node); 1987 if (ni )2011 if (ni && countreferences) 1988 2012 ni->ref_way++; 2013 return ni; 1989 2014 } 1990 2015 1991 int1992 resolve_ways(FILE *in, FILE *out)1993 {1994 struct item_bin *ib;1995 struct coord *c;1996 int i;1997 2016 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 2008 2017 void 2009 2018 osm_add_nd(osmid ref) 2010 2019 { 2011 2020 SET_REF(coord_buffer[coord_count], ref); 2012 node_ref_way(ref );2021 node_ref_way(ref,1); 2013 2022 coord_count++; 2014 2023 if (coord_count > 65536) { 2015 2024 fprintf(stderr,"ERROR: Overflow\n"); … … 2057 2066 } 2058 2067 2059 2068 int 2069 resolve_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 2114 int 2060 2115 map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final) 2061 2116 { 2062 2117 struct coord *c; -
navit/maptool/maptool.c
112 112 fprintf(f,"bzcat planet.osm.bz2 | maptool mymap.bin\n"); 113 113 fprintf(f,"Available switches:\n"); 114 114 fprintf(f,"-h (--help) : this screen\n"); 115 fprintf(f,"-2 (--doway2poi) : convert ways and polygons to POIs when applicable\n"); 115 116 fprintf(f,"-5 (--md5) : set file where to write md5 sum\n"); 116 117 fprintf(f,"-6 (--64bit) : set zip 64 bit compression\n"); 117 118 fprintf(f,"-a (--attr-debug-level) : control which data is included in the debug attribute\n"); … … 122 123 fprintf(f,"-e (--end) : end at specified phase\n"); 123 124 fprintf(f,"-i (--input-file) : specify the input file name (OSM), overrules default stdin\n"); 124 125 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"); 126 127 fprintf(f,"-N (--nodes-only) : process only nodes\n"); 127 128 fprintf(f,"-o (--coverage) : map every street to item coverage\n"); 128 129 fprintf(f,"-P (--protobuf) : input file is protobuf\n"); … … 139 140 140 141 int main(int argc, char **argv) 141 142 { 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; 143 144 FILE *files[10]; 144 145 FILE *references[10]; 145 146 … … 159 160 int input=0; 160 161 int protobuf=0; 161 162 int o5m=0; 163 int doway2poi=0; 162 164 int f,pos; 163 165 char *result,*optarg_cp,*attr_name,*attr_value; 164 166 char *protobufdb=NULL,*protobufdb_operation=NULL,*md5file=NULL; … … 199 201 #endif 200 202 int option_index = 0; 201 203 static struct option long_options[] = { 204 {"doway2poi", 0, 0, '2'}, 202 205 {"md5", 1, 0, '5'}, 203 206 {"64bit", 0, 0, '6'}, 204 207 {"attr-debug-level", 1, 0, 'a'}, … … 228 231 {"unknown-country", 0, 0, 'U'}, 229 232 {0, 0, 0, 0} 230 233 }; 231 c = getopt_long (argc, argv, " 5:6B:DMNO:PWS:a:bc"234 c = getopt_long (argc, argv, "25:6B:DMNO:PWS:a:bc" 232 235 #ifdef HAVE_POSTGRESQL 233 236 "d:" 234 237 #endif … … 236 239 if (c == -1) 237 240 break; 238 241 switch (c) { 242 case '2': 243 doway2poi=1; 244 break; 239 245 case '5': 240 246 md5file=optarg; 241 247 break; … … 386 392 ways=tempfile(suffix,"ways",1); 387 393 if (process_nodes) 388 394 nodes=tempfile(suffix,"nodes",1); 389 if (process_ways && process_nodes) 395 if (process_ways && process_nodes) { 390 396 turn_restrictions=tempfile(suffix,"turn_restrictions",1); 397 if(doway2poi) 398 way2poi=tempfile(suffix,"way2poi",1); 399 } 391 400 if (process_relations) 392 401 boundaries=tempfile(suffix,"boundaries",1); 393 402 phase=1; 394 403 fprintf(stderr,"PROGRESS: Phase 1: collecting data\n"); 395 404 #ifdef HAVE_POSTGRESQL 396 405 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); 398 407 else 399 408 #endif 400 409 if (map_handles) { … … 407 416 } 408 417 } 409 418 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); 411 420 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); 413 422 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); 415 424 if (slices) { 416 425 fprintf(stderr,"%d slices\n",slices); 417 426 flush_nodes(1); 418 427 for (i = slices-2 ; i>=0 ; i--) { 419 428 fprintf(stderr, "slice %d of %d\n",slices-i-1,slices-1); 420 429 load_buffer("coords.tmp",&node_buffer, i*slice_size, slice_size); 421 resolve_ways(ways, NULL );430 resolve_ways(ways, NULL, 1); 422 431 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 } 423 440 } 424 } else 441 } else { 425 442 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 } 426 452 if (ways) 427 453 fclose(ways); 454 if (way2poi) { 455 fclose(way2poi); 456 way2poi=tempfile(suffix,"way2poi",0); 457 process_binfile(way2poi, nodes); 458 fclose(way2poi); 459 } 428 460 if (nodes) 429 461 fclose(nodes); 430 462 if (turn_restrictions) … … 578 610 files[1]=tempfile(suffix,"ways_split",0); 579 611 if (process_nodes) 580 612 files[2]=tempfile(suffix,"nodes",0); 613 581 614 phase4(files,3,0,suffix,tilesdir,zip_info); 582 615 for (f = 0 ; f < 3 ; f++) { 583 616 if (files[f]) … … 628 661 } 629 662 if (process_nodes) 630 663 files[2]=tempfile(suffix,"nodes",0); 664 631 665 fprintf(stderr,"Slice %d\n",i); 632 666 633 667 phase5(files,references,3,0,suffix,zip_info); … … 642 676 tempfile_unlink(suffix,"relations"); 643 677 tempfile_unlink(suffix,"nodes"); 644 678 tempfile_unlink(suffix,"ways_split"); 679 tempfile_unlink(suffix,"way2poi"); 645 680 tempfile_unlink(suffix,"ways_split_ref"); 646 681 tempfile_unlink(suffix,"coastline"); 647 682 tempfile_unlink(suffix,"turn_restrictions"); -
navit/maptool/osm_o5m.c
170 170 } 171 171 172 172 int 173 map_collect_data_osm_o5m(FILE *in, FILE *out_ways, FILE *out_ nodes, FILE *out_turn_restrictions, FILE *out_boundaries)173 map_collect_data_osm_o5m(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 174 174 { 175 175 struct o5m o; 176 176 unsigned char c, *end, *rend; … … 304 304 osm_end_node(out_nodes); 305 305 break; 306 306 case 0x11: 307 osm_end_way(out_ways );307 osm_end_way(out_ways, out_way2poi); 308 308 break; 309 309 case 0x12: 310 310 osm_end_relation(out_turn_restrictions, out_boundaries); -
navit/maptool/osm_xml.c
178 178 } 179 179 180 180 int 181 map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_ nodes, FILE *out_turn_restrictions, FILE *out_boundaries)181 map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 182 182 { 183 183 int size=BUFFER_SIZE; 184 184 char buffer[size]; … … 217 217 } else if (!strncmp(p, "</node>",7)) { 218 218 osm_end_node(out_nodes); 219 219 } else if (!strncmp(p, "</way>",6)) { 220 osm_end_way(out_ways );220 osm_end_way(out_ways, out_way2poi); 221 221 } else if (!strncmp(p, "</relation>",11)) { 222 222 osm_end_relation(out_turn_restrictions, out_boundaries); 223 223 } else if (!strncmp(p, "</osm>",6)) { -
navit/maptool/osm_protobuf.c
241 241 #endif 242 242 243 243 static void 244 process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, FILE *out_ways )244 process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, FILE *out_ways, FILE *out_way2poi) 245 245 { 246 246 int i; 247 247 long long ref=0; … … 266 266 #if 0 267 267 printf("\t</way>\n"); 268 268 #endif 269 osm_end_way(out_ways );269 osm_end_way(out_ways, out_way2poi); 270 270 } 271 271 272 272 static void … … 318 318 } 319 319 320 320 static void 321 process_osmdata(OSMPBF__Blob *blob, unsigned char *data, FILE *out_nodes, FILE *out_ways, FILE *out_ turn_restrictions, FILE *out_boundaries)321 process_osmdata(OSMPBF__Blob *blob, unsigned char *data, FILE *out_nodes, FILE *out_ways, FILE *out_way2poi, FILE *out_turn_restrictions, FILE *out_boundaries) 322 322 { 323 323 int i,j; 324 324 OSMPBF__PrimitiveBlock *primitive_block; … … 327 327 OSMPBF__PrimitiveGroup *primitive_group=primitive_block->primitivegroup[i]; 328 328 process_dense(primitive_block, primitive_group->dense, out_nodes); 329 329 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); 331 331 for (j = 0 ; j < primitive_group->n_relations ; j++) 332 332 process_relation(primitive_block, primitive_group->relations[j], out_turn_restrictions, out_boundaries); 333 333 #if 0 … … 339 339 340 340 341 341 int 342 map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_ nodes, FILE *out_turn_restrictions, FILE *out_boundaries)342 map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 343 343 { 344 344 OSMPBF__BlobHeader *header; 345 345 OSMPBF__Blob *blob; … … 354 354 if (!strcmp(header->type,"OSMHeader")) { 355 355 process_osmheader(blob, data); 356 356 } 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); 358 358 } else { 359 359 printf("unknown\n"); 360 360 return 0; -
navit/maptool/maptool.h
144 144 void geom_coord_copy(struct coord *from, struct coord *to, int count, int reverse); 145 145 void geom_coord_revert(struct coord *c, int count); 146 146 long long geom_poly_area(struct coord *c, int count); 147 int geom_poly_centroid(struct coord *c, int count, struct coord *r); 148 int geom_poly_closest_point(struct coord *pl, int count, struct coord *p, struct coord *c); 147 149 GList *geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third); 148 150 void geom_poly_segment_destroy(struct geom_poly_segment *seg); 149 151 GList *geom_poly_segments_remove(GList *list, struct geom_poly_segment *seg); … … 235 237 void osm_add_relation(osmid id); 236 238 void osm_end_relation(FILE *turn_restrictions, FILE *boundaries); 237 239 void osm_add_member(int type, osmid ref, char *role); 238 void osm_end_way(FILE *out );240 void osm_end_way(FILE *out, FILE *outwaypoi); 239 241 void osm_end_node(FILE *out); 240 242 void osm_add_nd(osmid ref); 241 243 long long item_bin_get_id(struct item_bin *ib); 242 244 void flush_nodes(int final); 243 245 void sort_countries(int keep_tmpfiles); 244 246 void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out); 245 int resolve_ways(FILE *in, FILE *out );247 int resolve_ways(FILE *in, FILE *out, int countreferences); 246 248 int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final); 247 249 void write_countrydir(struct zip_info *zip_info); 248 250 void remove_countryfiles(void); 249 251 void osm_init(FILE*); 250 252 251 253 /* 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);254 int map_collect_data_osm_o5m(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 253 255 254 256 /* 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);257 int map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 256 258 257 259 /* 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);260 int map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 259 261 int osm_protobufdb_load(FILE *in, char *dir); 260 262 261 263 /* osm_xml.c */ 262 264 int osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size); 263 265 void 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);266 int map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); 265 267 266 268 267 269 /* sourcesink.c */ -
navit/maptool/geom.c
60 60 #if 0 61 61 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)); 62 62 #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); 64 64 #if 0 65 65 fprintf(stderr,"area="LONGLONG_FMT"\n",area); 66 66 #endif … … 68 68 return area/2; 69 69 } 70 70 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 */ 78 int 79 geom_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 */ 115 int 116 geom_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 71 152 GList * 72 153 geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third) 73 154 { -
navit/maptool/osm_psql.c
28 28 #include <libpq-fe.h> 29 29 30 30 int 31 map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_ nodes, FILE *out_turn_restrictions, FILE *out_boundaries)31 map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) 32 32 { 33 33 PGconn *conn; 34 34 PGresult *res,*node,*way,*tag; … … 169 169 break; 170 170 } 171 171 if (tagged) 172 osm_end_way(out_ways );172 osm_end_way(out_ways, out_way2poi); 173 173 } 174 174 PQclear(tag); 175 175 PQclear(node);
