1 | /** |
1 | /** |
2 | * ZANavi, Zoff Android Navigation system. |
2 | * ZANavi, Zoff Android Navigation system. |
3 | * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc> |
3 | * Copyright (C) 2011-2013 Zoff <zoff@zoff.cc> |
4 | * |
4 | * |
5 | * This program is free software; you can redistribute it and/or |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License |
6 | * modify it under the terms of the GNU General Public License |
7 | * version 2 as published by the Free Software Foundation. |
7 | * version 2 as published by the Free Software Foundation. |
8 | * |
8 | * |
… | |
… | |
143 | |
143 | |
144 | #define _FILE_OFFSET_BITS 64 |
144 | #define _FILE_OFFSET_BITS 64 |
145 | #define _LARGEFILE_SOURCE |
145 | #define _LARGEFILE_SOURCE |
146 | #define _LARGEFILE64_SOURCE |
146 | #define _LARGEFILE64_SOURCE |
147 | |
147 | |
|
|
148 | |
|
|
149 | |
|
|
150 | |
|
|
151 | #include "osm_countrytable.h" |
|
|
152 | |
|
|
153 | |
|
|
154 | // function def -- |
|
|
155 | static long long osm_process_street_by_manual_country_borders(GList *bl_manual, struct coord *c); |
|
|
156 | static int osm_check_all_inner_polys_of_country_id(int country_id, struct coord *c); |
|
|
157 | // function def -- |
|
|
158 | |
|
|
159 | |
148 | extern int doway2poi; |
160 | extern int doway2poi; |
149 | |
161 | |
150 | static int in_way, in_node, in_relation; |
162 | static int in_way, in_node, in_relation; |
151 | static osmid nodeid, wayid; |
163 | static osmid nodeid, wayid; |
152 | osmid current_id; |
164 | osmid current_id; |
… | |
… | |
175 | char is_in_buffer[BUFFER_SIZE]; |
187 | char is_in_buffer[BUFFER_SIZE]; |
176 | |
188 | |
177 | char attr_strings_buffer[BUFFER_SIZE * 16]; |
189 | char attr_strings_buffer[BUFFER_SIZE * 16]; |
178 | int attr_strings_buffer_len; |
190 | int attr_strings_buffer_len; |
179 | int alt_name_found = 0; |
191 | int alt_name_found = 0; |
|
|
192 | int real_alt_name_found = 0; |
180 | |
193 | |
181 | struct coord coord_buffer[65536]; |
194 | struct coord coord_buffer[65536]; |
|
|
195 | struct coord coord_buffer_3[65536]; |
182 | |
196 | |
183 | struct attr_mapping |
197 | struct attr_mapping |
184 | { |
198 | { |
185 | enum item_type type; |
199 | enum item_type type; |
186 | int attr_present_idx_count; |
200 | int attr_present_idx_count; |
… | |
… | |
201 | |
215 | |
202 | static long long seekpos1; |
216 | static long long seekpos1; |
203 | |
217 | |
204 | enum attr_strings |
218 | enum attr_strings |
205 | { |
219 | { |
206 | attr_string_phone, attr_string_fax, attr_string_email, attr_string_url, attr_string_street_name, attr_string_street_name_systematic, attr_string_house_number, attr_string_label, attr_string_label_alt, attr_string_postal, attr_string_population, attr_string_county_name, attr_string_colour_, attr_string_last, |
220 | attr_string_phone, attr_string_fax, attr_string_email, attr_string_url, attr_string_street_name, attr_string_street_name_systematic, attr_string_house_number, attr_string_label, attr_string_label_alt, attr_string_label_real_alt, attr_string_postal, |
|
|
221 | attr_string_population, attr_string_county_name, attr_string_colour_, attr_string_capacity, |
|
|
222 | attr_string_street_name_systematic_nat, |
|
|
223 | attr_string_street_name_systematic_int, |
|
|
224 | attr_string_ref, |
|
|
225 | attr_string_exit_to, |
|
|
226 | attr_string_street_destination, |
|
|
227 | attr_string_street_lanes, |
|
|
228 | // ---------- |
|
|
229 | attr_string_street_lanes_forward, |
|
|
230 | attr_string_street_turn_lanes, |
|
|
231 | attr_string_street_destination_lanes, |
|
|
232 | // ----- last ---- |
|
|
233 | attr_string_last, |
207 | }; |
234 | }; |
208 | |
235 | |
209 | char *attr_strings[attr_string_last]; |
236 | char *attr_strings[attr_string_last]; |
210 | |
237 | |
211 | char *osm_types[] = { "unknown", "node", "way", "relation" }; |
238 | char *osm_types[] = { "unknown", "node", "way", "relation" }; |
212 | |
239 | |
213 | int transform_from_geo_lat(double lat); |
240 | double save_node_lat; |
214 | int transform_from_geo_lon(double lon); |
241 | double save_node_lon; |
215 | |
242 | |
216 | // #define REF_X 1073741834 --> maptool.h // lat |
243 | // #define REF_X 1073741834 --> maptool.h // lat |
217 | // #define REF_Y 240000000 --> maptool.h // lon |
244 | // #define REF_Y 240000000 --> maptool.h // lon |
218 | #define IS_REF(c) (check_decode_nodeid(c)) // --> new method |
245 | #define IS_REF(c) (check_decode_nodeid(c)) // --> new method |
219 | // #define IS_REF(c) ((c).x >= (1 << 30)) // --> old method again |
246 | // #define IS_REF(c) ((c).x >= (1 << 30)) // --> old method again |
… | |
… | |
299 | |
326 | |
300 | return ret; |
327 | return ret; |
301 | } |
328 | } |
302 | |
329 | |
303 | |
330 | |
304 | |
|
|
305 | |
|
|
306 | struct country_table |
|
|
307 | { |
|
|
308 | int countryid; |
|
|
309 | char *names; |
|
|
310 | char *admin_levels; |
|
|
311 | FILE *file; |
|
|
312 | int size; |
|
|
313 | struct rect r; |
|
|
314 | } |
|
|
315 | country_table[] = |
|
|
316 | { { 4, "Afghanistan" }, { 8, "Albania" }, { 10, "Antarctica" }, { 12, "Algeria" }, { 16, "American Samoa" }, { 20, "Andorra" }, { 24, "Angola" }, { 28, "Antigua and Barbuda" }, { 31, "Azerbaijan" }, { 32, "Argentina,República Argentina,AR " }, { 36, "Australia,AUS" }, { 40, "Austria,Österreich,AUT" }, { 44, "Bahamas" }, { 48, "Bahrain" }, { 50, "Bangladesh" }, { 51, "Armenia" }, { 52, "Barbados" }, { 56, "Belgium,Belgique,Belgie,België,Belgien" }, { 60, "Bermuda" }, { 64, "Bhutan" }, { 68, "Bolivia, Plurinational State of" }, { 70, "Bosnia and Herzegovina,Bosna i Hercegovina,Босна и Херцеговина" }, { 72, "Botswana" }, { 74, "Bouvet Island" }, { 76, "Brazil" }, { 84, "Belize" }, { 86, "British Indian Ocean Territory" }, { 90, "Solomon Islands" }, { 92, "Virgin Islands, British" }, { 96, "Brunei Darussalam" }, { 100, "Bulgaria,България" }, { 104, "Myanmar" }, { 108, "Burundi" }, { 112, "Belarus" }, { 116, "Cambodia" }, { 120, "Cameroon" }, { 124, "Canada" }, { 132, "Cape Verde" }, { 136, "Cayman Islands" }, { 140, "Central African Republic" }, { 144, "Sri Lanka" }, { 148, "Chad" }, { 152, "Chile" }, { 156, "China" }, { 158, "Taiwan, Province of China" }, { 162, "Christmas Island" }, { 166, "Cocos (Keeling) Islands" }, { 170, "Colombia" }, { 174, "Comoros" }, { 175, "Mayotte" }, { 178, "Congo" }, { 180, "Congo, the Democratic Republic of the" }, { 184, "Cook Islands" }, { 188, "Costa Rica" }, { 191, "Croatia,Republika Hrvatska,HR" }, { 192, "Cuba" }, { 196, "Cyprus" }, { 203, "Czech Republic,Česká republika,CZ" }, { 204, "Benin" }, { 208, "Denmark,Danmark,DK" }, { 212, "Dominica" }, { 214, "Dominican Republic" }, { 218, "Ecuador" }, { 222, "El Salvador" }, { 226, "Equatorial Guinea" }, { 231, "Ethiopia" }, { 232, "Eritrea" }, { 233, "Estonia" }, { 234, "Faroe Islands,Føroyar" }, { 238, "Falkland Islands (Malvinas)" }, { 239, "South Georgia and the South Sandwich Islands" }, { 242, "Fiji" }, { 246, "Finland,Suomi" }, { 248, "Åland Islands" }, { 250, "France,République française,FR" }, { 254, "French Guiana" }, { 258, "French Polynesia" }, { 260, "French Southern Territories" }, { 262, "Djibouti" }, { 266, "Gabon" }, { 268, "Georgia" }, { 270, "Gambia" }, { 275, "Palestinian Territory, Occupied" }, { 276, "Germany,Deutschland,Bundesrepublik Deutschland", "345c7m" }, { 288, "Ghana" }, { 292, "Gibraltar" }, { 296, "Kiribati" }, { 300, "Greece" }, { 304, "Greenland" }, { 308, "Grenada" }, { 312, "Guadeloupe" }, { 316, "Guam" }, { 320, "Guatemala" }, { 324, "Guinea" }, { 328, "Guyana" }, { 332, "Haiti" }, { 334, "Heard Island and McDonald Islands" }, { 336, "Holy See (Vatican City State)" }, { 340, "Honduras" }, { 344, "Hong Kong" }, { 348, "Hungary,Magyarország" }, { 352, "Iceland" }, { 356, "India" }, { 360, "Indonesia" }, { 364, "Iran, Islamic Republic of" }, { 368, "Iraq" }, { 372, "Ireland" }, { 376, "Israel" }, { 380, "Italy,Italia" }, { 384, "Côte d'Ivoire" }, { 388, "Jamaica" }, { 392, "Japan" }, { 398, "Kazakhstan" }, { 400, "Jordan" }, { 404, "Kenya" }, { 408, "Korea, Democratic People's Republic of" }, { 410, "Korea, Republic of" }, { 414, "Kuwait" }, { 417, "Kyrgyzstan" }, { 418, "Lao People's Democratic Republic" }, { 422, "Lebanon" }, { 426, "Lesotho" }, { 428, "Latvia" }, { 430, "Liberia" }, { 434, "Libyan Arab Jamahiriya" }, { 438, "Liechtenstein" }, { 440, "Lithuania,Lietuva" }, { 442, "Luxembourg" }, { 446, "Macao" }, { 450, "Madagascar" }, { 454, "Malawi" }, { 458, "Malaysia" }, { 462, "Maldives" }, { 466, "Mali" }, { 470, "Malta" }, { 474, "Martinique" }, { 478, "Mauritania" }, { 480, "Mauritius" }, { 484, "Mexico" }, { 492, "Monaco" }, { 496, "Mongolia" }, { 498, "Moldova, Republic of" }, { 499, "Montenegro,Црна Гора,Crna Gora" }, { 500, "Montserrat" }, { 504, "Morocco" }, { 508, "Mozambique" }, { 512, "Oman" }, { 516, "Namibia" }, { 520, "Nauru" }, { 524, "Nepal" }, { 528, "Nederland,The Netherlands,Niederlande,NL,Netherlands" }, { 530, "Netherlands Antilles" }, { 533, "Aruba" }, { 540, "New Caledonia" }, { 548, "Vanuatu" }, { 554, "New Zealand" }, { 558, "Nicaragua" }, { 562, "Niger" }, { 566, "Nigeria" }, { 570, "Niue" }, { 574, "Norfolk Island" }, { 578, "Norway,Norge,Noreg,NO" }, { 580, "Northern Mariana Islands" }, { 581, "United States Minor Outlying Islands" }, { 583, "Micronesia, Federated States of" }, { 584, "Marshall Islands" }, { 585, "Palau" }, { 586, "Pakistan" }, { 591, "Panama" }, { 598, "Papua New Guinea" }, { 600, "Paraguay" }, { 604, "Peru" }, { 608, "Philippines" }, { 612, "Pitcairn" }, { 616, "Poland,Polska,PL" }, { 620, "Portugal" }, { 624, "Guinea-Bissau" }, { 626, "Timor-Leste" }, { 630, "Puerto Rico" }, { 634, "Qatar" }, { 638, "Réunion" }, { 642, "România,Romania,RO" }, { 643, "Россия,Российская Федерация,Russia,Russian Federation" }, { 646, "Rwanda" }, { 652, "Saint Barthélemy" }, { 654, "Saint Helena, Ascension and Tristan da Cunha" }, { 659, "Saint Kitts and Nevis" }, { 660, "Anguilla" }, { 662, "Saint Lucia" }, { 663, "Saint Martin (French part)" }, { 666, "Saint Pierre and Miquelon" }, { 670, "Saint Vincent and the Grenadines" }, { 674, "San Marino" }, { 678, "Sao Tome and Principe" }, { 682, "Saudi Arabia" }, { 686, "Senegal" }, { 688, "Srbija,Србија,Serbia" }, { 690, "Seychelles" }, { 694, "Sierra Leone" }, { 702, "Singapore" }, { 703, "Slovakia,Slovensko,SK" }, { 704, "Viet Nam" }, { 705, "Slovenia,Republika Slovenija,SI" }, { 706, "Somalia" }, { 710, "South Africa" }, { 716, "Zimbabwe" }, { 724, "Spain,Espana,España,Reino de Espana,Reino de España" }, { 732, "Western Sahara" }, { 736, "Sudan" }, { 740, "Suriname" }, { 744, "Svalbard and Jan Mayen" }, { 748, "Swaziland" }, { 752, "Sweden,Sverige,Konungariket Sverige,SE" }, { 756, "Switzerland,Schweiz" }, { 760, "Syrian Arab Republic" }, { 762, "Tajikistan" }, { 764, "Thailand" }, { 768, "Togo" }, { 772, "Tokelau" }, { 776, "Tonga" }, { 780, "Trinidad and Tobago" }, { 784, "United Arab Emirates" }, { 788, "Tunisia" }, { 792, "Turkey" }, { 795, "Turkmenistan" }, { 796, "Turks and Caicos Islands" }, { 798, "Tuvalu" }, { 800, "Uganda" }, { 804, "Ukraine" }, { 807, "Macedonia,Македонија" }, { 818, "Egypt" }, { 826, "United Kingdom,UK" }, { 831, "Guernsey" }, { 832, "Jersey" }, { 833, "Isle of Man" }, { 834, "Tanzania, United Republic of" }, { 840, "USA" }, { 850, "Virgin Islands, U.S." }, { 854, "Burkina Faso" }, { 858, "Uruguay" }, { 860, "Uzbekistan" }, { 862, "Venezuela, Bolivarian Republic of" }, { 876, "Wallis and Futuna" }, { 882, "Samoa" }, { 887, "Yemen" }, { 894, "Zambia" }, { 999, "Unknown" }, }; |
|
|
317 | |
331 | |
318 | // first char - item type |
332 | // first char - item type |
319 | // =w - ways |
333 | // =w - ways |
320 | // =? - used both for nodes and ways |
334 | // =? - used both for nodes and ways |
321 | // otherwise - nodes |
335 | // otherwise - nodes |
… | |
… | |
376 | "n amenity=kindergarten poi_kindergarten\n" |
390 | "n amenity=kindergarten poi_kindergarten\n" |
377 | "n amenity=library poi_library\n" |
391 | "n amenity=library poi_library\n" |
378 | "n amenity=nightclub poi_nightclub\n" |
392 | "n amenity=nightclub poi_nightclub\n" |
379 | //"n amenity=park_bench poi_bench\n" |
393 | //"n amenity=park_bench poi_bench\n" |
380 | "n amenity=parking poi_car_parking\n" |
394 | "n amenity=parking poi_car_parking\n" |
|
|
395 | "n amenity=bicycle_parking poi_bicycle_parking\n" |
|
|
396 | "n amenity=bicycle_rental poi_bicycle_rental\n" |
381 | "n amenity=pharmacy poi_pharmacy\n" |
397 | "n amenity=pharmacy poi_pharmacy\n" |
382 | "n amenity=place_of_worship,religion=christian poi_church\n" |
398 | "n amenity=place_of_worship,religion=christian poi_church\n" |
383 | "n amenity=place_of_worship poi_worship\n" |
399 | "n amenity=place_of_worship poi_worship\n" |
384 | "n amenity=police poi_police\n" |
400 | "n amenity=police poi_police\n" |
385 | //"n amenity=post_box poi_post_box\n" |
401 | //"n amenity=post_box poi_post_box\n" |
… | |
… | |
408 | "n highway=bus_stop poi_bus_stop\n" |
424 | "n highway=bus_stop poi_bus_stop\n" |
409 | "n highway=mini_roundabout mini_roundabout\n" |
425 | "n highway=mini_roundabout mini_roundabout\n" |
410 | "n highway=motorway_junction highway_exit\n" |
426 | "n highway=motorway_junction highway_exit\n" |
411 | "n highway=stop traffic_sign_stop\n" |
427 | "n highway=stop traffic_sign_stop\n" |
412 | "n highway=toll_booth poi_toll_booth\n" |
428 | "n highway=toll_booth poi_toll_booth\n" |
|
|
429 | "n highway=crossing,crossing=traffic_signals traffic_crossing_signal\n" |
|
|
430 | "n highway=crossing,crossing=uncontrolled traffic_crossing_uncontrolled\n" |
|
|
431 | "n highway=crossing traffic_crossing_uncontrolled\n" |
413 | "n highway=traffic_signals traffic_signals\n" |
432 | "n highway=traffic_signals traffic_signals\n" |
414 | "n highway=turning_circle turning_circle\n" |
433 | "n highway=turning_circle turning_circle\n" |
415 | //"n historic=boundary_stone poi_boundary_stone\n" |
434 | //"n historic=boundary_stone poi_boundary_stone\n" |
416 | "n historic=castle poi_castle\n" |
435 | "n historic=castle poi_castle\n" |
417 | "n historic=memorial poi_memorial\n" |
436 | "n historic=memorial poi_memorial\n" |
… | |
… | |
434 | "n military=range poi_military\n" |
453 | "n military=range poi_military\n" |
435 | "n natural=bay poi_bay\n" |
454 | "n natural=bay poi_bay\n" |
436 | "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation |
455 | "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation |
437 | //"n natural=tree poi_tree\n" |
456 | //"n natural=tree poi_tree\n" |
438 | "n place=city town_label_2e5\n" |
457 | "n place=city town_label_2e5\n" |
|
|
458 | "n place=town town_label_2e4\n" |
|
|
459 | "n place=village town_label_2e3\n" |
439 | "n place=hamlet town_label_2e2\n" |
460 | "n place=hamlet town_label_2e2\n" |
440 | "n place=locality town_label_2e0\n" |
461 | "n place=locality town_label_2e0\n" |
441 | "n place=suburb district_label\n" |
462 | "n place=suburb district_label\n" |
442 | "n place=town town_label_2e4\n" |
463 | "n place=quarter district_label_1e2\n" |
443 | "n place=village town_label_2e3\n" |
464 | "n place=neighbourhood district_label_1e1\n" |
444 | //"n power=tower power_tower\n" |
465 | //"n power=tower power_tower\n" |
445 | //"n power=sub_station power_substation\n" |
466 | //"n power=sub_station power_substation\n" |
446 | "n railway=halt poi_rail_halt\n" |
467 | "n railway=halt poi_rail_halt\n" |
447 | "n railway=level_crossing poi_level_crossing\n" |
468 | "n railway=level_crossing poi_level_crossing\n" |
448 | "n railway=station poi_rail_station\n" |
469 | "n railway=station poi_rail_station\n" |
… | |
… | |
547 | "w highway=pedestrian street_pedestrian\n" |
568 | "w highway=pedestrian street_pedestrian\n" |
548 | "w highway=pedestrian,area=1 poly_pedestrian\n" |
569 | "w highway=pedestrian,area=1 poly_pedestrian\n" |
549 | "w highway=plaza poly_plaza\n" |
570 | "w highway=plaza poly_plaza\n" |
550 | "w highway=motorway highway_land\n" |
571 | "w highway=motorway highway_land\n" |
551 | "w highway=motorway,rural=0 highway_city\n" |
572 | "w highway=motorway,rural=0 highway_city\n" |
552 | "w highway=motorway_link ramp\n" |
573 | "w highway=motorway_link ramp_highway_land\n" |
553 | "w highway=trunk street_4_land\n" |
574 | "w highway=trunk street_n_lanes\n" |
554 | "w highway=trunk,name=*,rural=1 street_4_land\n" |
575 | "w highway=trunk,name=*,rural=1 street_4_land\n" |
555 | "w highway=trunk,name=* street_4_city\n" |
576 | "w highway=trunk,name=* street_n_lanes\n" |
556 | "w highway=trunk,rural=0 street_4_city\n" |
577 | "w highway=trunk,rural=0 street_n_lanes\n" |
557 | "w highway=trunk_link ramp\n" |
578 | "w highway=trunk_link ramp_street_4_city\n" |
558 | "w highway=primary street_4_land\n" |
579 | "w highway=primary street_4_land\n" |
559 | "w highway=primary,name=*,rural=1 street_4_land\n" |
580 | "w highway=primary,name=*,rural=1 street_4_land\n" |
560 | "w highway=primary,name=* street_4_city\n" |
581 | "w highway=primary,name=* street_4_city\n" |
561 | "w highway=primary,rural=0 street_4_city\n" |
582 | "w highway=primary,rural=0 street_4_city\n" |
562 | "w highway=primary_link ramp\n" |
583 | "w highway=primary_link ramp_street_4_city\n" |
563 | "w highway=secondary street_3_land\n" |
584 | "w highway=secondary street_3_land\n" |
564 | "w highway=secondary,name=*,rural=1 street_3_land\n" |
585 | "w highway=secondary,name=*,rural=1 street_3_land\n" |
565 | "w highway=secondary,name=* street_3_city\n" |
586 | "w highway=secondary,name=* street_3_city\n" |
566 | "w highway=secondary,rural=0 street_3_city\n" |
587 | "w highway=secondary,rural=0 street_3_city\n" |
567 | "w highway=secondary,area=1 poly_street_3\n" |
588 | "w highway=secondary,area=1 poly_street_3\n" |
568 | "w highway=secondary_link ramp\n" |
589 | "w highway=secondary_link ramp_street_3_city\n" |
569 | "w highway=tertiary street_2_land\n" |
590 | "w highway=tertiary street_2_land\n" |
570 | "w highway=tertiary,name=*,rural=1 street_2_land\n" |
591 | "w highway=tertiary,name=*,rural=1 street_2_land\n" |
571 | "w highway=tertiary,name=* street_2_city\n" |
592 | "w highway=tertiary,name=* street_2_city\n" |
572 | "w highway=tertiary,rural=0 street_2_city\n" |
593 | "w highway=tertiary,rural=0 street_2_city\n" |
573 | "w highway=tertiary,area=1 poly_street_2\n" |
594 | "w highway=tertiary,area=1 poly_street_2\n" |
574 | "w highway=tertiary_link ramp\n" |
595 | "w highway=tertiary_link ramp_street_2_city\n" |
575 | "w highway=residential street_1_city\n" |
596 | "w highway=residential street_1_city\n" |
576 | "w highway=residential,area=1 poly_street_1\n" |
597 | "w highway=residential,area=1 poly_street_1\n" |
577 | "w highway=unclassified street_1_city\n" |
598 | "w highway=unclassified street_1_city\n" |
578 | "w highway=unclassified,area=1 poly_street_1\n" |
599 | "w highway=unclassified,area=1 poly_street_1\n" |
579 | "w highway=road street_1_city\n" |
600 | "w highway=road street_1_city\n" |
… | |
… | |
807 | while (map) |
828 | while (map) |
808 | { |
829 | { |
809 | p = strchr(map, '\n'); |
830 | p = strchr(map, '\n'); |
810 | if (p) |
831 | if (p) |
811 | *p++ = '\0'; |
832 | *p++ = '\0'; |
|
|
833 | |
812 | if (strlen(map)) |
834 | if (strlen(map)) |
813 | build_attrmap_line(map); |
835 | build_attrmap_line(map); |
|
|
836 | |
814 | map = p; |
837 | map = p; |
815 | } |
838 | } |
816 | } |
839 | } |
817 | |
840 | |
818 | attr_present = g_malloc0(sizeof(*attr_present) * attr_present_count); |
841 | attr_present = g_malloc0(sizeof(*attr_present) * attr_present_count); |
… | |
… | |
832 | str = NULL; |
855 | str = NULL; |
833 | g_hash_table_insert(country_table_hash, tok, (gpointer) & country_table[i]); |
856 | g_hash_table_insert(country_table_hash, tok, (gpointer) & country_table[i]); |
834 | } |
857 | } |
835 | } |
858 | } |
836 | } |
859 | } |
|
|
860 | |
|
|
861 | int string_endswith2(const char* ending, const char* instring) |
|
|
862 | { |
|
|
863 | int l1; |
|
|
864 | int l2; |
|
|
865 | |
|
|
866 | if (!ending) |
|
|
867 | { |
|
|
868 | return 0; |
|
|
869 | } |
|
|
870 | |
|
|
871 | if (!instring) |
|
|
872 | { |
|
|
873 | return 0; |
|
|
874 | } |
|
|
875 | |
|
|
876 | l1 = strlen(ending); |
|
|
877 | l2 = strlen(instring); |
|
|
878 | |
|
|
879 | if (l1 < 1) |
|
|
880 | { |
|
|
881 | return 0; |
|
|
882 | } |
|
|
883 | |
|
|
884 | if (l1 > l2) |
|
|
885 | { |
|
|
886 | return 0; |
|
|
887 | } |
|
|
888 | |
|
|
889 | int ret = strcmp(ending, instring + (l2 - l1)); |
|
|
890 | //dbg(0, "ending=%s in=%s ret=%d\n", ending, instring + (l2 - l1), (ret == 0)); |
|
|
891 | return (ret == 0); |
|
|
892 | } |
|
|
893 | |
837 | |
894 | |
838 | void osm_warning(char *type, long long id, int cont, char *fmt, ...) |
895 | void osm_warning(char *type, long long id, int cont, char *fmt, ...) |
839 | { |
896 | { |
840 | char str[4096]; |
897 | char str[4096]; |
841 | va_list ap; |
898 | va_list ap; |
… | |
… | |
856 | } |
913 | } |
857 | |
914 | |
858 | static void attr_strings_clear(void) |
915 | static void attr_strings_clear(void) |
859 | { |
916 | { |
860 | alt_name_found = 0; |
917 | alt_name_found = 0; |
|
|
918 | real_alt_name_found = 0; |
861 | attr_strings_buffer_len = 0; |
919 | attr_strings_buffer_len = 0; |
862 | memset(attr_strings, 0, sizeof(attr_strings)); |
920 | memset(attr_strings, 0, sizeof(attr_strings)); |
863 | } |
921 | } |
864 | |
922 | |
865 | static void attr_strings_save(enum attr_strings id, char *str) |
923 | static void attr_strings_save(enum attr_strings id, char *str) |
… | |
… | |
914 | return ret; |
972 | return ret; |
915 | } |
973 | } |
916 | |
974 | |
917 | static int node_is_tagged; |
975 | static int node_is_tagged; |
918 | static void relation_add_tag(char *k, char *v); |
976 | static void relation_add_tag(char *k, char *v); |
|
|
977 | osmid get_waynode_num_have_seekpos(osmid way_id, int coord_num, int local_thread_num, off_t seek_pos); |
|
|
978 | |
919 | |
979 | |
920 | static int access_value(char *v) |
980 | static int access_value(char *v) |
921 | { |
981 | { |
922 | if (!strcmp(v, "1")) |
982 | if (!strcmp(v, "1")) |
923 | return 1; |
983 | return 1; |
… | |
… | |
957 | return; |
1017 | return; |
958 | } |
1018 | } |
959 | |
1019 | |
960 | if (!strcmp(k, "ele")) |
1020 | if (!strcmp(k, "ele")) |
961 | level = 9; |
1021 | level = 9; |
|
|
1022 | |
962 | if (!strcmp(k, "time")) |
1023 | if (!strcmp(k, "time")) |
963 | level = 9; |
1024 | level = 9; |
|
|
1025 | |
964 | if (!strcmp(k, "created_by")) |
1026 | if (!strcmp(k, "created_by")) |
965 | level = 9; |
1027 | level = 9; |
|
|
1028 | |
966 | if (!strncmp(k, "tiger:", 6) || !strcmp(k, "AND_nodes")) |
1029 | if (!strncmp(k, "tiger:", 6) || !strcmp(k, "AND_nodes")) |
967 | level = 9; |
1030 | level = 9; |
|
|
1031 | |
968 | if (!strcmp(k, "converted_by") || !strcmp(k, "source")) |
1032 | if (!strcmp(k, "converted_by") || !strcmp(k, "source")) |
969 | level = 8; |
1033 | level = 8; |
|
|
1034 | |
970 | if (!strncmp(k, "osmarender:", 11) || !strncmp(k, "svg:", 4)) |
1035 | if (!strncmp(k, "osmarender:", 11) || !strncmp(k, "svg:", 4)) |
971 | level = 8; |
1036 | level = 8; |
|
|
1037 | |
972 | if (!strcmp(k, "layer")) |
1038 | if (!strcmp(k, "layer")) |
973 | level = 7; |
1039 | level = 7; |
|
|
1040 | |
974 | if (!strcasecmp(v, "true") || !strcasecmp(v, "yes")) |
1041 | if (!strcasecmp(v, "true") || !strcasecmp(v, "yes")) |
975 | v = "1"; |
1042 | v = "1"; |
|
|
1043 | |
976 | if (!strcasecmp(v, "false") || !strcasecmp(v, "no")) |
1044 | if (!strcasecmp(v, "false") || !strcasecmp(v, "no")) |
977 | v = "0"; |
1045 | v = "0"; |
|
|
1046 | |
|
|
1047 | |
|
|
1048 | |
|
|
1049 | |
|
|
1050 | |
978 | if (!strcmp(k, "oneway")) |
1051 | if (!strcmp(k, "oneway")) |
979 | { |
1052 | { |
980 | if (!strcmp(v, "1")) |
1053 | if (!strcmp(v, "1")) |
981 | { |
1054 | { |
982 | flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT_VALID; |
1055 | flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT_VALID; |
983 | } |
1056 | } |
|
|
1057 | |
984 | if (!strcmp(v, "-1")) |
1058 | if (!strcmp(v, "-1")) |
985 | { |
1059 | { |
986 | flags[0] |= NAVIT_AF_ONEWAYREV | NAVIT_AF_ROUNDABOUT_VALID; |
1060 | flags[0] |= NAVIT_AF_ONEWAYREV | NAVIT_AF_ROUNDABOUT_VALID; |
987 | } |
1061 | } |
|
|
1062 | |
988 | if (!in_way) |
1063 | if (!in_way) |
|
|
1064 | { |
989 | level = 6; |
1065 | level = 6; |
|
|
1066 | } |
990 | else |
1067 | else |
|
|
1068 | { |
991 | level = 5; |
1069 | level = 5; |
992 | } |
1070 | } |
|
|
1071 | } |
|
|
1072 | |
|
|
1073 | if (!strcmp(k, "cycleway")) |
|
|
1074 | { |
|
|
1075 | if (!strcmp(v, "opposite")) |
|
|
1076 | { |
|
|
1077 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_NO; |
|
|
1078 | } |
|
|
1079 | if (!strcmp(v, "opposite_lane")) |
|
|
1080 | { |
|
|
1081 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_NO; |
|
|
1082 | } |
|
|
1083 | |
|
|
1084 | if (!in_way) |
|
|
1085 | { |
|
|
1086 | level = 6; |
|
|
1087 | } |
|
|
1088 | else |
|
|
1089 | { |
|
|
1090 | level = 5; |
|
|
1091 | } |
|
|
1092 | } |
|
|
1093 | |
|
|
1094 | |
|
|
1095 | if (!strcmp(k, "bicycle:oneway")) |
|
|
1096 | { |
|
|
1097 | if (!strcmp(v, "0")) |
|
|
1098 | { |
|
|
1099 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_NO; |
|
|
1100 | } |
|
|
1101 | if (!strcmp(v, "1")) |
|
|
1102 | { |
|
|
1103 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_YES; |
|
|
1104 | } |
|
|
1105 | |
|
|
1106 | if (!in_way) |
|
|
1107 | { |
|
|
1108 | level = 6; |
|
|
1109 | } |
|
|
1110 | else |
|
|
1111 | { |
|
|
1112 | level = 5; |
|
|
1113 | } |
|
|
1114 | } |
|
|
1115 | |
|
|
1116 | if (!strcmp(k, "oneway:bicycle")) |
|
|
1117 | { |
|
|
1118 | if (!strcmp(v, "0")) |
|
|
1119 | { |
|
|
1120 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_NO; |
|
|
1121 | } |
|
|
1122 | if (!strcmp(v, "1")) |
|
|
1123 | { |
|
|
1124 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_YES; |
|
|
1125 | } |
|
|
1126 | |
|
|
1127 | if (!in_way) |
|
|
1128 | { |
|
|
1129 | level = 6; |
|
|
1130 | } |
|
|
1131 | else |
|
|
1132 | { |
|
|
1133 | level = 5; |
|
|
1134 | } |
|
|
1135 | } |
|
|
1136 | |
|
|
1137 | |
|
|
1138 | /* |
|
|
1139 | blue: cycleway=lane + oneway=yes |
|
|
1140 | blue: cycleway=lane + oneway=yes + bicycle=yes |
|
|
1141 | |
|
|
1142 | xxxx: cycleway=opposite_lane + cycleway:left=lane + oneway=yes |
|
|
1143 | xxxx: bicycle=yes + cycleway:right=lane + oneway=yes |
|
|
1144 | xxxx: cycleway:left=track + cycleway:right=lane + oneway=yes + oneway:bicycle=no |
|
|
1145 | xxxx: cycleway:left=share_busway + cycleway:right=lane + oneway=yes + oneway:bicycle=no |
|
|
1146 | |
|
|
1147 | dots: cycleway=track + oneway=yes |
|
|
1148 | dots: cycleway=track |
|
|
1149 | |
|
|
1150 | xxxx: cycleway:left=track + oneway=yes |
|
|
1151 | xxxx: cycleway:right=track + oneway=yes |
|
|
1152 | |
|
|
1153 | xxxx: cycleway:right=track |
|
|
1154 | xxxx: cycleway:right=track + cycleway:right:oneway=no |
|
|
1155 | */ |
|
|
1156 | |
|
|
1157 | if (!strcmp(k, "cycleway")) |
|
|
1158 | { |
|
|
1159 | if (!strcmp(v, "track")) |
|
|
1160 | { |
|
|
1161 | flags[0] |= NAVIT_AF_BICYCLE_TRACK; |
|
|
1162 | } |
|
|
1163 | |
|
|
1164 | if (!in_way) |
|
|
1165 | { |
|
|
1166 | level = 6; |
|
|
1167 | } |
|
|
1168 | else |
|
|
1169 | { |
|
|
1170 | level = 5; |
|
|
1171 | } |
|
|
1172 | } |
|
|
1173 | |
|
|
1174 | |
|
|
1175 | |
|
|
1176 | /* |
|
|
1177 | cycleway=lane |
|
|
1178 | cycleway:right=lane |
|
|
1179 | cycleway:left=lane |
|
|
1180 | |
|
|
1181 | cycleway=opposite_lane |
|
|
1182 | cycleway:left=opposite_lane |
|
|
1183 | cycleway:right=opposite_lane |
|
|
1184 | */ |
|
|
1185 | |
|
|
1186 | if (!strcmp(k, "cycleway")) |
|
|
1187 | { |
|
|
1188 | if (!strcmp(v, "lane")) |
|
|
1189 | { |
|
|
1190 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
|
|
1191 | } |
|
|
1192 | else if (!strcmp(v, "opposite_lane")) |
|
|
1193 | { |
|
|
1194 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
|
|
1195 | } |
|
|
1196 | |
|
|
1197 | if (!in_way) |
|
|
1198 | { |
|
|
1199 | level = 6; |
|
|
1200 | } |
|
|
1201 | else |
|
|
1202 | { |
|
|
1203 | level = 5; |
|
|
1204 | } |
|
|
1205 | } |
|
|
1206 | |
|
|
1207 | |
|
|
1208 | if (!strcmp(k, "cycleway:left")) |
|
|
1209 | { |
|
|
1210 | if (!strcmp(v, "lane")) |
|
|
1211 | { |
|
|
1212 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
|
|
1213 | } |
|
|
1214 | else if (!strcmp(v, "opposite_lane")) |
|
|
1215 | { |
|
|
1216 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
|
|
1217 | } |
|
|
1218 | |
|
|
1219 | if (!in_way) |
|
|
1220 | { |
|
|
1221 | level = 6; |
|
|
1222 | } |
|
|
1223 | else |
|
|
1224 | { |
|
|
1225 | level = 5; |
|
|
1226 | } |
|
|
1227 | } |
|
|
1228 | |
|
|
1229 | if (!strcmp(k, "cycleway:right")) |
|
|
1230 | { |
|
|
1231 | if (!strcmp(v, "lane")) |
|
|
1232 | { |
|
|
1233 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
|
|
1234 | } |
|
|
1235 | else if (!strcmp(v, "opposite_lane")) |
|
|
1236 | { |
|
|
1237 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
|
|
1238 | } |
|
|
1239 | |
|
|
1240 | if (!in_way) |
|
|
1241 | { |
|
|
1242 | level = 6; |
|
|
1243 | } |
|
|
1244 | else |
|
|
1245 | { |
|
|
1246 | level = 5; |
|
|
1247 | } |
|
|
1248 | } |
|
|
1249 | |
|
|
1250 | |
|
|
1251 | |
|
|
1252 | |
993 | if (!strcmp(k, "junction")) |
1253 | if (!strcmp(k, "junction")) |
994 | { |
1254 | { |
995 | if (!strcmp(v, "roundabout")) |
1255 | if (!strcmp(v, "roundabout")) |
996 | flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT | NAVIT_AF_ROUNDABOUT_VALID; |
1256 | flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT | NAVIT_AF_ROUNDABOUT_VALID; |
997 | } |
1257 | } |
|
|
1258 | |
998 | if (!strcmp(k, "maxspeed")) |
1259 | if (!strcmp(k, "maxspeed")) |
999 | { |
1260 | { |
1000 | if (strstr(v, "mph")) |
1261 | if (strstr(v, "mph")) |
1001 | { |
1262 | { |
1002 | maxspeed_attr_value = (int) floor(atof(v) * 1.609344); |
1263 | maxspeed_attr_value = (int) floor(atof(v) * 1.609344); |
1003 | } |
1264 | } |
1004 | else |
1265 | else |
1005 | { |
1266 | { |
1006 | maxspeed_attr_value = atoi(v); |
1267 | maxspeed_attr_value = atoi(v); |
1007 | } |
1268 | } |
|
|
1269 | |
1008 | if (maxspeed_attr_value) |
1270 | if (maxspeed_attr_value) |
|
|
1271 | |
1009 | flags[0] |= NAVIT_AF_SPEED_LIMIT; |
1272 | flags[0] |= NAVIT_AF_SPEED_LIMIT; |
1010 | level = 5; |
1273 | level = 5; |
1011 | } |
1274 | } |
1012 | if (!strcmp(k, "toll")) |
1275 | if (!strcmp(k, "toll")) |
1013 | { |
1276 | { |
… | |
… | |
1102 | } |
1365 | } |
1103 | if (!strcmp(k, "bridge") && !strcmp(v, "1")) |
1366 | if (!strcmp(k, "bridge") && !strcmp(v, "1")) |
1104 | { |
1367 | { |
1105 | flags[0] |= NAVIT_AF_BRIDGE; |
1368 | flags[0] |= NAVIT_AF_BRIDGE; |
1106 | } |
1369 | } |
|
|
1370 | |
1107 | if (!strcmp(k, "note")) |
1371 | if (!strcmp(k, "note")) |
|
|
1372 | { |
1108 | level = 5; |
1373 | level = 5; |
|
|
1374 | } |
|
|
1375 | |
1109 | if (!strcmp(k, "name")) |
1376 | if (!strcmp(k, "name")) |
1110 | { |
1377 | { |
1111 | attr_strings_save(attr_string_label, v); |
1378 | attr_strings_save(attr_string_label, v); |
1112 | level = 5; |
1379 | level = 5; |
1113 | } |
1380 | } |
1114 | |
1381 | |
|
|
1382 | if (!strcmp(k, "capacity")) |
|
|
1383 | { |
|
|
1384 | attr_strings_save(attr_string_capacity, v); |
|
|
1385 | level = 5; |
|
|
1386 | } |
|
|
1387 | |
|
|
1388 | if (!strcmp(k, "alt_name")) |
|
|
1389 | { |
|
|
1390 | // alternative name for some places (is sometimes what people call it in the local area) |
|
|
1391 | attr_strings_save(attr_string_label_real_alt, v); |
|
|
1392 | real_alt_name_found = 1; |
|
|
1393 | level = 5; |
|
|
1394 | } |
|
|
1395 | |
1115 | if ((!strcmp(k, "name:en")) && (alt_name_found == 0)) |
1396 | if ((!strcmp(k, "int_name")) && (alt_name_found == 0)) |
1116 | { |
1397 | { |
|
|
1398 | // only use "int_name" if we dont have "name:en" |
1117 | attr_strings_save(attr_string_label_alt, v); |
1399 | attr_strings_save(attr_string_label_alt, v); |
1118 | alt_name_found = 1; |
1400 | alt_name_found = 1; // lowest priority |
1119 | level = 5; |
1401 | level = 5; |
1120 | } |
1402 | } |
1121 | if ((!strcmp(k, "alt_name:en")) && (alt_name_found < 2)) |
1403 | if (!strcmp(k, "name:en")) |
1122 | { |
1404 | { |
1123 | // only use "alt_name:en" if we dont have "alt_name" |
|
|
1124 | attr_strings_save(attr_string_label_alt, v); |
1405 | attr_strings_save(attr_string_label_alt, v); |
1125 | alt_name_found = 2; |
1406 | alt_name_found = 2; // highest priority |
1126 | level = 5; |
|
|
1127 | } |
|
|
1128 | if (!strcmp(k, "alt_name")) |
|
|
1129 | { |
|
|
1130 | attr_strings_save(attr_string_label_alt, v); |
|
|
1131 | alt_name_found = 3; |
|
|
1132 | level = 5; |
1407 | level = 5; |
1133 | } |
1408 | } |
1134 | if (!strcmp(k, "addr:email")) |
1409 | if (!strcmp(k, "addr:email")) |
1135 | { |
1410 | { |
1136 | attr_strings_save(attr_string_email, v); |
1411 | attr_strings_save(attr_string_email, v); |
… | |
… | |
1182 | level = 5; |
1457 | level = 5; |
1183 | } |
1458 | } |
1184 | if (!strcmp(k, "ref")) |
1459 | if (!strcmp(k, "ref")) |
1185 | { |
1460 | { |
1186 | if (in_way) |
1461 | if (in_way) |
|
|
1462 | { |
1187 | attr_strings_save(attr_string_street_name_systematic, v); |
1463 | attr_strings_save(attr_string_street_name_systematic, v); |
|
|
1464 | } |
|
|
1465 | else |
|
|
1466 | { |
|
|
1467 | attr_strings_save(attr_string_ref, v); |
|
|
1468 | } |
1188 | level = 5; |
1469 | level = 5; |
1189 | } |
1470 | } |
|
|
1471 | if (! strcmp(k,"nat_ref")) |
|
|
1472 | { |
|
|
1473 | if (in_way) |
|
|
1474 | { |
|
|
1475 | attr_strings_save(attr_string_street_name_systematic_nat, v); |
|
|
1476 | //fprintf(stderr, "XYZ123!?:nat_ref=%s\n", v); |
|
|
1477 | } |
|
|
1478 | level=5; |
|
|
1479 | } |
|
|
1480 | if (! strcmp(k,"int_ref")) |
|
|
1481 | { |
|
|
1482 | if (in_way) |
|
|
1483 | { |
|
|
1484 | attr_strings_save(attr_string_street_name_systematic_int, v); |
|
|
1485 | //fprintf(stderr, "XYZ123!?:int_ref=%s\n", v); |
|
|
1486 | } |
|
|
1487 | level=5; |
|
|
1488 | } |
|
|
1489 | if (! strcmp(k,"destination:lanes")) |
|
|
1490 | { |
|
|
1491 | if (in_way) |
|
|
1492 | { |
|
|
1493 | attr_strings_save(attr_string_street_destination_lanes, v); |
|
|
1494 | //fprintf(stderr, "XYZ123!?:destination:lanes=%s\n", v); |
|
|
1495 | } |
|
|
1496 | level=5; |
|
|
1497 | } |
|
|
1498 | if (! strcmp(k,"destination")) |
|
|
1499 | { |
|
|
1500 | if (in_way) |
|
|
1501 | { |
|
|
1502 | attr_strings_save(attr_string_street_destination, v); |
|
|
1503 | //fprintf(stderr, "XYZ123!?:destination=%s\n", v); |
|
|
1504 | } |
|
|
1505 | level=5; |
|
|
1506 | } |
|
|
1507 | if (! strcmp(k,"exit_to")) |
|
|
1508 | { |
|
|
1509 | attr_strings_save(attr_string_exit_to, v); |
|
|
1510 | //fprintf(stderr, "XYZ123!?:exit_to=%s\n", v); |
|
|
1511 | level=5; |
|
|
1512 | } |
1190 | if (!strcmp(k, "openGeoDB:is_in")) |
1513 | if (!strcmp(k, "openGeoDB:is_in")) |
1191 | { |
1514 | { |
1192 | if (!is_in_buffer[0]) |
1515 | if (!is_in_buffer[0]) |
|
|
1516 | { |
1193 | strcpy(is_in_buffer, v); |
1517 | strcpy(is_in_buffer, v); |
|
|
1518 | } |
1194 | level = 5; |
1519 | level = 5; |
1195 | } |
1520 | } |
1196 | if (!strcmp(k, "is_in")) |
1521 | if (!strcmp(k, "is_in")) |
1197 | { |
1522 | { |
1198 | if (!is_in_buffer[0]) |
1523 | if (!is_in_buffer[0]) |
|
|
1524 | { |
1199 | strcpy(is_in_buffer, v); |
1525 | strcpy(is_in_buffer, v); |
|
|
1526 | } |
1200 | level = 5; |
1527 | level = 5; |
1201 | } |
1528 | } |
1202 | if (!strcmp(k, "is_in:country")) |
1529 | if (!strcmp(k, "is_in:country")) |
1203 | { |
1530 | { |
1204 | /** |
1531 | /** |
… | |
… | |
1228 | many US towns do not have is_in tags |
1555 | many US towns do not have is_in tags |
1229 | */ |
1556 | */ |
1230 | strcpy(is_in_buffer, "USA"); |
1557 | strcpy(is_in_buffer, "USA"); |
1231 | level = 5; |
1558 | level = 5; |
1232 | } |
1559 | } |
|
|
1560 | |
|
|
1561 | if (!strcmp(k, "turn:lanes")) |
|
|
1562 | { |
|
|
1563 | if (in_way) |
|
|
1564 | { |
|
|
1565 | attr_strings_save(attr_string_street_turn_lanes, v); |
|
|
1566 | //fprintf(stderr, "XYZ123!?:turn:lanes=%s\n", v); |
|
|
1567 | } |
|
|
1568 | level = 5; |
|
|
1569 | } |
|
|
1570 | |
|
|
1571 | |
|
|
1572 | if (!strcmp(k, "lanes:forward")) |
|
|
1573 | { |
|
|
1574 | if (in_way) |
|
|
1575 | { |
|
|
1576 | attr_strings_save(attr_string_street_lanes_forward, v); |
|
|
1577 | //fprintf(stderr, "XYZ123!?:lanes:forward=%s\n", v); |
|
|
1578 | } |
|
|
1579 | level = 5; |
|
|
1580 | } |
|
|
1581 | |
1233 | if (!strcmp(k, "lanes")) |
1582 | if (!strcmp(k, "lanes")) |
1234 | { |
1583 | { |
|
|
1584 | if (in_way) |
|
|
1585 | { |
|
|
1586 | attr_strings_save(attr_string_street_lanes, v); |
|
|
1587 | //fprintf(stderr, "XYZ123!?:lanes=%s\n", v); |
|
|
1588 | } |
1235 | level = 5; |
1589 | level = 5; |
1236 | } |
1590 | } |
|
|
1591 | |
|
|
1592 | |
1237 | if (attr_debug_level >= level) |
1593 | if (attr_debug_level >= level) |
1238 | { |
1594 | { |
1239 | int bytes_left = sizeof(debug_attr_buffer) - strlen(debug_attr_buffer) - 1; |
1595 | int bytes_left = sizeof(debug_attr_buffer) - strlen(debug_attr_buffer) - 1; |
1240 | if (bytes_left > 0) |
1596 | if (bytes_left > 0) |
1241 | { |
1597 | { |
… | |
… | |
1250 | node_is_tagged = 1; |
1606 | node_is_tagged = 1; |
1251 | } |
1607 | } |
1252 | |
1608 | |
1253 | strcpy(buffer, "*=*"); |
1609 | strcpy(buffer, "*=*"); |
1254 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1610 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
|
|
1611 | { |
1255 | attr_present[idx] = 1; |
1612 | attr_present[idx] = 1; |
|
|
1613 | } |
1256 | |
1614 | |
1257 | sprintf(buffer, "%s=*", k); |
1615 | sprintf(buffer, "%s=*", k); |
1258 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1616 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
|
|
1617 | { |
1259 | attr_present[idx] = 2; |
1618 | attr_present[idx] = 2; |
|
|
1619 | } |
1260 | |
1620 | |
1261 | sprintf(buffer, "*=%s", v); |
1621 | sprintf(buffer, "*=%s", v); |
1262 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1622 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
|
|
1623 | { |
1263 | attr_present[idx] = 2; |
1624 | attr_present[idx] = 2; |
|
|
1625 | } |
1264 | |
1626 | |
1265 | sprintf(buffer, "%s=%s", k, v); |
1627 | sprintf(buffer, "%s=%s", k, v); |
1266 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1628 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
|
|
1629 | { |
1267 | attr_present[idx] = 4; |
1630 | attr_present[idx] = 4; |
|
|
1631 | } |
1268 | } |
1632 | } |
1269 | |
1633 | |
1270 | int coord_count; |
1634 | int coord_count; |
1271 | |
1635 | |
1272 | static void extend_buffer(struct buffer *b) |
1636 | static void extend_buffer(struct buffer *b) |
… | |
… | |
1285 | |
1649 | |
1286 | osmid nodeid_last; |
1650 | osmid nodeid_last; |
1287 | GHashTable *way_hash, *waytag_hash; |
1651 | GHashTable *way_hash, *waytag_hash; |
1288 | cfuhash_table_t *way_hash_cfu = NULL; |
1652 | cfuhash_table_t *way_hash_cfu = NULL; |
1289 | |
1653 | |
1290 | typedef struct dummy_cfuhash_entry { |
1654 | typedef struct dummy_cfuhash_entry |
|
|
1655 | { |
1291 | long long key; |
1656 | long long key; |
1292 | int data; |
1657 | int data; |
1293 | struct dummy_cfuhash_entry *next; |
1658 | struct dummy_cfuhash_entry *next; |
1294 | } dummy_cfuhash_entry; |
1659 | } dummy_cfuhash_entry; |
1295 | |
1660 | |
1296 | static void node_buffer_to_hash(int local_thread_num) |
1661 | static void node_buffer_to_hash(int local_thread_num) |
1297 | { |
1662 | { |
1298 | if (verbose_mode) |
1663 | if (verbose_mode) |
|
|
1664 | { |
1299 | fprintf(stderr, "node_buffer_to_hash t:%d nb->size:%lu\n", local_thread_num, node_buffer[local_thread_num].size); |
1665 | fprintf(stderr, "node_buffer_to_hash t:%d nb->size:%lu\n", local_thread_num, node_buffer[local_thread_num].size); |
1300 | if (verbose_mode) |
|
|
1301 | fprintf(stderr, "node_buffer_to_hash t:%d nb->base:%lu\n", local_thread_num, node_buffer[local_thread_num].base); |
1666 | fprintf(stderr, "node_buffer_to_hash t:%d nb->base:%lu\n", local_thread_num, node_buffer[local_thread_num].base); |
1302 | if (verbose_mode) |
|
|
1303 | fprintf(stderr, "node_buffer_to_hash t:%d nh:%p\n", local_thread_num, node_hash[local_thread_num]); |
1667 | fprintf(stderr, "node_buffer_to_hash t:%d nh:%p\n", local_thread_num, node_hash[local_thread_num]); |
|
|
1668 | } |
1304 | |
1669 | |
1305 | int i = 0; |
1670 | int i = 0; |
1306 | int count2 = node_buffer[local_thread_num].size / sizeof(struct node_item); |
1671 | int count2 = node_buffer[local_thread_num].size / sizeof(struct node_item); |
1307 | struct node_item *ni = (struct node_item *) node_buffer[local_thread_num].base; |
1672 | struct node_item *ni = (struct node_item *) node_buffer[local_thread_num].base; |
1308 | |
1673 | |
|
|
1674 | #if 0 |
1309 | fprintf(stderr, "[THREAD] #%d fill hash node: count=%d size=%d\n", local_thread_num, count2, sizeof(dummy_cfuhash_entry)); |
1675 | fprintf(stderr, "[THREAD] #%d fill hash node: count=%d size=%d\n", local_thread_num, count2, sizeof(dummy_cfuhash_entry)); |
|
|
1676 | #endif |
|
|
1677 | |
|
|
1678 | struct dummy_dummy_entry |
|
|
1679 | { |
|
|
1680 | long long key; |
|
|
1681 | int value_ptr; |
|
|
1682 | }; |
|
|
1683 | |
|
|
1684 | fprintf_(stderr, "[THREAD] #%d fill hash node: count=%d size=%d\n", local_thread_num, count2, sizeof(struct dummy_dummy_entry)); |
1310 | |
1685 | |
1311 | for (i = 0; i < count2; i++) |
1686 | for (i = 0; i < count2; i++) |
1312 | { |
1687 | { |
1313 | /* |
1688 | /* |
1314 | if (i % 5000) |
1689 | if (i % 5000) |
1315 | { |
1690 | { |
1316 | fprintf(stderr, "thread #%d fill #%d\n", local_thread_num, i); |
|
|
1317 | } |
1691 | } |
1318 | */ |
1692 | */ |
|
|
1693 | |
|
|
1694 | // fprintf_(stderr, "thread #%d fill #%d/%d\n", local_thread_num, i, count2); |
|
|
1695 | |
1319 | // g_hash_table_insert(node_hash[local_thread_num], (gpointer) (long) (ni[i].id), (gpointer) (long) i); |
1696 | // g_hash_table_insert(node_hash[local_thread_num], (gpointer) (long) (ni[i].id), (gpointer) (long) i); |
1320 | //cfuhash_put(node_hash_cfu[local_thread_num], &(long long)ni[i].id, xxx); |
1697 | //cfuhash_put(node_hash_cfu[local_thread_num], &(long long)ni[i].id, xxx); |
1321 | |
1698 | |
|
|
1699 | #if 0 |
1322 | //fprintf(stderr, "node id:%lld i:%d\n", (long long)ni[i].id, i); |
1700 | //fprintf(stderr, "node id:%lld i:%d\n", (long long)ni[i].id, i); |
1323 | cfuhash_put_data(node_hash_cfu[local_thread_num], (long long)ni[i].id, sizeof(long long), i, sizeof(int), NULL); |
1701 | cfuhash_put_data(node_hash_cfu[local_thread_num], (long long)ni[i].id, sizeof(long long), i, sizeof(int), NULL); |
|
|
1702 | #endif |
|
|
1703 | |
|
|
1704 | // fprintf(stderr, "node id:%lld mem:%p\n", (long long)ni->id, ni); |
|
|
1705 | quick_hash_add_entry(node_hash_cfu[local_thread_num], (long long)ni[i].id, i); |
|
|
1706 | // ni++; |
1324 | } |
1707 | } |
|
|
1708 | |
|
|
1709 | // fprintf_(stderr, "thread #%d node_buffer_to_hash ready\n", local_thread_num); |
1325 | |
1710 | |
1326 | if (verbose_mode) |
1711 | if (verbose_mode) |
1327 | { |
1712 | { |
1328 | fprintf(stderr, "node_buffer_to_hash ready\n"); |
1713 | fprintf(stderr, "node_buffer_to_hash ready\n"); |
1329 | } |
1714 | } |
… | |
… | |
1353 | //} |
1738 | //} |
1354 | //else |
1739 | //else |
1355 | //{ |
1740 | //{ |
1356 | //*node_hash[i] = g_hash_table_new(NULL, NULL); |
1741 | //*node_hash[i] = g_hash_table_new(NULL, NULL); |
1357 | //} |
1742 | //} |
|
|
1743 | #if 0 |
1358 | node_hash_cfu[i] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
1744 | node_hash_cfu[i] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
1359 | cfuhash_set_flag(node_hash_cfu[i], CFUHASH_FROZEN); |
1745 | cfuhash_set_flag(node_hash_cfu[i], CFUHASH_FROZEN); |
|
|
1746 | #endif |
|
|
1747 | node_hash_cfu[i] = quick_hash_init(CFUHASH_BUCKETS_NODES); |
1360 | } |
1748 | } |
1361 | } |
1749 | } |
1362 | |
1750 | |
1363 | void fill_hash_node(int local_thread_num) |
1751 | void fill_hash_node(int local_thread_num) |
1364 | { |
1752 | { |
1365 | //fprintf(stderr, "001t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1753 | //fprintf(stderr, "001t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1366 | |
1754 | |
1367 | if (verbose_mode) |
1755 | if (verbose_mode) |
|
|
1756 | { |
1368 | fprintf(stderr, "fill_hash_node - START\n"); |
1757 | fprintf(stderr, "fill_hash_node - START\n"); |
|
|
1758 | } |
1369 | //if (node_hash[local_thread_num]) |
1759 | //if (node_hash[local_thread_num]) |
1370 | if (node_hash_cfu[local_thread_num]) |
1760 | if (node_hash_cfu[local_thread_num]) |
1371 | { |
1761 | { |
|
|
1762 | #if 0 |
1372 | //g_hash_table_destroy(node_hash[local_thread_num]); |
1763 | //g_hash_table_destroy(node_hash[local_thread_num]); |
1373 | //node_hash[local_thread_num] = NULL; |
1764 | //node_hash[local_thread_num] = NULL; |
1374 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
1765 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
1375 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
1766 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
1376 | node_hash_cfu[local_thread_num] = NULL; |
1767 | node_hash_cfu[local_thread_num] = NULL; |
|
|
1768 | #endif |
|
|
1769 | quick_hash_destroy(node_hash_cfu[local_thread_num]); |
|
|
1770 | node_hash_cfu[local_thread_num] = NULL; |
1377 | } |
1771 | } |
1378 | |
1772 | |
|
|
1773 | #if 0 |
1379 | // node_hash[local_thread_num] = g_hash_table_new(NULL, NULL); |
1774 | // node_hash[local_thread_num] = g_hash_table_new(NULL, NULL); |
1380 | node_hash_cfu[local_thread_num] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
1775 | node_hash_cfu[local_thread_num] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
1381 | cfuhash_set_flag(node_hash_cfu[local_thread_num], CFUHASH_FROZEN); |
1776 | cfuhash_set_flag(node_hash_cfu[local_thread_num], CFUHASH_FROZEN); |
|
|
1777 | #endif |
|
|
1778 | node_hash_cfu[local_thread_num] = quick_hash_init(CFUHASH_BUCKETS_NODES); |
|
|
1779 | |
1382 | |
1780 | |
1383 | //fprintf(stderr, "002t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1781 | //fprintf(stderr, "002t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1384 | node_buffer_to_hash(local_thread_num); |
1782 | node_buffer_to_hash(local_thread_num); |
|
|
1783 | |
|
|
1784 | quick_hash_print_stats(node_hash_cfu[local_thread_num]); |
|
|
1785 | |
1385 | //fprintf(stderr, "003t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1786 | //fprintf(stderr, "003t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1386 | if (verbose_mode) |
1787 | if (verbose_mode) |
|
|
1788 | { |
1387 | fprintf(stderr, "fill_hash_node - END\n"); |
1789 | fprintf(stderr, "fill_hash_node - END\n"); |
|
|
1790 | } |
1388 | } |
1791 | } |
1389 | |
1792 | |
1390 | void flush_nodes(int final, int local_thread_num) |
1793 | void flush_nodes(int final, int local_thread_num) |
1391 | { |
1794 | { |
1392 | save_buffer("coords.tmp", &node_buffer[local_thread_num], slices * slice_size); |
1795 | save_buffer("coords.tmp", &node_buffer[local_thread_num], slices * slice_size); |
… | |
… | |
1405 | |
1808 | |
1406 | //if (node_hash[local_thread_num]) |
1809 | //if (node_hash[local_thread_num]) |
1407 | if (node_hash_cfu[local_thread_num]) |
1810 | if (node_hash_cfu[local_thread_num]) |
1408 | { |
1811 | { |
1409 | if (verbose_mode) fprintf(stderr,"node_hash size="LONGLONG_FMT"\n", g_hash_table_size (node_hash[local_thread_num])); |
1812 | if (verbose_mode) fprintf(stderr,"node_hash size="LONGLONG_FMT"\n", g_hash_table_size (node_hash[local_thread_num])); |
|
|
1813 | #if 0 |
1410 | //g_hash_table_destroy(node_hash[local_thread_num]); |
1814 | //g_hash_table_destroy(node_hash[local_thread_num]); |
1411 | //node_hash[local_thread_num] = NULL; |
1815 | //node_hash[local_thread_num] = NULL; |
1412 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
1816 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
1413 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
1817 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
1414 | node_hash_cfu[local_thread_num] = NULL; |
1818 | node_hash_cfu[local_thread_num] = NULL; |
|
|
1819 | #endif |
|
|
1820 | quick_hash_destroy(node_hash_cfu[local_thread_num]); |
|
|
1821 | node_hash_cfu[local_thread_num] = NULL; |
1415 | } |
1822 | } |
1416 | } |
1823 | } |
1417 | |
1824 | |
1418 | if (verbose_mode) fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer[local_thread_num].size); |
1825 | if (verbose_mode) fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer[local_thread_num].size); |
1419 | if (verbose_mode) fprintf(stderr,"node: node_buffer malloced="LONGLONG_FMT"\n", node_buffer[local_thread_num].malloced); |
1826 | if (verbose_mode) fprintf(stderr,"node: node_buffer malloced="LONGLONG_FMT"\n", node_buffer[local_thread_num].malloced); |
1420 | //fprintf(stderr, "007t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1827 | //fprintf(stderr, "007t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1421 | |
1828 | |
1422 | slices++; |
1829 | slices++; |
1423 | } |
1830 | } |
1424 | |
1831 | |
|
|
1832 | |
|
|
1833 | |
1425 | double transform_to_geo_lat(int y) |
1834 | inline double transform_to_geo_lat(int y) |
1426 | { |
1835 | { |
1427 | double lat = navit_atan(exp(y / 6371000.0)) / M_PI * 360 - 90; |
1836 | /* ZZ GEO TRANS ZZ */ |
1428 | return lat; |
1837 | return TO_GEO_LAT_(y); |
1429 | } |
1838 | } |
1430 | |
1839 | |
1431 | double transform_to_geo_lon(int x) |
1840 | inline double transform_to_geo_lon(int x) |
1432 | { |
1841 | { |
1433 | double lon = (x * 0.00000899322); |
1842 | /* ZZ GEO TRANS ZZ */ |
1434 | return lon; |
1843 | return TO_GEO_LON_(x); |
1435 | } |
1844 | } |
1436 | |
1845 | |
1437 | int transform_from_geo_lat(double lat) |
1846 | inline int transform_from_geo_lat(double lat) |
1438 | { |
1847 | { |
1439 | /* slower */ |
1848 | /* ZZ GEO TRANS ZZ */ |
1440 | // int ret = log(tan(M_PI_4 + lat * M_PI / 360)) * 6371000.0; |
1849 | return FROM_GEO_LAT_(lat); |
1441 | //fprintf(stderr, "y=%d\n", ret); |
|
|
1442 | /* slower */ |
|
|
1443 | |
|
|
1444 | /* fast */ |
|
|
1445 | int ret = log(tan(M_PI_4 + lat * 0.008726646259971647884618)) * 6371000.0; // already calced (M_PI/360) |
|
|
1446 | /* fast */ |
|
|
1447 | |
|
|
1448 | return ret; |
|
|
1449 | } |
1850 | } |
1450 | |
1851 | |
1451 | int transform_from_geo_lon(double lon) |
1852 | inline int transform_from_geo_lon(double lon) |
1452 | { |
1853 | { |
1453 | /* slower */ |
1854 | /* ZZ GEO TRANS ZZ */ |
1454 | //int ret = lon * 6371000.0 * M_PI / 180; |
1855 | return FROM_GEO_LON_(lon); |
1455 | // fprintf(stderr, "x=%d\n", ret); |
|
|
1456 | /* slower */ |
|
|
1457 | |
|
|
1458 | /* fast */ |
|
|
1459 | int ret = lon * 111194.9266445587373; // already calced (6371000.0*M_PI/180) |
|
|
1460 | /* fast */ |
|
|
1461 | |
|
|
1462 | return ret; |
|
|
1463 | } |
1856 | } |
1464 | |
1857 | |
1465 | void osm_add_node(osmid id, double lat, double lon) |
1858 | void osm_add_node(osmid id, double lat, double lon) |
1466 | { |
1859 | { |
1467 | in_node = 1; |
1860 | in_node = 1; |
… | |
… | |
1488 | ni->ref_node = 0; |
1881 | ni->ref_node = 0; |
1489 | ni->ref_way = 0; |
1882 | ni->ref_way = 0; |
1490 | ni->ref_ref = 0; |
1883 | ni->ref_ref = 0; |
1491 | ni->dummy = 0; |
1884 | ni->dummy = 0; |
1492 | |
1885 | |
1493 | /* slower */ |
1886 | // fprintf(stderr, "NNDD:000:%f %f\n", lat, lon); |
1494 | // ni->c.x = lon * 6371000.0 * M_PI / 180; |
|
|
1495 | // ni->c.y = log(tan(M_PI_4 + lat * M_PI / 360)) * 6371000.0; |
|
|
1496 | /* slower */ |
|
|
1497 | |
1887 | |
1498 | /* fast */ |
1888 | /* ZZ GEO TRANS ZZ */ |
1499 | ni->c.x = lon * 111194.9266445587373; // already calced (6371000.0*M_PI/180) |
1889 | ni->c.x = FROM_GEO_LON_(lon); |
1500 | ni->c.y = log(tan(M_PI_4 + lat * 0.008726646259971647884618)) * 6371000.0; // already calced (M_PI/360) |
1890 | ni->c.y = FROM_GEO_LAT_(lat); |
1501 | /* fast */ |
1891 | /* ZZ GEO TRANS ZZ */ |
|
|
1892 | |
|
|
1893 | // fprintf(stderr, "NNDD:002:%d %d\n", ni->c.x, ni->c.y); |
|
|
1894 | |
|
|
1895 | |
|
|
1896 | // save values ----- |
|
|
1897 | save_node_lat = lat; |
|
|
1898 | save_node_lon = lon; |
|
|
1899 | // save values ----- |
|
|
1900 | |
1502 | |
1901 | |
1503 | #ifdef MAPTOOL_USE_SQL |
1902 | #ifdef MAPTOOL_USE_SQL |
1504 | |
1903 | |
1505 | if (sql_counter2 == 0) |
1904 | if (sql_counter2 == 0) |
1506 | { |
1905 | { |
… | |
… | |
1626 | } |
2025 | } |
1627 | |
2026 | |
1628 | static struct node_item * |
2027 | static struct node_item * |
1629 | node_item_get_fast(osmid id, int local_thread_num) |
2028 | node_item_get_fast(osmid id, int local_thread_num) |
1630 | { |
2029 | { |
|
|
2030 | #if 1 |
1631 | int i; |
2031 | int i; |
1632 | void *p_tmp; |
2032 | //void *p_tmp; |
1633 | int rr; |
2033 | //int rr; |
1634 | size_t data_size2 = sizeof(int); |
2034 | //size_t data_size2 = sizeof(int); |
1635 | struct node_item *ni = (struct node_item *) (node_buffer[local_thread_num].base); |
2035 | struct node_item *ni = (struct node_item *) (node_buffer[local_thread_num].base); |
|
|
2036 | #endif |
1636 | |
2037 | |
1637 | //if (node_hash[local_thread_num]) |
2038 | //if (node_hash[local_thread_num]) |
1638 | if (node_hash_cfu[local_thread_num]) |
2039 | if (node_hash_cfu[local_thread_num]) |
1639 | { |
2040 | { |
|
|
2041 | #if 0 |
1640 | //p_tmp = (gpointer)(g_hash_table_lookup(node_hash[local_thread_num], (gpointer) (long) id)); |
2042 | //p_tmp = (gpointer)(g_hash_table_lookup(node_hash[local_thread_num], (gpointer) (long) id)); |
1641 | rr = cfuhash_get_data(node_hash_cfu[local_thread_num], (long long) id, sizeof(long long), &p_tmp, &data_size2); |
2043 | rr = cfuhash_get_data(node_hash_cfu[local_thread_num], (long long) id, sizeof(long long), &p_tmp, &data_size2); |
1642 | if (rr == 1) |
2044 | if (rr == 1) |
1643 | { |
2045 | { |
1644 | //fprintf(stderr, "got key=%lld value=%d\n", (long long) id, p_tmp); |
2046 | //fprintf(stderr, "got key=%lld value=%d\n", (long long) id, p_tmp); |
1645 | i = p_tmp; |
2047 | i = p_tmp; |
1646 | return ni + i; |
2048 | return ni + i; |
|
|
2049 | } |
|
|
2050 | #endif |
|
|
2051 | |
|
|
2052 | //struct node_item *ni = quick_hash_lookup(node_hash_cfu[local_thread_num], id); |
|
|
2053 | //fprintf(stderr, "got key=%lld value=%p\n", (long long)id, ni); |
|
|
2054 | //if (ni) |
|
|
2055 | //{ |
|
|
2056 | // fprintf(stderr, "x=%d y=%d\n", ni->c.x, ni->c.y); |
|
|
2057 | //} |
|
|
2058 | i = quick_hash_lookup(node_hash_cfu[local_thread_num], id); |
|
|
2059 | if (i != -1) |
|
|
2060 | { |
|
|
2061 | return ni + i; // move pointer "i" number of items forward |
1647 | } |
2062 | } |
1648 | |
2063 | |
1649 | //if (p_tmp != NULL) |
2064 | //if (p_tmp != NULL) |
1650 | //{ |
2065 | //{ |
1651 | // // only if node is found in hash! |
2066 | // // only if node is found in hash! |
… | |
… | |
1682 | maxspeed_attr_value = 0; |
2097 | maxspeed_attr_value = 0; |
1683 | flags_attr_value = 0; |
2098 | flags_attr_value = 0; |
1684 | memset(flags, 0, sizeof(flags)); |
2099 | memset(flags, 0, sizeof(flags)); |
1685 | debug_attr_buffer[0] = '\0'; |
2100 | debug_attr_buffer[0] = '\0'; |
1686 | osmid_attr_value = id; |
2101 | osmid_attr_value = id; |
|
|
2102 | |
1687 | if (wayid < wayid_last && !way_hash_cfu) |
2103 | if (wayid < wayid_last && !way_hash_cfu) |
1688 | { |
2104 | { |
1689 | if (verbose_mode) |
2105 | if (verbose_mode) |
1690 | { |
2106 | { |
1691 | fprintf(stderr, "INFO: Ways out of sequence (new %d vs old %d), adding hash\n", wayid, wayid_last); |
2107 | fprintf(stderr, "INFO: Ways out of sequence (new %d vs old %d), adding hash\n", wayid, wayid_last); |
1692 | } |
2108 | } |
1693 | // way_hash = g_hash_table_new(NULL, NULL); |
2109 | // way_hash = g_hash_table_new(NULL, NULL); |
1694 | way_hash_cfu = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_WAYS); |
2110 | way_hash_cfu = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_WAYS); |
1695 | cfuhash_set_flag(node_hash_cfu, CFUHASH_FROZEN); |
2111 | cfuhash_set_flag(way_hash_cfu, CFUHASH_FROZEN); |
1696 | |
2112 | |
1697 | } |
2113 | } |
1698 | wayid_last = wayid; |
2114 | wayid_last = wayid; |
1699 | } |
2115 | } |
1700 | |
2116 | |
… | |
… | |
1710 | debug_attr_buffer[0] = '\0'; |
2126 | debug_attr_buffer[0] = '\0'; |
1711 | relation_type[0] = '\0'; |
2127 | relation_type[0] = '\0'; |
1712 | iso_code[0] = '\0'; |
2128 | iso_code[0] = '\0'; |
1713 | admin_level = -1; |
2129 | admin_level = -1; |
1714 | boundary = 0; |
2130 | boundary = 0; |
|
|
2131 | |
|
|
2132 | // zero out buffer ----------------------- |
|
|
2133 | // bzero(item_bin_2, MAX_ITEMBIN_BYTES_); |
|
|
2134 | // zero out buffer ----------------------- |
|
|
2135 | |
1715 | item_bin_init(item_bin_2, type_none); |
2136 | item_bin_init(item_bin_2, type_none); |
1716 | item_bin_add_attr_longlong(item_bin_2, attr_osm_relationid, current_id); |
2137 | item_bin_add_attr_longlong(item_bin_2, attr_osm_relationid, current_id); |
1717 | } |
2138 | } |
1718 | |
2139 | |
1719 | static int country_id_from_iso2(char *iso) |
2140 | static int country_id_from_iso2(char *iso) |
1720 | { |
2141 | { |
1721 | int ret = 0; |
2142 | int ret = 0; |
1722 | if (iso) |
2143 | if (iso) |
1723 | { |
2144 | { |
1724 | // make lowercase |
2145 | // make uppercase |
1725 | int i99; |
2146 | int i99; |
1726 | for (i99 = 0; iso[i99]; i99++) |
2147 | for (i99 = 0; iso[i99]; i99++) |
1727 | { |
2148 | { |
1728 | iso[i99] = tolower(iso[i99]); |
2149 | iso[i99] = toupper(iso[i99]); |
1729 | } |
2150 | } |
1730 | struct country_search *search; |
2151 | struct country_search *search; |
1731 | struct attr country_iso2, country_id; |
2152 | struct attr country_iso2, country_id; |
1732 | struct item *item; |
2153 | struct item *item; |
1733 | country_iso2.type = attr_country_iso2; |
2154 | country_iso2.type = attr_country_iso2; |
… | |
… | |
1751 | country_search_destroy(search); |
2172 | country_search_destroy(search); |
1752 | } |
2173 | } |
1753 | return ret; |
2174 | return ret; |
1754 | } |
2175 | } |
1755 | |
2176 | |
1756 | static struct country_table * |
2177 | struct country_table *country_from_countryid(int id) |
1757 | country_from_countryid(int id) |
|
|
1758 | { |
2178 | { |
1759 | int i; |
2179 | int i; |
1760 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
2180 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
1761 | { |
2181 | { |
1762 | //if (debug_itembin(3)) |
2182 | //if (debug_itembin(3)) |
… | |
… | |
1961 | default: |
2381 | default: |
1962 | fprintf(stderr, "Error: %d\n", rc2); |
2382 | fprintf(stderr, "Error: %d\n", rc2); |
1963 | break; |
2383 | break; |
1964 | } |
2384 | } |
1965 | sqlite3_reset(st); |
2385 | sqlite3_reset(st); |
|
|
2386 | // sqlite3_finalize(st); |
1966 | |
2387 | |
1967 | if (nd != 0) |
2388 | if (nd != 0) |
1968 | { |
2389 | { |
1969 | get_lat_lon_for_node(nd, node); |
2390 | get_lat_lon_for_node(nd, node); |
1970 | } |
2391 | } |
… | |
… | |
2204 | int number_of_points_current_poly = 0; |
2625 | int number_of_points_current_poly = 0; |
2205 | int exception = 0; |
2626 | int exception = 0; |
2206 | int role_ = 0; |
2627 | int role_ = 0; |
2207 | |
2628 | |
2208 | double factor = 10000000; |
2629 | double factor = 10000000; |
|
|
2630 | |
|
|
2631 | struct node_lat_lon* lat_lon_c; |
2209 | |
2632 | |
2210 | // triangulate vars |
2633 | // triangulate vars |
2211 | #if 0 |
2634 | #if 0 |
2212 | struct triangulateio in, mid, out, vorout; |
2635 | struct triangulateio in, mid, out, vorout; |
2213 | #endif |
2636 | #endif |
… | |
… | |
2634 | //fprintf(stderr, "after while loop 2\n"); |
3057 | //fprintf(stderr, "after while loop 2\n"); |
2635 | |
3058 | |
2636 | if (found_new_way == 0) |
3059 | if (found_new_way == 0) |
2637 | { |
3060 | { |
2638 | // some problem with this multipolygon |
3061 | // some problem with this multipolygon |
2639 | fprintf(stderr, "relation id=%lld\n", current_id); |
3062 | fprintf_(stderr, "relation id=%lld\n", current_id); |
2640 | fprintf(stderr, "some problem with this multipolygon\n"); |
3063 | fprintf_(stderr, "some problem with this multipolygon\n"); |
2641 | triangulate_not_done = 1; |
3064 | triangulate_not_done = 1; |
2642 | problem = 1; |
3065 | problem = 1; |
2643 | break; |
3066 | break; |
2644 | } |
3067 | } |
2645 | } |
3068 | } |
… | |
… | |
2735 | cdt = p2t_cdt_new(current_points); |
3158 | cdt = p2t_cdt_new(current_points); |
2736 | //fprintf(stderr, "all OK (p2t_cdt_new)\n"); |
3159 | //fprintf(stderr, "all OK (p2t_cdt_new)\n"); |
2737 | } |
3160 | } |
2738 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3161 | CATCH( MAPTOOL_00001_EXCEPTION ) |
2739 | { |
3162 | { |
2740 | fprintf(stderr, "relation id=%lld\n", current_id); |
3163 | fprintf_(stderr, "relation id=%lld\n", current_id); |
2741 | fprintf(stderr, "Got Exception 1!\n"); |
3164 | fprintf_(stderr, "Got Exception 1!\n"); |
2742 | exception = 1; |
3165 | exception = 1; |
2743 | } |
3166 | } |
2744 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3167 | CATCH( MAPTOOL_00002_EXCEPTION ) |
2745 | { |
3168 | { |
2746 | fprintf(stderr, "relation id=%lld\n", current_id); |
3169 | fprintf_(stderr, "relation id=%lld\n", current_id); |
2747 | fprintf(stderr, "Got segv Exception 1!\n"); |
3170 | fprintf_(stderr, "Got segv Exception 1!\n"); |
2748 | exception = 1; |
3171 | exception = 1; |
2749 | } |
3172 | } |
2750 | FINALLY |
3173 | FINALLY |
2751 | { |
3174 | { |
2752 | // set default |
3175 | // set default |
… | |
… | |
2794 | // the last node should always be same as first node (for now we only support holes that dont span over multiple ways!) |
3217 | // the last node should always be same as first node (for now we only support holes that dont span over multiple ways!) |
2795 | if (cur_node_count_in_way < number_of_nodes_in_this_way) |
3218 | if (cur_node_count_in_way < number_of_nodes_in_this_way) |
2796 | { |
3219 | { |
2797 | if (glist_find_already_inside(temp_nodes_list, ndptr) != 0) |
3220 | if (glist_find_already_inside(temp_nodes_list, ndptr) != 0) |
2798 | { |
3221 | { |
2799 | fprintf(stderr, "relation id=%lld\n", current_id); |
3222 | fprintf_(stderr, "relation id=%lld\n", current_id); |
2800 | fprintf(stderr, "problem with hole!\n"); |
3223 | fprintf_(stderr, "problem with hole!\n"); |
2801 | no_holes = 1; |
3224 | no_holes = 1; |
2802 | break; |
3225 | break; |
2803 | } |
3226 | } |
2804 | else |
3227 | else |
2805 | { |
3228 | { |
… | |
… | |
2982 | g_ptr_array_add(current_hole, p2t_point_new_dd(x, y)); |
3405 | g_ptr_array_add(current_hole, p2t_point_new_dd(x, y)); |
2983 | //fprintf(stderr, "hole new done\n"); |
3406 | //fprintf(stderr, "hole new done\n"); |
2984 | } |
3407 | } |
2985 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3408 | CATCH( MAPTOOL_00001_EXCEPTION ) |
2986 | { |
3409 | { |
2987 | fprintf(stderr, "relation id=%lld\n", current_id); |
3410 | fprintf_(stderr, "relation id=%lld\n", current_id); |
2988 | fprintf(stderr, "Got Exception A!\n"); |
3411 | fprintf_(stderr, "Got Exception A!\n"); |
2989 | exception = 1; |
3412 | exception = 1; |
2990 | } |
3413 | } |
2991 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3414 | CATCH( MAPTOOL_00002_EXCEPTION ) |
2992 | { |
3415 | { |
2993 | fprintf(stderr, "relation id=%lld\n", current_id); |
3416 | fprintf_(stderr, "relation id=%lld\n", current_id); |
2994 | fprintf(stderr, "Got segv Exception A!\n"); |
3417 | fprintf_(stderr, "Got segv Exception A!\n"); |
2995 | exception = 1; |
3418 | exception = 1; |
2996 | } |
3419 | } |
2997 | FINALLY |
3420 | FINALLY |
2998 | { |
3421 | { |
2999 | // set default |
3422 | // set default |
… | |
… | |
3064 | } |
3487 | } |
3065 | //fprintf(stderr, "adding done\n"); |
3488 | //fprintf(stderr, "adding done\n"); |
3066 | } |
3489 | } |
3067 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3490 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3068 | { |
3491 | { |
3069 | fprintf(stderr, "relation id=%lld\n", current_id); |
3492 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3070 | fprintf(stderr, "Got Exception 8!\n"); |
3493 | fprintf_(stderr, "Got Exception 8!\n"); |
3071 | exception = 1; |
3494 | exception = 1; |
3072 | } |
3495 | } |
3073 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3496 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3074 | { |
3497 | { |
3075 | fprintf(stderr, "relation id=%lld\n", current_id); |
3498 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3076 | fprintf(stderr, "Got segv Exception 8!\n"); |
3499 | fprintf_(stderr, "Got segv Exception 8!\n"); |
3077 | exception = 1; |
3500 | exception = 1; |
3078 | } |
3501 | } |
3079 | FINALLY |
3502 | FINALLY |
3080 | { |
3503 | { |
3081 | // set default |
3504 | // set default |
… | |
… | |
3129 | p2t_cdt_triangulate(cdt); |
3552 | p2t_cdt_triangulate(cdt); |
3130 | //fprintf(stderr, "triangulate end\n"); |
3553 | //fprintf(stderr, "triangulate end\n"); |
3131 | } |
3554 | } |
3132 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3555 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3133 | { |
3556 | { |
3134 | fprintf(stderr, "relation id=%lld\n", current_id); |
3557 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3135 | fprintf(stderr, "Got Exception 2! (in triangulate)\n"); |
3558 | fprintf_(stderr, "Got Exception 2! (in triangulate)\n"); |
3136 | exception = 1; |
3559 | exception = 1; |
3137 | } |
3560 | } |
3138 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3561 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3139 | { |
3562 | { |
3140 | fprintf(stderr, "relation id=%lld\n", current_id); |
3563 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3141 | fprintf(stderr, "Got segv Exception 2! (in triangulate)\n"); |
3564 | fprintf_(stderr, "Got segv Exception 2! (in triangulate)\n"); |
3142 | exception = 1; |
3565 | exception = 1; |
3143 | } |
3566 | } |
3144 | FINALLY |
3567 | FINALLY |
3145 | { |
3568 | { |
3146 | //fprintf(stderr, "finally 2 (in triangulate)\n"); |
3569 | //fprintf(stderr, "finally 2 (in triangulate)\n"); |
… | |
… | |
3234 | // default |
3657 | // default |
3235 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
3658 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
3236 | //fprintf(stderr, "T:water\n"); |
3659 | //fprintf(stderr, "T:water\n"); |
3237 | } |
3660 | } |
3238 | |
3661 | |
3239 | // add dummy osm wayid |
3662 | // first add coords |
3240 | item_bin_add_attr_longlong(item_bin_tri, attr_osm_wayid, current_id); |
|
|
3241 | coord_tri.x = transform_from_geo_lon(pt1->c.x); |
3663 | coord_tri.x = transform_from_geo_lon(pt1->c.x); |
3242 | coord_tri.y = transform_from_geo_lat(pt1->c.y); |
3664 | coord_tri.y = transform_from_geo_lat(pt1->c.y); |
3243 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
3665 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
3244 | coord_tri.x = transform_from_geo_lon(pt2->c.x); |
3666 | coord_tri.x = transform_from_geo_lon(pt2->c.x); |
3245 | coord_tri.y = transform_from_geo_lat(pt2->c.y); |
3667 | coord_tri.y = transform_from_geo_lat(pt2->c.y); |
3246 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
3668 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
3247 | coord_tri.x = transform_from_geo_lon(pt3->c.x); |
3669 | coord_tri.x = transform_from_geo_lon(pt3->c.x); |
3248 | coord_tri.y = transform_from_geo_lat(pt3->c.y); |
3670 | coord_tri.y = transform_from_geo_lat(pt3->c.y); |
3249 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
3671 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
|
|
3672 | // now add dummy osm wayid |
|
|
3673 | item_bin_add_attr_longlong(item_bin_tri, attr_osm_wayid, current_id); |
3250 | |
3674 | |
|
|
3675 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
3676 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
3677 | // dump_itembin(item_bin_tri); |
|
|
3678 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
3679 | // DEBUG -- DEBUG -- DEBUG -- |
3251 | item_bin_write(item_bin_tri, osm->ways_with_coords); |
3680 | item_bin_write(item_bin_tri, osm->ways_with_coords); |
|
|
3681 | |
3252 | // make item and write it to ways file ------------------- |
3682 | // make item and write it to ways file ------------------- |
3253 | // make item and write it to ways file ------------------- |
3683 | // make item and write it to ways file ------------------- |
3254 | |
3684 | |
3255 | } |
3685 | } |
3256 | |
3686 | |
… | |
… | |
3278 | g_hash_table_destroy(point_map); |
3708 | g_hash_table_destroy(point_map); |
3279 | } |
3709 | } |
3280 | } |
3710 | } |
3281 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3711 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3282 | { |
3712 | { |
3283 | fprintf(stderr, "relation id=%lld\n", current_id); |
3713 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3284 | fprintf(stderr, "Got Exception 3!\n"); |
3714 | fprintf_(stderr, "Got Exception 3!\n"); |
3285 | exception = 1; |
3715 | exception = 1; |
3286 | } |
3716 | } |
3287 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3717 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3288 | { |
3718 | { |
3289 | fprintf(stderr, "relation id=%lld\n", current_id); |
3719 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3290 | fprintf(stderr, "Got segv Exception 3!\n"); |
3720 | fprintf_(stderr, "Got segv Exception 3!\n"); |
3291 | exception = 1; |
3721 | exception = 1; |
3292 | } |
3722 | } |
3293 | FINALLY |
3723 | FINALLY |
3294 | { |
3724 | { |
3295 | signal (SIGSEGV, SIG_DFL); |
3725 | signal (SIGSEGV, SIG_DFL); |
… | |
… | |
3305 | // p2tr_mesh_clear(rmesh->mesh); |
3735 | // p2tr_mesh_clear(rmesh->mesh); |
3306 | // --- maybe need this?? --- p2tr_mesh_unref(rmesh->mesh); |
3736 | // --- maybe need this?? --- p2tr_mesh_unref(rmesh->mesh); |
3307 | } |
3737 | } |
3308 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3738 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3309 | { |
3739 | { |
3310 | fprintf(stderr, "relation id=%lld\n", current_id); |
3740 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3311 | fprintf(stderr, "Got Exception 4!\n"); |
3741 | fprintf_(stderr, "Got Exception 4!\n"); |
3312 | exception = 1; |
3742 | exception = 1; |
3313 | } |
3743 | } |
3314 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3744 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3315 | { |
3745 | { |
3316 | fprintf(stderr, "relation id=%lld\n", current_id); |
3746 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3317 | fprintf(stderr, "Got segv Exception 4!\n"); |
3747 | fprintf_(stderr, "Got segv Exception 4!\n"); |
3318 | exception = 1; |
3748 | exception = 1; |
3319 | } |
3749 | } |
3320 | FINALLY |
3750 | FINALLY |
3321 | { |
3751 | { |
3322 | signal (SIGSEGV, SIG_DFL); |
3752 | signal (SIGSEGV, SIG_DFL); |
… | |
… | |
3330 | signal(SIGSEGV, catch_signal); |
3760 | signal(SIGSEGV, catch_signal); |
3331 | p2t_cdt_free(cdt); |
3761 | p2t_cdt_free(cdt); |
3332 | } |
3762 | } |
3333 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3763 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3334 | { |
3764 | { |
3335 | fprintf(stderr, "relation id=%lld\n", current_id); |
3765 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3336 | fprintf(stderr, "Got Exception 5!\n"); |
3766 | fprintf_(stderr, "Got Exception 5!\n"); |
3337 | exception = 1; |
3767 | exception = 1; |
3338 | } |
3768 | } |
3339 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3769 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3340 | { |
3770 | { |
3341 | fprintf(stderr, "relation id=%lld\n", current_id); |
3771 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3342 | fprintf(stderr, "Got segv Exception 5!\n"); |
3772 | fprintf_(stderr, "Got segv Exception 5!\n"); |
3343 | exception = 1; |
3773 | exception = 1; |
3344 | } |
3774 | } |
3345 | FINALLY |
3775 | FINALLY |
3346 | { |
3776 | { |
3347 | signal (SIGSEGV, SIG_DFL); |
3777 | signal (SIGSEGV, SIG_DFL); |
… | |
… | |
3537 | |
3967 | |
3538 | if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) |
3968 | if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) |
3539 | { |
3969 | { |
3540 | int found_town_rel = 0; |
3970 | int found_town_rel = 0; |
3541 | |
3971 | |
|
|
3972 | fprintf_(stderr, "town to relation 00: r:%lld\n", current_id); |
|
|
3973 | |
3542 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
3974 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
3543 | { |
3975 | { |
3544 | // save relation id for towns into DB |
3976 | // save relation id for towns into DB |
3545 | str = NULL; |
3977 | str = NULL; |
3546 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
3978 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
3547 | { |
3979 | { |
3548 | if (get_relation_member(str, &memb)) |
3980 | if (get_relation_member(str, &memb)) |
3549 | { |
3981 | { |
3550 | if (memb.type == 1) |
3982 | if (memb.type == 1) |
3551 | { |
3983 | { |
3552 | //fprintf(stderr, "role=%s\n", memb.role); |
3984 | fprintf_(stderr, "role=%s\n", memb.role); |
3553 | |
3985 | |
3554 | if (!strcmp(memb.role, "label")) |
3986 | if (!strcmp(memb.role, "label")) |
3555 | { |
3987 | { |
3556 | fprintf(stderr, "town to relation 1: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
3988 | fprintf_(stderr, "town to relation 1: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
3557 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
3989 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
3558 | // fprintf(stderr, "ret=%d\n", rr); |
3990 | // fprintf(stderr, "ret=%d\n", rr); |
3559 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
3991 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
3560 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
3992 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
3561 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
3993 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
… | |
… | |
3564 | sqlite3_reset(stmt_town_sel008); |
3996 | sqlite3_reset(stmt_town_sel008); |
3565 | //fprintf(stderr, "ret=%d\n", rr); |
3997 | //fprintf(stderr, "ret=%d\n", rr); |
3566 | |
3998 | |
3567 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
3999 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
3568 | |
4000 | |
|
|
4001 | lat_lon_c = get_first_coord_of_boundary(item_bin_2, &memb); |
|
|
4002 | if (lat_lon_c) |
|
|
4003 | { |
|
|
4004 | sqlite3_bind_double(stmt_town, 6, lat_lon_c->lat); |
|
|
4005 | sqlite3_bind_double(stmt_town, 7, lat_lon_c->lon); |
|
|
4006 | g_free(lat_lon_c); |
|
|
4007 | } |
|
|
4008 | |
3569 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
4009 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
3570 | sqlite3_bind_int(stmt_town, 2, 999); |
4010 | sqlite3_bind_int(stmt_town, 2, 999); |
3571 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
4011 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
3572 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
4012 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
3573 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
4013 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
… | |
… | |
3596 | { |
4036 | { |
3597 | if (get_relation_member(str, &memb)) |
4037 | if (get_relation_member(str, &memb)) |
3598 | { |
4038 | { |
3599 | if (memb.type == 1) |
4039 | if (memb.type == 1) |
3600 | { |
4040 | { |
3601 | //fprintf(stderr, "role=%s\n", memb.role); |
4041 | fprintf_(stderr, "role=%s\n", memb.role); |
3602 | |
4042 | |
3603 | if (!strcmp(memb.role, "admin_centre")) |
4043 | if (!strcmp(memb.role, "admin_centre")) |
3604 | { |
4044 | { |
3605 | fprintf(stderr, "town to relation 2: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
4045 | fprintf_(stderr, "town to relation 2: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
3606 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4046 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
3607 | // fprintf(stderr, "ret=%d\n", rr); |
4047 | // fprintf(stderr, "ret=%d\n", rr); |
3608 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
4048 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
3609 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
4049 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
3610 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
4050 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
… | |
… | |
3613 | sqlite3_reset(stmt_town_sel008); |
4053 | sqlite3_reset(stmt_town_sel008); |
3614 | //fprintf(stderr, "ret=%d\n", rr); |
4054 | //fprintf(stderr, "ret=%d\n", rr); |
3615 | |
4055 | |
3616 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
4056 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
3617 | |
4057 | |
|
|
4058 | lat_lon_c = get_first_coord_of_boundary(item_bin_2, &memb); |
|
|
4059 | if (lat_lon_c) |
|
|
4060 | { |
|
|
4061 | sqlite3_bind_double(stmt_town, 6, lat_lon_c->lat); |
|
|
4062 | sqlite3_bind_double(stmt_town, 7, lat_lon_c->lon); |
|
|
4063 | g_free(lat_lon_c); |
|
|
4064 | } |
|
|
4065 | |
3618 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
4066 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
3619 | sqlite3_bind_int(stmt_town, 2, 999); |
4067 | sqlite3_bind_int(stmt_town, 2, 999); |
3620 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
4068 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
3621 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
4069 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
3622 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
4070 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
… | |
… | |
3647 | { |
4095 | { |
3648 | //fprintf(stderr, "role=%s\n", memb.role); |
4096 | //fprintf(stderr, "role=%s\n", memb.role); |
3649 | |
4097 | |
3650 | if (!strcmp(memb.role, "admin_center")) |
4098 | if (!strcmp(memb.role, "admin_center")) |
3651 | { |
4099 | { |
3652 | fprintf(stderr, "town to relation 3: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
4100 | fprintf_(stderr, "town to relation 3: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
3653 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4101 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
3654 | // fprintf(stderr, "ret=%d\n", rr); |
4102 | // fprintf(stderr, "ret=%d\n", rr); |
3655 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
4103 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
3656 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
4104 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
3657 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
4105 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
… | |
… | |
3660 | sqlite3_reset(stmt_town_sel008); |
4108 | sqlite3_reset(stmt_town_sel008); |
3661 | //fprintf(stderr, "ret=%d\n", rr); |
4109 | //fprintf(stderr, "ret=%d\n", rr); |
3662 | |
4110 | |
3663 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
4111 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
3664 | |
4112 | |
|
|
4113 | lat_lon_c = get_first_coord_of_boundary(item_bin_2, &memb); |
|
|
4114 | if (lat_lon_c) |
|
|
4115 | { |
|
|
4116 | sqlite3_bind_double(stmt_town, 6, lat_lon_c->lat); |
|
|
4117 | sqlite3_bind_double(stmt_town, 7, lat_lon_c->lon); |
|
|
4118 | g_free(lat_lon_c); |
|
|
4119 | } |
|
|
4120 | |
3665 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
4121 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
3666 | sqlite3_bind_int(stmt_town, 2, 999); |
4122 | sqlite3_bind_int(stmt_town, 2, 999); |
3667 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
4123 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
3668 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
4124 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
3669 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
4125 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
… | |
… | |
3685 | |
4141 | |
3686 | |
4142 | |
3687 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
4143 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
3688 | { |
4144 | { |
3689 | // save relation id for towns into DB (use dummy town data) |
4145 | // save relation id for towns into DB (use dummy town data) |
3690 | fprintf(stderr, "town to relation(*): rel-name:%s admlevel:%d r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), admin_level, current_id, dummy_town_id); |
4146 | fprintf_(stderr, "town to relation(*): rel-name:%s admlevel:%d r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), admin_level, current_id, dummy_town_id); |
3691 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4147 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
3692 | // fprintf(stderr, "ret=%d\n", rr); |
4148 | // fprintf(stderr, "ret=%d\n", rr); |
3693 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
4149 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
3694 | sqlite3_bind_int64(stmt_town_sel008, 2, dummy_town_id); |
4150 | sqlite3_bind_int64(stmt_town_sel008, 2, dummy_town_id); |
3695 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
4151 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
3696 | sqlite3_step(stmt_town_sel008); |
4152 | sqlite3_step(stmt_town_sel008); |
3697 | //fprintf(stderr, "ret=%d\n", rr); |
4153 | //fprintf(stderr, "ret=%d\n", rr); |
3698 | sqlite3_reset(stmt_town_sel008); |
4154 | sqlite3_reset(stmt_town_sel008); |
3699 | //fprintf(stderr, "ret=%d\n", rr); |
4155 | //fprintf(stderr, "ret=%d\n", rr); |
3700 | |
4156 | |
3701 | |
4157 | int did_write_boundary_to_db = 0; |
3702 | str = NULL; |
4158 | str = NULL; |
3703 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
4159 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
3704 | { |
4160 | { |
3705 | if (get_relation_member(str, &memb)) |
4161 | if (get_relation_member(str, &memb)) |
3706 | { |
4162 | { |
3707 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) |
4163 | if ((memb.type == 2) && (strcmp(memb.role, "inner"))) |
3708 | { |
4164 | { |
3709 | // way-id is "memb.id" |
4165 | // way-id is "memb.id" |
3710 | // use the first nodes coords |
4166 | // use the first nodes coords |
3711 | get_lat_lon_way_first_node(memb.id, &node_coords); |
4167 | //get_lat_lon_way_first_node(memb.id, &node_coords); |
3712 | if (node_coords.valid == 1) |
4168 | //if (node_coords.valid == 1) |
3713 | { |
4169 | //{ |
3714 | sqlite3_bind_double(stmt_town, 6, node_coords.lat); |
4170 | // sqlite3_bind_double(stmt_town, 6, node_coords.lat); |
3715 | sqlite3_bind_double(stmt_town, 7, node_coords.lon); |
4171 | // sqlite3_bind_double(stmt_town, 7, node_coords.lon); |
3716 | } |
4172 | //} |
3717 | |
4173 | |
3718 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
4174 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
4175 | did_write_boundary_to_db = 1; |
3719 | |
4176 | |
3720 | break; |
4177 | break; |
3721 | } |
4178 | } |
3722 | } |
4179 | } |
3723 | } |
4180 | } |
|
|
4181 | |
|
|
4182 | lat_lon_c = get_first_coord_of_boundary(item_bin_2, &memb); |
|
|
4183 | if (lat_lon_c) |
|
|
4184 | { |
|
|
4185 | sqlite3_bind_double(stmt_town, 6, lat_lon_c->lat); |
|
|
4186 | sqlite3_bind_double(stmt_town, 7, lat_lon_c->lon); |
|
|
4187 | fprintf_(stderr, "town to relation(*):coords %f %f\n", lat_lon_c->lat, lat_lon_c->lon); |
|
|
4188 | g_free(lat_lon_c); |
|
|
4189 | } |
|
|
4190 | |
3724 | |
4191 | |
3725 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
4192 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
3726 | sqlite3_bind_int(stmt_town, 2, 999); |
4193 | sqlite3_bind_int(stmt_town, 2, 999); |
3727 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
4194 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
3728 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
4195 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
3729 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
4196 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
|
|
4197 | |
|
|
4198 | if (did_write_boundary_to_db == 1) |
|
|
4199 | { |
3730 | sqlite3_bind_int64(stmt_town, 8, current_id); |
4200 | sqlite3_bind_int64(stmt_town, 8, current_id); |
|
|
4201 | } |
|
|
4202 | else |
|
|
4203 | { |
|
|
4204 | // boundary not in DB |
|
|
4205 | // ----- what? i have no idea what to do here ----- |
|
|
4206 | } |
3731 | sqlite3_step(stmt_town); |
4207 | sqlite3_step(stmt_town); |
3732 | sqlite3_reset(stmt_town); |
4208 | sqlite3_reset(stmt_town); |
3733 | |
4209 | |
3734 | found_town_rel = 1; |
4210 | found_town_rel = 1; |
3735 | |
4211 | |
… | |
… | |
3749 | { |
4225 | { |
3750 | if (get_relation_member(str, &memb)) |
4226 | if (get_relation_member(str, &memb)) |
3751 | { |
4227 | { |
3752 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) |
4228 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) |
3753 | { |
4229 | { |
3754 | fprintf(stderr, "town to relation(+): rel-name:%s admlevel:%d r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), admin_level, current_id, 9797979797); |
4230 | fprintf_(stderr, "town to relation(+): rel-name:%s admlevel:%d r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), admin_level, current_id, 9797979797); |
3755 | |
4231 | |
3756 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
4232 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
3757 | break; |
4233 | break; |
3758 | } |
4234 | } |
3759 | } |
4235 | } |
… | |
… | |
3783 | item_bin_write(item_bin_2, osm->turn_restrictions); |
4259 | item_bin_write(item_bin_2, osm->turn_restrictions); |
3784 | } |
4260 | } |
3785 | } |
4261 | } |
3786 | |
4262 | |
3787 | |
4263 | |
|
|
4264 | // #define DEBUG_CORRECT_BOUNDARY_REF_POINT 1 |
|
|
4265 | |
3788 | void correct_boundary_ref_point(GList *bl) |
4266 | void correct_boundary_ref_point(GList *bl) |
|
|
4267 | { |
|
|
4268 | long long rid; |
|
|
4269 | int retval; |
|
|
4270 | int rc = 0; |
|
|
4271 | int commit_after = 20000; |
|
|
4272 | int count = 0; |
|
|
4273 | int admin_l = 99; |
|
|
4274 | double lat, lon; |
|
|
4275 | struct coord c; |
|
|
4276 | GList *l = NULL; |
|
|
4277 | GList *l2 = NULL; |
|
|
4278 | GList *match = NULL; |
|
|
4279 | struct boundary *b = NULL; |
|
|
4280 | int admin_l_boundary; |
|
|
4281 | int max_admin_l; |
|
|
4282 | |
|
|
4283 | //fprintf(stderr, "BRP:001\n"); |
|
|
4284 | |
|
|
4285 | // loop thru all the boundaries |
|
|
4286 | do |
|
|
4287 | { |
|
|
4288 | |
|
|
4289 | //fprintf(stderr, "BRP:002\n"); |
|
|
4290 | |
|
|
4291 | rc = sqlite3_step(stmt_bd_002); |
|
|
4292 | |
|
|
4293 | //fprintf(stderr, "BRP:003\n"); |
|
|
4294 | |
|
|
4295 | switch (rc) |
|
|
4296 | { |
|
|
4297 | case SQLITE_DONE: |
|
|
4298 | break; |
|
|
4299 | case SQLITE_ROW: |
|
|
4300 | |
|
|
4301 | //fprintf(stderr, "BRP:004\n"); |
|
|
4302 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
|
|
4303 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
|
|
4304 | //fprintf(stderr, "BRP:005\n"); |
|
|
4305 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
|
|
4306 | //fprintf(stderr, "BRP:006\n"); |
|
|
4307 | lat = sqlite3_column_double(stmt_bd_002, 2); |
|
|
4308 | //fprintf(stderr, "BRP:007\n"); |
|
|
4309 | lon = sqlite3_column_double(stmt_bd_002, 3); |
|
|
4310 | //fprintf(stderr, "BRP:008\n"); |
|
|
4311 | c.x = transform_from_geo_lon(lon); |
|
|
4312 | //fprintf(stderr, "BRP:009\n"); |
|
|
4313 | c.y = transform_from_geo_lat(lat); |
|
|
4314 | //fprintf(stderr, "BRP:010\n"); |
|
|
4315 | |
|
|
4316 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4317 | fprintf(stderr, "correct_boundary_ref_point: relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
|
|
4318 | #endif |
|
|
4319 | |
|
|
4320 | // find this boundary in list |
|
|
4321 | l = bl; |
|
|
4322 | match = NULL; |
|
|
4323 | |
|
|
4324 | //fprintf(stderr, "BRP:011\n"); |
|
|
4325 | |
|
|
4326 | while (l) |
|
|
4327 | { |
|
|
4328 | // fprintf(stderr, "BRP:012 l=%p l->data=%p\n", l, l->data); |
|
|
4329 | |
|
|
4330 | b = l->data; |
|
|
4331 | |
|
|
4332 | // fprintf(stderr, "BRP:012a b=%p\n", b); |
|
|
4333 | |
|
|
4334 | if (b) |
|
|
4335 | { |
|
|
4336 | // fprintf(stderr, "BRP:012b\n"); |
|
|
4337 | if (b->ib) |
|
|
4338 | { |
|
|
4339 | // fprintf(stderr, "BRP:012c\n"); |
|
|
4340 | |
|
|
4341 | // fprintf(stderr, "BRP:013a %p\n", b); |
|
|
4342 | // fprintf(stderr, "BRP:013b %p\n", b->ib); |
|
|
4343 | // fprintf(stderr, "BRP:013c %lld\n", (long long)rid); |
|
|
4344 | |
|
|
4345 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4346 | fprintf(stderr, "correct_boundary_ref_point: %lld %lld\n", item_bin_get_relationid(b->ib), rid); |
|
|
4347 | #endif |
|
|
4348 | if (item_bin_get_relationid(b->ib) == rid) |
|
|
4349 | { |
|
|
4350 | // fprintf(stderr, "BRP:014\n"); |
|
|
4351 | match = l; |
|
|
4352 | break; |
|
|
4353 | } |
|
|
4354 | // fprintf(stderr, "BRP:015\n"); |
|
|
4355 | |
|
|
4356 | } |
|
|
4357 | } |
|
|
4358 | |
|
|
4359 | l = g_list_next(l); |
|
|
4360 | |
|
|
4361 | // fprintf(stderr, "BRP:016\n"); |
|
|
4362 | |
|
|
4363 | } |
|
|
4364 | |
|
|
4365 | //fprintf(stderr, "BRP:017\n"); |
|
|
4366 | |
|
|
4367 | if (match) |
|
|
4368 | { |
|
|
4369 | //fprintf(stderr, "BRP:018\n"); |
|
|
4370 | |
|
|
4371 | b = match->data; |
|
|
4372 | |
|
|
4373 | if (b) |
|
|
4374 | { |
|
|
4375 | |
|
|
4376 | //fprintf(stderr, "BRP:019\n"); |
|
|
4377 | |
|
|
4378 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4379 | fprintf(stderr, "correct_boundary_ref_point: relid:%lld(%d) parentid:%lld(%d)\n", rid, admin_l, item_bin_get_relationid(b->ib), max_admin_l); |
|
|
4380 | #endif |
|
|
4381 | // ------------------------------------------- |
|
|
4382 | /* |
|
|
4383 | GList *sl; |
|
|
4384 | sl = b->sorted_segments; |
|
|
4385 | if (sl) |
|
|
4386 | { |
|
|
4387 | struct geom_poly_segment *gs = sl->data; |
|
|
4388 | struct coord *c2 = gs->first; |
|
|
4389 | fprintf(stderr, "1a c=%d y=%d\n", c2->x, c2->y); |
|
|
4390 | } |
|
|
4391 | */ |
|
|
4392 | // ------------------------------------------- |
|
|
4393 | |
|
|
4394 | if (find_correct_point_in_boundary(match, &lat, &lon) == 1) |
|
|
4395 | { |
|
|
4396 | |
|
|
4397 | //fprintf(stderr, "BRP:020\n"); |
|
|
4398 | sqlite3_bind_double(stmt_bd_004, 1, lat); |
|
|
4399 | //fprintf(stderr, "BRP:021\n"); |
|
|
4400 | sqlite3_bind_double(stmt_bd_004, 2, lon); |
|
|
4401 | //fprintf(stderr, "BRP:022\n"); |
|
|
4402 | sqlite3_bind_int64(stmt_bd_004, 3, rid); |
|
|
4403 | //fprintf(stderr, "BRP:023\n"); |
|
|
4404 | sqlite3_step(stmt_bd_004); |
|
|
4405 | //fprintf(stderr, "BRP:024\n"); |
|
|
4406 | sqlite3_reset(stmt_bd_004); |
|
|
4407 | //fprintf(stderr, "BRP:025\n"); |
|
|
4408 | } |
|
|
4409 | |
|
|
4410 | //fprintf(stderr, "BRP:026\n"); |
|
|
4411 | |
|
|
4412 | } |
|
|
4413 | |
|
|
4414 | } |
|
|
4415 | |
|
|
4416 | //fprintf(stderr, "BRP:027\n"); |
|
|
4417 | |
|
|
4418 | if (count == 0) |
|
|
4419 | { |
|
|
4420 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
4421 | } |
|
|
4422 | count++; |
|
|
4423 | |
|
|
4424 | //fprintf(stderr, "BRP:028\n"); |
|
|
4425 | |
|
|
4426 | if (count > commit_after) |
|
|
4427 | { |
|
|
4428 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4429 | count = 0; |
|
|
4430 | } |
|
|
4431 | |
|
|
4432 | //fprintf(stderr, "BRP:029\n"); |
|
|
4433 | |
|
|
4434 | break; |
|
|
4435 | default: |
|
|
4436 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
4437 | break; |
|
|
4438 | } |
|
|
4439 | } |
|
|
4440 | while (rc == SQLITE_ROW); |
|
|
4441 | |
|
|
4442 | //fprintf(stderr, "BRP:091\n"); |
|
|
4443 | |
|
|
4444 | sqlite3_reset(stmt_bd_002); |
|
|
4445 | |
|
|
4446 | //fprintf(stderr, "BRP:092\n"); |
|
|
4447 | |
|
|
4448 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4449 | |
|
|
4450 | //fprintf(stderr, "BRP:093\n"); |
|
|
4451 | |
|
|
4452 | } |
|
|
4453 | |
|
|
4454 | |
|
|
4455 | int find_correct_point_in_boundary(GList *bl, double* lat, double* lon) |
|
|
4456 | { |
|
|
4457 | double lat2, lon2; |
|
|
4458 | struct coord c; |
|
|
4459 | struct boundary *b; |
|
|
4460 | GList *matches; |
|
|
4461 | double lat_d = 0.00006; |
|
|
4462 | double lon_d = 0.00006; |
|
|
4463 | |
|
|
4464 | lat2 = *lat; |
|
|
4465 | lon2 = *lon; |
|
|
4466 | |
|
|
4467 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
4468 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
4469 | |
|
|
4470 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4471 | fprintf(stderr, "2 c=%d y=%d\n", c.x, c.y); |
|
|
4472 | #endif |
|
|
4473 | |
|
|
4474 | matches = NULL; |
|
|
4475 | matches = boundary_find_matches_single(bl, &c); |
|
|
4476 | if (g_list_length(matches) > 0) |
|
|
4477 | { |
|
|
4478 | *lon = lon2 + lon_d; |
|
|
4479 | *lat = lat2 + lat_d; |
|
|
4480 | return 1; |
|
|
4481 | } |
|
|
4482 | |
|
|
4483 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
4484 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
4485 | |
|
|
4486 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4487 | fprintf(stderr, "3 c=%d y=%d\n", c.x, c.y); |
|
|
4488 | #endif |
|
|
4489 | |
|
|
4490 | matches = NULL; |
|
|
4491 | matches = boundary_find_matches_single(bl, &c); |
|
|
4492 | if (g_list_length(matches) > 0) |
|
|
4493 | { |
|
|
4494 | *lon = lon2 + lon_d; |
|
|
4495 | *lat = lat2 - lat_d; |
|
|
4496 | return 1; |
|
|
4497 | } |
|
|
4498 | |
|
|
4499 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
4500 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
4501 | |
|
|
4502 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4503 | fprintf(stderr, "4 c=%d y=%d\n", c.x, c.y); |
|
|
4504 | #endif |
|
|
4505 | |
|
|
4506 | matches = NULL; |
|
|
4507 | matches = boundary_find_matches_single(bl, &c); |
|
|
4508 | if (g_list_length(matches) > 0) |
|
|
4509 | { |
|
|
4510 | *lon = lon2 - lon_d; |
|
|
4511 | *lat = lat2 + lat_d; |
|
|
4512 | return 1; |
|
|
4513 | } |
|
|
4514 | |
|
|
4515 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
4516 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
4517 | |
|
|
4518 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4519 | fprintf(stderr, "5 c=%d y=%d\n", c.x, c.y); |
|
|
4520 | #endif |
|
|
4521 | |
|
|
4522 | matches = NULL; |
|
|
4523 | matches = boundary_find_matches_single(bl, &c); |
|
|
4524 | if (g_list_length(matches) > 0) |
|
|
4525 | { |
|
|
4526 | *lon = lon2 - lon_d; |
|
|
4527 | *lat = lat2 - lat_d; |
|
|
4528 | return 1; |
|
|
4529 | } |
|
|
4530 | |
|
|
4531 | |
|
|
4532 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
4533 | c.y = transform_from_geo_lat(lat2); |
|
|
4534 | |
|
|
4535 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4536 | fprintf(stderr, "6 c=%d y=%d\n", c.x, c.y); |
|
|
4537 | #endif |
|
|
4538 | |
|
|
4539 | matches = NULL; |
|
|
4540 | matches = boundary_find_matches_single(bl, &c); |
|
|
4541 | if (g_list_length(matches) > 0) |
|
|
4542 | { |
|
|
4543 | *lon = lon2 + lon_d; |
|
|
4544 | *lat = lat2; |
|
|
4545 | return 1; |
|
|
4546 | } |
|
|
4547 | |
|
|
4548 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
4549 | c.y = transform_from_geo_lat(lat2); |
|
|
4550 | |
|
|
4551 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4552 | fprintf(stderr, "7 c=%d y=%d\n", c.x, c.y); |
|
|
4553 | #endif |
|
|
4554 | |
|
|
4555 | matches = NULL; |
|
|
4556 | matches = boundary_find_matches_single(bl, &c); |
|
|
4557 | if (g_list_length(matches) > 0) |
|
|
4558 | { |
|
|
4559 | *lon = lon2 - lon_d; |
|
|
4560 | *lat = lat2; |
|
|
4561 | return 1; |
|
|
4562 | } |
|
|
4563 | |
|
|
4564 | c.x = transform_from_geo_lon(lon2); |
|
|
4565 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
4566 | |
|
|
4567 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4568 | fprintf(stderr, "8 c=%d y=%d\n", c.x, c.y); |
|
|
4569 | #endif |
|
|
4570 | |
|
|
4571 | matches = NULL; |
|
|
4572 | matches = boundary_find_matches_single(bl, &c); |
|
|
4573 | if (g_list_length(matches) > 0) |
|
|
4574 | { |
|
|
4575 | *lon = lon2; |
|
|
4576 | *lat = lat2 + lat_d; |
|
|
4577 | return 1; |
|
|
4578 | } |
|
|
4579 | |
|
|
4580 | |
|
|
4581 | c.x = transform_from_geo_lon(lon2); |
|
|
4582 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
4583 | |
|
|
4584 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
|
|
4585 | fprintf(stderr, "9 c=%d y=%d\n", c.x, c.y); |
|
|
4586 | #endif |
|
|
4587 | |
|
|
4588 | matches = NULL; |
|
|
4589 | matches = boundary_find_matches_single(bl, &c); |
|
|
4590 | if (g_list_length(matches) > 0) |
|
|
4591 | { |
|
|
4592 | *lon = lon2; |
|
|
4593 | *lat = lat2 - lat_d; |
|
|
4594 | return 1; |
|
|
4595 | } |
|
|
4596 | |
|
|
4597 | return 0; |
|
|
4598 | |
|
|
4599 | } |
|
|
4600 | |
|
|
4601 | void build_boundary_tree(GList *bl, GList *man_bl) |
3789 | { |
4602 | { |
3790 | long long rid; |
4603 | long long rid; |
3791 | int retval; |
4604 | int retval; |
3792 | int rc = 0; |
4605 | int rc = 0; |
3793 | int commit_after = 20000; |
4606 | int commit_after = 20000; |
… | |
… | |
3799 | GList *l2 = NULL; |
4612 | GList *l2 = NULL; |
3800 | GList *match = NULL; |
4613 | GList *match = NULL; |
3801 | struct boundary *b; |
4614 | struct boundary *b; |
3802 | int admin_l_boundary; |
4615 | int admin_l_boundary; |
3803 | int max_admin_l; |
4616 | int max_admin_l; |
|
|
4617 | long long b_count = 0; |
|
|
4618 | long long b_max_count = 0; |
|
|
4619 | |
|
|
4620 | |
|
|
4621 | sqlite3_stmt *stmt_mm_1; |
|
|
4622 | int retval8 = sqlite3_prepare_v2(sql_handle, "select count(*) from boundary where done = 0;", -1, &stmt_mm_1, NULL); |
|
|
4623 | fprintf_(stderr, "prep:%d\n", retval8); |
|
|
4624 | sqlite3_step(stmt_mm_1); |
|
|
4625 | b_max_count = sqlite3_column_int64(stmt_mm_1, 0); |
|
|
4626 | fprintf_(stderr, "b_max_count:%lld\n", b_max_count); |
|
|
4627 | sqlite3_reset(stmt_mm_1); |
|
|
4628 | sqlite3_finalize(stmt_mm_1); |
|
|
4629 | |
3804 | |
4630 | |
3805 | // loop thru all the boundaries |
4631 | // loop thru all the boundaries |
3806 | do |
4632 | do |
3807 | { |
4633 | { |
3808 | rc = sqlite3_step(stmt_bd_002); |
4634 | rc = sqlite3_step(stmt_bd_002); |
… | |
… | |
3818 | lat = sqlite3_column_double(stmt_bd_002, 2); |
4644 | lat = sqlite3_column_double(stmt_bd_002, 2); |
3819 | lon = sqlite3_column_double(stmt_bd_002, 3); |
4645 | lon = sqlite3_column_double(stmt_bd_002, 3); |
3820 | c.x = transform_from_geo_lon(lon); |
4646 | c.x = transform_from_geo_lon(lon); |
3821 | c.y = transform_from_geo_lat(lat); |
4647 | c.y = transform_from_geo_lat(lat); |
3822 | |
4648 | |
3823 | //fprintf(stderr, "correct_boundary_ref_point: relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
4649 | b_count++; |
3824 | |
4650 | if ((b_count % 100) == 0) |
3825 | // find this boundary in list |
|
|
3826 | l = bl; |
|
|
3827 | match = NULL; |
|
|
3828 | while (l) |
|
|
3829 | { |
4651 | { |
3830 | b = l->data; |
4652 | fprintf_(stderr, "rel:%lld/%lld\n", b_count, b_max_count); |
3831 | //fprintf(stderr, "correct_boundary_ref_point: %lld %lld\n", item_bin_get_relationid(b->ib), rid); |
4653 | // fprintf(stderr, "relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
3832 | if (item_bin_get_relationid(b->ib) == rid) |
|
|
3833 | { |
|
|
3834 | match = l; |
|
|
3835 | break; |
|
|
3836 | } |
|
|
3837 | l = g_list_next(l); |
|
|
3838 | } |
4654 | } |
3839 | |
|
|
3840 | if (match) |
|
|
3841 | { |
|
|
3842 | b = match->data; |
|
|
3843 | //fprintf(stderr, "correct_boundary_ref_point: relid:%lld(%d) parentid:%lld(%d)\n", rid, admin_l, item_bin_get_relationid(b->ib), max_admin_l); |
|
|
3844 | |
|
|
3845 | // ------------------------------------------- |
|
|
3846 | /* |
|
|
3847 | GList *sl; |
|
|
3848 | sl = b->sorted_segments; |
|
|
3849 | if (sl) |
|
|
3850 | { |
|
|
3851 | struct geom_poly_segment *gs = sl->data; |
|
|
3852 | struct coord *c2 = gs->first; |
|
|
3853 | fprintf(stderr, "1a c=%d y=%d\n", c2->x, c2->y); |
|
|
3854 | } |
|
|
3855 | */ |
|
|
3856 | // ------------------------------------------- |
|
|
3857 | |
|
|
3858 | if (find_correct_point_in_boundary(match, &lat, &lon) == 1) |
|
|
3859 | { |
|
|
3860 | sqlite3_bind_double(stmt_bd_004, 1, lat); |
|
|
3861 | sqlite3_bind_double(stmt_bd_004, 2, lon); |
|
|
3862 | sqlite3_bind_int64(stmt_bd_004, 3, rid); |
|
|
3863 | sqlite3_step(stmt_bd_004); |
|
|
3864 | sqlite3_reset(stmt_bd_004); |
|
|
3865 | } |
|
|
3866 | } |
|
|
3867 | |
|
|
3868 | |
|
|
3869 | if (count == 0) |
|
|
3870 | { |
|
|
3871 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3872 | } |
|
|
3873 | count++; |
|
|
3874 | |
|
|
3875 | if (count > commit_after) |
|
|
3876 | { |
|
|
3877 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3878 | count = 0; |
|
|
3879 | } |
|
|
3880 | |
|
|
3881 | break; |
|
|
3882 | default: |
|
|
3883 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
3884 | break; |
|
|
3885 | } |
|
|
3886 | } |
|
|
3887 | while (rc == SQLITE_ROW); |
|
|
3888 | sqlite3_reset(stmt_bd_002); |
|
|
3889 | |
|
|
3890 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3891 | |
|
|
3892 | } |
|
|
3893 | |
|
|
3894 | |
|
|
3895 | int find_correct_point_in_boundary(GList *bl, double* lat, double* lon) |
|
|
3896 | { |
|
|
3897 | double lat2, lon2; |
|
|
3898 | struct coord c; |
|
|
3899 | struct boundary *b; |
|
|
3900 | GList *matches; |
|
|
3901 | double lat_d = 0.00006; |
|
|
3902 | double lon_d = 0.00006; |
|
|
3903 | |
|
|
3904 | lat2 = *lat; |
|
|
3905 | lon2 = *lon; |
|
|
3906 | |
|
|
3907 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
3908 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
3909 | //fprintf(stderr, "2 c=%d y=%d\n", c.x, c.y); |
|
|
3910 | matches = NULL; |
|
|
3911 | matches = boundary_find_matches_single(bl, &c); |
|
|
3912 | if (g_list_length(matches) > 0) |
|
|
3913 | { |
|
|
3914 | *lon = lon2 + lon_d; |
|
|
3915 | *lat = lat2 + lat_d; |
|
|
3916 | return 1; |
|
|
3917 | } |
|
|
3918 | |
|
|
3919 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
3920 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
3921 | //fprintf(stderr, "3 c=%d y=%d\n", c.x, c.y); |
|
|
3922 | matches = NULL; |
|
|
3923 | matches = boundary_find_matches_single(bl, &c); |
|
|
3924 | if (g_list_length(matches) > 0) |
|
|
3925 | { |
|
|
3926 | *lon = lon2 + lon_d; |
|
|
3927 | *lat = lat2 - lat_d; |
|
|
3928 | return 1; |
|
|
3929 | } |
|
|
3930 | |
|
|
3931 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
3932 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
3933 | //fprintf(stderr, "4 c=%d y=%d\n", c.x, c.y); |
|
|
3934 | matches = NULL; |
|
|
3935 | matches = boundary_find_matches_single(bl, &c); |
|
|
3936 | if (g_list_length(matches) > 0) |
|
|
3937 | { |
|
|
3938 | *lon = lon2 - lon_d; |
|
|
3939 | *lat = lat2 + lat_d; |
|
|
3940 | return 1; |
|
|
3941 | } |
|
|
3942 | |
|
|
3943 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
3944 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
3945 | //fprintf(stderr, "5 c=%d y=%d\n", c.x, c.y); |
|
|
3946 | matches = NULL; |
|
|
3947 | matches = boundary_find_matches_single(bl, &c); |
|
|
3948 | if (g_list_length(matches) > 0) |
|
|
3949 | { |
|
|
3950 | *lon = lon2 - lon_d; |
|
|
3951 | *lat = lat2 - lat_d; |
|
|
3952 | return 1; |
|
|
3953 | } |
|
|
3954 | |
|
|
3955 | |
|
|
3956 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
3957 | c.y = transform_from_geo_lat(lat2); |
|
|
3958 | //fprintf(stderr, "6 c=%d y=%d\n", c.x, c.y); |
|
|
3959 | matches = NULL; |
|
|
3960 | matches = boundary_find_matches_single(bl, &c); |
|
|
3961 | if (g_list_length(matches) > 0) |
|
|
3962 | { |
|
|
3963 | *lon = lon2 - lon_d; |
|
|
3964 | *lat = lat2; |
|
|
3965 | return 1; |
|
|
3966 | } |
|
|
3967 | |
|
|
3968 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
3969 | c.y = transform_from_geo_lat(lat2); |
|
|
3970 | //fprintf(stderr, "7 c=%d y=%d\n", c.x, c.y); |
|
|
3971 | matches = NULL; |
|
|
3972 | matches = boundary_find_matches_single(bl, &c); |
|
|
3973 | if (g_list_length(matches) > 0) |
|
|
3974 | { |
|
|
3975 | *lon = lon2 - lon_d; |
|
|
3976 | *lat = lat2; |
|
|
3977 | return 1; |
|
|
3978 | } |
|
|
3979 | |
|
|
3980 | c.x = transform_from_geo_lon(lon2); |
|
|
3981 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
3982 | //fprintf(stderr, "8 c=%d y=%d\n", c.x, c.y); |
|
|
3983 | matches = NULL; |
|
|
3984 | matches = boundary_find_matches_single(bl, &c); |
|
|
3985 | if (g_list_length(matches) > 0) |
|
|
3986 | { |
|
|
3987 | *lon = lon2; |
|
|
3988 | *lat = lat2 + lat_d; |
|
|
3989 | return 1; |
|
|
3990 | } |
|
|
3991 | |
|
|
3992 | |
|
|
3993 | c.x = transform_from_geo_lon(lon2); |
|
|
3994 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
3995 | //fprintf(stderr, "9 c=%d y=%d\n", c.x, c.y); |
|
|
3996 | matches = NULL; |
|
|
3997 | matches = boundary_find_matches_single(bl, &c); |
|
|
3998 | if (g_list_length(matches) > 0) |
|
|
3999 | { |
|
|
4000 | *lon = lon2; |
|
|
4001 | *lat = lat2 - lat_d; |
|
|
4002 | return 1; |
|
|
4003 | } |
|
|
4004 | |
|
|
4005 | return 0; |
|
|
4006 | |
|
|
4007 | } |
|
|
4008 | |
|
|
4009 | void build_boundary_tree(GList *bl) |
|
|
4010 | { |
|
|
4011 | long long rid; |
|
|
4012 | int retval; |
|
|
4013 | int rc = 0; |
|
|
4014 | int commit_after = 20000; |
|
|
4015 | int count = 0; |
|
|
4016 | int admin_l = 99; |
|
|
4017 | double lat, lon; |
|
|
4018 | struct coord c; |
|
|
4019 | GList *l = NULL; |
|
|
4020 | GList *l2 = NULL; |
|
|
4021 | GList *match = NULL; |
|
|
4022 | struct boundary *b; |
|
|
4023 | int admin_l_boundary; |
|
|
4024 | int max_admin_l; |
|
|
4025 | |
|
|
4026 | // loop thru all the boundaries |
|
|
4027 | do |
|
|
4028 | { |
|
|
4029 | rc = sqlite3_step(stmt_bd_002); |
|
|
4030 | switch (rc) |
|
|
4031 | { |
|
|
4032 | case SQLITE_DONE: |
|
|
4033 | break; |
|
|
4034 | case SQLITE_ROW: |
|
|
4035 | |
|
|
4036 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
|
|
4037 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
|
|
4038 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
|
|
4039 | lat = sqlite3_column_double(stmt_bd_002, 2); |
|
|
4040 | lon = sqlite3_column_double(stmt_bd_002, 3); |
|
|
4041 | c.x = transform_from_geo_lon(lon); |
|
|
4042 | c.y = transform_from_geo_lat(lat); |
|
|
4043 | |
|
|
4044 | //fprintf(stderr, "relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
|
|
4045 | |
4655 | |
4046 | max_admin_l = 0; |
4656 | max_admin_l = 0; |
4047 | l2 = boundary_find_matches_level(bl, &c, 0, (admin_l - 1)); |
4657 | l2 = boundary_find_matches_level(bl, &c, 0, (admin_l - 1)); |
4048 | l = l2; |
4658 | l = l2; |
4049 | match = NULL; |
4659 | match = NULL; |
… | |
… | |
4104 | fprintf(stderr, "SQL Error: %d\n", rc); |
4714 | fprintf(stderr, "SQL Error: %d\n", rc); |
4105 | break; |
4715 | break; |
4106 | } |
4716 | } |
4107 | } |
4717 | } |
4108 | while (rc == SQLITE_ROW); |
4718 | while (rc == SQLITE_ROW); |
|
|
4719 | |
4109 | sqlite3_reset(stmt_bd_002); |
4720 | sqlite3_reset(stmt_bd_002); |
4110 | |
4721 | |
4111 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4722 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4723 | |
|
|
4724 | |
|
|
4725 | // ------- enter manual countries into boundary DB ---------- |
|
|
4726 | GList *bl2 = man_bl; |
|
|
4727 | struct boundary_manual *bb3; |
|
|
4728 | |
|
|
4729 | struct country_table3 |
|
|
4730 | { |
|
|
4731 | int countryid; |
|
|
4732 | char *names; |
|
|
4733 | char *admin_levels; |
|
|
4734 | FILE *file; |
|
|
4735 | int size; |
|
|
4736 | struct rect r; |
|
|
4737 | }; |
|
|
4738 | |
|
|
4739 | |
|
|
4740 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
4741 | while (bl2) |
|
|
4742 | { |
|
|
4743 | bb3 = bl2->data; |
|
|
4744 | if (bb3) |
|
|
4745 | { |
|
|
4746 | struct country_table3* cc3 = bb3->country; |
|
|
4747 | sqlite3_bind_int64(stmt_bd_001, 1, bb3->town_id); // dummy id |
|
|
4748 | sqlite3_bind_int(stmt_bd_001, 2, 2); // admin level |
|
|
4749 | sqlite3_bind_text(stmt_bd_001, 5, cc3->names, -1, SQLITE_STATIC); // name |
|
|
4750 | sqlite3_step(stmt_bd_001); |
|
|
4751 | sqlite3_reset(stmt_bd_001); |
|
|
4752 | } |
|
|
4753 | bl2 = g_list_next(bl2); |
|
|
4754 | } |
|
|
4755 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4756 | count = 0; |
|
|
4757 | |
|
|
4758 | |
|
|
4759 | // ------- now assign all the left overs towns/boundaries to countries ---------- |
|
|
4760 | long long dummy_town_id2 = 0; |
|
|
4761 | count = 0; |
|
|
4762 | admin_l = 99; |
|
|
4763 | rc = 0; |
|
|
4764 | |
|
|
4765 | // loop thru all the boundaries |
|
|
4766 | do |
|
|
4767 | { |
|
|
4768 | rc = sqlite3_step(stmt_bd_002); |
|
|
4769 | switch (rc) |
|
|
4770 | { |
|
|
4771 | case SQLITE_DONE: |
|
|
4772 | break; |
|
|
4773 | case SQLITE_ROW: |
|
|
4774 | |
|
|
4775 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
|
|
4776 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
|
|
4777 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
|
|
4778 | lat = sqlite3_column_double(stmt_bd_002, 2); |
|
|
4779 | lon = sqlite3_column_double(stmt_bd_002, 3); |
|
|
4780 | c.x = transform_from_geo_lon(lon); |
|
|
4781 | c.y = transform_from_geo_lat(lat); |
|
|
4782 | |
|
|
4783 | //fprintf(stderr, "relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
|
|
4784 | if (admin_l > 2) |
|
|
4785 | { |
|
|
4786 | |
|
|
4787 | // check if c is inside manual country border |
|
|
4788 | dummy_town_id2 = osm_process_street_by_manual_country_borders(man_bl, &c); |
|
|
4789 | |
|
|
4790 | if (dummy_town_id2 != -1) |
|
|
4791 | { |
|
|
4792 | sqlite3_bind_int64(stmt_bd_003, 1, dummy_town_id2); // parent rel_id |
|
|
4793 | sqlite3_bind_int64(stmt_bd_003, 2, rid); // rel_id |
|
|
4794 | sqlite3_step(stmt_bd_003); |
|
|
4795 | sqlite3_reset(stmt_bd_003); |
|
|
4796 | } |
|
|
4797 | |
|
|
4798 | |
|
|
4799 | if (count == 0) |
|
|
4800 | { |
|
|
4801 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
4802 | } |
|
|
4803 | count++; |
|
|
4804 | |
|
|
4805 | if (count > commit_after) |
|
|
4806 | { |
|
|
4807 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4808 | count = 0; |
|
|
4809 | } |
|
|
4810 | |
|
|
4811 | } |
|
|
4812 | break; |
|
|
4813 | default: |
|
|
4814 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
4815 | break; |
|
|
4816 | } |
|
|
4817 | } |
|
|
4818 | while (rc == SQLITE_ROW); |
|
|
4819 | sqlite3_reset(stmt_bd_002); |
|
|
4820 | |
|
|
4821 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4822 | |
|
|
4823 | } |
|
|
4824 | |
|
|
4825 | struct node_lat_lon* get_first_coord_of_boundary(struct item_bin *item_bin_3, struct relation_member *memb) |
|
|
4826 | { |
|
|
4827 | char *str = NULL; |
|
|
4828 | struct node_lat_lon* node_coords=g_new0(struct node_lat_lon, 1); |
|
|
4829 | |
|
|
4830 | while ((str = item_bin_get_attr(item_bin_3, attr_osm_member, str))) |
|
|
4831 | { |
|
|
4832 | if (get_relation_member(str, memb)) |
|
|
4833 | { |
|
|
4834 | if (memb->type == 2) |
|
|
4835 | { |
|
|
4836 | // way-id is "memb.id" |
|
|
4837 | // use the first nodes coords |
|
|
4838 | get_lat_lon_way_first_node(memb->id, node_coords); |
|
|
4839 | if (node_coords->valid == 1) |
|
|
4840 | { |
|
|
4841 | return node_coords; |
|
|
4842 | } |
|
|
4843 | break; |
|
|
4844 | } |
|
|
4845 | } |
|
|
4846 | } |
|
|
4847 | |
|
|
4848 | return NULL; |
4112 | } |
4849 | } |
4113 | |
4850 | |
4114 | void add_boundary_to_db(long long current_id, int admin_level, struct item_bin *item_bin_3, struct relation_member *memb) |
4851 | void add_boundary_to_db(long long current_id, int admin_level, struct item_bin *item_bin_3, struct relation_member *memb) |
4115 | { |
4852 | { |
4116 | char *str = NULL; |
4853 | char *str = NULL; |
4117 | struct node_lat_lon node_coords; |
4854 | struct node_lat_lon node_coords; |
|
|
4855 | |
|
|
4856 | // fprintf(stderr, "add_boundary_to_db:bid:%lld admin_level:%d\n", current_id, admin_level); |
4118 | |
4857 | |
4119 | sqlite3_bind_int64(stmt_bd_001, 1, current_id); |
4858 | sqlite3_bind_int64(stmt_bd_001, 1, current_id); |
4120 | |
4859 | |
4121 | if (admin_level < 2) |
4860 | if (admin_level < 2) |
4122 | { |
4861 | { |
… | |
… | |
4299 | } |
5038 | } |
4300 | |
5039 | |
4301 | // fprintf(stderr, "(2)in=%s sub=%s\n", in, sub); |
5040 | // fprintf(stderr, "(2)in=%s sub=%s\n", in, sub); |
4302 | return sub; |
5041 | return sub; |
4303 | } |
5042 | } |
|
|
5043 | |
|
|
5044 | |
|
|
5045 | |
|
|
5046 | static int tab_atan[]= |
|
|
5047 | { 0,262,524,787,1051,1317,1584,1853,2126,2401,2679,2962,3249,3541,3839,4142,4452,4770,5095,5430,5774,6128,6494,6873,7265,7673,8098,8541,9004,9490,10000,10538}; |
|
|
5048 | |
|
|
5049 | static int |
|
|
5050 | atan2_int_lookup(int val) |
|
|
5051 | { |
|
|
5052 | int len=sizeof(tab_atan)/sizeof(int); |
|
|
5053 | int i=len/2; |
|
|
5054 | int p=i-1; |
|
|
5055 | |
|
|
5056 | for (;;) |
|
|
5057 | { |
|
|
5058 | i>>=1; |
|
|
5059 | if (val < tab_atan[p]) |
|
|
5060 | { |
|
|
5061 | p-=i; |
|
|
5062 | } |
|
|
5063 | else |
|
|
5064 | { |
|
|
5065 | if (val < tab_atan[p+1]) |
|
|
5066 | { |
|
|
5067 | return p+(p>>1); |
|
|
5068 | } |
|
|
5069 | else |
|
|
5070 | { |
|
|
5071 | p+=i; |
|
|
5072 | } |
|
|
5073 | } |
|
|
5074 | } |
|
|
5075 | } |
|
|
5076 | |
|
|
5077 | |
|
|
5078 | inline double my_atan2_double(double x, double y) |
|
|
5079 | { |
|
|
5080 | double result; |
|
|
5081 | |
|
|
5082 | asm ( |
|
|
5083 | "fpatan\n\t" |
|
|
5084 | : "=t" (result) // outputs; t = top of fpu stack |
|
|
5085 | : "0" (x), // inputs; 0 = same as result |
|
|
5086 | "u" (y) // u = 2nd floating point register |
|
|
5087 | ); |
|
|
5088 | |
|
|
5089 | return result; |
|
|
5090 | } |
|
|
5091 | |
|
|
5092 | |
|
|
5093 | static int |
|
|
5094 | atan2_int(int dx, int dy) |
|
|
5095 | { |
|
|
5096 | int mul=1,add=0,ret; |
|
|
5097 | |
|
|
5098 | if (! dx) |
|
|
5099 | { |
|
|
5100 | return dy < 0 ? 180 : 0; |
|
|
5101 | } |
|
|
5102 | |
|
|
5103 | if (! dy) |
|
|
5104 | { |
|
|
5105 | return dx < 0 ? -90 : 90; |
|
|
5106 | } |
|
|
5107 | |
|
|
5108 | if (dx < 0) |
|
|
5109 | { |
|
|
5110 | dx=-dx; |
|
|
5111 | mul=-1; |
|
|
5112 | } |
|
|
5113 | |
|
|
5114 | if (dy < 0) |
|
|
5115 | { |
|
|
5116 | dy=-dy; |
|
|
5117 | add=180*mul; |
|
|
5118 | mul*=-1; |
|
|
5119 | } |
|
|
5120 | |
|
|
5121 | while (dx > 20000 || dy > 20000) |
|
|
5122 | { |
|
|
5123 | dx/=10; |
|
|
5124 | dy/=10; |
|
|
5125 | } |
|
|
5126 | |
|
|
5127 | if (dx > dy) |
|
|
5128 | { |
|
|
5129 | ret=90-atan2_int_lookup(dy*10000/dx); |
|
|
5130 | } |
|
|
5131 | else |
|
|
5132 | { |
|
|
5133 | ret=atan2_int_lookup(dx*10000/dy); |
|
|
5134 | } |
|
|
5135 | |
|
|
5136 | return ret*mul+add; |
|
|
5137 | } |
|
|
5138 | |
|
|
5139 | |
|
|
5140 | |
|
|
5141 | static int maptool_get_angle_delta(struct coord *c1, struct coord *c2, int dir) |
|
|
5142 | { |
|
|
5143 | int dx = c2->x - c1->x; |
|
|
5144 | int dy = c2->y - c1->y; |
|
|
5145 | |
|
|
5146 | // fprintf(stderr, "angle: %d %d %d %d\n", c1->x, c1->y, c2->x, c2->y); |
|
|
5147 | |
|
|
5148 | #if 0 |
|
|
5149 | double angle; |
|
|
5150 | angle = my_atan2_double(dy, dx); |
|
|
5151 | angle *= 57.29577952019129709110; // ( 180/ M_PI ) = 57.29577952019129709110 |
|
|
5152 | //fprintf(stderr, "1 angle=%lf\n", angle); |
|
|
5153 | #endif |
|
|
5154 | |
|
|
5155 | #if 0 |
|
|
5156 | double angle; |
|
|
5157 | angle = atan2(dx, dy); |
|
|
5158 | angle *= 57.29577952019129709110; // ( 180/ M_PI ) = 57.29577952019129709110 |
|
|
5159 | fprintf(stderr, "2 angle=%lf\n", angle); |
|
|
5160 | #endif |
|
|
5161 | |
|
|
5162 | #if 1 |
|
|
5163 | int angle; |
|
|
5164 | angle=atan2_int(dx,dy); |
|
|
5165 | //fprintf(stderr, "3 angle=%d\n", (int)(angle)); |
|
|
5166 | #endif |
|
|
5167 | |
|
|
5168 | if (dir == -1) |
|
|
5169 | { |
|
|
5170 | angle = angle - 180; |
|
|
5171 | } |
|
|
5172 | |
|
|
5173 | if (angle < 0) |
|
|
5174 | { |
|
|
5175 | angle += 360; |
|
|
5176 | } |
|
|
5177 | |
|
|
5178 | return angle; |
|
|
5179 | } |
|
|
5180 | |
|
|
5181 | |
|
|
5182 | /** |
|
|
5183 | * @brief Calculates the delta between two angles |
|
|
5184 | * @param angle1 The first angle |
|
|
5185 | * @param angle2 The second angle |
|
|
5186 | * @return The difference between the angles: -179..-1=angle2 is left of angle1,0=same,1..179=angle2 is right of angle1,180=angle1 is opposite of angle2 |
|
|
5187 | */ |
|
|
5188 | static int maptool_delta_angle(int angle1, int angle2) |
|
|
5189 | { |
|
|
5190 | int delta = angle2 - angle1; |
|
|
5191 | |
|
|
5192 | if (delta <= -180) |
|
|
5193 | { |
|
|
5194 | delta += 360; |
|
|
5195 | } |
|
|
5196 | |
|
|
5197 | if (delta > 180) |
|
|
5198 | { |
|
|
5199 | delta -= 360; |
|
|
5200 | } |
|
|
5201 | |
|
|
5202 | return delta; |
|
|
5203 | } |
|
|
5204 | |
|
|
5205 | |
|
|
5206 | clock_t maptool_debug_measure_start(void) |
|
|
5207 | { |
|
|
5208 | clock_t start = clock(); |
|
|
5209 | return start; |
|
|
5210 | } |
|
|
5211 | |
|
|
5212 | clock_t maptool_debug_measure_end(clock_t start_time) |
|
|
5213 | { |
|
|
5214 | clock_t diff_time = clock() - start_time; |
|
|
5215 | return diff_time; |
|
|
5216 | } |
|
|
5217 | |
|
|
5218 | int maptool_debug_measure_end_tsecs(clock_t start_time) |
|
|
5219 | { |
|
|
5220 | clock_t diff_time = clock() - start_time; |
|
|
5221 | return (int) (((double) diff_time / (double) CLOCKS_PER_SEC) * 1000); |
|
|
5222 | } |
|
|
5223 | |
|
|
5224 | void maptool_debug_measure_result_str(clock_t diff, char *buffer) |
|
|
5225 | { |
|
|
5226 | sprintf(buffer, "elapsed: %fs\n", (diff / CLOCKS_PER_SEC)); |
|
|
5227 | } |
|
|
5228 | |
|
|
5229 | void maptool_debug_mrp(clock_t diff) |
|
|
5230 | { |
|
|
5231 | fprintf(stderr, "angle el:%fs\n", (double) ((double) diff / (double) CLOCKS_PER_SEC)); |
|
|
5232 | } |
|
|
5233 | |
|
|
5234 | |
|
|
5235 | |
|
|
5236 | static int maptool_get_node_x_y(long long way_id, int node_num_in_way, struct coord *c_ret) |
|
|
5237 | { |
|
|
5238 | int ret = 0; |
|
|
5239 | struct node_lat_lon node_coords2; |
|
|
5240 | |
|
|
5241 | // fprintf(stderr, "angle way id=%lld\n", way_id); |
|
|
5242 | |
|
|
5243 | long long way_node = get_waynode_num_have_seekpos(way_id, node_num_in_way, 0, (off_t)seekpos1); |
|
|
5244 | |
|
|
5245 | if (way_node > 0) |
|
|
5246 | { |
|
|
5247 | // fprintf(stderr, "angle way node id=%lld\n", way_node); |
|
|
5248 | |
|
|
5249 | get_lat_lon_for_node(way_node, &node_coords2); |
|
|
5250 | if (node_coords2.valid == 1) |
|
|
5251 | { |
|
|
5252 | //c_ret->x = transform_from_geo_lon(node_coords2.lon); |
|
|
5253 | c_ret->x = (int)(node_coords2.lon * 100000.0); |
|
|
5254 | |
|
|
5255 | //c_ret->y = transform_from_geo_lat(node_coords2.lat); |
|
|
5256 | c_ret->y = (int)(node_coords2.lat * 100000.0); |
|
|
5257 | |
|
|
5258 | // save coord of way_node |
|
|
5259 | // coord_buffer_3[node_num_in_way].x = c_ret->x; |
|
|
5260 | // coord_buffer_3[node_num_in_way].y = c_ret->y; |
|
|
5261 | |
|
|
5262 | // fprintf(stderr, "angle node_num=%d x=%d y=%d lon=%f lat=%f\n", node_num_in_way, c_ret->x, c_ret->y, node_coords2.lon, node_coords2.lat); |
|
|
5263 | ret = 1; |
|
|
5264 | } |
|
|
5265 | } |
|
|
5266 | |
|
|
5267 | return ret; |
|
|
5268 | } |
|
|
5269 | |
|
|
5270 | |
|
|
5271 | static void osm_write_cycle_way(FILE *ways_file, int i, int type, struct coord *coord_buffer_2, int start_node_num_in_way, int node_count, int part_num) |
|
|
5272 | { |
|
|
5273 | int *def_flags, add_flags; |
|
|
5274 | struct item_bin *item_bin; |
|
|
5275 | |
|
|
5276 | item_bin = init_item(type, 0); |
|
|
5277 | def_flags = item_get_default_flags(type); |
|
|
5278 | |
|
|
5279 | // struct coord *coord_buffer_4 = &coord_buffer_3[start_node_num_in_way]; |
|
|
5280 | struct coord *coord_buffer_4 = &coord_buffer[start_node_num_in_way]; |
|
|
5281 | item_bin_add_coord(item_bin, coord_buffer_4, node_count); |
|
|
5282 | |
|
|
5283 | // fprintf(stderr, "Xangle node_num=%d count=%d wayid=%lld\n", start_node_num_in_way, node_count, osmid_attr_value); |
|
|
5284 | //int ii; |
|
|
5285 | //for (ii=0;ii<node_count;ii++) |
|
|
5286 | //{ |
|
|
5287 | // fprintf(stderr, "Yangle node_num=%d x=%d y=%d\n", ii, coord_buffer_4[ii].x, coord_buffer_4[ii].y); |
|
|
5288 | //} |
|
|
5289 | |
|
|
5290 | if (def_flags) |
|
|
5291 | { |
|
|
5292 | flags_attr_value = (*def_flags | flags[0] | flags[1]) & ~flags[2]; |
|
|
5293 | // only add flags if they differ from the default flags!! |
|
|
5294 | if (flags_attr_value != *def_flags) |
|
|
5295 | { |
|
|
5296 | add_flags = 1; |
|
|
5297 | } |
|
|
5298 | } |
|
|
5299 | else // maybe should explicitly specify which "types" to consider? now its all "types" |
|
|
5300 | { |
|
|
5301 | def_flags = 0; |
|
|
5302 | flags_attr_value = (flags[0] | flags[1]) & ~flags[2]; |
|
|
5303 | |
|
|
5304 | // only add flags if we really have a value |
|
|
5305 | if (flags_attr_value != 0) |
|
|
5306 | { |
|
|
5307 | add_flags = 1; |
|
|
5308 | } |
|
|
5309 | } |
|
|
5310 | |
|
|
5311 | item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]); |
|
|
5312 | |
|
|
5313 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
|
|
5314 | |
|
|
5315 | if (add_flags) |
|
|
5316 | { |
|
|
5317 | item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); |
|
|
5318 | } |
|
|
5319 | |
|
|
5320 | // ------- add DEBUG ATTR -------- |
|
|
5321 | item_bin_add_attr_int(item_bin, attr_debugsplitway, start_node_num_in_way); |
|
|
5322 | // ------- add DEBUG ATTR -------- |
|
|
5323 | |
|
|
5324 | if (maxspeed_attr_value) |
|
|
5325 | { |
|
|
5326 | item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); |
|
|
5327 | } |
|
|
5328 | |
|
|
5329 | // custom color attribute |
|
|
5330 | if (attr_strings[attr_string_colour_]) |
|
|
5331 | { |
|
|
5332 | unsigned int cc = color_int_value_from_string(attr_strings[attr_string_colour_]); |
|
|
5333 | //fprintf(stderr, "col:ret=%d\n", cc); |
|
|
5334 | if (cc != 0) |
|
|
5335 | { |
|
|
5336 | cc = (cc >> 8); |
|
|
5337 | //fprintf(stderr, "col:in map=%d\n", (int)cc); |
|
|
5338 | item_bin_add_attr_int(item_bin, attr_colour2, (int)cc); |
|
|
5339 | } |
|
|
5340 | } |
|
|
5341 | |
|
|
5342 | item_bin_write(item_bin, ways_file); |
|
|
5343 | } |
|
|
5344 | |
|
|
5345 | long long cycle_w_processed_count = 0; |
4304 | |
5346 | |
4305 | void osm_end_way(struct maptool_osm *osm) |
5347 | void osm_end_way(struct maptool_osm *osm) |
4306 | { |
5348 | { |
4307 | int i, count; |
5349 | int i, count; |
4308 | int *def_flags, add_flags; |
5350 | int *def_flags, add_flags; |
… | |
… | |
4314 | int retval; |
5356 | int retval; |
4315 | char *name_folded = NULL; |
5357 | char *name_folded = NULL; |
4316 | char *name_folded2 = NULL; |
5358 | char *name_folded2 = NULL; |
4317 | struct node_lat_lon node_coords; |
5359 | struct node_lat_lon node_coords; |
4318 | osmid w_node; |
5360 | osmid w_node; |
|
|
5361 | int write_this_item_to_binfile; |
|
|
5362 | off_t seek_posx = 0; |
4319 | |
5363 | |
4320 | in_way = 0; |
5364 | in_way = 0; |
4321 | |
5365 | |
4322 | if (!osm->ways) |
5366 | if (!osm->ways) |
4323 | { |
5367 | { |
4324 | return; |
5368 | return; |
4325 | } |
5369 | } |
4326 | |
5370 | |
4327 | ways_processed_count++; |
5371 | ways_processed_count++; |
|
|
5372 | |
|
|
5373 | write_this_item_to_binfile = 1; |
4328 | |
5374 | |
4329 | count = attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types) / sizeof(enum item_type)); |
5375 | count = attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types) / sizeof(enum item_type)); |
4330 | if (!count) |
5376 | if (!count) |
4331 | { |
5377 | { |
4332 | count = 1; |
5378 | count = 1; |
4333 | types[0] = type_street_unkn; |
5379 | types[0] = type_street_unkn; |
4334 | } |
5380 | } |
4335 | |
5381 | |
4336 | if (count >= 10) |
5382 | if (count >= 10) |
4337 | { |
5383 | { |
4338 | fprintf(stderr, "way id %lld\n", osmid_attr_value); |
5384 | fprintf_(stderr, "way id %lld\n", osmid_attr_value); |
4339 | dbg_assert(count < 10); |
5385 | dbg_assert(count < 10); |
4340 | } |
5386 | } |
4341 | |
5387 | |
4342 | if (attr_strings[attr_string_label] != NULL) |
5388 | if (attr_strings[attr_string_label] != NULL) |
4343 | { |
5389 | { |
4344 | if (strlen(attr_strings[attr_string_label]) > 0) |
5390 | if (strlen(attr_strings[attr_string_label]) > 0) |
4345 | { |
5391 | { |
4346 | dont_save_to_db = 0; |
5392 | dont_save_to_db = 0; |
|
|
5393 | |
|
|
5394 | // check if "alt name" is same as normal name |
|
|
5395 | if (attr_strings[attr_string_label_alt] != NULL) |
|
|
5396 | { |
|
|
5397 | if (!strcmp(attr_strings[attr_string_label], attr_strings[attr_string_label_alt])) |
|
|
5398 | { |
|
|
5399 | // strings are the same, clear "alt name" |
|
|
5400 | attr_strings[attr_string_label_alt] = NULL; |
|
|
5401 | } |
|
|
5402 | } |
4347 | } |
5403 | } |
4348 | } |
5404 | } |
4349 | |
5405 | |
4350 | // required for fread to work! |
5406 | // required for fread to work! |
4351 | fseeko(ways_ref_file, 0L, SEEK_CUR); |
5407 | fseeko(ways_ref_file, 0L, SEEK_CUR); |
4352 | |
5408 | |
|
|
5409 | |
|
|
5410 | // correct bicycle flags ------------------------------------------------------------------------ |
|
|
5411 | if ((flags[0] & NAVIT_AF_ONEWAY) || (flags[0] & NAVIT_AF_ONEWAYREV)) // it's a one way road |
|
|
5412 | { |
|
|
5413 | if (flags[0] & NAVIT_AF_ONEWAY_BICYCLE_NO) // bike against oneway |
|
|
5414 | { |
|
|
5415 | flags[0] = (flags[0] & ~NAVIT_AF_BICYCLE_LANE); // remove the lane flag |
|
|
5416 | flags[0] = (flags[0] & ~NAVIT_AF_BICYCLE_TRACK); // remove the track flag |
|
|
5417 | } |
|
|
5418 | flags[0] = (flags[0] & ~NAVIT_AF_ONEWAY_BICYCLE_YES); // its already oneway, so remove additional oneway-bike flag |
|
|
5419 | } |
|
|
5420 | else // no oneway |
|
|
5421 | { |
|
|
5422 | flags[0] = (flags[0] & ~NAVIT_AF_ONEWAY_BICYCLE_NO); // remove the bike against-oneway-road flag, if no oneway road |
|
|
5423 | } |
|
|
5424 | // correct bicycle flags ------------------------------------------------------------------------ |
|
|
5425 | |
|
|
5426 | |
|
|
5427 | |
|
|
5428 | |
|
|
5429 | |
|
|
5430 | // check if its a bicycle way and also a footway, remove footway then!! ------------------------- |
|
|
5431 | int is_cycleway = -1; |
|
|
5432 | int is_footway = -1; |
|
|
5433 | for (i = 0; i < count; i++) |
|
|
5434 | { |
|
|
5435 | // cycleway |
|
|
5436 | // footway |
|
|
5437 | if (types[i] == type_cycleway) |
|
|
5438 | { |
|
|
5439 | is_cycleway = i; |
|
|
5440 | } |
|
|
5441 | else if (types[i] == type_footway) |
|
|
5442 | { |
|
|
5443 | is_footway = i; |
|
|
5444 | } |
|
|
5445 | } |
|
|
5446 | |
|
|
5447 | if ((is_footway > -1) && (is_cycleway > -1)) |
|
|
5448 | { |
|
|
5449 | types[is_footway] = type_none; // remove the footway |
|
|
5450 | } |
|
|
5451 | // check if its a bicycle way and also a footway, remove footway then!! ------------------------- |
|
|
5452 | |
|
|
5453 | |
|
|
5454 | |
4353 | for (i = 0; i < count; i++) // loop thru all the attributes of this way (and add a way for every attribute known -> so ways get duplicated here!!) |
5455 | for (i = 0; i < count; i++) // loop thru all the attributes of this way (and add a way for every attribute known -> so ways get duplicated here!!) |
4354 | { |
5456 | { |
4355 | add_flags = 0; |
5457 | add_flags = 0; |
|
|
5458 | write_this_item_to_binfile = 1; |
4356 | if (types[i] == type_none) |
5459 | if (types[i] == type_none) |
4357 | { |
5460 | { |
4358 | continue; |
5461 | continue; |
4359 | } |
5462 | } |
4360 | |
5463 | |
… | |
… | |
4364 | // DO NOT exclude unknown streets here, or city-to-countrypolygon matching won't work!! |
5467 | // DO NOT exclude unknown streets here, or city-to-countrypolygon matching won't work!! |
4365 | if (ignore_unkown && (types[i] == type_point_unkn)) |
5468 | if (ignore_unkown && (types[i] == type_point_unkn)) |
4366 | { |
5469 | { |
4367 | continue; |
5470 | continue; |
4368 | } |
5471 | } |
|
|
5472 | |
|
|
5473 | |
|
|
5474 | if (types[i] == type_cycleway) |
|
|
5475 | { |
|
|
5476 | |
|
|
5477 | // fprintf(stderr, "C=%lld W=%lld\n", cycle_w_processed_count, ways_processed_count); |
|
|
5478 | |
|
|
5479 | // check if we have a turn inside this way with angle greater than ROAD_ANGLE_MIN_FOR_TURN_BICYCLEMODE |
|
|
5480 | int i_coord; |
|
|
5481 | int i_coord_prev = 0; |
|
|
5482 | struct coord c1_; |
|
|
5483 | struct coord c2_; |
|
|
5484 | struct coord c3_; |
|
|
5485 | int angle_way_1; |
|
|
5486 | int angle_way_2; |
|
|
5487 | int angle_way_delta; |
|
|
5488 | osmid way_node; |
|
|
5489 | int is_valid_; |
|
|
5490 | int fff = 1; |
|
|
5491 | int split_part_num; |
|
|
5492 | struct coord *coord_buffer_2 = NULL; |
|
|
5493 | |
|
|
5494 | if (coord_count > 2) |
|
|
5495 | { |
|
|
5496 | if (osmid_attr_value > 0) |
|
|
5497 | { |
|
|
5498 | cycle_w_processed_count++; |
|
|
5499 | |
|
|
5500 | coord_buffer_2 = &coord_buffer[0]; // point to first real coordinate of way |
|
|
5501 | split_part_num = 1; |
|
|
5502 | |
|
|
5503 | for (i_coord = 1; i_coord < (coord_count - 1); i_coord++) |
|
|
5504 | { |
|
|
5505 | is_valid_ = 0; |
|
|
5506 | |
|
|
5507 | //fprintf(stderr, "angle i_coord=%d\n", i_coord); |
|
|
5508 | |
|
|
5509 | if (fff == 1) |
|
|
5510 | { |
|
|
5511 | is_valid_ = is_valid_ + (maptool_get_node_x_y(osmid_attr_value, (i_coord - 1), &c1_)); |
|
|
5512 | is_valid_ = is_valid_ + (maptool_get_node_x_y(osmid_attr_value, i_coord, &c2_)); |
|
|
5513 | fff = 0; |
|
|
5514 | } |
|
|
5515 | else |
|
|
5516 | { |
|
|
5517 | c1_.x = c2_.x; |
|
|
5518 | c1_.y = c2_.y; |
|
|
5519 | c2_.x = c3_.x; |
|
|
5520 | c2_.y = c3_.y; |
|
|
5521 | is_valid_++; |
|
|
5522 | is_valid_++; |
|
|
5523 | } |
|
|
5524 | |
|
|
5525 | if (is_valid_ == 2) |
|
|
5526 | { |
|
|
5527 | angle_way_1 = maptool_get_angle_delta(&c1_, &c2_, 1); |
|
|
5528 | //fprintf(stderr, "angle1=%d\n", angle_way_1); |
|
|
5529 | } |
|
|
5530 | |
|
|
5531 | is_valid_++; |
|
|
5532 | is_valid_ = is_valid_ + (maptool_get_node_x_y(osmid_attr_value, (i_coord + 1), &c3_)); |
|
|
5533 | |
|
|
5534 | if (is_valid_ == 4) |
|
|
5535 | { |
|
|
5536 | angle_way_2 = maptool_get_angle_delta(&c2_, &c3_, 1); |
|
|
5537 | //fprintf(stderr, "angle2=%d\n", angle_way_2); |
|
|
5538 | |
|
|
5539 | angle_way_delta = abs(maptool_delta_angle(angle_way_1, angle_way_2)); |
|
|
5540 | //fprintf(stderr, "angle_way_delta=%d\n", angle_way_delta); |
|
|
5541 | |
|
|
5542 | if (angle_way_delta >= ROAD_ANGLE_MIN_FOR_TURN_BICYCLEMODE) |
|
|
5543 | { |
|
|
5544 | // dont write this item to binfile in the normal way |
|
|
5545 | write_this_item_to_binfile = 0; |
|
|
5546 | |
|
|
5547 | //fprintf(stderr, "angle cut at node:%d prevnode:%d\n", i_coord, i_coord_prev); |
|
|
5548 | osm_write_cycle_way(osm->ways, i, types[i], coord_buffer_2, i_coord_prev, (i_coord - i_coord_prev + 1), split_part_num); |
|
|
5549 | i_coord_prev = i_coord; |
|
|
5550 | coord_buffer_2 = coord_buffer_2 + (i_coord - i_coord_prev); // move pointer to next starting coord of split-way |
|
|
5551 | split_part_num++; |
|
|
5552 | } |
|
|
5553 | } |
|
|
5554 | } |
|
|
5555 | |
|
|
5556 | if (write_this_item_to_binfile == 0) |
|
|
5557 | { |
|
|
5558 | //fprintf(stderr, "angle: write last part node:%d prevnode:%d\n", i_coord, i_coord_prev); |
|
|
5559 | // write last part of split-way |
|
|
5560 | osm_write_cycle_way(osm->ways, i, types[i], coord_buffer_2, i_coord_prev, (i_coord - i_coord_prev + 1), split_part_num); |
|
|
5561 | } |
|
|
5562 | } |
|
|
5563 | } |
|
|
5564 | } |
|
|
5565 | |
4369 | |
5566 | |
4370 | if (types[i] != type_street_unkn) |
5567 | if (types[i] != type_street_unkn) |
4371 | { |
5568 | { |
4372 | if (types[i] < type_area) |
5569 | if (types[i] < type_area) |
4373 | { |
5570 | { |
… | |
… | |
4382 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
5579 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
4383 | def_flags = item_get_default_flags(types[i]); |
5580 | def_flags = item_get_default_flags(types[i]); |
4384 | |
5581 | |
4385 | // save nodes of way ----------------- |
5582 | // save nodes of way ----------------- |
4386 | // save nodes of way ----------------- |
5583 | // save nodes of way ----------------- |
|
|
5584 | |
|
|
5585 | if (coastline_only_map == 1) |
|
|
5586 | { |
|
|
5587 | first = 0; |
|
|
5588 | } |
|
|
5589 | |
4387 | if (first == 1) |
5590 | if (first == 1) |
4388 | { |
5591 | { |
4389 | first = 0; |
5592 | first = 0; |
4390 | int i788 = 0; |
5593 | int i788 = 0; |
4391 | struct coord *c788 = (struct coord *) (item_bin + 1); // set pointer to coord struct of this item |
5594 | struct coord *c788 = (struct coord *) (item_bin + 1); // set pointer to coord struct of this item |
… | |
… | |
4405 | if (sql_counter == 0) |
5608 | if (sql_counter == 0) |
4406 | { |
5609 | { |
4407 | retval = sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
5610 | retval = sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4408 | if ((retval > 0) && (retval < 100)) |
5611 | if ((retval > 0) && (retval < 100)) |
4409 | { |
5612 | { |
|
|
5613 | fprintf_(stderr, "==================================\n"); |
4410 | fprintf(stderr, "begin: ways code:%d\n", retval); |
5614 | fprintf_(stderr, "begin: ways code:%d\n", retval); |
|
|
5615 | retval = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5616 | fprintf_(stderr, "begin:(commit) ways code:%d\n", retval); |
|
|
5617 | retval = sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5618 | fprintf_(stderr, "begin:(begin) ways code:%d\n", retval); |
|
|
5619 | fprintf_(stderr, "==================================\n"); |
4411 | } |
5620 | } |
4412 | else |
5621 | else |
4413 | { |
5622 | { |
4414 | //fprintf(stderr, "begin: ways\n"); |
5623 | //fprintf(stderr, "begin: ways\n"); |
4415 | } |
5624 | } |
4416 | } |
5625 | } |
4417 | |
5626 | |
|
|
5627 | |
|
|
5628 | // only save this way info to way table (used for index search) if its not a nonsearch way (like river, or some district outline) |
|
|
5629 | |
|
|
5630 | if (!item_not_for_search_index(types[i])) |
|
|
5631 | { |
|
|
5632 | |
4418 | sql_counter++; |
5633 | sql_counter++; |
4419 | |
5634 | |
|
|
5635 | // save ORIG name to DB ------------------------------------- |
4420 | sqlite3_bind_int64(stmt_way, 1, osmid_attr_value); |
5636 | sqlite3_bind_int64(stmt_way, 1, osmid_attr_value); |
4421 | sqlite3_bind_text(stmt_way, 2, attr_strings[attr_string_label], -1, SQLITE_STATIC); |
5637 | sqlite3_bind_text(stmt_way, 2, attr_strings[attr_string_label], -1, SQLITE_STATIC); |
4422 | |
5638 | |
4423 | // streetname folded for later sort/search |
5639 | // streetname folded for later sort/search |
4424 | char *sub = NULL; |
5640 | char *sub = NULL; |
… | |
… | |
4463 | sqlite3_bind_double(stmt_way, 4, node_coords.lat); |
5679 | sqlite3_bind_double(stmt_way, 4, node_coords.lat); |
4464 | // lon |
5680 | // lon |
4465 | sqlite3_bind_double(stmt_way, 5, node_coords.lon); |
5681 | sqlite3_bind_double(stmt_way, 5, node_coords.lon); |
4466 | } |
5682 | } |
4467 | |
5683 | |
|
|
5684 | // waytype |
|
|
5685 | if (types[i] != type_street_unkn) |
|
|
5686 | { |
|
|
5687 | sqlite3_bind_int(stmt_way, 8, 1); |
|
|
5688 | } |
|
|
5689 | else |
|
|
5690 | { |
|
|
5691 | // type -> POI |
|
|
5692 | sqlite3_bind_int(stmt_way, 8, 40); |
|
|
5693 | } |
|
|
5694 | |
4468 | // retval = |
5695 | // retval = |
4469 | sqlite3_step(stmt_way); |
5696 | sqlite3_step(stmt_way); |
4470 | //if ((retval > 0) && (retval < 100)) |
5697 | //if ((retval > 0) && (retval < 100)) |
4471 | //{ |
5698 | //{ |
4472 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
5699 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
… | |
… | |
4485 | |
5712 | |
4486 | if (sub) |
5713 | if (sub) |
4487 | { |
5714 | { |
4488 | g_free(sub); |
5715 | g_free(sub); |
4489 | } |
5716 | } |
|
|
5717 | // save ORIG name to DB ------------------------------------- |
|
|
5718 | |
|
|
5719 | // save alternate name to DB aswell ------------------------------------- |
|
|
5720 | if (attr_strings[attr_string_label_real_alt]) |
|
|
5721 | { |
|
|
5722 | sqlite3_bind_int64(stmt_way, 1, osmid_attr_value); |
|
|
5723 | sqlite3_bind_text(stmt_way, 2, attr_strings[attr_string_label_real_alt], -1, SQLITE_STATIC); |
|
|
5724 | |
|
|
5725 | |
|
|
5726 | // streetname folded for later sort/search |
|
|
5727 | char *sub = NULL; |
|
|
5728 | name_folded = linguistics_casefold(attr_strings[attr_string_label_real_alt]); |
|
|
5729 | if (name_folded) |
|
|
5730 | { |
|
|
5731 | name_folded2 = linguistics_remove_all_specials(name_folded); |
|
|
5732 | if (name_folded2) |
|
|
5733 | { |
|
|
5734 | g_free(name_folded); |
|
|
5735 | name_folded = name_folded2; |
|
|
5736 | } |
|
|
5737 | |
|
|
5738 | name_folded2 = linguistics_expand_special(name_folded, 1); |
|
|
5739 | if (name_folded2) |
|
|
5740 | { |
|
|
5741 | sqlite3_bind_text(stmt_way, 6, name_folded2, -1, SQLITE_STATIC); |
|
|
5742 | sub = get_index_for_string(name_folded2); |
|
|
5743 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
5744 | } |
|
|
5745 | else |
|
|
5746 | { |
|
|
5747 | sqlite3_bind_text(stmt_way, 6, name_folded, -1, SQLITE_STATIC); |
|
|
5748 | sub = get_index_for_string(name_folded); |
|
|
5749 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
5750 | } |
|
|
5751 | } |
|
|
5752 | else |
|
|
5753 | { |
|
|
5754 | // use original string |
|
|
5755 | sqlite3_bind_text(stmt_way, 6, attr_strings[attr_string_label_real_alt], -1, SQLITE_STATIC); |
|
|
5756 | sub = get_index_for_string(attr_strings[attr_string_label_real_alt]); |
|
|
5757 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
5758 | } |
|
|
5759 | |
|
|
5760 | // town id |
|
|
5761 | sqlite3_bind_int(stmt_way, 3, -1); |
|
|
5762 | |
|
|
5763 | if (node_coords.valid == 1) |
|
|
5764 | { |
|
|
5765 | // lat |
|
|
5766 | sqlite3_bind_double(stmt_way, 4, node_coords.lat); |
|
|
5767 | // lon |
|
|
5768 | sqlite3_bind_double(stmt_way, 5, node_coords.lon); |
|
|
5769 | } |
|
|
5770 | |
|
|
5771 | // waytype |
|
|
5772 | if (types[i] != type_street_unkn) |
|
|
5773 | { |
|
|
5774 | sqlite3_bind_int(stmt_way, 8, 3); |
|
|
5775 | } |
|
|
5776 | else |
|
|
5777 | { |
|
|
5778 | // type -> POI |
|
|
5779 | sqlite3_bind_int(stmt_way, 8, 40); |
|
|
5780 | } |
|
|
5781 | |
|
|
5782 | // retval = |
|
|
5783 | sqlite3_step(stmt_way); |
|
|
5784 | //if ((retval > 0) && (retval < 100)) |
|
|
5785 | //{ |
|
|
5786 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
|
|
5787 | //} |
|
|
5788 | sqlite3_reset(stmt_way); |
|
|
5789 | |
|
|
5790 | if (name_folded) |
|
|
5791 | { |
|
|
5792 | g_free(name_folded); |
|
|
5793 | } |
|
|
5794 | |
|
|
5795 | if (name_folded2) |
|
|
5796 | { |
|
|
5797 | g_free(name_folded2); |
|
|
5798 | } |
|
|
5799 | |
|
|
5800 | if (sub) |
|
|
5801 | { |
|
|
5802 | g_free(sub); |
|
|
5803 | } |
|
|
5804 | |
|
|
5805 | } |
|
|
5806 | // save alternate name to DB aswell ------------------------------------- |
|
|
5807 | |
|
|
5808 | |
|
|
5809 | // save english name to DB aswell ------------------------------------- |
|
|
5810 | if (attr_strings[attr_string_label_alt]) |
|
|
5811 | { |
|
|
5812 | sqlite3_bind_int64(stmt_way, 1, osmid_attr_value); |
|
|
5813 | sqlite3_bind_text(stmt_way, 2, attr_strings[attr_string_label_alt], -1, SQLITE_STATIC); |
|
|
5814 | |
|
|
5815 | |
|
|
5816 | // streetname folded for later sort/search |
|
|
5817 | char *sub = NULL; |
|
|
5818 | name_folded = linguistics_casefold(attr_strings[attr_string_label_alt]); |
|
|
5819 | if (name_folded) |
|
|
5820 | { |
|
|
5821 | name_folded2 = linguistics_remove_all_specials(name_folded); |
|
|
5822 | if (name_folded2) |
|
|
5823 | { |
|
|
5824 | g_free(name_folded); |
|
|
5825 | name_folded = name_folded2; |
|
|
5826 | } |
|
|
5827 | |
|
|
5828 | name_folded2 = linguistics_expand_special(name_folded, 1); |
|
|
5829 | if (name_folded2) |
|
|
5830 | { |
|
|
5831 | sqlite3_bind_text(stmt_way, 6, name_folded2, -1, SQLITE_STATIC); |
|
|
5832 | sub = get_index_for_string(name_folded2); |
|
|
5833 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
5834 | } |
|
|
5835 | else |
|
|
5836 | { |
|
|
5837 | sqlite3_bind_text(stmt_way, 6, name_folded, -1, SQLITE_STATIC); |
|
|
5838 | sub = get_index_for_string(name_folded); |
|
|
5839 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
5840 | } |
|
|
5841 | } |
|
|
5842 | else |
|
|
5843 | { |
|
|
5844 | // use original string |
|
|
5845 | sqlite3_bind_text(stmt_way, 6, attr_strings[attr_string_label_alt], -1, SQLITE_STATIC); |
|
|
5846 | sub = get_index_for_string(attr_strings[attr_string_label_alt]); |
|
|
5847 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
5848 | } |
|
|
5849 | |
|
|
5850 | // town id |
|
|
5851 | sqlite3_bind_int(stmt_way, 3, -1); |
|
|
5852 | |
|
|
5853 | if (node_coords.valid == 1) |
|
|
5854 | { |
|
|
5855 | // lat |
|
|
5856 | sqlite3_bind_double(stmt_way, 4, node_coords.lat); |
|
|
5857 | // lon |
|
|
5858 | sqlite3_bind_double(stmt_way, 5, node_coords.lon); |
|
|
5859 | } |
|
|
5860 | |
|
|
5861 | // waytype |
|
|
5862 | if (types[i] != type_street_unkn) |
|
|
5863 | { |
|
|
5864 | sqlite3_bind_int(stmt_way, 8, 2); |
|
|
5865 | } |
|
|
5866 | else |
|
|
5867 | { |
|
|
5868 | // type -> POI |
|
|
5869 | sqlite3_bind_int(stmt_way, 8, 40); |
|
|
5870 | } |
|
|
5871 | |
|
|
5872 | // retval = |
|
|
5873 | sqlite3_step(stmt_way); |
|
|
5874 | //if ((retval > 0) && (retval < 100)) |
|
|
5875 | //{ |
|
|
5876 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
|
|
5877 | //} |
|
|
5878 | sqlite3_reset(stmt_way); |
|
|
5879 | |
|
|
5880 | if (name_folded) |
|
|
5881 | { |
|
|
5882 | g_free(name_folded); |
|
|
5883 | } |
|
|
5884 | |
|
|
5885 | if (name_folded2) |
|
|
5886 | { |
|
|
5887 | g_free(name_folded2); |
|
|
5888 | } |
|
|
5889 | |
|
|
5890 | if (sub) |
|
|
5891 | { |
|
|
5892 | g_free(sub); |
|
|
5893 | } |
|
|
5894 | |
|
|
5895 | } |
|
|
5896 | // save english name to DB aswell ------------------------------------- |
|
|
5897 | |
|
|
5898 | } |
|
|
5899 | |
4490 | |
5900 | |
4491 | if (sql_counter > MAX_ROWS_WO_COMMIT_3) |
5901 | if (sql_counter > MAX_ROWS_WO_COMMIT_3) |
4492 | { |
5902 | { |
4493 | sql_counter = 0; |
5903 | sql_counter = 0; |
4494 | retval = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
5904 | retval = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4495 | if ((retval > 0) && (retval < 100)) |
5905 | if ((retval > 0) && (retval < 100)) |
4496 | { |
5906 | { |
4497 | fprintf(stderr, "ways: %lld code:%d\n", ways_processed_count, retval); |
5907 | fprintf_(stderr, "ways: %lld code:%d\n", ways_processed_count, retval); |
4498 | } |
5908 | } |
4499 | else |
5909 | else |
4500 | { |
5910 | { |
4501 | //fprintf(stderr, "ways: %lld\n", ways_processed_count); |
5911 | //fprintf(stderr, "ways: %lld\n", ways_processed_count); |
4502 | } |
5912 | } |
4503 | } |
5913 | } |
4504 | #endif |
5914 | #endif |
4505 | // set ref file to start of waynodes of current way |
5915 | // set ref file to start of waynodes of current way |
4506 | // fprintf(stderr, "w seek1 pos=%lld\n", seekpos1); |
5916 | // fprintf(stderr, "w seek1 pos=%lld\n", seekpos1); |
|
|
5917 | seek_posx = ftello(ways_ref_file); |
|
|
5918 | if ((off_t)seek_posx != (off_t)seekpos1) |
|
|
5919 | { |
4507 | fseeko(ways_ref_file, (off_t)seekpos1, SEEK_SET); |
5920 | fseeko(ways_ref_file, (off_t)seekpos1, SEEK_SET); |
|
|
5921 | } |
4508 | } |
5922 | } |
4509 | // save all the way nodes for streets |
5923 | // save all the way nodes for streets |
4510 | int fret = (int)fread(&w_node, sizeof(osmid), 1, ways_ref_file); |
5924 | int fret = (int)fread(&w_node, sizeof(osmid), 1, ways_ref_file); |
4511 | if (fret == 0) |
5925 | if (fret == 0) |
4512 | { |
5926 | { |
… | |
… | |
4515 | else if ((osmid)w_node > 4994968164L) |
5929 | else if ((osmid)w_node > 4994968164L) |
4516 | { |
5930 | { |
4517 | fprintf(stderr, "**ERROR** at fread 001b: wayid:%lld count=%d w_node=%lld\n", osmid_attr_value, (int)i788, (osmid)w_node); |
5931 | fprintf(stderr, "**ERROR** at fread 001b: wayid:%lld count=%d w_node=%lld\n", osmid_attr_value, (int)i788, (osmid)w_node); |
4518 | } |
5932 | } |
4519 | // fprintf(stderr, "at fread: w_node:%lld\n", (osmid)w_node); |
5933 | // fprintf(stderr, "at fread: w_node:%lld\n", (osmid)w_node); |
|
|
5934 | // save first node of WAYS with name/label into db |
4520 | add_waynode_to_db((osmid)w_node, (int)i788); |
5935 | add_waynode_to_db((osmid)w_node, (int)i788); |
4521 | } |
5936 | } |
4522 | else |
5937 | else // rest of ways |
4523 | { |
5938 | { |
4524 | // save all the waynodes to db |
5939 | // save all the waynodes to db |
4525 | if (i788 == 0) |
5940 | if (i788 == 0) |
4526 | { |
5941 | { |
4527 | // set ref file to start of waynodes of current way |
5942 | // set ref file to start of waynodes of current way |
4528 | // fprintf(stderr, "w seek1.1 pos=%lld\n", seekpos1); |
5943 | // fprintf(stderr, "w seek1.1 pos=%lld\n", seekpos1); |
|
|
5944 | seek_posx = ftello(ways_ref_file); |
|
|
5945 | if ((off_t)seek_posx != (off_t)seekpos1) |
|
|
5946 | { |
4529 | fseeko(ways_ref_file, (off_t)seekpos1, SEEK_SET); |
5947 | fseeko(ways_ref_file, (off_t)seekpos1, SEEK_SET); |
|
|
5948 | } |
4530 | } |
5949 | } |
4531 | |
5950 | |
4532 | int fret = (int)fread(&w_node, sizeof(osmid), 1, ways_ref_file); |
5951 | int fret = (int)fread(&w_node, sizeof(osmid), 1, ways_ref_file); |
4533 | if (fret == 0) |
5952 | if (fret == 0) |
4534 | { |
5953 | { |
… | |
… | |
4536 | } |
5955 | } |
4537 | else if ((osmid)w_node > 4994968164L) |
5956 | else if ((osmid)w_node > 4994968164L) |
4538 | { |
5957 | { |
4539 | fprintf(stderr, "**ERROR** at fread 001.1b: wayid:%lld count=%d w_node=%lld\n", osmid_attr_value, (int)i788, (osmid)w_node); |
5958 | fprintf(stderr, "**ERROR** at fread 001.1b: wayid:%lld count=%d w_node=%lld\n", osmid_attr_value, (int)i788, (osmid)w_node); |
4540 | } |
5959 | } |
|
|
5960 | // save first node of ALL WAYS into db |
4541 | add_waynode_to_db((osmid)w_node, (int)i788); |
5961 | add_waynode_to_db((osmid)w_node, (int)i788); |
4542 | } |
5962 | } |
4543 | } |
5963 | } |
4544 | |
5964 | |
4545 | if (dont_save_to_db == 0) |
5965 | if (dont_save_to_db == 0) |
… | |
… | |
4598 | fprintf(stderr, "street name alt: %s\n", attr_strings[attr_string_label_alt]); |
6018 | fprintf(stderr, "street name alt: %s\n", attr_strings[attr_string_label_alt]); |
4599 | } |
6019 | } |
4600 | } |
6020 | } |
4601 | item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]); |
6021 | item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]); |
4602 | |
6022 | |
|
|
6023 | // -- NEW 001 -- |
|
|
6024 | item_bin_add_attr_string(item_bin, attr_street_name_systematic_nat, attr_strings[attr_string_street_name_systematic_nat]); |
|
|
6025 | item_bin_add_attr_string(item_bin, attr_street_lanes, attr_strings[attr_string_street_lanes]); |
|
|
6026 | item_bin_add_attr_string(item_bin, attr_street_lanes_forward, attr_strings[attr_string_street_lanes_forward]); |
|
|
6027 | item_bin_add_attr_string(item_bin, attr_street_turn_lanes, attr_strings[attr_string_street_turn_lanes]); |
|
|
6028 | item_bin_add_attr_string(item_bin, attr_street_destination, attr_strings[attr_string_street_destination]); |
|
|
6029 | item_bin_add_attr_string(item_bin, attr_street_destination_lanes, attr_strings[attr_string_street_destination_lanes]); |
|
|
6030 | // -- NEW 001 -- |
|
|
6031 | |
4603 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
6032 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
|
|
6033 | |
4604 | if (debug_attr_buffer[0]) |
6034 | if (debug_attr_buffer[0]) |
|
|
6035 | { |
4605 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
6036 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
|
|
6037 | } |
|
|
6038 | |
4606 | if (add_flags) |
6039 | if (add_flags) |
|
|
6040 | { |
4607 | item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); |
6041 | item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); |
|
|
6042 | } |
|
|
6043 | |
4608 | if (maxspeed_attr_value) |
6044 | if (maxspeed_attr_value) |
|
|
6045 | { |
4609 | item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); |
6046 | item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); |
4610 | |
6047 | } |
4611 | |
6048 | |
4612 | // custom color attribute |
6049 | // custom color attribute |
4613 | if (attr_strings[attr_string_colour_]) |
6050 | if (attr_strings[attr_string_colour_]) |
4614 | { |
6051 | { |
4615 | unsigned int cc = color_int_value_from_string(attr_strings[attr_string_colour_]); |
6052 | unsigned int cc = color_int_value_from_string(attr_strings[attr_string_colour_]); |
… | |
… | |
4627 | { |
6064 | { |
4628 | item_bin_add_attr_int(item_bin, attr_duplicate_way, 1); |
6065 | item_bin_add_attr_int(item_bin, attr_duplicate_way, 1); |
4629 | //fprintf(stderr, "attr_duplicate_way:1: dup=true wayid=%lld\n", item_bin_get_wayid(item_bin)); |
6066 | //fprintf(stderr, "attr_duplicate_way:1: dup=true wayid=%lld\n", item_bin_get_wayid(item_bin)); |
4630 | } |
6067 | } |
4631 | |
6068 | |
|
|
6069 | if (write_this_item_to_binfile == 1) |
|
|
6070 | { |
4632 | item_bin_write(item_bin, osm->ways); |
6071 | item_bin_write(item_bin, osm->ways); |
|
|
6072 | } |
4633 | |
6073 | |
4634 | if (border_only_map_as_xml == 1) |
6074 | if (border_only_map_as_xml == 1) |
4635 | { |
6075 | { |
4636 | item_bin_write_xml(item_bin, "borders.xml"); |
6076 | item_bin_write_xml(item_bin, "borders.xml"); |
4637 | } |
6077 | } |
… | |
… | |
4829 | } |
6269 | } |
4830 | |
6270 | |
4831 | |
6271 | |
4832 | void osm_append_housenumber_node(FILE *out, struct coord *c, char *house_number, char *street_name) |
6272 | void osm_append_housenumber_node(FILE *out, struct coord *c, char *house_number, char *street_name) |
4833 | { |
6273 | { |
|
|
6274 | |
|
|
6275 | // c is inside the same buffer as the new item will be. so make a copy of c now! |
|
|
6276 | struct coord *c_cpy = coord_new(c->x, c->y); |
|
|
6277 | |
4834 | struct item_bin *item_bin; |
6278 | struct item_bin *item_bin; |
4835 | item_bin = init_item(type_house_number, 0); |
6279 | item_bin = init_item(type_house_number, 0); |
4836 | // item_bin->type = type_house_number; |
6280 | // item_bin->type = type_house_number; |
4837 | |
6281 | |
4838 | item_bin_add_coord(item_bin, c, 1); |
6282 | item_bin_add_coord(item_bin, c_cpy, 1); |
4839 | item_bin_add_attr_string(item_bin, attr_house_number, house_number); |
6283 | item_bin_add_attr_string(item_bin, attr_house_number, house_number); |
4840 | item_bin_add_attr_string(item_bin, attr_street_name, street_name); |
6284 | item_bin_add_attr_string(item_bin, attr_street_name, street_name); |
4841 | |
6285 | |
4842 | // DEBUG -- DEBUG -- DEBUG -- |
6286 | // DEBUG -- DEBUG -- DEBUG -- |
4843 | // DEBUG -- DEBUG -- DEBUG -- |
6287 | // DEBUG -- DEBUG -- DEBUG -- |
4844 | // dump_itembin(item_bin); |
6288 | // dump_itembin(item_bin); |
4845 | // DEBUG -- DEBUG -- DEBUG -- |
6289 | // DEBUG -- DEBUG -- DEBUG -- |
4846 | // DEBUG -- DEBUG -- DEBUG -- |
6290 | // DEBUG -- DEBUG -- DEBUG -- |
4847 | |
6291 | |
4848 | item_bin_write(item_bin, out); |
6292 | item_bin_write(item_bin, out); |
|
|
6293 | |
|
|
6294 | g_free(c_cpy); |
4849 | } |
6295 | } |
|
|
6296 | |
|
|
6297 | |
|
|
6298 | void add_point_as_way_to_db(char *label, osmid id, int waytype, double lat, double lon) |
|
|
6299 | { |
|
|
6300 | char *sub = NULL; |
|
|
6301 | char *name_folded2 = NULL; |
|
|
6302 | char *name_folded = NULL; |
|
|
6303 | int retval; |
|
|
6304 | |
|
|
6305 | if (label) |
|
|
6306 | { |
|
|
6307 | if (sql_counter == 0) |
|
|
6308 | { |
|
|
6309 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
6310 | } |
|
|
6311 | |
|
|
6312 | |
|
|
6313 | sqlite3_bind_int64(stmt_way, 1, id); |
|
|
6314 | sqlite3_bind_text(stmt_way, 2, label, -1, SQLITE_STATIC); |
|
|
6315 | |
|
|
6316 | |
|
|
6317 | // streetname folded for later sort/search |
|
|
6318 | name_folded = linguistics_casefold(label); |
|
|
6319 | if (name_folded) |
|
|
6320 | { |
|
|
6321 | name_folded2 = linguistics_remove_all_specials(name_folded); |
|
|
6322 | if (name_folded2) |
|
|
6323 | { |
|
|
6324 | g_free(name_folded); |
|
|
6325 | name_folded = name_folded2; |
|
|
6326 | } |
|
|
6327 | |
|
|
6328 | name_folded2 = linguistics_expand_special(name_folded, 1); |
|
|
6329 | if (name_folded2) |
|
|
6330 | { |
|
|
6331 | sqlite3_bind_text(stmt_way, 6, name_folded2, -1, SQLITE_STATIC); |
|
|
6332 | sub = get_index_for_string(name_folded2); |
|
|
6333 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
6334 | } |
|
|
6335 | else |
|
|
6336 | { |
|
|
6337 | sqlite3_bind_text(stmt_way, 6, name_folded, -1, SQLITE_STATIC); |
|
|
6338 | sub = get_index_for_string(name_folded); |
|
|
6339 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
6340 | } |
|
|
6341 | } |
|
|
6342 | else |
|
|
6343 | { |
|
|
6344 | // use original string |
|
|
6345 | sqlite3_bind_text(stmt_way, 6, label, -1, SQLITE_STATIC); |
|
|
6346 | sub = get_index_for_string(label); |
|
|
6347 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
6348 | } |
|
|
6349 | |
|
|
6350 | // town id |
|
|
6351 | sqlite3_bind_int(stmt_way, 3, -1); |
|
|
6352 | |
|
|
6353 | // lat |
|
|
6354 | sqlite3_bind_double(stmt_way, 4, lat); |
|
|
6355 | // lon |
|
|
6356 | sqlite3_bind_double(stmt_way, 5, lon); |
|
|
6357 | |
|
|
6358 | // waytype |
|
|
6359 | sqlite3_bind_int(stmt_way, 8, waytype); |
|
|
6360 | |
|
|
6361 | // retval = |
|
|
6362 | sqlite3_step(stmt_way); |
|
|
6363 | //if ((retval > 0) && (retval < 100)) |
|
|
6364 | //{ |
|
|
6365 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
|
|
6366 | //} |
|
|
6367 | sqlite3_reset(stmt_way); |
|
|
6368 | |
|
|
6369 | if (name_folded) |
|
|
6370 | { |
|
|
6371 | g_free(name_folded); |
|
|
6372 | } |
|
|
6373 | |
|
|
6374 | if (name_folded2) |
|
|
6375 | { |
|
|
6376 | g_free(name_folded2); |
|
|
6377 | } |
|
|
6378 | |
|
|
6379 | if (sub) |
|
|
6380 | { |
|
|
6381 | g_free(sub); |
|
|
6382 | } |
|
|
6383 | |
|
|
6384 | sql_counter++; |
|
|
6385 | if (sql_counter > MAX_ROWS_WO_COMMIT_3) |
|
|
6386 | { |
|
|
6387 | sql_counter = 0; |
|
|
6388 | retval = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
6389 | if ((retval > 0) && (retval < 100)) |
|
|
6390 | { |
|
|
6391 | fprintf_(stderr, "add_point_as_way_to_db:code:%d\n", retval); |
|
|
6392 | } |
|
|
6393 | } |
|
|
6394 | |
|
|
6395 | } |
|
|
6396 | |
|
|
6397 | } |
|
|
6398 | |
4850 | |
6399 | |
4851 | void osm_end_node(struct maptool_osm *osm) |
6400 | void osm_end_node(struct maptool_osm *osm) |
4852 | { |
6401 | { |
4853 | int count, i; |
6402 | int count, i; |
4854 | char *postal; |
6403 | char *postal; |
4855 | enum item_type types[10]; |
6404 | enum item_type types[10]; |
4856 | struct item_bin *item_bin; |
6405 | struct item_bin *item_bin; |
4857 | in_node = 0; |
6406 | in_node = 0; |
4858 | |
6407 | |
4859 | if (!osm->nodes || !node_is_tagged || !nodeid) |
6408 | if (!osm->nodes || !node_is_tagged || !nodeid) |
|
|
6409 | { |
4860 | return; |
6410 | return; |
|
|
6411 | } |
4861 | |
6412 | |
4862 | count = attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types) / sizeof(enum item_type)); |
6413 | count = attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types) / sizeof(enum item_type)); |
4863 | |
6414 | |
4864 | if (!count) |
6415 | if (!count) |
4865 | { |
6416 | { |
… | |
… | |
4867 | count = 1; |
6418 | count = 1; |
4868 | } |
6419 | } |
4869 | |
6420 | |
4870 | dbg_assert(count < 10); |
6421 | dbg_assert(count < 10); |
4871 | |
6422 | |
|
|
6423 | |
|
|
6424 | if (attr_strings[attr_string_label] != NULL) |
|
|
6425 | { |
|
|
6426 | // check if "alt name" is same as normal name |
|
|
6427 | if (attr_strings[attr_string_label_alt] != NULL) |
|
|
6428 | { |
|
|
6429 | if (!strcmp(attr_strings[attr_string_label], attr_strings[attr_string_label_alt])) |
|
|
6430 | { |
|
|
6431 | // strings are the same, clear "alt name" |
|
|
6432 | attr_strings[attr_string_label_alt] = NULL; |
|
|
6433 | } |
|
|
6434 | } |
|
|
6435 | } |
|
|
6436 | |
|
|
6437 | |
4872 | for (i = 0; i < count; i++) |
6438 | for (i = 0; i < count; i++) |
4873 | { |
6439 | { |
4874 | if (types[i] == type_none) |
6440 | if (types[i] == type_none) |
4875 | { |
6441 | { |
4876 | continue; |
6442 | continue; |
… | |
… | |
4912 | { |
6478 | { |
4913 | item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population])); |
6479 | item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population])); |
4914 | } |
6480 | } |
4915 | |
6481 | |
4916 | item_bin_add_coord(item_bin, &ni->c, 1); |
6482 | item_bin_add_coord(item_bin, &ni->c, 1); |
|
|
6483 | if (((types[i] == type_poi_bicycle_parking) || (types[i] == type_poi_bicycle_rental)) && (attr_strings[attr_string_capacity] != NULL) && (strlen(attr_strings[attr_string_capacity]) > 0)) |
|
|
6484 | { |
|
|
6485 | char *label_new; |
|
|
6486 | if ((attr_strings[attr_string_label] != NULL) && (strlen(attr_strings[attr_string_label]) > 1)) |
|
|
6487 | { |
|
|
6488 | // fprintf(stderr, "XXX1:%s:%s\n", attr_strings[attr_string_label], attr_strings[attr_string_capacity]); |
|
|
6489 | label_new = g_strdup_printf("%s:%s", attr_strings[attr_string_label], attr_strings[attr_string_capacity]); |
|
|
6490 | } |
|
|
6491 | else |
|
|
6492 | { |
|
|
6493 | label_new = g_strdup_printf("%s", attr_strings[attr_string_capacity]); |
|
|
6494 | } |
|
|
6495 | item_bin_add_attr_string(item_bin, attr_label, label_new); |
|
|
6496 | g_free(label_new); |
|
|
6497 | } |
|
|
6498 | else |
|
|
6499 | { |
4917 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]); |
6500 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]); |
|
|
6501 | } |
4918 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
6502 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
4919 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
6503 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
4920 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
6504 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
4921 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
6505 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
4922 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
6506 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
4923 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
6507 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
4924 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
6508 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
|
|
6509 | |
|
|
6510 | // -- NEW 001 -- |
|
|
6511 | item_bin_add_attr_string(item_bin, attr_ref, attr_strings[attr_string_ref]); |
|
|
6512 | item_bin_add_attr_string(item_bin, attr_exit_to, attr_strings[attr_string_exit_to]); |
|
|
6513 | // -- NEW 001 -- |
|
|
6514 | |
|
|
6515 | if ((types[i] == type_poi_bicycle_parking) || (types[i] == type_poi_bicycle_rental)) |
|
|
6516 | { |
|
|
6517 | int capacity = 0; |
|
|
6518 | if (attr_strings[attr_string_capacity] != NULL) |
|
|
6519 | { |
|
|
6520 | if (strlen(attr_strings[attr_string_capacity]) > 0) |
|
|
6521 | { |
|
|
6522 | capacity = atoi(attr_strings[attr_string_capacity]); |
|
|
6523 | item_bin_add_attr_int(item_bin, attr_capacity, attr_strings[attr_string_capacity]); |
|
|
6524 | } |
|
|
6525 | } |
|
|
6526 | } |
|
|
6527 | |
4925 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
6528 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
4926 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
6529 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
4927 | |
6530 | |
|
|
6531 | if ((item_is_town(*item_bin)) || (item_is_district(*item_bin))) |
|
|
6532 | { |
|
|
6533 | if (attr_strings[attr_string_label_alt]) |
|
|
6534 | { |
|
|
6535 | item_bin_add_attr_string(item_bin, attr_town_name_match, attr_strings[attr_string_label_alt]); |
|
|
6536 | // if (debug_itembin(item_bin)) |
|
|
6537 | // { |
|
|
6538 | // fprintf(stderr, "town name : %s\n", attr_strings[attr_string_label]); |
|
|
6539 | // fprintf(stderr, "town name alt: %s\n", attr_strings[attr_string_label_alt]); |
|
|
6540 | // } |
|
|
6541 | } |
|
|
6542 | } |
|
|
6543 | |
4928 | postal = attr_strings[attr_string_postal]; |
6544 | postal = attr_strings[attr_string_postal]; |
4929 | if (postal) |
6545 | if (postal) |
4930 | { |
6546 | { |
4931 | char *sep = strchr(postal, ','); |
6547 | char *sep = strchr(postal, ','); |
4932 | if (sep) |
6548 | if (sep) |
… | |
… | |
4935 | } |
6551 | } |
4936 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal); |
6552 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal); |
4937 | } |
6553 | } |
4938 | |
6554 | |
4939 | item_bin_write(item_bin, osm->nodes); |
6555 | item_bin_write(item_bin, osm->nodes); |
|
|
6556 | |
|
|
6557 | |
|
|
6558 | |
|
|
6559 | |
|
|
6560 | // town waytype = 4 |
|
|
6561 | if ((item_is_town(*item_bin)) || (item_is_district(*item_bin))) |
|
|
6562 | { |
|
|
6563 | if (attr_strings[attr_string_label]) |
|
|
6564 | { |
|
|
6565 | add_point_as_way_to_db(attr_strings[attr_string_label], osmid_attr_value, 4, save_node_lat, save_node_lon); |
|
|
6566 | } |
|
|
6567 | |
|
|
6568 | if (attr_strings[attr_string_label_alt]) |
|
|
6569 | { |
|
|
6570 | add_point_as_way_to_db(attr_strings[attr_string_label_alt], osmid_attr_value, 4, save_node_lat, save_node_lon); |
|
|
6571 | } |
|
|
6572 | } |
|
|
6573 | |
|
|
6574 | // POI waytype = 40 |
|
|
6575 | if (item_is_poi(types[i])) |
|
|
6576 | { |
|
|
6577 | |
|
|
6578 | if (!item_not_for_search_index(types[i])) |
|
|
6579 | { |
|
|
6580 | if (attr_strings[attr_string_label]) |
|
|
6581 | { |
|
|
6582 | add_point_as_way_to_db(attr_strings[attr_string_label], osmid_attr_value, 40, save_node_lat, save_node_lon); |
|
|
6583 | // fprintf(stderr, "POI name : %s id=%lld\n", attr_strings[attr_string_label], osmid_attr_value); |
|
|
6584 | } |
|
|
6585 | |
|
|
6586 | if (attr_strings[attr_string_label_alt]) |
|
|
6587 | { |
|
|
6588 | add_point_as_way_to_db(attr_strings[attr_string_label_alt], osmid_attr_value, 40, save_node_lat, save_node_lon); |
|
|
6589 | } |
|
|
6590 | } |
|
|
6591 | } |
|
|
6592 | |
|
|
6593 | |
4940 | |
6594 | |
4941 | if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) |
6595 | if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) |
4942 | { |
6596 | { |
4943 | item_bin = init_item(item_bin->type, 0); |
6597 | item_bin = init_item(item_bin->type, 0); |
4944 | item_bin_add_coord(item_bin, &ni->c, 1); |
6598 | item_bin_add_coord(item_bin, &ni->c, 1); |
… | |
… | |
4946 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
6600 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
4947 | item_bin_add_attr_string(item_bin, attr_town_postal, postal); |
6601 | item_bin_add_attr_string(item_bin, attr_town_postal, postal); |
4948 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
6602 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
4949 | item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]); |
6603 | item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]); |
4950 | |
6604 | |
4951 | if (attr_strings[attr_string_label_alt]) |
6605 | //if (attr_strings[attr_string_label_alt]) |
4952 | { |
6606 | //{ |
4953 | item_bin_add_attr_string(item_bin, attr_town_name_match, attr_strings[attr_string_label_alt]); |
6607 | // item_bin_add_attr_string(item_bin, attr_town_name_match, attr_strings[attr_string_label_alt]); |
4954 | if (debug_itembin(item_bin)) |
6608 | // if (debug_itembin(item_bin)) |
4955 | { |
6609 | // { |
4956 | fprintf(stderr, "town name : %s\n", attr_strings[attr_string_label]); |
6610 | // fprintf(stderr, "town name : %s\n", attr_strings[attr_string_label]); |
4957 | fprintf(stderr, "town name alt: %s\n", attr_strings[attr_string_label_alt]); |
6611 | // fprintf(stderr, "town name alt: %s\n", attr_strings[attr_string_label_alt]); |
4958 | } |
6612 | // } |
4959 | } |
6613 | //} |
4960 | |
6614 | |
4961 | item_bin_write(item_bin, osm->towns); |
6615 | item_bin_write(item_bin, osm->towns); |
4962 | } |
6616 | } |
|
|
6617 | |
|
|
6618 | // put POI into DB for index search |
|
|
6619 | // put town into DB for index search |
|
|
6620 | // put district into DB for index search |
|
|
6621 | // ****** retval = sqlite3_prepare_v2(sql_handle, "INSERT INTO way (id, name, town_id, lat, lon, name_fold, ind, name_fold_idx, waytype) VALUES (?,?,?,?,?,?,0,?,?);", -1, &stmt_way, NULL); |
|
|
6622 | |
4963 | |
6623 | |
4964 | //fprintf(stderr,"********DUMP nd1***********\n"); |
6624 | //fprintf(stderr,"********DUMP nd1***********\n"); |
4965 | //if (types[i] == type_house_number) |
6625 | //if (types[i] == type_house_number) |
4966 | //{ |
6626 | //{ |
4967 | // dump_itembin(item_bin); |
6627 | // dump_itembin(item_bin); |
… | |
… | |
4980 | unknown = country_from_countryid(999); |
6640 | unknown = country_from_countryid(999); |
4981 | return unknown; |
6641 | return unknown; |
4982 | } |
6642 | } |
4983 | |
6643 | |
4984 | static struct country_table * |
6644 | static struct country_table * |
|
|
6645 | osm_process_item_by_country_id(int id) |
|
|
6646 | { |
|
|
6647 | static struct country_table *ct; |
|
|
6648 | ct = country_from_countryid(id); |
|
|
6649 | return ct; |
|
|
6650 | } |
|
|
6651 | |
|
|
6652 | static struct country_table * |
4985 | osm_process_item_fixed_country(void) |
6653 | osm_process_item_fixed_country(void) |
4986 | { |
6654 | { |
4987 | static struct country_table *fixed; |
6655 | static struct country_table *fixed; |
4988 | fixed = country_from_countryid(global_fixed_country_id); |
6656 | fixed = country_from_countryid(global_fixed_country_id); |
4989 | return fixed; |
6657 | return fixed; |
… | |
… | |
5030 | } |
6698 | } |
5031 | |
6699 | |
5032 | return 0; |
6700 | return 0; |
5033 | } |
6701 | } |
5034 | |
6702 | |
|
|
6703 | |
|
|
6704 | static struct country_table* osm_process_town_by_manual_country_borders(GList *bl_manual, struct coord *c) |
|
|
6705 | { |
|
|
6706 | GList *l = bl_manual; |
|
|
6707 | while (l) |
|
|
6708 | { |
|
|
6709 | if (l) |
|
|
6710 | { |
|
|
6711 | struct boundary_manual *b = l->data; |
|
|
6712 | if (b) |
|
|
6713 | { |
|
|
6714 | if (bbox_contains_coord(&b->r, c) == 1) |
|
|
6715 | { |
|
|
6716 | if (geom_poly_point_inside(b->c, b->coord_count, c) == 1) |
|
|
6717 | { |
|
|
6718 | // ok, now check all innery polys of this country id |
|
|
6719 | if (osm_check_all_inner_polys_of_country_id(b->countryid, c) == 1) |
|
|
6720 | { |
|
|
6721 | return b->country; |
|
|
6722 | } |
|
|
6723 | } |
|
|
6724 | } |
|
|
6725 | } |
|
|
6726 | l = g_list_next(l); |
|
|
6727 | } |
|
|
6728 | } |
|
|
6729 | |
|
|
6730 | return NULL; |
|
|
6731 | } |
|
|
6732 | |
|
|
6733 | // return: 1 -> coord is not in ANY inner of this country id |
|
|
6734 | // 0 -> coord is at least in 1 inner of this country id |
|
|
6735 | static int osm_check_all_inner_polys_of_country_id(int country_id, struct coord *c) |
|
|
6736 | { |
|
|
6737 | GList *l = boundary_list_inner_manual; |
|
|
6738 | |
|
|
6739 | while (l) |
|
|
6740 | { |
|
|
6741 | if (l) |
|
|
6742 | { |
|
|
6743 | struct boundary_manual *b = l->data; |
|
|
6744 | if (b) |
|
|
6745 | { |
|
|
6746 | if (b->countryid == country_id) |
|
|
6747 | { |
|
|
6748 | if (bbox_contains_coord(&b->r, c) == 1) |
|
|
6749 | { |
|
|
6750 | if (geom_poly_point_inside(b->c, b->coord_count, c) == 1) |
|
|
6751 | { |
|
|
6752 | // c is inside 1 inner poly |
|
|
6753 | return 0; |
|
|
6754 | } |
|
|
6755 | } |
|
|
6756 | } |
|
|
6757 | } |
|
|
6758 | l = g_list_next(l); |
|
|
6759 | } |
|
|
6760 | } |
|
|
6761 | |
|
|
6762 | return 1; |
|
|
6763 | } |
|
|
6764 | |
|
|
6765 | |
|
|
6766 | static long long osm_process_street_by_manual_country_borders(GList *bl_manual, struct coord *c) |
|
|
6767 | { |
|
|
6768 | GList *l = bl_manual; |
|
|
6769 | |
|
|
6770 | while (l) |
|
|
6771 | { |
|
|
6772 | if (l) |
|
|
6773 | { |
|
|
6774 | struct boundary_manual *b = l->data; |
|
|
6775 | if (b) |
|
|
6776 | { |
|
|
6777 | if (bbox_contains_coord(&b->r, c) == 1) |
|
|
6778 | { |
|
|
6779 | if (geom_poly_point_inside(b->c, b->coord_count, c) == 1) |
|
|
6780 | { |
|
|
6781 | // ok, now check all innery polys of this country id |
|
|
6782 | if (osm_check_all_inner_polys_of_country_id(b->countryid, c) == 1) |
|
|
6783 | { |
|
|
6784 | return b->town_id; |
|
|
6785 | } |
|
|
6786 | } |
|
|
6787 | } |
|
|
6788 | } |
|
|
6789 | l = g_list_next(l); |
|
|
6790 | } |
|
|
6791 | } |
|
|
6792 | |
|
|
6793 | return -1; |
|
|
6794 | } |
|
|
6795 | |
|
|
6796 | static long long osm_process_town_by_manual_country_id(GList *bl_manual, int country_id) |
|
|
6797 | { |
|
|
6798 | struct country_table4 |
|
|
6799 | { |
|
|
6800 | int countryid; |
|
|
6801 | char *names; |
|
|
6802 | char *admin_levels; |
|
|
6803 | FILE *file; |
|
|
6804 | int size; |
|
|
6805 | struct rect r; |
|
|
6806 | }; |
|
|
6807 | |
|
|
6808 | struct country_table4 *c4; |
|
|
6809 | struct boundary_manual *b; |
|
|
6810 | |
|
|
6811 | GList *l = bl_manual; |
|
|
6812 | while (l) |
|
|
6813 | { |
|
|
6814 | if (l) |
|
|
6815 | { |
|
|
6816 | b = l->data; |
|
|
6817 | if (b) |
|
|
6818 | { |
|
|
6819 | c4 = b->country; |
|
|
6820 | if (c4) |
|
|
6821 | { |
|
|
6822 | if (c4->countryid == country_id) |
|
|
6823 | { |
|
|
6824 | return b->town_id; |
|
|
6825 | } |
|
|
6826 | } |
|
|
6827 | } |
|
|
6828 | l = g_list_next(l); |
|
|
6829 | } |
|
|
6830 | } |
|
|
6831 | |
|
|
6832 | return -1; |
|
|
6833 | } |
5035 | |
6834 | |
5036 | static struct country_table * |
6835 | static struct country_table * |
5037 | osm_process_town_by_boundary(GList *bl, struct item_bin *ib, struct coord *c, struct attr *attrs) |
6836 | osm_process_town_by_boundary(GList *bl, struct item_bin *ib, struct coord *c, struct attr *attrs) |
5038 | { |
6837 | { |
5039 | GList *l, *matches = boundary_find_matches(bl, c); |
6838 | GList *l, *matches = boundary_find_matches(bl, c); |
… | |
… | |
5116 | attrs[0].u.str = postal; |
6915 | attrs[0].u.str = postal; |
5117 | } |
6916 | } |
5118 | l = g_list_next(l); |
6917 | l = g_list_next(l); |
5119 | } |
6918 | } |
5120 | } |
6919 | } |
|
|
6920 | g_list_free(matches); |
5121 | return match->country; |
6921 | return match->country; |
5122 | } |
6922 | } |
5123 | else |
6923 | else |
5124 | { |
6924 | { |
5125 | //fprintf(stderr,"town_by_boundary:099\n"); |
6925 | //fprintf(stderr,"town_by_boundary:099\n"); |
|
|
6926 | g_list_free(matches); |
5126 | return NULL; |
6927 | return NULL; |
5127 | } |
6928 | } |
5128 | } |
6929 | } |
5129 | |
6930 | |
5130 | int town_size_estimate(int type) |
6931 | int town_size_estimate(int type) |
… | |
… | |
5151 | case type_town_label_2e3: |
6952 | case type_town_label_2e3: |
5152 | size = 1460; |
6953 | size = 1460; |
5153 | break; |
6954 | break; |
5154 | case type_town_label_1e3: |
6955 | case type_town_label_1e3: |
5155 | case type_town_label_5e2: |
6956 | case type_town_label_5e2: |
5156 | // case type_town_label_2e2: |
6957 | case type_town_label_2e2: |
5157 | case type_town_label_1e2: |
6958 | case type_town_label_1e2: |
5158 | case type_town_label_5e1: |
6959 | case type_town_label_5e1: |
5159 | case type_town_label_2e1: |
6960 | case type_town_label_2e1: |
5160 | case type_town_label_1e1: |
6961 | case type_town_label_1e1: |
5161 | case type_town_label_5e0: |
6962 | case type_town_label_5e0: |
5162 | // case type_town_label_2e0: |
6963 | case type_town_label_2e0: |
5163 | case type_town_label_1e0: |
6964 | case type_town_label_1e0: |
5164 | case type_town_label_0e0: |
6965 | case type_town_label_0e0: |
5165 | size = 660; |
6966 | size = 660; |
5166 | break; |
6967 | break; |
5167 | default: |
6968 | default: |
… | |
… | |
5184 | */ |
6985 | */ |
5185 | return size; |
6986 | return size; |
5186 | } |
6987 | } |
5187 | |
6988 | |
5188 | void assign_town_to_streets_v1(); |
6989 | void assign_town_to_streets_v1(); |
5189 | void assign_town_to_streets_by_boundary(GList *bl); |
6990 | void assign_town_to_streets_by_boundary(GList *bl, GList *man_borders); |
|
|
6991 | void assign_town_to_country_by_manual_borders(GList *bl, GList *man_borders); |
5190 | void copy_town_border_data(); |
6992 | void copy_town_border_data(); |
|
|
6993 | void assign_streets_to_towns_by_manual_country_borders(GList *man_borders); |
5191 | |
6994 | |
5192 | void assign_town_to_streets(GList *bl) |
6995 | void assign_town_to_streets(GList *bl, GList *man_borders) |
5193 | { |
6996 | { |
5194 | int skipped = 0; |
6997 | int skipped = 0; |
5195 | |
6998 | |
5196 | copy_town_border_data(); |
6999 | copy_town_border_data(); |
|
|
7000 | assign_town_to_country_by_manual_borders(bl, man_borders); |
5197 | assign_town_to_streets_by_boundary(bl); |
7001 | assign_town_to_streets_by_boundary(bl, man_borders); |
5198 | |
7002 | |
5199 | // now process all the left over towns |
7003 | // now process all the left over towns |
5200 | assign_town_to_streets_v1(1); |
7004 | assign_town_to_streets_v1(1); |
5201 | assign_town_to_streets_v1(2); // make townsize double on second pass |
7005 | assign_town_to_streets_v1(2); // make townsize double on second pass |
5202 | } |
|
|
5203 | |
7006 | |
|
|
7007 | assign_streets_to_towns_by_manual_country_borders(man_borders); |
|
|
7008 | } |
5204 | |
7009 | |
5205 | void copy_town_border_data() |
7010 | void purge_unused_towns() |
5206 | { |
7011 | { |
5207 | long long bid; |
|
|
5208 | long long tid; |
|
|
5209 | int retval; |
7012 | int retval8; |
5210 | int rc = 0; |
|
|
5211 | int commit_after = 20000; |
|
|
5212 | int count = 0; |
|
|
5213 | int admin_l = 99; |
|
|
5214 | |
|
|
5215 | sqlite3_stmt *stmt_d_1; |
7013 | sqlite3_stmt *stmt_mm_1; |
5216 | sqlite3_stmt *stmt_d_2; |
7014 | |
5217 | retval = sqlite3_prepare_v2(sql_handle, "select border_id, id, admin_level from town2;", -1, &stmt_d_1, NULL); |
7015 | sql_counter = 0; |
|
|
7016 | retval8 = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7017 | fprintf_(stderr, "prep:%d (error here is ok!)\n", retval8); |
|
|
7018 | |
|
|
7019 | retval8 = sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
5218 | // fprintf(stderr, "prep:%d\n", retval); |
7020 | fprintf_(stderr, "prep:%d\n", retval8); |
5219 | retval = sqlite3_prepare_v2(sql_handle, "update town set border_id = ?, size = ? where id = ?;", -1, &stmt_d_2, NULL); |
7021 | |
|
|
7022 | retval8 = sqlite3_prepare_v2(sql_handle, "select count(*) from town where id not in (select town_id from way);", -1, &stmt_mm_1, NULL); |
5220 | // fprintf(stderr, "prep:%d\n", retval); |
7023 | fprintf_(stderr, "prep:%d\n", retval8); |
5221 | |
|
|
5222 | // loop thru all the towns |
|
|
5223 | do |
|
|
5224 | { |
|
|
5225 | rc = sqlite3_step(stmt_d_1); |
|
|
5226 | switch (rc) |
|
|
5227 | { |
|
|
5228 | case SQLITE_DONE: |
|
|
5229 | break; |
|
|
5230 | case SQLITE_ROW: |
|
|
5231 | bid = sqlite3_column_int64(stmt_d_1, 0); |
|
|
5232 | tid = sqlite3_column_int64(stmt_d_1, 1); |
|
|
5233 | admin_l = sqlite3_column_int(stmt_d_1, 2); |
|
|
5234 | |
|
|
5235 | // fprintf(stderr, "bid=%lld tid=%lld amdin_level=%d\n", bid, tid, admin_l); |
|
|
5236 | |
|
|
5237 | if (count == 0) |
|
|
5238 | { |
|
|
5239 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5240 | } |
|
|
5241 | count++; |
|
|
5242 | |
|
|
5243 | sqlite3_bind_int64(stmt_d_2, 1, bid); |
|
|
5244 | sqlite3_bind_int64(stmt_d_2, 2, tid); |
|
|
5245 | sqlite3_bind_int(stmt_d_2, 3, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_l) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
|
|
5246 | sqlite3_step(stmt_d_2); |
7024 | sqlite3_step(stmt_mm_1); |
5247 | sqlite3_reset(stmt_d_2); |
7025 | fprintf(stderr, "purge_unused_towns:%lld\n", sqlite3_column_int64(stmt_mm_1, 0)); |
5248 | |
|
|
5249 | if (count > commit_after) |
|
|
5250 | { |
|
|
5251 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5252 | count = 0; |
|
|
5253 | } |
|
|
5254 | |
|
|
5255 | break; |
|
|
5256 | default: |
|
|
5257 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
5258 | break; |
|
|
5259 | } |
|
|
5260 | } |
|
|
5261 | while (rc == SQLITE_ROW); |
|
|
5262 | sqlite3_reset(stmt_d_1); |
7026 | sqlite3_reset(stmt_mm_1); |
5263 | |
7027 | |
5264 | retval = sqlite3_finalize(stmt_d_2); |
7028 | // SQL:fin: |
5265 | // fprintf(stderr, "fin:%d\n", retval); |
|
|
5266 | retval = sqlite3_finalize(stmt_d_1); |
7029 | retval8 = sqlite3_finalize(stmt_mm_1); |
5267 | // fprintf(stderr, "fin:%d\n", retval); |
7030 | fprintf_(stderr, "fin:%d\n", retval8); |
5268 | |
7031 | |
|
|
7032 | retval8 = sqlite3_exec(sql_handle, "delete from town where id not in (select town_id from way);", 0, 0, 0); |
|
|
7033 | fprintf_(stderr, "prep:%d\n", retval8); |
|
|
7034 | |
|
|
7035 | sql_counter = 0; |
5269 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
7036 | retval8 = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
5270 | |
7037 | fprintf_(stderr, "prep:%d\n", retval8); |
5271 | } |
7038 | } |
5272 | |
7039 | |
5273 | void assign_town_to_streets_by_boundary(GList *bl) |
7040 | void assign_town_to_country_by_manual_borders(GList *bl, GList *man_borders) |
5274 | { |
7041 | { |
5275 | long long nd; |
7042 | long long nd; |
5276 | long long wid; |
7043 | long long wid; |
5277 | long long town_rel_id; |
7044 | long long town_rel_id; |
5278 | int size; |
7045 | int size; |
… | |
… | |
5288 | long long town_count; |
7055 | long long town_count; |
5289 | long long town_processed_count; |
7056 | long long town_processed_count; |
5290 | int town_steps = 1; |
7057 | int town_steps = 1; |
5291 | int result = 0; |
7058 | int result = 0; |
5292 | struct boundary *bound_temp; |
7059 | struct boundary *bound_temp; |
|
|
7060 | int retval8; |
|
|
7061 | sqlite3_stmt *stmt_mm_2; |
|
|
7062 | struct coord c; |
|
|
7063 | long long dummy_town_id2 = 0; |
|
|
7064 | int commit_after = 20000; |
|
|
7065 | int count = 0; |
|
|
7066 | |
5293 | |
7067 | |
5294 | sql_counter = 0; |
7068 | sql_counter = 0; |
5295 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
7069 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
5296 | |
7070 | |
5297 | // number of towns in DB |
7071 | // number of towns in DB |
5298 | sqlite3_reset(stmt_town_sel002); |
7072 | sqlite3_reset(stmt_town_sel002); |
5299 | sqlite3_step(stmt_town_sel002); |
7073 | sqlite3_step(stmt_town_sel002); |
5300 | town_count = sqlite3_column_int64(stmt_town_sel002, 0); |
7074 | town_count = sqlite3_column_int64(stmt_town_sel002, 0); |
5301 | town_processed_count = 0; |
7075 | town_processed_count = 0; |
5302 | |
7076 | |
5303 | fprintf(stderr, "towns0: %lld/%lld\n", town_processed_count, town_count); |
7077 | fprintf(stderr, "towns0a: %lld/%lld\n", town_processed_count, town_count); |
|
|
7078 | |
|
|
7079 | if (town_count == 0) |
|
|
7080 | { |
|
|
7081 | sqlite3_reset(stmt_town_sel002); |
|
|
7082 | return; |
|
|
7083 | } |
|
|
7084 | |
|
|
7085 | retval8 = sqlite3_prepare_v2(sql_handle, "update town set border_id = ? where id = ?;", -1, &stmt_mm_2, NULL); |
|
|
7086 | fprintf_(stderr, "prep:%d\n", retval8); |
|
|
7087 | |
|
|
7088 | |
|
|
7089 | sql_counter = 0; |
|
|
7090 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7091 | |
|
|
7092 | if (town_count > 1000000) |
|
|
7093 | { |
|
|
7094 | town_steps = 500; |
|
|
7095 | } |
|
|
7096 | else if (town_count > 100000) |
|
|
7097 | { |
|
|
7098 | town_steps = 100; |
|
|
7099 | } |
|
|
7100 | else if (town_count > 10000) |
|
|
7101 | { |
|
|
7102 | town_steps = 10; |
|
|
7103 | } |
|
|
7104 | |
|
|
7105 | // DEBUG |
|
|
7106 | // town_steps = 1; |
|
|
7107 | // DEBUG |
|
|
7108 | |
|
|
7109 | // loop thru all the towns |
|
|
7110 | do |
|
|
7111 | { |
|
|
7112 | rc = sqlite3_step(stmt_town_sel001); |
|
|
7113 | switch (rc) |
|
|
7114 | { |
|
|
7115 | case SQLITE_DONE: |
|
|
7116 | break; |
|
|
7117 | case SQLITE_ROW: |
|
|
7118 | nd = sqlite3_column_int64(stmt_town_sel001, 0); |
|
|
7119 | town_rel_id = sqlite3_column_int64(stmt_town_sel001, 5); |
|
|
7120 | lat = sqlite3_column_double(stmt_town_sel001, 2); |
|
|
7121 | lon = sqlite3_column_double(stmt_town_sel001, 3); |
|
|
7122 | |
|
|
7123 | if (town_rel_id == -1) |
|
|
7124 | { |
|
|
7125 | if ((lat != 999) && (lon != 999)) |
|
|
7126 | { |
|
|
7127 | c.x = transform_from_geo_lon(lon); |
|
|
7128 | c.y = transform_from_geo_lat(lat); |
|
|
7129 | // check if c is inside manual country border |
|
|
7130 | dummy_town_id2 = osm_process_street_by_manual_country_borders(man_borders, &c); |
|
|
7131 | |
|
|
7132 | if (dummy_town_id2 != -1) |
|
|
7133 | { |
|
|
7134 | //fprintf(stderr, "== town_to_country_by_manual_borders: townid=%lld\n", nd); |
|
|
7135 | sqlite3_bind_int64(stmt_mm_2, 1, dummy_town_id2); // parent country rel id |
|
|
7136 | sqlite3_bind_int64(stmt_mm_2, 2, nd); // town id |
|
|
7137 | sqlite3_step(stmt_mm_2); |
|
|
7138 | sqlite3_reset(stmt_mm_2); |
|
|
7139 | } |
|
|
7140 | |
|
|
7141 | if (count == 0) |
|
|
7142 | { |
|
|
7143 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
7144 | } |
|
|
7145 | count++; |
|
|
7146 | |
|
|
7147 | if (count > commit_after) |
|
|
7148 | { |
|
|
7149 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7150 | count = 0; |
|
|
7151 | } |
|
|
7152 | } |
|
|
7153 | } |
|
|
7154 | break; |
|
|
7155 | default: |
|
|
7156 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7157 | break; |
|
|
7158 | } |
|
|
7159 | } |
|
|
7160 | while (rc == SQLITE_ROW); |
|
|
7161 | sqlite3_reset(stmt_town_sel001); |
|
|
7162 | |
|
|
7163 | // SQL:fin: |
|
|
7164 | rc = sqlite3_finalize(stmt_mm_2); |
|
|
7165 | fprintf_(stderr, "fin:%d\n", rc); |
|
|
7166 | |
|
|
7167 | sql_counter = 0; |
|
|
7168 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7169 | |
|
|
7170 | |
|
|
7171 | } |
|
|
7172 | |
|
|
7173 | |
|
|
7174 | void save_manual_country_borders_to_db(GList *man_borders) |
|
|
7175 | { |
|
|
7176 | GList *l = man_borders; |
|
|
7177 | while (l) |
|
|
7178 | { |
|
|
7179 | struct boundary_manual *b = l->data; |
|
|
7180 | |
|
|
7181 | // also save dummy id to border list, to be able to compare it later |
|
|
7182 | b->town_id = dummy_town_id; |
|
|
7183 | |
|
|
7184 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); // town id |
|
|
7185 | sqlite3_bind_int(stmt_town, 2, b->country->countryid); // country id |
|
|
7186 | sqlite3_bind_text(stmt_town, 3, b->country->names, -1, SQLITE_STATIC); // name |
|
|
7187 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + 2) * TOWN_BY_BOUNDARY_SIZE_FACTOR); // town size |
|
|
7188 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); // postal |
|
|
7189 | |
|
|
7190 | sqlite3_bind_double(stmt_town, 6, 999); // lat -> 999:exclude |
|
|
7191 | sqlite3_bind_double(stmt_town, 7, 999); // lon -> 999:exclude |
|
|
7192 | |
|
|
7193 | sqlite3_bind_int64(stmt_town, 8, -1); // border relation id |
|
|
7194 | sqlite3_step(stmt_town); |
|
|
7195 | sqlite3_reset(stmt_town); |
|
|
7196 | dummy_town_id--; |
|
|
7197 | |
|
|
7198 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7199 | |
|
|
7200 | l = g_list_next(l); |
|
|
7201 | } |
|
|
7202 | } |
|
|
7203 | |
|
|
7204 | void assign_streets_to_towns_by_manual_country_borders(GList *man_borders) |
|
|
7205 | { |
|
|
7206 | long long nd; |
|
|
7207 | int size; |
|
|
7208 | double lat; |
|
|
7209 | double lon; |
|
|
7210 | double lat_min; |
|
|
7211 | double lat_max; |
|
|
7212 | double lon_min; |
|
|
7213 | double lon_max; |
|
|
7214 | double temp; |
|
|
7215 | int rc; |
|
|
7216 | sqlite3_stmt *stmt_mm_1; |
|
|
7217 | sqlite3_stmt *stmt_mm_2; |
|
|
7218 | int retval9; |
|
|
7219 | int retval8; |
|
|
7220 | int street_steps; |
|
|
7221 | long long streets_processed_count; |
|
|
7222 | long long wid; |
|
|
7223 | struct coord c; |
|
|
7224 | char *wname; |
|
|
7225 | |
|
|
7226 | sql_counter = 0; |
|
|
7227 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7228 | |
|
|
7229 | |
|
|
7230 | retval9 = sqlite3_prepare_v2(sql_handle, "select w.lat, w.lon, w.id, w.name from way w where w.town_id='-1';", -1, &stmt_mm_1, NULL); |
|
|
7231 | fprintf_(stderr, "prep:%d\n", retval9); |
|
|
7232 | |
|
|
7233 | retval8 = sqlite3_prepare_v2(sql_handle, "update way set town_id = ? where id = ?;", -1, &stmt_mm_2, NULL); |
|
|
7234 | fprintf_(stderr, "prep:%d\n", retval8); |
|
|
7235 | |
|
|
7236 | street_steps = 1000; // set to better value!! |
|
|
7237 | streets_processed_count = 0; |
|
|
7238 | |
|
|
7239 | sql_counter = 0; |
|
|
7240 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7241 | |
|
|
7242 | // loop thru all the ways |
|
|
7243 | do |
|
|
7244 | { |
|
|
7245 | rc = sqlite3_step(stmt_mm_1); |
|
|
7246 | switch (rc) |
|
|
7247 | { |
|
|
7248 | case SQLITE_DONE: |
|
|
7249 | break; |
|
|
7250 | case SQLITE_ROW: |
|
|
7251 | lat = sqlite3_column_double(stmt_mm_1, 0); |
|
|
7252 | lon = sqlite3_column_double(stmt_mm_1, 1); |
|
|
7253 | wid = sqlite3_column_int64(stmt_mm_1, 2); |
|
|
7254 | wname = g_strdup_printf("%s", sqlite3_column_text(stmt_mm_1, 3)); |
|
|
7255 | |
|
|
7256 | // now update the ways |
|
|
7257 | if (sql_counter == 0) |
|
|
7258 | { |
|
|
7259 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
7260 | } |
|
|
7261 | |
|
|
7262 | c.x = transform_from_geo_lon(lon); |
|
|
7263 | c.y = transform_from_geo_lat(lat); |
|
|
7264 | nd = osm_process_street_by_manual_country_borders(man_borders, &c); |
|
|
7265 | |
|
|
7266 | streets_processed_count++; |
|
|
7267 | if ((streets_processed_count % street_steps) == 0) |
|
|
7268 | { |
|
|
7269 | fprintf_(stderr, "streets0: %lld\n", streets_processed_count); |
|
|
7270 | } |
|
|
7271 | |
|
|
7272 | if (nd != -1) |
|
|
7273 | { |
|
|
7274 | // fprintf(stderr, "== streets by manual_country_borders: way=%s townid=%lld\n", wname, nd); |
|
|
7275 | |
|
|
7276 | sqlite3_bind_int64(stmt_mm_2, 1, nd); |
|
|
7277 | sqlite3_bind_int64(stmt_mm_2, 2, wid); |
|
|
7278 | sqlite3_step(stmt_mm_2); |
|
|
7279 | sqlite3_reset(stmt_mm_2); |
|
|
7280 | |
|
|
7281 | sql_counter++; |
|
|
7282 | if (sql_counter > MAX_ROWS_WO_COMMIT_2a) |
|
|
7283 | { |
|
|
7284 | sql_counter = 0; |
|
|
7285 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7286 | } |
|
|
7287 | } |
|
|
7288 | |
|
|
7289 | if (wname) |
|
|
7290 | { |
|
|
7291 | g_free(wname); |
|
|
7292 | } |
|
|
7293 | |
|
|
7294 | break; |
|
|
7295 | default: |
|
|
7296 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7297 | break; |
|
|
7298 | } |
|
|
7299 | } |
|
|
7300 | while (rc == SQLITE_ROW); |
|
|
7301 | sqlite3_reset(stmt_mm_1); |
|
|
7302 | |
|
|
7303 | // SQL:fin: |
|
|
7304 | rc = sqlite3_finalize(stmt_mm_1); |
|
|
7305 | fprintf_(stderr, "fin:%d\n", rc); |
|
|
7306 | |
|
|
7307 | // SQL:fin: |
|
|
7308 | rc = sqlite3_finalize(stmt_mm_2); |
|
|
7309 | fprintf_(stderr, "fin:%d\n", rc); |
|
|
7310 | |
|
|
7311 | sql_counter = 0; |
|
|
7312 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7313 | |
|
|
7314 | } |
|
|
7315 | |
|
|
7316 | |
|
|
7317 | void copy_town_border_data() |
|
|
7318 | { |
|
|
7319 | long long bid; |
|
|
7320 | long long tid; |
|
|
7321 | int retval; |
|
|
7322 | int rc = 0; |
|
|
7323 | int commit_after = 20000; |
|
|
7324 | int count = 0; |
|
|
7325 | int admin_l = 99; |
|
|
7326 | |
|
|
7327 | sqlite3_stmt *stmt_d_1; |
|
|
7328 | sqlite3_stmt *stmt_d_2; |
|
|
7329 | retval = sqlite3_prepare_v2(sql_handle, "select border_id, id, admin_level from town2;", -1, &stmt_d_1, NULL); |
|
|
7330 | // fprintf(stderr, "prep:%d\n", retval); |
|
|
7331 | retval = sqlite3_prepare_v2(sql_handle, "update town set border_id = ?, size = ? where id = ?;", -1, &stmt_d_2, NULL); |
|
|
7332 | // fprintf(stderr, "prep:%d\n", retval); |
|
|
7333 | |
|
|
7334 | // loop thru all the towns |
|
|
7335 | do |
|
|
7336 | { |
|
|
7337 | rc = sqlite3_step(stmt_d_1); |
|
|
7338 | switch (rc) |
|
|
7339 | { |
|
|
7340 | case SQLITE_DONE: |
|
|
7341 | break; |
|
|
7342 | case SQLITE_ROW: |
|
|
7343 | bid = sqlite3_column_int64(stmt_d_1, 0); |
|
|
7344 | tid = sqlite3_column_int64(stmt_d_1, 1); |
|
|
7345 | admin_l = sqlite3_column_int(stmt_d_1, 2); |
|
|
7346 | |
|
|
7347 | // fprintf(stderr, "bid=%lld tid=%lld amdin_level=%d\n", bid, tid, admin_l); |
|
|
7348 | |
|
|
7349 | if (count == 0) |
|
|
7350 | { |
|
|
7351 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
7352 | } |
|
|
7353 | count++; |
|
|
7354 | |
|
|
7355 | sqlite3_bind_int64(stmt_d_2, 1, bid); |
|
|
7356 | sqlite3_bind_int64(stmt_d_2, 2, tid); |
|
|
7357 | sqlite3_bind_int(stmt_d_2, 3, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_l) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
|
|
7358 | sqlite3_step(stmt_d_2); |
|
|
7359 | sqlite3_reset(stmt_d_2); |
|
|
7360 | |
|
|
7361 | if (count > commit_after) |
|
|
7362 | { |
|
|
7363 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7364 | count = 0; |
|
|
7365 | } |
|
|
7366 | |
|
|
7367 | break; |
|
|
7368 | default: |
|
|
7369 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7370 | break; |
|
|
7371 | } |
|
|
7372 | } |
|
|
7373 | while (rc == SQLITE_ROW); |
|
|
7374 | sqlite3_reset(stmt_d_1); |
|
|
7375 | |
|
|
7376 | retval = sqlite3_finalize(stmt_d_2); |
|
|
7377 | // fprintf(stderr, "fin:%d\n", retval); |
|
|
7378 | retval = sqlite3_finalize(stmt_d_1); |
|
|
7379 | // fprintf(stderr, "fin:%d\n", retval); |
|
|
7380 | |
|
|
7381 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7382 | |
|
|
7383 | } |
|
|
7384 | |
|
|
7385 | void assign_town_to_streets_by_boundary(GList *bl, GList *man_borders) |
|
|
7386 | { |
|
|
7387 | long long nd; |
|
|
7388 | long long wid; |
|
|
7389 | long long town_rel_id; |
|
|
7390 | int size; |
|
|
7391 | double lat; |
|
|
7392 | double lon; |
|
|
7393 | double temp; |
|
|
7394 | double lat_min; |
|
|
7395 | double lat_max; |
|
|
7396 | double lon_min; |
|
|
7397 | double lon_max; |
|
|
7398 | int rc; |
|
|
7399 | int rc2; |
|
|
7400 | long long town_count; |
|
|
7401 | long long town_processed_count; |
|
|
7402 | int town_steps = 1; |
|
|
7403 | int result = 0; |
|
|
7404 | struct boundary *bound_temp; |
|
|
7405 | |
|
|
7406 | sql_counter = 0; |
|
|
7407 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7408 | |
|
|
7409 | // number of towns in DB |
|
|
7410 | sqlite3_reset(stmt_town_sel002); |
|
|
7411 | sqlite3_step(stmt_town_sel002); |
|
|
7412 | town_count = sqlite3_column_int64(stmt_town_sel002, 0); |
|
|
7413 | town_processed_count = 0; |
|
|
7414 | |
|
|
7415 | fprintf(stderr, "towns0b: %lld/%lld\n", town_processed_count, town_count); |
5304 | |
7416 | |
5305 | if (town_count == 0) |
7417 | if (town_count == 0) |
5306 | { |
7418 | { |
5307 | sqlite3_reset(stmt_town_sel002); |
7419 | sqlite3_reset(stmt_town_sel002); |
5308 | return; |
7420 | return; |
… | |
… | |
5346 | |
7458 | |
5347 | GList *match_town = NULL; |
7459 | GList *match_town = NULL; |
5348 | GList *l = bl; |
7460 | GList *l = bl; |
5349 | int has_found = 0; |
7461 | int has_found = 0; |
5350 | |
7462 | |
5351 | if (town_rel_id != 0) |
7463 | if ((town_rel_id != 0) && (town_rel_id != -1)) |
5352 | { |
7464 | { |
5353 | // fprintf(stderr ,"processing town name:%s id:%lld border_id:%lld\n", sqlite3_column_text(stmt_town_sel001, 4), nd, town_rel_id); |
7465 | //fprintf(stderr ,"processing town name:%s id:%lld border_id:%lld\n", sqlite3_column_text(stmt_town_sel001, 4), nd, town_rel_id); |
5354 | |
7466 | |
5355 | while (l) |
7467 | while (l) |
5356 | { |
7468 | { |
5357 | struct boundary *b = l->data; |
7469 | struct boundary *b = l->data; |
5358 | //fprintf(stderr, "bid=%lld tid=%lld\n", item_bin_get_relationid(b->ib), town_rel_id); |
7470 | //fprintf(stderr, "bid=%lld tid=%lld\n", item_bin_get_relationid(b->ib), town_rel_id); |
… | |
… | |
5399 | |
7511 | |
5400 | struct coord c; |
7512 | struct coord c; |
5401 | c.x = transform_from_geo_lon(lon); |
7513 | c.x = transform_from_geo_lon(lon); |
5402 | c.y = transform_from_geo_lat(lat); |
7514 | c.y = transform_from_geo_lat(lat); |
5403 | |
7515 | |
5404 | //fprintf(stderr,"== street by boundary == x:%d y:%d ==\n", c.x, c.y); |
7516 | //fprintf(stderr,"== street by boundary == x:%d y:%d name:%s ==\n", c.x, c.y, sqlite3_column_text(stmt_way3a, 3)); |
5405 | |
7517 | |
5406 | if (town_rel_id != 0) |
7518 | if (town_rel_id != 0) |
5407 | { |
7519 | { |
5408 | // fprintf(stderr, "town:%lld\n", nd); |
7520 | //fprintf(stderr, "town:%lld\n", nd); |
5409 | // fprintf(stderr,"== street by boundary == x:%d y:%d ==\n", c.x, c.y); |
7521 | //fprintf(stderr,"== street by boundary == x:%d y:%d ==\n", c.x, c.y); |
5410 | result = osm_process_street_by_boundary(match_town, nd, town_rel_id, &c); |
7522 | result = osm_process_street_by_boundary(match_town, nd, town_rel_id, &c); |
5411 | if (result == 1) |
7523 | if (result == 1) |
5412 | { |
7524 | { |
5413 | //fprintf(stderr,"== street by boundary == wid:%lld townid:%lld ==\n", wid, nd); |
7525 | //fprintf(stderr,"== street by boundary == wid:%lld townid:%lld ==\n", wid, nd); |
5414 | // write "town id" to "way" |
7526 | // write "town id" to "way" |
… | |
… | |
5457 | } |
7569 | } |
5458 | |
7570 | |
5459 | town_processed_count++; |
7571 | town_processed_count++; |
5460 | if ((town_processed_count % town_steps) == 0) |
7572 | if ((town_processed_count % town_steps) == 0) |
5461 | { |
7573 | { |
5462 | fprintf(stderr, "towns0: %lld/%lld\n", town_processed_count, town_count); |
7574 | fprintf_(stderr, "towns0b: %lld/%lld\n", town_processed_count, town_count); |
5463 | } |
7575 | } |
5464 | |
7576 | |
5465 | break; |
7577 | break; |
5466 | default: |
7578 | default: |
5467 | fprintf(stderr, "SQL Error: %d\n", rc); |
7579 | fprintf(stderr, "SQL Error: %d\n", rc); |
… | |
… | |
5541 | case SQLITE_ROW: |
7653 | case SQLITE_ROW: |
5542 | nd = sqlite3_column_int64(stmt_town_sel001, 0); |
7654 | nd = sqlite3_column_int64(stmt_town_sel001, 0); |
5543 | size = sqlite3_column_int(stmt_town_sel001, 1); |
7655 | size = sqlite3_column_int(stmt_town_sel001, 1); |
5544 | lat = sqlite3_column_double(stmt_town_sel001, 2); |
7656 | lat = sqlite3_column_double(stmt_town_sel001, 2); |
5545 | lon = sqlite3_column_double(stmt_town_sel001, 3); |
7657 | lon = sqlite3_column_double(stmt_town_sel001, 3); |
5546 | //fprintf(stderr ,"processing (size:%d) town name:%s id:%lld\n", size, sqlite3_column_text(stmt_town_sel001, 4), nd); |
|
|
5547 | |
7658 | |
5548 | // now update the ways |
7659 | if ((lat == 999) && (lon == 999)) |
5549 | if (sql_counter == 0) |
|
|
5550 | { |
7660 | { |
5551 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
7661 | // this should be excluded!! |
5552 | } |
7662 | } |
5553 | |
7663 | else |
5554 | sqlite3_bind_int64(stmt_way3, 1, nd); |
|
|
5555 | |
|
|
5556 | if ((pass_num == 2) && (size > 0)) |
|
|
5557 | { |
7664 | { |
|
|
7665 | //fprintf(stderr ,"processing (size:%d) town name:%s id:%lld\n", size, sqlite3_column_text(stmt_town_sel001, 4), nd); |
|
|
7666 | |
|
|
7667 | // now update the ways |
|
|
7668 | if (sql_counter == 0) |
|
|
7669 | { |
|
|
7670 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
7671 | } |
|
|
7672 | |
|
|
7673 | sqlite3_bind_int64(stmt_way3, 1, nd); |
|
|
7674 | |
|
|
7675 | if ((pass_num == 2) && (size > 0)) |
|
|
7676 | { |
5558 | size = size * 3; |
7677 | size = size * 3; |
5559 | } |
7678 | } |
5560 | |
7679 | |
5561 | temp = ((double) size) / 100000; |
7680 | temp = ((double) size) / 100000; |
5562 | lat_min = lat - temp; |
7681 | lat_min = lat - temp; |
5563 | lat_max = lat + temp; |
7682 | lat_max = lat + temp; |
5564 | lon_min = lon - temp; |
7683 | lon_min = lon - temp; |
5565 | lon_max = lon + temp; |
7684 | lon_max = lon + temp; |
5566 | sqlite3_bind_double(stmt_way3, 2, lat_min); |
7685 | sqlite3_bind_double(stmt_way3, 2, lat_min); |
5567 | sqlite3_bind_double(stmt_way3, 3, lat_max); |
7686 | sqlite3_bind_double(stmt_way3, 3, lat_max); |
5568 | sqlite3_bind_double(stmt_way3, 4, lon_min); |
7687 | sqlite3_bind_double(stmt_way3, 4, lon_min); |
5569 | sqlite3_bind_double(stmt_way3, 5, lon_max); |
7688 | sqlite3_bind_double(stmt_way3, 5, lon_max); |
5570 | //fprintf(stderr, "size korr:%f %f %f %f %f\n", temp, lat_min, lat_max, lon_min, lon_max); |
7689 | //fprintf(stderr, "size korr:%f %f %f %f %f\n", temp, lat_min, lat_max, lon_min, lon_max); |
5571 | |
7690 | |
5572 | sqlite3_step(stmt_way3); |
7691 | sqlite3_step(stmt_way3); |
5573 | sqlite3_reset(stmt_way3); |
7692 | sqlite3_reset(stmt_way3); |
5574 | |
7693 | |
5575 | sql_counter++; |
7694 | sql_counter++; |
5576 | if (sql_counter > MAX_ROWS_WO_COMMIT_2a) |
7695 | if (sql_counter > MAX_ROWS_WO_COMMIT_2a) |
5577 | { |
7696 | { |
5578 | sql_counter = 0; |
7697 | sql_counter = 0; |
5579 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
7698 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
5580 | } |
7699 | } |
5581 | town_processed_count++; |
7700 | town_processed_count++; |
5582 | |
7701 | |
5583 | if ((town_processed_count % town_steps) == 0) |
7702 | if ((town_processed_count % town_steps) == 0) |
5584 | { |
7703 | { |
5585 | fprintf(stderr, "towns1-%d: %lld/%lld\n", pass_num, town_processed_count, town_count); |
7704 | fprintf_(stderr, "towns1-%d: %lld/%lld\n", pass_num, town_processed_count, town_count); |
|
|
7705 | } |
5586 | } |
7706 | } |
5587 | |
7707 | |
5588 | break; |
7708 | break; |
5589 | default: |
7709 | default: |
5590 | fprintf(stderr, "SQL Error: %d\n", rc); |
7710 | fprintf(stderr, "SQL Error: %d\n", rc); |
… | |
… | |
5608 | } |
7728 | } |
5609 | |
7729 | |
5610 | return 0; |
7730 | return 0; |
5611 | } |
7731 | } |
5612 | |
7732 | |
5613 | GList* osm_process_towns(FILE *in, FILE *coords, FILE *boundaries, FILE *ways) |
7733 | GList* osm_process_towns(FILE *in, FILE *coords, FILE *boundaries, FILE *ways, GList *bl_manual) |
5614 | { |
7734 | { |
5615 | struct item_bin *ib; |
7735 | struct item_bin *ib = NULL; |
5616 | GList *bl = NULL; |
7736 | GList *bl = NULL; |
5617 | struct attr attrs[10]; |
7737 | struct attr attrs[10]; |
5618 | time_t start_tt, end_tt; |
7738 | time_t start_tt, end_tt; |
5619 | double diff_tt; |
7739 | double diff_tt; |
5620 | double diff2_tt; |
7740 | double diff2_tt; |
5621 | long long size_in; |
7741 | long long size_in; |
5622 | long long pos_in; |
7742 | long long pos_in; |
5623 | struct node_lat_lon node_coords; |
7743 | struct node_lat_lon node_coords; |
|
|
7744 | FILE *file_coords_for_map = NULL; |
|
|
7745 | FILE *file_coords_for_map2 = NULL; |
5624 | |
7746 | |
5625 | if (debug_itembin(1)) |
7747 | if (debug_itembin(1)) |
5626 | { |
7748 | { |
5627 | fprintf(stderr, "osm_process_towns == START ==\n"); |
7749 | fprintf(stderr, "osm_process_towns == START ==\n"); |
|
|
7750 | } |
|
|
7751 | |
|
|
7752 | if (!global_less_verbose) |
|
|
7753 | { |
|
|
7754 | file_coords_for_map = fopen("towns_no_country.coords.txt", "wb"); |
|
|
7755 | fprintf(file_coords_for_map, "-175.0|85.0|-175_85\n"); |
|
|
7756 | fprintf(file_coords_for_map, "175|85.0|175_85\n"); |
|
|
7757 | fprintf(file_coords_for_map, "-175.0|-85.0|-175_-85\n"); |
|
|
7758 | fprintf(file_coords_for_map, "175.0|-85.0|175_-85\n"); |
|
|
7759 | |
|
|
7760 | file_coords_for_map2 = fopen("towns_no_country.coords_names.txt", "wb"); |
|
|
7761 | fprintf(file_coords_for_map2, "-175.0|85.0|-175_85\n"); |
|
|
7762 | fprintf(file_coords_for_map2, "175|85.0|175_85\n"); |
|
|
7763 | fprintf(file_coords_for_map2, "-175.0|-85.0|-175_-85\n"); |
|
|
7764 | fprintf(file_coords_for_map2, "175.0|-85.0|175_-85\n"); |
5628 | } |
7765 | } |
5629 | |
7766 | |
5630 | //fprintf(stderr,"osm_process_towns == PB 001 %p,%p ==\n", boundaries, ways); |
7767 | //fprintf(stderr,"osm_process_towns == PB 001 %p,%p ==\n", boundaries, ways); |
5631 | |
7768 | |
5632 | time(&start_tt); |
7769 | time(&start_tt); |
… | |
… | |
5691 | } |
7828 | } |
5692 | } |
7829 | } |
5693 | |
7830 | |
5694 | if (!result) |
7831 | if (!result) |
5695 | { |
7832 | { |
5696 | //char *name=item_bin_get_attr(ib, attr_town_name, NULL); |
|
|
5697 | //fprintf(stderr,"== town by boundary == t:%s ==\n", name); |
|
|
5698 | |
|
|
5699 | result = osm_process_town_by_boundary(bl, ib, c, attrs); |
7833 | result = osm_process_town_by_boundary(bl, ib, c, attrs); |
5700 | if (result) // DEBUG |
7834 | if (result) // DEBUG |
5701 | { |
7835 | { |
|
|
7836 | if (debug_itembin(ib)) |
|
|
7837 | { |
|
|
7838 | char *name=item_bin_get_attr(ib, attr_town_name, NULL); |
|
|
7839 | //fprintf(stderr,"== town by boundary == t:%s ==\n", name); |
5702 | //fprintf(stderr,"== town by boundary == country_id:%d country_name:%s ==\n", result->countryid, result->names); |
7840 | //fprintf(stderr,"== town by boundary == country_id:%d country_name:%s townname:%s ==\n", result->countryid, result->names, name); |
|
|
7841 | } |
5703 | } |
7842 | } |
5704 | } |
7843 | } |
5705 | |
7844 | |
5706 | if (!result) |
7845 | if (!result) |
5707 | { |
7846 | { |
… | |
… | |
5711 | } |
7850 | } |
5712 | result = osm_process_town_by_is_in(ib, is_in); |
7851 | result = osm_process_town_by_is_in(ib, is_in); |
5713 | if (result) // DEBUG |
7852 | if (result) // DEBUG |
5714 | { |
7853 | { |
5715 | // fprintf(stderr,"== town by is_in == country_id:%d country_name:%s ==\n", result->countryid, result->names); |
7854 | // fprintf(stderr,"== town by is_in == country_id:%d country_name:%s ==\n", result->countryid, result->names); |
|
|
7855 | } |
|
|
7856 | } |
|
|
7857 | |
|
|
7858 | |
|
|
7859 | // ok as a last resort check in manual country borders |
|
|
7860 | if (!result) |
|
|
7861 | { |
|
|
7862 | result = osm_process_town_by_manual_country_borders(bl_manual, c); |
|
|
7863 | if (result) |
|
|
7864 | { |
|
|
7865 | if (debug_itembin(ib)) |
|
|
7866 | { |
|
|
7867 | char *name=item_bin_get_attr(ib, attr_town_name, NULL); |
|
|
7868 | fprintf(stderr,"== town by manual_country_borders == country_id:%d country_name:%s town_name=%s ==\n", result->countryid, result->names, name); |
|
|
7869 | } |
5716 | } |
7870 | } |
5717 | } |
7871 | } |
5718 | |
7872 | |
5719 | if (!result && unknown_country) |
7873 | if (!result && unknown_country) |
5720 | { |
7874 | { |
… | |
… | |
5737 | fprintf(stderr, "== create: country_%d.unsorted.tmp == FILEP: %p ==\n", result->countryid, result->file); |
7891 | fprintf(stderr, "== create: country_%d.unsorted.tmp == FILEP: %p ==\n", result->countryid, result->file); |
5738 | } |
7892 | } |
5739 | |
7893 | |
5740 | g_free(name); |
7894 | g_free(name); |
5741 | } |
7895 | } |
|
|
7896 | |
|
|
7897 | // generate file to plot coords on world map ------------------- |
|
|
7898 | if (result->countryid == 999) |
|
|
7899 | { |
|
|
7900 | if (!global_less_verbose) |
|
|
7901 | { |
|
|
7902 | // format: lon|lat|[townname]\n |
|
|
7903 | fprintf(file_coords_for_map, "%lf|%lf|\n", transform_to_geo_lon(c->x), transform_to_geo_lat(c->y)); |
|
|
7904 | |
|
|
7905 | char *town_name_tmp = item_bin_get_attr(ib, attr_town_name, NULL); |
|
|
7906 | fprintf(file_coords_for_map2, "%lf|%lf|%s\n", transform_to_geo_lon(c->x), transform_to_geo_lat(c->y), town_name_tmp); |
|
|
7907 | } |
|
|
7908 | } |
|
|
7909 | // generate file to plot coords on world map ------------------- |
5742 | |
7910 | |
5743 | if (result->file) |
7911 | if (result->file) |
5744 | { |
7912 | { |
5745 | long long *nodeid; |
7913 | long long *nodeid; |
5746 | long long nd_id = item_bin_get_nodeid(ib); |
7914 | long long nd_id = item_bin_get_nodeid(ib); |
… | |
… | |
5861 | time(&end_tt); |
8029 | time(&end_tt); |
5862 | diff_tt = difftime(end_tt, start_tt); |
8030 | diff_tt = difftime(end_tt, start_tt); |
5863 | convert_to_human_time(diff_tt, outstring); |
8031 | convert_to_human_time(diff_tt, outstring); |
5864 | convert_to_human_bytes(pos_in, outstring2); |
8032 | convert_to_human_bytes(pos_in, outstring2); |
5865 | convert_to_human_bytes(size_in, outstring3); |
8033 | convert_to_human_bytes(size_in, outstring3); |
5866 | fprintf(stderr, "-RUNTIME-LOOP-TOWN: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3); |
8034 | fprintf_(stderr, "-RUNTIME-LOOP-TOWN: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3); |
5867 | if (pos_in > 0) |
8035 | if (pos_in > 0) |
5868 | { |
8036 | { |
5869 | double eta_time = ((diff_tt / (pos_in)) * (size_in)) - diff_tt; |
8037 | double eta_time = ((diff_tt / (pos_in)) * (size_in)) - diff_tt; |
5870 | convert_to_human_time(eta_time, outstring); |
8038 | convert_to_human_time(eta_time, outstring); |
5871 | fprintf(stderr, "-RUNTIME-LOOP-TOWN: %s left\n", outstring); |
8039 | fprintf_(stderr, "-RUNTIME-LOOP-TOWN: %s left\n", outstring); |
5872 | } |
8040 | } |
5873 | } |
8041 | } |
5874 | } |
8042 | } |
5875 | |
8043 | |
5876 | if (debug_itembin(1)) |
8044 | if (debug_itembin(1)) |
5877 | { |
8045 | { |
5878 | fprintf(stderr, "osm_process_towns == END ==\n"); |
8046 | fprintf(stderr, "osm_process_towns == END ==\n"); |
|
|
8047 | } |
|
|
8048 | |
|
|
8049 | if (!global_less_verbose) |
|
|
8050 | { |
|
|
8051 | fclose(file_coords_for_map); |
|
|
8052 | fclose(file_coords_for_map2); |
5879 | } |
8053 | } |
5880 | |
8054 | |
5881 | return bl; |
8055 | return bl; |
5882 | |
8056 | |
5883 | } |
8057 | } |
… | |
… | |
5953 | int count, interval, p; |
8127 | int count, interval, p; |
5954 | void *p_tmp; |
8128 | void *p_tmp; |
5955 | int rr; |
8129 | int rr; |
5956 | size_t data_size2 = sizeof(int); |
8130 | size_t data_size2 = sizeof(int); |
5957 | |
8131 | |
5958 | fprintf(stderr, "seek_to_way ---\n"); |
8132 | fprintf_(stderr, "seek_to_way ---\n"); |
5959 | |
8133 | |
5960 | if (way_hash_cfu) |
8134 | if (way_hash_cfu) |
5961 | { |
8135 | { |
5962 | //if (!(g_hash_table_lookup_extended(way_hash, (gpointer) (long) wayid, NULL, (gpointer) & offset))) |
8136 | //if (!(g_hash_table_lookup_extended(way_hash, (gpointer) (long) wayid, NULL, (gpointer) & offset))) |
5963 | //{ |
8137 | //{ |
… | |
… | |
6099 | count = 1; |
8273 | count = 1; |
6100 | } |
8274 | } |
6101 | else |
8275 | else |
6102 | { |
8276 | { |
6103 | count = 2; |
8277 | count = 2; |
|
|
8278 | } |
|
|
8279 | |
6104 | }turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count); |
8280 | turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count); |
6105 | turn_restriction->c[type][turn_restriction->c_count[type]++] = c[0]; |
8281 | turn_restriction->c[type][turn_restriction->c_count[type]++] = c[0]; |
|
|
8282 | |
6106 | if (count > 1) |
8283 | if (count > 1) |
6107 | { |
8284 | { |
6108 | turn_restriction->c[type][turn_restriction->c_count[type]++] = c[ccount - 1]; |
8285 | turn_restriction->c[type][turn_restriction->c_count[type]++] = c[ccount - 1]; |
6109 | } |
8286 | } |
6110 | } |
8287 | } |
… | |
… | |
6311 | |
8488 | |
6312 | static void node_ref_way(osmid node, int local_thread_num) |
8489 | static void node_ref_way(osmid node, int local_thread_num) |
6313 | { |
8490 | { |
6314 | struct node_item *ni; |
8491 | struct node_item *ni; |
6315 | ni = node_item_get_fast(node, local_thread_num); |
8492 | ni = node_item_get_fast(node, local_thread_num); |
|
|
8493 | |
6316 | if (ni) |
8494 | if (ni) |
6317 | { |
8495 | { |
|
|
8496 | // fprintf(stderr, "node id=%lld ref=%d\n", node, (ni->ref_way + 1)); |
6318 | ni->ref_way++; |
8497 | ni->ref_way++; |
6319 | } |
8498 | } |
6320 | } |
8499 | } |
6321 | |
8500 | |
6322 | static void nodes_ref_item_bin(struct item_bin *ib, int local_thread_num, osmid this_way_id) |
8501 | static void nodes_ref_item_bin(struct item_bin *ib, int local_thread_num, osmid this_way_id) |
6323 | { |
8502 | { |
6324 | int i; |
8503 | int i; |
|
|
8504 | int *node_num_offset; |
|
|
8505 | int offset = 0; |
6325 | osmid way_node; |
8506 | osmid way_node; |
6326 | struct coord *c = (struct coord *) (ib + 1); // set pointer to coord struct of this item |
8507 | struct coord *c = (struct coord *) (ib + 1); // set pointer to coord struct of this item |
|
|
8508 | |
6327 | for (i = 0; i < ib->clen / 2; i++) |
8509 | for (i = 0; i < ib->clen / 2; i++) |
6328 | { |
8510 | { |
|
|
8511 | // fprintf(stderr, "1 i=%d this_way_id=%lld\n", i, this_way_id); |
|
|
8512 | |
|
|
8513 | // offset for split cycleways! |
|
|
8514 | node_num_offset = item_bin_get_attr(ib, attr_debugsplitway, NULL); |
|
|
8515 | |
|
|
8516 | if (node_num_offset) |
|
|
8517 | { |
|
|
8518 | offset = (int)*node_num_offset; |
|
|
8519 | } |
|
|
8520 | |
6329 | way_node = get_waynode_num(this_way_id, i, local_thread_num); |
8521 | way_node = get_waynode_num(this_way_id, (i + offset), local_thread_num); |
|
|
8522 | // fprintf(stderr, "2 ref2=%lld this_way_id=%lld offset=%d\n", way_node, this_way_id, offset); |
6330 | node_ref_way(way_node, local_thread_num); |
8523 | node_ref_way(way_node, local_thread_num); |
6331 | //fprintf(stderr, "ref2=%lld this_way_id=%lld\n", way_node, this_way_id); |
8524 | // fprintf(stderr, "3 ref2=%lld this_way_id=%lld\n", way_node, this_way_id); |
6332 | } |
8525 | } |
6333 | |
8526 | |
6334 | //fprintf(stderr,"********DUMP rw ***********\n"); |
8527 | //fprintf(stderr,"********DUMP rw ***********\n"); |
6335 | //dump_itembin(ib); |
8528 | // dump_itembin(ib); |
6336 | //fprintf(stderr,"********DUMP rw ***********\n"); |
8529 | //fprintf(stderr,"********DUMP rw ***********\n"); |
6337 | |
|
|
6338 | } |
8530 | } |
6339 | |
8531 | |
6340 | osmid get_waynode_num(osmid way_id, int coord_num, int local_thread_num) |
8532 | osmid get_waynode_num(osmid way_id, int coord_num, int local_thread_num) |
6341 | { |
8533 | { |
6342 | int rc2; |
8534 | int rc2; |
… | |
… | |
6350 | if (last_seek_wayid[local_thread_num] != way_id) |
8542 | if (last_seek_wayid[local_thread_num] != way_id) |
6351 | { |
8543 | { |
6352 | |
8544 | |
6353 | last_seek_wayid[local_thread_num] = way_id; |
8545 | last_seek_wayid[local_thread_num] = way_id; |
6354 | |
8546 | |
6355 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
8547 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
6356 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
8548 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
6357 | { |
8549 | { |
6358 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
8550 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
6359 | { |
8551 | { |
6360 | #endif |
8552 | #endif |
6361 | st = stmt_sel0012_tt[local_thread_num]; |
8553 | st = stmt_sel0012_tt[local_thread_num]; |
6362 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
8554 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
6363 | } |
8555 | } |
6364 | else |
8556 | else |
6365 | { |
8557 | { |
6366 | st = stmt_sel0012b_tt[local_thread_num]; |
8558 | st = stmt_sel0012b_tt[local_thread_num]; |
6367 | } |
8559 | } |
… | |
… | |
6375 | else |
8567 | else |
6376 | { |
8568 | { |
6377 | st = stmt_sel0012__2b_tt[local_thread_num]; |
8569 | st = stmt_sel0012__2b_tt[local_thread_num]; |
6378 | } |
8570 | } |
6379 | } |
8571 | } |
6380 | #endif |
8572 | #endif |
6381 | |
8573 | |
6382 | sqlite3_bind_int64(st, 1, way_id); |
8574 | sqlite3_bind_int64(st, 1, way_id); |
6383 | sqlite3_bind_int(st, 2, (int)1); |
8575 | sqlite3_bind_int(st, 2, (int)1); |
6384 | |
8576 | |
6385 | // execute the statement |
8577 | // execute the statement |
6386 | rc2 = sqlite3_step(st); |
8578 | rc2 = sqlite3_step(st); |
|
|
8579 | |
6387 | switch (rc2) |
8580 | switch (rc2) |
6388 | { |
8581 | { |
6389 | case SQLITE_DONE: |
8582 | case SQLITE_DONE: |
6390 | break; |
8583 | break; |
6391 | case SQLITE_ROW: |
8584 | case SQLITE_ROW: |
… | |
… | |
6418 | else if ((osmid)nd > 4994968164L) |
8611 | else if ((osmid)nd > 4994968164L) |
6419 | { |
8612 | { |
6420 | fprintf(stderr, "**ERROR** at fread 002b: wayid:%lld count=%d w_node=%lld\n", way_id, coord_num, (osmid)nd); |
8613 | fprintf(stderr, "**ERROR** at fread 002b: wayid:%lld count=%d w_node=%lld\n", way_id, coord_num, (osmid)nd); |
6421 | } |
8614 | } |
6422 | |
8615 | |
|
|
8616 | last_seekpos_waynode[local_thread_num] = seekpos_waynode2 + sizeof(osmid); |
|
|
8617 | //fprintf(stderr, "get_waynode_num:result node=%lld last_seekpos_waynode=%lld\n", nd, last_seekpos_waynode[local_thread_num]); |
|
|
8618 | |
|
|
8619 | return nd; |
|
|
8620 | } |
|
|
8621 | |
|
|
8622 | |
|
|
8623 | osmid get_waynode_num_have_seekpos(osmid way_id, int coord_num, int local_thread_num, off_t seek_pos) |
|
|
8624 | { |
|
|
8625 | int rc2; |
|
|
8626 | sqlite3_stmt *st; |
|
|
8627 | osmid nd; |
|
|
8628 | long long seekpos_waynode2; |
|
|
8629 | #define __USE_WAYNODEFILE_CACHE__ 1 |
|
|
8630 | |
|
|
8631 | //fprintf(stderr, "get_waynode_num:w=%lld cnum=%d\n", way_id, (coord_num + 1)); |
|
|
8632 | |
|
|
8633 | if (last_seek_wayid[local_thread_num] != way_id) |
|
|
8634 | { |
|
|
8635 | last_seek_wayid[local_thread_num] = way_id; |
|
|
8636 | } |
|
|
8637 | |
|
|
8638 | seekpos_waynode[local_thread_num] = seek_pos; |
|
|
8639 | seekpos_waynode2 = seekpos_waynode[local_thread_num] + (sizeof(osmid) * coord_num); // seek to coord in way |
|
|
8640 | |
|
|
8641 | if ((! __USE_WAYNODEFILE_CACHE__) || (seekpos_waynode2 != last_seekpos_waynode[local_thread_num])) |
|
|
8642 | { |
|
|
8643 | //fprintf(stderr, "w seek3 seekpos_waynode=%lld last_seekpos_waynode=%lld\n", seekpos_waynode[local_thread_num], last_seekpos_waynode[local_thread_num]); |
|
|
8644 | fseeko(ways_ref_file_thread[local_thread_num], (off_t)seekpos_waynode2, SEEK_SET); |
|
|
8645 | } |
|
|
8646 | //else |
|
|
8647 | //{ |
|
|
8648 | // fprintf(stderr, "w seek3:NO SEEK\n"); |
|
|
8649 | //} |
|
|
8650 | |
|
|
8651 | int fret = (int)fread(&nd, sizeof(osmid), 1, ways_ref_file_thread[local_thread_num]); |
|
|
8652 | if (fret == 0) |
|
|
8653 | { |
|
|
8654 | fprintf(stderr, "**ERROR** at fread 002b: wayid:%lld count=%d\n", way_id, coord_num); |
|
|
8655 | } |
|
|
8656 | else if ((osmid)nd > 4994968164L) |
|
|
8657 | { |
|
|
8658 | fprintf(stderr, "**ERROR** at fread 002b: wayid:%lld count=%d w_node=%lld\n", way_id, coord_num, (osmid)nd); |
|
|
8659 | } |
|
|
8660 | |
6423 | |
8661 | |
6424 | last_seekpos_waynode[local_thread_num] = seekpos_waynode2 + sizeof(osmid); |
8662 | last_seekpos_waynode[local_thread_num] = seekpos_waynode2 + sizeof(osmid); |
6425 | // fprintf(stderr, "get_waynode_num:result node=%lld last_seekpos_waynode=%lld\n", nd, last_seekpos_waynode[local_thread_num]); |
8663 | // fprintf(stderr, "get_waynode_num:result node=%lld last_seekpos_waynode=%lld\n", nd, last_seekpos_waynode[local_thread_num]); |
6426 | |
8664 | |
6427 | return nd; |
8665 | return nd; |
6428 | } |
8666 | } |
|
|
8667 | |
6429 | |
8668 | |
6430 | void add_waynode_to_db(osmid ref, int c_count) |
8669 | void add_waynode_to_db(osmid ref, int c_count) |
6431 | { |
8670 | { |
6432 | // ------- save way node to SQL db ------------ |
8671 | // ------- save way node to SQL db ------------ |
6433 | #ifdef MAPTOOL_USE_SQL |
8672 | #ifdef MAPTOOL_USE_SQL |
… | |
… | |
6501 | } |
8740 | } |
6502 | #endif |
8741 | #endif |
6503 | // ------- save way node to SQL db ------------ |
8742 | // ------- save way node to SQL db ------------ |
6504 | |
8743 | |
6505 | |
8744 | |
6506 | // fprintf(stderr, "osm_add_nd:FIN\n"); |
|
|
6507 | |
|
|
6508 | } |
8745 | } |
6509 | |
8746 | |
6510 | void osm_add_nd(osmid ref) |
8747 | void osm_add_nd(osmid ref) |
6511 | { |
8748 | { |
6512 | // SET_REF(&coord_buffer[coord_count], ref); |
8749 | // SET_REF(&coord_buffer[coord_count], ref); |
… | |
… | |
6601 | last_seekpos_waynode[local_thread_num] = -1; |
8838 | last_seekpos_waynode[local_thread_num] = -1; |
6602 | last_seek_wayid[local_thread_num] = -1; |
8839 | last_seek_wayid[local_thread_num] = -1; |
6603 | fseeko(ways_ref_file_thread[local_thread_num], (off_t)0, SEEK_SET); |
8840 | fseeko(ways_ref_file_thread[local_thread_num], (off_t)0, SEEK_SET); |
6604 | // ---------- reset the cached values ---------- |
8841 | // ---------- reset the cached values ---------- |
6605 | |
8842 | |
6606 | |
|
|
6607 | fseek(in, 0, SEEK_SET); |
8843 | fseek(in, 0, SEEK_SET); |
6608 | while ((ib = read_item(in, local_thread_num))) // loop all "ways" from file "in" |
8844 | while ((ib = read_item(in, local_thread_num))) // loop all "ways" from file "in" |
6609 | { |
8845 | { |
6610 | this_way_id = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
8846 | this_way_id = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
|
|
8847 | |
6611 | if (this_way_id) |
8848 | if (this_way_id) |
6612 | { |
8849 | { |
6613 | nodes_ref_item_bin(ib, local_thread_num, *this_way_id); |
8850 | nodes_ref_item_bin(ib, local_thread_num, *this_way_id); |
6614 | } |
8851 | } |
6615 | else |
8852 | else |
… | |
… | |
6619 | } |
8856 | } |
6620 | ways_count++; |
8857 | ways_count++; |
6621 | |
8858 | |
6622 | if ((ways_count % 1000000) == 0) |
8859 | if ((ways_count % 1000000) == 0) |
6623 | { |
8860 | { |
6624 | fprintf(stderr, "[THREAD] #%d ways: %lld\n", local_thread_num, ways_count); |
8861 | fprintf_(stderr, "[THREAD] #%d ways: %lld\n", local_thread_num, ways_count); |
6625 | } |
8862 | } |
6626 | } |
8863 | } |
6627 | } |
8864 | } |
6628 | |
8865 | |
6629 | |
8866 | |
… | |
… | |
6880 | { |
9117 | { |
6881 | putc(c, ofp); |
9118 | putc(c, ofp); |
6882 | } |
9119 | } |
6883 | } |
9120 | } |
6884 | |
9121 | |
6885 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
6886 | typedef unsigned char uint8; |
|
|
6887 | typedef unsigned short uint16; |
|
|
6888 | typedef unsigned int uint; |
|
|
6889 | |
9122 | |
6890 | #define MZ_MIN(a,b) (((a)<(b))?(a):(b)) |
|
|
6891 | #define my_min(a,b) (((a) < (b)) ? (a) : (b)) |
|
|
6892 | |
9123 | |
|
|
9124 | #include "osm_s_index.h" |
6893 | |
9125 | |
6894 | |
9126 | |
6895 | |
9127 | |
6896 | // ------------------------------- |
|
|
6897 | // ------------------------------- |
|
|
6898 | |
9128 | |
6899 | int IN_BUF_SIZE; |
|
|
6900 | static uint8* s_inbuf; |
|
|
6901 | int OUT_BUF_SIZE; |
|
|
6902 | static uint8* s_outbuf; |
|
|
6903 | int COMP_OUT_BUF_SIZE; |
|
|
6904 | |
9129 | |
6905 | int s_IN_BUF_SIZE = sizeof(struct streets_index_data_block) * 1024; |
|
|
6906 | int t_IN_BUF_SIZE = sizeof(struct town_index_data_block) * 1024; |
|
|
6907 | static uint8 s_s_inbuf[(sizeof(struct streets_index_data_block) * 1024)]; |
|
|
6908 | static uint8 t_s_inbuf[(sizeof(struct town_index_data_block) * 1024)]; |
|
|
6909 | |
9130 | |
6910 | int s_OUT_BUF_SIZE = sizeof(struct streets_index_data_block) * 1024; |
|
|
6911 | int t_OUT_BUF_SIZE = sizeof(struct town_index_data_block) * 1024; |
|
|
6912 | static uint8 s_s_outbuf[(sizeof(struct streets_index_data_block) * 1024)]; |
|
|
6913 | static uint8 t_s_outbuf[(sizeof(struct town_index_data_block) * 1024)]; |
|
|
6914 | |
|
|
6915 | int s_COMP_OUT_BUF_SIZE; |
|
|
6916 | int t_COMP_OUT_BUF_SIZE; |
|
|
6917 | |
|
|
6918 | // IN_BUF_SIZE is the size of the file read buffer. |
|
|
6919 | // IN_BUF_SIZE must be >= 1 |
|
|
6920 | //**#define IN_BUF_SIZE (1024*512) |
|
|
6921 | //**static uint8 s_inbuf[IN_BUF_SIZE]; |
|
|
6922 | |
|
|
6923 | // COMP_OUT_BUF_SIZE is the size of the output buffer used during compression. |
|
|
6924 | // COMP_OUT_BUF_SIZE must be >= 1 and <= OUT_BUF_SIZE |
|
|
6925 | //**#define COMP_OUT_BUF_SIZE (1024*512) |
|
|
6926 | |
|
|
6927 | // OUT_BUF_SIZE is the size of the output buffer used during decompression. |
|
|
6928 | // OUT_BUF_SIZE must be a power of 2 >= TINFL_LZ_DICT_SIZE (because the low-level decompressor not only writes, but reads from the output buffer as it decompresses) |
|
|
6929 | //#define OUT_BUF_SIZE (TINFL_LZ_DICT_SIZE) |
|
|
6930 | //*#define OUT_BUF_SIZE (1024*512) |
|
|
6931 | //*static uint8 s_outbuf[OUT_BUF_SIZE]; |
|
|
6932 | |
|
|
6933 | // ------------------------------- |
|
|
6934 | // ------------------------------- |
|
|
6935 | |
|
|
6936 | |
|
|
6937 | // compression level |
|
|
6938 | int street_index_compress_level = 9; // = MZ_BEST_COMPRESSION |
|
|
6939 | |
|
|
6940 | long long compress_file(char *in, char *out, int keep_tempfile) |
|
|
6941 | { |
|
|
6942 | long long out_size = 0; |
|
|
6943 | // compress structure |
|
|
6944 | tdefl_compressor *g_deflator; |
|
|
6945 | g_deflator = g_new0(tdefl_compressor, 1); |
|
|
6946 | // compress structure |
|
|
6947 | |
|
|
6948 | // ok now compress the block (file) ------------------------------- |
|
|
6949 | const void *next_in = s_inbuf; |
|
|
6950 | size_t avail_in = 0; |
|
|
6951 | void *next_out = s_outbuf; |
|
|
6952 | size_t avail_out = OUT_BUF_SIZE; |
|
|
6953 | size_t total_in = 0, total_out = 0; |
|
|
6954 | |
|
|
6955 | FILE *in_uncompr = tempfile("", in, 0); |
|
|
6956 | FILE *out_compr = NULL; |
|
|
6957 | out_compr = tempfile("", out, 1); |
|
|
6958 | |
|
|
6959 | // Determine input file's size. |
|
|
6960 | fseek(in_uncompr, 0, SEEK_END); |
|
|
6961 | long file_loc = ftell(in_uncompr); |
|
|
6962 | fseek(in_uncompr, 0, SEEK_SET); |
|
|
6963 | uint infile_size = (uint)file_loc; |
|
|
6964 | |
|
|
6965 | // The number of dictionary probes to use at each compression level (0-10). 0=implies fastest/minimal possible probing. |
|
|
6966 | static const mz_uint s_tdefl_num_probes[11] = |
|
|
6967 | { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500}; |
|
|
6968 | |
|
|
6969 | tdefl_status status; |
|
|
6970 | uint infile_remaining = infile_size; |
|
|
6971 | |
|
|
6972 | // create tdefl() compatible flags (we have to compose the low-level flags ourselves, or use tdefl_create_comp_flags_from_zip_params() but that means MINIZ_NO_ZLIB_APIS can't be defined). |
|
|
6973 | mz_uint comp_flags = TDEFL_WRITE_ZLIB_HEADER | s_tdefl_num_probes[MZ_MIN(10, street_index_compress_level)] | ((street_index_compress_level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0); |
|
|
6974 | if (!street_index_compress_level) |
|
|
6975 | { |
|
|
6976 | comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS; |
|
|
6977 | } |
|
|
6978 | |
|
|
6979 | // Initialize the low-level compressor. |
|
|
6980 | status = tdefl_init(g_deflator, NULL, NULL, comp_flags); |
|
|
6981 | if (status != TDEFL_STATUS_OKAY) |
|
|
6982 | { |
|
|
6983 | fprintf(stderr, "tdefl_init() failed!\n"); |
|
|
6984 | g_free(g_deflator); |
|
|
6985 | return 0; |
|
|
6986 | } |
|
|
6987 | avail_out = COMP_OUT_BUF_SIZE; |
|
|
6988 | |
|
|
6989 | // Compression. |
|
|
6990 | for (;; ) |
|
|
6991 | { |
|
|
6992 | size_t in_bytes, out_bytes; |
|
|
6993 | |
|
|
6994 | if (!avail_in) |
|
|
6995 | { |
|
|
6996 | // Input buffer is empty, so read more bytes from input file. |
|
|
6997 | uint n = my_min(IN_BUF_SIZE, infile_remaining); |
|
|
6998 | |
|
|
6999 | if (fread(s_inbuf, 1, n, in_uncompr) != n) |
|
|
7000 | { |
|
|
7001 | fprintf(stderr, "Failed reading from input file!\n"); |
|
|
7002 | g_free(g_deflator); |
|
|
7003 | return 0; |
|
|
7004 | } |
|
|
7005 | |
|
|
7006 | next_in = s_inbuf; |
|
|
7007 | avail_in = n; |
|
|
7008 | |
|
|
7009 | infile_remaining -= n; |
|
|
7010 | //printf("Input bytes remaining: %u\n", infile_remaining); |
|
|
7011 | } |
|
|
7012 | |
|
|
7013 | in_bytes = avail_in; |
|
|
7014 | out_bytes = avail_out; |
|
|
7015 | // Compress as much of the input as possible (or all of it) to the output buffer. |
|
|
7016 | status = tdefl_compress(g_deflator, next_in, &in_bytes, next_out, &out_bytes, infile_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH); |
|
|
7017 | |
|
|
7018 | next_in = (const char *)next_in + in_bytes; |
|
|
7019 | avail_in -= in_bytes; |
|
|
7020 | total_in += in_bytes; |
|
|
7021 | |
|
|
7022 | next_out = (char *)next_out + out_bytes; |
|
|
7023 | avail_out -= out_bytes; |
|
|
7024 | total_out += out_bytes; |
|
|
7025 | |
|
|
7026 | if ((status != TDEFL_STATUS_OKAY) || (!avail_out)) |
|
|
7027 | { |
|
|
7028 | // Output buffer is full, or compression is done or failed, so write buffer to output file. |
|
|
7029 | uint n = COMP_OUT_BUF_SIZE - (uint)avail_out; |
|
|
7030 | if (fwrite(s_outbuf, 1, n, out_compr) != n) |
|
|
7031 | { |
|
|
7032 | fprintf(stderr, "Failed writing to output file!\n"); |
|
|
7033 | g_free(g_deflator); |
|
|
7034 | return 0; |
|
|
7035 | } |
|
|
7036 | next_out = s_outbuf; |
|
|
7037 | avail_out = COMP_OUT_BUF_SIZE; |
|
|
7038 | } |
|
|
7039 | |
|
|
7040 | if (status == TDEFL_STATUS_DONE) |
|
|
7041 | { |
|
|
7042 | // Compression completed successfully. |
|
|
7043 | break; |
|
|
7044 | } |
|
|
7045 | else if (status != TDEFL_STATUS_OKAY) |
|
|
7046 | { |
|
|
7047 | // Compression somehow failed. |
|
|
7048 | fprintf(stderr, "tdefl_compress() failed with status %i!\n", status); |
|
|
7049 | g_free(g_deflator); |
|
|
7050 | return 0; |
|
|
7051 | } |
|
|
7052 | } |
|
|
7053 | |
|
|
7054 | fprintf(stderr, "Total input bytes: %u\n", (mz_uint32)total_in); |
|
|
7055 | fprintf(stderr, "Total output bytes: %u\n", (mz_uint32)total_out); |
|
|
7056 | |
|
|
7057 | out_size = (long long)total_out; |
|
|
7058 | |
|
|
7059 | fclose(in_uncompr); |
|
|
7060 | fclose(out_compr); |
|
|
7061 | |
|
|
7062 | if (keep_tempfile == 1) |
|
|
7063 | { |
|
|
7064 | char *in2; |
|
|
7065 | in2 = g_strdup_printf("%s.tmptmp", in); |
|
|
7066 | tempfile_rename("", in, in2); |
|
|
7067 | g_free(in2); |
|
|
7068 | tempfile_rename("", out, in); |
|
|
7069 | } |
|
|
7070 | else |
|
|
7071 | { |
|
|
7072 | tempfile_unlink("", in); |
|
|
7073 | tempfile_rename("", out, in); |
|
|
7074 | } |
|
|
7075 | |
|
|
7076 | g_free(g_deflator); |
|
|
7077 | |
|
|
7078 | return out_size; |
|
|
7079 | } |
|
|
7080 | #endif |
|
|
7081 | |
|
|
7082 | void generate_combined_index_file(FILE *towni, FILE *streeti, FILE *out) |
|
|
7083 | { |
|
|
7084 | #ifdef MAPTOOL_USE_SQL |
|
|
7085 | fseek(towni, 0, SEEK_END); |
|
|
7086 | fseek(streeti, 0, SEEK_END); |
|
|
7087 | long long towni_size = (long long)ftello(towni); |
|
|
7088 | long long streeti_size = (long long)ftello(streeti); |
|
|
7089 | fprintf(stderr, "ftell towns=%lld\n", towni_size); |
|
|
7090 | fprintf(stderr, "ftell streets=%lld\n", streeti_size); |
|
|
7091 | |
|
|
7092 | fseek(towni, 0, SEEK_SET); |
|
|
7093 | fseek(streeti, 0, SEEK_SET); |
|
|
7094 | |
|
|
7095 | // size |
|
|
7096 | fwrite(&streeti_size, sizeof(long long), 1, out); |
|
|
7097 | // append street index file |
|
|
7098 | filecopy(streeti, out); |
|
|
7099 | // append town index file |
|
|
7100 | filecopy(towni, out); |
|
|
7101 | |
|
|
7102 | #endif |
|
|
7103 | } |
|
|
7104 | |
|
|
7105 | char* get_town_name_recursive(long long border_id, int level) |
|
|
7106 | { |
|
|
7107 | char *ret = NULL; |
|
|
7108 | char *ret2 = NULL; |
|
|
7109 | char *str2 = NULL; |
|
|
7110 | int rc = 0; |
|
|
7111 | long long parent_rel_id = 0; |
|
|
7112 | |
|
|
7113 | //fprintf(stderr, "get town name:bid:%lld level:%d\n", border_id, level); |
|
|
7114 | |
|
|
7115 | // select this boundary |
|
|
7116 | sqlite3_bind_int64(stmt_bd_005, 1, border_id); |
|
|
7117 | rc = sqlite3_step(stmt_bd_005); |
|
|
7118 | switch (rc) |
|
|
7119 | { |
|
|
7120 | case SQLITE_DONE: |
|
|
7121 | break; |
|
|
7122 | case SQLITE_ROW: |
|
|
7123 | // rel_id, parent_rel_id, name |
|
|
7124 | parent_rel_id = sqlite3_column_int(stmt_bd_005, 1); |
|
|
7125 | ret = g_strdup_printf("%s", sqlite3_column_text(stmt_bd_005, 2)); |
|
|
7126 | sqlite3_reset(stmt_bd_005); |
|
|
7127 | |
|
|
7128 | //fprintf(stderr, "get town name:ret=%s\n", ret); |
|
|
7129 | |
|
|
7130 | if (level < 12) |
|
|
7131 | { |
|
|
7132 | str2 = get_town_name_recursive(parent_rel_id, (level + 1)); |
|
|
7133 | if (str2) |
|
|
7134 | { |
|
|
7135 | ret2 = g_strdup_printf("%s, %s", ret, str2); |
|
|
7136 | g_free(ret); |
|
|
7137 | g_free(str2); |
|
|
7138 | ret = ret2; |
|
|
7139 | } |
|
|
7140 | } |
|
|
7141 | break; |
|
|
7142 | default: |
|
|
7143 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7144 | break; |
|
|
7145 | } |
|
|
7146 | |
|
|
7147 | if (level == 0) |
|
|
7148 | { |
|
|
7149 | sqlite3_reset(stmt_bd_005); |
|
|
7150 | } |
|
|
7151 | |
|
|
7152 | return ret; |
|
|
7153 | } |
|
|
7154 | |
|
|
7155 | void generate_town_index_file(FILE *out) |
|
|
7156 | { |
|
|
7157 | #ifdef MAPTOOL_USE_SQL |
|
|
7158 | |
|
|
7159 | struct town_index_data_block db; |
|
|
7160 | struct town_index_index_block_start is; |
|
|
7161 | struct town_index_index_block ib; |
|
|
7162 | char *townname = NULL; |
|
|
7163 | char *townname2 = NULL; |
|
|
7164 | long long last_len = 0; |
|
|
7165 | long long border_id = 0; |
|
|
7166 | int town_count = 0; |
|
|
7167 | int index_blocks; |
|
|
7168 | int index_block_towns; |
|
|
7169 | int i; |
|
|
7170 | int first; |
|
|
7171 | int rc = 0; |
|
|
7172 | int current_index_block; |
|
|
7173 | int current_index_block_old; |
|
|
7174 | char tmp_letter[TOWN_INDEX_TOWN_NAME_SIZE]; |
|
|
7175 | char *newfilename = NULL; |
|
|
7176 | char *newfilename_compr = NULL; |
|
|
7177 | |
|
|
7178 | int chunkSize; |
|
|
7179 | int stringLength; |
|
|
7180 | int ii22; |
|
|
7181 | |
|
|
7182 | FILE *town_index_index = NULL; |
|
|
7183 | FILE *town_index_index_data_block = NULL; |
|
|
7184 | |
|
|
7185 | |
|
|
7186 | // init compression for towns |
|
|
7187 | // init compression for towns |
|
|
7188 | IN_BUF_SIZE = t_IN_BUF_SIZE; |
|
|
7189 | s_inbuf = t_s_inbuf; |
|
|
7190 | OUT_BUF_SIZE = t_OUT_BUF_SIZE; |
|
|
7191 | s_outbuf = t_s_outbuf; |
|
|
7192 | COMP_OUT_BUF_SIZE = t_OUT_BUF_SIZE; |
|
|
7193 | // init compression for towns |
|
|
7194 | // init compression for towns |
|
|
7195 | |
|
|
7196 | |
|
|
7197 | sqlite3_step(stmt_town_sel006); |
|
|
7198 | town_count = sqlite3_column_int(stmt_town_sel006, 0); |
|
|
7199 | sqlite3_reset(stmt_town_sel006); |
|
|
7200 | |
|
|
7201 | // calculate number of index blocks |
|
|
7202 | index_blocks = 2; |
|
|
7203 | if (town_count > 1000000) |
|
|
7204 | { |
|
|
7205 | index_blocks = 100; |
|
|
7206 | } |
|
|
7207 | else if (town_count > 100000) |
|
|
7208 | { |
|
|
7209 | index_blocks = 50; |
|
|
7210 | } |
|
|
7211 | else if (town_count > 10000) |
|
|
7212 | { |
|
|
7213 | index_blocks = 10; |
|
|
7214 | } |
|
|
7215 | else if (town_count > 2000) |
|
|
7216 | { |
|
|
7217 | index_blocks = 5; |
|
|
7218 | } |
|
|
7219 | |
|
|
7220 | is.count_of_index_blocks = index_blocks; |
|
|
7221 | ib.offset = sizeof (is.count_of_index_blocks) + is.count_of_index_blocks * sizeof(struct town_index_index_block); // start offset = index size |
|
|
7222 | town_index_index = tempfile("", "town_index_index", 1); |
|
|
7223 | |
|
|
7224 | index_block_towns = (town_count / index_blocks); |
|
|
7225 | if ((index_block_towns * index_blocks) < town_count) |
|
|
7226 | { |
|
|
7227 | index_block_towns++; |
|
|
7228 | } |
|
|
7229 | |
|
|
7230 | fprintf(stderr, "towns per block=%d\n", index_block_towns); |
|
|
7231 | |
|
|
7232 | fprintf(stderr, "index size=%d\n", ib.offset); |
|
|
7233 | |
|
|
7234 | fprintf(stderr, "ftell=%d\n", ftell(town_index_index)); |
|
|
7235 | fwrite(&is, sizeof(struct town_index_index_block_start), 1, town_index_index); |
|
|
7236 | fprintf(stderr, "ftell=%d\n", ftell(town_index_index)); |
|
|
7237 | |
|
|
7238 | current_index_block = 1; |
|
|
7239 | current_index_block_old = 0; |
|
|
7240 | ib.len = 0; |
|
|
7241 | i = -1; |
|
|
7242 | first = 1; |
|
|
7243 | |
|
|
7244 | // loop thru all the towns |
|
|
7245 | do |
|
|
7246 | { |
|
|
7247 | rc = sqlite3_step(stmt_town_sel005); |
|
|
7248 | switch (rc) |
|
|
7249 | { |
|
|
7250 | case SQLITE_DONE: |
|
|
7251 | break; |
|
|
7252 | case SQLITE_ROW: |
|
|
7253 | i++; |
|
|
7254 | townname2 = NULL; |
|
|
7255 | db.town_id = sqlite3_column_int64(stmt_town_sel005, 0); |
|
|
7256 | db.country_id = sqlite3_column_int(stmt_town_sel005, 1); |
|
|
7257 | border_id = sqlite3_column_int64(stmt_town_sel005, 3); |
|
|
7258 | |
|
|
7259 | townname = get_town_name_recursive(border_id, 0); |
|
|
7260 | |
|
|
7261 | if (townname == NULL) |
|
|
7262 | { |
|
|
7263 | townname2 = g_strdup_printf("%s", sqlite3_column_text(stmt_town_sel005, 2)); |
|
|
7264 | } |
|
|
7265 | else |
|
|
7266 | { |
|
|
7267 | townname2 = townname; |
|
|
7268 | // townname2 = g_strdup_printf("%s", townname); // dont use the column result here, or string will be double! |
|
|
7269 | // g_free(townname); |
|
|
7270 | } |
|
|
7271 | //fprintf(stderr, "indextown:%s\n", townname2); |
|
|
7272 | |
|
|
7273 | //fprintf(stderr, "i=%d\n", i); |
|
|
7274 | //fprintf(stderr, "block=%d\n", current_index_block); |
|
|
7275 | if ((i + 1) > index_block_towns) |
|
|
7276 | { |
|
|
7277 | // start new index data block |
|
|
7278 | i = 0; |
|
|
7279 | current_index_block++; |
|
|
7280 | //fprintf(stderr, "incr block=%d\n", current_index_block); |
|
|
7281 | } |
|
|
7282 | |
|
|
7283 | if (current_index_block != current_index_block_old) |
|
|
7284 | { |
|
|
7285 | |
|
|
7286 | if (first != 1) |
|
|
7287 | { |
|
|
7288 | // close old datafile |
|
|
7289 | fclose(town_index_index_data_block); |
|
|
7290 | town_index_index_data_block = NULL; |
|
|
7291 | |
|
|
7292 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7293 | { |
|
|
7294 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7295 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7296 | #endif |
|
|
7297 | } |
|
|
7298 | |
|
|
7299 | // append to indexfile |
|
|
7300 | fprintf(stderr, "first_id=%lld offset=%lld len=%lld\n", ib.first_id, ib.offset, ib.len); |
|
|
7301 | fwrite(&ib, sizeof(struct town_index_index_block), 1, town_index_index); |
|
|
7302 | |
|
|
7303 | if (newfilename) |
|
|
7304 | { |
|
|
7305 | g_free(newfilename); |
|
|
7306 | newfilename = NULL; |
|
|
7307 | } |
|
|
7308 | |
|
|
7309 | if (newfilename_compr) |
|
|
7310 | { |
|
|
7311 | g_free(newfilename_compr); |
|
|
7312 | newfilename_compr = NULL; |
|
|
7313 | } |
|
|
7314 | } |
|
|
7315 | |
|
|
7316 | current_index_block_old = current_index_block; |
|
|
7317 | ib.first_id = db.town_id; |
|
|
7318 | ib.offset = ib.offset + ib.len; |
|
|
7319 | |
|
|
7320 | // open new datafile |
|
|
7321 | newfilename = g_strdup_printf("town_index_index_%d", current_index_block); |
|
|
7322 | fprintf(stderr, "new data file: %s first_id=%lld\n", newfilename, ib.first_id); |
|
|
7323 | newfilename_compr = g_strdup_printf("town_index_index_compr_%d", current_index_block); |
|
|
7324 | town_index_index_data_block = tempfile("", newfilename, 1); |
|
|
7325 | fprintf(stderr, "town index file %d\n", current_index_block); |
|
|
7326 | |
|
|
7327 | ib.len = 0; |
|
|
7328 | } |
|
|
7329 | |
|
|
7330 | |
|
|
7331 | // now check if we need to split the string into parts |
|
|
7332 | if ((strlen(townname2) + 1) > TOWN_INDEX_TOWN_NAME_SIZE) |
|
|
7333 | { |
|
|
7334 | //fprintf(stderr, " block-split: START\n"); |
|
|
7335 | chunkSize = TOWN_INDEX_TOWN_NAME_SIZE - 1; |
|
|
7336 | stringLength = strlen(townname2); |
|
|
7337 | for (ii22 = 0; ii22 < stringLength ; ii22 += chunkSize) |
|
|
7338 | { |
|
|
7339 | if (ii22 + chunkSize > stringLength) |
|
|
7340 | { |
|
|
7341 | chunkSize = stringLength - ii22; |
|
|
7342 | db.town_name[chunkSize] = '\0'; // make sure string is terminated |
|
|
7343 | } |
|
|
7344 | strncpy(&db.town_name, (townname2 + ii22), chunkSize); |
|
|
7345 | db.town_name[TOWN_INDEX_TOWN_NAME_SIZE - 1] = '\0'; // make sure string is terminated |
|
|
7346 | if (ii22 > 0) |
|
|
7347 | { |
|
|
7348 | // set "split"-marker |
|
|
7349 | db.town_id = 0; |
|
|
7350 | db.country_id = 0; // setting this to zero is actually not needed |
|
|
7351 | } |
|
|
7352 | ib.len = ib.len + sizeof(struct town_index_data_block); |
|
|
7353 | //fprintf(stderr, "->block-split: town_id=%lld country_id=%d town_name=%s\n", db.town_id, db.country_id, db.town_name); |
|
|
7354 | fwrite(&db, sizeof(struct town_index_data_block), 1, town_index_index_data_block); |
|
|
7355 | } |
|
|
7356 | //fprintf(stderr, " block-split: END\n"); |
|
|
7357 | g_free(townname2); |
|
|
7358 | } |
|
|
7359 | else |
|
|
7360 | { |
|
|
7361 | strncpy(&db.town_name, townname2, TOWN_INDEX_TOWN_NAME_SIZE); |
|
|
7362 | g_free(townname2); |
|
|
7363 | db.town_name[TOWN_INDEX_TOWN_NAME_SIZE - 1]= '\0'; // make sure string is terminated |
|
|
7364 | |
|
|
7365 | ib.len = ib.len + sizeof(struct town_index_data_block); |
|
|
7366 | fwrite(&db, sizeof(struct town_index_data_block), 1, town_index_index_data_block); |
|
|
7367 | } |
|
|
7368 | |
|
|
7369 | if (first == 1) |
|
|
7370 | { |
|
|
7371 | first = 0; |
|
|
7372 | } |
|
|
7373 | |
|
|
7374 | break; |
|
|
7375 | default: |
|
|
7376 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7377 | break; |
|
|
7378 | } |
|
|
7379 | } |
|
|
7380 | while (rc == SQLITE_ROW); |
|
|
7381 | |
|
|
7382 | sqlite3_reset(stmt_town_sel005); |
|
|
7383 | |
|
|
7384 | // rest of the towns |
|
|
7385 | if (i > 0) |
|
|
7386 | { |
|
|
7387 | if (town_index_index_data_block) |
|
|
7388 | { |
|
|
7389 | fclose(town_index_index_data_block); |
|
|
7390 | town_index_index_data_block = NULL; |
|
|
7391 | } |
|
|
7392 | |
|
|
7393 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7394 | { |
|
|
7395 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7396 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7397 | #endif |
|
|
7398 | } |
|
|
7399 | |
|
|
7400 | // append to indexfile |
|
|
7401 | fprintf(stderr, "(last)first_id=%lld offset=%lld len=%lld\n", ib.first_id, ib.offset, ib.len); |
|
|
7402 | fwrite(&ib, sizeof(struct town_index_index_block), 1, town_index_index); |
|
|
7403 | } |
|
|
7404 | |
|
|
7405 | if (town_index_index != NULL) |
|
|
7406 | { |
|
|
7407 | fclose(town_index_index); |
|
|
7408 | } |
|
|
7409 | |
|
|
7410 | if (town_index_index_data_block != NULL) |
|
|
7411 | { |
|
|
7412 | fclose(town_index_index_data_block); |
|
|
7413 | } |
|
|
7414 | |
|
|
7415 | if (newfilename) |
|
|
7416 | { |
|
|
7417 | g_free(newfilename); |
|
|
7418 | newfilename = NULL; |
|
|
7419 | } |
|
|
7420 | |
|
|
7421 | if (newfilename_compr) |
|
|
7422 | { |
|
|
7423 | g_free(newfilename_compr); |
|
|
7424 | newfilename_compr = NULL; |
|
|
7425 | } |
|
|
7426 | |
|
|
7427 | |
|
|
7428 | |
|
|
7429 | |
|
|
7430 | |
|
|
7431 | // put all parts together |
|
|
7432 | town_index_index = tempfile("", "town_index_index", 0); |
|
|
7433 | filecopy(town_index_index, out); |
|
|
7434 | fclose(town_index_index); |
|
|
7435 | tempfile_unlink("", "town_index_index"); |
|
|
7436 | |
|
|
7437 | for (i=1;i < (current_index_block + 2);i++) |
|
|
7438 | { |
|
|
7439 | fprintf(stderr, "index block #%d\n", i); |
|
|
7440 | newfilename = g_strdup_printf("town_index_index_%d", i); |
|
|
7441 | town_index_index_data_block = tempfile("", newfilename, 0); |
|
|
7442 | |
|
|
7443 | if (town_index_index_data_block) |
|
|
7444 | { |
|
|
7445 | fprintf(stderr, "using: index block #%d in %s\n", i, newfilename); |
|
|
7446 | filecopy(town_index_index_data_block, out); |
|
|
7447 | fclose(town_index_index_data_block); |
|
|
7448 | tempfile_unlink("", newfilename); |
|
|
7449 | } |
|
|
7450 | |
|
|
7451 | if (newfilename) |
|
|
7452 | { |
|
|
7453 | g_free(newfilename); |
|
|
7454 | newfilename = NULL; |
|
|
7455 | } |
|
|
7456 | } |
|
|
7457 | |
|
|
7458 | |
|
|
7459 | |
|
|
7460 | #endif |
|
|
7461 | } |
|
|
7462 | |
|
|
7463 | void generate_street_index_file(FILE *out) |
|
|
7464 | { |
|
|
7465 | #ifdef MAPTOOL_USE_SQL |
|
|
7466 | int rc = 0; |
|
|
7467 | int i; |
|
|
7468 | struct streets_index_data_block db; |
|
|
7469 | struct streets_index_index_block_start is; |
|
|
7470 | struct streets_index_index_block ib; |
|
|
7471 | long long last_len = 0; |
|
|
7472 | static const char *alpha = "abcdefghijklmnopqrstuvwxyz"; |
|
|
7473 | char tmp_letter[STREET_INDEX_STREET_NAME_SIZE]; |
|
|
7474 | char *newfilename = NULL; |
|
|
7475 | char *newfilename_compr = NULL; |
|
|
7476 | int count_of_blocks; |
|
|
7477 | int do_rest; |
|
|
7478 | int num1; |
|
|
7479 | int num2; |
|
|
7480 | |
|
|
7481 | FILE *street_index_index; |
|
|
7482 | FILE *street_index_index_data_block; |
|
|
7483 | |
|
|
7484 | // init compression for streets |
|
|
7485 | // init compression for streets |
|
|
7486 | IN_BUF_SIZE = s_IN_BUF_SIZE; |
|
|
7487 | s_inbuf = s_s_inbuf; |
|
|
7488 | OUT_BUF_SIZE = s_OUT_BUF_SIZE; |
|
|
7489 | s_outbuf = s_s_outbuf; |
|
|
7490 | COMP_OUT_BUF_SIZE = s_OUT_BUF_SIZE; |
|
|
7491 | // init compression for streets |
|
|
7492 | // init compression for streets |
|
|
7493 | |
|
|
7494 | |
|
|
7495 | is.count_of_index_blocks = 703; // 26+1 letters ((26+1)*26 + 1) = 703 |
|
|
7496 | ib.offset = sizeof (is.count_of_index_blocks) + is.count_of_index_blocks * sizeof(struct streets_index_index_block); // start offset = index size |
|
|
7497 | street_index_index = tempfile("", "street_index_index", 1); |
|
|
7498 | fprintf(stderr, "index size=%d\n", ib.offset); |
|
|
7499 | |
|
|
7500 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7501 | fwrite(&is, sizeof(struct streets_index_index_block_start), 1, street_index_index); |
|
|
7502 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7503 | |
|
|
7504 | // fprintf(stderr, "len=%d\n", strlen(alpha)); |
|
|
7505 | |
|
|
7506 | count_of_blocks = 702; |
|
|
7507 | do_rest = 0; |
|
|
7508 | num1 = 1; |
|
|
7509 | num2 = 0; |
|
|
7510 | for (i=0; i < count_of_blocks; i++) |
|
|
7511 | { |
|
|
7512 | num2++; |
|
|
7513 | do_rest = 0; |
|
|
7514 | if (num2 == 27) |
|
|
7515 | { |
|
|
7516 | do_rest = 1; |
|
|
7517 | } |
|
|
7518 | else if (num2 > 27) |
|
|
7519 | { |
|
|
7520 | num2 = 1; |
|
|
7521 | num1++; |
|
|
7522 | } |
|
|
7523 | |
|
|
7524 | fprintf(stderr, "i=%d num1=%d num2=%d\n", i, num1, num2); |
|
|
7525 | |
|
|
7526 | if (do_rest) |
|
|
7527 | { |
|
|
7528 | sprintf(tmp_letter, "%c", alpha[num1 - 1]); |
|
|
7529 | } |
|
|
7530 | else |
|
|
7531 | { |
|
|
7532 | sprintf(tmp_letter, "%c%c", alpha[num1 - 1], alpha[num2 - 1]); |
|
|
7533 | } |
|
|
7534 | fprintf(stderr, "letter=%s\n", tmp_letter); |
|
|
7535 | |
|
|
7536 | ib.first_letter = alpha[num1 - 1]; |
|
|
7537 | ib.len = 0; |
|
|
7538 | |
|
|
7539 | newfilename = g_strdup_printf("street_index_index_%d", i); |
|
|
7540 | newfilename_compr = g_strdup_printf("street_index_index_compr_%d", i); |
|
|
7541 | street_index_index_data_block = tempfile("", newfilename, 1); |
|
|
7542 | |
|
|
7543 | |
|
|
7544 | // ------ TIMER ------- |
|
|
7545 | time_t start_tt_4, end_tt_4; |
|
|
7546 | double diff_tt_4; |
|
|
7547 | char outstring_4[200]; |
|
|
7548 | // ------ TIMER ------- |
|
|
7549 | |
|
|
7550 | // ------ TIMER ------- |
|
|
7551 | time(&start_tt_4); |
|
|
7552 | // ------ TIMER ------- |
|
|
7553 | |
|
|
7554 | // loop thru all the streets that match '<letter>...' |
|
|
7555 | sqlite3_bind_text(stmt_sel003, 1, tmp_letter, -1, SQLITE_STATIC); |
|
|
7556 | do |
|
|
7557 | { |
|
|
7558 | rc = sqlite3_step(stmt_sel003); |
|
|
7559 | switch (rc) |
|
|
7560 | { |
|
|
7561 | case SQLITE_DONE: |
|
|
7562 | break; |
|
|
7563 | case SQLITE_ROW: |
|
|
7564 | db.town_id = sqlite3_column_int64(stmt_sel003, 0); |
|
|
7565 | db.lat = transform_from_geo_lat(sqlite3_column_double(stmt_sel003, 1)); |
|
|
7566 | db.lon = transform_from_geo_lon(sqlite3_column_double(stmt_sel003, 2)); |
|
|
7567 | strncpy(&db.street_name, sqlite3_column_text(stmt_sel003, 3), STREET_INDEX_STREET_NAME_SIZE); |
|
|
7568 | db.street_name[STREET_INDEX_STREET_NAME_SIZE - 1]= '\0'; // make sure string is terminated |
|
|
7569 | |
|
|
7570 | ib.len = ib.len + sizeof(struct streets_index_data_block); |
|
|
7571 | |
|
|
7572 | // fprintf(stderr ,"gen_street_index id:%lld lat:%d lon:%d name:%s\n", db.town_id, db.lat, db.lon, db.street_name); |
|
|
7573 | fwrite(&db, sizeof(struct streets_index_data_block), 1, street_index_index_data_block); |
|
|
7574 | |
|
|
7575 | break; |
|
|
7576 | default: |
|
|
7577 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7578 | break; |
|
|
7579 | } |
|
|
7580 | } |
|
|
7581 | while (rc == SQLITE_ROW); |
|
|
7582 | |
|
|
7583 | sqlite3_reset(stmt_sel003); |
|
|
7584 | fclose(street_index_index_data_block); |
|
|
7585 | |
|
|
7586 | // ------ TIMER ------- |
|
|
7587 | time(&end_tt_4); |
|
|
7588 | diff_tt_4 = difftime(end_tt_4, start_tt_4); |
|
|
7589 | convert_to_human_time(diff_tt_4, outstring_4); |
|
|
7590 | fprintf(stderr, "-TIME-IND-001: %s\n", outstring_4); |
|
|
7591 | // ------ TIMER ------- |
|
|
7592 | |
|
|
7593 | |
|
|
7594 | // ------ TIMER ------- |
|
|
7595 | time(&start_tt_4); |
|
|
7596 | // ------ TIMER ------- |
|
|
7597 | |
|
|
7598 | sqlite3_bind_int(stmt_sel003u, 1, (i + 1)); |
|
|
7599 | sqlite3_bind_text(stmt_sel003u, 2, tmp_letter, -1, SQLITE_STATIC); |
|
|
7600 | sqlite3_step(stmt_sel003u); |
|
|
7601 | sqlite3_reset(stmt_sel003u); |
|
|
7602 | // sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7603 | |
|
|
7604 | |
|
|
7605 | // ------ TIMER ------- |
|
|
7606 | time(&end_tt_4); |
|
|
7607 | diff_tt_4 = difftime(end_tt_4, start_tt_4); |
|
|
7608 | convert_to_human_time(diff_tt_4, outstring_4); |
|
|
7609 | fprintf(stderr, "-TIME-IND-002: %s\n", outstring_4); |
|
|
7610 | // ------ TIMER ------- |
|
|
7611 | |
|
|
7612 | |
|
|
7613 | // ------ TIMER ------- |
|
|
7614 | time(&start_tt_4); |
|
|
7615 | // ------ TIMER ------- |
|
|
7616 | |
|
|
7617 | |
|
|
7618 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7619 | { |
|
|
7620 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7621 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7622 | #endif |
|
|
7623 | } |
|
|
7624 | |
|
|
7625 | // ------ TIMER ------- |
|
|
7626 | time(&end_tt_4); |
|
|
7627 | diff_tt_4 = difftime(end_tt_4, start_tt_4); |
|
|
7628 | convert_to_human_time(diff_tt_4, outstring_4); |
|
|
7629 | fprintf(stderr, "-TIME-IND-COMPR: %s\n", outstring_4); |
|
|
7630 | // ------ TIMER ------- |
|
|
7631 | |
|
|
7632 | |
|
|
7633 | last_len = ib.len; |
|
|
7634 | fprintf(stderr ,"letter=%c offset=%lld len=%lld\n", ib.first_letter, ib.offset, ib.len); |
|
|
7635 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7636 | fwrite(&ib, sizeof(struct streets_index_index_block), 1, street_index_index); |
|
|
7637 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7638 | ib.offset = ib.offset + last_len; |
|
|
7639 | |
|
|
7640 | if (newfilename) |
|
|
7641 | { |
|
|
7642 | g_free(newfilename); |
|
|
7643 | newfilename = NULL; |
|
|
7644 | } |
|
|
7645 | |
|
|
7646 | if (newfilename_compr) |
|
|
7647 | { |
|
|
7648 | g_free(newfilename_compr); |
|
|
7649 | newfilename_compr = NULL; |
|
|
7650 | } |
|
|
7651 | } |
|
|
7652 | |
|
|
7653 | // rest of the streets |
|
|
7654 | fprintf(stderr, "rest of letters\n"); |
|
|
7655 | |
|
|
7656 | ib.first_letter = 65; // dummy "A" |
|
|
7657 | ib.len = 0; |
|
|
7658 | |
|
|
7659 | newfilename = g_strdup_printf("street_index_index_%d", i); |
|
|
7660 | newfilename_compr = g_strdup_printf("street_index_index_compr_%d", i); |
|
|
7661 | street_index_index_data_block = tempfile("", newfilename, 1); |
|
|
7662 | |
|
|
7663 | do |
|
|
7664 | { |
|
|
7665 | rc = sqlite3_step(stmt_sel004); |
|
|
7666 | switch (rc) |
|
|
7667 | { |
|
|
7668 | case SQLITE_DONE: |
|
|
7669 | break; |
|
|
7670 | case SQLITE_ROW: |
|
|
7671 | db.town_id = sqlite3_column_int64(stmt_sel004, 0); |
|
|
7672 | db.lat = transform_from_geo_lat(sqlite3_column_double(stmt_sel004, 1)); |
|
|
7673 | db.lon = transform_from_geo_lon(sqlite3_column_double(stmt_sel004, 2)); |
|
|
7674 | strncpy(&db.street_name, sqlite3_column_text(stmt_sel004, 3), STREET_INDEX_STREET_NAME_SIZE); |
|
|
7675 | db.street_name[STREET_INDEX_STREET_NAME_SIZE - 1]= '\0'; // make sure string is terminated |
|
|
7676 | |
|
|
7677 | ib.len = ib.len + sizeof(struct streets_index_data_block); |
|
|
7678 | |
|
|
7679 | //fprintf(stderr ,"id:%lld lat:%d lon:%d name:%s\n", db.town_id, db.lat, db.lon, db.street_name); |
|
|
7680 | fwrite(&db, sizeof(struct streets_index_data_block), 1, street_index_index_data_block); |
|
|
7681 | |
|
|
7682 | break; |
|
|
7683 | default: |
|
|
7684 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7685 | break; |
|
|
7686 | } |
|
|
7687 | } |
|
|
7688 | while (rc == SQLITE_ROW); |
|
|
7689 | sqlite3_reset(stmt_sel004); |
|
|
7690 | fclose(street_index_index_data_block); |
|
|
7691 | |
|
|
7692 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7693 | { |
|
|
7694 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7695 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7696 | #endif |
|
|
7697 | } |
|
|
7698 | |
|
|
7699 | last_len = ib.len; |
|
|
7700 | fprintf(stderr ,"letter=%c offset=%lld len=%lld\n", ib.first_letter, ib.offset, ib.len); |
|
|
7701 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7702 | fwrite(&ib, sizeof(struct streets_index_index_block), 1, street_index_index); |
|
|
7703 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7704 | // ib.offset = ib.offset + last_len; |
|
|
7705 | |
|
|
7706 | |
|
|
7707 | fclose(street_index_index); |
|
|
7708 | |
|
|
7709 | if (newfilename) |
|
|
7710 | { |
|
|
7711 | g_free(newfilename); |
|
|
7712 | newfilename = NULL; |
|
|
7713 | } |
|
|
7714 | |
|
|
7715 | if (newfilename_compr) |
|
|
7716 | { |
|
|
7717 | g_free(newfilename_compr); |
|
|
7718 | newfilename_compr = NULL; |
|
|
7719 | } |
|
|
7720 | |
|
|
7721 | // put all parts together |
|
|
7722 | street_index_index = tempfile("", "street_index_index", 0); |
|
|
7723 | filecopy(street_index_index, out); |
|
|
7724 | fclose(street_index_index); |
|
|
7725 | tempfile_unlink("", "street_index_index"); |
|
|
7726 | |
|
|
7727 | for (i=0;i < (is.count_of_index_blocks + 1);i++) |
|
|
7728 | { |
|
|
7729 | fprintf(stderr, "cat #%d\n", i); |
|
|
7730 | newfilename = g_strdup_printf("street_index_index_%d", i); |
|
|
7731 | street_index_index_data_block = tempfile("", newfilename, 0); |
|
|
7732 | |
|
|
7733 | if (street_index_index_data_block) |
|
|
7734 | { |
|
|
7735 | filecopy(street_index_index_data_block, out); |
|
|
7736 | fclose(street_index_index_data_block); |
|
|
7737 | tempfile_unlink("", newfilename); |
|
|
7738 | } |
|
|
7739 | |
|
|
7740 | if (newfilename) |
|
|
7741 | { |
|
|
7742 | g_free(newfilename); |
|
|
7743 | newfilename = NULL; |
|
|
7744 | } |
|
|
7745 | } |
|
|
7746 | #endif |
|
|
7747 | } |
|
|
7748 | |
9131 | |
7749 | void remove_attr_str(struct item_bin *ib, int attr_type) |
9132 | void remove_attr_str(struct item_bin *ib, int attr_type) |
7750 | { |
9133 | { |
7751 | char *attr_str = item_bin_get_attr(ib, attr_type, NULL); |
9134 | char *attr_str = item_bin_get_attr(ib, attr_type, NULL); |
7752 | if (attr_str) |
9135 | if (attr_str) |
7753 | { |
9136 | { |
7754 | item_bin_remove_attr(ib, attr_str); |
9137 | item_bin_remove_attr(ib, attr_str); |
|
|
9138 | } |
|
|
9139 | } |
|
|
9140 | |
|
|
9141 | int remove_useless_ways(FILE *in, FILE *out) |
|
|
9142 | { |
|
|
9143 | struct item_bin *ib; |
|
|
9144 | long long *wayid; |
|
|
9145 | int *dup; |
|
|
9146 | |
|
|
9147 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
|
|
9148 | { |
|
|
9149 | if (ib->type != type_street_unkn) // remove unknown streets here |
|
|
9150 | { |
|
|
9151 | // write way to outfile |
|
|
9152 | item_bin_write(ib, out); |
|
|
9153 | } |
7755 | } |
9154 | } |
7756 | } |
9155 | } |
7757 | |
9156 | |
7758 | int remove_useless_tags_from_ways(FILE *in, FILE *out) |
9157 | int remove_useless_tags_from_ways(FILE *in, FILE *out) |
7759 | { |
9158 | { |
… | |
… | |
7822 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
9221 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
7823 | { |
9222 | { |
7824 | ways_count++; |
9223 | ways_count++; |
7825 | if ((ways_count % 10000000) == 0) |
9224 | if ((ways_count % 10000000) == 0) |
7826 | { |
9225 | { |
7827 | fprintf(stderr, "ways: %lld\n", ways_count); |
9226 | fprintf_(stderr, "ways: %lld\n", ways_count); |
7828 | } |
9227 | } |
7829 | |
9228 | |
7830 | // we need at least 2 points in way |
9229 | // we need at least 2 points in way |
7831 | if (ccount <= 1) |
9230 | if (ccount <= 1) |
7832 | { |
9231 | { |
… | |
… | |
7871 | long long ways_count = 0; |
9270 | long long ways_count = 0; |
7872 | osmid *this_way_id; |
9271 | osmid *this_way_id; |
7873 | osmid this_way_id_real; |
9272 | osmid this_way_id_real; |
7874 | int i_real = -1; |
9273 | int i_real = -1; |
7875 | |
9274 | |
7876 | processed_nodes = processed_nodes_out = processed_ways = processed_relations = processed_tiles = 0; |
9275 | processed_nodes = 0; |
|
|
9276 | processed_nodes_out = 0; |
|
|
9277 | processed_ways = 0; |
|
|
9278 | processed_relations = 0; |
|
|
9279 | processed_tiles = 0; |
|
|
9280 | |
7877 | |
9281 | |
7878 | // ---------- reset the cached values ---------- |
9282 | // ---------- reset the cached values ---------- |
7879 | seekpos_waynode[0] = -1; |
9283 | seekpos_waynode[0] = -1; |
7880 | last_seekpos_waynode[0] = -1; |
9284 | last_seekpos_waynode[0] = -1; |
7881 | last_seek_wayid[0] = -1; |
9285 | last_seek_wayid[0] = -1; |
… | |
… | |
7906 | |
9310 | |
7907 | |
9311 | |
7908 | ways_count++; |
9312 | ways_count++; |
7909 | if ((ways_count % 10000000) == 0) |
9313 | if ((ways_count % 10000000) == 0) |
7910 | { |
9314 | { |
7911 | fprintf(stderr, "ways: %lld\n", ways_count); |
9315 | fprintf_(stderr, "ways: %lld\n", ways_count); |
7912 | } |
9316 | } |
7913 | |
9317 | |
7914 | c = (struct coord *) (ib + 1); |
9318 | c = (struct coord *) (ib + 1); |
7915 | last = 0; |
9319 | last = 0; |
7916 | i_real = -1; |
9320 | i_real = -1; |
… | |
… | |
7989 | } |
9393 | } |
7990 | |
9394 | |
7991 | return 0; |
9395 | return 0; |
7992 | } |
9396 | } |
7993 | |
9397 | |
|
|
9398 | int map_find_intersections__quick__for__debug(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final) |
|
|
9399 | { |
|
|
9400 | struct coord *c; |
|
|
9401 | int i, ccount, last, remaining; |
|
|
9402 | osmid ndref; |
|
|
9403 | struct item_bin *ib; |
|
|
9404 | struct node_item *ni; |
|
|
9405 | long long last_id = 0; |
|
|
9406 | long long ways_count = 0; |
|
|
9407 | osmid *this_way_id; |
|
|
9408 | osmid this_way_id_real; |
|
|
9409 | int i_real = -1; |
|
|
9410 | |
|
|
9411 | fprintf(stderr, "DEBUG:map_find_intersections__quick__for__debug\n"); |
|
|
9412 | |
|
|
9413 | processed_nodes = 0; |
|
|
9414 | processed_nodes_out = 0; |
|
|
9415 | processed_ways = 0; |
|
|
9416 | processed_relations = 0; |
|
|
9417 | processed_tiles = 0; |
|
|
9418 | |
|
|
9419 | |
|
|
9420 | // ---------- reset the cached values ---------- |
|
|
9421 | seekpos_waynode[0] = -1; |
|
|
9422 | last_seekpos_waynode[0] = -1; |
|
|
9423 | last_seek_wayid[0] = -1; |
|
|
9424 | fseeko(ways_ref_file_thread[0], (off_t)0, SEEK_SET); |
|
|
9425 | // ---------- reset the cached values ---------- |
|
|
9426 | |
|
|
9427 | |
|
|
9428 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
|
|
9429 | { |
|
|
9430 | |
|
|
9431 | this_way_id = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
|
|
9432 | if (this_way_id) |
|
|
9433 | { |
|
|
9434 | this_way_id_real = *this_way_id; |
|
|
9435 | // fprintf(stderr,"wayid:%lld type:0x%x len:%d clen:%d\n", *this_way_id, ib->type, ib->len, (ib->clen / 2)); |
|
|
9436 | } |
|
|
9437 | |
|
|
9438 | ccount = ib->clen / 2; |
|
|
9439 | |
|
|
9440 | if (ccount <= 1) |
|
|
9441 | { |
|
|
9442 | continue; |
|
|
9443 | } |
|
|
9444 | |
|
|
9445 | //fprintf(stderr,"********DUMP ww1***********\n"); |
|
|
9446 | //dump_itembin(ib); |
|
|
9447 | //fprintf(stderr,"********DUMP ww1***********\n"); |
|
|
9448 | |
|
|
9449 | |
|
|
9450 | ways_count++; |
|
|
9451 | if ((ways_count % 10000000) == 0) |
|
|
9452 | { |
|
|
9453 | fprintf_(stderr, "ways: %lld\n", ways_count); |
|
|
9454 | } |
|
|
9455 | |
|
|
9456 | c = (struct coord *) (ib + 1); |
|
|
9457 | last = 0; |
|
|
9458 | i_real = -1; |
|
|
9459 | for (i = 0; i < ccount; i++) // loop thru all the coordinates (nodes) of this way |
|
|
9460 | { |
|
|
9461 | //if (this_way_id_real != 0) |
|
|
9462 | //{ |
|
|
9463 | // fprintf(stderr, "this_way_id_real=%lld this_way_id=%lld i=%d ccount=%d\n", this_way_id_real, *this_way_id, i, ccount); |
|
|
9464 | //} |
|
|
9465 | |
|
|
9466 | if (IS_REF(c[i])) |
|
|
9467 | { |
|
|
9468 | //fprintf(stderr, "is ref\n"); |
|
|
9469 | if (this_way_id_real != 0) |
|
|
9470 | { |
|
|
9471 | i_real = c[i].y; // number of this node in the way (starting at zero) |
|
|
9472 | ndref = get_waynode_num(this_way_id_real, i_real, 0); |
|
|
9473 | //fprintf(stderr, "wayid:%lld wid(p)=%p i_real=%d i=%d ndref(1)=%lld\n", this_way_id_real, this_way_id, i_real, i, ndref); |
|
|
9474 | ni = node_item_get_fast(ndref, 0); |
|
|
9475 | //fprintf(stderr, "ni(1)=%p\n", ni); |
|
|
9476 | } |
|
|
9477 | else |
|
|
9478 | { |
|
|
9479 | ni = NULL; |
|
|
9480 | } |
|
|
9481 | |
|
|
9482 | //fprintf(stderr, "ndref(2)=%lld\n", ndref); |
|
|
9483 | |
|
|
9484 | if (ni) |
|
|
9485 | { |
|
|
9486 | //fprintf(stderr, "ni TRUE\n"); |
|
|
9487 | |
|
|
9488 | c[i] = ni->c; // write "lat,long" from node into way !! |
|
|
9489 | } |
|
|
9490 | } |
|
|
9491 | } |
|
|
9492 | item_bin_write(ib, out); |
|
|
9493 | |
|
|
9494 | } |
|
|
9495 | |
|
|
9496 | return 0; |
|
|
9497 | } |
|
|
9498 | |
|
|
9499 | |
7994 | static void index_country_add(struct zip_info *info, int country_id, int zipnum) |
9500 | static void index_country_add(struct zip_info *info, int country_id, int zipnum) |
7995 | { |
9501 | { |
7996 | struct item_bin *item_bin = init_item(type_countryindex, 0); |
9502 | struct item_bin *item_bin = init_item(type_countryindex, 0); |
7997 | item_bin_add_attr_int(item_bin, attr_country_id, country_id); |
9503 | item_bin_add_attr_int(item_bin, attr_country_id, country_id); |
7998 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, zipnum); |
9504 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, zipnum); |
… | |
… | |
8021 | tile(&co->r, suffix, tilename, max, overlap, NULL); |
9527 | tile(&co->r, suffix, tilename, max, overlap, NULL); |
8022 | |
9528 | |
8023 | sprintf(filename, "country_%d.tmp", co->countryid); |
9529 | sprintf(filename, "country_%d.tmp", co->countryid); |
8024 | if (debug_itembin(4)) |
9530 | if (debug_itembin(4)) |
8025 | { |
9531 | { |
8026 | fprintf(stderr, "write_countrydir: tilename=%s country_%d.tmp\n", tilename, co->countryid); |
9532 | fprintf_(stderr, "write_countrydir: tilename=%s country_%d.tmp\n", tilename, co->countryid); |
8027 | } |
9533 | } |
8028 | zipnum = add_aux_tile(zip_info, tilename, filename, co->size); |
9534 | zipnum = add_aux_tile(zip_info, tilename, filename, co->size); |
8029 | } |
9535 | } |
8030 | while (zipnum == -1); |
9536 | while (zipnum == -1); |
8031 | index_country_add(zip_info, co->countryid, zipnum); |
9537 | index_country_add(zip_info, co->countryid, zipnum); |
… | |
… | |
8044 | { |
9550 | { |
8045 | co = &country_table[i]; |
9551 | co = &country_table[i]; |
8046 | sprintf(filename, "country_%d.tmp", co->countryid); |
9552 | sprintf(filename, "country_%d.tmp", co->countryid); |
8047 | if (debug_itembin(4)) |
9553 | if (debug_itembin(4)) |
8048 | { |
9554 | { |
8049 | fprintf(stderr, "load_countries: country_%d.tmp\n", co->countryid); |
9555 | fprintf_(stderr, "load_countries: country_%d.tmp\n", co->countryid); |
8050 | } |
9556 | } |
8051 | |
9557 | |
8052 | f = fopen(filename, "rb"); |
9558 | f = fopen(filename, "rb"); |
8053 | if (f) |
9559 | if (f) |
8054 | { |
9560 | { |