1 | /** |
|
|
2 | * ZANavi, Zoff Android Navigation system. |
|
|
3 | * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc> |
|
|
4 | * |
|
|
5 | * This program is free software; you can redistribute it and/or |
|
|
6 | * modify it under the terms of the GNU General Public License |
|
|
7 | * version 2 as published by the Free Software Foundation. |
|
|
8 | * |
|
|
9 | * This program is distributed in the hope that it will be useful, |
|
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
12 | * GNU General Public License for more details. |
|
|
13 | * |
|
|
14 | * You should have received a copy of the GNU General Public License |
|
|
15 | * along with this program; if not, write to the |
|
|
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
|
17 | * Boston, MA 02110-1301, USA. |
|
|
18 | */ |
|
|
19 | |
|
|
20 | /** |
1 | /** |
21 | * Navit, a modular navigation system. |
2 | * Navit, a modular navigation system. |
22 | * Copyright (C) 2005-2011 Navit Team |
3 | * Copyright (C) 2005-2011 Navit Team |
23 | * |
4 | * |
24 | * This program is free software; you can redistribute it and/or |
5 | * This program is free software; you can redistribute it and/or |
… | |
… | |
33 | * You should have received a copy of the GNU General Public License |
14 | * You should have received a copy of the GNU General Public License |
34 | * along with this program; if not, write to the |
15 | * along with this program; if not, write to the |
35 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
36 | * Boston, MA 02110-1301, USA. |
17 | * Boston, MA 02110-1301, USA. |
37 | */ |
18 | */ |
38 | |
|
|
39 | #include "maptool.h" |
|
|
40 | #include "linguistics.h" |
|
|
41 | |
|
|
42 | #ifdef MAPTOOL_USE_SQL |
|
|
43 | // sqlite 3 |
|
|
44 | //#include "sqlite3.h" |
|
|
45 | // sqlite 3 |
|
|
46 | #else |
|
|
47 | #ifndef SQL_DUMMY_ |
|
|
48 | #define SQL_DUMMY_ 1 |
|
|
49 | int sqlite3_reset(void* v) |
|
|
50 | { |
|
|
51 | return 0; |
|
|
52 | } |
|
|
53 | int sqlite3_step(void* v) |
|
|
54 | { |
|
|
55 | return 0; |
|
|
56 | } |
|
|
57 | int sqlite3_exec(void* v1, void* v2, void* v3, void* v4, void* v5) |
|
|
58 | { |
|
|
59 | return 0; |
|
|
60 | } |
|
|
61 | int sqlite3_bind_int64(void* v, int i, long l) |
|
|
62 | { |
|
|
63 | return 0; |
|
|
64 | } |
|
|
65 | int sqlite3_bind_int(void* v, int i, int i2) |
|
|
66 | { |
|
|
67 | return 0; |
|
|
68 | } |
|
|
69 | int sqlite3_bind_double(void* v, int i, double d) |
|
|
70 | { |
|
|
71 | return 0; |
|
|
72 | } |
|
|
73 | long sqlite3_column_int64(void* v, int i) |
|
|
74 | { |
|
|
75 | return 0; |
|
|
76 | } |
|
|
77 | double sqlite3_column_double(void* v, int i) |
|
|
78 | { |
|
|
79 | return 0; |
|
|
80 | } |
|
|
81 | int sqlite3_column_int(void* v, int i) |
|
|
82 | { |
|
|
83 | return 0; |
|
|
84 | } |
|
|
85 | int sqlite3_bind_text(void* v, int i, char* c, int i2, int i3) |
|
|
86 | { |
|
|
87 | return 0; |
|
|
88 | } |
|
|
89 | #endif |
|
|
90 | |
|
|
91 | #endif |
|
|
92 | |
|
|
93 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
94 | |
|
|
95 | // compression |
|
|
96 | #define MINIZ_NO_ZLIB_COMPATIBLE_NAMES |
|
|
97 | |
|
|
98 | #define MINIZ_NO_STDIO |
|
|
99 | #define MINIZ_NO_ARCHIVE_APIS |
|
|
100 | #define MINIZ_NO_TIME |
|
|
101 | #define MINIZ_NO_ZLIB_APIS |
|
|
102 | #define MINIZ_NO_MALLOC |
|
|
103 | |
|
|
104 | #define MINIZ_HEADER_FILE_ONLY |
|
|
105 | #include "miniz.c" |
|
|
106 | // compression |
|
|
107 | |
|
|
108 | #endif |
|
|
109 | |
|
|
110 | #include <sys/stat.h> |
|
|
111 | #include <unistd.h> |
19 | #include <unistd.h> |
112 | #include <time.h> |
|
|
113 | #include <stdio.h> |
|
|
114 | #include <string.h> |
20 | #include <string.h> |
115 | #include <stdlib.h> |
21 | #include <stdlib.h> |
116 | #include <math.h> |
22 | #include <math.h> |
|
|
23 | #include "maptool.h" |
117 | #include "debug.h" |
24 | #include "debug.h" |
118 | #include "linguistics.h" |
25 | #include "linguistics.h" |
119 | #include "country.h" |
|
|
120 | #include "file.h" |
26 | #include "file.h" |
121 | |
27 | |
122 | /* triangulate */ |
|
|
123 | /* |
|
|
124 | #ifdef SINGLE |
|
|
125 | #define REAL float |
|
|
126 | #else // not SINGLE |
|
|
127 | #define REAL double |
|
|
128 | #endif // not SINGLE |
|
|
129 | #include "poly_to_tri002/triangle.h" |
|
|
130 | */ |
|
|
131 | |
|
|
132 | #include <signal.h> |
|
|
133 | |
|
|
134 | #ifdef MAPTOOL_TRIANGULATE |
|
|
135 | |
|
|
136 | #include "p2t/poly2tri.h" |
|
|
137 | #include "refine/refine.h" |
|
|
138 | #define MAX_HOLES_PER_POLY 50 |
|
|
139 | |
|
|
140 | #endif |
|
|
141 | |
|
|
142 | /* triangulate */ |
|
|
143 | |
|
|
144 | #define _FILE_OFFSET_BITS 64 |
|
|
145 | #define _LARGEFILE_SOURCE |
|
|
146 | #define _LARGEFILE64_SOURCE |
|
|
147 | |
|
|
148 | extern int doway2poi; |
|
|
149 | |
|
|
150 | static int in_way, in_node, in_relation; |
28 | static int in_way, in_node, in_relation; |
151 | static int nodeid, wayid; |
29 | static int nodeid,wayid; |
152 | long long current_id; |
30 | long long current_id; |
153 | |
31 | |
154 | static GHashTable *attr_hash, *country_table_hash; |
32 | static GHashTable *attr_hash,*country_table_hash,*attr_hash; |
155 | |
|
|
156 | void add_boundary_to_db(long long current_id, int admin_level, struct item_bin *item_bin_3, struct relation_member *memb); |
|
|
157 | |
33 | |
158 | static char *attr_present; |
34 | static char *attr_present; |
159 | static int attr_present_count; |
35 | static int attr_present_count; |
160 | |
36 | |
161 | static struct item_bin item; |
37 | static struct item_bin item; |
162 | |
38 | |
|
|
39 | |
163 | int maxspeed_attr_value; |
40 | int maxspeed_attr_value; |
164 | |
41 | |
165 | char debug_attr_buffer[BUFFER_SIZE]; |
42 | char debug_attr_buffer[BUFFER_SIZE]; |
166 | |
43 | |
167 | int flags[4]; |
44 | int flags[4]; |
… | |
… | |
171 | struct attr_bin osmid_attr; |
48 | struct attr_bin osmid_attr; |
172 | long int osmid_attr_value; |
49 | long int osmid_attr_value; |
173 | |
50 | |
174 | char is_in_buffer[BUFFER_SIZE]; |
51 | char is_in_buffer[BUFFER_SIZE]; |
175 | |
52 | |
176 | char attr_strings_buffer[BUFFER_SIZE * 16]; |
53 | char attr_strings_buffer[BUFFER_SIZE*16]; |
177 | int attr_strings_buffer_len; |
54 | int attr_strings_buffer_len; |
178 | int alt_name_found = 0; |
55 | |
179 | |
56 | |
180 | struct coord coord_buffer[65536]; |
57 | struct coord coord_buffer[65536]; |
181 | |
58 | |
182 | struct attr_mapping |
59 | struct attr_mapping { |
183 | { |
|
|
184 | enum item_type type; |
60 | enum item_type type; |
185 | int attr_present_idx_count; |
61 | int attr_present_idx_count; |
186 | int attr_present_idx[0]; |
62 | int attr_present_idx[0]; |
187 | }; |
63 | }; |
188 | |
64 | |
189 | static void nodes_ref_item_bin(struct item_bin *ib, int local_thread_num); |
|
|
190 | |
|
|
191 | static struct attr_mapping **attr_mapping_node; |
65 | static struct attr_mapping **attr_mapping_node; |
192 | static int attr_mapping_node_count; |
66 | static int attr_mapping_node_count; |
193 | static struct attr_mapping **attr_mapping_way; |
67 | static struct attr_mapping **attr_mapping_way; |
194 | static int attr_mapping_way_count; |
68 | static int attr_mapping_way_count; |
195 | static struct attr_mapping **attr_mapping_way2poi; |
|
|
196 | static int attr_mapping_way2poi_count; |
|
|
197 | |
69 | |
198 | static char *attr_present; |
70 | static char *attr_present; |
199 | static int attr_present_count; |
71 | static int attr_present_count; |
200 | |
72 | |
|
|
73 | |
|
|
74 | |
201 | enum attr_strings |
75 | enum attr_strings { |
202 | { |
76 | attr_string_phone, |
203 | 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_last, |
77 | attr_string_fax, |
|
|
78 | attr_string_email, |
|
|
79 | attr_string_url, |
|
|
80 | attr_string_street_name, |
|
|
81 | attr_string_street_name_systematic, |
|
|
82 | attr_string_house_number, |
|
|
83 | attr_string_label, |
|
|
84 | attr_string_postal, |
|
|
85 | attr_string_population, |
|
|
86 | attr_string_county_name, |
|
|
87 | attr_string_last, |
204 | }; |
88 | }; |
205 | |
89 | |
206 | char *attr_strings[attr_string_last]; |
90 | char *attr_strings[attr_string_last]; |
207 | |
91 | |
208 | char *osm_types[] = { "unknown", "node", "way", "relation" }; |
92 | char *osm_types[]={"unknown","node","way","relation"}; |
209 | |
93 | |
210 | #define IS_REF(c) ((c).x >= (1 << 30)) |
94 | #define IS_REF(c) ((c).x >= (1 << 30)) |
211 | #define REF(c) ((c).y) |
95 | #define REF(c) ((c).y) |
212 | #define SET_REF(c,ref) do { (c).x = 1 << 30; (c).y = ref ; } while(0) |
96 | #define SET_REF(c,ref) do { (c).x = 1 << 30; (c).y = ref ; } while(0) |
213 | |
97 | |
214 | struct country_table |
98 | struct country_table { |
215 | { |
|
|
216 | int countryid; |
99 | int countryid; |
217 | char *names; |
100 | char *names; |
218 | char *admin_levels; |
|
|
219 | FILE *file; |
101 | FILE *file; |
220 | int size; |
102 | int size; |
221 | struct rect r; |
103 | struct rect r; |
222 | } |
|
|
223 | country_table[] = |
104 | } country_table[] = { |
224 | { { 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" }, }; |
105 | { 4,"Afghanistan"}, |
|
|
106 | { 8,"Albania"}, |
|
|
107 | { 10,"Antarctica"}, |
|
|
108 | { 12,"Algeria"}, |
|
|
109 | { 16,"American Samoa"}, |
|
|
110 | { 20,"Andorra"}, |
|
|
111 | { 24,"Angola"}, |
|
|
112 | { 28,"Antigua and Barbuda"}, |
|
|
113 | { 31,"Azerbaijan"}, |
|
|
114 | { 32,"Argentina,República Argentina,AR "}, |
|
|
115 | { 36,"Australia,AUS"}, |
|
|
116 | { 40,"Austria,Österreich,AUT"}, |
|
|
117 | { 44,"Bahamas"}, |
|
|
118 | { 48,"Bahrain"}, |
|
|
119 | { 50,"Bangladesh"}, |
|
|
120 | { 51,"Armenia"}, |
|
|
121 | { 52,"Barbados"}, |
|
|
122 | { 56,"Belgium,Belgique,Belgie,België,Belgien"}, |
|
|
123 | { 60,"Bermuda"}, |
|
|
124 | { 64,"Bhutan"}, |
|
|
125 | { 68,"Bolivia, Plurinational State of"}, |
|
|
126 | { 70,"Bosnia and Herzegovina,Bosna i Hercegovina,Босна и Херцеговина"}, |
|
|
127 | { 72,"Botswana"}, |
|
|
128 | { 74,"Bouvet Island"}, |
|
|
129 | { 76,"Brazil"}, |
|
|
130 | { 84,"Belize"}, |
|
|
131 | { 86,"British Indian Ocean Territory"}, |
|
|
132 | { 90,"Solomon Islands"}, |
|
|
133 | { 92,"Virgin Islands, British"}, |
|
|
134 | { 96,"Brunei Darussalam"}, |
|
|
135 | { 100,"Bulgaria,България"}, |
|
|
136 | { 104,"Myanmar"}, |
|
|
137 | { 108,"Burundi"}, |
|
|
138 | { 112,"Belarus"}, |
|
|
139 | { 116,"Cambodia"}, |
|
|
140 | { 120,"Cameroon"}, |
|
|
141 | { 124,"Canada"}, |
|
|
142 | { 132,"Cape Verde"}, |
|
|
143 | { 136,"Cayman Islands"}, |
|
|
144 | { 140,"Central African Republic"}, |
|
|
145 | { 144,"Sri Lanka"}, |
|
|
146 | { 148,"Chad"}, |
|
|
147 | { 152,"Chile"}, |
|
|
148 | { 156,"China"}, |
|
|
149 | { 158,"Taiwan, Province of China"}, |
|
|
150 | { 162,"Christmas Island"}, |
|
|
151 | { 166,"Cocos (Keeling) Islands"}, |
|
|
152 | { 170,"Colombia"}, |
|
|
153 | { 174,"Comoros"}, |
|
|
154 | { 175,"Mayotte"}, |
|
|
155 | { 178,"Congo"}, |
|
|
156 | { 180,"Congo, the Democratic Republic of the"}, |
|
|
157 | { 184,"Cook Islands"}, |
|
|
158 | { 188,"Costa Rica"}, |
|
|
159 | { 191,"Croatia,Republika Hrvatska,HR"}, |
|
|
160 | { 192,"Cuba"}, |
|
|
161 | { 196,"Cyprus"}, |
|
|
162 | { 203,"Czech Republic,Česká republika,CZ"}, |
|
|
163 | { 204,"Benin"}, |
|
|
164 | { 208,"Denmark,Danmark,DK"}, |
|
|
165 | { 212,"Dominica"}, |
|
|
166 | { 214,"Dominican Republic"}, |
|
|
167 | { 218,"Ecuador"}, |
|
|
168 | { 222,"El Salvador"}, |
|
|
169 | { 226,"Equatorial Guinea"}, |
|
|
170 | { 231,"Ethiopia"}, |
|
|
171 | { 232,"Eritrea"}, |
|
|
172 | { 233,"Estonia"}, |
|
|
173 | { 234,"Faroe Islands,Føroyar"}, |
|
|
174 | { 238,"Falkland Islands (Malvinas)"}, |
|
|
175 | { 239,"South Georgia and the South Sandwich Islands"}, |
|
|
176 | { 242,"Fiji"}, |
|
|
177 | { 246,"Finland,Suomi"}, |
|
|
178 | { 248,"Åland Islands"}, |
|
|
179 | { 250,"France,République française,FR"}, |
|
|
180 | { 254,"French Guiana"}, |
|
|
181 | { 258,"French Polynesia"}, |
|
|
182 | { 260,"French Southern Territories"}, |
|
|
183 | { 262,"Djibouti"}, |
|
|
184 | { 266,"Gabon"}, |
|
|
185 | { 268,"Georgia"}, |
|
|
186 | { 270,"Gambia"}, |
|
|
187 | { 275,"Palestinian Territory, Occupied"}, |
|
|
188 | { 276,"Germany,Deutschland,Bundesrepublik Deutschland"}, |
|
|
189 | { 288,"Ghana"}, |
|
|
190 | { 292,"Gibraltar"}, |
|
|
191 | { 296,"Kiribati"}, |
|
|
192 | { 300,"Greece"}, |
|
|
193 | { 304,"Greenland"}, |
|
|
194 | { 308,"Grenada"}, |
|
|
195 | { 312,"Guadeloupe"}, |
|
|
196 | { 316,"Guam"}, |
|
|
197 | { 320,"Guatemala"}, |
|
|
198 | { 324,"Guinea"}, |
|
|
199 | { 328,"Guyana"}, |
|
|
200 | { 332,"Haiti"}, |
|
|
201 | { 334,"Heard Island and McDonald Islands"}, |
|
|
202 | { 336,"Holy See (Vatican City State)"}, |
|
|
203 | { 340,"Honduras"}, |
|
|
204 | { 344,"Hong Kong"}, |
|
|
205 | { 348,"Hungary,Magyarország"}, |
|
|
206 | { 352,"Iceland"}, |
|
|
207 | { 356,"India"}, |
|
|
208 | { 360,"Indonesia"}, |
|
|
209 | { 364,"Iran, Islamic Republic of"}, |
|
|
210 | { 368,"Iraq"}, |
|
|
211 | { 372,"Ireland"}, |
|
|
212 | { 376,"Israel"}, |
|
|
213 | { 380,"Italy,Italia"}, |
|
|
214 | { 384,"Côte d'Ivoire"}, |
|
|
215 | { 388,"Jamaica"}, |
|
|
216 | { 392,"Japan"}, |
|
|
217 | { 398,"Kazakhstan"}, |
|
|
218 | { 400,"Jordan"}, |
|
|
219 | { 404,"Kenya"}, |
|
|
220 | { 408,"Korea, Democratic People's Republic of"}, |
|
|
221 | { 410,"Korea, Republic of"}, |
|
|
222 | { 414,"Kuwait"}, |
|
|
223 | { 417,"Kyrgyzstan"}, |
|
|
224 | { 418,"Lao People's Democratic Republic"}, |
|
|
225 | { 422,"Lebanon"}, |
|
|
226 | { 426,"Lesotho"}, |
|
|
227 | { 428,"Latvia"}, |
|
|
228 | { 430,"Liberia"}, |
|
|
229 | { 434,"Libyan Arab Jamahiriya"}, |
|
|
230 | { 438,"Liechtenstein"}, |
|
|
231 | { 440,"Lithuania,Lietuva"}, |
|
|
232 | { 442,"Luxembourg"}, |
|
|
233 | { 446,"Macao"}, |
|
|
234 | { 450,"Madagascar"}, |
|
|
235 | { 454,"Malawi"}, |
|
|
236 | { 458,"Malaysia"}, |
|
|
237 | { 462,"Maldives"}, |
|
|
238 | { 466,"Mali"}, |
|
|
239 | { 470,"Malta"}, |
|
|
240 | { 474,"Martinique"}, |
|
|
241 | { 478,"Mauritania"}, |
|
|
242 | { 480,"Mauritius"}, |
|
|
243 | { 484,"Mexico"}, |
|
|
244 | { 492,"Monaco"}, |
|
|
245 | { 496,"Mongolia"}, |
|
|
246 | { 498,"Moldova, Republic of"}, |
|
|
247 | { 499,"Montenegro,Црна Гора,Crna Gora"}, |
|
|
248 | { 500,"Montserrat"}, |
|
|
249 | { 504,"Morocco"}, |
|
|
250 | { 508,"Mozambique"}, |
|
|
251 | { 512,"Oman"}, |
|
|
252 | { 516,"Namibia"}, |
|
|
253 | { 520,"Nauru"}, |
|
|
254 | { 524,"Nepal"}, |
|
|
255 | { 528,"Nederland,The Netherlands,Niederlande,NL,Netherlands"}, |
|
|
256 | { 530,"Netherlands Antilles"}, |
|
|
257 | { 533,"Aruba"}, |
|
|
258 | { 540,"New Caledonia"}, |
|
|
259 | { 548,"Vanuatu"}, |
|
|
260 | { 554,"New Zealand"}, |
|
|
261 | { 558,"Nicaragua"}, |
|
|
262 | { 562,"Niger"}, |
|
|
263 | { 566,"Nigeria"}, |
|
|
264 | { 570,"Niue"}, |
|
|
265 | { 574,"Norfolk Island"}, |
|
|
266 | { 578,"Norway,Norge,Noreg,NO"}, |
|
|
267 | { 580,"Northern Mariana Islands"}, |
|
|
268 | { 581,"United States Minor Outlying Islands"}, |
|
|
269 | { 583,"Micronesia, Federated States of"}, |
|
|
270 | { 584,"Marshall Islands"}, |
|
|
271 | { 585,"Palau"}, |
|
|
272 | { 586,"Pakistan"}, |
|
|
273 | { 591,"Panama"}, |
|
|
274 | { 598,"Papua New Guinea"}, |
|
|
275 | { 600,"Paraguay"}, |
|
|
276 | { 604,"Peru"}, |
|
|
277 | { 608,"Philippines"}, |
|
|
278 | { 612,"Pitcairn"}, |
|
|
279 | { 616,"Poland,Polska,PL"}, |
|
|
280 | { 620,"Portugal"}, |
|
|
281 | { 624,"Guinea-Bissau"}, |
|
|
282 | { 626,"Timor-Leste"}, |
|
|
283 | { 630,"Puerto Rico"}, |
|
|
284 | { 634,"Qatar"}, |
|
|
285 | { 638,"Réunion"}, |
|
|
286 | { 642,"România,Romania,RO"}, |
|
|
287 | { 643,"Россия,Российская Федерация,Russia,Russian Federation"}, |
|
|
288 | { 646,"Rwanda"}, |
|
|
289 | { 652,"Saint Barthélemy"}, |
|
|
290 | { 654,"Saint Helena, Ascension and Tristan da Cunha"}, |
|
|
291 | { 659,"Saint Kitts and Nevis"}, |
|
|
292 | { 660,"Anguilla"}, |
|
|
293 | { 662,"Saint Lucia"}, |
|
|
294 | { 663,"Saint Martin (French part)"}, |
|
|
295 | { 666,"Saint Pierre and Miquelon"}, |
|
|
296 | { 670,"Saint Vincent and the Grenadines"}, |
|
|
297 | { 674,"San Marino"}, |
|
|
298 | { 678,"Sao Tome and Principe"}, |
|
|
299 | { 682,"Saudi Arabia"}, |
|
|
300 | { 686,"Senegal"}, |
|
|
301 | { 688,"Srbija,Србија,Serbia"}, |
|
|
302 | { 690,"Seychelles"}, |
|
|
303 | { 694,"Sierra Leone"}, |
|
|
304 | { 702,"Singapore"}, |
|
|
305 | { 703,"Slovakia,Slovensko,SK"}, |
|
|
306 | { 704,"Viet Nam"}, |
|
|
307 | { 705,"Slovenia,Republika Slovenija,SI"}, |
|
|
308 | { 706,"Somalia"}, |
|
|
309 | { 710,"South Africa"}, |
|
|
310 | { 716,"Zimbabwe"}, |
|
|
311 | { 724,"Spain,Espana,España,Reino de Espana,Reino de España"}, |
|
|
312 | { 732,"Western Sahara"}, |
|
|
313 | { 736,"Sudan"}, |
|
|
314 | { 740,"Suriname"}, |
|
|
315 | { 744,"Svalbard and Jan Mayen"}, |
|
|
316 | { 748,"Swaziland"}, |
|
|
317 | { 752,"Sweden,Sverige,Konungariket Sverige,SE"}, |
|
|
318 | { 756,"Switzerland,Schweiz"}, |
|
|
319 | { 760,"Syrian Arab Republic"}, |
|
|
320 | { 762,"Tajikistan"}, |
|
|
321 | { 764,"Thailand"}, |
|
|
322 | { 768,"Togo"}, |
|
|
323 | { 772,"Tokelau"}, |
|
|
324 | { 776,"Tonga"}, |
|
|
325 | { 780,"Trinidad and Tobago"}, |
|
|
326 | { 784,"United Arab Emirates"}, |
|
|
327 | { 788,"Tunisia"}, |
|
|
328 | { 792,"Turkey"}, |
|
|
329 | { 795,"Turkmenistan"}, |
|
|
330 | { 796,"Turks and Caicos Islands"}, |
|
|
331 | { 798,"Tuvalu"}, |
|
|
332 | { 800,"Uganda"}, |
|
|
333 | { 804,"Ukraine"}, |
|
|
334 | { 807,"Macedonia,Македонија"}, |
|
|
335 | { 818,"Egypt"}, |
|
|
336 | { 826,"United Kingdom,UK"}, |
|
|
337 | { 831,"Guernsey"}, |
|
|
338 | { 832,"Jersey"}, |
|
|
339 | { 833,"Isle of Man"}, |
|
|
340 | { 834,"Tanzania, United Republic of"}, |
|
|
341 | { 840,"USA"}, |
|
|
342 | { 850,"Virgin Islands, U.S."}, |
|
|
343 | { 854,"Burkina Faso"}, |
|
|
344 | { 858,"Uruguay"}, |
|
|
345 | { 860,"Uzbekistan"}, |
|
|
346 | { 862,"Venezuela, Bolivarian Republic of"}, |
|
|
347 | { 876,"Wallis and Futuna"}, |
|
|
348 | { 882,"Samoa"}, |
|
|
349 | { 887,"Yemen"}, |
|
|
350 | { 894,"Zambia"}, |
|
|
351 | { 999,"Unknown"}, |
|
|
352 | }; |
225 | |
353 | |
226 | // first char - item type |
|
|
227 | // =w - ways |
|
|
228 | // =? - used both for nodes and ways |
|
|
229 | // otherwise - nodes |
|
|
230 | |
354 | |
231 | |
355 | static char *attrmap={ |
232 | // for coastline-only map |
|
|
233 | static char *attrmap_cl = { "n *=* point_unkn\n" |
|
|
234 | "w *=* street_unkn\n" |
356 | "n *=* point_unkn\n" |
235 | "w natural=coastline water_line\n" }; |
|
|
236 | |
|
|
237 | // for border-only map |
|
|
238 | static char *attrmap_bo = { "n *=* point_unkn\n" |
|
|
239 | "w *=* street_unkn\n" |
|
|
240 | "w boundary=administrative,admin_level=2 border_country\n" |
|
|
241 | "w boundary=territorial,admin_level=2 border_country\n" |
|
|
242 | "w boundary=maritime,admin_level=2 border_country\n" |
|
|
243 | "w administrative=boundary,admin_level=2 border_country\n" |
|
|
244 | "w boundary=administrative,maritime=yes,admin_level=2 border_country\n" |
|
|
245 | "w boundary=administrative,maritime=yes,admin_level=4 border_country\n" |
|
|
246 | "w boundary=administrative,border_type=state,admin_level=4 border_country\n" }; |
|
|
247 | |
|
|
248 | // ========================== |
|
|
249 | // for USA |
|
|
250 | // ========================== |
|
|
251 | // admin_level = 4 |
|
|
252 | // border_type = state |
|
|
253 | // boundary = administrative |
|
|
254 | // ========================== |
|
|
255 | |
|
|
256 | |
|
|
257 | // for normal map |
|
|
258 | static char *attrmap_normal = { "n *=* point_unkn\n" |
|
|
259 | //// "n Annehmlichkeit=Hochsitz poi_hunting_stand\n" |
357 | // "n Annehmlichkeit=Hochsitz poi_hunting_stand\n" |
260 | "n addr:housenumber=* house_number\n" |
358 | "n addr:housenumber=* house_number\n" |
261 | "n aeroway=aerodrome poi_airport\n" |
359 | "n aeroway=aerodrome poi_airport\n" |
262 | "n aeroway=airport poi_airport\n" |
360 | "n aeroway=airport poi_airport\n" |
263 | "n aeroway=helipad poi_heliport\n" |
361 | "n aeroway=helipad poi_heliport\n" |
264 | "n aeroway=terminal poi_airport\n" |
362 | "n aeroway=terminal poi_airport\n" |
265 | "n amenity=atm poi_bank\n" |
363 | "n amenity=atm poi_bank\n" |
266 | "n amenity=bank poi_bank\n" |
364 | "n amenity=bank poi_bank\n" |
267 | "n amenity=bar poi_bar\n" |
365 | "n amenity=bar poi_bar\n" |
268 | //"n amenity=bench poi_bench\n" |
366 | "n amenity=bench poi_bench\n" |
269 | "n amenity=biergarten poi_biergarten\n" |
367 | "n amenity=biergarten poi_biergarten\n" |
270 | "n amenity=bus_station poi_bus_station\n" |
368 | "n amenity=bus_station poi_bus_station\n" |
271 | "n amenity=cafe poi_cafe\n" |
369 | "n amenity=cafe poi_cafe\n" |
272 | "n amenity=car_wash poi_car_wash\n" |
370 | "n amenity=car_wash poi_car_wash\n" |
273 | "n amenity=cinema poi_cinema\n" |
371 | "n amenity=cinema poi_cinema\n" |
274 | "n amenity=college poi_school_college\n" |
372 | "n amenity=college poi_school_college\n" |
275 | "n amenity=courthouse poi_justice\n" |
373 | "n amenity=courthouse poi_justice\n" |
276 | //"n amenity=drinking_water poi_potable_water\n" |
374 | "n amenity=drinking_water poi_potable_water\n" |
277 | "n amenity=fast_food poi_fastfood\n" |
375 | "n amenity=fast_food poi_fastfood\n" |
278 | "n amenity=fire_station poi_firebrigade\n" |
376 | "n amenity=fire_station poi_firebrigade\n" |
279 | //"n amenity=fountain poi_fountain\n" |
377 | "n amenity=fountain poi_fountain\n" |
280 | "n amenity=fuel poi_fuel\n" |
378 | "n amenity=fuel poi_fuel\n" |
281 | "n amenity=grave_yard poi_cemetery\n" |
379 | "n amenity=grave_yard poi_cemetery\n" |
282 | "n amenity=hospital poi_hospital\n" |
380 | "n amenity=hospital poi_hospital\n" |
283 | //"n amenity=hunting_stand poi_hunting_stand\n" |
381 | "n amenity=hunting_stand poi_hunting_stand\n" |
284 | "n amenity=kindergarten poi_kindergarten\n" |
382 | "n amenity=kindergarten poi_kindergarten\n" |
285 | "n amenity=library poi_library\n" |
383 | "n amenity=library poi_library\n" |
286 | "n amenity=nightclub poi_nightclub\n" |
384 | "n amenity=nightclub poi_nightclub\n" |
287 | //"n amenity=park_bench poi_bench\n" |
385 | "n amenity=park_bench poi_bench\n" |
288 | "n amenity=parking poi_car_parking\n" |
386 | "n amenity=parking poi_car_parking\n" |
289 | "n amenity=pharmacy poi_pharmacy\n" |
387 | "n amenity=pharmacy poi_pharmacy\n" |
290 | "n amenity=place_of_worship,religion=christian poi_church\n" |
388 | "n amenity=place_of_worship,religion=christian poi_church\n" |
291 | "n amenity=place_of_worship poi_worship\n" |
389 | "n amenity=place_of_worship poi_worship\n" |
292 | "n amenity=police poi_police\n" |
390 | "n amenity=police poi_police\n" |
293 | //"n amenity=post_box poi_post_box\n" |
391 | "n amenity=post_box poi_post_box\n" |
294 | "n amenity=post_office poi_post_office\n" |
392 | "n amenity=post_office poi_post_office\n" |
295 | "n amenity=prison poi_prison\n" |
393 | "n amenity=prison poi_prison\n" |
296 | //"n amenity=pub poi_pub\n" |
394 | "n amenity=pub poi_pub\n" |
297 | "n amenity=public_building poi_public_office\n" |
395 | "n amenity=public_building poi_public_office\n" |
298 | //"n amenity=recycling poi_recycling\n" |
396 | "n amenity=recycling poi_recycling\n" |
299 | "n amenity=restaurant,cuisine=fine_dining poi_dining\n" |
397 | "n amenity=restaurant,cuisine=fine_dining poi_dining\n" |
300 | "n amenity=restaurant poi_restaurant\n" |
398 | "n amenity=restaurant poi_restaurant\n" |
301 | "n amenity=school poi_school\n" |
399 | "n amenity=school poi_school\n" |
302 | //"n amenity=shelter poi_shelter\n" |
400 | "n amenity=shelter poi_shelter\n" |
303 | "n amenity=taxi poi_taxi\n" |
401 | "n amenity=taxi poi_taxi\n" |
304 | //"n amenity=tec_common tec_common\n" |
402 | "n amenity=tec_common tec_common\n" |
305 | //"n amenity=telephone poi_telephone\n" |
403 | "n amenity=telephone poi_telephone\n" |
306 | "n amenity=theatre poi_theater\n" |
404 | "n amenity=theatre poi_theater\n" |
307 | "n amenity=toilets poi_restroom\n" |
405 | "n amenity=toilets poi_restroom\n" |
308 | "n amenity=townhall poi_townhall\n" |
406 | "n amenity=townhall poi_townhall\n" |
309 | "n amenity=university poi_school_university\n" |
407 | "n amenity=university poi_school_university\n" |
310 | //"n amenity=vending_machine poi_vending_machine\n" |
408 | "n amenity=vending_machine poi_vending_machine\n" |
311 | "n barrier=bollard barrier_bollard\n" |
409 | "n barrier=bollard barrier_bollard\n" |
312 | "n barrier=cycle_barrier barrier_cycle\n" |
410 | "n barrier=cycle_barrier barrier_cycle\n" |
313 | "n barrier=lift_gate barrier_lift_gate\n" |
411 | "n barrier=lift_gate barrier_lift_gate\n" |
314 | //"n car=car_rental poi_car_rent\n" |
412 | "n car=car_rental poi_car_rent\n" |
315 | "n highway=bus_station poi_bus_station\n" |
413 | "n highway=bus_station poi_bus_station\n" |
316 | "n highway=bus_stop poi_bus_stop\n" |
414 | "n highway=bus_stop poi_bus_stop\n" |
317 | "n highway=mini_roundabout mini_roundabout\n" |
415 | "n highway=mini_roundabout mini_roundabout\n" |
318 | "n highway=motorway_junction highway_exit\n" |
416 | "n highway=motorway_junction highway_exit\n" |
319 | "n highway=stop traffic_sign_stop\n" |
417 | "n highway=stop traffic_sign_stop\n" |
320 | "n highway=toll_booth poi_toll_booth\n" |
418 | "n highway=toll_booth poi_toll_booth\n" |
321 | "n highway=traffic_signals traffic_signals\n" |
419 | "n highway=traffic_signals traffic_signals\n" |
322 | "n highway=turning_circle turning_circle\n" |
420 | "n highway=turning_circle turning_circle\n" |
323 | //"n historic=boundary_stone poi_boundary_stone\n" |
421 | "n historic=boundary_stone poi_boundary_stone\n" |
324 | "n historic=castle poi_castle\n" |
422 | "n historic=castle poi_castle\n" |
325 | "n historic=memorial poi_memorial\n" |
423 | "n historic=memorial poi_memorial\n" |
326 | "n historic=monument poi_monument\n" |
424 | "n historic=monument poi_monument\n" |
327 | "n historic=ruins poi_ruins\n" |
425 | "n historic=ruins poi_ruins\n" |
328 | //// "n historic=* poi_ruins\n" |
426 | // "n historic=* poi_ruins\n" |
329 | "n landuse=cemetery poi_cemetery\n" |
427 | "n landuse=cemetery poi_cemetery\n" |
330 | //"n leisure=fishing poi_fish\n" |
428 | "n leisure=fishing poi_fish\n" |
331 | "n leisure=golf_course poi_golf\n" |
429 | "n leisure=golf_course poi_golf\n" |
332 | "n leisure=marina poi_marine\n" |
430 | "n leisure=marina poi_marine\n" |
333 | //"n leisure=playground poi_playground\n" |
431 | "n leisure=playground poi_playground\n" |
334 | //"n leisure=slipway poi_boat_ramp\n" |
432 | "n leisure=slipway poi_boat_ramp\n" |
335 | //"n leisure=sports_centre poi_sport\n" |
433 | "n leisure=sports_centre poi_sport\n" |
336 | "n leisure=stadium poi_stadium\n" |
434 | "n leisure=stadium poi_stadium\n" |
337 | //"n man_made=tower poi_tower\n" |
435 | "n man_made=tower poi_tower\n" |
338 | "n military=airfield poi_military\n" |
436 | "n military=airfield poi_military\n" |
339 | //"n military=barracks poi_military\n" |
437 | "n military=barracks poi_military\n" |
340 | //"n military=bunker poi_military\n" |
438 | "n military=bunker poi_military\n" |
341 | "n military=danger_area poi_danger_area\n" |
439 | "n military=danger_area poi_danger_area\n" |
342 | "n military=range poi_military\n" |
440 | "n military=range poi_military\n" |
343 | "n natural=bay poi_bay\n" |
441 | "n natural=bay poi_bay\n" |
344 | "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation |
442 | "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation |
345 | //"n natural=tree poi_tree\n" |
443 | "n natural=tree poi_tree\n" |
346 | "n place=city town_label_2e5\n" |
444 | "n place=city town_label_2e5\n" |
347 | "n place=hamlet town_label_2e2\n" |
445 | "n place=hamlet town_label_2e2\n" |
348 | "n place=locality town_label_2e0\n" |
446 | "n place=locality town_label_2e0\n" |
349 | "n place=suburb district_label\n" |
447 | "n place=suburb district_label\n" |
350 | "n place=town town_label_2e4\n" |
448 | "n place=town town_label_2e4\n" |
351 | "n place=village town_label_2e3\n" |
449 | "n place=village town_label_2e3\n" |
352 | //"n power=tower power_tower\n" |
450 | "n power=tower power_tower\n" |
353 | //"n power=sub_station power_substation\n" |
451 | "n power=sub_station power_substation\n" |
354 | "n railway=halt poi_rail_halt\n" |
452 | "n railway=halt poi_rail_halt\n" |
355 | "n railway=level_crossing poi_level_crossing\n" |
453 | "n railway=level_crossing poi_level_crossing\n" |
356 | "n railway=station poi_rail_station\n" |
454 | "n railway=station poi_rail_station\n" |
357 | "n railway=tram_stop poi_rail_tram_stop\n" |
455 | "n railway=tram_stop poi_rail_tram_stop\n" |
358 | //"n shop=baker poi_shop_baker\n" |
456 | "n shop=baker poi_shop_baker\n" |
359 | //"n shop=bakery poi_shop_baker\n" |
457 | "n shop=bakery poi_shop_baker\n" |
360 | //"n shop=beverages poi_shop_beverages\n" |
458 | "n shop=beverages poi_shop_beverages\n" |
361 | //"n shop=bicycle poi_shop_bicycle\n" |
459 | "n shop=bicycle poi_shop_bicycle\n" |
362 | //"n shop=butcher poi_shop_butcher\n" |
460 | "n shop=butcher poi_shop_butcher\n" |
363 | "n shop=car poi_car_dealer_parts\n" |
461 | "n shop=car poi_car_dealer_parts\n" |
364 | "n shop=car_repair poi_repair_service\n" |
462 | "n shop=car_repair poi_repair_service\n" |
365 | //"n shop=clothes poi_shop_apparel\n" |
463 | "n shop=clothes poi_shop_apparel\n" |
366 | //"n shop=convenience poi_shop_grocery\n" |
464 | "n shop=convenience poi_shop_grocery\n" |
367 | //"n shop=drogist poi_shop_drugstore\n" |
465 | "n shop=drogist poi_shop_drugstore\n" |
368 | //"n shop=florist poi_shop_florist\n" |
466 | "n shop=florist poi_shop_florist\n" |
369 | //"n shop=fruit poi_shop_fruit\n" |
467 | "n shop=fruit poi_shop_fruit\n" |
370 | //"n shop=furniture poi_shop_furniture\n" |
468 | "n shop=furniture poi_shop_furniture\n" |
371 | //"n shop=garden_centre poi_shop_handg\n" |
469 | "n shop=garden_centre poi_shop_handg\n" |
372 | //"n shop=hardware poi_shop_handg\n" |
470 | "n shop=hardware poi_shop_handg\n" |
373 | //"n shop=hairdresser poi_hairdresser\n" |
471 | "n shop=hairdresser poi_hairdresser\n" |
374 | //"n shop=kiosk poi_shop_kiosk\n" |
472 | "n shop=kiosk poi_shop_kiosk\n" |
375 | //"n shop=optician poi_shop_optician\n" |
473 | "n shop=optician poi_shop_optician\n" |
376 | //"n shop=parfum poi_shop_parfum\n" |
474 | "n shop=parfum poi_shop_parfum\n" |
377 | //"n shop=photo poi_shop_photo\n" |
475 | "n shop=photo poi_shop_photo\n" |
378 | //"n shop=shoes poi_shop_shoes\n" |
476 | "n shop=shoes poi_shop_shoes\n" |
379 | "n shop=supermarket poi_shopping\n" |
477 | "n shop=supermarket poi_shopping\n" |
380 | //"n sport=10pin poi_bowling\n" |
478 | "n sport=10pin poi_bowling\n" |
381 | //"n sport=baseball poi_baseball\n" |
479 | "n sport=baseball poi_baseball\n" |
382 | //"n sport=basketball poi_basketball\n" |
480 | "n sport=basketball poi_basketball\n" |
383 | //"n sport=climbing poi_climbing\n" |
481 | "n sport=climbing poi_climbing\n" |
384 | //"n sport=golf poi_golf\n" |
482 | "n sport=golf poi_golf\n" |
385 | //"n sport=motor_sports poi_motor_sport\n" |
483 | "n sport=motor_sports poi_motor_sport\n" |
386 | //"n sport=skiing poi_skiing\n" |
484 | "n sport=skiing poi_skiing\n" |
387 | //"n sport=soccer poi_soccer\n" |
485 | "n sport=soccer poi_soccer\n" |
388 | "n sport=stadium poi_stadium\n" |
486 | "n sport=stadium poi_stadium\n" |
389 | "n sport=swimming poi_swimming\n" |
487 | "n sport=swimming poi_swimming\n" |
390 | //"n sport=tennis poi_tennis\n" |
488 | "n sport=tennis poi_tennis\n" |
391 | "n tourism=attraction poi_attraction\n" |
489 | "n tourism=attraction poi_attraction\n" |
392 | "n tourism=camp_site poi_camp_rv\n" |
490 | "n tourism=camp_site poi_camp_rv\n" |
393 | "n tourism=caravan_site poi_camp_rv\n" |
491 | "n tourism=caravan_site poi_camp_rv\n" |
394 | "n tourism=guest_house poi_guesthouse\n" |
492 | "n tourism=guest_house poi_guesthouse\n" |
395 | "n tourism=hostel poi_hostel\n" |
493 | "n tourism=hostel poi_hostel\n" |
396 | "n tourism=hotel poi_hotel\n" |
494 | "n tourism=hotel poi_hotel\n" |
397 | "n tourism=information poi_information\n" |
495 | "n tourism=information poi_information\n" |
398 | "n tourism=motel poi_motel\n" |
496 | "n tourism=motel poi_motel\n" |
399 | "n tourism=museum poi_museum_history\n" |
497 | "n tourism=museum poi_museum_history\n" |
400 | //"n tourism=picnic_site poi_picnic\n" |
498 | "n tourism=picnic_site poi_picnic\n" |
401 | "n tourism=theme_park poi_resort\n" |
499 | "n tourism=theme_park poi_resort\n" |
402 | //"n tourism=viewpoint poi_viewpoint\n" |
500 | "n tourism=viewpoint poi_viewpoint\n" |
403 | "n tourism=zoo poi_zoo\n" |
501 | "n tourism=zoo poi_zoo\n" |
404 | "n traffic_sign=city_limit traffic_sign_city_limit\n" |
502 | "n traffic_sign=city_limit traffic_sign_city_limit\n" |
405 | "n highway=speed_camera tec_common\n" |
503 | "n highway=speed_camera tec_common\n" |
406 | "w *=* street_unkn\n" |
504 | "w *=* street_unkn\n" |
407 | "w addr:interpolation=even house_number_interpolation_even\n" |
505 | "w addr:interpolation=even house_number_interpolation_even\n" |
408 | "w addr:interpolation=odd house_number_interpolation_odd\n" |
506 | "w addr:interpolation=odd house_number_interpolation_odd\n" |
409 | "w addr:interpolation=all house_number_interpolation_all\n" |
507 | "w addr:interpolation=all house_number_interpolation_all\n" |
410 | "w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n" |
508 | "w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n" |
411 | //"w aerialway=cable_car lift_cable_car\n" |
509 | "w aerialway=cable_car lift_cable_car\n" |
412 | //"w aerialway=chair_lift lift_chair\n" |
510 | "w aerialway=chair_lift lift_chair\n" |
413 | //"w aerialway=drag_lift lift_drag\n" |
511 | "w aerialway=drag_lift lift_drag\n" |
414 | "w aeroway=aerodrome poly_airport\n" |
512 | "w aeroway=aerodrome poly_airport\n" |
415 | "w aeroway=apron poly_apron\n" |
513 | "w aeroway=apron poly_apron\n" |
416 | "w aeroway=runway aeroway_runway\n" |
514 | "w aeroway=runway aeroway_runway\n" |
417 | "w aeroway=taxiway aeroway_taxiway\n" |
515 | "w aeroway=taxiway aeroway_taxiway\n" |
418 | "w aeroway=terminal poly_terminal\n" |
516 | "w aeroway=terminal poly_terminal\n" |
419 | "w amenity=college poly_college\n" |
517 | "w amenity=college poly_college\n" |
420 | //"w amenity=grave_yard poly_cemetery\n" |
518 | "w amenity=grave_yard poly_cemetery\n" |
421 | "w amenity=parking poly_car_parking\n" |
519 | "w amenity=parking poly_car_parking\n" |
422 | "w amenity=place_of_worship poly_building\n" |
520 | "w amenity=place_of_worship poly_building\n" |
423 | "w amenity=university poly_university\n" |
521 | "w amenity=university poly_university\n" |
424 | // "w boundary=administrative,admin_level=2 border_country\n" --> in border map |
522 | "w boundary=administrative,admin_level=2 border_country\n" |
425 | //"w boundary=civil border_civil\n" |
523 | "w boundary=civil border_civil\n" |
426 | "w boundary=national_park border_national_park\n" |
524 | "w boundary=national_park border_national_park\n" |
427 | "w boundary=political border_political\n" |
525 | "w boundary=political border_political\n" |
428 | "w building=* poly_building\n" |
526 | "w building=* poly_building\n" |
429 | "w contour_ext=elevation_major height_line_1\n" |
527 | "w contour_ext=elevation_major height_line_1\n" |
430 | "w contour_ext=elevation_medium height_line_2\n" |
528 | "w contour_ext=elevation_medium height_line_2\n" |
… | |
… | |
444 | "w highway=path,bicycle=official cycleway\n" |
542 | "w highway=path,bicycle=official cycleway\n" |
445 | "w highway=path,foot=designated footway\n" |
543 | "w highway=path,foot=designated footway\n" |
446 | "w highway=path,foot=official footway\n" |
544 | "w highway=path,foot=official footway\n" |
447 | "w highway=path,horse=designated bridleway\n" |
545 | "w highway=path,horse=designated bridleway\n" |
448 | "w highway=path,horse=official bridleway\n" |
546 | "w highway=path,horse=official bridleway\n" |
449 | //"w highway=path,sac_scale=alpine_hiking hiking_alpine\n" |
547 | "w highway=path,sac_scale=alpine_hiking hiking_alpine\n" |
450 | //"w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n" |
548 | "w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n" |
451 | //"w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n" |
549 | "w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n" |
452 | //"w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n" |
550 | "w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n" |
453 | //"w highway=path,sac_scale=hiking hiking\n" |
551 | "w highway=path,sac_scale=hiking hiking\n" |
454 | //"w highway=path,sac_scale=mountain_hiking hiking_mountain\n" |
552 | "w highway=path,sac_scale=mountain_hiking hiking_mountain\n" |
455 | "w highway=pedestrian street_pedestrian\n" |
553 | "w highway=pedestrian street_pedestrian\n" |
456 | "w highway=pedestrian,area=1 poly_pedestrian\n" |
554 | "w highway=pedestrian,area=1 poly_pedestrian\n" |
457 | "w highway=plaza poly_plaza\n" |
555 | "w highway=plaza poly_plaza\n" |
458 | "w highway=motorway highway_land\n" |
556 | "w highway=motorway highway_land\n" |
459 | "w highway=motorway,rural=0 highway_city\n" |
557 | "w highway=motorway,rural=0 highway_city\n" |
… | |
… | |
508 | "w highway=steps steps\n" |
606 | "w highway=steps steps\n" |
509 | "w historic=archaeological_site poly_archaeological_site\n" |
607 | "w historic=archaeological_site poly_archaeological_site\n" |
510 | "w historic=battlefield poly_battlefield\n" |
608 | "w historic=battlefield poly_battlefield\n" |
511 | "w historic=ruins poly_ruins\n" |
609 | "w historic=ruins poly_ruins\n" |
512 | "w historic=town gate poly_building\n" |
610 | "w historic=town gate poly_building\n" |
513 | //"w landuse=allotments poly_allotments\n" |
611 | "w landuse=allotments poly_allotments\n" |
514 | //"w landuse=basin poly_basin\n" |
612 | "w landuse=basin poly_basin\n" |
515 | //"w landuse=brownfield poly_brownfield\n" |
613 | "w landuse=brownfield poly_brownfield\n" |
516 | "w landuse=cemetery poly_cemetery\n" |
614 | "w landuse=cemetery poly_cemetery\n" |
517 | //"w landuse=commercial poly_commercial\n" |
615 | "w landuse=commercial poly_commercial\n" |
518 | //"w landuse=construction poly_construction\n" |
616 | "w landuse=construction poly_construction\n" |
519 | //"w landuse=farm poly_farm\n" |
617 | "w landuse=farm poly_farm\n" |
520 | //"w landuse=farmland poly_farm\n" |
618 | "w landuse=farmland poly_farm\n" |
521 | //"w landuse=farmyard poly_town\n" |
619 | "w landuse=farmyard poly_town\n" |
522 | "w landuse=forest poly_wood\n" |
620 | "w landuse=forest poly_wood\n" |
523 | "w landuse=greenfield poly_greenfield\n" |
621 | "w landuse=greenfield poly_greenfield\n" |
524 | //"w landuse=industrial poly_industry\n" |
622 | "w landuse=industrial poly_industry\n" |
525 | //"w landuse=landfill poly_landfill\n" |
623 | "w landuse=landfill poly_landfill\n" |
526 | "w landuse=military poly_military\n" |
624 | "w landuse=military poly_military\n" |
527 | "w landuse=plaza poly_plaza\n" |
625 | "w landuse=plaza poly_plaza\n" |
528 | //"w landuse=quarry poly_quarry\n" |
626 | "w landuse=quarry poly_quarry\n" |
529 | "w landuse=railway poly_railway\n" |
627 | "w landuse=railway poly_railway\n" |
530 | //"w landuse=recreation_ground poly_recreation_ground\n" |
628 | "w landuse=recreation_ground poly_recreation_ground\n" |
531 | "w landuse=reservoir poly_reservoir\n" |
629 | "w landuse=reservoir poly_reservoir\n" |
532 | //"w landuse=residential poly_town\n" |
630 | "w landuse=residential poly_town\n" |
533 | //"w landuse=residential,area=1 poly_town\n" |
631 | "w landuse=residential,area=1 poly_town\n" |
534 | //"w landuse=retail poly_retail\n" |
632 | "w landuse=retail poly_retail\n" |
535 | //"w landuse=village_green poly_village_green\n" |
633 | "w landuse=village_green poly_village_green\n" |
536 | //"w landuse=vineyard poly_farm\n" |
634 | "w landuse=vineyard poly_farm\n" |
537 | //"w leisure=common poly_common\n" |
635 | "w leisure=common poly_common\n" |
538 | //"w leisure=fishing poly_fishing\n" |
636 | "w leisure=fishing poly_fishing\n" |
539 | //"w leisure=garden poly_garden\n" |
637 | "w leisure=garden poly_garden\n" |
540 | //"w leisure=golf_course poly_golf_course\n" |
638 | "w leisure=golf_course poly_golf_course\n" |
541 | //"w leisure=marina poly_marina\n" |
639 | "w leisure=marina poly_marina\n" |
542 | //"w leisure=nature_reserve poly_nature_reserve\n" |
640 | "w leisure=nature_reserve poly_nature_reserve\n" |
543 | "w leisure=park poly_park\n" |
641 | "w leisure=park poly_park\n" |
544 | //"w leisure=pitch poly_sports_pitch\n" |
642 | "w leisure=pitch poly_sports_pitch\n" |
545 | "w leisure=playground poly_playground\n" |
643 | "w leisure=playground poly_playground\n" |
546 | //"w leisure=sports_centre poly_sport\n" |
644 | "w leisure=sports_centre poly_sport\n" |
547 | "w leisure=stadium poly_sports_stadium\n" |
645 | "w leisure=stadium poly_sports_stadium\n" |
548 | //"w leisure=track poly_sports_track\n" |
646 | "w leisure=track poly_sports_track\n" |
549 | "w leisure=water_park poly_water_park\n" |
647 | "w leisure=water_park poly_water_park\n" |
550 | "w military=airfield poly_airfield\n" |
648 | "w military=airfield poly_airfield\n" |
551 | //"w military=barracks poly_barracks\n" |
649 | "w military=barracks poly_barracks\n" |
552 | "w military=danger_area poly_danger_area\n" |
650 | "w military=danger_area poly_danger_area\n" |
553 | "w military=naval_base poly_naval_base\n" |
651 | "w military=naval_base poly_naval_base\n" |
554 | //"w military=range poly_range\n" |
652 | "w military=range poly_range\n" |
555 | "w natural=beach poly_beach\n" |
653 | "w natural=beach poly_beach\n" |
556 | // "w natural=coastline water_line\n" --> in coastline map |
654 | "w natural=coastline water_line\n" |
557 | "w natural=fell poly_fell\n" |
655 | "w natural=fell poly_fell\n" |
558 | "w natural=glacier poly_glacier\n" |
656 | "w natural=glacier poly_glacier\n" |
559 | "w natural=heath poly_heath\n" |
657 | "w natural=heath poly_heath\n" |
560 | "w natural=land poly_land\n" |
658 | "w natural=land poly_land\n" |
561 | "w natural=marsh poly_marsh\n" |
659 | "w natural=marsh poly_marsh\n" |
562 | "w natural=mud poly_mud\n" |
660 | "w natural=mud poly_mud\n" |
563 | "w natural=scree poly_scree\n" |
661 | "w natural=scree poly_scree\n" |
564 | "w natural=scrub poly_scrub\n" |
662 | "w natural=scrub poly_scrub\n" |
565 | "w natural=water poly_water\n" |
663 | "w natural=water poly_water\n" |
566 | "w natural=wood poly_wood\n" |
664 | "w natural=wood poly_wood\n" |
567 | //"w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n" |
665 | "w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n" |
568 | //"w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n" |
666 | "w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n" |
569 | //"w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n" |
667 | "w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n" |
570 | //"w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n" |
668 | "w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n" |
571 | //"w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n" |
669 | "w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n" |
572 | //"w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n" |
670 | "w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n" |
573 | //"w piste:type=nordic piste_nordic\n" |
671 | "w piste:type=nordic piste_nordic\n" |
574 | "w place=suburb poly_place1\n" |
672 | "w place=suburb poly_place1\n" |
575 | "w place=hamlet poly_place2\n" |
673 | "w place=hamlet poly_place2\n" |
576 | "w place=village poly_place3\n" |
674 | "w place=village poly_place3\n" |
577 | "w place=municipality poly_place4\n" |
675 | "w place=municipality poly_place4\n" |
578 | "w place=town poly_place5\n" |
676 | "w place=town poly_place5\n" |
579 | "w place=city poly_place6\n" |
677 | "w place=city poly_place6\n" |
580 | //"w power=line powerline\n" |
678 | "w power=line powerline\n" |
581 | //"w railway=abandoned rail_abandoned\n" |
679 | "w railway=abandoned rail_abandoned\n" |
582 | //"w railway=disused rail_disused\n" |
680 | "w railway=disused rail_disused\n" |
583 | "w railway=light_rail rail_light\n" |
681 | "w railway=light_rail rail_light\n" |
584 | "w railway=monorail rail_mono\n" |
682 | "w railway=monorail rail_mono\n" |
585 | "w railway=narrow_gauge rail_narrow_gauge\n" |
683 | "w railway=narrow_gauge rail_narrow_gauge\n" |
586 | //"w railway=preserved rail_preserved\n" |
684 | "w railway=preserved rail_preserved\n" |
587 | "w railway=rail rail\n" |
685 | "w railway=rail rail\n" |
588 | "w railway=subway rail_subway\n" |
686 | "w railway=subway rail_subway\n" |
589 | "w railway=tram rail_tram\n" |
687 | "w railway=tram rail_tram\n" |
590 | "w route=ferry ferry\n" |
688 | "w route=ferry ferry\n" |
591 | //"w route=ski piste_nordic\n" |
689 | "w route=ski piste_nordic\n" |
592 | //"w sport=* poly_sport\n" |
690 | "w sport=* poly_sport\n" |
593 | "w tourism=artwork poly_artwork\n" |
691 | "w tourism=artwork poly_artwork\n" |
594 | "w tourism=attraction poly_attraction\n" |
692 | "w tourism=attraction poly_attraction\n" |
595 | "w tourism=camp_site poly_camp_site\n" |
693 | "w tourism=camp_site poly_camp_site\n" |
596 | "w tourism=caravan_site poly_caravan_site\n" |
694 | "w tourism=caravan_site poly_caravan_site\n" |
597 | "w tourism=picnic_site poly_picnic_site\n" |
695 | "w tourism=picnic_site poly_picnic_site\n" |
… | |
… | |
605 | "w barrier=ditch ditch\n" |
703 | "w barrier=ditch ditch\n" |
606 | "w barrier=hedge hedge\n" |
704 | "w barrier=hedge hedge\n" |
607 | "w barrier=fence fence\n" |
705 | "w barrier=fence fence\n" |
608 | "w barrier=wall wall\n" |
706 | "w barrier=wall wall\n" |
609 | "w barrier=retaining_wall retaining_wall\n" |
707 | "w barrier=retaining_wall retaining_wall\n" |
610 | "w barrier=city_wall city_wall\n" }; |
708 | "w barrier=city_wall city_wall\n" |
|
|
709 | }; |
611 | |
710 | |
|
|
711 | |
|
|
712 | static void |
612 | static void build_attrmap_line(char *line) |
713 | build_attrmap_line(char *line) |
613 | { |
714 | { |
614 | char *t = NULL, *kvl = NULL, *i = NULL, *p, *kv; |
715 | char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv; |
615 | struct attr_mapping *attr_mapping = g_malloc0(sizeof(struct attr_mapping)); |
716 | struct attr_mapping ***attr_mapping_curr,*attr_mapping=g_malloc0(sizeof(struct attr_mapping)); |
616 | int idx, attr_mapping_count = 0; |
717 | int idx,attr_mapping_count=0,*attr_mapping_curr_count; |
617 | t = line; |
718 | t=line; |
618 | p = strchr(t, '\t'); |
719 | p=strchr(t,'\t'); |
619 | if (p) |
720 | if (p) { |
620 | { |
|
|
621 | while (*p == '\t') |
721 | while (*p == '\t') |
622 | *p++ = '\0'; |
722 | *p++='\0'; |
623 | kvl = p; |
723 | kvl=p; |
624 | p = strchr(kvl, '\t'); |
724 | p=strchr(kvl,'\t'); |
625 | } |
725 | } |
626 | if (p) |
726 | if (p) { |
627 | { |
|
|
628 | while (*p == '\t') |
727 | while (*p == '\t') |
629 | *p++ = '\0'; |
728 | *p++='\0'; |
630 | i = p; |
729 | i=p; |
631 | } |
730 | } |
632 | if (t[0] == 'w') |
731 | if (t[0] == 'w') { |
633 | { |
|
|
634 | if (!i) |
732 | if (! i) |
635 | i = "street_unkn"; |
733 | i="street_unkn"; |
636 | } |
734 | attr_mapping_curr=&attr_mapping_way; |
637 | else |
735 | attr_mapping_curr_count=&attr_mapping_way_count; |
638 | { |
736 | } else { |
639 | if (!i) |
737 | if (! i) |
640 | i = "point_unkn"; |
738 | i="point_unkn"; |
|
|
739 | attr_mapping_curr=&attr_mapping_node; |
|
|
740 | attr_mapping_curr_count=&attr_mapping_node_count; |
641 | } |
741 | } |
642 | |
|
|
643 | attr_mapping->type = item_from_name(i); |
742 | attr_mapping->type=item_from_name(i); |
644 | |
|
|
645 | if (!attr_mapping->type) |
|
|
646 | { |
|
|
647 | printf("no id found for '%s'\n", i); |
|
|
648 | } |
|
|
649 | |
|
|
650 | while ((kv = strtok(kvl, ","))) |
743 | while ((kv=strtok(kvl, ","))) { |
651 | { |
|
|
652 | kvl = NULL; |
744 | kvl=NULL; |
653 | if (!(idx = (int) (long) g_hash_table_lookup(attr_hash, kv))) |
745 | if (!(idx=(int)(long)g_hash_table_lookup(attr_hash, kv))) { |
654 | { |
|
|
655 | idx = attr_present_count++; |
746 | idx=attr_present_count++; |
656 | g_hash_table_insert(attr_hash, kv, (gpointer) (long) idx); |
747 | g_hash_table_insert(attr_hash, kv, (gpointer)(long)idx); |
657 | } |
748 | } |
658 | attr_mapping = g_realloc(attr_mapping, sizeof(struct attr_mapping) + (attr_mapping_count + 1) * sizeof(int)); |
749 | attr_mapping=g_realloc(attr_mapping, sizeof(struct attr_mapping)+(attr_mapping_count+1)*sizeof(int)); |
659 | attr_mapping->attr_present_idx[attr_mapping_count++] = idx; |
750 | attr_mapping->attr_present_idx[attr_mapping_count++]=idx; |
660 | attr_mapping->attr_present_idx_count = attr_mapping_count; |
751 | attr_mapping->attr_present_idx_count=attr_mapping_count; |
661 | } |
752 | } |
662 | if (t[0] == 'w') |
753 | *attr_mapping_curr=g_realloc(*attr_mapping_curr, sizeof(**attr_mapping_curr)*(*attr_mapping_curr_count+1)); |
663 | { |
|
|
664 | attr_mapping_way = g_realloc(attr_mapping_way, sizeof(*attr_mapping_way) * (attr_mapping_way_count + 1)); |
|
|
665 | attr_mapping_way[attr_mapping_way_count++] = attr_mapping; |
754 | (*attr_mapping_curr)[(*attr_mapping_curr_count)++]=attr_mapping; |
666 | } |
|
|
667 | if (t[0] == '?' && doway2poi) |
|
|
668 | { |
|
|
669 | attr_mapping_way2poi = g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi) * (attr_mapping_way2poi_count + 1)); |
|
|
670 | attr_mapping_way2poi[attr_mapping_way2poi_count++] = attr_mapping; |
|
|
671 | } |
|
|
672 | if (t[0] != 'w') |
|
|
673 | { |
|
|
674 | attr_mapping_node = g_realloc(attr_mapping_node, sizeof(*attr_mapping_node) * (attr_mapping_node_count + 1)); |
|
|
675 | attr_mapping_node[attr_mapping_node_count++] = attr_mapping; |
|
|
676 | } |
|
|
677 | |
|
|
678 | } |
755 | } |
679 | |
756 | |
|
|
757 | static void |
680 | static void build_attrmap(FILE* rule_file) |
758 | build_attrmap(FILE* rule_file) |
681 | { |
759 | { |
682 | attr_hash = g_hash_table_new(g_str_hash, g_str_equal); |
760 | attr_hash=g_hash_table_new(g_str_hash, g_str_equal); |
683 | attr_present_count = 1; |
761 | attr_present_count=1; |
684 | |
762 | |
685 | // build attribute map from rule file if given |
763 | // build attribute map from rule file if given |
686 | if (rule_file) |
764 | if( rule_file ) |
687 | { |
765 | { |
688 | char buffer[200], *p; |
766 | char buffer[200], *p; |
689 | while (fgets(buffer, 200, rule_file)) |
767 | while (fgets( buffer, 200, rule_file )) { |
690 | { |
768 | p=strchr(buffer,'\n'); |
691 | p = strchr(buffer, '\n'); |
769 | if(p) |
692 | if (p) |
770 | *p = 0; |
693 | *p = 0; |
|
|
694 | build_attrmap_line(g_strdup(buffer)); |
771 | build_attrmap_line( g_strdup( buffer ) ); |
695 | } |
772 | } |
696 | fclose(rule_file); |
773 | fclose( rule_file ); |
697 | } |
774 | } |
698 | // use hardcoded default attributes |
775 | // use hardcoded default attributes |
699 | else |
776 | else |
700 | { |
777 | { |
701 | char *p, *map; |
778 | char *p,*map=g_strdup(attrmap); |
702 | if (border_only_map == 1) |
779 | while (map) { |
703 | { |
780 | p=strchr(map,'\n'); |
704 | map = g_strdup(attrmap_bo); |
781 | if (p) |
705 | } |
782 | *p++='\0'; |
706 | else if (coastline_only_map == 1) |
783 | if (strlen(map)) |
707 | { |
784 | build_attrmap_line(map); |
708 | map = g_strdup(attrmap_cl); |
785 | map=p; |
709 | } |
786 | } |
710 | else |
787 | } |
711 | { |
|
|
712 | map = g_strdup(attrmap_normal); |
|
|
713 | } |
|
|
714 | |
788 | |
715 | while (map) |
|
|
716 | { |
|
|
717 | p = strchr(map, '\n'); |
|
|
718 | if (p) |
|
|
719 | *p++ = '\0'; |
|
|
720 | if (strlen(map)) |
|
|
721 | build_attrmap_line(map); |
|
|
722 | map = p; |
|
|
723 | } |
|
|
724 | } |
|
|
725 | |
|
|
726 | attr_present = g_malloc0(sizeof(*attr_present) * attr_present_count); |
789 | attr_present=g_malloc0(sizeof(*attr_present)*attr_present_count); |
727 | } |
790 | } |
728 | |
791 | |
|
|
792 | static void |
729 | static void build_countrytable(void) |
793 | build_countrytable(void) |
730 | { |
794 | { |
731 | int i; |
795 | int i; |
732 | char *names, *str, *tok; |
796 | char *names,*str,*tok; |
733 | country_table_hash = g_hash_table_new(g_str_hash, g_str_equal); |
797 | country_table_hash=g_hash_table_new(g_str_hash, g_str_equal); |
734 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
798 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { |
735 | { |
|
|
736 | names = g_strdup(country_table[i].names); |
799 | names=g_strdup(country_table[i].names); |
737 | str = names; |
800 | str=names; |
738 | while ((tok = strtok(str, ","))) |
801 | while ((tok=strtok(str, ","))) { |
739 | { |
|
|
740 | str = NULL; |
802 | str=NULL; |
741 | g_hash_table_insert(country_table_hash, tok, (gpointer) & country_table[i]); |
803 | g_hash_table_insert(country_table_hash, tok, (gpointer)&country_table[i]); |
742 | } |
|
|
743 | } |
804 | } |
|
|
805 | } |
744 | } |
806 | } |
745 | |
807 | static void |
746 | void osm_warning(char *type, long long id, int cont, char *fmt, ...) |
808 | osm_warning(char *type, long long id, int cont, char *fmt, ...) |
747 | { |
809 | { |
748 | char str[4096]; |
810 | char str[4096]; |
749 | va_list ap; |
811 | va_list ap; |
750 | va_start(ap, fmt); |
812 | va_start(ap, fmt); |
751 | vsnprintf(str, sizeof(str), fmt, ap); |
813 | vsnprintf(str, sizeof(str), fmt, ap); |
752 | va_end(ap); |
814 | va_end(ap); |
753 | if (verbose_mode) fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Warning:",type,id,str); |
815 | fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Warning:",type,id,str); |
754 | } |
816 | } |
755 | |
817 | |
756 | void osm_info(char *type, long long id, int cont, char *fmt, ...) |
818 | static void |
757 | { |
|
|
758 | char str[4096]; |
|
|
759 | va_list ap; |
|
|
760 | va_start(ap, fmt); |
|
|
761 | vsnprintf(str, sizeof(str), fmt, ap); |
|
|
762 | va_end(ap); |
|
|
763 | if (verbose_mode) fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Info:",type,id,str); |
|
|
764 | } |
|
|
765 | |
|
|
766 | static void attr_strings_clear(void) |
819 | attr_strings_clear(void) |
767 | { |
820 | { |
768 | alt_name_found = 0; |
|
|
769 | attr_strings_buffer_len = 0; |
821 | attr_strings_buffer_len=0; |
770 | memset(attr_strings, 0, sizeof(attr_strings)); |
822 | memset(attr_strings, 0, sizeof(attr_strings)); |
771 | } |
823 | } |
772 | |
824 | |
|
|
825 | static void |
773 | static void attr_strings_save(enum attr_strings id, char *str) |
826 | attr_strings_save(enum attr_strings id, char *str) |
774 | { |
827 | { |
775 | attr_strings[id] = attr_strings_buffer + attr_strings_buffer_len; |
828 | attr_strings[id]=attr_strings_buffer+attr_strings_buffer_len; |
776 | strcpy(attr_strings[id], str); |
829 | strcpy(attr_strings[id], str); |
777 | attr_strings_buffer_len += strlen(str) + 1; |
830 | attr_strings_buffer_len+=strlen(str)+1; |
778 | } |
831 | } |
779 | |
832 | |
|
|
833 | static long long |
780 | long long item_bin_get_nodeid(struct item_bin *ib) |
834 | item_bin_get_nodeid(struct item_bin *ib) |
781 | { |
835 | { |
782 | long long *ret = item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
836 | long long *ret=item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
783 | if (ret) |
837 | if (ret) |
784 | { |
|
|
785 | return *ret; |
838 | return *ret; |
786 | } |
|
|
787 | return 0; |
839 | return 0; |
788 | } |
840 | } |
789 | |
841 | |
|
|
842 | static long long |
790 | long long item_bin_get_wayid(struct item_bin *ib) |
843 | item_bin_get_wayid(struct item_bin *ib) |
791 | { |
844 | { |
792 | long long *ret = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
845 | long long *ret=item_bin_get_attr(ib, attr_osm_wayid, NULL); |
793 | if (ret) |
846 | if (ret) |
794 | { |
|
|
795 | return *ret; |
847 | return *ret; |
796 | } |
|
|
797 | return 0; |
848 | return 0; |
798 | } |
849 | } |
799 | |
850 | |
|
|
851 | static long long |
800 | long long item_bin_get_relationid(struct item_bin *ib) |
852 | item_bin_get_relationid(struct item_bin *ib) |
801 | { |
853 | { |
802 | long long *ret = item_bin_get_attr(ib, attr_osm_relationid, NULL); |
854 | long long *ret=item_bin_get_attr(ib, attr_osm_relationid, NULL); |
803 | if (ret) |
855 | if (ret) |
804 | { |
|
|
805 | return *ret; |
856 | return *ret; |
806 | } |
|
|
807 | return 0; |
857 | return 0; |
808 | } |
858 | } |
809 | |
859 | |
|
|
860 | long long |
810 | long long item_bin_get_id(struct item_bin *ib) |
861 | item_bin_get_id(struct item_bin *ib) |
811 | { |
862 | { |
812 | long long ret; |
863 | long long ret; |
813 | if (ib->type < 0x80000000) |
864 | if (ib->type < 0x80000000) |
814 | { |
|
|
815 | return item_bin_get_nodeid(ib); |
865 | return item_bin_get_nodeid(ib); |
816 | } |
|
|
817 | ret = item_bin_get_wayid(ib); |
866 | ret=item_bin_get_wayid(ib); |
818 | if (!ret) |
867 | if (!ret) |
819 | { |
|
|
820 | ret = item_bin_get_relationid(ib); |
868 | ret=item_bin_get_relationid(ib); |
821 | } |
|
|
822 | return ret; |
869 | return ret; |
823 | } |
870 | } |
824 | |
871 | |
825 | static int node_is_tagged; |
872 | static int node_is_tagged; |
826 | static void relation_add_tag(char *k, char *v); |
873 | static void relation_add_tag(char *k, char *v); |
827 | |
874 | |
|
|
875 | static int |
828 | static int access_value(char *v) |
876 | access_value(char *v) |
829 | { |
877 | { |
830 | if (!strcmp(v, "1")) |
878 | if (!strcmp(v,"1")) |
831 | return 1; |
879 | return 1; |
832 | if (!strcmp(v, "yes")) |
880 | if (!strcmp(v,"yes")) |
833 | return 1; |
881 | return 1; |
834 | if (!strcmp(v, "designated")) |
882 | if (!strcmp(v,"designated")) |
835 | return 1; |
883 | return 1; |
836 | if (!strcmp(v, "official")) |
884 | if (!strcmp(v,"official")) |
837 | return 1; |
885 | return 1; |
838 | if (!strcmp(v, "permissive")) |
886 | if (!strcmp(v,"permissive")) |
839 | return 1; |
887 | return 1; |
840 | if (!strcmp(v, "0")) |
888 | if (!strcmp(v,"0")) |
841 | return 2; |
889 | return 2; |
842 | if (!strcmp(v, "no")) |
890 | if (!strcmp(v,"no")) |
843 | return 2; |
891 | return 2; |
844 | if (!strcmp(v, "agricultural")) |
892 | if (!strcmp(v,"agricultural")) |
845 | return 2; |
893 | return 2; |
846 | if (!strcmp(v, "forestry")) |
894 | if (!strcmp(v,"forestry")) |
847 | return 2; |
895 | return 2; |
848 | if (!strcmp(v, "private")) |
896 | if (!strcmp(v,"private")) |
849 | return 2; |
897 | return 2; |
850 | if (!strcmp(v, "delivery")) |
898 | if (!strcmp(v,"delivery")) |
851 | return 2; |
899 | return 2; |
852 | if (!strcmp(v, "destination")) |
900 | if (!strcmp(v,"destination")) |
853 | return 2; |
901 | return 2; |
854 | return 3; |
902 | return 3; |
855 | } |
903 | } |
856 | |
904 | |
|
|
905 | void |
857 | void osm_add_tag(char *k, char *v) |
906 | osm_add_tag(char *k, char *v) |
858 | { |
907 | { |
859 | int idx, level = 2; |
908 | int idx,level=2; |
860 | char buffer[BUFFER_SIZE * 2 + 2]; |
909 | char buffer[BUFFER_SIZE*2+2]; |
861 | |
|
|
862 | if (in_relation) |
910 | if (in_relation) { |
863 | { |
|
|
864 | relation_add_tag(k, v); |
911 | relation_add_tag(k,v); |
865 | return; |
912 | return; |
866 | } |
913 | } |
867 | |
|
|
868 | if (!strcmp(k, "ele")) |
914 | if (! strcmp(k,"ele")) |
869 | level = 9; |
915 | level=9; |
870 | if (!strcmp(k, "time")) |
916 | if (! strcmp(k,"time")) |
871 | level = 9; |
917 | level=9; |
872 | if (!strcmp(k, "created_by")) |
918 | if (! strcmp(k,"created_by")) |
873 | level = 9; |
919 | level=9; |
874 | if (!strncmp(k, "tiger:", 6) || !strcmp(k, "AND_nodes")) |
920 | if (! strncmp(k,"tiger:",6) || !strcmp(k,"AND_nodes")) |
875 | level = 9; |
921 | level=9; |
876 | if (!strcmp(k, "converted_by") || !strcmp(k, "source")) |
922 | if (! strcmp(k,"converted_by") || ! strcmp(k,"source")) |
877 | level = 8; |
923 | level=8; |
878 | if (!strncmp(k, "osmarender:", 11) || !strncmp(k, "svg:", 4)) |
924 | if (! strncmp(k,"osmarender:",11) || !strncmp(k,"svg:",4)) |
879 | level = 8; |
925 | level=8; |
880 | if (!strcmp(k, "layer")) |
926 | if (! strcmp(k,"layer")) |
881 | level = 7; |
927 | level=7; |
882 | if (!strcasecmp(v, "true") || !strcasecmp(v, "yes")) |
928 | if (! strcasecmp(v,"true") || ! strcasecmp(v,"yes")) |
883 | v = "1"; |
929 | v="1"; |
884 | if (!strcasecmp(v, "false") || !strcasecmp(v, "no")) |
930 | if (! strcasecmp(v,"false") || ! strcasecmp(v,"no")) |
885 | v = "0"; |
931 | v="0"; |
886 | if (!strcmp(k, "oneway")) |
932 | if (! strcmp(k,"oneway")) { |
887 | { |
|
|
888 | if (!strcmp(v, "1")) |
933 | if (!strcmp(v,"1")) { |
889 | { |
|
|
890 | flags[0] |= AF_ONEWAY | AF_ROUNDABOUT_VALID; |
934 | flags[0] |= AF_ONEWAY | AF_ROUNDABOUT_VALID; |
891 | } |
935 | } |
892 | if (!strcmp(v, "-1")) |
936 | if (! strcmp(v,"-1")) { |
893 | { |
|
|
894 | flags[0] |= AF_ONEWAYREV | AF_ROUNDABOUT_VALID; |
937 | flags[0] |= AF_ONEWAYREV | AF_ROUNDABOUT_VALID; |
895 | } |
938 | } |
896 | if (!in_way) |
939 | if (!in_way) |
897 | level = 6; |
940 | level=6; |
898 | else |
941 | else |
899 | level = 5; |
942 | level=5; |
900 | } |
943 | } |
901 | if (!strcmp(k, "junction")) |
944 | if (! strcmp(k,"junction")) { |
902 | { |
|
|
903 | if (!strcmp(v, "roundabout")) |
945 | if (! strcmp(v,"roundabout")) |
904 | flags[0] |= AF_ONEWAY | AF_ROUNDABOUT | AF_ROUNDABOUT_VALID; |
946 | flags[0] |= AF_ONEWAY | AF_ROUNDABOUT | AF_ROUNDABOUT_VALID; |
905 | } |
947 | } |
906 | if (!strcmp(k, "maxspeed")) |
948 | if (! strcmp(k,"maxspeed")) { |
907 | { |
|
|
908 | if (strstr(v, "mph")) |
949 | if (strstr(v, "mph")) { |
909 | { |
|
|
910 | maxspeed_attr_value = (int) floor(atof(v) * 1.609344); |
950 | maxspeed_attr_value = (int)floor(atof(v) * 1.609344); |
911 | } |
|
|
912 | else |
951 | } else { |
913 | { |
|
|
914 | maxspeed_attr_value = atoi(v); |
952 | maxspeed_attr_value = atoi(v); |
915 | } |
953 | } |
916 | if (maxspeed_attr_value) |
954 | if (maxspeed_attr_value) |
917 | flags[0] |= AF_SPEED_LIMIT; |
955 | flags[0] |= AF_SPEED_LIMIT; |
918 | level = 5; |
956 | level=5; |
919 | } |
|
|
920 | if (!strcmp(k, "toll")) |
|
|
921 | { |
|
|
922 | if (!strcmp(v, "1")) |
|
|
923 | { |
|
|
924 | flags[0] |= AF_TOLL; |
|
|
925 | } |
957 | } |
926 | } |
|
|
927 | if (!strcmp(k, "access")) |
958 | if (! strcmp(k,"access")) { |
928 | { |
959 | flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_HORSE|AF_BIKE|AF_PEDESTRIAN; |
929 | flags[access_value(v)] |= AF_DANGEROUS_GOODS | AF_EMERGENCY_VEHICLES | AF_TRANSPORT_TRUCK | AF_DELIVERY_TRUCK | AF_PUBLIC_BUS | AF_TAXI | AF_HIGH_OCCUPANCY_CAR | AF_CAR | AF_MOTORCYCLE | AF_MOPED | AF_HORSE | AF_BIKE | AF_PEDESTRIAN; |
|
|
930 | level = 5; |
960 | level=5; |
931 | } |
961 | } |
932 | if (!strcmp(k, "vehicle")) |
962 | if (! strcmp(k,"vehicle")) { |
933 | { |
|
|
934 | flags[access_value(v)] |= AF_DANGEROUS_GOODS | AF_EMERGENCY_VEHICLES | AF_TRANSPORT_TRUCK | AF_DELIVERY_TRUCK | AF_PUBLIC_BUS | AF_TAXI | AF_HIGH_OCCUPANCY_CAR | AF_CAR | AF_MOTORCYCLE | AF_MOPED | AF_BIKE; |
963 | flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_BIKE; |
935 | level = 5; |
964 | level=5; |
936 | } |
965 | } |
937 | if (!strcmp(k, "motorvehicle")) |
966 | if (! strcmp(k,"motorvehicle")) { |
938 | { |
|
|
939 | flags[access_value(v)] |= AF_DANGEROUS_GOODS | AF_EMERGENCY_VEHICLES | AF_TRANSPORT_TRUCK | AF_DELIVERY_TRUCK | AF_PUBLIC_BUS | AF_TAXI | AF_HIGH_OCCUPANCY_CAR | AF_CAR | AF_MOTORCYCLE | AF_MOPED; |
967 | flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED; |
940 | level = 5; |
968 | level=5; |
941 | } |
969 | } |
942 | if (!strcmp(k, "bicycle")) |
970 | if (! strcmp(k,"bicycle")) { |
943 | { |
|
|
944 | flags[access_value(v)] |= AF_BIKE; |
971 | flags[access_value(v)] |= AF_BIKE; |
945 | level = 5; |
972 | level=5; |
946 | } |
973 | } |
947 | if (!strcmp(k, "foot")) |
974 | if (! strcmp(k,"foot")) { |
948 | { |
|
|
949 | flags[access_value(v)] |= AF_PEDESTRIAN; |
975 | flags[access_value(v)] |= AF_PEDESTRIAN; |
950 | level = 5; |
976 | level=5; |
951 | } |
977 | } |
952 | if (!strcmp(k, "horse")) |
978 | if (! strcmp(k,"horse")) { |
953 | { |
|
|
954 | flags[access_value(v)] |= AF_HORSE; |
979 | flags[access_value(v)] |= AF_HORSE; |
955 | level = 5; |
980 | level=5; |
956 | } |
981 | } |
957 | if (!strcmp(k, "moped")) |
982 | if (! strcmp(k,"moped")) { |
958 | { |
|
|
959 | flags[access_value(v)] |= AF_MOPED; |
983 | flags[access_value(v)] |= AF_MOPED; |
960 | level = 5; |
984 | level=5; |
961 | } |
985 | } |
962 | if (!strcmp(k, "motorcycle")) |
986 | if (! strcmp(k,"motorcycle")) { |
963 | { |
|
|
964 | flags[access_value(v)] |= AF_MOTORCYCLE; |
987 | flags[access_value(v)] |= AF_MOTORCYCLE; |
965 | level = 5; |
988 | level=5; |
966 | } |
989 | } |
967 | if (!strcmp(k, "motorcar")) |
990 | if (! strcmp(k,"motorcar")) { |
968 | { |
|
|
969 | flags[access_value(v)] |= AF_CAR; |
991 | flags[access_value(v)] |= AF_CAR; |
970 | level = 5; |
992 | level=5; |
971 | } |
993 | } |
972 | if (!strcmp(k, "hov")) |
994 | if (! strcmp(k,"hov")) { |
973 | { |
|
|
974 | flags[access_value(v)] |= AF_HIGH_OCCUPANCY_CAR; |
995 | flags[access_value(v)] |= AF_HIGH_OCCUPANCY_CAR; |
975 | level = 5; |
996 | level=5; |
976 | } |
997 | } |
977 | if (!strcmp(k, "bus")) |
998 | if (! strcmp(k,"bus")) { |
978 | { |
|
|
979 | flags[access_value(v)] |= AF_PUBLIC_BUS; |
999 | flags[access_value(v)] |= AF_PUBLIC_BUS; |
980 | level = 5; |
1000 | level=5; |
981 | } |
1001 | } |
982 | if (!strcmp(k, "taxi")) |
1002 | if (! strcmp(k,"taxi")) { |
983 | { |
|
|
984 | flags[access_value(v)] |= AF_TAXI; |
1003 | flags[access_value(v)] |= AF_TAXI; |
985 | level = 5; |
1004 | level=5; |
986 | } |
1005 | } |
987 | if (!strcmp(k, "goods")) |
1006 | if (! strcmp(k,"goods")) { |
988 | { |
|
|
989 | flags[access_value(v)] |= AF_DELIVERY_TRUCK; |
1007 | flags[access_value(v)] |= AF_DELIVERY_TRUCK; |
990 | level = 5; |
1008 | level=5; |
991 | } |
1009 | } |
992 | if (!strcmp(k, "hgv")) |
1010 | if (! strcmp(k,"hgv")) { |
993 | { |
|
|
994 | flags[access_value(v)] |= AF_TRANSPORT_TRUCK; |
1011 | flags[access_value(v)] |= AF_TRANSPORT_TRUCK; |
995 | level = 5; |
1012 | level=5; |
996 | } |
1013 | } |
997 | if (!strcmp(k, "emergency")) |
1014 | if (! strcmp(k,"emergency")) { |
998 | { |
|
|
999 | flags[access_value(v)] |= AF_EMERGENCY_VEHICLES; |
1015 | flags[access_value(v)] |= AF_EMERGENCY_VEHICLES; |
1000 | level = 5; |
1016 | level=5; |
1001 | } |
1017 | } |
1002 | if (!strcmp(k, "hazmat")) |
1018 | if (! strcmp(k,"hazmat")) { |
1003 | { |
|
|
1004 | flags[access_value(v)] |= AF_DANGEROUS_GOODS; |
1019 | flags[access_value(v)] |= AF_DANGEROUS_GOODS; |
1005 | level = 5; |
1020 | level=5; |
1006 | } |
1021 | } |
1007 | if (!strcmp(k, "tunnel") && !strcmp(v, "1")) |
|
|
1008 | { |
|
|
1009 | flags[0] |= AF_UNDERGROUND; |
|
|
1010 | } |
|
|
1011 | if (!strcmp(k, "bridge") && !strcmp(v, "1")) |
|
|
1012 | { |
|
|
1013 | flags[0] |= AF_BRIDGE; |
|
|
1014 | } |
|
|
1015 | if (!strcmp(k, "note")) |
1022 | if (! strcmp(k,"note")) |
1016 | level = 5; |
1023 | level=5; |
1017 | if (!strcmp(k, "name")) |
1024 | if (! strcmp(k,"name")) { |
1018 | { |
|
|
1019 | attr_strings_save(attr_string_label, v); |
1025 | attr_strings_save(attr_string_label, v); |
1020 | level = 5; |
1026 | level=5; |
1021 | } |
1027 | } |
1022 | |
|
|
1023 | if ((!strcmp(k, "name:en")) && (alt_name_found == 0)) |
|
|
1024 | { |
|
|
1025 | attr_strings_save(attr_string_label_alt, v); |
|
|
1026 | alt_name_found = 1; |
|
|
1027 | level = 5; |
|
|
1028 | } |
|
|
1029 | if ((!strcmp(k, "alt_name:en")) && (alt_name_found < 2)) |
|
|
1030 | { |
|
|
1031 | // only use "alt_name:en" if we dont have "alt_name" |
|
|
1032 | attr_strings_save(attr_string_label_alt, v); |
|
|
1033 | alt_name_found = 2; |
|
|
1034 | level = 5; |
|
|
1035 | } |
|
|
1036 | if (!strcmp(k, "alt_name")) |
|
|
1037 | { |
|
|
1038 | attr_strings_save(attr_string_label_alt, v); |
|
|
1039 | alt_name_found = 3; |
|
|
1040 | level = 5; |
|
|
1041 | } |
|
|
1042 | if (!strcmp(k, "addr:email")) |
1028 | if (! strcmp(k,"addr:email")) { |
1043 | { |
|
|
1044 | attr_strings_save(attr_string_email, v); |
1029 | attr_strings_save(attr_string_email, v); |
1045 | level = 5; |
1030 | level=5; |
1046 | } |
1031 | } |
1047 | if (!strcmp(k, "addr:housenumber")) |
1032 | if (! strcmp(k,"addr:housenumber")) { |
1048 | { |
|
|
1049 | attr_strings_save(attr_string_house_number, v); |
1033 | attr_strings_save(attr_string_house_number, v); |
1050 | level = 5; |
1034 | level=5; |
1051 | } |
1035 | } |
1052 | if (!strcmp(k, "addr:street")) |
1036 | if (! strcmp(k,"addr:street")) { |
1053 | { |
|
|
1054 | attr_strings_save(attr_string_street_name, v); |
1037 | attr_strings_save(attr_string_street_name, v); |
1055 | level = 5; |
1038 | level=5; |
1056 | } |
1039 | } |
1057 | if (!strcmp(k, "phone")) |
1040 | if (! strcmp(k,"phone")) { |
1058 | { |
|
|
1059 | attr_strings_save(attr_string_phone, v); |
1041 | attr_strings_save(attr_string_phone, v); |
1060 | level = 5; |
1042 | level=5; |
1061 | } |
1043 | } |
1062 | if (!strcmp(k, "fax")) |
1044 | if (! strcmp(k,"fax")) { |
1063 | { |
|
|
1064 | attr_strings_save(attr_string_fax, v); |
1045 | attr_strings_save(attr_string_fax, v); |
1065 | level = 5; |
1046 | level=5; |
1066 | } |
1047 | } |
1067 | if (!strcmp(k, "postal_code")) |
1048 | if (! strcmp(k,"postal_code")) { |
1068 | { |
|
|
1069 | attr_strings_save(attr_string_postal, v); |
1049 | attr_strings_save(attr_string_postal, v); |
1070 | level = 5; |
1050 | level=5; |
1071 | } |
1051 | } |
1072 | if (!strcmp(k, "openGeoDB:postal_codes") && !attr_strings[attr_string_postal]) |
1052 | if (! strcmp(k,"openGeoDB:postal_codes") && !attr_strings[attr_string_postal]) { |
1073 | { |
|
|
1074 | attr_strings_save(attr_string_postal, v); |
1053 | attr_strings_save(attr_string_postal, v); |
1075 | level = 5; |
1054 | level=5; |
1076 | } |
1055 | } |
1077 | if (!strcmp(k, "population")) |
1056 | if (! strcmp(k,"population")) { |
1078 | { |
|
|
1079 | attr_strings_save(attr_string_population, v); |
1057 | attr_strings_save(attr_string_population, v); |
1080 | level = 5; |
1058 | level=5; |
1081 | } |
1059 | } |
1082 | if (!strcmp(k, "openGeoDB:population") && !attr_strings[attr_string_population]) |
1060 | if (! strcmp(k,"openGeoDB:population") && !attr_strings[attr_string_population]) { |
1083 | { |
|
|
1084 | attr_strings_save(attr_string_population, v); |
1061 | attr_strings_save(attr_string_population, v); |
1085 | level = 5; |
1062 | level=5; |
1086 | } |
1063 | } |
1087 | if (!strcmp(k, "ref")) |
1064 | if (! strcmp(k,"ref")) { |
1088 | { |
|
|
1089 | if (in_way) |
1065 | if (in_way) |
1090 | attr_strings_save(attr_string_street_name_systematic, v); |
1066 | attr_strings_save(attr_string_street_name_systematic, v); |
1091 | level = 5; |
1067 | level=5; |
1092 | } |
1068 | } |
1093 | if (!strcmp(k, "openGeoDB:is_in")) |
1069 | if (! strcmp(k,"openGeoDB:is_in")) { |
1094 | { |
1070 | if (!is_in_buffer[0]) |
|
|
1071 | strcpy(is_in_buffer, v); |
|
|
1072 | level=5; |
|
|
1073 | } |
|
|
1074 | if (! strcmp(k,"is_in")) { |
1095 | if (!is_in_buffer[0]) |
1075 | if (!is_in_buffer[0]) |
1096 | strcpy(is_in_buffer, v); |
1076 | strcpy(is_in_buffer, v); |
1097 | level = 5; |
1077 | level=5; |
1098 | } |
1078 | } |
1099 | if (!strcmp(k, "is_in")) |
|
|
1100 | { |
|
|
1101 | if (!is_in_buffer[0]) |
|
|
1102 | strcpy(is_in_buffer, v); |
|
|
1103 | level = 5; |
|
|
1104 | } |
|
|
1105 | if (!strcmp(k, "is_in:country")) |
1079 | if (! strcmp(k,"is_in:country")) { |
1106 | { |
|
|
1107 | /** |
1080 | /** |
1108 | * Sometimes there is no is_in tag, only is_in:country. |
1081 | * Sometimes there is no is_in tag, only is_in:country. |
1109 | * I put this here so it can be overwritten by the previous if clause if there IS an is_in tag. |
1082 | * I put this here so it can be overwritten by the previous if clause if there IS an is_in tag. |
1110 | */ |
1083 | */ |
1111 | strcpy(is_in_buffer, v); |
1084 | strcpy(is_in_buffer, v); |
1112 | level = 5; |
1085 | level=5; |
1113 | } |
1086 | } |
1114 | if (!strcmp(k, "place_county")) |
1087 | if (! strcmp(k,"place_county")) { |
1115 | { |
|
|
1116 | /** |
1088 | /** |
1117 | * Ireland uses the place_county OSM tag to describe what county a town is in. |
1089 | * Ireland uses the place_county OSM tag to describe what county a town is in. |
1118 | * This would be equivalent to is_in: Town; Locality; Country |
1090 | * This would be equivalent to is_in: Town; Locality; Country |
1119 | * A real world example would be Node: Moycullen (52234625) |
1091 | * A real world example would be Node: Moycullen (52234625) |
1120 | * The tag is processed as Moycullen; Galway; Ireland |
1092 | * The tag is processed as Moycullen; Galway; Ireland |
1121 | * where Galway is the county |
1093 | * where Galway is the county |
1122 | */ |
1094 | */ |
1123 | strcpy(is_in_buffer, "Ireland"); |
1095 | strcpy(is_in_buffer, "Ireland"); |
1124 | attr_strings_save(attr_string_county_name, v); |
1096 | attr_strings_save(attr_string_county_name, v); |
1125 | level = 5; |
1097 | level=5; |
1126 | } |
1098 | } |
1127 | if (!strcmp(k, "gnis:ST_alpha")) |
1099 | if (! strcmp(k,"gnis:ST_alpha")) { |
1128 | { |
|
|
1129 | /* assume a gnis tag means it is part of the USA: |
1100 | /* assume a gnis tag means it is part of the USA: |
1130 | http://en.wikipedia.org/wiki/Geographic_Names_Information_System |
1101 | http://en.wikipedia.org/wiki/Geographic_Names_Information_System |
1131 | many US towns do not have is_in tags |
1102 | many US towns do not have is_in tags |
1132 | */ |
1103 | */ |
1133 | strcpy(is_in_buffer, "USA"); |
1104 | strcpy(is_in_buffer, "USA"); |
1134 | level = 5; |
1105 | level=5; |
1135 | } |
1106 | } |
1136 | if (!strcmp(k, "lanes")) |
1107 | if (! strcmp(k,"lanes")) { |
1137 | { |
|
|
1138 | level = 5; |
1108 | level=5; |
1139 | } |
1109 | } |
1140 | if (attr_debug_level >= level) |
1110 | if (attr_debug_level >= level) { |
1141 | { |
|
|
1142 | int bytes_left = sizeof(debug_attr_buffer) - strlen(debug_attr_buffer) - 1; |
1111 | int bytes_left = sizeof( debug_attr_buffer ) - strlen(debug_attr_buffer) - 1; |
1143 | if (bytes_left > 0) |
1112 | if ( bytes_left > 0 ) |
1144 | { |
1113 | { |
1145 | snprintf(debug_attr_buffer + strlen(debug_attr_buffer), bytes_left, " %s=%s", k, v); |
1114 | snprintf(debug_attr_buffer+strlen(debug_attr_buffer), bytes_left, " %s=%s", k, v); |
1146 | debug_attr_buffer[sizeof(debug_attr_buffer) - 1] = '\0'; |
1115 | debug_attr_buffer[ sizeof( debug_attr_buffer ) - 1 ] = '\0'; |
1147 | node_is_tagged = 1; |
1116 | node_is_tagged=1; |
1148 | } |
|
|
1149 | } |
1117 | } |
1150 | |
1118 | } |
1151 | if (level < 6) |
1119 | if (level < 6) |
1152 | { |
|
|
1153 | node_is_tagged = 1; |
1120 | node_is_tagged=1; |
1154 | } |
|
|
1155 | |
1121 | |
1156 | strcpy(buffer, "*=*"); |
1122 | strcpy(buffer,"*=*"); |
1157 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1123 | if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) |
1158 | attr_present[idx] = 1; |
1124 | attr_present[idx]=1; |
1159 | |
1125 | |
1160 | sprintf(buffer, "%s=*", k); |
1126 | sprintf(buffer,"%s=*", k); |
1161 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1127 | if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) |
1162 | attr_present[idx] = 2; |
1128 | attr_present[idx]=2; |
1163 | |
1129 | |
1164 | sprintf(buffer, "*=%s", v); |
1130 | sprintf(buffer,"*=%s", v); |
1165 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1131 | if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) |
1166 | attr_present[idx] = 2; |
1132 | attr_present[idx]=2; |
1167 | |
1133 | |
1168 | sprintf(buffer, "%s=%s", k, v); |
1134 | sprintf(buffer,"%s=%s", k, v); |
1169 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1135 | if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) |
1170 | attr_present[idx] = 4; |
1136 | attr_present[idx]=4; |
1171 | } |
1137 | } |
1172 | |
1138 | |
1173 | int coord_count; |
1139 | int coord_count; |
1174 | |
1140 | |
|
|
1141 | struct node_item { |
|
|
1142 | int id; |
|
|
1143 | char ref_node; |
|
|
1144 | char ref_way; |
|
|
1145 | char ref_ref; |
|
|
1146 | char dummy; |
|
|
1147 | struct coord c; |
|
|
1148 | }; |
|
|
1149 | |
|
|
1150 | static void |
1175 | static void extend_buffer(struct buffer *b) |
1151 | extend_buffer(struct buffer *b) |
1176 | { |
1152 | { |
1177 | b->malloced += b->malloced_step; |
1153 | b->malloced+=b->malloced_step; |
1178 | b->base = realloc(b->base, (size_t) b->malloced); |
1154 | b->base=realloc(b->base, b->malloced); |
1179 | if (b->base == NULL) |
1155 | if (b->base == NULL) { |
1180 | { |
|
|
1181 | fprintf(stderr, "realloc of "LONGLONG_FMT" bytes failed\n", (size_t) b->malloced); |
1156 | fprintf(stderr,"realloc of %d bytes failed\n",(int)b->malloced); |
1182 | exit(1); |
1157 | exit(1); |
1183 | } |
1158 | } |
1184 | if (verbose_mode) fprintf(stderr, "extend_buffer: "LONGLONG_FMT" bytes\n", (size_t) b->malloced); |
1159 | |
1185 | } |
1160 | } |
1186 | |
1161 | |
1187 | int nodeid_last; |
1162 | int nodeid_last; |
1188 | GHashTable *way_hash, *waytag_hash; |
1163 | GHashTable *node_hash,*way_hash; |
1189 | cfuhash_table_t *way_hash_cfu = NULL; |
|
|
1190 | |
1164 | |
1191 | static void node_buffer_to_hash(int local_thread_num) |
1165 | static void |
|
|
1166 | node_buffer_to_hash(void) |
1192 | { |
1167 | { |
1193 | if (verbose_mode) |
|
|
1194 | fprintf(stderr, "node_buffer_to_hash t:%d nb->size:%lu\n", local_thread_num, node_buffer[local_thread_num].size); |
|
|
1195 | if (verbose_mode) |
|
|
1196 | fprintf(stderr, "node_buffer_to_hash t:%d nb->base:%lu\n", local_thread_num, node_buffer[local_thread_num].base); |
|
|
1197 | if (verbose_mode) |
|
|
1198 | fprintf(stderr, "node_buffer_to_hash t:%d nh:%p\n", local_thread_num, node_hash[local_thread_num]); |
|
|
1199 | |
|
|
1200 | int i = 0; |
|
|
1201 | int count2 = node_buffer[local_thread_num].size / sizeof(struct node_item); |
1168 | int i,count=node_buffer.size/sizeof(struct node_item); |
1202 | struct node_item *ni = (struct node_item *) node_buffer[local_thread_num].base; |
1169 | struct node_item *ni=(struct node_item *)node_buffer.base; |
1203 | |
|
|
1204 | if (verbose_mode) |
|
|
1205 | fprintf(stderr, "node_buffer_to_hash %d %d %d\n", local_thread_num, i, count2); |
|
|
1206 | |
|
|
1207 | for (i = 0; i < count2; i++) |
|
|
1208 | { |
|
|
1209 | /* |
|
|
1210 | if (i % 5000) |
|
|
1211 | { |
|
|
1212 | fprintf(stderr, "thread #%d fill #%d\n", local_thread_num, i); |
|
|
1213 | } |
|
|
1214 | */ |
|
|
1215 | // g_hash_table_insert(node_hash[local_thread_num], (gpointer) (long) (ni[i].id), (gpointer) (long) i); |
|
|
1216 | //cfuhash_put(node_hash_cfu[local_thread_num], &(long long)ni[i].id, xxx); |
|
|
1217 | |
|
|
1218 | //fprintf(stderr, "node id:%lld i:%d\n", (long long)ni[i].id, i); |
|
|
1219 | cfuhash_put_data(node_hash_cfu[local_thread_num], (long long)ni[i].id, sizeof(long long), i, 1, NULL); |
|
|
1220 | } |
|
|
1221 | |
|
|
1222 | if (verbose_mode) |
|
|
1223 | { |
|
|
1224 | fprintf(stderr, "node_buffer_to_hash ready\n"); |
|
|
1225 | } |
|
|
1226 | } |
|
|
1227 | |
|
|
1228 | static void waytag_buffer_to_hash(void) |
|
|
1229 | { |
|
|
1230 | int i, count = waytag_buffer.size / sizeof(struct way_tag); |
|
|
1231 | struct way_tag *wt = (struct way_tag *) waytag_buffer.base; |
|
|
1232 | for (i = 0; i < count; i++) |
1170 | for (i = 0 ; i < count ; i++) |
1233 | { |
|
|
1234 | // fprintf(stderr, "waytag_hash insert:%lu %lu\n", (long) (wt[i].way_id), (long) i); |
|
|
1235 | g_hash_table_insert(waytag_hash, (gpointer) (long) (wt[i].way_id), (gpointer) (long) i); |
1171 | g_hash_table_insert(node_hash, (gpointer)(long)(ni[i].id), (gpointer)(long)i); |
1236 | } |
|
|
1237 | } |
1172 | } |
1238 | |
1173 | |
1239 | static struct node_item *ni; |
1174 | static struct node_item *ni; |
1240 | |
1175 | |
1241 | void init_node_hash(int threads, int clear) |
1176 | void |
|
|
1177 | flush_nodes(int final) |
1242 | { |
1178 | { |
1243 | int i; |
|
|
1244 | for (i = 0; i < threads; i++) |
|
|
1245 | { |
|
|
1246 | //if (clear) |
|
|
1247 | //{ |
|
|
1248 | //*node_hash[i] = NULL; |
|
|
1249 | //} |
|
|
1250 | //else |
|
|
1251 | //{ |
|
|
1252 | //*node_hash[i] = g_hash_table_new(NULL, NULL); |
|
|
1253 | //} |
|
|
1254 | node_hash_cfu[i] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
|
|
1255 | cfuhash_set_flag(node_hash_cfu[i], CFUHASH_FROZEN); |
|
|
1256 | } |
|
|
1257 | } |
|
|
1258 | |
|
|
1259 | void fill_hash_node(int local_thread_num) |
|
|
1260 | { |
|
|
1261 | //fprintf(stderr, "001t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1262 | |
|
|
1263 | if (verbose_mode) |
|
|
1264 | fprintf(stderr, "fill_hash_node - START\n"); |
|
|
1265 | //if (node_hash[local_thread_num]) |
|
|
1266 | if (node_hash_cfu[local_thread_num]) |
|
|
1267 | { |
|
|
1268 | //g_hash_table_destroy(node_hash[local_thread_num]); |
|
|
1269 | //node_hash[local_thread_num] = NULL; |
|
|
1270 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
|
|
1271 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
|
|
1272 | node_hash_cfu[local_thread_num] = NULL; |
|
|
1273 | } |
|
|
1274 | |
|
|
1275 | // node_hash[local_thread_num] = g_hash_table_new(NULL, NULL); |
|
|
1276 | node_hash_cfu[local_thread_num] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
|
|
1277 | cfuhash_set_flag(node_hash_cfu[local_thread_num], CFUHASH_FROZEN); |
|
|
1278 | |
|
|
1279 | //fprintf(stderr, "002t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1280 | node_buffer_to_hash(local_thread_num); |
|
|
1281 | //fprintf(stderr, "003t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1282 | if (verbose_mode) |
|
|
1283 | fprintf(stderr, "fill_hash_node - END\n"); |
|
|
1284 | } |
|
|
1285 | |
|
|
1286 | void flush_nodes(int final, int local_thread_num) |
|
|
1287 | { |
|
|
1288 | save_buffer("coords.tmp", &node_buffer[local_thread_num], slices * slice_size); |
|
|
1289 | //fprintf(stderr, "004t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1290 | |
|
|
1291 | if (verbose_mode) |
|
|
1292 | fprintf(stderr, "flush_nodes %d\n", final); |
1179 | fprintf(stderr,"flush_nodes %d\n",final); |
|
|
1180 | save_buffer("coords.tmp",&node_buffer,slices*slice_size); |
1293 | if (!final) |
1181 | if (!final) { |
1294 | { |
1182 | node_buffer.size=0; |
1295 | // ------ this part optional ------ |
|
|
1296 | // //free buffer |
|
|
1297 | //fprintf(stderr, "flush_nodes:# freeing buffer #\n"); |
|
|
1298 | //free(node_buffer.base); |
|
|
1299 | //node_buffer.base = NULL; |
|
|
1300 | //node_buffer.malloced = 0; |
|
|
1301 | // //malloc a new buffer |
|
|
1302 | //node_buffer.malloced = 10 * 1024 * 1024; |
|
|
1303 | //node_buffer.base = malloc((size_t) node_buffer.malloced); // 10 MByte |
|
|
1304 | // ------ this part optional ------ |
|
|
1305 | |
|
|
1306 | // ------- need this always -------- |
|
|
1307 | |
|
|
1308 | //fprintf(stderr, "005t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1309 | node_buffer[local_thread_num].size = 0; |
|
|
1310 | //fprintf(stderr, "006t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1311 | |
|
|
1312 | //if (node_hash[local_thread_num]) |
|
|
1313 | if (node_hash_cfu[local_thread_num]) |
|
|
1314 | { |
|
|
1315 | if (verbose_mode) fprintf(stderr,"node_hash size="LONGLONG_FMT"\n", g_hash_table_size (node_hash[local_thread_num])); |
|
|
1316 | //g_hash_table_destroy(node_hash[local_thread_num]); |
|
|
1317 | //node_hash[local_thread_num] = NULL; |
|
|
1318 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
|
|
1319 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
|
|
1320 | node_hash_cfu[local_thread_num] = NULL; |
|
|
1321 | } |
1183 | } |
1322 | } |
|
|
1323 | if (verbose_mode) fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer[local_thread_num].size); |
|
|
1324 | if (verbose_mode) fprintf(stderr,"node: node_buffer malloced="LONGLONG_FMT"\n", node_buffer[local_thread_num].malloced); |
|
|
1325 | //fprintf(stderr, "007t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1326 | slices++; |
1184 | slices++; |
1327 | } |
1185 | } |
1328 | |
1186 | |
1329 | double transform_to_geo_lat(int y) |
1187 | void |
1330 | { |
|
|
1331 | double lat = navit_atan(exp(y / 6371000.0)) / M_PI * 360 - 90; |
|
|
1332 | return lat; |
|
|
1333 | } |
|
|
1334 | |
|
|
1335 | double transform_to_geo_lon(int x) |
|
|
1336 | { |
|
|
1337 | double lon = (x * 0.00000899322); |
|
|
1338 | return lon; |
|
|
1339 | } |
|
|
1340 | |
|
|
1341 | int transform_from_geo_lat(double lat) |
|
|
1342 | { |
|
|
1343 | /* slower */ |
|
|
1344 | // int ret = log(tan(M_PI_4 + lat * M_PI / 360)) * 6371000.0; |
|
|
1345 | //fprintf(stderr, "y=%d\n", ret); |
|
|
1346 | /* slower */ |
|
|
1347 | |
|
|
1348 | /* fast */ |
|
|
1349 | int ret = log(tan(M_PI_4 + lat * 0.008726646259971647884618)) * 6371000.0; // already calced (M_PI/360) |
|
|
1350 | /* fast */ |
|
|
1351 | |
|
|
1352 | return ret; |
|
|
1353 | } |
|
|
1354 | |
|
|
1355 | int transform_from_geo_lon(double lon) |
|
|
1356 | { |
|
|
1357 | /* slower */ |
|
|
1358 | //int ret = lon * 6371000.0 * M_PI / 180; |
|
|
1359 | // fprintf(stderr, "x=%d\n", ret); |
|
|
1360 | /* slower */ |
|
|
1361 | |
|
|
1362 | /* fast */ |
|
|
1363 | int ret = lon * 111194.9266445587373; // already calced (6371000.0*M_PI/180) |
|
|
1364 | /* fast */ |
|
|
1365 | |
|
|
1366 | return ret; |
|
|
1367 | } |
|
|
1368 | |
|
|
1369 | void osm_add_node(osmid id, double lat, double lon) |
1188 | osm_add_node(osmid id, double lat, double lon) |
1370 | { |
1189 | { |
1371 | in_node = 1; |
1190 | in_node=1; |
1372 | if (node_buffer[0].size + sizeof(struct node_item) > node_buffer[0].malloced) |
1191 | if (node_buffer.size + sizeof(struct node_item) > node_buffer.malloced) |
1373 | { |
|
|
1374 | extend_buffer(&node_buffer[0]); |
1192 | extend_buffer(&node_buffer); |
1375 | } |
|
|
1376 | attr_strings_clear(); |
1193 | attr_strings_clear(); |
1377 | node_is_tagged = 0; |
1194 | node_is_tagged=0; |
1378 | nodeid = id; |
1195 | nodeid=id; |
1379 | item.type = type_point_unkn; |
1196 | item.type=type_point_unkn; |
1380 | debug_attr_buffer[0] = '\0'; |
1197 | debug_attr_buffer[0]='\0'; |
1381 | is_in_buffer[0] = '\0'; |
1198 | is_in_buffer[0]='\0'; |
1382 | debug_attr_buffer[0] = '\0'; |
1199 | debug_attr_buffer[0]='\0'; |
1383 | osmid_attr.type = attr_osm_nodeid; |
1200 | osmid_attr.type=attr_osm_nodeid; |
1384 | osmid_attr.len = 3; |
1201 | osmid_attr.len=3; |
1385 | osmid_attr_value = id; |
1202 | osmid_attr_value=id; |
1386 | if (node_buffer[0].size + sizeof(struct node_item) > slice_size) |
1203 | if (node_buffer.size + sizeof(struct node_item) > slice_size) { |
1387 | { |
|
|
1388 | flush_nodes(0, 0); |
1204 | flush_nodes(0); |
1389 | } |
1205 | } |
1390 | ni = (struct node_item *) (node_buffer[0].base + node_buffer[0].size); |
1206 | ni=(struct node_item *)(node_buffer.base+node_buffer.size); |
1391 | ni->id = id; |
1207 | ni->id=id; |
1392 | ni->ref_node = 0; |
1208 | ni->ref_node=0; |
1393 | ni->ref_way = 0; |
1209 | ni->ref_way=0; |
1394 | ni->ref_ref = 0; |
1210 | ni->ref_ref=0; |
1395 | ni->dummy = 0; |
1211 | ni->dummy=0; |
1396 | |
|
|
1397 | /* slower */ |
|
|
1398 | // ni->c.x = lon * 6371000.0 * M_PI / 180; |
1212 | ni->c.x=lon*6371000.0*M_PI/180; |
1399 | // ni->c.y = log(tan(M_PI_4 + lat * M_PI / 360)) * 6371000.0; |
1213 | ni->c.y=log(tan(M_PI_4+lat*M_PI/360))*6371000.0; |
1400 | /* slower */ |
|
|
1401 | |
|
|
1402 | /* fast */ |
|
|
1403 | ni->c.x = lon * 111194.9266445587373; // already calced (6371000.0*M_PI/180) |
|
|
1404 | ni->c.y = log(tan(M_PI_4 + lat * 0.008726646259971647884618)) * 6371000.0; // already calced (M_PI/360) |
|
|
1405 | /* fast */ |
|
|
1406 | |
|
|
1407 | #ifdef MAPTOOL_USE_SQL |
|
|
1408 | |
|
|
1409 | if (sql_counter2 == 0) |
|
|
1410 | { |
|
|
1411 | sqlite3_exec(sql_handle002a, "BEGIN", 0, 0, 0); |
|
|
1412 | sqlite3_exec(sql_handle003a, "BEGIN", 0, 0, 0); |
|
|
1413 | sqlite3_exec(sql_handle002b, "BEGIN", 0, 0, 0); |
|
|
1414 | sqlite3_exec(sql_handle003b, "BEGIN", 0, 0, 0); |
|
|
1415 | } |
|
|
1416 | sql_counter2++; |
|
|
1417 | |
|
|
1418 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
1419 | if (nodeid % 2) |
|
|
1420 | { |
|
|
1421 | if ((nodeid & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
1422 | { |
|
|
1423 | sqlite3_bind_int64(stmt_node__2a, 1, nodeid); |
|
|
1424 | sqlite3_bind_double(stmt_node__2a, 2, lat); |
|
|
1425 | sqlite3_bind_double(stmt_node__2a, 3, lon); |
|
|
1426 | sqlite3_step(stmt_node__2a); |
|
|
1427 | sqlite3_reset(stmt_node__2a); |
|
|
1428 | } |
|
|
1429 | else |
|
|
1430 | { |
|
|
1431 | sqlite3_bind_int64(stmt_node__2b, 1, nodeid); |
|
|
1432 | sqlite3_bind_double(stmt_node__2b, 2, lat); |
|
|
1433 | sqlite3_bind_double(stmt_node__2b, 3, lon); |
|
|
1434 | sqlite3_step(stmt_node__2b); |
|
|
1435 | sqlite3_reset(stmt_node__2b); |
|
|
1436 | } |
|
|
1437 | } |
|
|
1438 | else |
|
|
1439 | { |
|
|
1440 | if ((nodeid & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
1441 | { |
|
|
1442 | #endif |
|
|
1443 | sqlite3_bind_int64(stmt_nodea, 1, nodeid); |
|
|
1444 | sqlite3_bind_double(stmt_nodea, 2, lat); |
|
|
1445 | sqlite3_bind_double(stmt_nodea, 3, lon); |
|
|
1446 | sqlite3_step(stmt_nodea); |
|
|
1447 | sqlite3_reset(stmt_nodea); |
|
|
1448 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
1449 | } |
|
|
1450 | else |
|
|
1451 | { |
|
|
1452 | sqlite3_bind_int64(stmt_nodeb, 1, nodeid); |
|
|
1453 | sqlite3_bind_double(stmt_nodeb, 2, lat); |
|
|
1454 | sqlite3_bind_double(stmt_nodeb, 3, lon); |
|
|
1455 | sqlite3_step(stmt_nodeb); |
|
|
1456 | sqlite3_reset(stmt_nodeb); |
|
|
1457 | } |
|
|
1458 | } |
|
|
1459 | #endif |
|
|
1460 | |
|
|
1461 | if (sql_counter2 > MAX_ROWS_WO_COMMIT) |
|
|
1462 | { |
|
|
1463 | sql_counter2 = 0; |
|
|
1464 | sqlite3_exec(sql_handle002a, "COMMIT", 0, 0, 0); |
|
|
1465 | sqlite3_exec(sql_handle003a, "COMMIT", 0, 0, 0); |
|
|
1466 | sqlite3_exec(sql_handle002b, "COMMIT", 0, 0, 0); |
|
|
1467 | sqlite3_exec(sql_handle003b, "COMMIT", 0, 0, 0); |
|
|
1468 | //fprintf(stderr, "SQL: COMMIT\n"); |
|
|
1469 | } |
|
|
1470 | |
|
|
1471 | #endif |
|
|
1472 | |
|
|
1473 | //fprintf(stderr,"node: %d %d\n", ni->c.x, ni->c.y); |
|
|
1474 | //fprintf(stderr,"node: %f %f\n", lat, lon); |
|
|
1475 | |
|
|
1476 | |
|
|
1477 | node_buffer[0].size += sizeof(struct node_item); |
1214 | node_buffer.size+=sizeof(struct node_item); |
1478 | //fprintf(stderr,"node: inc node_buffer by %d\n", sizeof(struct node_item)); |
|
|
1479 | //fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer.size); |
|
|
1480 | |
|
|
1481 | #if 0 |
|
|
1482 | //if (!node_hash[0]) |
1215 | if (! node_hash) { |
1483 | if (!node_hash_cfu[0]) |
|
|
1484 | { |
|
|
1485 | if (ni->id > nodeid_last) |
1216 | if (ni->id > nodeid_last) { |
1486 | { |
|
|
1487 | nodeid_last = ni->id; |
1217 | nodeid_last=ni->id; |
1488 | } |
|
|
1489 | else |
1218 | } else { |
1490 | { |
|
|
1491 | //fprintf(stderr,"INFO: Nodes out of sequence (new %d vs old %d), adding hash\n", ni->id, nodeid_last); |
1219 | fprintf(stderr,"INFO: Nodes out of sequence (new %d vs old %d), adding hash\n", ni->id, nodeid_last); |
1492 | //node_hash[0] = g_hash_table_new(NULL, NULL); |
1220 | node_hash=g_hash_table_new(NULL, NULL); |
1493 | |
|
|
1494 | node_hash_cfu[0] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_OTHER); |
|
|
1495 | cfuhash_set_flag(node_hash_cfu[0], CFUHASH_FROZEN); |
|
|
1496 | |
|
|
1497 | node_buffer_to_hash(0); |
1221 | node_buffer_to_hash(); |
1498 | } |
|
|
1499 | } |
1222 | } |
|
|
1223 | } else |
1500 | //else if (!g_hash_table_lookup(node_hash[0], (gpointer) (long) (ni->id))) |
1224 | if (!g_hash_table_lookup(node_hash, (gpointer)(long)(ni->id))) |
1501 | // else if (!cfuhash_exists(node_hash_cfu[0], (long long) ni->id )) |
|
|
1502 | |
|
|
1503 | else if (!cfuhash_exists_data(node_hash_cfu[0], (long long) ni->id, sizeof(long long))) |
|
|
1504 | { |
|
|
1505 | //g_hash_table_insert(node_hash[0], (gpointer) (long) (ni->id), (gpointer) (long) (ni - (struct node_item *) node_buffer[0].base)); |
1225 | g_hash_table_insert(node_hash, (gpointer)(long)(ni->id), (gpointer)(long)(ni-(struct node_item *)node_buffer.base)); |
1506 | //cfuhash_put(node_hash_cfu[0], (gpointer)ni->id, (gpointer)(long) (ni - (struct node_item *) node_buffer[0].base) ); |
|
|
1507 | cfuhash_put_data(node_hash_cfu[0], (long long)ni->id, sizeof(long long), (long) (ni - (struct node_item *) node_buffer[0].base), 1, NULL); |
|
|
1508 | |
|
|
1509 | } |
|
|
1510 | else |
1226 | else { |
1511 | { |
|
|
1512 | node_buffer[0].size -= sizeof(struct node_item); |
1227 | node_buffer.size-=sizeof(struct node_item); |
1513 | if (verbose_mode) |
|
|
1514 | fprintf(stderr, "node: Decr. node_buffer by %d\n", sizeof(struct node_item)); |
|
|
1515 | if (verbose_mode) fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer[0].size); |
|
|
1516 | nodeid = 0; |
1228 | nodeid=0; |
1517 | } |
1229 | } |
1518 | #endif |
|
|
1519 | |
1230 | |
1520 | } |
|
|
1521 | |
|
|
1522 | void clear_node_item_buffer(void) |
|
|
1523 | { |
|
|
1524 | int j, count = node_buffer[0].size / sizeof(struct node_item); |
|
|
1525 | struct node_item *ni = (struct node_item *) (node_buffer[0].base); |
|
|
1526 | for (j = 0; j < count; j++) |
|
|
1527 | { |
|
|
1528 | ni[j].ref_way = 0; |
|
|
1529 | } |
|
|
1530 | } |
1231 | } |
1531 | |
1232 | |
1532 | static struct node_item * |
1233 | static struct node_item * |
1533 | node_item_get_fast(int id, int local_thread_num) |
1234 | node_item_get(int id) |
1534 | { |
1235 | { |
1535 | int i; |
|
|
1536 | void *p_tmp; |
|
|
1537 | int rr; |
|
|
1538 | size_t data_size2 = sizeof(int *); |
|
|
1539 | struct node_item *ni = (struct node_item *) (node_buffer[local_thread_num].base); |
1236 | struct node_item *ni=(struct node_item *)(node_buffer.base); |
1540 | |
|
|
1541 | //if (node_hash[local_thread_num]) |
|
|
1542 | if (node_hash_cfu[local_thread_num]) |
|
|
1543 | { |
|
|
1544 | //p_tmp = (gpointer)(g_hash_table_lookup(node_hash[local_thread_num], (gpointer) (long) id)); |
|
|
1545 | rr = cfuhash_get_data(node_hash_cfu[local_thread_num], (long long) id, sizeof(long long), &p_tmp, &data_size2); |
|
|
1546 | if (rr == 1) |
|
|
1547 | { |
|
|
1548 | // printf("got value %ld\n", p_tmp); |
|
|
1549 | i = p_tmp; |
|
|
1550 | return ni + i; |
|
|
1551 | } |
|
|
1552 | |
|
|
1553 | //if (p_tmp != NULL) |
|
|
1554 | //{ |
|
|
1555 | // // only if node is found in hash! |
|
|
1556 | // i = (int) (long) (p_tmp); |
|
|
1557 | // return ni + i; |
|
|
1558 | //} |
|
|
1559 | } |
|
|
1560 | return NULL; |
|
|
1561 | } |
|
|
1562 | |
|
|
1563 | static struct node_item * |
|
|
1564 | node_item_get(int id, int local_thread_num) |
|
|
1565 | { |
|
|
1566 | struct node_item *ni = (struct node_item *) (node_buffer[local_thread_num].base); |
|
|
1567 | int count = node_buffer[local_thread_num].size / sizeof(struct node_item); |
1237 | int count=node_buffer.size/sizeof(struct node_item); |
1568 | int interval = count / 4; |
1238 | int interval=count/4; |
1569 | int p = count / 2; |
1239 | int p=count/2; |
1570 | if (interval == 0) |
1240 | if(interval==0) { |
1571 | { |
|
|
1572 | // If fewer than 4 nodes defined so far set interval to 1 to |
1241 | // If fewer than 4 nodes defined so far set interval to 1 to |
1573 | // avoid infinite loop |
1242 | // avoid infinite loop |
1574 | interval = 1; |
1243 | interval = 1; |
1575 | } |
1244 | } |
1576 | |
1245 | if (node_hash) { |
1577 | if (node_hash[local_thread_num]) |
|
|
1578 | { |
|
|
1579 | int i; |
1246 | int i; |
1580 | void* p_tmp = (gpointer)(g_hash_table_lookup(node_hash[local_thread_num], (gpointer) (long) id)); |
1247 | i=(int)(long)(g_hash_table_lookup(node_hash, (gpointer)(long)id)); |
1581 | if (p_tmp != NULL) |
|
|
1582 | { |
|
|
1583 | // only if node is found in hash! |
|
|
1584 | i = (int) (long) (p_tmp); |
|
|
1585 | return ni + i; |
1248 | return ni+i; |
1586 | } |
1249 | } |
1587 | } |
|
|
1588 | |
|
|
1589 | fprintf(stderr, "[THREAD] #%d **BAD**\n", local_thread_num); |
|
|
1590 | // return NULL; |
|
|
1591 | |
|
|
1592 | if (ni[0].id > id) |
1250 | if (ni[0].id > id) |
1593 | { |
|
|
1594 | return NULL; |
1251 | return NULL; |
1595 | } |
|
|
1596 | |
|
|
1597 | if (ni[count - 1].id < id) |
1252 | if (ni[count-1].id < id) |
1598 | { |
|
|
1599 | return NULL; |
1253 | return NULL; |
1600 | } |
|
|
1601 | |
|
|
1602 | while (ni[p].id != id) |
1254 | while (ni[p].id != id) { |
1603 | { |
|
|
1604 | #if 0 |
1255 | #if 0 |
1605 | fprintf(stderr,"p=%d count=%d interval=%d id=%d ni[p].id=%d\n", p, count, interval, id, ni[p].id); |
1256 | fprintf(stderr,"p=%d count=%d interval=%d id=%d ni[p].id=%d\n", p, count, interval, id, ni[p].id); |
1606 | #endif |
1257 | #endif |
1607 | if (ni[p].id < id) |
1258 | if (ni[p].id < id) { |
1608 | { |
|
|
1609 | p += interval; |
1259 | p+=interval; |
1610 | if (interval == 1) |
1260 | if (interval == 1) { |
1611 | { |
|
|
1612 | if (p >= count) |
1261 | if (p >= count) |
1613 | return NULL; |
1262 | return NULL; |
1614 | |
|
|
1615 | if (ni[p].id > id) |
1263 | if (ni[p].id > id) |
1616 | return NULL; |
1264 | return NULL; |
|
|
1265 | } else { |
|
|
1266 | if (p >= count) |
|
|
1267 | p=count-1; |
1617 | } |
1268 | } |
1618 | else |
|
|
1619 | { |
|
|
1620 | if (p >= count) |
|
|
1621 | p = count - 1; |
|
|
1622 | } |
|
|
1623 | } |
|
|
1624 | else |
1269 | } else { |
1625 | { |
|
|
1626 | p -= interval; |
1270 | p-=interval; |
1627 | if (interval == 1) |
1271 | if (interval == 1) { |
1628 | { |
|
|
1629 | if (p < 0) |
1272 | if (p < 0) |
1630 | return NULL; |
1273 | return NULL; |
1631 | if (ni[p].id < id) |
1274 | if (ni[p].id < id) |
1632 | return NULL; |
1275 | return NULL; |
|
|
1276 | } else { |
|
|
1277 | if (p < 0) |
|
|
1278 | p=0; |
1633 | } |
1279 | } |
|
|
1280 | } |
|
|
1281 | if (interval > 1) |
|
|
1282 | interval/=2; |
|
|
1283 | } |
|
|
1284 | |
|
|
1285 | return &ni[p]; |
|
|
1286 | } |
|
|
1287 | |
|
|
1288 | static int |
|
|
1289 | load_node(FILE *coords, int p, struct node_item *ret) |
|
|
1290 | { |
|
|
1291 | fseek(coords, p*sizeof(struct node_item), SEEK_SET); |
|
|
1292 | if (fread(ret, sizeof(*ret), 1, coords) != 1) { |
|
|
1293 | fprintf(stderr,"read failed\n"); |
|
|
1294 | return 0; |
|
|
1295 | } |
|
|
1296 | return 1; |
|
|
1297 | } |
|
|
1298 | |
|
|
1299 | static int |
|
|
1300 | node_item_get_from_file(FILE *coords, int id, struct node_item *ret) |
|
|
1301 | { |
|
|
1302 | int count; |
|
|
1303 | int interval; |
|
|
1304 | int p; |
|
|
1305 | if (node_hash) { |
|
|
1306 | int i; |
|
|
1307 | i=(int)(long)(g_hash_table_lookup(node_hash, (gpointer)(long)id)); |
|
|
1308 | fseek(coords, i*sizeof(*ret), SEEK_SET); |
|
|
1309 | if (fread(ret, sizeof(*ret), 1, coords) == 1) |
|
|
1310 | return 1; |
1634 | else |
1311 | else |
|
|
1312 | return 0; |
|
|
1313 | } |
|
|
1314 | |
|
|
1315 | fseek(coords, 0, SEEK_END); |
|
|
1316 | count=ftell(coords)/sizeof(struct node_item); |
|
|
1317 | interval=count/4; |
|
|
1318 | p=count/2; |
|
|
1319 | if(interval==0) { |
|
|
1320 | // If fewer than 4 nodes defined so far set interval to 1 to |
|
|
1321 | // avoid infinite loop |
|
|
1322 | interval = 1; |
|
|
1323 | } |
|
|
1324 | if (!load_node(coords, p, ret)) |
|
|
1325 | return 0; |
|
|
1326 | for (;;) { |
|
|
1327 | if (ret->id == id) |
|
|
1328 | return 1; |
|
|
1329 | if (ret->id < id) { |
|
|
1330 | p+=interval; |
|
|
1331 | if (interval == 1) { |
|
|
1332 | if (p >= count) |
|
|
1333 | return 0; |
|
|
1334 | if (!load_node(coords, p, ret)) |
|
|
1335 | return 0; |
|
|
1336 | if (ret->id > id) |
|
|
1337 | return 0; |
|
|
1338 | } else { |
|
|
1339 | if (p >= count) |
|
|
1340 | p=count-1; |
|
|
1341 | if (!load_node(coords, p, ret)) |
|
|
1342 | return 0; |
1635 | { |
1343 | } |
|
|
1344 | } else { |
|
|
1345 | p-=interval; |
|
|
1346 | if (interval == 1) { |
1636 | if (p < 0) |
1347 | if (p < 0) |
|
|
1348 | return 0; |
|
|
1349 | if (!load_node(coords, p, ret)) |
|
|
1350 | return 0; |
|
|
1351 | if (ret->id < id) |
|
|
1352 | return 0; |
|
|
1353 | } else { |
|
|
1354 | if (p < 0) |
1637 | p = 0; |
1355 | p=0; |
|
|
1356 | if (!load_node(coords, p, ret)) |
|
|
1357 | return 0; |
1638 | } |
1358 | } |
1639 | } |
1359 | } |
1640 | |
|
|
1641 | if (interval > 1) |
1360 | if (interval > 1) |
1642 | interval /= 2; |
1361 | interval/=2; |
1643 | } |
1362 | } |
1644 | |
|
|
1645 | return &ni[p]; |
|
|
1646 | } |
1363 | } |
1647 | |
1364 | |
1648 | static int load_node(FILE *coords, int p, struct node_item *ret) |
1365 | void |
1649 | { |
|
|
1650 | fseek(coords, p * sizeof(struct node_item), SEEK_SET); |
|
|
1651 | if (fread(ret, sizeof(*ret), 1, coords) != 1) |
|
|
1652 | { |
|
|
1653 | fprintf(stderr, "read failed\n"); |
|
|
1654 | return 0; |
|
|
1655 | } |
|
|
1656 | return 1; |
|
|
1657 | } |
|
|
1658 | |
|
|
1659 | void osm_add_way(osmid id) |
1366 | osm_add_way(osmid id) |
1660 | { |
1367 | { |
1661 | static int wayid_last; |
1368 | static int wayid_last; |
1662 | |
1369 | |
1663 | in_way = 1; |
1370 | in_way=1; |
1664 | wayid = id; |
1371 | wayid=id; |
1665 | coord_count = 0; |
1372 | coord_count=0; |
1666 | attr_strings_clear(); |
1373 | attr_strings_clear(); |
1667 | item.type = type_street_unkn; |
1374 | item.type=type_street_unkn; |
1668 | debug_attr_buffer[0] = '\0'; |
1375 | debug_attr_buffer[0]='\0'; |
1669 | maxspeed_attr_value = 0; |
1376 | maxspeed_attr_value=0; |
1670 | flags_attr_value = 0; |
1377 | flags_attr_value = 0; |
1671 | memset(flags, 0, sizeof(flags)); |
1378 | memset(flags, 0, sizeof(flags)); |
1672 | debug_attr_buffer[0] = '\0'; |
1379 | debug_attr_buffer[0]='\0'; |
1673 | osmid_attr_value = id; |
1380 | osmid_attr_value=id; |
1674 | if (wayid < wayid_last && !way_hash_cfu) |
1381 | if (wayid < wayid_last && !way_hash) { |
1675 | { |
|
|
1676 | if (verbose_mode) |
|
|
1677 | { |
|
|
1678 | fprintf(stderr, "INFO: Ways out of sequence (new %d vs old %d), adding hash\n", wayid, wayid_last); |
1382 | fprintf(stderr,"INFO: Ways out of sequence (new %d vs old %d), adding hash\n", wayid, wayid_last); |
1679 | } |
|
|
1680 | // way_hash = g_hash_table_new(NULL, NULL); |
1383 | way_hash=g_hash_table_new(NULL, NULL); |
1681 | way_hash_cfu = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_WAYS); |
|
|
1682 | cfuhash_set_flag(node_hash_cfu, CFUHASH_FROZEN); |
|
|
1683 | |
|
|
1684 | } |
1384 | } |
1685 | wayid_last = wayid; |
1385 | wayid_last=wayid; |
1686 | } |
1386 | } |
1687 | |
1387 | |
1688 | char relation_type[BUFFER_SIZE]; |
1388 | char relation_type[BUFFER_SIZE]; |
1689 | char iso_code[BUFFER_SIZE]; |
1389 | char iso_code[BUFFER_SIZE]; |
1690 | int admin_level; |
1390 | int admin_level; |
1691 | int boundary; |
1391 | int boundary; |
1692 | |
1392 | |
|
|
1393 | void |
1693 | void osm_add_relation(osmid id) |
1394 | osm_add_relation(osmid id) |
1694 | { |
1395 | { |
|
|
1396 | struct attr idattr = { attr_type }; |
1695 | current_id = id; |
1397 | current_id=id; |
1696 | in_relation = 1; |
1398 | in_relation=1; |
1697 | debug_attr_buffer[0] = '\0'; |
1399 | debug_attr_buffer[0]='\0'; |
1698 | relation_type[0] = '\0'; |
1400 | relation_type[0]='\0'; |
1699 | iso_code[0] = '\0'; |
1401 | iso_code[0]='\0'; |
1700 | admin_level = -1; |
1402 | admin_level=-1; |
1701 | boundary = 0; |
1403 | boundary=0; |
1702 | item_bin_init(item_bin_2, type_none); |
1404 | item_bin_init(item_bin, type_none); |
1703 | item_bin_add_attr_longlong(item_bin_2, attr_osm_relationid, current_id); |
1405 | idattr.u.num64=¤t_id; |
|
|
1406 | item_bin_add_attr(item_bin, &idattr); |
1704 | } |
1407 | } |
1705 | |
1408 | |
1706 | static int country_id_from_iso2(char *iso) |
1409 | void |
|
|
1410 | osm_end_relation(FILE *turn_restrictions, FILE *boundaries) |
1707 | { |
1411 | { |
1708 | int ret = 0; |
1412 | in_relation=0; |
1709 | if (iso) |
1413 | if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) { |
1710 | { |
|
|
1711 | // make lowercase |
|
|
1712 | int i99; |
|
|
1713 | for (i99 = 0; iso[i99]; i99++) |
|
|
1714 | { |
|
|
1715 | iso[i99] = tolower(iso[i99]); |
|
|
1716 | } |
|
|
1717 | struct country_search *search; |
|
|
1718 | struct attr country_iso2, country_id; |
|
|
1719 | struct item *item; |
|
|
1720 | country_iso2.type = attr_country_iso2; |
|
|
1721 | country_iso2.u.str = iso; |
|
|
1722 | search = country_search_new(&country_iso2, 0); |
|
|
1723 | if ((item = country_search_get_item(search)) && item_attr_get(item, attr_country_id, &country_id)) |
|
|
1724 | { |
|
|
1725 | ret = country_id.u.num; |
|
|
1726 | if (debug_itembin(3)) |
|
|
1727 | { |
|
|
1728 | fprintf(stderr, "country id(1)=%d\n", ret); |
|
|
1729 | } |
|
|
1730 | } |
|
|
1731 | else |
|
|
1732 | { |
|
|
1733 | if (debug_itembin(3)) |
|
|
1734 | { |
|
|
1735 | fprintf(stderr, "country id(2)=%d\n", ret); |
|
|
1736 | } |
|
|
1737 | } |
|
|
1738 | country_search_destroy(search); |
|
|
1739 | } |
|
|
1740 | return ret; |
|
|
1741 | } |
|
|
1742 | |
|
|
1743 | static struct country_table * |
|
|
1744 | country_from_countryid(int id) |
|
|
1745 | { |
|
|
1746 | int i; |
|
|
1747 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
|
|
1748 | { |
|
|
1749 | //if (debug_itembin(3)) |
|
|
1750 | //{ |
|
|
1751 | // fprintf(stderr,"== country_from_countryid: %d ==\n", country_table[i].countryid); |
|
|
1752 | //} |
|
|
1753 | |
|
|
1754 | if (country_table[i].countryid == id) |
|
|
1755 | { |
|
|
1756 | return &country_table[i]; |
|
|
1757 | } |
|
|
1758 | } |
|
|
1759 | |
|
|
1760 | //if (debug_itembin(3)) |
|
|
1761 | //{ |
|
|
1762 | // fprintf(stderr,"== country_from_countryid: return NULL ==\n"); |
|
|
1763 | //} |
|
|
1764 | |
|
|
1765 | return NULL; |
|
|
1766 | } |
|
|
1767 | |
|
|
1768 | struct country_table * |
|
|
1769 | country_from_iso2(char *iso) |
|
|
1770 | { |
|
|
1771 | return country_from_countryid(country_id_from_iso2(iso)); |
|
|
1772 | } |
|
|
1773 | |
|
|
1774 | static int get_relation_member(char *str, struct relation_member *memb) |
|
|
1775 | { |
|
|
1776 | int len; |
|
|
1777 | sscanf(str,"%d:"LONGLONG_FMT":%n",&memb->type,&memb->id,&len); |
|
|
1778 | memb->role = str + len; |
|
|
1779 | return 1; |
|
|
1780 | } |
|
|
1781 | |
|
|
1782 | #if 0 |
1414 | #if 0 |
1783 | void report(io, markers, reporttriangles, reportneighbors, reportsegments, reportedges, reportnorms) |
|
|
1784 | struct triangulateio *io;int markers;int reporttriangles;int reportneighbors;int reportsegments;int reportedges;int reportnorms; |
|
|
1785 | { |
|
|
1786 | int i, j; |
|
|
1787 | |
|
|
1788 | for (i = 0; i < io->numberofpoints; i++) |
|
|
1789 | { |
|
|
1790 | fprintf(stderr, "Point %4d:", i); |
|
|
1791 | for (j = 0; j < 2; j++) |
|
|
1792 | { |
|
|
1793 | fprintf(stderr, " %.6g", io->pointlist[i * 2 + j]); |
|
|
1794 | } |
|
|
1795 | if (io->numberofpointattributes > 0) |
|
|
1796 | { |
|
|
1797 | fprintf(stderr, " attributes"); |
|
|
1798 | } |
|
|
1799 | for (j = 0; j < io->numberofpointattributes; j++) |
|
|
1800 | { |
|
|
1801 | fprintf(stderr, " %.6g", io->pointattributelist[i * io->numberofpointattributes + j]); |
|
|
1802 | } |
|
|
1803 | if (markers) |
|
|
1804 | { |
|
|
1805 | fprintf(stderr, " marker %d\n", io->pointmarkerlist[i]); |
|
|
1806 | } |
|
|
1807 | else |
|
|
1808 | { |
|
|
1809 | fprintf(stderr, "\n"); |
|
|
1810 | } |
|
|
1811 | } |
|
|
1812 | fprintf(stderr, "\n"); |
|
|
1813 | |
|
|
1814 | if (reporttriangles || reportneighbors) |
|
|
1815 | { |
|
|
1816 | for (i = 0; i < io->numberoftriangles; i++) |
|
|
1817 | { |
|
|
1818 | if (reporttriangles) |
|
|
1819 | { |
|
|
1820 | fprintf(stderr, "Triangle %4d points:", i); |
|
|
1821 | for (j = 0; j < io->numberofcorners; j++) |
|
|
1822 | { |
|
|
1823 | fprintf(stderr, " %4d", io->trianglelist[i * io->numberofcorners + j]); |
|
|
1824 | } |
|
|
1825 | if (io->numberoftriangleattributes > 0) |
|
|
1826 | { |
|
|
1827 | fprintf(stderr, " attributes"); |
|
|
1828 | } |
|
|
1829 | for (j = 0; j < io->numberoftriangleattributes; j++) |
|
|
1830 | { |
|
|
1831 | fprintf(stderr, " %.6g", io->triangleattributelist[i * io->numberoftriangleattributes + j]); |
|
|
1832 | } |
|
|
1833 | fprintf(stderr, "\n"); |
|
|
1834 | } |
|
|
1835 | if (reportneighbors) |
|
|
1836 | { |
|
|
1837 | fprintf(stderr, "Triangle %4d neighbors:", i); |
|
|
1838 | for (j = 0; j < 3; j++) |
|
|
1839 | { |
|
|
1840 | fprintf(stderr, " %4d", io->neighborlist[i * 3 + j]); |
|
|
1841 | } |
|
|
1842 | fprintf(stderr, "\n"); |
|
|
1843 | } |
|
|
1844 | } |
|
|
1845 | fprintf(stderr, "\n"); |
|
|
1846 | } |
|
|
1847 | |
|
|
1848 | if (reportsegments) |
|
|
1849 | { |
|
|
1850 | for (i = 0; i < io->numberofsegments; i++) |
|
|
1851 | { |
|
|
1852 | fprintf(stderr, "Segment %4d points:", i); |
|
|
1853 | for (j = 0; j < 2; j++) |
|
|
1854 | { |
|
|
1855 | fprintf(stderr, " %4d", io->segmentlist[i * 2 + j]); |
|
|
1856 | } |
|
|
1857 | if (markers) |
|
|
1858 | { |
|
|
1859 | fprintf(stderr, " marker %d\n", io->segmentmarkerlist[i]); |
|
|
1860 | } |
|
|
1861 | else |
|
|
1862 | { |
|
|
1863 | fprintf(stderr, "\n"); |
|
|
1864 | } |
|
|
1865 | } |
|
|
1866 | fprintf(stderr, "\n"); |
|
|
1867 | } |
|
|
1868 | |
|
|
1869 | if (reportedges) |
|
|
1870 | { |
|
|
1871 | for (i = 0; i < io->numberofedges; i++) |
|
|
1872 | { |
|
|
1873 | fprintf(stderr, "Edge %4d points:", i); |
|
|
1874 | for (j = 0; j < 2; j++) |
|
|
1875 | { |
|
|
1876 | fprintf(stderr, " %4d", io->edgelist[i * 2 + j]); |
|
|
1877 | } |
|
|
1878 | if (reportnorms && (io->edgelist[i * 2 + 1] == -1)) |
|
|
1879 | { |
|
|
1880 | for (j = 0; j < 2; j++) |
|
|
1881 | { |
|
|
1882 | fprintf(stderr, " %.6g", io->normlist[i * 2 + j]); |
|
|
1883 | } |
|
|
1884 | } |
|
|
1885 | if (markers) |
|
|
1886 | { |
|
|
1887 | fprintf(stderr, " marker %d\n", io->edgemarkerlist[i]); |
|
|
1888 | } |
|
|
1889 | else |
|
|
1890 | { |
|
|
1891 | fprintf(stderr, "\n"); |
|
|
1892 | } |
|
|
1893 | } |
|
|
1894 | fprintf(stderr, "\n"); |
|
|
1895 | } |
|
|
1896 | } |
|
|
1897 | |
|
|
1898 | #endif |
|
|
1899 | |
|
|
1900 | void get_lat_lon_for_node(long long nd, struct node_lat_lon *node); |
|
|
1901 | |
|
|
1902 | void get_lat_lon_way_first_node(long long way_id, struct node_lat_lon *node) |
|
|
1903 | { |
|
|
1904 | int rc2; |
|
|
1905 | sqlite3_stmt *st; |
|
|
1906 | long long nd = 0; |
|
|
1907 | |
|
|
1908 | |
|
|
1909 | node->valid = 0; |
|
|
1910 | |
|
|
1911 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
1912 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
|
|
1913 | { |
|
|
1914 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
1915 | { |
|
|
1916 | #endif |
|
|
1917 | st = stmt_sel001; |
|
|
1918 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
1919 | } |
|
|
1920 | else |
|
|
1921 | { |
|
|
1922 | st = stmt_sel001b; |
|
|
1923 | } |
|
|
1924 | } |
|
|
1925 | else |
|
|
1926 | { |
|
|
1927 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
1928 | { |
|
|
1929 | st = stmt_sel001__2; |
|
|
1930 | } |
|
|
1931 | else |
|
|
1932 | { |
|
|
1933 | st = stmt_sel001__2b; |
|
|
1934 | } |
|
|
1935 | } |
|
|
1936 | #endif |
|
|
1937 | sqlite3_bind_int64(st, 1, way_id); |
|
|
1938 | |
|
|
1939 | // execute the statement |
|
|
1940 | rc2 = sqlite3_step(st); |
|
|
1941 | switch (rc2) |
|
|
1942 | { |
|
|
1943 | case SQLITE_DONE: |
|
|
1944 | break; |
|
|
1945 | case SQLITE_ROW: |
|
|
1946 | nd = sqlite3_column_int64(st, 0); |
|
|
1947 | break; |
|
|
1948 | default: |
|
|
1949 | fprintf(stderr, "Error: %d\n", rc2); |
|
|
1950 | break; |
|
|
1951 | } |
|
|
1952 | sqlite3_reset(st); |
|
|
1953 | |
|
|
1954 | if (nd != 0) |
|
|
1955 | { |
|
|
1956 | get_lat_lon_for_node(nd, node); |
|
|
1957 | } |
|
|
1958 | } |
|
|
1959 | |
|
|
1960 | void get_lat_lon_for_node(long long nd, struct node_lat_lon *node) |
|
|
1961 | { |
|
|
1962 | int rc2; |
|
|
1963 | |
|
|
1964 | // now read the coords of this node |
|
|
1965 | node->valid = 0; |
|
|
1966 | |
|
|
1967 | #ifdef MAPTOOL_USE_SQL |
|
|
1968 | |
|
|
1969 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
1970 | if (nd % 2) |
|
|
1971 | { |
|
|
1972 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
1973 | { |
|
|
1974 | sqlite3_bind_int64(stmt_sel002__2a, 1, nd); |
|
|
1975 | } |
|
|
1976 | else |
|
|
1977 | { |
|
|
1978 | sqlite3_bind_int64(stmt_sel002__2b, 1, nd); |
|
|
1979 | } |
|
|
1980 | } |
|
|
1981 | else |
|
|
1982 | { |
|
|
1983 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
1984 | { |
|
|
1985 | #endif |
|
|
1986 | sqlite3_bind_int64(stmt_sel002a, 1, nd); |
|
|
1987 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
1988 | } |
|
|
1989 | else |
|
|
1990 | { |
|
|
1991 | sqlite3_bind_int64(stmt_sel002b, 1, nd); |
|
|
1992 | } |
|
|
1993 | } |
|
|
1994 | #endif |
|
|
1995 | |
|
|
1996 | rc2 = 0; |
|
|
1997 | //do |
|
|
1998 | //{ |
|
|
1999 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2000 | if (nd % 2) |
|
|
2001 | { |
|
|
2002 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2003 | { |
|
|
2004 | rc2 = sqlite3_step(stmt_sel002__2a); |
|
|
2005 | } |
|
|
2006 | else |
|
|
2007 | { |
|
|
2008 | rc2 = sqlite3_step(stmt_sel002__2b); |
|
|
2009 | } |
|
|
2010 | } |
|
|
2011 | else |
|
|
2012 | { |
|
|
2013 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2014 | { |
|
|
2015 | #endif |
|
|
2016 | rc2 = sqlite3_step(stmt_sel002a); |
|
|
2017 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2018 | } |
|
|
2019 | else |
|
|
2020 | { |
|
|
2021 | rc2 = sqlite3_step(stmt_sel002b); |
|
|
2022 | } |
|
|
2023 | } |
|
|
2024 | #endif |
|
|
2025 | //cols2 = sqlite3_column_count(stmt_sel002); |
|
|
2026 | switch (rc2) |
|
|
2027 | { |
|
|
2028 | //case SQLITE_DONE: |
|
|
2029 | // break; |
|
|
2030 | case SQLITE_ROW: |
|
|
2031 | |
|
|
2032 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2033 | if (nd % 2) |
|
|
2034 | { |
|
|
2035 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2036 | { |
|
|
2037 | node->lat = (double) sqlite3_column_double(stmt_sel002__2a, 0); |
|
|
2038 | node->lon = (double) sqlite3_column_double(stmt_sel002__2a, 1); |
|
|
2039 | } |
|
|
2040 | else |
|
|
2041 | { |
|
|
2042 | node->lat = (double) sqlite3_column_double(stmt_sel002__2b, 0); |
|
|
2043 | node->lon = (double) sqlite3_column_double(stmt_sel002__2b, 1); |
|
|
2044 | } |
|
|
2045 | } |
|
|
2046 | else |
|
|
2047 | { |
|
|
2048 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2049 | { |
|
|
2050 | #endif |
|
|
2051 | node->lat = (double) sqlite3_column_double(stmt_sel002a, 0); |
|
|
2052 | node->lon = (double) sqlite3_column_double(stmt_sel002a, 1); |
|
|
2053 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2054 | } |
|
|
2055 | else |
|
|
2056 | { |
|
|
2057 | node->lat = (double) sqlite3_column_double(stmt_sel002b, 0); |
|
|
2058 | node->lon = (double) sqlite3_column_double(stmt_sel002b, 1); |
|
|
2059 | } |
|
|
2060 | } |
|
|
2061 | #endif |
|
|
2062 | node->valid = 1; |
|
|
2063 | break; |
|
|
2064 | default: |
|
|
2065 | fprintf(stderr, "get_lat_lon_for_node:SQL Error: %d nodeid:%lld\n", rc2, nd); |
|
|
2066 | break; |
|
|
2067 | } |
|
|
2068 | //} |
|
|
2069 | //while (rc2 == SQLITE_ROW); |
|
|
2070 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2071 | if (nd % 2) |
|
|
2072 | { |
|
|
2073 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2074 | { |
|
|
2075 | sqlite3_reset(stmt_sel002__2a); |
|
|
2076 | } |
|
|
2077 | else |
|
|
2078 | { |
|
|
2079 | sqlite3_reset(stmt_sel002__2b); |
|
|
2080 | } |
|
|
2081 | } |
|
|
2082 | else |
|
|
2083 | { |
|
|
2084 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2085 | { |
|
|
2086 | #endif |
|
|
2087 | sqlite3_reset(stmt_sel002a); |
|
|
2088 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2089 | } |
|
|
2090 | else |
|
|
2091 | { |
|
|
2092 | sqlite3_reset(stmt_sel002b); |
|
|
2093 | } |
|
|
2094 | } |
|
|
2095 | #endif |
|
|
2096 | #endif |
|
|
2097 | |
|
|
2098 | } |
|
|
2099 | |
|
|
2100 | void catch_signal(int param) |
|
|
2101 | { |
|
|
2102 | // fprintf (stderr, "Terminating program...\n"); |
|
|
2103 | fprintf(stderr, "****** got SIGSEGV ******\n"); |
|
|
2104 | THROW(MAPTOOL_00002_EXCEPTION); |
|
|
2105 | // exit(1); |
|
|
2106 | } |
|
|
2107 | |
|
|
2108 | struct way_and_endnodes |
|
|
2109 | { |
|
|
2110 | unsigned long long way_id; |
|
|
2111 | unsigned long long first_node_id; |
|
|
2112 | unsigned long long last_node_id; |
|
|
2113 | int reverse; |
|
|
2114 | int role; |
|
|
2115 | GList *nodes; |
|
|
2116 | }; |
|
|
2117 | |
|
|
2118 | // if same value -> 0 |
|
|
2119 | // otherwise -> 1 |
|
|
2120 | gint comp_func(gconstpointer item1, gconstpointer item2) |
|
|
2121 | { |
|
|
2122 | long long a; |
|
|
2123 | long long b; |
|
|
2124 | |
|
|
2125 | a = *((long long *) item1); |
|
|
2126 | b = *((long long *) item2); |
|
|
2127 | |
|
|
2128 | //fprintf(stderr," item1=%lld\n", a); |
|
|
2129 | //fprintf(stderr," item2=%lld\n", b); |
|
|
2130 | |
|
|
2131 | if (a == b) |
|
|
2132 | { |
|
|
2133 | return 0; |
|
|
2134 | } |
|
|
2135 | |
|
|
2136 | return 1; |
|
|
2137 | } |
|
|
2138 | |
|
|
2139 | // return 0 if item is not found in GList |
|
|
2140 | int glist_find_already_inside(GList* list, gconstpointer item) |
|
|
2141 | { |
|
|
2142 | if (g_list_find_custom(list, item, (GCompareFunc) comp_func) == NULL) |
|
|
2143 | { |
|
|
2144 | return 0; |
|
|
2145 | } |
|
|
2146 | return 1; |
|
|
2147 | } |
|
|
2148 | |
|
|
2149 | void osm_end_relation(struct maptool_osm *osm) |
|
|
2150 | { |
|
|
2151 | //fprintf(stderr, "XXX000\n"); |
|
|
2152 | |
|
|
2153 | struct item_bin *item_bin_tri; |
|
|
2154 | struct coord coord_tri; |
|
|
2155 | struct node_lat_lon node_coords; |
|
|
2156 | int i9; |
|
|
2157 | int j9; |
|
|
2158 | int tmp9; |
|
|
2159 | |
|
|
2160 | int save_relation = 0; |
|
|
2161 | int save_relations_other_method = 0; |
|
|
2162 | int tag_id = 1; |
|
|
2163 | char *str = NULL; |
|
|
2164 | int triangulate_not_done = 1; |
|
|
2165 | int problem = 0; |
|
|
2166 | struct relation_member memb; |
|
|
2167 | struct relation_member memb2; |
|
|
2168 | struct way_and_endnodes *way_nodes1; |
|
|
2169 | struct way_and_endnodes *way_nodes2; |
|
|
2170 | int found_new_way = 0; |
|
|
2171 | gpointer *gptr; |
|
|
2172 | int rc = 0; |
|
|
2173 | int rc2 = 0; |
|
|
2174 | int cols; |
|
|
2175 | int col; |
|
|
2176 | int first_node_found = 0; |
|
|
2177 | long long nd; |
|
|
2178 | long long first_nd; |
|
|
2179 | long long search_nd; |
|
|
2180 | long long *ndptr; |
|
|
2181 | |
|
|
2182 | /* |
|
|
2183 | long lat_nd; |
|
|
2184 | long lon_nd; |
|
|
2185 | */ |
|
|
2186 | |
|
|
2187 | double lat_nd; |
|
|
2188 | double lon_nd; |
|
|
2189 | |
|
|
2190 | int number_of_points_in_poly = 0; |
|
|
2191 | int number_of_points_current_poly = 0; |
|
|
2192 | int exception = 0; |
|
|
2193 | int role_ = 0; |
|
|
2194 | |
|
|
2195 | double factor = 10000000; |
|
|
2196 | |
|
|
2197 | // triangulate vars |
|
|
2198 | #if 0 |
|
|
2199 | struct triangulateio in, mid, out, vorout; |
|
|
2200 | #endif |
|
|
2201 | |
|
|
2202 | #ifdef MAPTOOL_TRIANGULATE |
|
|
2203 | GPtrArray *current_points; |
|
|
2204 | GPtrArray *current_hole; |
|
|
2205 | P2tCDT *cdt; |
|
|
2206 | P2trCDT *rcdt; |
|
|
2207 | P2trRefiner *refiner; |
|
|
2208 | P2tTrianglePtrArray triangles; |
|
|
2209 | gint refine_max_steps = 1000; |
|
|
2210 | double x; |
|
|
2211 | double y; |
|
|
2212 | int i; |
|
|
2213 | int j; |
|
|
2214 | GHashTable *point_map; |
|
|
2215 | P2trCDT *rmesh; |
|
|
2216 | #endif |
|
|
2217 | GList *all_holes; |
|
|
2218 | |
|
|
2219 | int count_of_outer_ways = 0; |
|
|
2220 | |
|
|
2221 | GList *unsorted_outer_ways = NULL; |
|
|
2222 | GList *unsorted_inner_ways = NULL; |
|
|
2223 | GList *sorted_outer_ways = NULL; |
|
|
2224 | GList *temp_nodes_list = NULL; |
|
|
2225 | all_holes = NULL; |
|
|
2226 | |
|
|
2227 | // -- save relations for riverbanks -- |
|
|
2228 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_tag, str))) |
|
|
2229 | { |
|
|
2230 | if (!strcmp(str, "waterway=riverbank")) |
|
|
2231 | { |
|
|
2232 | // fprintf(stderr,"k:v=%s\n", str); |
|
|
2233 | save_relation = 1; |
|
|
2234 | save_relations_other_method = 0; |
|
|
2235 | tag_id = 1; |
|
|
2236 | } |
|
|
2237 | else if (!strcmp(str, "natural=water")) |
|
|
2238 | { |
|
|
2239 | save_relation = 1; |
|
|
2240 | save_relations_other_method = 0; |
|
|
2241 | tag_id = 2; |
|
|
2242 | } |
|
|
2243 | /* |
|
|
2244 | else if (!strcmp(str, "water=river")) |
|
|
2245 | { |
|
|
2246 | save_relation = 1; |
|
|
2247 | tag_id = 3; |
|
|
2248 | } |
|
|
2249 | */ |
|
|
2250 | else if (!strcmp(str, "natural=lake")) |
|
|
2251 | { |
|
|
2252 | save_relation = 1; |
|
|
2253 | save_relations_other_method = 0; |
|
|
2254 | tag_id = 4; |
|
|
2255 | } |
|
|
2256 | else if (!strcmp(str, "landuse=forest")) |
|
|
2257 | { |
|
|
2258 | save_relation = 1; |
|
|
2259 | save_relations_other_method = 1; |
|
|
2260 | tag_id = 5; |
|
|
2261 | } |
|
|
2262 | else if (!strcmp(str, "natural=wood")) |
|
|
2263 | { |
|
|
2264 | save_relation = 1; |
|
|
2265 | save_relations_other_method = 1; |
|
|
2266 | tag_id = 6; |
|
|
2267 | } |
|
|
2268 | else if (!strcmp(str, "building=yes")) |
|
|
2269 | { |
|
|
2270 | save_relation = 1; |
|
|
2271 | save_relations_other_method = 0; |
|
|
2272 | tag_id = 9; |
|
|
2273 | //fprintf(stderr,"k:v=%s id=%lld\n", str, current_id); |
|
|
2274 | } |
|
|
2275 | |
|
|
2276 | } |
|
|
2277 | |
|
|
2278 | if (save_relation == 1) |
|
|
2279 | { |
|
|
2280 | |
|
|
2281 | #ifdef MAPTOOL_TRIANGULATE |
|
|
2282 | |
|
|
2283 | if (save_relations_other_method == 0) |
|
|
2284 | { |
|
|
2285 | |
|
|
2286 | //fprintf(stderr, "START relation id=%lld tag=%d\n", current_id, tag_id); |
|
|
2287 | |
|
|
2288 | sqlite3_stmt *st; |
|
|
2289 | |
|
|
2290 | triangulate_not_done = 1; |
|
|
2291 | str = NULL; |
|
|
2292 | number_of_points_in_poly = 0; |
|
|
2293 | count_of_outer_ways = 0; |
|
|
2294 | //fprintf(stderr, "\n\n----------START---------\n"); |
|
|
2295 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
2296 | { |
|
|
2297 | if (get_relation_member(str, &memb)) |
|
|
2298 | { |
|
|
2299 | if (!strcmp(memb.role, "outer")) |
|
|
2300 | { |
|
|
2301 | if (memb.type == 2) |
|
|
2302 | { |
|
|
2303 | count_of_outer_ways++; |
|
|
2304 | } |
|
|
2305 | } |
|
|
2306 | } |
|
|
2307 | } |
|
|
2308 | //fprintf(stderr, "number of outer ways: %d\n", count_of_outer_ways); |
|
|
2309 | |
|
|
2310 | str = NULL; |
|
|
2311 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
2312 | { |
|
|
2313 | if (get_relation_member(str, &memb)) |
|
|
2314 | { |
|
|
2315 | role_=0; |
|
|
2316 | if (!strcmp(memb.role, "outer")) |
|
|
2317 | { |
|
|
2318 | role_=1; |
|
|
2319 | //fprintf(stderr, "1:role=%s id=%lld\n", memb.role, memb.id); |
|
|
2320 | } |
|
|
2321 | else if (!strcmp(memb.role, "inner")) |
|
|
2322 | { |
|
|
2323 | role_=2; |
|
|
2324 | //fprintf(stderr, "2:role=%s id=%lld\n", memb.role, memb.id); |
|
|
2325 | } |
|
|
2326 | |
|
|
2327 | if ((memb.type == 2) && ( (role_ == 1)||(role_ == 2) )) // use "outer" and "inner" ways |
|
|
2328 | |
|
|
2329 | { |
|
|
2330 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
|
|
2331 | way_nodes1->nodes = NULL; |
|
|
2332 | // get id for last and first nodes |
|
|
2333 | |
|
|
2334 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
2335 | if ((memb.id & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
|
|
2336 | { |
|
|
2337 | if ((memb.id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
2338 | { |
|
|
2339 | #endif |
|
|
2340 | st = stmt_sel001; |
|
|
2341 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
2342 | } |
|
|
2343 | else |
|
|
2344 | { |
|
|
2345 | st = stmt_sel001b; |
|
|
2346 | } |
|
|
2347 | } |
|
|
2348 | else |
|
|
2349 | { |
|
|
2350 | if ((memb.id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
2351 | { |
|
|
2352 | st = stmt_sel001__2; |
|
|
2353 | } |
|
|
2354 | else |
|
|
2355 | { |
|
|
2356 | st = stmt_sel001__2b; |
|
|
2357 | } |
|
|
2358 | } |
|
|
2359 | #endif |
|
|
2360 | sqlite3_bind_int64(st, 1, memb.id); |
|
|
2361 | |
|
|
2362 | first_node_found = 0; |
|
|
2363 | way_nodes1->first_node_id = 0; |
|
|
2364 | nd = 0; |
|
|
2365 | number_of_points_current_poly = 0; |
|
|
2366 | // execute the statement |
|
|
2367 | do |
|
|
2368 | { |
|
|
2369 | rc = sqlite3_step(st); |
|
|
2370 | // cols = sqlite3_column_count(st); |
|
|
2371 | switch (rc) |
|
|
2372 | { |
|
|
2373 | case SQLITE_DONE: |
|
|
2374 | break; |
|
|
2375 | case SQLITE_ROW: |
|
|
2376 | nd = sqlite3_column_int64(st, 0); |
|
|
2377 | number_of_points_current_poly++; |
|
|
2378 | //fprintf(stderr, "------ %s = %d\n", sqlite3_column_name(st, 0), nd ? nd : "NULL"); |
|
|
2379 | if (first_node_found == 0) |
|
|
2380 | { |
|
|
2381 | way_nodes1->first_node_id = nd; |
|
|
2382 | way_nodes1->role = role_; |
|
|
2383 | first_node_found = 1; |
|
|
2384 | //fprintf(stderr, "------ first node found\n"); |
|
|
2385 | } |
|
|
2386 | ndptr = malloc(sizeof(long long)); |
|
|
2387 | *ndptr = nd; |
|
|
2388 | way_nodes1->nodes = g_list_append(way_nodes1->nodes, ndptr); |
|
|
2389 | break; |
|
|
2390 | default: |
|
|
2391 | fprintf(stderr, "Error: %d\n", rc); |
|
|
2392 | break; |
|
|
2393 | } |
|
|
2394 | } |
|
|
2395 | while (rc == SQLITE_ROW); |
|
|
2396 | |
|
|
2397 | // dont count the last node of each way |
|
|
2398 | number_of_points_current_poly--; |
|
|
2399 | |
|
|
2400 | sqlite3_reset(st); |
|
|
2401 | |
|
|
2402 | way_nodes1->last_node_id = nd; |
|
|
2403 | way_nodes1->way_id = memb.id; |
|
|
2404 | |
|
|
2405 | if (way_nodes1->last_node_id == 0) |
|
|
2406 | { |
|
|
2407 | if (way_nodes1->nodes) |
|
|
2408 | { |
|
|
2409 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2410 | while (way_nodes1->nodes) |
|
|
2411 | { |
|
|
2412 | ndptr = way_nodes1->nodes->data; |
|
|
2413 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
2414 | g_free(ndptr); |
|
|
2415 | ndptr = NULL; |
|
|
2416 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
2417 | } |
|
|
2418 | } |
|
|
2419 | g_free(way_nodes1); |
|
|
2420 | } |
|
|
2421 | else if (way_nodes1->last_node_id == way_nodes1->first_node_id) |
|
|
2422 | { |
|
|
2423 | //fprintf(stderr, "ln id=%lld, fn id=%lld\n", way_nodes1->last_node_id, way_nodes1->first_node_id); |
|
|
2424 | |
|
|
2425 | if (way_nodes1->nodes) |
|
|
2426 | { |
|
|
2427 | if (role_ == 2) |
|
|
2428 | { |
|
|
2429 | //fprintf(stderr, "role=2\n"); |
|
|
2430 | unsorted_inner_ways = g_list_append(unsorted_inner_ways, way_nodes1); |
|
|
2431 | } |
|
|
2432 | else if (role_ == 1) |
|
|
2433 | { |
|
|
2434 | if (count_of_outer_ways == 1) |
|
|
2435 | { |
|
|
2436 | // we have only 1 outer way, it must be a closed loop. add it |
|
|
2437 | unsorted_outer_ways = g_list_append(unsorted_outer_ways, way_nodes1); |
|
|
2438 | number_of_points_in_poly = number_of_points_in_poly + number_of_points_current_poly; |
|
|
2439 | //fprintf(stderr, "w,sn,en %lld,%lld,%lld\n", way_nodes1->way_id, way_nodes1->first_node_id, way_nodes1->last_node_id); |
|
|
2440 | //fprintf(stderr, "num points=%d\n", number_of_points_current_poly); |
|
|
2441 | //fprintf(stderr, "SUM points=%d\n", number_of_points_in_poly); |
|
|
2442 | } |
|
|
2443 | else |
|
|
2444 | { |
|
|
2445 | // we have an outer way that is a loop (remove it) |
|
|
2446 | //fprintf(stderr, "remove node ... start\n"); |
|
|
2447 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2448 | while (way_nodes1->nodes) |
|
|
2449 | { |
|
|
2450 | //fprintf(stderr, "remove node\n"); |
|
|
2451 | ndptr = way_nodes1->nodes->data; |
|
|
2452 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
2453 | g_free(ndptr); |
|
|
2454 | ndptr = NULL; |
|
|
2455 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
2456 | } |
|
|
2457 | g_free(way_nodes1); |
|
|
2458 | //fprintf(stderr, "remove node ... ready\n"); |
|
|
2459 | } |
|
|
2460 | } |
|
|
2461 | } |
|
|
2462 | } |
|
|
2463 | else |
|
|
2464 | { |
|
|
2465 | if (role_ == 1) |
|
|
2466 | { |
|
|
2467 | unsorted_outer_ways = g_list_append(unsorted_outer_ways, way_nodes1); |
|
|
2468 | number_of_points_in_poly = number_of_points_in_poly + number_of_points_current_poly; |
|
|
2469 | } |
|
|
2470 | //fprintf(stderr, "w,sn,en %lld,%lld,%lld\n", way_nodes1->way_id, way_nodes1->first_node_id, way_nodes1->last_node_id); |
|
|
2471 | //fprintf(stderr, "num points=%d\n", number_of_points_current_poly); |
|
|
2472 | //fprintf(stderr, "SUM points=%d\n", number_of_points_in_poly); |
|
|
2473 | } |
|
|
2474 | } |
|
|
2475 | } |
|
|
2476 | } |
|
|
2477 | |
|
|
2478 | // now sort ways to have a linked polygon |
|
|
2479 | if (unsorted_outer_ways) |
|
|
2480 | { |
|
|
2481 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
2482 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
|
|
2483 | way_nodes2 = (struct way_and_endnodes *) unsorted_outer_ways->data; |
|
|
2484 | way_nodes1->way_id = way_nodes2->way_id; |
|
|
2485 | //fprintf(stderr, "(START)way id=%llu\n", way_nodes1->way_id); |
|
|
2486 | way_nodes1->last_node_id = way_nodes2->last_node_id; |
|
|
2487 | way_nodes1->first_node_id = way_nodes2->first_node_id; |
|
|
2488 | // only copy over the pointer to the node list!! |
|
|
2489 | way_nodes1->nodes = way_nodes2->nodes; |
|
|
2490 | // first node is always in the right order |
|
|
2491 | way_nodes1->reverse = 0; |
|
|
2492 | |
|
|
2493 | gptr = unsorted_outer_ways->data; |
|
|
2494 | sorted_outer_ways = g_list_append(sorted_outer_ways, way_nodes1); |
|
|
2495 | // save the very first node of the poly |
|
|
2496 | first_nd = way_nodes1->first_node_id; |
|
|
2497 | // what node we want to find |
|
|
2498 | search_nd = way_nodes1->last_node_id; |
|
|
2499 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, gptr); |
|
|
2500 | g_free(gptr); |
|
|
2501 | gptr = NULL; |
|
|
2502 | |
|
|
2503 | //fprintf(stderr,"remaining=%d sorted=%d\n", g_list_length(unsorted_outer_ways), g_list_length(sorted_outer_ways)); |
|
|
2504 | } |
|
|
2505 | |
|
|
2506 | if (unsorted_outer_ways) |
|
|
2507 | { |
|
|
2508 | |
|
|
2509 | problem = 0; |
|
|
2510 | //fprintf(stderr, "start length unsorted_outer_ways=%d\n", g_list_length(unsorted_outer_ways)); |
|
|
2511 | |
|
|
2512 | while ((g_list_length(unsorted_outer_ways) > 0) && (problem == 0)) |
|
|
2513 | { |
|
|
2514 | //fprintf(stderr, "loop thru remaining ways 1\n"); |
|
|
2515 | |
|
|
2516 | // loop thru all the remaining ways |
|
|
2517 | found_new_way = 0; |
|
|
2518 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
2519 | while (unsorted_outer_ways) |
|
|
2520 | { |
|
|
2521 | //fprintf(stderr, "loop thru remaining ways 2 search=%lld\n", search_nd); |
|
|
2522 | |
|
|
2523 | if (unsorted_outer_ways->data) |
|
|
2524 | { |
|
|
2525 | way_nodes2 = (struct way_and_endnodes *) unsorted_outer_ways->data; |
|
|
2526 | if (way_nodes2->first_node_id == search_nd) |
|
|
2527 | { |
|
|
2528 | |
|
|
2529 | if (way_nodes2->last_node_id == first_nd) |
|
|
2530 | { |
|
|
2531 | if (g_list_length(unsorted_outer_ways) > 1) |
|
|
2532 | { |
|
|
2533 | // we have close the poly, but there are still "ways" left |
|
|
2534 | // sounds broken |
|
|
2535 | problem = 1; |
|
|
2536 | break; |
|
|
2537 | } |
|
|
2538 | } |
|
|
2539 | |
|
|
2540 | // what node we want to find |
|
|
2541 | search_nd = way_nodes2->last_node_id; |
|
|
2542 | |
|
|
2543 | // now move the way from unsorted to sorted list |
|
|
2544 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
|
|
2545 | way_nodes1->way_id = way_nodes2->way_id; |
|
|
2546 | |
|
|
2547 | // ok next way found |
|
|
2548 | //fprintf(stderr, "(F)way id=%llu\n", way_nodes1->way_id); |
|
|
2549 | //fprintf(stderr, "now search id=%llu\n", search_nd); |
|
|
2550 | |
|
|
2551 | way_nodes1->last_node_id = way_nodes2->last_node_id; |
|
|
2552 | way_nodes1->first_node_id = way_nodes2->first_node_id; |
|
|
2553 | // only copy over the pointer to the node list!! |
|
|
2554 | way_nodes1->nodes = way_nodes2->nodes; |
|
|
2555 | // first node is always in the right order |
|
|
2556 | way_nodes1->reverse = 0; |
|
|
2557 | sorted_outer_ways = g_list_append(sorted_outer_ways, way_nodes1); |
|
|
2558 | if (unsorted_outer_ways) |
|
|
2559 | { |
|
|
2560 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
2561 | } |
|
|
2562 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, way_nodes2); |
|
|
2563 | g_free(way_nodes2); |
|
|
2564 | way_nodes2 = NULL; |
|
|
2565 | |
|
|
2566 | found_new_way = 1; |
|
|
2567 | //fprintf(stderr, "length unsorted_outer_ways=%d\n", g_list_length(unsorted_outer_ways)); |
|
|
2568 | break; |
|
|
2569 | } |
|
|
2570 | else if (way_nodes2->last_node_id == search_nd) |
|
|
2571 | { |
|
|
2572 | if (way_nodes2->first_node_id == first_nd) |
|
|
2573 | { |
|
|
2574 | if (g_list_length(unsorted_outer_ways) > 1) |
|
|
2575 | { |
|
|
2576 | // we have closed the poly, but there are still "ways" left |
|
|
2577 | // sounds broken |
|
|
2578 | problem = 1; |
|
|
2579 | break; |
|
|
2580 | } |
|
|
2581 | } |
|
|
2582 | |
|
|
2583 | // what node we want to find |
|
|
2584 | search_nd = way_nodes2->first_node_id; |
|
|
2585 | |
|
|
2586 | // now move the way from unsorted to sorted list |
|
|
2587 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
|
|
2588 | way_nodes1->way_id = way_nodes2->way_id; |
|
|
2589 | |
|
|
2590 | // ok next way found |
|
|
2591 | //fprintf(stderr, "(R)way id=%llu\n", way_nodes1->way_id); |
|
|
2592 | //fprintf(stderr, "now search id=%llu\n", search_nd); |
|
|
2593 | |
|
|
2594 | way_nodes1->first_node_id = way_nodes2->last_node_id; |
|
|
2595 | way_nodes1->last_node_id = way_nodes2->first_node_id; |
|
|
2596 | // only copy over the pointer to the node list!! |
|
|
2597 | way_nodes1->nodes = way_nodes2->nodes; |
|
|
2598 | way_nodes1->nodes = g_list_reverse(way_nodes1->nodes); |
|
|
2599 | // first node is always in the right order |
|
|
2600 | way_nodes1->reverse = 1; |
|
|
2601 | sorted_outer_ways = g_list_append(sorted_outer_ways, way_nodes1); |
|
|
2602 | if (unsorted_outer_ways) |
|
|
2603 | { |
|
|
2604 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
2605 | } |
|
|
2606 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, way_nodes2); |
|
|
2607 | g_free(way_nodes2); |
|
|
2608 | way_nodes2 = NULL; |
|
|
2609 | |
|
|
2610 | found_new_way = 1; |
|
|
2611 | //fprintf(stderr, "length unsorted_outer_ways=%d\n", g_list_length(unsorted_outer_ways)); |
|
|
2612 | break; |
|
|
2613 | } |
|
|
2614 | } |
|
|
2615 | unsorted_outer_ways = g_list_next(unsorted_outer_ways); |
|
|
2616 | } |
|
|
2617 | //fprintf(stderr, "after while loop 2\n"); |
|
|
2618 | |
|
|
2619 | if (found_new_way == 0) |
|
|
2620 | { |
|
|
2621 | // some problem with this multipolygon |
|
|
2622 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2623 | fprintf(stderr, "some problem with this multipolygon\n"); |
|
|
2624 | triangulate_not_done = 1; |
|
|
2625 | problem = 1; |
|
|
2626 | break; |
|
|
2627 | } |
|
|
2628 | } |
|
|
2629 | //fprintf(stderr, "after while loop 1\n"); |
|
|
2630 | |
|
|
2631 | } |
|
|
2632 | |
|
|
2633 | // now at last check if very first node matches the last found node |
|
|
2634 | // and less than xxx 1000 points in polygon |
|
|
2635 | // if ((search_nd == first_nd) && (number_of_points_in_poly > 2) && (number_of_points_in_poly < 1000)) |
|
|
2636 | if ((problem == 0) && ((search_nd == first_nd) && (number_of_points_in_poly > 2) && (number_of_points_in_poly < 30000))) |
|
|
2637 | { |
|
|
2638 | |
|
|
2639 | //fprintf(stderr, "in relation id=%lld\n", current_id); |
|
|
2640 | |
|
|
2641 | point_map = g_hash_table_new(g_direct_hash, g_direct_equal); |
|
|
2642 | current_points = g_ptr_array_new(); |
|
|
2643 | |
|
|
2644 | number_of_points_in_poly = 0; |
|
|
2645 | |
|
|
2646 | sorted_outer_ways = g_list_first(sorted_outer_ways); |
|
|
2647 | while (sorted_outer_ways) |
|
|
2648 | { |
|
|
2649 | if (sorted_outer_ways->data) |
|
|
2650 | { |
|
|
2651 | way_nodes1 = (struct way_and_endnodes *) sorted_outer_ways->data; |
|
|
2652 | // now read all the nodes of this way |
|
|
2653 | //**alread in GList** //sqlite3_bind_int64(stmt_sel001, 1, way_nodes1->way_id); |
|
|
2654 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2655 | first_node_found = 0; |
|
|
2656 | while (way_nodes1->nodes) |
|
|
2657 | { |
|
|
2658 | ndptr = (long long *) way_nodes1->nodes->data; |
|
|
2659 | nd = *ndptr; |
|
|
2660 | |
|
|
2661 | get_lat_lon_for_node(nd, &node_coords); |
|
|
2662 | if (node_coords.valid == 1) |
|
|
2663 | { |
|
|
2664 | // lat |
|
|
2665 | lat_nd = node_coords.lat; |
|
|
2666 | // lon |
|
|
2667 | lon_nd = node_coords.lon; |
|
|
2668 | |
|
|
2669 | if (first_node_found == 0) |
|
|
2670 | { |
|
|
2671 | first_node_found = 1; |
|
|
2672 | } |
|
|
2673 | else |
|
|
2674 | { |
|
|
2675 | y = lat_nd * factor; |
|
|
2676 | x = lon_nd * factor; |
|
|
2677 | |
|
|
2678 | // ------ ok use this node and coords for triangulation ---- |
|
|
2679 | //fprintf(stderr, "nd,lat,lon %lld,%f,%f\n", nd,lat_nd,lon_nd); |
|
|
2680 | //fprintf(stderr, "x,y %f,%f\n", x, y); |
|
|
2681 | |
|
|
2682 | g_ptr_array_add(current_points, p2t_point_new_dd(x, y)); |
|
|
2683 | } |
|
|
2684 | } |
|
|
2685 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
2686 | } |
|
|
2687 | } |
|
|
2688 | //sqlite3_reset(st); |
|
|
2689 | |
|
|
2690 | sorted_outer_ways = g_list_next(sorted_outer_ways); |
|
|
2691 | } |
|
|
2692 | |
|
|
2693 | //fprintf(stderr, "after sorting ways\n"); |
|
|
2694 | |
|
|
2695 | |
|
|
2696 | exception = 0; |
|
|
2697 | |
|
|
2698 | TRY |
|
|
2699 | { |
|
|
2700 | // catch SIGSEGV !! |
|
|
2701 | signal(SIGSEGV, catch_signal); |
|
|
2702 | |
|
|
2703 | // alternate signal stack ------------ |
|
|
2704 | //ss.ss_size = SIGSTKSZ; |
|
|
2705 | //ss.ss_sp = stack; |
|
|
2706 | //sa.sa_handler = catch_signal; |
|
|
2707 | //sa.sa_flags = SA_ONSTACK; |
|
|
2708 | //sigfillset(&sa.sa_mask); |
|
|
2709 | |
|
|
2710 | //sigaltstack(&ss, 0); |
|
|
2711 | //sigfillset(&sa.sa_mask); |
|
|
2712 | //sigaction(SIGSEGV, &sa, 0); |
|
|
2713 | // alternate signal stack ------------ |
|
|
2714 | |
|
|
2715 | // catch SIGSEGV !! |
|
|
2716 | |
|
|
2717 | //fprintf(stderr, "In Try Statement (p2t_cdt_new)\n"); |
|
|
2718 | cdt = p2t_cdt_new(current_points); |
|
|
2719 | //fprintf(stderr, "all OK (p2t_cdt_new)\n"); |
|
|
2720 | } |
|
|
2721 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
2722 | { |
|
|
2723 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2724 | fprintf(stderr, "Got Exception 1!\n"); |
|
|
2725 | exception = 1; |
|
|
2726 | } |
|
|
2727 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
2728 | { |
|
|
2729 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2730 | fprintf(stderr, "Got segv Exception 1!\n"); |
|
|
2731 | exception = 1; |
|
|
2732 | } |
|
|
2733 | FINALLY |
|
|
2734 | { |
|
|
2735 | // set default |
|
|
2736 | signal (SIGSEGV, SIG_DFL); |
|
|
2737 | // set default |
|
|
2738 | |
|
|
2739 | //fprintf(stderr, "finally\n"); |
|
|
2740 | } |
|
|
2741 | ETRY; |
|
|
2742 | |
|
|
2743 | //fprintf(stderr, "after cdt_new\n"); |
|
|
2744 | |
|
|
2745 | GList* save = unsorted_inner_ways; |
|
|
2746 | |
|
|
2747 | int no_holes = 0; |
|
|
2748 | if (exception == 0) |
|
|
2749 | { |
|
|
2750 | |
|
|
2751 | // first run a check loop |
|
|
2752 | int number_of_nodes_in_this_way; |
|
|
2753 | int cur_node_count_in_way; |
|
|
2754 | unsorted_inner_ways = g_list_first(unsorted_inner_ways); |
|
|
2755 | |
|
|
2756 | int number_of_nodes_in_this_way3 = g_list_length(unsorted_inner_ways); |
|
|
2757 | //fprintf(stderr, "uiw 001.0 c=%d\n", number_of_nodes_in_this_way3); |
|
|
2758 | while (unsorted_inner_ways) |
|
|
2759 | { |
|
|
2760 | if ((unsorted_inner_ways->data)&&(no_holes == 0)) |
|
|
2761 | { |
|
|
2762 | way_nodes1 = (struct way_and_endnodes *) unsorted_inner_ways->data; |
|
|
2763 | number_of_nodes_in_this_way = g_list_length(way_nodes1->nodes); |
|
|
2764 | // now read all the nodes of this "hole"-way |
|
|
2765 | GList* save0 = way_nodes1->nodes; |
|
|
2766 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2767 | first_node_found = 0; |
|
|
2768 | cur_node_count_in_way = 1; |
|
|
2769 | while (way_nodes1->nodes) |
|
|
2770 | { |
|
|
2771 | ndptr = (long long *) way_nodes1->nodes->data; |
|
|
2772 | // fprintf(stderr, "hole node:%lld\n", (long long)*ndptr); |
|
|
2773 | |
|
|
2774 | if (temp_nodes_list != NULL) |
|
|
2775 | { |
|
|
2776 | //fprintf(stderr, "cur_node_count_in_way %d number_of_nodes_in_this_way %d\n", cur_node_count_in_way, number_of_nodes_in_this_way); |
|
|
2777 | // the last node should always be same as first node (for now we only support holes that dont span over multiple ways!) |
|
|
2778 | if (cur_node_count_in_way < number_of_nodes_in_this_way) |
|
|
2779 | { |
|
|
2780 | if (glist_find_already_inside(temp_nodes_list, ndptr) != 0) |
|
|
2781 | { |
|
|
2782 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2783 | fprintf(stderr, "problem with hole!\n"); |
|
|
2784 | no_holes = 1; |
|
|
2785 | break; |
|
|
2786 | } |
|
|
2787 | else |
|
|
2788 | { |
|
|
2789 | //fprintf(stderr, "hole check ok\n"); |
|
|
2790 | } |
|
|
2791 | } |
|
|
2792 | } |
|
|
2793 | |
|
|
2794 | temp_nodes_list = g_list_append(temp_nodes_list, ndptr); |
|
|
2795 | |
|
|
2796 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
2797 | cur_node_count_in_way++; |
|
|
2798 | } |
|
|
2799 | way_nodes1->nodes = save0; |
|
|
2800 | } |
|
|
2801 | unsorted_inner_ways = g_list_next(unsorted_inner_ways); |
|
|
2802 | } |
|
|
2803 | |
|
|
2804 | } |
|
|
2805 | |
|
|
2806 | unsorted_inner_ways = save; |
|
|
2807 | |
|
|
2808 | //fprintf(stderr, "ex=%d nohole=%d\n", exception, no_holes); |
|
|
2809 | |
|
|
2810 | |
|
|
2811 | |
|
|
2812 | if ((exception == 0) && (no_holes == 0)) |
|
|
2813 | { |
|
|
2814 | //fprintf(stderr, "uiw 000\n"); |
|
|
2815 | |
|
|
2816 | // now do the real loop |
|
|
2817 | int number_of_added_holes = 0; |
|
|
2818 | |
|
|
2819 | unsorted_inner_ways = g_list_first(unsorted_inner_ways); |
|
|
2820 | //int number_of_nodes_in_this_way4 = g_list_length(unsorted_inner_ways); |
|
|
2821 | //fprintf(stderr, "uiw 001.2 c=%d\n", number_of_nodes_in_this_way4); |
|
|
2822 | while (unsorted_inner_ways) |
|
|
2823 | { |
|
|
2824 | //fprintf(stderr, "uiw 001\n"); |
|
|
2825 | |
|
|
2826 | if (unsorted_inner_ways->data) |
|
|
2827 | { |
|
|
2828 | //fprintf(stderr, "uiw 002\n"); |
|
|
2829 | |
|
|
2830 | current_hole = g_ptr_array_new(); |
|
|
2831 | |
|
|
2832 | //fprintf(stderr, "uiw 003\n"); |
|
|
2833 | |
|
|
2834 | way_nodes1 = (struct way_and_endnodes *) unsorted_inner_ways->data; |
|
|
2835 | // now read all the nodes of this "hole"-way |
|
|
2836 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2837 | first_node_found = 0; |
|
|
2838 | while (way_nodes1->nodes) |
|
|
2839 | { |
|
|
2840 | //fprintf(stderr, "uiw 004\n"); |
|
|
2841 | |
|
|
2842 | ndptr = (long long *) way_nodes1->nodes->data; |
|
|
2843 | nd = *ndptr; |
|
|
2844 | |
|
|
2845 | // now read the coords of this node |
|
|
2846 | |
|
|
2847 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2848 | if (nd % 2) |
|
|
2849 | { |
|
|
2850 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2851 | { |
|
|
2852 | sqlite3_bind_int64(stmt_sel002__2a, 1, nd); |
|
|
2853 | } |
|
|
2854 | else |
|
|
2855 | { |
|
|
2856 | sqlite3_bind_int64(stmt_sel002__2b, 1, nd); |
|
|
2857 | } |
|
|
2858 | } |
|
|
2859 | else |
|
|
2860 | { |
|
|
2861 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2862 | { |
|
|
2863 | #endif |
|
|
2864 | sqlite3_bind_int64(stmt_sel002a, 1, nd); |
|
|
2865 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2866 | } |
|
|
2867 | else |
|
|
2868 | { |
|
|
2869 | sqlite3_bind_int64(stmt_sel002b, 1, nd); |
|
|
2870 | } |
|
|
2871 | } |
|
|
2872 | #endif |
|
|
2873 | rc2 = 0; |
|
|
2874 | do |
|
|
2875 | { |
|
|
2876 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2877 | if (nd % 2) |
|
|
2878 | { |
|
|
2879 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2880 | { |
|
|
2881 | rc2 = sqlite3_step(stmt_sel002__2a); |
|
|
2882 | } |
|
|
2883 | else |
|
|
2884 | { |
|
|
2885 | rc2 = sqlite3_step(stmt_sel002__2b); |
|
|
2886 | } |
|
|
2887 | } |
|
|
2888 | else |
|
|
2889 | { |
|
|
2890 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2891 | { |
|
|
2892 | #endif |
|
|
2893 | rc2 = sqlite3_step(stmt_sel002a); |
|
|
2894 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2895 | } |
|
|
2896 | else |
|
|
2897 | { |
|
|
2898 | rc2 = sqlite3_step(stmt_sel002b); |
|
|
2899 | } |
|
|
2900 | } |
|
|
2901 | #endif |
|
|
2902 | |
|
|
2903 | switch (rc2) |
|
|
2904 | { |
|
|
2905 | case SQLITE_DONE: |
|
|
2906 | break; |
|
|
2907 | case SQLITE_ROW: |
|
|
2908 | |
|
|
2909 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2910 | if (nd % 2) |
|
|
2911 | { |
|
|
2912 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2913 | { |
|
|
2914 | lat_nd = (double) sqlite3_column_double(stmt_sel002__2a, 0); |
|
|
2915 | lon_nd = (double) sqlite3_column_double(stmt_sel002__2a, 1); |
|
|
2916 | } |
|
|
2917 | else |
|
|
2918 | { |
|
|
2919 | lat_nd = (double) sqlite3_column_double(stmt_sel002__2b, 0); |
|
|
2920 | lon_nd = (double) sqlite3_column_double(stmt_sel002__2b, 1); |
|
|
2921 | } |
|
|
2922 | } |
|
|
2923 | else |
|
|
2924 | { |
|
|
2925 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2926 | { |
|
|
2927 | #endif |
|
|
2928 | lat_nd = (double) sqlite3_column_double(stmt_sel002a, 0); |
|
|
2929 | lon_nd = (double) sqlite3_column_double(stmt_sel002a, 1); |
|
|
2930 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2931 | } |
|
|
2932 | else |
|
|
2933 | { |
|
|
2934 | lat_nd = (double) sqlite3_column_double(stmt_sel002b, 0); |
|
|
2935 | lon_nd = (double) sqlite3_column_double(stmt_sel002b, 1); |
|
|
2936 | } |
|
|
2937 | } |
|
|
2938 | #endif |
|
|
2939 | |
|
|
2940 | if (first_node_found == 0) |
|
|
2941 | { |
|
|
2942 | first_node_found = 1; |
|
|
2943 | } |
|
|
2944 | else |
|
|
2945 | { |
|
|
2946 | // ------ ok use this node and coords for triangulation ---- |
|
|
2947 | //fprintf(stderr, "HOLE:nd,lat,lon %lld,%f,%f\n", nd,lat_nd,lon_nd); |
|
|
2948 | |
|
|
2949 | //fprintf(stderr, "np=%d\n", number_of_points_in_poly); |
|
|
2950 | //in.pointlist[number_of_points_in_poly] = (REAL) (lat_nd*10); |
|
|
2951 | //number_of_points_in_poly++; |
|
|
2952 | //fprintf(stderr, "np=%d\n", number_of_points_in_poly); |
|
|
2953 | //in.pointlist[number_of_points_in_poly] = (REAL) (lon_nd*10); |
|
|
2954 | //number_of_points_in_poly++; |
|
|
2955 | #if 1 |
|
|
2956 | y = lat_nd * factor; |
|
|
2957 | x = lon_nd * factor; |
|
|
2958 | |
|
|
2959 | TRY |
|
|
2960 | { |
|
|
2961 | signal(SIGSEGV, catch_signal); |
|
|
2962 | |
|
|
2963 | // hole complete, now add it |
|
|
2964 | //fprintf(stderr, "hole new\n"); |
|
|
2965 | g_ptr_array_add(current_hole, p2t_point_new_dd(x, y)); |
|
|
2966 | //fprintf(stderr, "hole new done\n"); |
|
|
2967 | } |
|
|
2968 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
2969 | { |
|
|
2970 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2971 | fprintf(stderr, "Got Exception A!\n"); |
|
|
2972 | exception = 1; |
|
|
2973 | } |
|
|
2974 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
2975 | { |
|
|
2976 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2977 | fprintf(stderr, "Got segv Exception A!\n"); |
|
|
2978 | exception = 1; |
|
|
2979 | } |
|
|
2980 | FINALLY |
|
|
2981 | { |
|
|
2982 | // set default |
|
|
2983 | signal (SIGSEGV, SIG_DFL); |
|
|
2984 | // set default |
|
|
2985 | |
|
|
2986 | //fprintf(stderr, "finally\n"); |
|
|
2987 | } |
|
|
2988 | ETRY; |
|
|
2989 | |
|
|
2990 | #endif |
|
|
2991 | } |
|
|
2992 | break; |
|
|
2993 | default: |
|
|
2994 | fprintf(stderr, "Error: %d\n", rc2); |
|
|
2995 | break; |
|
|
2996 | } |
|
|
2997 | } |
|
|
2998 | while (rc2 == SQLITE_ROW); |
|
|
2999 | |
|
|
3000 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
3001 | if (nd % 2) |
|
|
3002 | { |
|
|
3003 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
3004 | { |
|
|
3005 | sqlite3_reset(stmt_sel002__2a); |
|
|
3006 | } |
|
|
3007 | else |
|
|
3008 | { |
|
|
3009 | sqlite3_reset(stmt_sel002__2b); |
|
|
3010 | } |
|
|
3011 | } |
|
|
3012 | else |
|
|
3013 | { |
|
|
3014 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
3015 | { |
|
|
3016 | #endif |
|
|
3017 | sqlite3_reset(stmt_sel002a); |
|
|
3018 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
3019 | } |
|
|
3020 | else |
|
|
3021 | { |
|
|
3022 | sqlite3_reset(stmt_sel002b); |
|
|
3023 | } |
|
|
3024 | } |
|
|
3025 | #endif |
|
|
3026 | |
|
|
3027 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
3028 | } |
|
|
3029 | |
|
|
3030 | //fprintf(stderr, "uiw 005\n"); |
|
|
3031 | |
|
|
3032 | // remember the pointer, to free the memory later |
|
|
3033 | all_holes = g_list_append(all_holes, current_hole); |
|
|
3034 | |
|
|
3035 | //fprintf(stderr, "uiw 005.1\n"); |
|
|
3036 | |
|
|
3037 | TRY |
|
|
3038 | { |
|
|
3039 | signal(SIGSEGV, catch_signal); |
|
|
3040 | |
|
|
3041 | // hole complete, now add it |
|
|
3042 | //fprintf(stderr, "adding hole\n"); |
|
|
3043 | if (number_of_added_holes < MAX_HOLES_PER_POLY) |
|
|
3044 | { |
|
|
3045 | p2t_cdt_add_hole(cdt, current_hole); |
|
|
3046 | number_of_added_holes++; |
|
|
3047 | } |
|
|
3048 | //fprintf(stderr, "adding done\n"); |
|
|
3049 | } |
|
|
3050 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3051 | { |
|
|
3052 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3053 | fprintf(stderr, "Got Exception 8!\n"); |
|
|
3054 | exception = 1; |
|
|
3055 | } |
|
|
3056 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3057 | { |
|
|
3058 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3059 | fprintf(stderr, "Got segv Exception 8!\n"); |
|
|
3060 | exception = 1; |
|
|
3061 | } |
|
|
3062 | FINALLY |
|
|
3063 | { |
|
|
3064 | // set default |
|
|
3065 | signal (SIGSEGV, SIG_DFL); |
|
|
3066 | // set default |
|
|
3067 | |
|
|
3068 | //fprintf(stderr, "finally\n"); |
|
|
3069 | } |
|
|
3070 | ETRY; |
|
|
3071 | |
|
|
3072 | } |
|
|
3073 | |
|
|
3074 | //fprintf(stderr, "uiw 006\n"); |
|
|
3075 | unsorted_inner_ways = g_list_next(unsorted_inner_ways); |
|
|
3076 | |
|
|
3077 | } |
|
|
3078 | //sqlite3_reset(st); |
|
|
3079 | |
|
|
3080 | //fprintf(stderr, "uiw 007\n"); |
|
|
3081 | } |
|
|
3082 | |
|
|
3083 | //fprintf(stderr, "after adding holes\n"); |
|
|
3084 | |
|
|
3085 | #if 1 |
|
|
3086 | |
|
|
3087 | if (exception == 0) |
|
|
3088 | { |
|
|
3089 | exception = 0; |
|
|
3090 | |
|
|
3091 | TRY |
|
|
3092 | { |
|
|
3093 | // catch SIGSEGV !! |
|
|
3094 | signal(SIGSEGV, catch_signal); |
|
|
3095 | //signal(SIGILL, catch_signal); |
|
|
3096 | |
|
|
3097 | // alternate signal stack ------------ |
|
|
3098 | //ss.ss_size = SIGSTKSZ; |
|
|
3099 | //ss.ss_sp = stack; |
|
|
3100 | //sa.sa_handler = catch_signal; |
|
|
3101 | //sa.sa_flags = SA_ONSTACK; |
|
|
3102 | //sigfillset(&sa.sa_mask); |
|
|
3103 | |
|
|
3104 | //sigaltstack(&ss, 0); |
|
|
3105 | //sigfillset(&sa.sa_mask); |
|
|
3106 | //sigaction(SIGSEGV, &sa, 0); |
|
|
3107 | // alternate signal stack ------------ |
|
|
3108 | |
|
|
3109 | // catch SIGSEGV !! |
|
|
3110 | |
|
|
3111 | //fprintf(stderr, "triangulate start ...\n"); |
|
|
3112 | p2t_cdt_triangulate(cdt); |
|
|
3113 | //fprintf(stderr, "triangulate end\n"); |
|
|
3114 | } |
|
|
3115 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3116 | { |
|
|
3117 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3118 | fprintf(stderr, "Got Exception 2! (in triangulate)\n"); |
|
|
3119 | exception = 1; |
|
|
3120 | } |
|
|
3121 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3122 | { |
|
|
3123 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3124 | fprintf(stderr, "Got segv Exception 2! (in triangulate)\n"); |
|
|
3125 | exception = 1; |
|
|
3126 | } |
|
|
3127 | FINALLY |
|
|
3128 | { |
|
|
3129 | //fprintf(stderr, "finally 2 (in triangulate)\n"); |
|
|
3130 | |
|
|
3131 | //sa.sa_handler = SIG_DFL; |
|
|
3132 | // sigfillset(&sa.sa_mask); |
|
|
3133 | //sigaction(SIGSEGV, &sa, 0); |
|
|
3134 | |
|
|
3135 | // set default |
|
|
3136 | signal (SIGSEGV, SIG_DFL); |
|
|
3137 | // set default |
|
|
3138 | } |
|
|
3139 | ETRY; |
|
|
3140 | |
|
|
3141 | if (exception == 0) |
|
|
3142 | { |
|
|
3143 | rmesh = g_slice_new (P2trCDT); |
|
|
3144 | rmesh->mesh = p2tr_mesh_new (); |
|
|
3145 | // rmesh->outline = p2tr_pslg_new (); |
|
|
3146 | |
|
|
3147 | /* First iteration over the CDT - create all the points */ |
|
|
3148 | //fprintf(stderr, "trinew 006\n"); |
|
|
3149 | triangles = p2t_cdt_get_triangles(cdt); |
|
|
3150 | //fprintf(stderr, "trinew 007\n"); |
|
|
3151 | for (i = 0; i < triangles->len; i++) |
|
|
3152 | { |
|
|
3153 | P2tTriangle *cdt_tri = triangle_index (triangles, i); |
|
|
3154 | for (j = 0; j < 3; j++) |
|
|
3155 | { |
|
|
3156 | P2tPoint *cdt_pt = p2t_triangle_get_point(cdt_tri, j); |
|
|
3157 | P2trPoint *new_pt = (P2trPoint*) g_hash_table_lookup (point_map, cdt_pt); |
|
|
3158 | |
|
|
3159 | if (new_pt == NULL) |
|
|
3160 | { |
|
|
3161 | //fprintf(stderr, "p1 x=%d, y=%d\n",(int)cdt_pt->x, (int)cdt_pt->y); |
|
|
3162 | new_pt = p2tr_mesh_new_point2 (rmesh->mesh, (cdt_pt->x / factor), (cdt_pt->y / factor)); |
|
|
3163 | g_hash_table_insert (point_map, cdt_pt, new_pt); |
|
|
3164 | } |
|
|
3165 | } |
|
|
3166 | } |
|
|
3167 | |
|
|
3168 | for (i = 0; i < triangles->len; i++) |
|
|
3169 | { |
|
|
3170 | P2tTriangle *cdt_tri = triangle_index(triangles, i); |
|
|
3171 | //fprintf(stderr, "tri# %d\n", i); |
|
|
3172 | gboolean ii = p2t_triangle_is_interior(cdt_tri); |
|
|
3173 | //fprintf(stderr, "is int=%d\n", ii); |
|
|
3174 | |
|
|
3175 | P2trPoint *pt1 = (P2trPoint*) g_hash_table_lookup (point_map, p2t_triangle_get_point (cdt_tri, 0)); |
|
|
3176 | P2trPoint *pt2 = (P2trPoint*) g_hash_table_lookup (point_map, p2t_triangle_get_point (cdt_tri, 1)); |
|
|
3177 | P2trPoint *pt3 = (P2trPoint*) g_hash_table_lookup (point_map, p2t_triangle_get_point (cdt_tri, 2)); |
|
|
3178 | |
|
|
3179 | //fprintf(stderr, "0 x=%f, y=%f\n",pt1->c.x, pt1->c.y); |
|
|
3180 | //fprintf(stderr, "1 x=%f, y=%f\n",pt2->c.x, pt2->c.y); |
|
|
3181 | //fprintf(stderr, "2 x=%f, y=%f\n",pt3->c.x, pt3->c.y); |
|
|
3182 | |
|
|
3183 | // make item and write it to ways file ------------------- |
|
|
3184 | // make item and write it to ways file ------------------- |
|
|
3185 | if (tag_id == 1) |
|
|
3186 | { |
|
|
3187 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
|
|
3188 | //fprintf(stderr, "T:water\n"); |
|
|
3189 | } |
|
|
3190 | else if (tag_id == 2) |
|
|
3191 | { |
|
|
3192 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
|
|
3193 | //fprintf(stderr, "T:water\n"); |
|
|
3194 | } |
|
|
3195 | else if (tag_id == 4) |
|
|
3196 | { |
|
|
3197 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
|
|
3198 | //fprintf(stderr, "T:water\n"); |
|
|
3199 | } |
|
|
3200 | else if (tag_id == 5) |
|
|
3201 | { |
|
|
3202 | item_bin_tri = init_item(type_poly_wood_from_triang, 0); |
|
|
3203 | //fprintf(stderr, "T:forest\n"); |
|
|
3204 | } |
|
|
3205 | else if (tag_id == 6) |
|
|
3206 | { |
|
|
3207 | item_bin_tri = init_item(type_poly_wood_from_triang, 0); |
|
|
3208 | //fprintf(stderr, "T:forest\n"); |
|
|
3209 | } |
|
|
3210 | else if (tag_id == 9) |
|
|
3211 | { |
|
|
3212 | item_bin_tri = init_item(type_poly_building_from_triang, 0); |
|
|
3213 | //fprintf(stderr, "T:building\n"); |
|
|
3214 | } |
|
|
3215 | else |
|
|
3216 | { |
|
|
3217 | // default |
|
|
3218 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
|
|
3219 | //fprintf(stderr, "T:water\n"); |
|
|
3220 | } |
|
|
3221 | |
|
|
3222 | // add dummy osm wayid |
|
|
3223 | item_bin_add_attr_longlong(item_bin_tri, attr_osm_wayid, current_id); |
|
|
3224 | coord_tri.x = transform_from_geo_lon(pt1->c.x); |
|
|
3225 | coord_tri.y = transform_from_geo_lat(pt1->c.y); |
|
|
3226 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
|
|
3227 | coord_tri.x = transform_from_geo_lon(pt2->c.x); |
|
|
3228 | coord_tri.y = transform_from_geo_lat(pt2->c.y); |
|
|
3229 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
|
|
3230 | coord_tri.x = transform_from_geo_lon(pt3->c.x); |
|
|
3231 | coord_tri.y = transform_from_geo_lat(pt3->c.y); |
|
|
3232 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
|
|
3233 | |
|
|
3234 | item_bin_write(item_bin_tri, osm->ways_with_coords); |
|
|
3235 | // make item and write it to ways file ------------------- |
|
|
3236 | // make item and write it to ways file ------------------- |
|
|
3237 | |
|
|
3238 | } |
|
|
3239 | |
|
|
3240 | //fprintf(stderr, "trinew 091\n"); |
|
|
3241 | |
|
|
3242 | } |
|
|
3243 | |
|
|
3244 | //fprintf(stderr, "trinew 092.0\n"); |
|
|
3245 | |
|
|
3246 | |
|
|
3247 | TRY |
|
|
3248 | { |
|
|
3249 | signal(SIGSEGV, catch_signal); |
|
|
3250 | |
|
|
3251 | /* Now finally unref the points we added into the map */ |
|
|
3252 | if (point_map != NULL) |
|
|
3253 | { |
|
|
3254 | GHashTableIter iter; |
|
|
3255 | P2trPoint *pt_iter = NULL; |
|
|
3256 | g_hash_table_iter_init (&iter, point_map); |
|
|
3257 | while (g_hash_table_iter_next (&iter, NULL, (gpointer*)&pt_iter)) |
|
|
3258 | { |
|
|
3259 | p2tr_point_unref(pt_iter); |
|
|
3260 | } |
|
|
3261 | g_hash_table_destroy(point_map); |
|
|
3262 | } |
|
|
3263 | } |
|
|
3264 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3265 | { |
|
|
3266 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3267 | fprintf(stderr, "Got Exception 3!\n"); |
|
|
3268 | exception = 1; |
|
|
3269 | } |
|
|
3270 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3271 | { |
|
|
3272 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3273 | fprintf(stderr, "Got segv Exception 3!\n"); |
|
|
3274 | exception = 1; |
|
|
3275 | } |
|
|
3276 | FINALLY |
|
|
3277 | { |
|
|
3278 | signal (SIGSEGV, SIG_DFL); |
|
|
3279 | } |
|
|
3280 | ETRY; |
|
|
3281 | |
|
|
3282 | //fprintf(stderr, "trinew 092.1\n"); |
|
|
3283 | |
|
|
3284 | |
|
|
3285 | TRY |
|
|
3286 | { |
|
|
3287 | signal(SIGSEGV, catch_signal); |
|
|
3288 | // p2tr_mesh_clear(rmesh->mesh); |
|
|
3289 | // --- maybe need this?? --- p2tr_mesh_unref(rmesh->mesh); |
|
|
3290 | } |
|
|
3291 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3292 | { |
|
|
3293 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3294 | fprintf(stderr, "Got Exception 4!\n"); |
|
|
3295 | exception = 1; |
|
|
3296 | } |
|
|
3297 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3298 | { |
|
|
3299 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3300 | fprintf(stderr, "Got segv Exception 4!\n"); |
|
|
3301 | exception = 1; |
|
|
3302 | } |
|
|
3303 | FINALLY |
|
|
3304 | { |
|
|
3305 | signal (SIGSEGV, SIG_DFL); |
|
|
3306 | } |
|
|
3307 | ETRY; |
|
|
3308 | |
|
|
3309 | //fprintf(stderr, "trinew 092.2\n"); |
|
|
3310 | |
|
|
3311 | TRY |
|
|
3312 | { |
|
|
3313 | signal(SIGSEGV, catch_signal); |
|
|
3314 | p2t_cdt_free(cdt); |
|
|
3315 | } |
|
|
3316 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3317 | { |
|
|
3318 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3319 | fprintf(stderr, "Got Exception 5!\n"); |
|
|
3320 | exception = 1; |
|
|
3321 | } |
|
|
3322 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3323 | { |
|
|
3324 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3325 | fprintf(stderr, "Got segv Exception 5!\n"); |
|
|
3326 | exception = 1; |
|
|
3327 | } |
|
|
3328 | FINALLY |
|
|
3329 | { |
|
|
3330 | signal (SIGSEGV, SIG_DFL); |
|
|
3331 | } |
|
|
3332 | ETRY; |
|
|
3333 | |
|
|
3334 | //fprintf(stderr, "trinew 092.3\n"); |
|
|
3335 | |
|
|
3336 | } // exception == 0 ? -- END |
|
|
3337 | |
|
|
3338 | // rcdt = p2tr_cdt_new(cdt); |
|
|
3339 | /* |
|
|
3340 | if (refine_max_steps > 0) |
|
|
3341 | { |
|
|
3342 | fprintf(stderr, "Refining the mesh!\n"); |
|
|
3343 | refiner = p2tr_refiner_new(G_PI / 6, p2tr_refiner_false_too_big, rcdt); |
|
|
3344 | p2tr_refiner_refine(refiner, refine_max_steps, NULL); |
|
|
3345 | p2tr_refiner_free(refiner); |
|
|
3346 | |
|
|
3347 | p2tr_cdt_validate_edges(rcdt); |
|
|
3348 | } |
|
|
3349 | */ |
|
|
3350 | |
|
|
3351 | //fprintf(stderr, "free holes\n"); |
|
|
3352 | |
|
|
3353 | if (all_holes) |
|
|
3354 | { |
|
|
3355 | all_holes = g_list_first(all_holes); |
|
|
3356 | while (all_holes) |
|
|
3357 | { |
|
|
3358 | current_hole = all_holes->data; |
|
|
3359 | for (i = 0; i < current_hole->len; ++i) |
|
|
3360 | { |
|
|
3361 | p2t_point_free(g_ptr_array_index(current_hole, i)); |
|
|
3362 | } |
|
|
3363 | g_ptr_array_free(current_hole, TRUE); |
|
|
3364 | |
|
|
3365 | all_holes = g_list_next(all_holes); |
|
|
3366 | } |
|
|
3367 | g_list_free(all_holes); |
|
|
3368 | all_holes = NULL; |
|
|
3369 | } |
|
|
3370 | |
|
|
3371 | //fprintf(stderr, "free points\n"); |
|
|
3372 | |
|
|
3373 | for (i = 0; i < current_points->len; ++i) |
|
|
3374 | { |
|
|
3375 | p2t_point_free(g_ptr_array_index(current_points, i)); |
|
|
3376 | } |
|
|
3377 | g_ptr_array_free(current_points, TRUE); |
|
|
3378 | |
|
|
3379 | // p2tr_cdt_free(rcdt); |
|
|
3380 | |
|
|
3381 | #endif |
|
|
3382 | |
|
|
3383 | #if 0 |
|
|
3384 | item_bin_write(item_bin_tri, osm->ways_with_coords); |
|
|
3385 | #endif |
|
|
3386 | triangulate_not_done = 0; |
|
|
3387 | } |
|
|
3388 | |
|
|
3389 | // free everything!! ---------------- |
|
|
3390 | if (unsorted_outer_ways) |
|
|
3391 | { |
|
|
3392 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
3393 | while (unsorted_outer_ways) |
|
|
3394 | { |
|
|
3395 | gptr = unsorted_outer_ways->data; |
|
|
3396 | way_nodes1 = unsorted_outer_ways->data; |
|
|
3397 | if (way_nodes1->nodes) |
|
|
3398 | { |
|
|
3399 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
3400 | while (way_nodes1->nodes) |
|
|
3401 | { |
|
|
3402 | ndptr = way_nodes1->nodes->data; |
|
|
3403 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
3404 | g_free(ndptr); |
|
|
3405 | ndptr = NULL; |
|
|
3406 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
3407 | } |
|
|
3408 | } |
|
|
3409 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, gptr); |
|
|
3410 | g_free(gptr); |
|
|
3411 | gptr = NULL; |
|
|
3412 | unsorted_outer_ways = g_list_next(unsorted_outer_ways); |
|
|
3413 | } |
|
|
3414 | } |
|
|
3415 | |
|
|
3416 | if (unsorted_inner_ways) |
|
|
3417 | { |
|
|
3418 | unsorted_inner_ways = g_list_first(unsorted_inner_ways); |
|
|
3419 | while (unsorted_inner_ways) |
|
|
3420 | { |
|
|
3421 | gptr = unsorted_inner_ways->data; |
|
|
3422 | way_nodes1 = unsorted_inner_ways->data; |
|
|
3423 | if (way_nodes1->nodes) |
|
|
3424 | { |
|
|
3425 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
3426 | while (way_nodes1->nodes) |
|
|
3427 | { |
|
|
3428 | ndptr = way_nodes1->nodes->data; |
|
|
3429 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
3430 | g_free(ndptr); |
|
|
3431 | ndptr = NULL; |
|
|
3432 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
3433 | } |
|
|
3434 | } |
|
|
3435 | unsorted_inner_ways = g_list_remove(unsorted_inner_ways, gptr); |
|
|
3436 | g_free(gptr); |
|
|
3437 | gptr = NULL; |
|
|
3438 | unsorted_inner_ways = g_list_next(unsorted_inner_ways); |
|
|
3439 | } |
|
|
3440 | } |
|
|
3441 | |
|
|
3442 | if (sorted_outer_ways) |
|
|
3443 | { |
|
|
3444 | sorted_outer_ways = g_list_first(sorted_outer_ways); |
|
|
3445 | while (sorted_outer_ways) |
|
|
3446 | { |
|
|
3447 | gptr = sorted_outer_ways->data; |
|
|
3448 | way_nodes1 = sorted_outer_ways->data; |
|
|
3449 | if (way_nodes1->nodes) |
|
|
3450 | { |
|
|
3451 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
3452 | while (way_nodes1->nodes) |
|
|
3453 | { |
|
|
3454 | ndptr = way_nodes1->nodes->data; |
|
|
3455 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
3456 | g_free(ndptr); |
|
|
3457 | ndptr = NULL; |
|
|
3458 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
3459 | } |
|
|
3460 | } |
|
|
3461 | sorted_outer_ways = g_list_remove(sorted_outer_ways, gptr); |
|
|
3462 | g_free(gptr); |
|
|
3463 | gptr = NULL; |
|
|
3464 | sorted_outer_ways = g_list_next(sorted_outer_ways); |
|
|
3465 | } |
|
|
3466 | } |
|
|
3467 | // free everything!! ---------------- |
|
|
3468 | } |
|
|
3469 | // save relations other method -------------- |
|
|
3470 | |
|
|
3471 | #endif |
|
|
3472 | |
|
|
3473 | if (triangulate_not_done == 1) |
|
|
3474 | { |
|
|
3475 | str = NULL; |
|
|
3476 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3477 | { |
|
|
3478 | if (get_relation_member(str, &memb)) |
|
|
3479 | { |
|
|
3480 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) // use only "outer" "ways" here!! |
|
|
3481 | { |
|
|
3482 | struct way_tag wt; |
|
|
3483 | wt.way_id = memb.id; |
|
|
3484 | wt.tag_id = tag_id; |
|
|
3485 | // only use "water" related ways here |
|
|
3486 | if ((tag_id == 1) || (tag_id == 2) || (tag_id == 4) || (tag_id == 5) || (tag_id == 6)) |
|
|
3487 | { |
|
|
3488 | //fprintf(stderr,"rel way=%llu\n", memb.id); |
|
|
3489 | fwrite(&wt, sizeof(struct way_tag), 1, osm->relations_riverbank); |
|
|
3490 | } |
|
|
3491 | } |
|
|
3492 | else if ((memb.type == 2) && (!strcmp(memb.role, "inner"))) // use only "outer" "ways" here!! |
|
|
3493 | { |
|
|
3494 | struct way_tag wt; |
|
|
3495 | wt.way_id = memb.id; |
|
|
3496 | wt.tag_id = tag_id; |
|
|
3497 | // only use "water" related ways here |
|
|
3498 | if (tag_id == 6) |
|
|
3499 | { |
|
|
3500 | wt.tag_id = 8; |
|
|
3501 | //fprintf(stderr,"rel way(8)=%llu\n", memb.id); |
|
|
3502 | fwrite(&wt, sizeof(struct way_tag), 1, osm->relations_riverbank); |
|
|
3503 | } |
|
|
3504 | else if (tag_id == 5) |
|
|
3505 | { |
|
|
3506 | wt.tag_id = 7; |
|
|
3507 | //fprintf(stderr,"rel way(7)=%llu\n", memb.id); |
|
|
3508 | fwrite(&wt, sizeof(struct way_tag), 1, osm->relations_riverbank); |
|
|
3509 | } |
|
|
3510 | } |
|
|
3511 | |
|
|
3512 | } |
|
|
3513 | } |
|
|
3514 | } |
|
|
3515 | } |
|
|
3516 | // -- save relations for riverbanks -- |
|
|
3517 | |
|
|
3518 | |
|
|
3519 | in_relation = 0; |
|
|
3520 | |
|
|
3521 | if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) |
|
|
3522 | { |
|
|
3523 | int found_town_rel = 0; |
|
|
3524 | |
|
|
3525 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
|
|
3526 | { |
|
|
3527 | // save relation id for towns into DB |
|
|
3528 | str = NULL; |
|
|
3529 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3530 | { |
|
|
3531 | if (get_relation_member(str, &memb)) |
|
|
3532 | { |
|
|
3533 | if (memb.type == 1) |
|
|
3534 | { |
|
|
3535 | //fprintf(stderr, "role=%s\n", memb.role); |
|
|
3536 | |
|
|
3537 | if (!strcmp(memb.role, "label")) |
|
|
3538 | { |
|
|
3539 | fprintf(stderr, "town to relation: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
|
|
3540 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3541 | // fprintf(stderr, "ret=%d\n", rr); |
|
|
3542 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
|
|
3543 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
|
|
3544 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
|
|
3545 | sqlite3_step(stmt_town_sel008); |
|
|
3546 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3547 | sqlite3_reset(stmt_town_sel008); |
|
|
3548 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3549 | |
|
|
3550 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3551 | |
|
|
3552 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3553 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3554 | |
|
|
3555 | found_town_rel = 1; |
|
|
3556 | } |
|
|
3557 | } |
|
|
3558 | } |
|
|
3559 | } |
|
|
3560 | } |
|
|
3561 | |
|
|
3562 | |
|
|
3563 | |
|
|
3564 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
|
|
3565 | { |
|
|
3566 | // save relation id for towns into DB |
|
|
3567 | str = NULL; |
|
|
3568 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3569 | { |
|
|
3570 | if (get_relation_member(str, &memb)) |
|
|
3571 | { |
|
|
3572 | if (memb.type == 1) |
|
|
3573 | { |
|
|
3574 | //fprintf(stderr, "role=%s\n", memb.role); |
|
|
3575 | |
|
|
3576 | if (!strcmp(memb.role, "admin_centre")) |
|
|
3577 | { |
|
|
3578 | fprintf(stderr, "town to relation: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
|
|
3579 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3580 | // fprintf(stderr, "ret=%d\n", rr); |
|
|
3581 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
|
|
3582 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
|
|
3583 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
|
|
3584 | sqlite3_step(stmt_town_sel008); |
|
|
3585 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3586 | sqlite3_reset(stmt_town_sel008); |
|
|
3587 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3588 | |
|
|
3589 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3590 | |
|
|
3591 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3592 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3593 | |
|
|
3594 | found_town_rel = 1; |
|
|
3595 | } |
|
|
3596 | } |
|
|
3597 | } |
|
|
3598 | } |
|
|
3599 | } |
|
|
3600 | |
|
|
3601 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
|
|
3602 | { |
|
|
3603 | // save relation id for towns into DB |
|
|
3604 | str = NULL; |
|
|
3605 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3606 | { |
|
|
3607 | if (get_relation_member(str, &memb)) |
|
|
3608 | { |
|
|
3609 | if (memb.type == 1) |
|
|
3610 | { |
|
|
3611 | //fprintf(stderr, "role=%s\n", memb.role); |
|
|
3612 | |
|
|
3613 | if (!strcmp(memb.role, "admin_center")) |
|
|
3614 | { |
|
|
3615 | fprintf(stderr, "town to relation: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
|
|
3616 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3617 | // fprintf(stderr, "ret=%d\n", rr); |
|
|
3618 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
|
|
3619 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
|
|
3620 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
|
|
3621 | sqlite3_step(stmt_town_sel008); |
|
|
3622 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3623 | sqlite3_reset(stmt_town_sel008); |
|
|
3624 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3625 | |
|
|
3626 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3627 | |
|
|
3628 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3629 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3630 | |
|
|
3631 | found_town_rel = 1; |
|
|
3632 | } |
|
|
3633 | } |
|
|
3634 | } |
|
|
3635 | } |
|
|
3636 | } |
|
|
3637 | |
|
|
3638 | |
|
|
3639 | |
|
|
3640 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
|
|
3641 | { |
|
|
3642 | // save relation id for towns into DB (use dummy town data) |
|
|
3643 | 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); |
|
|
3644 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3645 | // fprintf(stderr, "ret=%d\n", rr); |
|
|
3646 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
|
|
3647 | sqlite3_bind_int64(stmt_town_sel008, 2, dummy_town_id); |
|
|
3648 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
|
|
3649 | sqlite3_step(stmt_town_sel008); |
|
|
3650 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3651 | sqlite3_reset(stmt_town_sel008); |
|
|
3652 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3653 | |
|
|
3654 | |
|
|
3655 | str = NULL; |
|
|
3656 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3657 | { |
|
|
3658 | if (get_relation_member(str, &memb)) |
|
|
3659 | { |
|
|
3660 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) |
|
|
3661 | { |
|
|
3662 | // way-id is "memb.id" |
|
|
3663 | // use the first nodes coords |
|
|
3664 | get_lat_lon_way_first_node(memb.id, &node_coords); |
|
|
3665 | if (node_coords.valid == 1) |
|
|
3666 | { |
|
|
3667 | sqlite3_bind_double(stmt_town, 6, node_coords.lat); |
|
|
3668 | sqlite3_bind_double(stmt_town, 7, node_coords.lon); |
|
|
3669 | } |
|
|
3670 | |
|
|
3671 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3672 | |
|
|
3673 | break; |
|
|
3674 | } |
|
|
3675 | } |
|
|
3676 | } |
|
|
3677 | |
|
|
3678 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
|
|
3679 | sqlite3_bind_int(stmt_town, 2, 999); |
|
|
3680 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
|
|
3681 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
|
|
3682 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
|
|
3683 | sqlite3_bind_int64(stmt_town, 8, current_id); |
|
|
3684 | sqlite3_step(stmt_town); |
|
|
3685 | sqlite3_reset(stmt_town); |
|
|
3686 | |
|
|
3687 | found_town_rel = 1; |
|
|
3688 | |
|
|
3689 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3690 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3691 | |
|
|
3692 | dummy_town_id--; |
|
|
3693 | } |
|
|
3694 | |
|
|
3695 | // rest of the boundaries!!! |
|
|
3696 | if (found_town_rel == 0) |
|
|
3697 | { |
|
|
3698 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3699 | |
|
|
3700 | str = NULL; |
|
|
3701 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3702 | { |
|
|
3703 | if (get_relation_member(str, &memb)) |
|
|
3704 | { |
|
|
3705 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) |
|
|
3706 | { |
|
|
3707 | 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); |
|
|
3708 | |
|
|
3709 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3710 | break; |
|
|
3711 | } |
|
|
3712 | } |
|
|
3713 | } |
|
|
3714 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3715 | |
|
|
3716 | found_town_rel = 0; |
|
|
3717 | } |
|
|
3718 | |
|
|
3719 | |
|
|
3720 | #if 0 |
|
|
3721 | if (admin_level == 2) |
1415 | if (admin_level == 2) { |
3722 | { |
|
|
3723 | FILE *f; |
1416 | FILE *f; |
3724 | fprintf(stderr,"Multipolygon for %s\n", iso_code); |
1417 | fprintf(stderr,"Multipolygon for %s\n", iso_code); |
3725 | char *name=g_strdup_printf("country_%s.tmp",iso_code); |
1418 | char *name=g_strdup_printf("country_%s.tmp",iso_code); |
3726 | f=fopen(name,"w"); |
1419 | f=fopen(name,"w"); |
3727 | item_bin_write(item_bin_2, f); |
1420 | item_bin_write(item_bin, f); |
3728 | fclose(f); |
1421 | fclose(f); |
3729 | } |
1422 | } |
3730 | #endif |
1423 | #endif |
3731 | item_bin_write(item_bin_2, osm->boundaries); |
1424 | item_bin_write(item_bin, boundaries); |
3732 | } |
1425 | } |
3733 | |
1426 | |
3734 | if (!strcmp(relation_type, "restriction") && (item_bin_2->type == type_street_turn_restriction_no || item_bin_2->type == type_street_turn_restriction_only)) |
1427 | if (!strcmp(relation_type, "restriction") && (item_bin->type == type_street_turn_restriction_no || item_bin->type == type_street_turn_restriction_only)) |
3735 | { |
|
|
3736 | item_bin_write(item_bin_2, osm->turn_restrictions); |
1428 | item_bin_write(item_bin, turn_restrictions); |
3737 | } |
|
|
3738 | } |
1429 | } |
3739 | |
1430 | |
3740 | |
1431 | void |
3741 | void correct_boundary_ref_point(GList *bl) |
|
|
3742 | { |
|
|
3743 | long long rid; |
|
|
3744 | int retval; |
|
|
3745 | int rc = 0; |
|
|
3746 | int commit_after = 20000; |
|
|
3747 | int count = 0; |
|
|
3748 | int admin_l = 99; |
|
|
3749 | double lat, lon; |
|
|
3750 | struct coord c; |
|
|
3751 | GList *l = NULL; |
|
|
3752 | GList *l2 = NULL; |
|
|
3753 | GList *match = NULL; |
|
|
3754 | struct boundary *b; |
|
|
3755 | int admin_l_boundary; |
|
|
3756 | int max_admin_l; |
|
|
3757 | |
|
|
3758 | // loop thru all the boundaries |
|
|
3759 | do |
|
|
3760 | { |
|
|
3761 | rc = sqlite3_step(stmt_bd_002); |
|
|
3762 | switch (rc) |
|
|
3763 | { |
|
|
3764 | case SQLITE_DONE: |
|
|
3765 | break; |
|
|
3766 | case SQLITE_ROW: |
|
|
3767 | |
|
|
3768 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
|
|
3769 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
|
|
3770 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
|
|
3771 | lat = sqlite3_column_double(stmt_bd_002, 2); |
|
|
3772 | lon = sqlite3_column_double(stmt_bd_002, 3); |
|
|
3773 | c.x = transform_from_geo_lon(lon); |
|
|
3774 | c.y = transform_from_geo_lat(lat); |
|
|
3775 | |
|
|
3776 | //fprintf(stderr, "correct_boundary_ref_point: relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
|
|
3777 | |
|
|
3778 | // find this boundary in list |
|
|
3779 | l = bl; |
|
|
3780 | match = NULL; |
|
|
3781 | while (l) |
|
|
3782 | { |
|
|
3783 | b = l->data; |
|
|
3784 | //fprintf(stderr, "correct_boundary_ref_point: %lld %lld\n", item_bin_get_relationid(b->ib), rid); |
|
|
3785 | if (item_bin_get_relationid(b->ib) == rid) |
|
|
3786 | { |
|
|
3787 | match = l; |
|
|
3788 | break; |
|
|
3789 | } |
|
|
3790 | l = g_list_next(l); |
|
|
3791 | } |
|
|
3792 | |
|
|
3793 | if (match) |
|
|
3794 | { |
|
|
3795 | b = match->data; |
|
|
3796 | //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); |
|
|
3797 | |
|
|
3798 | // ------------------------------------------- |
|
|
3799 | /* |
|
|
3800 | GList *sl; |
|
|
3801 | sl = b->sorted_segments; |
|
|
3802 | if (sl) |
|
|
3803 | { |
|
|
3804 | struct geom_poly_segment *gs = sl->data; |
|
|
3805 | struct coord *c2 = gs->first; |
|
|
3806 | fprintf(stderr, "1a c=%d y=%d\n", c2->x, c2->y); |
|
|
3807 | } |
|
|
3808 | */ |
|
|
3809 | // ------------------------------------------- |
|
|
3810 | |
|
|
3811 | if (find_correct_point_in_boundary(match, &lat, &lon) == 1) |
|
|
3812 | { |
|
|
3813 | sqlite3_bind_double(stmt_bd_004, 1, lat); |
|
|
3814 | sqlite3_bind_double(stmt_bd_004, 2, lon); |
|
|
3815 | sqlite3_bind_int64(stmt_bd_004, 3, rid); |
|
|
3816 | sqlite3_step(stmt_bd_004); |
|
|
3817 | sqlite3_reset(stmt_bd_004); |
|
|
3818 | } |
|
|
3819 | } |
|
|
3820 | |
|
|
3821 | |
|
|
3822 | if (count == 0) |
|
|
3823 | { |
|
|
3824 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3825 | } |
|
|
3826 | count++; |
|
|
3827 | |
|
|
3828 | if (count > commit_after) |
|
|
3829 | { |
|
|
3830 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3831 | count = 0; |
|
|
3832 | } |
|
|
3833 | |
|
|
3834 | break; |
|
|
3835 | default: |
|
|
3836 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
3837 | break; |
|
|
3838 | } |
|
|
3839 | } |
|
|
3840 | while (rc == SQLITE_ROW); |
|
|
3841 | sqlite3_reset(stmt_bd_002); |
|
|
3842 | |
|
|
3843 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3844 | |
|
|
3845 | } |
|
|
3846 | |
|
|
3847 | |
|
|
3848 | int find_correct_point_in_boundary(GList *bl, double* lat, double* lon) |
|
|
3849 | { |
|
|
3850 | double lat2, lon2; |
|
|
3851 | struct coord c; |
|
|
3852 | struct boundary *b; |
|
|
3853 | GList *matches; |
|
|
3854 | double lat_d = 0.00006; |
|
|
3855 | double lon_d = 0.00006; |
|
|
3856 | |
|
|
3857 | lat2 = *lat; |
|
|
3858 | lon2 = *lon; |
|
|
3859 | |
|
|
3860 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
3861 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
3862 | //fprintf(stderr, "2 c=%d y=%d\n", c.x, c.y); |
|
|
3863 | matches = NULL; |
|
|
3864 | matches = boundary_find_matches_single(bl, &c); |
|
|
3865 | if (g_list_length(matches) > 0) |
|
|
3866 | { |
|
|
3867 | *lon = lon2 + lon_d; |
|
|
3868 | *lat = lat2 + lat_d; |
|
|
3869 | return 1; |
|
|
3870 | } |
|
|
3871 | |
|
|
3872 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
3873 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
3874 | //fprintf(stderr, "3 c=%d y=%d\n", c.x, c.y); |
|
|
3875 | matches = NULL; |
|
|
3876 | matches = boundary_find_matches_single(bl, &c); |
|
|
3877 | if (g_list_length(matches) > 0) |
|
|
3878 | { |
|
|
3879 | *lon = lon2 + lon_d; |
|
|
3880 | *lat = lat2 - lat_d; |
|
|
3881 | return 1; |
|
|
3882 | } |
|
|
3883 | |
|
|
3884 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
3885 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
3886 | //fprintf(stderr, "4 c=%d y=%d\n", c.x, c.y); |
|
|
3887 | matches = NULL; |
|
|
3888 | matches = boundary_find_matches_single(bl, &c); |
|
|
3889 | if (g_list_length(matches) > 0) |
|
|
3890 | { |
|
|
3891 | *lon = lon2 - lon_d; |
|
|
3892 | *lat = lat2 + lat_d; |
|
|
3893 | return 1; |
|
|
3894 | } |
|
|
3895 | |
|
|
3896 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
3897 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
3898 | //fprintf(stderr, "5 c=%d y=%d\n", c.x, c.y); |
|
|
3899 | matches = NULL; |
|
|
3900 | matches = boundary_find_matches_single(bl, &c); |
|
|
3901 | if (g_list_length(matches) > 0) |
|
|
3902 | { |
|
|
3903 | *lon = lon2 - lon_d; |
|
|
3904 | *lat = lat2 - lat_d; |
|
|
3905 | return 1; |
|
|
3906 | } |
|
|
3907 | |
|
|
3908 | |
|
|
3909 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
3910 | c.y = transform_from_geo_lat(lat2); |
|
|
3911 | //fprintf(stderr, "6 c=%d y=%d\n", c.x, c.y); |
|
|
3912 | matches = NULL; |
|
|
3913 | matches = boundary_find_matches_single(bl, &c); |
|
|
3914 | if (g_list_length(matches) > 0) |
|
|
3915 | { |
|
|
3916 | *lon = lon2 - lon_d; |
|
|
3917 | *lat = lat2; |
|
|
3918 | return 1; |
|
|
3919 | } |
|
|
3920 | |
|
|
3921 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
3922 | c.y = transform_from_geo_lat(lat2); |
|
|
3923 | //fprintf(stderr, "7 c=%d y=%d\n", c.x, c.y); |
|
|
3924 | matches = NULL; |
|
|
3925 | matches = boundary_find_matches_single(bl, &c); |
|
|
3926 | if (g_list_length(matches) > 0) |
|
|
3927 | { |
|
|
3928 | *lon = lon2 - lon_d; |
|
|
3929 | *lat = lat2; |
|
|
3930 | return 1; |
|
|
3931 | } |
|
|
3932 | |
|
|
3933 | c.x = transform_from_geo_lon(lon2); |
|
|
3934 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
3935 | //fprintf(stderr, "8 c=%d y=%d\n", c.x, c.y); |
|
|
3936 | matches = NULL; |
|
|
3937 | matches = boundary_find_matches_single(bl, &c); |
|
|
3938 | if (g_list_length(matches) > 0) |
|
|
3939 | { |
|
|
3940 | *lon = lon2; |
|
|
3941 | *lat = lat2 + lat_d; |
|
|
3942 | return 1; |
|
|
3943 | } |
|
|
3944 | |
|
|
3945 | |
|
|
3946 | c.x = transform_from_geo_lon(lon2); |
|
|
3947 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
3948 | //fprintf(stderr, "9 c=%d y=%d\n", c.x, c.y); |
|
|
3949 | matches = NULL; |
|
|
3950 | matches = boundary_find_matches_single(bl, &c); |
|
|
3951 | if (g_list_length(matches) > 0) |
|
|
3952 | { |
|
|
3953 | *lon = lon2; |
|
|
3954 | *lat = lat2 - lat_d; |
|
|
3955 | return 1; |
|
|
3956 | } |
|
|
3957 | |
|
|
3958 | return 0; |
|
|
3959 | |
|
|
3960 | } |
|
|
3961 | |
|
|
3962 | void build_boundary_tree(GList *bl) |
|
|
3963 | { |
|
|
3964 | long long rid; |
|
|
3965 | int retval; |
|
|
3966 | int rc = 0; |
|
|
3967 | int commit_after = 20000; |
|
|
3968 | int count = 0; |
|
|
3969 | int admin_l = 99; |
|
|
3970 | double lat, lon; |
|
|
3971 | struct coord c; |
|
|
3972 | GList *l = NULL; |
|
|
3973 | GList *l2 = NULL; |
|
|
3974 | GList *match = NULL; |
|
|
3975 | struct boundary *b; |
|
|
3976 | int admin_l_boundary; |
|
|
3977 | int max_admin_l; |
|
|
3978 | |
|
|
3979 | // loop thru all the boundaries |
|
|
3980 | do |
|
|
3981 | { |
|
|
3982 | rc = sqlite3_step(stmt_bd_002); |
|
|
3983 | switch (rc) |
|
|
3984 | { |
|
|
3985 | case SQLITE_DONE: |
|
|
3986 | break; |
|
|
3987 | case SQLITE_ROW: |
|
|
3988 | |
|
|
3989 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
|
|
3990 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
|
|
3991 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
|
|
3992 | lat = sqlite3_column_double(stmt_bd_002, 2); |
|
|
3993 | lon = sqlite3_column_double(stmt_bd_002, 3); |
|
|
3994 | c.x = transform_from_geo_lon(lon); |
|
|
3995 | c.y = transform_from_geo_lat(lat); |
|
|
3996 | |
|
|
3997 | //fprintf(stderr, "relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
|
|
3998 | |
|
|
3999 | max_admin_l = 0; |
|
|
4000 | l2 = boundary_find_matches_level(bl, &c, 0, (admin_l - 1)); |
|
|
4001 | l = l2; |
|
|
4002 | match = NULL; |
|
|
4003 | while (l) |
|
|
4004 | { |
|
|
4005 | b = l->data; |
|
|
4006 | char *admin_l_boundary_str = osm_tag_value(b->ib, "admin_level"); |
|
|
4007 | if (!admin_l_boundary_str) |
|
|
4008 | { |
|
|
4009 | admin_l_boundary = 9999; |
|
|
4010 | } |
|
|
4011 | else |
|
|
4012 | { |
|
|
4013 | admin_l_boundary = atoi(admin_l_boundary_str); |
|
|
4014 | } |
|
|
4015 | |
|
|
4016 | if (admin_l_boundary < 2) |
|
|
4017 | { |
|
|
4018 | admin_l_boundary = 9999; |
|
|
4019 | } |
|
|
4020 | |
|
|
4021 | //fprintf(stderr, "b=%d\n", admin_l_boundary); |
|
|
4022 | if (admin_l_boundary > max_admin_l) |
|
|
4023 | { |
|
|
4024 | max_admin_l = admin_l_boundary; |
|
|
4025 | match = l; |
|
|
4026 | //fprintf(stderr, "b2=%d\n", max_admin_l); |
|
|
4027 | } |
|
|
4028 | l = g_list_next(l); |
|
|
4029 | } |
|
|
4030 | |
|
|
4031 | if (match) |
|
|
4032 | { |
|
|
4033 | b = match->data; |
|
|
4034 | //fprintf(stderr, "relid:%lld(%d) parentid:%lld(%d)\n", rid, admin_l, item_bin_get_relationid(b->ib), max_admin_l); |
|
|
4035 | |
|
|
4036 | sqlite3_bind_int64(stmt_bd_003, 1, item_bin_get_relationid(b->ib)); |
|
|
4037 | sqlite3_bind_int64(stmt_bd_003, 2, rid); |
|
|
4038 | sqlite3_step(stmt_bd_003); |
|
|
4039 | sqlite3_reset(stmt_bd_003); |
|
|
4040 | } |
|
|
4041 | |
|
|
4042 | |
|
|
4043 | if (count == 0) |
|
|
4044 | { |
|
|
4045 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
4046 | } |
|
|
4047 | count++; |
|
|
4048 | |
|
|
4049 | if (count > commit_after) |
|
|
4050 | { |
|
|
4051 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4052 | count = 0; |
|
|
4053 | } |
|
|
4054 | |
|
|
4055 | break; |
|
|
4056 | default: |
|
|
4057 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
4058 | break; |
|
|
4059 | } |
|
|
4060 | } |
|
|
4061 | while (rc == SQLITE_ROW); |
|
|
4062 | sqlite3_reset(stmt_bd_002); |
|
|
4063 | |
|
|
4064 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4065 | } |
|
|
4066 | |
|
|
4067 | void add_boundary_to_db(long long current_id, int admin_level, struct item_bin *item_bin_3, struct relation_member *memb) |
|
|
4068 | { |
|
|
4069 | char *str = NULL; |
|
|
4070 | struct node_lat_lon node_coords; |
|
|
4071 | |
|
|
4072 | sqlite3_bind_int64(stmt_bd_001, 1, current_id); |
|
|
4073 | |
|
|
4074 | if (admin_level < 2) |
|
|
4075 | { |
|
|
4076 | sqlite3_bind_int(stmt_bd_001, 2, 9999); |
|
|
4077 | } |
|
|
4078 | else |
|
|
4079 | { |
|
|
4080 | sqlite3_bind_int(stmt_bd_001, 2, admin_level); |
|
|
4081 | } |
|
|
4082 | while ((str = item_bin_get_attr(item_bin_3, attr_osm_member, str))) |
|
|
4083 | { |
|
|
4084 | if (get_relation_member(str, memb)) |
|
|
4085 | { |
|
|
4086 | if (memb->type == 2) |
|
|
4087 | { |
|
|
4088 | // way-id is "memb.id" |
|
|
4089 | // use the first nodes coords |
|
|
4090 | get_lat_lon_way_first_node(memb->id, &node_coords); |
|
|
4091 | if (node_coords.valid == 1) |
|
|
4092 | { |
|
|
4093 | sqlite3_bind_double(stmt_bd_001, 3, node_coords.lat); |
|
|
4094 | sqlite3_bind_double(stmt_bd_001, 4, node_coords.lon); |
|
|
4095 | } |
|
|
4096 | break; |
|
|
4097 | } |
|
|
4098 | } |
|
|
4099 | } |
|
|
4100 | sqlite3_bind_text(stmt_bd_001, 5, osm_tag_value(item_bin_3, "name"), -1, SQLITE_STATIC); |
|
|
4101 | sqlite3_step(stmt_bd_001); |
|
|
4102 | sqlite3_reset(stmt_bd_001); |
|
|
4103 | } |
|
|
4104 | |
|
|
4105 | |
|
|
4106 | void osm_add_member(int type, osmid ref, char *role) |
1432 | osm_add_member(int type, osmid ref, char *role) |
4107 | { |
1433 | { |
4108 | char member_buffer[BUFFER_SIZE * 3 + 3]; |
1434 | char member_buffer[BUFFER_SIZE*3+3]; |
4109 | struct attr memberattr = { attr_osm_member }; |
1435 | struct attr memberattr = { attr_osm_member }; |
4110 | |
1436 | |
4111 | sprintf(member_buffer,"%d:"LONGLONG_FMT":%s", type, (long long) ref, role); |
1437 | sprintf(member_buffer,"%d:"LONGLONG_FMT":%s", type, (long long) ref, role); |
4112 | memberattr.u.str = member_buffer; |
1438 | memberattr.u.str=member_buffer; |
4113 | item_bin_add_attr(item_bin_2, &memberattr); |
1439 | item_bin_add_attr(item_bin, &memberattr); |
4114 | } |
1440 | } |
4115 | |
1441 | |
|
|
1442 | static void |
4116 | static void relation_add_tag(char *k, char *v) |
1443 | relation_add_tag(char *k, char *v) |
4117 | { |
1444 | { |
4118 | int add_tag = 1; |
1445 | int add_tag=1; |
4119 | #if 0 |
1446 | #if 0 |
4120 | fprintf(stderr,"add tag %s %s\n",k,v); |
1447 | fprintf(stderr,"add tag %s %s\n",k,v); |
4121 | #endif |
1448 | #endif |
4122 | if (!strcmp(k, "type")) |
1449 | if (!strcmp(k,"type")) { |
4123 | { |
|
|
4124 | strcpy(relation_type, v); |
1450 | strcpy(relation_type, v); |
4125 | add_tag = 0; |
1451 | add_tag=0; |
4126 | } |
1452 | } |
4127 | else if (!strcmp(k, "restriction")) |
1453 | else if (!strcmp(k,"restriction")) { |
4128 | { |
|
|
4129 | if (!strncmp(v, "no_", 3)) |
1454 | if (!strncmp(v,"no_",3)) { |
4130 | { |
|
|
4131 | item_bin_2->type = type_street_turn_restriction_no; |
1455 | item_bin->type=type_street_turn_restriction_no; |
4132 | add_tag = 0; |
1456 | add_tag=0; |
4133 | } |
|
|
4134 | else if (!strncmp(v, "only_", 5)) |
1457 | } else if (!strncmp(v,"only_",5)) { |
4135 | { |
|
|
4136 | item_bin_2->type = type_street_turn_restriction_only; |
1458 | item_bin->type=type_street_turn_restriction_only; |
4137 | add_tag = 0; |
1459 | add_tag=0; |
4138 | } |
|
|
4139 | else |
1460 | } else { |
4140 | { |
|
|
4141 | item_bin_2->type = type_none; |
1461 | item_bin->type=type_none; |
4142 | //osm_warning("relation", current_id, 0, "Unknown restriction %s\n", v); |
1462 | osm_warning("relation", current_id, 0, "Unknown restriction %s\n",v); |
4143 | } |
|
|
4144 | } |
1463 | } |
4145 | else if (!strcmp(k, "admin_level")) |
1464 | } else if (!strcmp(k,"admin_level")) { |
4146 | { |
|
|
4147 | admin_level = atoi(v); |
1465 | admin_level=atoi(v); |
4148 | } |
|
|
4149 | else if (!strcmp(k, "boundary")) |
1466 | } else if (!strcmp(k,"boundary")) { |
4150 | { |
1467 | if (!strcmp(v,"administrative")) { |
4151 | if (!strcmp(v, "administrative") || (experimental && !strcmp(v, "postal_code"))) |
|
|
4152 | { |
|
|
4153 | boundary = 1; |
1468 | boundary=1; |
4154 | } |
|
|
4155 | } |
1469 | } |
4156 | else if (!strcmp(k, "ISO3166-1")) |
1470 | } else if (!strcmp(k,"ISO3166-1")) { |
4157 | { |
|
|
4158 | strcpy(iso_code, v); |
1471 | strcpy(iso_code, v); |
4159 | } |
1472 | } |
4160 | |
1473 | #if 0 |
4161 | if (add_tag) |
1474 | if (add_tag) { |
4162 | { |
|
|
4163 | //fprintf(stderr,"*TAG*%s=%s\n", k, v); |
|
|
4164 | char tag[strlen(k) + strlen(v) + 2]; |
1475 | char tag[strlen(k)+strlen(v)+2]; |
4165 | sprintf(tag, "%s=%s", k, v); |
1476 | sprintf(tag,"%s=%s",k,v); |
4166 | item_bin_add_attr_string(item_bin_2, attr_osm_tag, tag); |
1477 | item_bin_add_attr_string(item_bin, attr_osm_tag, tag); |
4167 | } |
1478 | } |
|
|
1479 | #endif |
4168 | } |
1480 | } |
4169 | |
1481 | |
|
|
1482 | |
|
|
1483 | static int |
4170 | static int attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count) |
1484 | attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count) |
4171 | { |
1485 | { |
4172 | int i, j, longest = 0, ret = 0, sum, val; |
1486 | int i,j,longest=0,ret=0,sum,val; |
4173 | struct attr_mapping *curr; |
1487 | struct attr_mapping *curr; |
4174 | for (i = 0; i < mapping_count; i++) |
1488 | for (i = 0 ; i < mapping_count ; i++) { |
4175 | { |
|
|
4176 | sum = 0; |
1489 | sum=0; |
4177 | curr = mapping[i]; |
1490 | curr=mapping[i]; |
4178 | for (j = 0; j < curr->attr_present_idx_count; j++) |
1491 | for (j = 0 ; j < curr->attr_present_idx_count ; j++) { |
4179 | { |
|
|
4180 | val = attr_present[curr->attr_present_idx[j]]; |
1492 | val=attr_present[curr->attr_present_idx[j]]; |
4181 | if (val) |
1493 | if (val) |
4182 | sum += val; |
1494 | sum+=val; |
4183 | else |
1495 | else { |
4184 | { |
|
|
4185 | sum = -1; |
1496 | sum=-1; |
4186 | break; |
1497 | break; |
4187 | } |
1498 | } |
4188 | } |
1499 | } |
4189 | if (sum > longest) |
1500 | if (sum > longest) { |
4190 | { |
|
|
4191 | longest = sum; |
1501 | longest=sum; |
4192 | ret = 0; |
1502 | ret=0; |
4193 | } |
1503 | } |
4194 | if (sum > 0 && sum == longest && ret < types_count) |
1504 | if (sum > 0 && sum == longest && ret < types_count) |
4195 | types[ret++] = curr->type; |
1505 | types[ret++]=curr->type; |
4196 | } |
1506 | } |
|
|
1507 | memset(attr_present, 0, sizeof(*attr_present)*attr_present_count); |
4197 | return ret; |
1508 | return ret; |
4198 | } |
1509 | } |
4199 | |
1510 | |
4200 | static void attr_longest_match_clear(void) |
1511 | void |
|
|
1512 | osm_end_way(FILE *out) |
4201 | { |
1513 | { |
4202 | memset(attr_present, 0, sizeof(*attr_present) * attr_present_count); |
|
|
4203 | } |
|
|
4204 | |
|
|
4205 | char* remove_all_spaces_non_utf8(char *str) |
|
|
4206 | { |
|
|
4207 | char *write = str, *read = str; |
|
|
4208 | |
|
|
4209 | if (str == NULL) |
|
|
4210 | { |
|
|
4211 | return NULL; |
|
|
4212 | } |
|
|
4213 | |
|
|
4214 | do |
|
|
4215 | { |
|
|
4216 | if (!g_ascii_isspace(*read)) |
|
|
4217 | { |
|
|
4218 | *write++ = *read; |
|
|
4219 | } |
|
|
4220 | } while (*read++); |
|
|
4221 | |
|
|
4222 | return str; |
|
|
4223 | } |
|
|
4224 | |
|
|
4225 | void osm_end_way(struct maptool_osm *osm) |
|
|
4226 | { |
|
|
4227 | int i, count; |
1514 | int i,count; |
4228 | int *def_flags, add_flags; |
1515 | int *def_flags,add_flags; |
4229 | enum item_type types[10]; |
1516 | enum item_type types[10]; |
4230 | struct item_bin *item_bin; |
1517 | struct item_bin *item_bin; |
4231 | int count_lines = 0, count_areas = 0; |
|
|
4232 | int dont_save_to_db = 1; |
|
|
4233 | int first = 1; |
|
|
4234 | int retval; |
|
|
4235 | char *name_folded = NULL; |
|
|
4236 | char *name_folded2 = NULL; |
|
|
4237 | struct node_lat_lon node_coords; |
|
|
4238 | |
1518 | |
4239 | in_way = 0; |
1519 | in_way=0; |
4240 | |
1520 | |
4241 | if (!osm->ways) |
1521 | if (! out) |
4242 | { |
|
|
4243 | return; |
1522 | return; |
4244 | } |
|
|
4245 | |
1523 | |
4246 | /* |
|
|
4247 | if (dedupe_ways_hash) |
1524 | if (dedupe_ways_hash) { |
4248 | { |
|
|
4249 | if (g_hash_table_lookup(dedupe_ways_hash, (gpointer) (long) wayid)) |
1525 | if (g_hash_table_lookup(dedupe_ways_hash, (gpointer)(long)wayid)) |
4250 | { |
|
|
4251 | return; |
1526 | return; |
4252 | } |
|
|
4253 | g_hash_table_insert(dedupe_ways_hash, (gpointer) (long) wayid, (gpointer) 1); |
1527 | g_hash_table_insert(dedupe_ways_hash, (gpointer)(long)wayid, (gpointer)1); |
4254 | } |
1528 | } |
4255 | */ |
|
|
4256 | |
1529 | |
4257 | ways_processed_count++; |
|
|
4258 | |
|
|
4259 | count = attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types) / sizeof(enum item_type)); |
1530 | count=attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types)/sizeof(enum item_type)); |
4260 | if (!count) |
1531 | if (!count) { |
4261 | { |
|
|
4262 | count = 1; |
1532 | count=1; |
4263 | types[0] = type_street_unkn; |
1533 | types[0]=type_street_unkn; |
4264 | } |
1534 | } |
4265 | |
|
|
4266 | if (count >= 10) |
1535 | if (count >= 10) { |
4267 | { |
|
|
4268 | fprintf(stderr, "way id %ld\n", osmid_attr_value); |
1536 | fprintf(stderr,"way id %ld\n",osmid_attr_value); |
4269 | dbg_assert(count < 10); |
1537 | dbg_assert(count < 10); |
4270 | } |
1538 | } |
4271 | |
1539 | for (i = 0 ; i < count ; i++) { |
4272 | if (attr_strings[attr_string_label] != NULL) |
|
|
4273 | { |
|
|
4274 | if (strlen(attr_strings[attr_string_label]) > 0) |
|
|
4275 | { |
|
|
4276 | dont_save_to_db = 0; |
|
|
4277 | } |
|
|
4278 | } |
|
|
4279 | |
|
|
4280 | 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!!) |
|
|
4281 | { |
|
|
4282 | add_flags = 0; |
1540 | add_flags=0; |
4283 | if (types[i] == type_none) |
1541 | if (types[i] == type_none) |
4284 | { |
|
|
4285 | continue; |
1542 | continue; |
4286 | } |
|
|
4287 | |
|
|
4288 | //if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) |
1543 | if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) |
4289 | // continue; |
|
|
4290 | |
|
|
4291 | // DO NOT exclude unknown streets here, or city-to-countrypolygon matching won't work!! |
|
|
4292 | if (ignore_unkown && (types[i] == type_point_unkn)) |
|
|
4293 | { |
|
|
4294 | continue; |
1544 | continue; |
4295 | } |
|
|
4296 | |
|
|
4297 | if (types[i] != type_street_unkn) |
|
|
4298 | { |
|
|
4299 | if (types[i] < type_area) |
|
|
4300 | { |
|
|
4301 | count_lines++; |
|
|
4302 | } |
|
|
4303 | else |
|
|
4304 | { |
|
|
4305 | count_areas++; |
|
|
4306 | } |
|
|
4307 | } |
|
|
4308 | item_bin = init_item(types[i], 0); |
1545 | item_bin=init_item(types[i]); |
4309 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
1546 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
4310 | nodes_ref_item_bin(item_bin, 0); |
|
|
4311 | def_flags = item_get_default_flags(types[i]); |
1547 | def_flags=item_get_default_flags(types[i]); |
4312 | |
|
|
4313 | // save nodes of way ----------------- |
|
|
4314 | // save nodes of way ----------------- |
|
|
4315 | // * now save ALL way_nodes to DB !! could be a very big DB !! |
|
|
4316 | if (first == 1) |
|
|
4317 | { |
|
|
4318 | first = 0; |
|
|
4319 | int i788; |
|
|
4320 | struct coord *c788 = (struct coord *) (item_bin + 1); // set pointer to coord struct of this item |
|
|
4321 | for (i788 = 0; i788 < item_bin->clen / 2; i788++) |
|
|
4322 | { |
|
|
4323 | if (i788 == 0) |
|
|
4324 | { |
|
|
4325 | // save lat,lon of first node of this way |
|
|
4326 | if (dont_save_to_db == 0) |
|
|
4327 | { |
|
|
4328 | |
|
|
4329 | #ifdef MAPTOOL_USE_SQL |
|
|
4330 | |
|
|
4331 | //fprintf(stderr, "insert -w\n"); |
|
|
4332 | |
|
|
4333 | get_lat_lon_for_node(REF(c788[i788]), &node_coords); |
|
|
4334 | |
|
|
4335 | if (sql_counter == 0) |
|
|
4336 | { |
|
|
4337 | retval = sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
4338 | if ((retval > 0) && (retval < 100)) |
|
|
4339 | { |
|
|
4340 | fprintf(stderr, "begin: ways code:%d\n", retval); |
|
|
4341 | } |
|
|
4342 | else |
|
|
4343 | { |
|
|
4344 | //fprintf(stderr, "begin: ways\n"); |
|
|
4345 | } |
|
|
4346 | } |
|
|
4347 | |
|
|
4348 | sql_counter++; |
|
|
4349 | |
|
|
4350 | sqlite3_bind_int64(stmt_way, 1, osmid_attr_value); |
|
|
4351 | sqlite3_bind_text(stmt_way, 2, attr_strings[attr_string_label], -1, SQLITE_STATIC); |
|
|
4352 | |
|
|
4353 | // streetname folded for later sort/search |
|
|
4354 | name_folded = linguistics_casefold(attr_strings[attr_string_label]); |
|
|
4355 | if (name_folded) |
|
|
4356 | { |
|
|
4357 | name_folded2 = linguistics_remove_all_specials(name_folded); |
|
|
4358 | if (name_folded2) |
|
|
4359 | { |
|
|
4360 | g_free(name_folded); |
|
|
4361 | name_folded = name_folded2; |
|
|
4362 | } |
|
|
4363 | |
|
|
4364 | name_folded2 = linguistics_expand_special(name_folded, 1); |
|
|
4365 | if (name_folded2) |
|
|
4366 | { |
|
|
4367 | sqlite3_bind_text(stmt_way, 6, name_folded2, -1, SQLITE_STATIC); |
|
|
4368 | } |
|
|
4369 | else |
|
|
4370 | { |
|
|
4371 | sqlite3_bind_text(stmt_way, 6, name_folded, -1, SQLITE_STATIC); |
|
|
4372 | } |
|
|
4373 | } |
|
|
4374 | else |
|
|
4375 | { |
|
|
4376 | // use original string |
|
|
4377 | sqlite3_bind_text(stmt_way, 6, attr_strings[attr_string_label], -1, SQLITE_STATIC); |
|
|
4378 | } |
|
|
4379 | |
|
|
4380 | // town id |
|
|
4381 | sqlite3_bind_int(stmt_way, 3, -1); |
|
|
4382 | |
|
|
4383 | if (node_coords.valid == 1) |
|
|
4384 | { |
|
|
4385 | // lat |
|
|
4386 | sqlite3_bind_double(stmt_way, 4, node_coords.lat); |
|
|
4387 | // lon |
|
|
4388 | sqlite3_bind_double(stmt_way, 5, node_coords.lon); |
|
|
4389 | } |
|
|
4390 | |
|
|
4391 | // retval = |
|
|
4392 | sqlite3_step(stmt_way); |
|
|
4393 | //if ((retval > 0) && (retval < 100)) |
|
|
4394 | //{ |
|
|
4395 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
|
|
4396 | //} |
|
|
4397 | sqlite3_reset(stmt_way); |
|
|
4398 | |
|
|
4399 | if (name_folded) |
|
|
4400 | { |
|
|
4401 | g_free(name_folded); |
|
|
4402 | } |
|
|
4403 | |
|
|
4404 | if (name_folded2) |
|
|
4405 | { |
|
|
4406 | g_free(name_folded2); |
|
|
4407 | } |
|
|
4408 | |
|
|
4409 | if (sql_counter > MAX_ROWS_WO_COMMIT_3) |
|
|
4410 | { |
|
|
4411 | sql_counter = 0; |
|
|
4412 | retval = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4413 | if ((retval > 0) && (retval < 100)) |
|
|
4414 | { |
|
|
4415 | fprintf(stderr, "ways: %lld code:%d\n", ways_processed_count, retval); |
|
|
4416 | } |
|
|
4417 | else |
|
|
4418 | { |
|
|
4419 | //fprintf(stderr, "ways: %lld\n", ways_processed_count); |
|
|
4420 | } |
|
|
4421 | } |
|
|
4422 | |
|
|
4423 | #endif |
|
|
4424 | |
|
|
4425 | } |
|
|
4426 | |
|
|
4427 | } |
|
|
4428 | |
|
|
4429 | #ifdef MAPTOOL_USE_SQL |
|
|
4430 | |
|
|
4431 | if (sql_counter4 == 0) |
|
|
4432 | { |
|
|
4433 | sqlite3_exec(sql_handle004, "BEGIN", 0, 0, 0); |
|
|
4434 | sqlite3_exec(sql_handle005, "BEGIN", 0, 0, 0); |
|
|
4435 | sqlite3_exec(sql_handle006, "BEGIN", 0, 0, 0); |
|
|
4436 | sqlite3_exec(sql_handle007, "BEGIN", 0, 0, 0); |
|
|
4437 | //fprintf(stderr, "begin: way nodes\n"); |
|
|
4438 | } |
|
|
4439 | sql_counter4++; |
|
|
4440 | // fprintf(stderr, "insert #WN\n"); |
|
|
4441 | |
|
|
4442 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
4443 | if ((osmid_attr_value & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
|
|
4444 | { |
|
|
4445 | if ((osmid_attr_value & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
4446 | { |
|
|
4447 | #endif |
|
|
4448 | sqlite3_bind_int64(stmt_way_node, 1, osmid_attr_value); |
|
|
4449 | sqlite3_bind_int64(stmt_way_node, 2, REF(c788[i788])); |
|
|
4450 | sqlite3_bind_int64(stmt_way_node, 3, (i788 + 1)); |
|
|
4451 | sqlite3_step(stmt_way_node); |
|
|
4452 | sqlite3_reset(stmt_way_node); |
|
|
4453 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
4454 | } |
|
|
4455 | else |
|
|
4456 | { |
|
|
4457 | sqlite3_bind_int64(stmt_way_nodeb, 1, osmid_attr_value); |
|
|
4458 | sqlite3_bind_int64(stmt_way_nodeb, 2, REF(c788[i788])); |
|
|
4459 | sqlite3_bind_int64(stmt_way_nodeb, 3, (i788 + 1)); |
|
|
4460 | sqlite3_step(stmt_way_nodeb); |
|
|
4461 | sqlite3_reset(stmt_way_nodeb); |
|
|
4462 | } |
|
|
4463 | } |
|
|
4464 | else |
|
|
4465 | { |
|
|
4466 | if ((osmid_attr_value & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
4467 | { |
|
|
4468 | sqlite3_bind_int64(stmt_way_node__2, 1, osmid_attr_value); |
|
|
4469 | sqlite3_bind_int64(stmt_way_node__2, 2, REF(c788[i788])); |
|
|
4470 | sqlite3_bind_int64(stmt_way_node__2, 3, (i788 + 1)); |
|
|
4471 | sqlite3_step(stmt_way_node__2); |
|
|
4472 | sqlite3_reset(stmt_way_node__2); |
|
|
4473 | } |
|
|
4474 | else |
|
|
4475 | { |
|
|
4476 | sqlite3_bind_int64(stmt_way_node__2b, 1, osmid_attr_value); |
|
|
4477 | sqlite3_bind_int64(stmt_way_node__2b, 2, REF(c788[i788])); |
|
|
4478 | sqlite3_bind_int64(stmt_way_node__2b, 3, (i788 + 1)); |
|
|
4479 | sqlite3_step(stmt_way_node__2b); |
|
|
4480 | sqlite3_reset(stmt_way_node__2b); |
|
|
4481 | } |
|
|
4482 | } |
|
|
4483 | #endif |
|
|
4484 | |
|
|
4485 | if (sql_counter4 > MAX_ROWS_WO_COMMIT_4) |
|
|
4486 | { |
|
|
4487 | sqlite3_exec(sql_handle004, "COMMIT", 0, 0, 0); |
|
|
4488 | sqlite3_exec(sql_handle005, "COMMIT", 0, 0, 0); |
|
|
4489 | sqlite3_exec(sql_handle006, "COMMIT", 0, 0, 0); |
|
|
4490 | sqlite3_exec(sql_handle007, "COMMIT", 0, 0, 0); |
|
|
4491 | //fprintf(stderr, "way nodes: %lld\n", sql_counter4); |
|
|
4492 | sql_counter4 = 0; |
|
|
4493 | } |
|
|
4494 | #endif |
|
|
4495 | } |
|
|
4496 | } |
|
|
4497 | // save nodes of way ----------------- |
|
|
4498 | // save nodes of way ----------------- |
|
|
4499 | |
|
|
4500 | |
|
|
4501 | if (def_flags) |
1548 | if (def_flags) { |
4502 | { |
|
|
4503 | flags_attr_value = (*def_flags | flags[0] | flags[1]) & ~flags[2]; |
1549 | flags_attr_value=(*def_flags | flags[0] | flags[1]) & ~flags[2]; |
4504 | // only add flags if they differ from the default flags!! |
|
|
4505 | if (flags_attr_value != *def_flags) |
1550 | if (flags_attr_value != *def_flags) |
4506 | { |
|
|
4507 | add_flags = 1; |
1551 | add_flags=1; |
4508 | } |
|
|
4509 | } |
|
|
4510 | else // maybe should explicitly specify which "types" to consider? now its all "types" |
|
|
4511 | { |
|
|
4512 | def_flags = 0; |
|
|
4513 | flags_attr_value = (flags[0] | flags[1]) & ~flags[2]; |
|
|
4514 | |
|
|
4515 | // only add flags if we really have a value |
|
|
4516 | if (flags_attr_value != 0) |
|
|
4517 | { |
|
|
4518 | add_flags = 1; |
|
|
4519 | } |
|
|
4520 | } |
1552 | } |
4521 | item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]); |
1553 | item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]); |
4522 | |
|
|
4523 | // housenumber from buildings -------------------- |
|
|
4524 | if (types[i] == type_poly_building) |
|
|
4525 | { |
|
|
4526 | // addr:street |
|
|
4527 | item_bin_add_attr_string(item_bin, attr_street_name_dummy, attr_strings[attr_string_street_name]); |
|
|
4528 | // fprintf(stderr, "addr:street :%s\n", attr_strings[attr_string_street_name]); |
|
|
4529 | // addr:housenumber |
|
|
4530 | item_bin_add_attr_string(item_bin, attr_house_number_dummy, attr_strings[attr_string_house_number]); |
|
|
4531 | // fprintf(stderr, "addr:housenumber:%s\n", attr_strings[attr_string_house_number]); |
|
|
4532 | } |
|
|
4533 | // housenumber from buildings -------------------- |
|
|
4534 | |
|
|
4535 | |
|
|
4536 | if (attr_strings[attr_string_label_alt]) |
|
|
4537 | { |
|
|
4538 | item_bin_add_attr_string(item_bin, attr_street_name_match, attr_strings[attr_string_label_alt]); |
|
|
4539 | if (debug_itembin(ib)) |
|
|
4540 | { |
|
|
4541 | fprintf(stderr, "street name : %s\n", attr_strings[attr_string_label]); |
|
|
4542 | fprintf(stderr, "street name sys: %s\n", attr_strings[attr_string_street_name_systematic]); |
|
|
4543 | fprintf(stderr, "street name alt: %s\n", attr_strings[attr_string_label_alt]); |
|
|
4544 | } |
|
|
4545 | } |
|
|
4546 | item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]); |
1554 | item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]); |
4547 | |
|
|
4548 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
1555 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
4549 | if (debug_attr_buffer[0]) |
1556 | if (debug_attr_buffer[0]) |
4550 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
1557 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
4551 | if (add_flags) |
1558 | if (add_flags) |
4552 | item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); |
1559 | item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); |
4553 | if (maxspeed_attr_value) |
1560 | if (maxspeed_attr_value) |
4554 | item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); |
1561 | item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); |
4555 | |
|
|
4556 | |
|
|
4557 | // if we duplicated this way here (because of multiple attributes), then set "duplicate_way" attr |
|
|
4558 | if (i > 0) |
|
|
4559 | { |
|
|
4560 | item_bin_add_attr_int(item_bin, attr_duplicate_way, 1); |
|
|
4561 | } |
|
|
4562 | |
|
|
4563 | item_bin_write(item_bin, osm->ways); |
|
|
4564 | |
|
|
4565 | if (border_only_map_as_xml == 1) |
|
|
4566 | { |
|
|
4567 | item_bin_write_xml(item_bin, "borders.xml"); |
|
|
4568 | } |
|
|
4569 | } |
|
|
4570 | |
|
|
4571 | /* |
|
|
4572 | if(osm->line2poi) { |
|
|
4573 | count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type)); |
|
|
4574 | dbg_assert(count < 10); |
|
|
4575 | for (i = 0 ; i < count ; i++) { |
|
|
4576 | if (types[i] == type_none || types[i] == type_point_unkn) |
|
|
4577 | continue; |
|
|
4578 | item_bin=init_item(types[i], 0); |
|
|
4579 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
|
|
4580 | item_bin_add_attr_string(item_bin, attr_label, attr_strings[attr_string_label]); |
|
|
4581 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
|
|
4582 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
|
|
4583 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
|
|
4584 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
|
|
4585 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
|
|
4586 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
|
|
4587 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
|
|
4588 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
|
|
4589 | item_bin_write(item_bin, count_areas<count_lines?osm->line2poi:osm->poly2poi); |
|
|
4590 | } |
|
|
4591 | } |
|
|
4592 | */ |
|
|
4593 | |
|
|
4594 | attr_longest_match_clear(); |
|
|
4595 | } |
|
|
4596 | |
|
|
4597 | void osm_append_housenumber_node(FILE *out, struct coord *c, char *house_number, char *street_name) |
|
|
4598 | { |
|
|
4599 | struct item_bin *item_bin; |
|
|
4600 | item_bin = init_item(type_house_number, 0); |
|
|
4601 | // item_bin->type = type_house_number; |
|
|
4602 | |
|
|
4603 | item_bin_add_coord(item_bin, c, 1); |
|
|
4604 | item_bin_add_attr_string(item_bin, attr_house_number, house_number); |
|
|
4605 | item_bin_add_attr_string(item_bin, attr_street_name, street_name); |
|
|
4606 | |
|
|
4607 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
4608 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
4609 | // dump_itembin(item_bin); |
|
|
4610 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
4611 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
4612 | |
|
|
4613 | item_bin_write(item_bin, out); |
1562 | item_bin_write(item_bin,out); |
|
|
1563 | } |
4614 | } |
1564 | } |
4615 | |
1565 | |
4616 | void osm_end_node(struct maptool_osm *osm) |
1566 | void |
|
|
1567 | osm_end_node(FILE *out) |
4617 | { |
1568 | { |
4618 | int count, i; |
1569 | int conflict,count,i; |
4619 | char *postal; |
1570 | char *postal; |
4620 | enum item_type types[10]; |
1571 | enum item_type types[10]; |
|
|
1572 | struct country_table *result=NULL, *lookup; |
4621 | struct item_bin *item_bin; |
1573 | struct item_bin *item_bin; |
4622 | in_node = 0; |
1574 | in_node=0; |
4623 | |
1575 | |
4624 | if (!osm->nodes || !node_is_tagged || !nodeid) |
1576 | if (!out || ! node_is_tagged || ! nodeid) |
4625 | return; |
1577 | return; |
4626 | |
|
|
4627 | count = attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types) / sizeof(enum item_type)); |
1578 | count=attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types)/sizeof(enum item_type)); |
4628 | |
|
|
4629 | if (!count) |
1579 | if (!count) { |
4630 | { |
|
|
4631 | types[0] = type_point_unkn; |
1580 | types[0]=type_point_unkn; |
4632 | count = 1; |
1581 | count=1; |
4633 | } |
1582 | } |
4634 | |
|
|
4635 | dbg_assert(count < 10); |
1583 | dbg_assert(count < 10); |
4636 | |
|
|
4637 | for (i = 0; i < count; i++) |
1584 | for (i = 0 ; i < count ; i++) { |
4638 | { |
1585 | conflict=0; |
4639 | if (types[i] == type_none) |
1586 | if (types[i] == type_none) |
4640 | { |
|
|
4641 | continue; |
1587 | continue; |
4642 | } |
|
|
4643 | |
|
|
4644 | //if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) |
1588 | if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) |
4645 | // continue; |
|
|
4646 | |
|
|
4647 | if (ignore_unkown && (types[i] == type_point_unkn)) |
|
|
4648 | { |
|
|
4649 | continue; |
1589 | continue; |
4650 | } |
|
|
4651 | |
|
|
4652 | item_bin = init_item(types[i], 0); |
1590 | item_bin=init_item(types[i]); |
4653 | |
|
|
4654 | if (item_is_town(*item_bin) && attr_strings[attr_string_label]) |
|
|
4655 | { |
|
|
4656 | if (debug_itembin(ib)) |
|
|
4657 | { |
|
|
4658 | fprintf(stderr, "osm_end_node: have town: %s\n", attr_strings[attr_string_label]); |
|
|
4659 | } |
|
|
4660 | } |
|
|
4661 | |
|
|
4662 | if (item_is_town(*item_bin) && attr_strings[attr_string_population]) |
1591 | if (item_is_town(*item_bin) && attr_strings[attr_string_population]) |
4663 | { |
|
|
4664 | item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population])); |
1592 | item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population])); |
4665 | } |
|
|
4666 | |
|
|
4667 | item_bin_add_coord(item_bin, &ni->c, 1); |
1593 | item_bin_add_coord(item_bin, &ni->c, 1); |
4668 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]); |
1594 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]); |
4669 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
1595 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
4670 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
1596 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
4671 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
1597 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
4672 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
1598 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
4673 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
1599 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
4674 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
1600 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
4675 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
1601 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
4676 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
1602 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
4677 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
1603 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
4678 | |
|
|
4679 | postal = attr_strings[attr_string_postal]; |
1604 | postal=attr_strings[attr_string_postal]; |
4680 | if (postal) |
1605 | if (postal) { |
4681 | { |
|
|
4682 | char *sep = strchr(postal, ','); |
1606 | char *sep=strchr(postal,','); |
4683 | if (sep) |
1607 | if (sep) |
4684 | { |
|
|
4685 | *sep = '\0'; |
1608 | *sep='\0'; |
|
|
1609 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal); |
|
|
1610 | } |
|
|
1611 | item_bin_write(item_bin,out); |
|
|
1612 | if (item_is_town(*item_bin) && attr_strings[attr_string_label]) { |
|
|
1613 | char *tok,*buf=is_in_buffer; |
|
|
1614 | if (!buf[0]) |
|
|
1615 | strcpy(is_in_buffer, "Unknown"); |
|
|
1616 | while ((tok=strtok(buf, ",;"))) { |
|
|
1617 | while (*tok==' ') |
|
|
1618 | tok++; |
|
|
1619 | lookup=g_hash_table_lookup(country_table_hash,tok); |
|
|
1620 | if (lookup) { |
|
|
1621 | if (result && result->countryid != lookup->countryid) { |
|
|
1622 | osm_warning("node",nodeid,0,"conflict for %s %s country %d vs %d\n", attr_strings[attr_string_label], debug_attr_buffer, lookup->countryid, result->countryid); |
|
|
1623 | conflict=1; |
|
|
1624 | } |
|
|
1625 | result=lookup; |
|
|
1626 | } |
|
|
1627 | buf=NULL; |
4686 | } |
1628 | } |
4687 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal); |
1629 | if (result) { |
4688 | } |
1630 | if (!result->file) { |
4689 | |
1631 | char *name=g_strdup_printf("country_%d.bin.unsorted", result->countryid); |
4690 | item_bin_write(item_bin, osm->nodes); |
1632 | result->file=fopen(name,"wb"); |
4691 | |
1633 | g_free(name); |
4692 | if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) |
|
|
4693 | { |
|
|
4694 | item_bin = init_item(item_bin->type, 0); |
|
|
4695 | item_bin_add_coord(item_bin, &ni->c, 1); |
|
|
4696 | item_bin_add_attr_string(item_bin, attr_osm_is_in, is_in_buffer); |
|
|
4697 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
|
|
4698 | item_bin_add_attr_string(item_bin, attr_town_postal, postal); |
|
|
4699 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
|
|
4700 | item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]); |
|
|
4701 | if (attr_strings[attr_string_label_alt]) |
|
|
4702 | { |
|
|
4703 | item_bin_add_attr_string(item_bin, attr_town_name_match, attr_strings[attr_string_label_alt]); |
|
|
4704 | if (debug_itembin(item_bin)) |
|
|
4705 | { |
|
|
4706 | fprintf(stderr, "town name : %s\n", attr_strings[attr_string_label]); |
|
|
4707 | fprintf(stderr, "town name alt: %s\n", attr_strings[attr_string_label_alt]); |
|
|
4708 | } |
1634 | } |
|
|
1635 | if (result->file) { |
|
|
1636 | item_bin=init_item(item_bin->type); |
|
|
1637 | item_bin_add_coord(item_bin, &ni->c, 1); |
|
|
1638 | item_bin_add_attr_string(item_bin, attr_town_postal, postal); |
|
|
1639 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
|
|
1640 | item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]); |
|
|
1641 | item_bin_write_match(item_bin, attr_town_name, attr_town_name_match, result->file); |
|
|
1642 | } |
|
|
1643 | |
4709 | } |
1644 | } |
4710 | |
|
|
4711 | item_bin_write(item_bin, osm->towns); |
|
|
4712 | } |
|
|
4713 | |
|
|
4714 | //fprintf(stderr,"********DUMP nd1***********\n"); |
|
|
4715 | //if (types[i] == type_house_number) |
|
|
4716 | //{ |
|
|
4717 | // dump_itembin(item_bin); |
|
|
4718 | //} |
1645 | } |
4719 | //fprintf(stderr,"********DUMP nd1***********\n"); |
|
|
4720 | |
|
|
4721 | } |
1646 | } |
4722 | processed_nodes_out++; |
1647 | processed_nodes_out++; |
4723 | attr_longest_match_clear(); |
|
|
4724 | } |
1648 | } |
4725 | |
1649 | |
4726 | static struct country_table * |
1650 | void |
4727 | osm_process_town_unknown_country(void) |
|
|
4728 | { |
|
|
4729 | static struct country_table *unknown; |
|
|
4730 | unknown = country_from_countryid(999); |
|
|
4731 | return unknown; |
|
|
4732 | } |
|
|
4733 | |
|
|
4734 | static struct country_table * |
|
|
4735 | osm_process_item_fixed_country(void) |
|
|
4736 | { |
|
|
4737 | static struct country_table *fixed; |
|
|
4738 | fixed = country_from_countryid(global_fixed_country_id); |
|
|
4739 | return fixed; |
|
|
4740 | } |
|
|
4741 | |
|
|
4742 | static struct country_table * |
|
|
4743 | osm_process_town_by_is_in(struct item_bin *ib, char *is_in) |
|
|
4744 | { |
|
|
4745 | struct country_table *result = NULL, *lookup; |
|
|
4746 | char *tok, *dup = g_strdup(is_in), *buf = dup; |
|
|
4747 | int conflict; |
|
|
4748 | |
|
|
4749 | while ((tok = strtok(buf, ",;"))) |
|
|
4750 | { |
|
|
4751 | while (*tok == ' ') |
|
|
4752 | { |
|
|
4753 | tok++; |
|
|
4754 | } |
|
|
4755 | lookup = g_hash_table_lookup(country_table_hash, tok); |
|
|
4756 | if (lookup) |
|
|
4757 | { |
|
|
4758 | if (result && result->countryid != lookup->countryid) |
|
|
4759 | { |
|
|
4760 | //char *label = item_bin_get_attr(ib, attr_town_name, NULL); |
|
|
4761 | //osm_warning("node", item_bin_get_nodeid(ib), 0, "conflict for %s is_in=%s country %d vs %d\n", label, is_in, lookup->countryid, result->countryid); |
|
|
4762 | conflict = 1; |
|
|
4763 | } |
|
|
4764 | result = lookup; |
|
|
4765 | } |
|
|
4766 | buf = NULL; |
|
|
4767 | } |
|
|
4768 | g_free(dup); |
|
|
4769 | return result; |
|
|
4770 | } |
|
|
4771 | |
|
|
4772 | static int osm_process_street_by_boundary(GList *bl, long long town_osm_id, long long town_relation_id, struct coord *c) |
|
|
4773 | { |
|
|
4774 | GList *matches = NULL; |
|
|
4775 | |
|
|
4776 | matches = boundary_find_matches_single(bl, c); |
|
|
4777 | if (g_list_length(matches) > 0) |
|
|
4778 | { |
|
|
4779 | return 1; |
|
|
4780 | } |
|
|
4781 | |
|
|
4782 | return 0; |
|
|
4783 | } |
|
|
4784 | |
|
|
4785 | |
|
|
4786 | static struct country_table * |
|
|
4787 | osm_process_town_by_boundary(GList *bl, struct item_bin *ib, struct coord *c, struct attr *attrs) |
|
|
4788 | { |
|
|
4789 | GList *l, *matches = boundary_find_matches(bl, c); |
|
|
4790 | struct boundary *match = NULL; |
|
|
4791 | |
|
|
4792 | //fprintf(stderr,"town_by_boundary:001\n"); |
|
|
4793 | |
|
|
4794 | l = matches; |
|
|
4795 | while (l) |
|
|
4796 | { |
|
|
4797 | //fprintf(stderr,"town_by_boundary:002\n"); |
|
|
4798 | struct boundary *b = l->data; |
|
|
4799 | if (b->country) |
|
|
4800 | { |
|
|
4801 | //fprintf(stderr,"town_by_boundary:003\n"); |
|
|
4802 | //if (match) |
|
|
4803 | //{ |
|
|
4804 | //osm_warning("node", item_bin_get_nodeid(ib), 0, "node (x=0x%x,y=0x%x) conflict country ", c->x, c->y); |
|
|
4805 | //osm_warning("relation", boundary_relid(match), 1, "country %d vs ", match->country->countryid); |
|
|
4806 | //osm_warning("relation", boundary_relid(b), 1, "country %d\n", b->country->countryid); |
|
|
4807 | //} |
|
|
4808 | match = b; |
|
|
4809 | } |
|
|
4810 | l = g_list_next(l); |
|
|
4811 | } |
|
|
4812 | |
|
|
4813 | //fprintf(stderr,"town_by_boundary:004\n"); |
|
|
4814 | |
|
|
4815 | if (match) |
|
|
4816 | { |
|
|
4817 | //fprintf(stderr,"town_by_boundary:005\n"); |
|
|
4818 | if (match && match->country && match->country->admin_levels) |
|
|
4819 | { |
|
|
4820 | //fprintf(stderr,"town_by_boundary:006\n"); |
|
|
4821 | l = matches; |
|
|
4822 | while (l) |
|
|
4823 | { |
|
|
4824 | //fprintf(stderr,"town_by_boundary:007\n"); |
|
|
4825 | |
|
|
4826 | struct boundary *b = l->data; |
|
|
4827 | char *admin_level = osm_tag_value(b->ib, "admin_level"); |
|
|
4828 | char *postal = osm_tag_value(b->ib, "postal_code"); |
|
|
4829 | if (admin_level) |
|
|
4830 | { |
|
|
4831 | //fprintf(stderr,"town_by_boundary:008\n"); |
|
|
4832 | |
|
|
4833 | int a = atoi(admin_level); |
|
|
4834 | int end = strlen(match->country->admin_levels) + 3; |
|
|
4835 | char *name; |
|
|
4836 | if (a > 2 && a < end) |
|
|
4837 | { |
|
|
4838 | //fprintf(stderr,"town_by_boundary:009\n"); |
|
|
4839 | |
|
|
4840 | enum attr_type attr_type = attr_none; |
|
|
4841 | switch (match->country->admin_levels[a - 3]) |
|
|
4842 | { |
|
|
4843 | case 's': |
|
|
4844 | attr_type = attr_state_name; |
|
|
4845 | break; |
|
|
4846 | case 'c': |
|
|
4847 | attr_type = attr_county_name; |
|
|
4848 | break; |
|
|
4849 | case 'm': |
|
|
4850 | attr_type = attr_municipality_name; |
|
|
4851 | break; |
|
|
4852 | } |
|
|
4853 | name = osm_tag_value(b->ib, "name"); |
|
|
4854 | if (name && attr_type != attr_none) |
|
|
4855 | { |
|
|
4856 | //fprintf(stderr,"town_by_boundary:010\n"); |
|
|
4857 | attrs[a - 2].type = attr_type; |
|
|
4858 | attrs[a - 2].u.str = name; |
|
|
4859 | } |
|
|
4860 | } |
|
|
4861 | } |
|
|
4862 | if (postal) |
|
|
4863 | { |
|
|
4864 | //fprintf(stderr,"town_by_boundary:011\n"); |
|
|
4865 | attrs[0].type = attr_town_postal; |
|
|
4866 | attrs[0].u.str = postal; |
|
|
4867 | } |
|
|
4868 | l = g_list_next(l); |
|
|
4869 | } |
|
|
4870 | } |
|
|
4871 | return match->country; |
|
|
4872 | } |
|
|
4873 | else |
|
|
4874 | { |
|
|
4875 | //fprintf(stderr,"town_by_boundary:099\n"); |
|
|
4876 | return NULL; |
|
|
4877 | } |
|
|
4878 | } |
|
|
4879 | |
|
|
4880 | int town_size_estimate(int type) |
|
|
4881 | { |
|
|
4882 | int size = 0; // default -> not use this area as a town! |
|
|
4883 | |
|
|
4884 | switch (type) |
|
|
4885 | { |
|
|
4886 | case type_town_label_1e7: |
|
|
4887 | case type_town_label_5e6: |
|
|
4888 | case type_town_label_2e6: |
|
|
4889 | case type_town_label_1e6: |
|
|
4890 | case type_town_label_5e5: |
|
|
4891 | case type_town_label_2e5: |
|
|
4892 | size = 10000; |
|
|
4893 | break; |
|
|
4894 | case type_town_label_1e5: |
|
|
4895 | case type_town_label_5e4: |
|
|
4896 | case type_town_label_2e4: |
|
|
4897 | size = 3100; |
|
|
4898 | break; |
|
|
4899 | case type_town_label_1e4: |
|
|
4900 | case type_town_label_5e3: |
|
|
4901 | case type_town_label_2e3: |
|
|
4902 | size = 1460; |
|
|
4903 | break; |
|
|
4904 | case type_town_label_1e3: |
|
|
4905 | case type_town_label_5e2: |
|
|
4906 | // case type_town_label_2e2: |
|
|
4907 | case type_town_label_1e2: |
|
|
4908 | case type_town_label_5e1: |
|
|
4909 | case type_town_label_2e1: |
|
|
4910 | case type_town_label_1e1: |
|
|
4911 | case type_town_label_5e0: |
|
|
4912 | // case type_town_label_2e0: |
|
|
4913 | case type_town_label_1e0: |
|
|
4914 | case type_town_label_0e0: |
|
|
4915 | size = 660; |
|
|
4916 | break; |
|
|
4917 | default: |
|
|
4918 | break; |
|
|
4919 | } |
|
|
4920 | |
|
|
4921 | // size = size * global_search_street_size_factor; |
|
|
4922 | |
|
|
4923 | // lat factor 0.072 |
|
|
4924 | // lon factor 0.101 |
|
|
4925 | |
|
|
4926 | // size = 10000 |
|
|
4927 | // lat lon size = size / 100000 |
|
|
4928 | |
|
|
4929 | /* |
|
|
4930 | sel->u.c_rect.lu.x = c->x - size; |
|
|
4931 | sel->u.c_rect.lu.y = c->y + size; |
|
|
4932 | sel->u.c_rect.rl.x = c->x + size; |
|
|
4933 | sel->u.c_rect.rl.y = c->y - size; |
|
|
4934 | */ |
|
|
4935 | return size; |
|
|
4936 | } |
|
|
4937 | |
|
|
4938 | void assign_town_to_streets_v1(); |
|
|
4939 | void assign_town_to_streets_by_boundary(GList *bl); |
|
|
4940 | void copy_town_border_data(); |
|
|
4941 | |
|
|
4942 | void assign_town_to_streets(GList *bl) |
|
|
4943 | { |
|
|
4944 | int skipped = 0; |
|
|
4945 | |
|
|
4946 | copy_town_border_data(); |
|
|
4947 | assign_town_to_streets_by_boundary(bl); |
|
|
4948 | |
|
|
4949 | // now process all the left over towns |
|
|
4950 | assign_town_to_streets_v1(1); |
|
|
4951 | assign_town_to_streets_v1(2); // make townsize double on second pass |
|
|
4952 | } |
|
|
4953 | |
|
|
4954 | |
|
|
4955 | void copy_town_border_data() |
|
|
4956 | { |
|
|
4957 | long long bid; |
|
|
4958 | long long tid; |
|
|
4959 | int retval; |
|
|
4960 | int rc = 0; |
|
|
4961 | int commit_after = 20000; |
|
|
4962 | int count = 0; |
|
|
4963 | int admin_l = 99; |
|
|
4964 | |
|
|
4965 | sqlite3_stmt *stmt_d_1; |
|
|
4966 | sqlite3_stmt *stmt_d_2; |
|
|
4967 | retval = sqlite3_prepare_v2(sql_handle, "select border_id, id, admin_level from town2;", -1, &stmt_d_1, NULL); |
|
|
4968 | //fprintf(stderr, "prep:%d\n", retval); |
|
|
4969 | retval = sqlite3_prepare_v2(sql_handle, "update town set border_id = ?, size = ? where id = ?;", -1, &stmt_d_2, NULL); |
|
|
4970 | //fprintf(stderr, "prep:%d\n", retval); |
|
|
4971 | |
|
|
4972 | // loop thru all the towns |
|
|
4973 | do |
|
|
4974 | { |
|
|
4975 | rc = sqlite3_step(stmt_d_1); |
|
|
4976 | switch (rc) |
|
|
4977 | { |
|
|
4978 | case SQLITE_DONE: |
|
|
4979 | break; |
|
|
4980 | case SQLITE_ROW: |
|
|
4981 | bid = sqlite3_column_int64(stmt_d_1, 0); |
|
|
4982 | tid = sqlite3_column_int64(stmt_d_1, 1); |
|
|
4983 | admin_l = sqlite3_column_int(stmt_d_1, 2); |
|
|
4984 | |
|
|
4985 | //fprintf(stderr, "bid=%lld tid=%lld amdin_level=%d\n", bid, tid, admin_l); |
|
|
4986 | |
|
|
4987 | if (count == 0) |
|
|
4988 | { |
|
|
4989 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
4990 | } |
|
|
4991 | count++; |
|
|
4992 | |
|
|
4993 | sqlite3_bind_int64(stmt_d_2, 1, bid); |
|
|
4994 | sqlite3_bind_int64(stmt_d_2, 2, tid); |
|
|
4995 | sqlite3_bind_int(stmt_d_2, 3, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_l) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
|
|
4996 | sqlite3_step(stmt_d_2); |
|
|
4997 | sqlite3_reset(stmt_d_2); |
|
|
4998 | |
|
|
4999 | if (count > commit_after) |
|
|
5000 | { |
|
|
5001 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5002 | count = 0; |
|
|
5003 | } |
|
|
5004 | |
|
|
5005 | break; |
|
|
5006 | default: |
|
|
5007 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
5008 | break; |
|
|
5009 | } |
|
|
5010 | } |
|
|
5011 | while (rc == SQLITE_ROW); |
|
|
5012 | sqlite3_reset(stmt_d_1); |
|
|
5013 | |
|
|
5014 | retval = sqlite3_finalize(stmt_d_2); |
|
|
5015 | //fprintf(stderr, "fin:%d\n", retval); |
|
|
5016 | retval = sqlite3_finalize(stmt_d_1); |
|
|
5017 | //fprintf(stderr, "fin:%d\n", retval); |
|
|
5018 | |
|
|
5019 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5020 | |
|
|
5021 | } |
|
|
5022 | |
|
|
5023 | void assign_town_to_streets_by_boundary(GList *bl) |
|
|
5024 | { |
|
|
5025 | long long nd; |
|
|
5026 | long long wid; |
|
|
5027 | long long town_rel_id; |
|
|
5028 | int size; |
|
|
5029 | double lat; |
|
|
5030 | double lon; |
|
|
5031 | double temp; |
|
|
5032 | double lat_min; |
|
|
5033 | double lat_max; |
|
|
5034 | double lon_min; |
|
|
5035 | double lon_max; |
|
|
5036 | int rc; |
|
|
5037 | int rc2; |
|
|
5038 | long long town_count; |
|
|
5039 | long long town_processed_count; |
|
|
5040 | int town_steps = 1; |
|
|
5041 | int result = 0; |
|
|
5042 | struct boundary *bound_temp; |
|
|
5043 | |
|
|
5044 | sql_counter = 0; |
|
|
5045 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5046 | |
|
|
5047 | // number of towns in DB |
|
|
5048 | sqlite3_reset(stmt_town_sel002); |
|
|
5049 | sqlite3_step(stmt_town_sel002); |
|
|
5050 | town_count = sqlite3_column_int64(stmt_town_sel002, 0); |
|
|
5051 | town_processed_count = 0; |
|
|
5052 | |
|
|
5053 | fprintf(stderr, "towns0: %lld/%lld\n", town_processed_count, town_count); |
|
|
5054 | |
|
|
5055 | if (town_count == 0) |
|
|
5056 | { |
|
|
5057 | sqlite3_reset(stmt_town_sel002); |
|
|
5058 | return; |
|
|
5059 | } |
|
|
5060 | |
|
|
5061 | sql_counter = 0; |
|
|
5062 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5063 | |
|
|
5064 | if (town_count > 1000000) |
|
|
5065 | { |
|
|
5066 | town_steps = 500; |
|
|
5067 | } |
|
|
5068 | else if (town_count > 100000) |
|
|
5069 | { |
|
|
5070 | town_steps = 100; |
|
|
5071 | } |
|
|
5072 | else if (town_count > 10000) |
|
|
5073 | { |
|
|
5074 | town_steps = 10; |
|
|
5075 | } |
|
|
5076 | |
|
|
5077 | // DEBUG |
|
|
5078 | // town_steps = 1; |
|
|
5079 | // DEBUG |
|
|
5080 | |
|
|
5081 | // loop thru all the towns |
|
|
5082 | do |
|
|
5083 | { |
|
|
5084 | rc = sqlite3_step(stmt_town_sel001); |
|
|
5085 | switch (rc) |
|
|
5086 | { |
|
|
5087 | case SQLITE_DONE: |
|
|
5088 | break; |
|
|
5089 | case SQLITE_ROW: |
|
|
5090 | nd = sqlite3_column_int64(stmt_town_sel001, 0); |
|
|
5091 | town_rel_id = sqlite3_column_int64(stmt_town_sel001, 5); |
|
|
5092 | //size = sqlite3_column_int(stmt_town_sel001, 1); |
|
|
5093 | //lat = sqlite3_column_double(stmt_town_sel001, 2); |
|
|
5094 | //lon = sqlite3_column_double(stmt_town_sel001, 3); |
|
|
5095 | |
|
|
5096 | |
|
|
5097 | GList *match_town = NULL; |
|
|
5098 | GList *l = bl; |
|
|
5099 | int has_found = 0; |
|
|
5100 | |
|
|
5101 | if (town_rel_id != 0) |
|
|
5102 | { |
|
|
5103 | // fprintf(stderr ,"processing town name:%s id:%lld border_id:%lld\n", sqlite3_column_text(stmt_town_sel001, 4), nd, town_rel_id); |
|
|
5104 | |
|
|
5105 | while (l) |
|
|
5106 | { |
|
|
5107 | struct boundary *b = l->data; |
|
|
5108 | //fprintf(stderr, "bid=%lld tid=%lld\n", item_bin_get_relationid(b->ib), town_rel_id); |
|
|
5109 | if (item_bin_get_relationid(b->ib) == town_rel_id) |
|
|
5110 | { |
|
|
5111 | match_town = l; |
|
|
5112 | has_found = 1; |
|
|
5113 | //fprintf(stderr, "bid=%lld tid=%lld\n", item_bin_get_relationid(b->ib), town_rel_id); |
|
|
5114 | //fprintf(stderr, "*** town border found***\n"); |
|
|
5115 | break; |
|
|
5116 | } |
|
|
5117 | l = g_list_next(l); |
|
|
5118 | } |
|
|
5119 | } |
|
|
5120 | |
|
|
5121 | if (has_found == 1) |
|
|
5122 | { |
|
|
5123 | // now run thru all the ways |
|
|
5124 | do |
|
|
5125 | { |
|
|
5126 | // only select ways that are in the bounding box of boundary! |
|
|
5127 | |
|
|
5128 | bound_temp = match_town->data; |
|
|
5129 | lat_min = transform_to_geo_lat(bound_temp->r.l.y); |
|
|
5130 | lat_max = transform_to_geo_lat(bound_temp->r.h.y); |
|
|
5131 | lon_min = transform_to_geo_lon(bound_temp->r.l.x); |
|
|
5132 | lon_max = transform_to_geo_lon(bound_temp->r.h.x); |
|
|
5133 | |
|
|
5134 | //fprintf(stderr, "lat min:%f max:%f lon min:%f max:%f \n", lat_min, lat_max, lon_min, lon_max); |
|
|
5135 | |
|
|
5136 | sqlite3_bind_double(stmt_way3a, 1, lat_min); |
|
|
5137 | sqlite3_bind_double(stmt_way3a, 2, lat_max); |
|
|
5138 | sqlite3_bind_double(stmt_way3a, 3, lon_min); |
|
|
5139 | sqlite3_bind_double(stmt_way3a, 4, lon_max); |
|
|
5140 | rc2 = sqlite3_step(stmt_way3a); |
|
|
5141 | switch (rc2) |
|
|
5142 | { |
|
|
5143 | case SQLITE_DONE: |
|
|
5144 | break; |
|
|
5145 | case SQLITE_ROW: |
|
|
5146 | wid = sqlite3_column_int64(stmt_way3a, 0); |
|
|
5147 | lat = sqlite3_column_double(stmt_way3a, 1); |
|
|
5148 | lon = sqlite3_column_double(stmt_way3a, 2); |
|
|
5149 | |
|
|
5150 | struct coord c; |
|
|
5151 | c.x = transform_from_geo_lon(lon); |
|
|
5152 | c.y = transform_from_geo_lat(lat); |
|
|
5153 | |
|
|
5154 | //fprintf(stderr,"== street by boundary == x:%d y:%d ==\n", c.x, c.y); |
|
|
5155 | |
|
|
5156 | if (town_rel_id != 0) |
|
|
5157 | { |
|
|
5158 | // fprintf(stderr, "town:%lld\n", nd); |
|
|
5159 | // fprintf(stderr,"== street by boundary == x:%d y:%d ==\n", c.x, c.y); |
|
|
5160 | result = osm_process_street_by_boundary(match_town, nd, town_rel_id, &c); |
|
|
5161 | if (result == 1) |
|
|
5162 | { |
|
|
5163 | //fprintf(stderr,"== street by boundary == wid:%lld townid:%lld ==\n", wid, nd); |
|
|
5164 | // write "town id" to "way" |
|
|
5165 | if (sql_counter == 0) |
|
|
5166 | { |
|
|
5167 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5168 | } |
|
|
5169 | sql_counter++; |
|
|
5170 | sqlite3_bind_int64(stmt_way3b, 1, nd); |
|
|
5171 | sqlite3_bind_int64(stmt_way3b, 2, wid); |
|
|
5172 | sqlite3_step(stmt_way3b); |
|
|
5173 | sqlite3_reset(stmt_way3b); |
|
|
5174 | if (sql_counter > MAX_ROWS_WO_COMMIT_2b) |
|
|
5175 | { |
|
|
5176 | sql_counter = 0; |
|
|
5177 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5178 | } |
|
|
5179 | } |
|
|
5180 | } |
|
|
5181 | |
|
|
5182 | break; |
|
|
5183 | default: |
|
|
5184 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
5185 | break; |
|
|
5186 | } |
|
|
5187 | } |
|
|
5188 | while (rc2 == SQLITE_ROW); |
|
|
5189 | sqlite3_reset(stmt_way3a); |
|
|
5190 | |
|
|
5191 | |
|
|
5192 | // mark town as "done" |
|
|
5193 | if (sql_counter == 0) |
|
|
5194 | { |
|
|
5195 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5196 | } |
|
|
5197 | sql_counter++; |
|
|
5198 | sqlite3_bind_int64(stmt_town_sel007, 1, nd); |
|
|
5199 | sqlite3_step(stmt_town_sel007); |
|
|
5200 | sqlite3_reset(stmt_town_sel007); |
|
|
5201 | if (sql_counter > MAX_ROWS_WO_COMMIT_2b) |
|
|
5202 | { |
|
|
5203 | sql_counter = 0; |
|
|
5204 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5205 | } |
|
|
5206 | |
|
|
5207 | } |
|
|
5208 | |
|
|
5209 | town_processed_count++; |
|
|
5210 | if ((town_processed_count % town_steps) == 0) |
|
|
5211 | { |
|
|
5212 | fprintf(stderr, "towns0: %lld/%lld\n", town_processed_count, town_count); |
|
|
5213 | } |
|
|
5214 | |
|
|
5215 | break; |
|
|
5216 | default: |
|
|
5217 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
5218 | break; |
|
|
5219 | } |
|
|
5220 | } |
|
|
5221 | while (rc == SQLITE_ROW); |
|
|
5222 | sqlite3_reset(stmt_town_sel001); |
|
|
5223 | |
|
|
5224 | sql_counter = 0; |
|
|
5225 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5226 | } |
|
|
5227 | |
|
|
5228 | |
|
|
5229 | void assign_town_to_streets_v1(int pass_num) |
|
|
5230 | { |
|
|
5231 | |
|
|
5232 | long long nd; |
|
|
5233 | int size; |
|
|
5234 | double lat; |
|
|
5235 | double lon; |
|
|
5236 | double lat_min; |
|
|
5237 | double lat_max; |
|
|
5238 | double lon_min; |
|
|
5239 | double lon_max; |
|
|
5240 | double temp; |
|
|
5241 | int rc; |
|
|
5242 | long long town_count; |
|
|
5243 | long long town_processed_count; |
|
|
5244 | int town_steps = 1; |
|
|
5245 | |
|
|
5246 | sql_counter = 0; |
|
|
5247 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5248 | |
|
|
5249 | // number of towns in DB |
|
|
5250 | sqlite3_reset(stmt_town_sel002); |
|
|
5251 | sqlite3_step(stmt_town_sel002); |
|
|
5252 | town_count = sqlite3_column_int64(stmt_town_sel002, 0); |
|
|
5253 | town_processed_count = 0; |
|
|
5254 | |
|
|
5255 | fprintf(stderr, "towns1: %lld/%lld\n", town_processed_count, town_count); |
|
|
5256 | |
|
|
5257 | if (town_count == 0) |
|
|
5258 | { |
|
|
5259 | sqlite3_reset(stmt_town_sel002); |
|
|
5260 | return; |
|
|
5261 | } |
|
|
5262 | |
|
|
5263 | sql_counter = 0; |
|
|
5264 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5265 | |
|
|
5266 | if (town_count > 1000000) |
|
|
5267 | { |
|
|
5268 | town_steps = 500; |
|
|
5269 | } |
|
|
5270 | else if (town_count > 100000) |
|
|
5271 | { |
|
|
5272 | town_steps = 100; |
|
|
5273 | } |
|
|
5274 | else if (town_count > 10000) |
|
|
5275 | { |
|
|
5276 | town_steps = 10; |
|
|
5277 | } |
|
|
5278 | |
|
|
5279 | // DEBUG |
|
|
5280 | // town_steps = 1; |
|
|
5281 | // DEBUG |
|
|
5282 | |
|
|
5283 | // loop thru all the towns |
|
|
5284 | do |
|
|
5285 | { |
|
|
5286 | rc = sqlite3_step(stmt_town_sel001); |
|
|
5287 | switch (rc) |
|
|
5288 | { |
|
|
5289 | case SQLITE_DONE: |
|
|
5290 | break; |
|
|
5291 | case SQLITE_ROW: |
|
|
5292 | nd = sqlite3_column_int64(stmt_town_sel001, 0); |
|
|
5293 | size = sqlite3_column_int(stmt_town_sel001, 1); |
|
|
5294 | lat = sqlite3_column_double(stmt_town_sel001, 2); |
|
|
5295 | lon = sqlite3_column_double(stmt_town_sel001, 3); |
|
|
5296 | //fprintf(stderr ,"processing (size:%d) town name:%s id:%lld\n", size, sqlite3_column_text(stmt_town_sel001, 4), nd); |
|
|
5297 | |
|
|
5298 | // now update the ways |
|
|
5299 | if (sql_counter == 0) |
|
|
5300 | { |
|
|
5301 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5302 | } |
|
|
5303 | |
|
|
5304 | sqlite3_bind_int64(stmt_way3, 1, nd); |
|
|
5305 | |
|
|
5306 | if ((pass_num == 2) && (size > 0)) |
|
|
5307 | { |
|
|
5308 | size = size * 3; |
|
|
5309 | } |
|
|
5310 | |
|
|
5311 | temp = ((double) size) / 100000; |
|
|
5312 | lat_min = lat - temp; |
|
|
5313 | lat_max = lat + temp; |
|
|
5314 | lon_min = lon - temp; |
|
|
5315 | lon_max = lon + temp; |
|
|
5316 | sqlite3_bind_double(stmt_way3, 2, lat_min); |
|
|
5317 | sqlite3_bind_double(stmt_way3, 3, lat_max); |
|
|
5318 | sqlite3_bind_double(stmt_way3, 4, lon_min); |
|
|
5319 | sqlite3_bind_double(stmt_way3, 5, lon_max); |
|
|
5320 | //fprintf(stderr, "size korr:%f %f %f %f %f\n", temp, lat_min, lat_max, lon_min, lon_max); |
|
|
5321 | |
|
|
5322 | sqlite3_step(stmt_way3); |
|
|
5323 | sqlite3_reset(stmt_way3); |
|
|
5324 | |
|
|
5325 | sql_counter++; |
|
|
5326 | if (sql_counter > MAX_ROWS_WO_COMMIT_2a) |
|
|
5327 | { |
|
|
5328 | sql_counter = 0; |
|
|
5329 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5330 | } |
|
|
5331 | town_processed_count++; |
|
|
5332 | |
|
|
5333 | if ((town_processed_count % town_steps) == 0) |
|
|
5334 | { |
|
|
5335 | fprintf(stderr, "towns1: %lld/%lld\n", town_processed_count, town_count); |
|
|
5336 | } |
|
|
5337 | |
|
|
5338 | break; |
|
|
5339 | default: |
|
|
5340 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
5341 | break; |
|
|
5342 | } |
|
|
5343 | } |
|
|
5344 | while (rc == SQLITE_ROW); |
|
|
5345 | sqlite3_reset(stmt_town_sel001); |
|
|
5346 | |
|
|
5347 | sql_counter = 0; |
|
|
5348 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5349 | |
|
|
5350 | } |
|
|
5351 | |
|
|
5352 | |
|
|
5353 | int lat_lon_inside_rect(struct node_lat_lon *n, struct rect_lat_lon *r) |
|
|
5354 | { |
|
|
5355 | if ((n->lat >= r->lu_lat) && (n->lon >= r->lu_lon) && (n->lat <= r->rl_lat) && (n->lon <= r->rl_lon)) |
|
|
5356 | { |
|
|
5357 | return 1; |
|
|
5358 | } |
|
|
5359 | |
|
|
5360 | return 0; |
|
|
5361 | } |
|
|
5362 | |
|
|
5363 | GList* osm_process_towns(FILE *in, FILE *coords, FILE *boundaries, FILE *ways) |
|
|
5364 | { |
|
|
5365 | struct item_bin *ib; |
|
|
5366 | GList *bl = NULL; |
|
|
5367 | struct attr attrs[10]; |
|
|
5368 | time_t start_tt, end_tt; |
|
|
5369 | double diff_tt; |
|
|
5370 | double diff2_tt; |
|
|
5371 | long long size_in; |
|
|
5372 | long long pos_in; |
|
|
5373 | struct node_lat_lon node_coords; |
|
|
5374 | |
|
|
5375 | if (debug_itembin(1)) |
|
|
5376 | { |
|
|
5377 | fprintf(stderr, "osm_process_towns == START ==\n"); |
|
|
5378 | } |
|
|
5379 | |
|
|
5380 | //fprintf(stderr,"osm_process_towns == PB 001 %p,%p ==\n", boundaries, ways); |
|
|
5381 | |
|
|
5382 | time(&start_tt); |
|
|
5383 | bl = process_boundaries(boundaries, coords, ways); |
|
|
5384 | time(&end_tt); |
|
|
5385 | diff_tt = difftime(end_tt, start_tt); |
|
|
5386 | char outstring[200]; |
|
|
5387 | char outstring2[200]; |
|
|
5388 | char outstring3[200]; |
|
|
5389 | convert_to_human_time(diff_tt, outstring); |
|
|
5390 | fprintf(stderr, "-RUNTIME-BOUNDARIES: %s\n", outstring); |
|
|
5391 | |
|
|
5392 | int _c = 0; |
|
|
5393 | int _e = 10000; |
|
|
5394 | |
|
|
5395 | //fprintf(stderr,"osm_process_towns == PB 002 ==\n"); |
|
|
5396 | |
|
|
5397 | long long pos_now = ftello(in); // 64bit |
|
|
5398 | fseeko(in, 0, SEEK_END); |
|
|
5399 | size_in = ftello(in); // 64bit |
|
|
5400 | fseeko(in, pos_now, SEEK_SET); |
|
|
5401 | |
|
|
5402 | // reset timer |
|
|
5403 | diff2_tt = 0; |
|
|
5404 | _c = 0; |
|
|
5405 | time(&start_tt); |
|
|
5406 | |
|
|
5407 | while ((ib = read_item(in, 0))) |
|
|
5408 | { |
|
|
5409 | struct coord *c = (struct coord *) (ib + 1); |
|
|
5410 | struct country_table *result = NULL; |
|
|
5411 | char *is_in = item_bin_get_attr(ib, attr_osm_is_in, NULL); |
|
|
5412 | int i; |
|
|
5413 | |
|
|
5414 | _c++; |
|
|
5415 | |
|
|
5416 | if (debug_itembin(ib)) |
|
|
5417 | { |
|
|
5418 | fprintf(stderr, "== item ==\n"); |
|
|
5419 | dump_itembin(ib); |
|
|
5420 | } |
|
|
5421 | |
|
|
5422 | memset(attrs, 0, sizeof(attrs)); |
|
|
5423 | if (debug_itembin(ib)) |
|
|
5424 | { |
|
|
5425 | fprintf(stderr, "== osm_process_town_by_boundary ==\n"); |
|
|
5426 | } |
|
|
5427 | |
|
|
5428 | if (use_global_fixed_country_id == 1) |
|
|
5429 | { |
|
|
5430 | result = osm_process_item_fixed_country(); |
|
|
5431 | if (debug_itembin(ib)) |
|
|
5432 | { |
|
|
5433 | if (result == NULL) |
|
|
5434 | { |
|
|
5435 | fprintf(stderr, "== osm_process_item_fixed_country == #NULL# ==\n"); |
|
|
5436 | } |
|
|
5437 | else |
|
|
5438 | { |
|
|
5439 | fprintf(stderr, "== osm_process_item_fixed_country == %d %s ==\n", result->countryid, result->names); |
|
|
5440 | } |
|
|
5441 | } |
|
|
5442 | } |
|
|
5443 | |
|
|
5444 | if (!result) |
|
|
5445 | { |
|
|
5446 | //char *name=item_bin_get_attr(ib, attr_town_name, NULL); |
|
|
5447 | //fprintf(stderr,"== town by boundary == t:%s ==\n", name); |
|
|
5448 | |
|
|
5449 | result = osm_process_town_by_boundary(bl, ib, c, attrs); |
|
|
5450 | if (result) // DEBUG |
|
|
5451 | { |
|
|
5452 | //fprintf(stderr,"== town by boundary == country_id:%d country_name:%s ==\n", result->countryid, result->names); |
|
|
5453 | } |
|
|
5454 | } |
|
|
5455 | |
|
|
5456 | if (!result) |
|
|
5457 | { |
|
|
5458 | if (debug_itembin(ib)) |
|
|
5459 | { |
|
|
5460 | fprintf(stderr, "== osm_process_town_by_is_in == %s ==\n", is_in); |
|
|
5461 | } |
|
|
5462 | result = osm_process_town_by_is_in(ib, is_in); |
|
|
5463 | if (result) // DEBUG |
|
|
5464 | { |
|
|
5465 | // fprintf(stderr,"== town by is_in == country_id:%d country_name:%s ==\n", result->countryid, result->names); |
|
|
5466 | } |
|
|
5467 | } |
|
|
5468 | |
|
|
5469 | if (!result && unknown_country) |
|
|
5470 | { |
|
|
5471 | if (debug_itembin(ib)) |
|
|
5472 | { |
|
|
5473 | fprintf(stderr, "== osm_process_town_unknown_country ==\n"); |
|
|
5474 | } |
|
|
5475 | result = osm_process_town_unknown_country(); |
|
|
5476 | } |
|
|
5477 | |
|
|
5478 | if (result) |
|
|
5479 | { |
|
|
5480 | if (!result->file) |
|
|
5481 | { |
|
|
5482 | char *name = g_strdup_printf("country_%d.unsorted.tmp", result->countryid); |
|
|
5483 | result->file = fopen(name, "wb"); |
|
|
5484 | |
|
|
5485 | if (debug_itembin(ib)) |
|
|
5486 | { |
|
|
5487 | fprintf(stderr, "== create: country_%d.unsorted.tmp == FILEP: %p ==\n", result->countryid, result->file); |
|
|
5488 | } |
|
|
5489 | |
|
|
5490 | g_free(name); |
|
|
5491 | } |
|
|
5492 | |
|
|
5493 | if (result->file) |
|
|
5494 | { |
|
|
5495 | long long *nodeid; |
|
|
5496 | long long nd_id = item_bin_get_nodeid(ib); |
|
|
5497 | if (is_in) |
|
|
5498 | { |
|
|
5499 | item_bin_remove_attr(ib, is_in); |
|
|
5500 | } |
|
|
5501 | nodeid = item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
|
|
5502 | if (nodeid) |
|
|
5503 | { |
|
|
5504 | item_bin_remove_attr(ib, nodeid); |
|
|
5505 | } |
|
|
5506 | |
|
|
5507 | char *postal = NULL; |
|
|
5508 | char *postal2 = NULL; |
|
|
5509 | //if (attrs[0].type != attr_none) // what does this line do?? |
|
|
5510 | //{ |
|
|
5511 | postal = item_bin_get_attr(ib, attr_town_postal, NULL); |
|
|
5512 | if (postal) |
|
|
5513 | { |
|
|
5514 | postal2 = g_strdup_printf("%s", postal); |
|
|
5515 | // --- item_bin_remove_attr(ib, postal); |
|
|
5516 | // fprintf(stderr, "town postal:%s\n", postal2); |
|
|
5517 | } |
|
|
5518 | //} |
|
|
5519 | |
|
|
5520 | for (i = 0; i < 10; i++) |
|
|
5521 | { |
|
|
5522 | if (attrs[i].type != attr_none) |
|
|
5523 | { |
|
|
5524 | item_bin_add_attr(ib, &attrs[i]); |
|
|
5525 | } |
|
|
5526 | } |
|
|
5527 | |
|
|
5528 | if (sql_counter == 0) |
|
|
5529 | { |
|
|
5530 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5531 | } |
|
|
5532 | |
|
|
5533 | if (nd_id) |
|
|
5534 | { |
|
|
5535 | // town size (will later be translated into radius) |
|
|
5536 | int twn_size = town_size_estimate(ib->type); |
|
|
5537 | |
|
|
5538 | if (twn_size > 0) |
|
|
5539 | { |
|
|
5540 | |
|
|
5541 | sqlite3_bind_int64(stmt_town, 1, nd_id); |
|
|
5542 | if (result->countryid) |
|
|
5543 | { |
|
|
5544 | sqlite3_bind_int(stmt_town, 2, result->countryid); |
|
|
5545 | } |
|
|
5546 | else |
|
|
5547 | { |
|
|
5548 | sqlite3_bind_int(stmt_town, 2, 999); |
|
|
5549 | } |
|
|
5550 | |
|
|
5551 | sqlite3_bind_int(stmt_town, 4, twn_size); |
|
|
5552 | |
|
|
5553 | char *label_t = item_bin_get_attr(ib, attr_town_name, NULL); |
|
|
5554 | //fprintf(stderr, "town: %lld,%d,%s\n", nd_id, result->countryid, label_t); |
|
|
5555 | |
|
|
5556 | sqlite3_bind_text(stmt_town, 3, label_t, -1, SQLITE_STATIC); |
|
|
5557 | |
|
|
5558 | if (postal2) |
|
|
5559 | { |
|
|
5560 | sqlite3_bind_text(stmt_town, 5, postal2, -1, SQLITE_STATIC); |
|
|
5561 | } |
|
|
5562 | else |
|
|
5563 | { |
|
|
5564 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
|
|
5565 | } |
|
|
5566 | |
|
|
5567 | get_lat_lon_for_node(nd_id, &node_coords); |
|
|
5568 | if (node_coords.valid == 1) |
|
|
5569 | { |
|
|
5570 | sqlite3_bind_double(stmt_town, 6, node_coords.lat); |
|
|
5571 | sqlite3_bind_double(stmt_town, 7, node_coords.lon); |
|
|
5572 | } |
|
|
5573 | |
|
|
5574 | sqlite3_step(stmt_town); |
|
|
5575 | sqlite3_reset(stmt_town); |
|
|
5576 | sql_counter++; |
|
|
5577 | |
|
|
5578 | if (postal2) |
|
|
5579 | { |
|
|
5580 | g_free(postal2); |
|
|
5581 | } |
|
|
5582 | |
|
|
5583 | } |
|
|
5584 | } |
|
|
5585 | |
|
|
5586 | if (sql_counter > MAX_ROWS_WO_COMMIT_5) |
|
|
5587 | { |
|
|
5588 | sql_counter = 0; |
|
|
5589 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5590 | //fprintf(stderr, "SQL: COMMIT\n"); |
|
|
5591 | } |
|
|
5592 | |
|
|
5593 | // ** used until 2011-11-06 seems bad ** item_bin_write_match(ib, attr_town_name, attr_town_name_match, result->file); |
|
|
5594 | item_bin_town_write_match(ib, attr_town_name, attr_town_name_match, result->file); |
|
|
5595 | // ** origname ** item_bin_write(ib,result->file); |
|
|
5596 | } |
|
|
5597 | } |
|
|
5598 | else |
|
|
5599 | { |
|
|
5600 | if (debug_itembin(ib)) |
|
|
5601 | { |
|
|
5602 | fprintf(stderr, "== no result ==\n"); |
|
|
5603 | } |
|
|
5604 | } |
|
|
5605 | |
|
|
5606 | if (_c > _e) |
|
|
5607 | { |
|
|
5608 | _c = 0; |
|
|
5609 | |
|
|
5610 | pos_in = ftello(in); // 64bit |
|
|
5611 | time(&end_tt); |
|
|
5612 | diff_tt = difftime(end_tt, start_tt); |
|
|
5613 | convert_to_human_time(diff_tt, outstring); |
|
|
5614 | convert_to_human_bytes(pos_in, outstring2); |
|
|
5615 | convert_to_human_bytes(size_in, outstring3); |
|
|
5616 | fprintf(stderr, "-RUNTIME-LOOP-TOWN: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3); |
|
|
5617 | if (pos_in > 0) |
|
|
5618 | { |
|
|
5619 | double eta_time = (diff_tt / (pos_in)) * (size_in); |
|
|
5620 | convert_to_human_time(eta_time, outstring); |
|
|
5621 | fprintf(stderr, "-RUNTIME-LOOP-TOWN: %s left\n", outstring); |
|
|
5622 | } |
|
|
5623 | } |
|
|
5624 | } |
|
|
5625 | |
|
|
5626 | if (debug_itembin(1)) |
|
|
5627 | { |
|
|
5628 | fprintf(stderr, "osm_process_towns == END ==\n"); |
|
|
5629 | } |
|
|
5630 | |
|
|
5631 | return bl; |
|
|
5632 | |
|
|
5633 | } |
|
|
5634 | |
|
|
5635 | void sort_countries(int keep_tmpfiles) |
1651 | sort_countries(int keep_tmpfiles) |
5636 | { |
1652 | { |
5637 | int i; |
1653 | int i; |
5638 | struct country_table *co; |
1654 | struct country_table *co; |
5639 | char *name_in, *name_out; |
1655 | char *name_in,*name_out; |
5640 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
1656 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { |
5641 | { |
|
|
5642 | co = &country_table[i]; |
1657 | co=&country_table[i]; |
5643 | if (co->file) |
1658 | if (co->file) { |
5644 | { |
|
|
5645 | fclose(co->file); |
1659 | fclose(co->file); |
5646 | co->file = NULL; |
1660 | co->file=NULL; |
5647 | } |
1661 | } |
5648 | name_in = g_strdup_printf("country_%d.unsorted.tmp", co->countryid); |
1662 | name_in=g_strdup_printf("country_%d.bin.unsorted", co->countryid); |
5649 | name_out = g_strdup_printf("country_%d.tmp", co->countryid); |
1663 | name_out=g_strdup_printf("country_%d.bin", co->countryid); |
5650 | |
|
|
5651 | if (debug_itembin(2)) |
|
|
5652 | { |
|
|
5653 | fprintf(stderr, "in=country_%d.unsorted.tmp\n", co->countryid); |
|
|
5654 | fprintf(stderr, "out=country_%d.tmp\n", co->countryid); |
|
|
5655 | } |
|
|
5656 | |
|
|
5657 | co->r = world_bbox; |
1664 | co->r=world_bbox; |
5658 | item_bin_sort_file(name_in, name_out, &co->r, &co->size); |
1665 | item_bin_sort_file(name_in, name_out, &co->r, &co->size); |
5659 | if (!keep_tmpfiles) |
1666 | if (!keep_tmpfiles) |
5660 | { |
|
|
5661 | unlink(name_in); |
1667 | unlink(name_in); |
5662 | } |
|
|
5663 | g_free(name_in); |
1668 | g_free(name_in); |
5664 | g_free(name_out); |
1669 | g_free(name_out); |
5665 | } |
1670 | } |
5666 | } |
1671 | } |
5667 | |
1672 | |
|
|
1673 | struct relation_member { |
|
|
1674 | int type; |
|
|
1675 | long long id; |
|
|
1676 | char *role; |
|
|
1677 | }; |
|
|
1678 | |
|
|
1679 | static int |
|
|
1680 | get_relation_member(char *str, struct relation_member *memb) |
|
|
1681 | { |
|
|
1682 | int len; |
|
|
1683 | sscanf(str,"%d:"LONGLONG_FMT":%n",&memb->type,&memb->id,&len); |
|
|
1684 | memb->role=str+len; |
|
|
1685 | return 1; |
|
|
1686 | } |
|
|
1687 | |
|
|
1688 | static int |
5668 | static int search_relation_member(struct item_bin *ib, char *role, struct relation_member *memb, int *min_count) |
1689 | search_relation_member(struct item_bin *ib, char *role, struct relation_member *memb, int *min_count) |
5669 | { |
1690 | { |
5670 | char *str = NULL; |
1691 | char *str=NULL; |
5671 | int count = 0; |
1692 | int count=0; |
5672 | while ((str = item_bin_get_attr(ib, attr_osm_member, str))) |
1693 | while ((str=item_bin_get_attr(ib, attr_osm_member, str))) { |
5673 | { |
|
|
5674 | if (!get_relation_member(str, memb)) |
1694 | if (!get_relation_member(str, memb)) |
5675 | return 0; |
1695 | return 0; |
5676 | count++; |
1696 | count++; |
5677 | if (!strcmp(memb->role, role) && (!min_count || *min_count < count)) |
1697 | if (!strcmp(memb->role, role) && (!min_count || *min_count < count)) { |
5678 | { |
|
|
5679 | if (min_count) |
1698 | if (min_count) |
5680 | *min_count = count; |
1699 | *min_count=count; |
5681 | return 1; |
1700 | return 1; |
5682 | } |
1701 | } |
5683 | } |
1702 | } |
5684 | return 0; |
1703 | return 0; |
5685 | } |
1704 | } |
5686 | |
1705 | |
|
|
1706 | static int |
5687 | static int load_way_index(FILE *ways_index, int p, long long *idx) |
1707 | load_way_index(FILE *ways_index, int p, long long *idx) |
5688 | { |
1708 | { |
5689 | int step = sizeof(*idx) * 2; |
1709 | int step=sizeof(*idx)*2; |
5690 | fseek(ways_index, p * step, SEEK_SET); |
1710 | fseek(ways_index, p*step, SEEK_SET); |
5691 | if (fread(idx, step, 1, ways_index) != 1) |
1711 | if (fread(idx, step, 1, ways_index) != 1) { |
5692 | { |
|
|
5693 | fprintf(stderr, "read failed\n"); |
1712 | fprintf(stderr,"read failed\n"); |
5694 | return 0; |
1713 | return 0; |
5695 | } |
1714 | } |
5696 | return 1; |
1715 | return 1; |
5697 | } |
1716 | } |
5698 | |
1717 | |
|
|
1718 | |
|
|
1719 | static int |
5699 | static int seek_to_way(FILE *way, FILE *ways_index, long long wayid) |
1720 | seek_to_way(FILE *way, FILE *ways_index, long long wayid) |
5700 | { |
1721 | { |
5701 | long offset; |
1722 | long offset; |
5702 | long long idx[2]; |
1723 | long long idx[2]; |
5703 | int count, interval, p; |
1724 | int count,interval,p; |
5704 | void *p_tmp; |
|
|
5705 | int rr; |
|
|
5706 | size_t data_size2 = sizeof(int *); |
|
|
5707 | |
|
|
5708 | fprintf(stderr, "seek_to_way ---\n"); |
|
|
5709 | |
|
|
5710 | if (way_hash_cfu) |
1725 | if (way_hash) { |
5711 | { |
|
|
5712 | //if (!(g_hash_table_lookup_extended(way_hash, (gpointer) (long) wayid, NULL, (gpointer) & offset))) |
1726 | if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long)wayid, NULL, (gpointer)&offset))) |
5713 | //{ |
|
|
5714 | // return 0; |
|
|
5715 | //} |
|
|
5716 | |
|
|
5717 | rr = cfuhash_get_data(way_hash_cfu, (long long) wayid, sizeof(long long), &p_tmp, &data_size2); |
|
|
5718 | if (rr == 0) |
|
|
5719 | { |
|
|
5720 | return 0; |
1727 | return 0; |
5721 | } |
|
|
5722 | |
|
|
5723 | // printf("got value %ld\n", p_tmp); |
|
|
5724 | offset = p_tmp; |
|
|
5725 | |
|
|
5726 | fseek(way, offset, SEEK_SET); |
1728 | fseek(way, offset, SEEK_SET); |
5727 | return 1; |
1729 | return 1; |
5728 | } |
1730 | } |
5729 | |
|
|
5730 | fprintf(stderr, "**BAD**WAYSTUFF**\n"); |
|
|
5731 | |
|
|
5732 | fseek(ways_index, 0, SEEK_END); |
1731 | fseek(ways_index, 0, SEEK_END); |
5733 | count = ftell(ways_index) / sizeof(idx); |
1732 | count=ftell(ways_index)/sizeof(idx); |
5734 | interval = count / 4; |
1733 | interval=count/4; |
5735 | p = count / 2; |
1734 | p=count/2; |
5736 | if (interval == 0) |
1735 | if(interval==0) { |
5737 | { |
|
|
5738 | // If fewer than 4 nodes defined so far set interval to 1 to |
1736 | // If fewer than 4 nodes defined so far set interval to 1 to |
5739 | // avoid infinite loop |
1737 | // avoid infinite loop |
5740 | interval = 1; |
1738 | interval = 1; |
5741 | } |
1739 | } |
5742 | if (!load_way_index(ways_index, p, idx)) |
1740 | if (!load_way_index(ways_index, p, idx)) |
5743 | return 0; |
1741 | return 0; |
5744 | for (;;) |
1742 | for (;;) { |
5745 | { |
|
|
5746 | if (idx[0] == wayid) |
1743 | if (idx[0] == wayid) { |
5747 | { |
|
|
5748 | fseek(way, idx[1], SEEK_SET); |
1744 | fseek(way, idx[1], SEEK_SET); |
5749 | return 1; |
1745 | return 1; |
5750 | } |
1746 | } |
5751 | if (idx[0] < wayid) |
1747 | if (idx[0] < wayid) { |
5752 | { |
|
|
5753 | p += interval; |
1748 | p+=interval; |
5754 | if (interval == 1) |
1749 | if (interval == 1) { |
5755 | { |
|
|
5756 | if (p >= count) |
1750 | if (p >= count) |
5757 | return 0; |
1751 | return 0; |
5758 | if (!load_way_index(ways_index, p, idx)) |
1752 | if (!load_way_index(ways_index, p, idx)) |
5759 | return 0; |
1753 | return 0; |
5760 | if (idx[0] > wayid) |
1754 | if (idx[0] > wayid) |
5761 | return 0; |
1755 | return 0; |
5762 | } |
|
|
5763 | else |
1756 | } else { |
5764 | { |
|
|
5765 | if (p >= count) |
1757 | if (p >= count) |
5766 | p = count - 1; |
1758 | p=count-1; |
5767 | if (!load_way_index(ways_index, p, idx)) |
1759 | if (!load_way_index(ways_index, p, idx)) |
5768 | return 0; |
1760 | return 0; |
5769 | } |
1761 | } |
5770 | } |
|
|
5771 | else |
1762 | } else { |
5772 | { |
|
|
5773 | p -= interval; |
1763 | p-=interval; |
5774 | if (interval == 1) |
1764 | if (interval == 1) { |
5775 | { |
|
|
5776 | if (p < 0) |
1765 | if (p < 0) |
5777 | return 0; |
1766 | return 0; |
5778 | if (!load_way_index(ways_index, p, idx)) |
1767 | if (!load_way_index(ways_index, p, idx)) |
5779 | return 0; |
1768 | return 0; |
5780 | if (idx[0] < wayid) |
1769 | if (idx[0] < wayid) |
5781 | return 0; |
1770 | return 0; |
5782 | } |
|
|
5783 | else |
1771 | } else { |
5784 | { |
|
|
5785 | if (p < 0) |
1772 | if (p < 0) |
5786 | p = 0; |
1773 | p=0; |
5787 | if (!load_way_index(ways_index, p, idx)) |
1774 | if (!load_way_index(ways_index, p, idx)) |
5788 | return 0; |
1775 | return 0; |
5789 | } |
1776 | } |
5790 | } |
1777 | } |
5791 | if (interval > 1) |
1778 | if (interval > 1) |
5792 | interval /= 2; |
1779 | interval/=2; |
5793 | } |
1780 | } |
5794 | } |
1781 | } |
|
|
1782 | |
5795 | |
1783 | |
5796 | static struct coord * |
1784 | static struct coord * |
5797 | get_way(FILE *way, FILE *ways_index, struct coord *c, long long wayid, struct item_bin *ret, int debug) |
1785 | get_way(FILE *way, FILE *ways_index, struct coord *c, long long wayid, struct item_bin *ret, int debug) |
5798 | { |
1786 | { |
5799 | long long currid; |
1787 | long long currid; |
5800 | int last; |
1788 | int last; |
5801 | struct coord *ic; |
1789 | struct coord *ic; |
5802 | if (!seek_to_way(way, ways_index, wayid)) |
1790 | if (!seek_to_way(way, ways_index, wayid)) { |
5803 | { |
|
|
5804 | if (debug) |
1791 | if (debug) |
5805 | { |
|
|
5806 | fprintf(stderr, "not found in index"); |
1792 | fprintf(stderr,"not found in index"); |
5807 | } |
|
|
5808 | return NULL; |
1793 | return NULL; |
5809 | } |
1794 | } |
5810 | |
|
|
5811 | while (item_bin_read(ret, way)) |
1795 | while (item_bin_read(ret, way)) { |
5812 | { |
|
|
5813 | currid = item_bin_get_wayid(ret); |
1796 | currid=item_bin_get_wayid(ret); |
5814 | if (debug) |
1797 | if (debug) |
5815 | fprintf(stderr,LONGLONG_FMT":",currid); |
1798 | fprintf(stderr,LONGLONG_FMT":",currid); |
5816 | if (currid != wayid) |
1799 | if (currid != wayid) |
5817 | return NULL; |
1800 | return NULL; |
5818 | ic = (struct coord *) (ret + 1); |
1801 | ic=(struct coord *)(ret+1); |
5819 | last = ret->clen / 2 - 1; |
1802 | last=ret->clen/2-1; |
5820 | if (debug) |
1803 | if (debug) |
5821 | fprintf(stderr, "(0x%x,0x%x)-(0x%x,0x%x)", ic[0].x, ic[0].y, ic[last].x, ic[last].y); |
1804 | fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)",ic[0].x,ic[0].y,ic[last].x,ic[last].y); |
5822 | if (!c) |
1805 | if (!c) |
5823 | return &ic[0]; |
1806 | return &ic[0]; |
5824 | if (ic[0].x == c->x && ic[0].y == c->y) |
1807 | if (ic[0].x == c->x && ic[0].y == c->y) |
5825 | return &ic[last]; |
1808 | return &ic[last]; |
5826 | if (ic[last].x == c->x && ic[last].y == c->y) |
1809 | if (ic[last].x == c->x && ic[last].y == c->y) |
5827 | return &ic[0]; |
1810 | return &ic[0]; |
5828 | } |
1811 | } |
5829 | return NULL; |
1812 | return NULL; |
5830 | } |
1813 | } |
5831 | |
1814 | |
5832 | struct turn_restriction |
1815 | void |
|
|
1816 | process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) |
5833 | { |
1817 | { |
5834 | osmid relid; |
1818 | struct relation_member fromm,tom,viam,tmpm; |
5835 | enum item_type type; |
1819 | struct node_item ni; |
5836 | struct coord *c[3]; |
1820 | long long relid; |
|
|
1821 | char from_buffer[65536],to_buffer[65536],via_buffer[65536]; |
|
|
1822 | struct item_bin *ib,*from=(struct item_bin *)from_buffer,*to=(struct item_bin *)to_buffer,*via=(struct item_bin *)via_buffer; |
|
|
1823 | struct coord *fromc,*toc,*viafrom,*viato,*tmp; |
|
|
1824 | fseek(in, 0, SEEK_SET); |
5837 | int c_count[3]; |
1825 | int min_count; |
5838 | }; |
1826 | while ((ib=read_item(in))) { |
5839 | |
1827 | relid=item_bin_get_relationid(ib); |
5840 | static void process_turn_restrictions_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) |
1828 | min_count=0; |
5841 | { |
1829 | if (!search_relation_member(ib, "from",&fromm,&min_count)) { |
5842 | int count, type = (long) member_priv; |
1830 | osm_warning("relation",relid,0,"turn restriction: from member missing\n"); |
5843 | struct turn_restriction *turn_restriction = relation_priv; |
1831 | continue; |
5844 | struct coord *c = (struct coord *) (member + 1); |
|
|
5845 | int ccount = member->clen / 2; |
|
|
5846 | |
|
|
5847 | if (member->type < type_line) |
|
|
5848 | { |
|
|
5849 | count = 1; |
|
|
5850 | } |
1832 | } |
5851 | else |
1833 | if (search_relation_member(ib, "from",&tmpm,&min_count)) { |
5852 | { |
1834 | osm_warning("relation",relid,0,"turn restriction: multiple from members\n"); |
5853 | count = 2; |
1835 | continue; |
5854 | }turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count); |
|
|
5855 | turn_restriction->c[type][turn_restriction->c_count[type]++] = c[0]; |
|
|
5856 | if (count > 1) |
|
|
5857 | { |
|
|
5858 | turn_restriction->c[type][turn_restriction->c_count[type]++] = c[ccount - 1]; |
|
|
5859 | } |
1836 | } |
5860 | } |
1837 | min_count=0; |
5861 | |
1838 | if (!search_relation_member(ib, "to",&tom,&min_count)) { |
5862 | static void process_turn_restrictions_fromto(struct turn_restriction *t, int type, struct coord **c) |
1839 | osm_warning("relation",relid,0,"turn restriction: to member missing\n"); |
5863 | { |
1840 | continue; |
5864 | int i, j; |
1841 | } |
5865 | for (i = 0; i < t->c_count[type]; i += 2) |
1842 | if (search_relation_member(ib, "to",&tmpm,&min_count)) { |
5866 | { |
1843 | osm_warning("relation",relid,0,"turn restriction: multiple to members\n"); |
5867 | for (j = 0; j < t->c_count[1]; j++) |
1844 | continue; |
5868 | { |
1845 | } |
5869 | if (coord_is_equal(t->c[type][i], t->c[1][j])) |
1846 | min_count=0; |
5870 | { |
1847 | if (!search_relation_member(ib, "via",&viam,&min_count)) { |
5871 | c[0] = &t->c[type][i + 1]; |
1848 | osm_warning("relation",relid,0,"turn restriction: via member missing\n"); |
5872 | c[1] = &t->c[type][i]; |
1849 | continue; |
5873 | return; |
1850 | } |
|
|
1851 | if (search_relation_member(ib, "via",&tmpm,&min_count)) { |
|
|
1852 | osm_warning("relation",relid,0,"turn restriction: multiple via member\n"); |
|
|
1853 | continue; |
|
|
1854 | } |
|
|
1855 | if (fromm.type != 2) { |
|
|
1856 | osm_warning("relation",relid,0,"turn restriction: wrong type for from member "); |
|
|
1857 | osm_warning(osm_types[fromm.type],fromm.id,1,"\n"); |
|
|
1858 | continue; |
|
|
1859 | } |
|
|
1860 | if (tom.type != 2) { |
|
|
1861 | osm_warning("relation",relid,0,"turn restriction: wrong type for to member "); |
|
|
1862 | osm_warning(osm_types[tom.type],tom.id,1,"\n"); |
|
|
1863 | continue; |
|
|
1864 | } |
|
|
1865 | if (viam.type != 1 && viam.type != 2) { |
|
|
1866 | osm_warning("relation",relid,0,"turn restriction: wrong type for via member "); |
|
|
1867 | osm_warning(osm_types[viam.type],viam.id,1,"\n"); |
|
|
1868 | continue; |
|
|
1869 | } |
|
|
1870 | if (viam.type == 1) { |
|
|
1871 | if (!node_item_get_from_file(coords, viam.id, &ni)) { |
|
|
1872 | osm_warning("relation",relid,0,"turn restriction: failed to get via member "); |
|
|
1873 | osm_warning(osm_types[viam.type],viam.id,1,"\n"); |
|
|
1874 | continue; |
5874 | } |
1875 | } |
5875 | if (coord_is_equal(t->c[type][i + 1], t->c[1][j])) |
1876 | viafrom=&ni.c; |
5876 | { |
1877 | viato=&ni.c; |
5877 | c[0] = &t->c[type][i]; |
1878 | } else { |
5878 | c[1] = &t->c[type][i + 1]; |
1879 | if (!(viafrom=get_way(ways, ways_index, NULL, viam.id, via, 0))) { |
5879 | return; |
1880 | osm_warning("relation",relid,0,"turn restriction: failed to get first via coordinate from "); |
|
|
1881 | osm_warning(osm_types[viam.type],viam.id,1,"\n"); |
|
|
1882 | continue; |
5880 | } |
1883 | } |
|
|
1884 | if (!(viato=get_way(ways, ways_index, viafrom, viam.id, via, 0))) { |
|
|
1885 | osm_warning("relation",relid,0,"turn restriction: failed to get last via coordinate from "); |
|
|
1886 | osm_warning(osm_types[viam.type],viam.id,1,"\n"); |
|
|
1887 | continue; |
5881 | } |
1888 | } |
|
|
1889 | |
5882 | } |
1890 | } |
5883 | } |
1891 | #if 0 |
5884 | |
1892 | fprintf(stderr,"via "LONGLONG_FMT" vs %d\n",viam.id, ni.id); |
5885 | static void process_turn_restrictions_dump_coord(struct coord *c, int count) |
|
|
5886 | { |
|
|
5887 | int i; |
|
|
5888 | for (i = 0; i < count; i++) |
|
|
5889 | { |
|
|
5890 | fprintf(stderr, "(0x%x,0x%x)", c[i].x, c[i].y); |
1893 | fprintf(stderr,"coord 0x%x,0x%x\n",ni.c.x,ni.c.y); |
5891 | } |
1894 | fprintf(stderr,"Lookup "LONGLONG_FMT"\n",fromm.id); |
5892 | } |
1895 | #endif |
5893 | |
1896 | if (!(fromc=get_way(ways, ways_index, viafrom, fromm.id, from, 0))) { |
5894 | static void process_turn_restrictions_finish(GList *tr, FILE *out) |
1897 | if (viam.type == 1 || !(fromc=get_way(ways, ways_index, viato, fromm.id, from, 0))) { |
5895 | { |
|
|
5896 | GList *l = tr; |
|
|
5897 | while (l) |
|
|
5898 | { |
|
|
5899 | struct turn_restriction *t = l->data; |
|
|
5900 | struct coord *c[4]; |
|
|
5901 | struct item_bin *ib = item_bin_2; |
|
|
5902 | |
|
|
5903 | // init array |
|
|
5904 | c[0] = NULL; |
|
|
5905 | c[1] = NULL; |
|
|
5906 | c[2] = NULL; |
|
|
5907 | c[3] = NULL; |
|
|
5908 | |
|
|
5909 | if (!t->c_count[0]) |
|
|
5910 | { |
|
|
5911 | //osm_warning("relation",t->relid,0,"turn restriction: from member not found\n"); |
|
|
5912 | } |
|
|
5913 | else if (!t->c_count[1]) |
|
|
5914 | { |
|
|
5915 | //osm_warning("relation",t->relid,0,"turn restriction: via member not found\n"); |
|
|
5916 | } |
|
|
5917 | else if (!t->c_count[2]) |
|
|
5918 | { |
|
|
5919 | //osm_warning("relation",t->relid,0,"turn restriction: to member not found\n"); |
|
|
5920 | } |
|
|
5921 | else |
|
|
5922 | { |
|
|
5923 | process_turn_restrictions_fromto(t, 0, c); |
|
|
5924 | process_turn_restrictions_fromto(t, 2, c + 2); |
|
|
5925 | if (!c[0] || !c[2]) |
|
|
5926 | { |
|
|
5927 | //osm_warning("relation",t->relid,0,"turn restriction: via ("); |
1898 | osm_warning("relation",relid,0,"turn restriction: failed to connect via "); |
5928 | //process_turn_restrictions_dump_coord(t->c[1], t->c_count[1]); |
1899 | osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to from member ",viafrom->x,viafrom->y,viato->x,viato->y); |
|
|
1900 | osm_warning(osm_types[fromm.type],fromm.id,1," ("); |
|
|
1901 | get_way(ways, ways_index, viafrom, fromm.id, from, 1); |
5929 | //fprintf(stderr,")"); |
1902 | fprintf(stderr,")\n"); |
5930 | if (!c[0]) |
1903 | continue; |
5931 | { |
1904 | } else { |
5932 | //fprintf(stderr," failed to connect to from ("); |
1905 | tmp=viato; |
5933 | //process_turn_restrictions_dump_coord(t->c[0], t->c_count[0]); |
1906 | viato=viafrom; |
|
|
1907 | viafrom=tmp; |
|
|
1908 | } |
|
|
1909 | } |
|
|
1910 | if (!(toc=get_way(ways, ways_index, viato, tom.id, to, 0))) { |
|
|
1911 | osm_warning("relation",relid,0,"turn restriction: failed to connect via "); |
|
|
1912 | osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to to member ",viafrom->x,viafrom->y,viato->x,viato->y); |
|
|
1913 | osm_warning(osm_types[tom.type],tom.id,1," ("); |
|
|
1914 | get_way(ways, ways_index, viato, tom.id, to, 1); |
5934 | //fprintf(stderr,")"); |
1915 | fprintf(stderr,")\n"); |
|
|
1916 | continue; |
|
|
1917 | } |
|
|
1918 | #if 0 |
|
|
1919 | fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x)\n",fromc->x,fromc->y, ni.c.x, ni.c.y, toc->x, toc->y); |
|
|
1920 | #endif |
|
|
1921 | item_bin_init(ib,ib->type); |
|
|
1922 | item_bin_add_coord(ib, fromc, 1); |
|
|
1923 | item_bin_add_coord(ib, viafrom, 1); |
|
|
1924 | if (viam.type == 2) |
|
|
1925 | item_bin_add_coord(ib, viato, 1); |
|
|
1926 | item_bin_add_coord(ib, toc, 1); |
|
|
1927 | item_bin_write(item_bin, out); |
|
|
1928 | } |
|
|
1929 | } |
|
|
1930 | |
|
|
1931 | static void |
|
|
1932 | process_countries(FILE *way, FILE *ways_index) |
|
|
1933 | { |
|
|
1934 | FILE *in=fopen("country_de.tmp","r"); |
|
|
1935 | struct item_bin *ib; |
|
|
1936 | char buffer2[400000]; |
|
|
1937 | struct item_bin *ib2=(struct item_bin *)buffer2; |
|
|
1938 | GList *segments=NULL,*sort_segments; |
|
|
1939 | fseek(in, 0, SEEK_SET); |
|
|
1940 | while ((ib=read_item(in))) { |
|
|
1941 | char *str=NULL; |
|
|
1942 | struct relation_member member; |
|
|
1943 | while ((str=item_bin_get_attr(ib, attr_osm_member, str))) { |
|
|
1944 | if (!get_relation_member(str, &member)) |
|
|
1945 | break; |
|
|
1946 | if (member.type == 2) { |
|
|
1947 | if (!seek_to_way(way, ways_index, member.id)) { |
|
|
1948 | fprintf(stderr,"not found in index"); |
|
|
1949 | break; |
5935 | } |
1950 | } |
5936 | if (!c[2]) |
1951 | while (item_bin_read(ib2, way)) { |
5937 | { |
1952 | if (item_bin_get_wayid(ib2) != member.id) |
5938 | //fprintf(stderr," failed to connect to to ("); |
1953 | break; |
5939 | //process_turn_restrictions_dump_coord(t->c[2], t->c_count[2]); |
1954 | segments=g_list_prepend(segments,item_bin_to_poly_segment(ib2, geom_poly_segment_type_way_unknown)); |
5940 | //fprintf(stderr,")"); |
1955 | break; |
5941 | } |
|
|
5942 | //fprintf(stderr,"\n"); |
|
|
5943 | } |
|
|
5944 | else |
|
|
5945 | { |
|
|
5946 | if (t->c_count[1] <= 2) |
|
|
5947 | { |
|
|
5948 | item_bin_init(ib, t->type); |
|
|
5949 | item_bin_add_coord(ib, c[0], 1); |
|
|
5950 | item_bin_add_coord(ib, c[1], 1); |
|
|
5951 | if (t->c_count[1] > 1) |
|
|
5952 | { |
|
|
5953 | item_bin_add_coord(ib, c[3], 1); |
|
|
5954 | } |
|
|
5955 | item_bin_add_coord(ib, c[2], 1); |
|
|
5956 | item_bin_write(ib, out); |
|
|
5957 | } |
|
|
5958 | |
|
|
5959 | } |
|
|
5960 | } |
|
|
5961 | g_free(t); |
|
|
5962 | l = g_list_next(l); |
|
|
5963 | } |
|
|
5964 | g_list_free(tr); |
|
|
5965 | } |
|
|
5966 | |
|
|
5967 | static GList * |
|
|
5968 | process_turn_restrictions_setup(FILE *in, struct relations *relations) |
|
|
5969 | { |
|
|
5970 | struct relation_member fromm, tom, viam, tmpm; |
|
|
5971 | long long relid; |
|
|
5972 | struct item_bin *ib; |
|
|
5973 | struct relations_func *relations_func; |
|
|
5974 | int min_count; |
|
|
5975 | GList *turn_restrictions = NULL; |
|
|
5976 | |
|
|
5977 | fseek(in, 0, SEEK_SET); |
|
|
5978 | relations_func = relations_func_new(process_turn_restrictions_member, NULL); |
|
|
5979 | while ((ib = read_item(in, 0))) |
|
|
5980 | { |
|
|
5981 | struct turn_restriction *turn_restriction=g_new0(struct turn_restriction, 1); |
|
|
5982 | relid = item_bin_get_relationid(ib); |
|
|
5983 | turn_restriction->relid = relid; |
|
|
5984 | turn_restriction->type = ib->type; |
|
|
5985 | min_count = 0; |
|
|
5986 | if (!search_relation_member(ib, "from", &fromm, &min_count)) |
|
|
5987 | { |
|
|
5988 | osm_warning("relation", relid, 0, "turn restriction: from member missing\n"); |
|
|
5989 | continue; |
|
|
5990 | } |
|
|
5991 | if (search_relation_member(ib, "from", &tmpm, &min_count)) |
|
|
5992 | { |
|
|
5993 | osm_warning("relation", relid, 0, "turn restriction: multiple from members\n"); |
|
|
5994 | continue; |
|
|
5995 | } |
|
|
5996 | min_count = 0; |
|
|
5997 | if (!search_relation_member(ib, "to", &tom, &min_count)) |
|
|
5998 | { |
|
|
5999 | osm_warning("relation", relid, 0, "turn restriction: to member missing\n"); |
|
|
6000 | continue; |
|
|
6001 | } |
|
|
6002 | if (search_relation_member(ib, "to", &tmpm, &min_count)) |
|
|
6003 | { |
|
|
6004 | osm_warning("relation", relid, 0, "turn restriction: multiple to members\n"); |
|
|
6005 | continue; |
|
|
6006 | } |
|
|
6007 | min_count = 0; |
|
|
6008 | if (!search_relation_member(ib, "via", &viam, &min_count)) |
|
|
6009 | { |
|
|
6010 | osm_warning("relation", relid, 0, "turn restriction: via member missing\n"); |
|
|
6011 | continue; |
|
|
6012 | } |
|
|
6013 | if (search_relation_member(ib, "via", &tmpm, &min_count)) |
|
|
6014 | { |
|
|
6015 | osm_warning("relation", relid, 0, "turn restriction: multiple via member\n"); |
|
|
6016 | continue; |
|
|
6017 | } |
|
|
6018 | if (fromm.type != 2) |
|
|
6019 | { |
|
|
6020 | osm_warning("relation", relid, 0, "turn restriction: wrong type for from member "); |
|
|
6021 | osm_warning(osm_types[fromm.type], fromm.id, 1, "\n"); |
|
|
6022 | continue; |
|
|
6023 | } |
|
|
6024 | if (tom.type != 2) |
|
|
6025 | { |
|
|
6026 | osm_warning("relation", relid, 0, "turn restriction: wrong type for to member "); |
|
|
6027 | osm_warning(osm_types[tom.type], tom.id, 1, "\n"); |
|
|
6028 | continue; |
|
|
6029 | } |
|
|
6030 | if (viam.type != 1 && viam.type != 2) |
|
|
6031 | { |
|
|
6032 | osm_warning("relation", relid, 0, "turn restriction: wrong type for via member "); |
|
|
6033 | osm_warning(osm_types[viam.type], viam.id, 1, "\n"); |
|
|
6034 | continue; |
|
|
6035 | } |
|
|
6036 | relations_add_func(relations, relations_func, turn_restriction, (gpointer) 0, fromm.type, fromm.id); |
|
|
6037 | relations_add_func(relations, relations_func, turn_restriction, (gpointer) 1, viam.type, viam.id); |
|
|
6038 | relations_add_func(relations, relations_func, turn_restriction, (gpointer) 2, tom.type, tom.id); |
|
|
6039 | turn_restrictions = g_list_append(turn_restrictions, turn_restriction); |
|
|
6040 | } |
|
|
6041 | return turn_restrictions; |
|
|
6042 | } |
|
|
6043 | |
|
|
6044 | void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) |
|
|
6045 | { |
|
|
6046 | struct relations *relations = relations_new(); |
|
|
6047 | GList *turn_restrictions; |
|
|
6048 | fseek(in, 0, SEEK_SET); |
|
|
6049 | if (verbose_mode) |
|
|
6050 | fprintf(stderr, "process_turn_restrictions A1\n"); |
|
|
6051 | turn_restrictions = process_turn_restrictions_setup(in, relations); |
|
|
6052 | if (verbose_mode) |
|
|
6053 | fprintf(stderr, "process_turn_restrictions B2\n"); |
|
|
6054 | relations_process(relations, coords, ways, NULL); |
|
|
6055 | if (verbose_mode) |
|
|
6056 | fprintf(stderr, "process_turn_restrictions C3\n"); |
|
|
6057 | process_turn_restrictions_finish(turn_restrictions, out); |
|
|
6058 | if (verbose_mode) |
|
|
6059 | fprintf(stderr, "process_turn_restrictions D4\n"); |
|
|
6060 | } |
|
|
6061 | |
|
|
6062 | static void node_ref_way(osmid node, int local_thread_num) |
|
|
6063 | { |
|
|
6064 | struct node_item *ni; |
|
|
6065 | ni = node_item_get_fast(node, local_thread_num); |
|
|
6066 | if (ni) |
|
|
6067 | { |
|
|
6068 | ni->ref_way++; |
|
|
6069 | } |
|
|
6070 | } |
|
|
6071 | |
|
|
6072 | static void nodes_ref_item_bin(struct item_bin *ib, int local_thread_num) |
|
|
6073 | { |
|
|
6074 | int i; |
|
|
6075 | struct coord *c = (struct coord *) (ib + 1); // set pointer to coord struct of this item |
|
|
6076 | for (i = 0; i < ib->clen / 2; i++) |
|
|
6077 | { |
|
|
6078 | node_ref_way(REF(c[i]), local_thread_num); // give c[i].y as parameter (which seems to be NODE ID) |
|
|
6079 | } |
|
|
6080 | |
|
|
6081 | //fprintf(stderr,"********DUMP rw ***********\n"); |
|
|
6082 | //dump_itembin(ib); |
|
|
6083 | //fprintf(stderr,"********DUMP rw ***********\n"); |
|
|
6084 | |
|
|
6085 | } |
|
|
6086 | |
|
|
6087 | void osm_add_nd(osmid ref) |
|
|
6088 | { |
|
|
6089 | SET_REF(coord_buffer[coord_count], ref); |
|
|
6090 | coord_count++; |
|
|
6091 | if (coord_count > 65536) |
|
|
6092 | { |
|
|
6093 | fprintf(stderr, "ERROR: Overflow\n"); |
|
|
6094 | exit(1); |
|
|
6095 | } |
|
|
6096 | } |
|
|
6097 | |
|
|
6098 | static void write_item_part(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig, int first, int last, long long *last_id) |
|
|
6099 | { |
|
|
6100 | struct item_bin new; |
|
|
6101 | struct coord *c = (struct coord *) (orig + 1); |
|
|
6102 | char *attr = (char *) (c + orig->clen / 2); |
|
|
6103 | int attr_len = orig->len - orig->clen - 2; |
|
|
6104 | processed_ways++; |
|
|
6105 | new.type = orig->type; |
|
|
6106 | new.clen = (last - first + 1) * 2; |
|
|
6107 | new.len = new.clen + attr_len + 2; |
|
|
6108 | |
|
|
6109 | if (out_index) |
|
|
6110 | { |
|
|
6111 | long long idx[2]; |
|
|
6112 | idx[0] = item_bin_get_wayid(orig); |
|
|
6113 | idx[1] = ftello(out); |
|
|
6114 | if (way_hash_cfu) |
|
|
6115 | { |
|
|
6116 | //if (!(g_hash_table_lookup_extended(way_hash, (gpointer) (long) idx[0], NULL, NULL))) |
|
|
6117 | //{ |
|
|
6118 | // g_hash_table_insert(way_hash, (gpointer) (long) idx[0], (gpointer) (long) idx[1]); |
|
|
6119 | // // fprintf(stderr,"way_hash size="LONGLONG_FMT"\n", g_hash_table_size(way_hash)); |
|
|
6120 | //} |
|
|
6121 | |
|
|
6122 | if (!cfuhash_exists_data(way_hash_cfu, (long long) idx[0], sizeof(long long))) |
|
|
6123 | { |
|
|
6124 | cfuhash_put_data(way_hash_cfu, (long long) idx[0], sizeof(long long), (long) idx[1], 1, NULL); |
|
|
6125 | } |
|
|
6126 | } |
|
|
6127 | else |
|
|
6128 | { |
|
|
6129 | if (!last_id || *last_id != idx[0]) |
|
|
6130 | { |
|
|
6131 | fwrite(idx, sizeof(idx), 1, out_index); |
|
|
6132 | } |
|
|
6133 | |
|
|
6134 | if (last_id) |
|
|
6135 | { |
|
|
6136 | *last_id = idx[0]; |
|
|
6137 | } |
|
|
6138 | } |
|
|
6139 | |
|
|
6140 | } |
|
|
6141 | |
|
|
6142 | fwrite(&new, sizeof(new), 1, out); |
|
|
6143 | fwrite(c + first, new.clen * 4, 1, out); |
|
|
6144 | fwrite(attr, attr_len * 4, 1, out); |
|
|
6145 | } |
|
|
6146 | |
|
|
6147 | void ref_ways(FILE *in, int local_thread_num) |
|
|
6148 | { |
|
|
6149 | struct item_bin *ib; |
|
|
6150 | |
|
|
6151 | long long ways_count = 0; |
|
|
6152 | |
|
|
6153 | fseek(in, 0, SEEK_SET); |
|
|
6154 | while ((ib = read_item(in, local_thread_num))) // loop all "ways" from file "in" |
|
|
6155 | { |
|
|
6156 | nodes_ref_item_bin(ib, local_thread_num); |
|
|
6157 | ways_count++; |
|
|
6158 | |
|
|
6159 | if ((ways_count % 1000000) == 0) |
|
|
6160 | { |
|
|
6161 | fprintf(stderr, "[THREAD] #%d ways: %lld\n", local_thread_num, ways_count); |
|
|
6162 | } |
|
|
6163 | } |
|
|
6164 | } |
|
|
6165 | |
|
|
6166 | /* |
|
|
6167 | void resolve_ways(FILE *in, FILE *out) |
|
|
6168 | { |
|
|
6169 | struct item_bin *ib; |
|
|
6170 | struct coord *c; |
|
|
6171 | int i; |
|
|
6172 | struct node_item *ni; |
|
|
6173 | |
|
|
6174 | fseek(in, 0, SEEK_SET); |
|
|
6175 | while ((ib = read_item(in))) |
|
|
6176 | { |
|
|
6177 | c = (struct coord *) (ib + 1); |
|
|
6178 | for (i = 0; i < ib->clen / 2; i++) |
|
|
6179 | { |
|
|
6180 | if (!IS_REF(c[i])) |
|
|
6181 | continue; |
|
|
6182 | ni = node_item_get(REF(c[i])); |
|
|
6183 | if (ni) |
|
|
6184 | { |
|
|
6185 | c[i].x = ni->c.x; |
|
|
6186 | c[i].y = ni->c.y; |
|
|
6187 | } |
|
|
6188 | } |
|
|
6189 | item_bin_write(ib, out); |
|
|
6190 | } |
|
|
6191 | } |
|
|
6192 | */ |
|
|
6193 | |
|
|
6194 | /* |
|
|
6195 | FILE * |
|
|
6196 | resolve_ways_file(FILE *in, char *suffix, char *filename) |
|
|
6197 | { |
|
|
6198 | char *newfilename = g_strdup_printf("%s_new", filename); |
|
|
6199 | FILE *new = tempfile(suffix, newfilename, 1); |
|
|
6200 | resolve_ways(in, new); |
|
|
6201 | fclose(in); |
|
|
6202 | fclose(new); |
|
|
6203 | tempfile_rename(suffix, newfilename, filename); |
|
|
6204 | g_free(newfilename); |
|
|
6205 | return tempfile(suffix, filename, 0); |
|
|
6206 | } |
|
|
6207 | */ |
|
|
6208 | |
|
|
6209 | /** |
|
|
6210 | * Get POI coordinates from area/line coordinates. |
|
|
6211 | * @param in *in input file with area/line coordinates. |
|
|
6212 | * @param in *out output file with POI coordinates |
|
|
6213 | * @param in type input file original contents type: type_line or type_area |
|
|
6214 | * @returns nothing |
|
|
6215 | */ |
|
|
6216 | // --- NOT NEEDED ------ |
|
|
6217 | // --- NOT NEEDED ------ |
|
|
6218 | void process_way2poi(FILE *in, FILE *out, int type) |
|
|
6219 | { |
|
|
6220 | struct item_bin *ib; |
|
|
6221 | while ((ib = read_item(in, 0))) |
|
|
6222 | { |
|
|
6223 | int count = ib->clen / 2; |
|
|
6224 | if (count > 1 && ib->type < type_line) |
|
|
6225 | { |
|
|
6226 | struct coord *c = (struct coord *) (ib + 1), c1, c2; |
|
|
6227 | int done = 0; |
|
|
6228 | if (type == type_area) |
|
|
6229 | { |
|
|
6230 | if (count < 3) |
|
|
6231 | { |
|
|
6232 | osm_warning("way", item_bin_get_wayid(ib), 0, "Broken polygon, less than 3 points defined\n"); |
|
|
6233 | } |
|
|
6234 | else if (!geom_poly_centroid(c, count, &c1)) |
|
|
6235 | { |
|
|
6236 | osm_warning("way", item_bin_get_wayid(ib), 0, "Broken polygon, area is 0\n"); |
|
|
6237 | } |
|
|
6238 | else |
|
|
6239 | { |
|
|
6240 | if (geom_poly_point_inside(c, count, &c1)) |
|
|
6241 | { |
|
|
6242 | c[0] = c1; |
|
|
6243 | } |
|
|
6244 | else |
|
|
6245 | { |
|
|
6246 | geom_poly_closest_point(c, count, &c1, &c2); |
|
|
6247 | c[0] = c2; |
|
|
6248 | } |
|
|
6249 | done = 1; |
|
|
6250 | } |
1956 | } |
6251 | } |
1957 | } |
6252 | if (!done) |
|
|
6253 | { |
|
|
6254 | geom_line_middle(c, count, &c1); |
|
|
6255 | c[0] = c1; |
|
|
6256 | } |
1958 | } |
6257 | write_item_part(out, NULL, NULL, ib, 0, 0, NULL); |
|
|
6258 | } |
1959 | } |
|
|
1960 | sort_segments=geom_poly_segments_sort(segments, geom_poly_segment_type_way_left_side); |
|
|
1961 | FILE *tmp=fopen("tst.txt","w"); |
|
|
1962 | while (sort_segments) { |
|
|
1963 | struct geom_poly_segment *seg=sort_segments->data; |
|
|
1964 | if (!seg) { |
|
|
1965 | fprintf(stderr,"is null\n"); |
|
|
1966 | } else { |
|
|
1967 | fprintf(stderr,"segment %p %s area "LONGLONG_FMT"\n",sort_segments,coord_is_equal(*seg->first, *seg->last) ? "closed":"open",geom_poly_area(seg->first,seg->last-seg->first+1)); |
6259 | } |
1968 | } |
6260 | } |
1969 | #if 0 |
|
|
1970 | int count=seg->last-seg->first+1; |
|
|
1971 | item_bin_init(ib, type_border_country); |
|
|
1972 | item_bin_add_coord(ib, seg->first, count); |
|
|
1973 | item_bin_dump(ib, tmp); |
|
|
1974 | #endif |
6261 | |
1975 | |
6262 | /** |
1976 | sort_segments=g_list_next(sort_segments); |
6263 | * Get POI coordinates from line coordinates. |
1977 | } |
6264 | * @param in *in input file with line coordinates. |
1978 | fclose(tmp); |
6265 | * @param in *out output file with POI coordinates |
1979 | fclose(in); |
6266 | * @param in type input file original contents type: type_line or type_area |
1980 | } |
6267 | * @returns nothing |
1981 | |
6268 | */ |
1982 | static void |
6269 | void process_way2poi_housenumber(FILE *in, FILE *out) |
1983 | node_ref_way(osmid node) |
|
|
1984 | { |
|
|
1985 | struct node_item *ni; |
|
|
1986 | ni=node_item_get(node); |
|
|
1987 | if (ni) |
|
|
1988 | ni->ref_way++; |
|
|
1989 | } |
|
|
1990 | |
|
|
1991 | int |
|
|
1992 | resolve_ways(FILE *in, FILE *out) |
6270 | { |
1993 | { |
6271 | struct item_bin *ib; |
1994 | struct item_bin *ib; |
6272 | // char *house_number = NULL; |
1995 | struct coord *c; |
6273 | // char *street_name = NULL; |
|
|
6274 | |
|
|
6275 | while ((ib = read_item(in, 0))) |
|
|
6276 | { |
|
|
6277 | int count = ib->clen / 2; |
|
|
6278 | if (count > 1 && ib->type == type_poly_building) |
|
|
6279 | { |
|
|
6280 | struct coord *c = (struct coord *) (ib + 1), c1, c2; |
|
|
6281 | int done = 0; |
|
|
6282 | //if (ib->type == type_area) // --> buildings are "lines" now, not polys |
|
|
6283 | //{ |
|
|
6284 | if (count < 3) |
|
|
6285 | { |
|
|
6286 | osm_warning("way", item_bin_get_wayid(ib), 0, "Broken polygon, less than 3 points defined\n"); |
|
|
6287 | } |
|
|
6288 | else if (!geom_poly_centroid(c, count, &c1)) |
|
|
6289 | { |
|
|
6290 | osm_warning("way", item_bin_get_wayid(ib), 0, "Broken polygon, area is 0\n"); |
|
|
6291 | } |
|
|
6292 | else |
|
|
6293 | { |
|
|
6294 | if (geom_poly_point_inside(c, count, &c1)) |
|
|
6295 | { |
|
|
6296 | //fprintf(stderr, "geom_poly_point_inside\n"); |
|
|
6297 | c[0] = c1; |
|
|
6298 | } |
|
|
6299 | else |
|
|
6300 | { |
|
|
6301 | //fprintf(stderr, "geom_poly_closest_point\n"); |
|
|
6302 | geom_poly_closest_point(c, count, &c1, &c2); |
|
|
6303 | c[0] = c2; |
|
|
6304 | } |
|
|
6305 | done = 1; |
|
|
6306 | } |
|
|
6307 | //} |
|
|
6308 | |
|
|
6309 | if (!done) |
|
|
6310 | { |
|
|
6311 | //fprintf(stderr, "geom_line_middle\n"); |
|
|
6312 | geom_line_middle(c, count, &c1); |
|
|
6313 | c[0] = c1; |
|
|
6314 | } |
|
|
6315 | |
|
|
6316 | char *street_name = item_bin_get_attr(ib, attr_street_name_dummy, NULL); |
|
|
6317 | char *house_number = item_bin_get_attr(ib, attr_house_number_dummy, NULL); |
|
|
6318 | if ((street_name != NULL) && (house_number != NULL)) |
|
|
6319 | { |
|
|
6320 | osm_append_housenumber_node(out, c, house_number, street_name); |
|
|
6321 | } |
|
|
6322 | } |
|
|
6323 | } |
|
|
6324 | } |
|
|
6325 | |
|
|
6326 | void fill_hash_waytag(void) |
|
|
6327 | { |
|
|
6328 | if (verbose_mode) |
|
|
6329 | fprintf(stderr, "fill_hash_waytag - START\n"); |
|
|
6330 | if (waytag_hash) |
|
|
6331 | { |
|
|
6332 | g_hash_table_destroy(waytag_hash); |
|
|
6333 | waytag_hash = NULL; |
|
|
6334 | } |
|
|
6335 | waytag_hash = g_hash_table_new(NULL, NULL); |
|
|
6336 | waytag_buffer_to_hash(); |
|
|
6337 | if (verbose_mode) |
|
|
6338 | fprintf(stderr, "fill_hash_waytag - END\n"); |
|
|
6339 | } |
|
|
6340 | |
|
|
6341 | void append_pre_resolved_ways(FILE *out, struct maptool_osm *osm2) |
|
|
6342 | { |
|
|
6343 | struct item_bin *ib; |
|
|
6344 | |
|
|
6345 | // fseek(out, 0, SEEK_END); // seek to the end of current way-file |
|
|
6346 | rewind(osm2->ways_with_coords); // start with the first "way" |
|
|
6347 | |
|
|
6348 | while ((ib = read_item(osm2->ways_with_coords, 0))) // loop thru all "ways" from file "in" |
|
|
6349 | { |
|
|
6350 | // write way to outfile |
|
|
6351 | item_bin_write(ib, out); |
|
|
6352 | } |
|
|
6353 | } |
|
|
6354 | |
|
|
6355 | int copy_tags_to_ways(FILE *in, FILE *out, FILE *tags_in) |
|
|
6356 | { |
|
|
6357 | struct item_bin *ib; |
|
|
6358 | |
|
|
6359 | long long slice_size2 = sizeof(struct way_tag) * 1024 * 1024; // xx MByte |
|
|
6360 | long long final_slice_size2; |
|
|
6361 | struct way_tag *wt3; |
|
|
6362 | int slices2 = 0; |
|
|
6363 | int i; |
1996 | int i; |
6364 | struct stat st; |
|
|
6365 | int final_slice = 0; |
|
|
6366 | long long size2; |
|
|
6367 | |
1997 | |
6368 | fseek(tags_in, 0, SEEK_END); |
|
|
6369 | size2 = ftello(tags_in); // 64bit |
|
|
6370 | |
|
|
6371 | slices2 = (size2 / slice_size2) + 1; |
|
|
6372 | final_slice_size2 = size2 - ((slices2 - 1) * slice_size2); |
|
|
6373 | |
|
|
6374 | if (slices2 == 1) |
|
|
6375 | { |
|
|
6376 | final_slice_size2 = size2; |
|
|
6377 | } |
|
|
6378 | |
|
|
6379 | if (verbose_mode) fprintf(stderr, "relationsfile size="LONGLONG_FMT" bytes\n", size2); |
|
|
6380 | if (verbose_mode) fprintf(stderr, "final_slice_size2="LONGLONG_FMT" bytes\n", final_slice_size2); |
|
|
6381 | if (verbose_mode) |
|
|
6382 | fprintf(stderr, "slices=%d\n", slices2); |
|
|
6383 | |
|
|
6384 | for (i = 0; i < slices2; i++) |
|
|
6385 | { |
|
|
6386 | if (i == (slices2 - 1)) |
|
|
6387 | { |
|
|
6388 | final_slice = 1; |
|
|
6389 | } |
|
|
6390 | |
|
|
6391 | if (final_slice == 1) |
|
|
6392 | { |
|
|
6393 | load_buffer_fp(tags_in, &waytag_buffer, i * slice_size2, final_slice_size2); // load in the relations |
|
|
6394 | } |
|
|
6395 | else |
|
|
6396 | { |
|
|
6397 | load_buffer_fp(tags_in, &waytag_buffer, i * slice_size2, slice_size2); // load in the relations |
|
|
6398 | } |
|
|
6399 | fill_hash_waytag(); |
|
|
6400 | struct way_tag *wt2 = (struct way_tag *) (waytag_buffer.base); |
|
|
6401 | |
|
|
6402 | rewind(in); // start with the first "way" |
|
|
6403 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
|
|
6404 | { |
|
|
6405 | if (waytag_hash) |
|
|
6406 | { |
|
|
6407 | int tag_start_pointer; |
|
|
6408 | long long wid = item_bin_get_wayid(ib); |
|
|
6409 | |
|
|
6410 | //fprintf(stderr,"looking for wid=%lu\n", wid); |
|
|
6411 | |
|
|
6412 | long long p_tmp = 0; |
|
|
6413 | int ret = 0; |
|
|
6414 | ret = g_hash_table_lookup_extended(waytag_hash, (gpointer) (long long) wid, NULL, (gpointer) & p_tmp); |
|
|
6415 | //fprintf(stderr,"ret=%d\n", ret); |
|
|
6416 | if (ret == 1) |
|
|
6417 | { |
|
|
6418 | // only if wayid is found in hash! |
|
|
6419 | tag_start_pointer = (int) (long long) (p_tmp); |
|
|
6420 | wt3 = wt2 + tag_start_pointer; |
|
|
6421 | |
|
|
6422 | if ((long long) wt3->way_id == (long long) wid) |
|
|
6423 | { |
|
|
6424 | if (wt3->tag_id == 1) |
|
|
6425 | { |
|
|
6426 | // add "type" to "way" |
|
|
6427 | // ## char tag[strlen("waterway") + strlen("riverbank") + 2]; |
|
|
6428 | // ## sprintf(tag, "%s=%s", "waterway", "riverbank"); |
|
|
6429 | // ## item_bin_add_attr_string(ib, attr_osm_tag, tag); |
|
|
6430 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6431 | { |
|
|
6432 | item_bin_set_type(ib, type_poly_water_from_relations); |
|
|
6433 | } |
|
|
6434 | else |
|
|
6435 | { |
|
|
6436 | item_bin_set_type(ib, type_water_river); |
|
|
6437 | } |
|
|
6438 | } |
|
|
6439 | else if (wt3->tag_id == 2) |
|
|
6440 | { |
|
|
6441 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6442 | { |
|
|
6443 | item_bin_set_type(ib, type_poly_water_from_relations); |
|
|
6444 | } |
|
|
6445 | else |
|
|
6446 | { |
|
|
6447 | item_bin_set_type(ib, type_water_river); |
|
|
6448 | } |
|
|
6449 | } |
|
|
6450 | else if (wt3->tag_id == 4) |
|
|
6451 | { |
|
|
6452 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6453 | { |
|
|
6454 | item_bin_set_type(ib, type_poly_water_from_relations); |
|
|
6455 | } |
|
|
6456 | else |
|
|
6457 | { |
|
|
6458 | item_bin_set_type(ib, type_water_river); |
|
|
6459 | } |
|
|
6460 | } |
|
|
6461 | else if (wt3->tag_id == 5) |
|
|
6462 | { |
|
|
6463 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6464 | { |
|
|
6465 | item_bin_set_type(ib, type_poly_wood_from_triang); |
|
|
6466 | } |
|
|
6467 | else |
|
|
6468 | { |
|
|
6469 | //fprintf(stderr, "wood_from_relations(5)\n"); |
|
|
6470 | item_bin_set_type(ib, type_wood_from_relations); |
|
|
6471 | } |
|
|
6472 | } |
|
|
6473 | else if (wt3->tag_id == 6) |
|
|
6474 | { |
|
|
6475 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6476 | { |
|
|
6477 | item_bin_set_type(ib, type_poly_wood_from_triang); |
|
|
6478 | } |
|
|
6479 | else |
|
|
6480 | { |
|
|
6481 | //fprintf(stderr, "wood_from_relations(6)\n"); |
|
|
6482 | item_bin_set_type(ib, type_wood_from_relations); |
|
|
6483 | } |
|
|
6484 | } |
|
|
6485 | else if (wt3->tag_id == 7) |
|
|
6486 | { |
|
|
6487 | // "inner" way |
|
|
6488 | //fprintf(stderr, "wood_from_relations(7)\n"); |
|
|
6489 | item_bin_set_type(ib, type_wood_from_relations); |
|
|
6490 | } |
|
|
6491 | else if (wt3->tag_id == 8) |
|
|
6492 | { |
|
|
6493 | // "inner" way |
|
|
6494 | //fprintf(stderr, "wood_from_relations(8)\n"); |
|
|
6495 | item_bin_set_type(ib, type_wood_from_relations); |
|
|
6496 | } |
|
|
6497 | } |
|
|
6498 | } |
|
|
6499 | } |
|
|
6500 | // write way to outfile |
|
|
6501 | item_bin_write(ib, out); |
|
|
6502 | } |
|
|
6503 | |
|
|
6504 | } |
|
|
6505 | } |
|
|
6506 | |
|
|
6507 | /* filecopy: copy file ifp to file ofp */ |
|
|
6508 | void filecopy(FILE *ifp, FILE *ofp) |
|
|
6509 | { |
|
|
6510 | int c; |
|
|
6511 | while ((c = getc(ifp)) != EOF) |
|
|
6512 | { |
|
|
6513 | putc(c, ofp); |
|
|
6514 | } |
|
|
6515 | } |
|
|
6516 | |
|
|
6517 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
6518 | typedef unsigned char uint8; |
|
|
6519 | typedef unsigned short uint16; |
|
|
6520 | typedef unsigned int uint; |
|
|
6521 | |
|
|
6522 | #define MZ_MIN(a,b) (((a)<(b))?(a):(b)) |
|
|
6523 | #define my_min(a,b) (((a) < (b)) ? (a) : (b)) |
|
|
6524 | |
|
|
6525 | |
|
|
6526 | |
|
|
6527 | |
|
|
6528 | // ------------------------------- |
|
|
6529 | // ------------------------------- |
|
|
6530 | |
|
|
6531 | int IN_BUF_SIZE; |
|
|
6532 | static uint8* s_inbuf; |
|
|
6533 | int OUT_BUF_SIZE; |
|
|
6534 | static uint8* s_outbuf; |
|
|
6535 | int COMP_OUT_BUF_SIZE; |
|
|
6536 | |
|
|
6537 | int s_IN_BUF_SIZE = sizeof(struct streets_index_data_block) * 1024; |
|
|
6538 | int t_IN_BUF_SIZE = sizeof(struct town_index_data_block) * 1024; |
|
|
6539 | static uint8 s_s_inbuf[(sizeof(struct streets_index_data_block) * 1024)]; |
|
|
6540 | static uint8 t_s_inbuf[(sizeof(struct town_index_data_block) * 1024)]; |
|
|
6541 | |
|
|
6542 | int s_OUT_BUF_SIZE = sizeof(struct streets_index_data_block) * 1024; |
|
|
6543 | int t_OUT_BUF_SIZE = sizeof(struct town_index_data_block) * 1024; |
|
|
6544 | static uint8 s_s_outbuf[(sizeof(struct streets_index_data_block) * 1024)]; |
|
|
6545 | static uint8 t_s_outbuf[(sizeof(struct town_index_data_block) * 1024)]; |
|
|
6546 | |
|
|
6547 | int s_COMP_OUT_BUF_SIZE; |
|
|
6548 | int t_COMP_OUT_BUF_SIZE; |
|
|
6549 | |
|
|
6550 | // IN_BUF_SIZE is the size of the file read buffer. |
|
|
6551 | // IN_BUF_SIZE must be >= 1 |
|
|
6552 | //**#define IN_BUF_SIZE (1024*512) |
|
|
6553 | //**static uint8 s_inbuf[IN_BUF_SIZE]; |
|
|
6554 | |
|
|
6555 | // COMP_OUT_BUF_SIZE is the size of the output buffer used during compression. |
|
|
6556 | // COMP_OUT_BUF_SIZE must be >= 1 and <= OUT_BUF_SIZE |
|
|
6557 | //**#define COMP_OUT_BUF_SIZE (1024*512) |
|
|
6558 | |
|
|
6559 | // OUT_BUF_SIZE is the size of the output buffer used during decompression. |
|
|
6560 | // 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) |
|
|
6561 | //#define OUT_BUF_SIZE (TINFL_LZ_DICT_SIZE) |
|
|
6562 | //*#define OUT_BUF_SIZE (1024*512) |
|
|
6563 | //*static uint8 s_outbuf[OUT_BUF_SIZE]; |
|
|
6564 | |
|
|
6565 | // ------------------------------- |
|
|
6566 | // ------------------------------- |
|
|
6567 | |
|
|
6568 | |
|
|
6569 | // compression level |
|
|
6570 | int street_index_compress_level = 9; // = MZ_BEST_COMPRESSION |
|
|
6571 | |
|
|
6572 | long long compress_file(char *in, char *out, int keep_tempfile) |
|
|
6573 | { |
|
|
6574 | long long out_size = 0; |
|
|
6575 | // compress structure |
|
|
6576 | tdefl_compressor *g_deflator; |
|
|
6577 | g_deflator = g_new0(tdefl_compressor, 1); |
|
|
6578 | // compress structure |
|
|
6579 | |
|
|
6580 | // ok now compress the block (file) ------------------------------- |
|
|
6581 | const void *next_in = s_inbuf; |
|
|
6582 | size_t avail_in = 0; |
|
|
6583 | void *next_out = s_outbuf; |
|
|
6584 | size_t avail_out = OUT_BUF_SIZE; |
|
|
6585 | size_t total_in = 0, total_out = 0; |
|
|
6586 | |
|
|
6587 | FILE *in_uncompr = tempfile("", in, 0); |
|
|
6588 | FILE *out_compr = NULL; |
|
|
6589 | out_compr = tempfile("", out, 1); |
|
|
6590 | |
|
|
6591 | // Determine input file's size. |
|
|
6592 | fseek(in_uncompr, 0, SEEK_END); |
|
|
6593 | long file_loc = ftell(in_uncompr); |
|
|
6594 | fseek(in_uncompr, 0, SEEK_SET); |
1998 | fseek(in, 0, SEEK_SET); |
6595 | uint infile_size = (uint)file_loc; |
1999 | while ((ib=read_item(in))) { |
6596 | |
2000 | c=(struct coord *)(ib+1); |
6597 | // The number of dictionary probes to use at each compression level (0-10). 0=implies fastest/minimal possible probing. |
2001 | for (i = 0 ; i < ib->clen/2 ; i++) { |
6598 | static const mz_uint s_tdefl_num_probes[11] = |
2002 | node_ref_way(REF(c[i])); |
6599 | { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500}; |
|
|
6600 | |
|
|
6601 | tdefl_status status; |
|
|
6602 | uint infile_remaining = infile_size; |
|
|
6603 | |
|
|
6604 | // 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). |
|
|
6605 | 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); |
|
|
6606 | if (!street_index_compress_level) |
|
|
6607 | { |
|
|
6608 | comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS; |
|
|
6609 | } |
2003 | } |
6610 | |
2004 | } |
6611 | // Initialize the low-level compressor. |
|
|
6612 | status = tdefl_init(g_deflator, NULL, NULL, comp_flags); |
|
|
6613 | if (status != TDEFL_STATUS_OKAY) |
|
|
6614 | { |
|
|
6615 | fprintf(stderr, "tdefl_init() failed!\n"); |
|
|
6616 | g_free(g_deflator); |
|
|
6617 | return 0; |
2005 | return 0; |
6618 | } |
2006 | } |
6619 | avail_out = COMP_OUT_BUF_SIZE; |
|
|
6620 | |
2007 | |
6621 | // Compression. |
2008 | void |
6622 | for (;; ) |
2009 | osm_add_nd(osmid ref) |
6623 | { |
2010 | { |
6624 | size_t in_bytes, out_bytes; |
2011 | SET_REF(coord_buffer[coord_count], ref); |
|
|
2012 | node_ref_way(ref); |
|
|
2013 | coord_count++; |
|
|
2014 | if (coord_count > 65536) { |
|
|
2015 | fprintf(stderr,"ERROR: Overflow\n"); |
|
|
2016 | exit(1); |
|
|
2017 | } |
|
|
2018 | } |
6625 | |
2019 | |
6626 | if (!avail_in) |
2020 | static void |
6627 | { |
2021 | write_item_part(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig, int first, int last, long long *last_id) |
6628 | // Input buffer is empty, so read more bytes from input file. |
2022 | { |
6629 | uint n = my_min(IN_BUF_SIZE, infile_remaining); |
2023 | struct item_bin new; |
6630 | |
2024 | struct coord *c=(struct coord *)(orig+1); |
6631 | if (fread(s_inbuf, 1, n, in_uncompr) != n) |
2025 | char *attr=(char *)(c+orig->clen/2); |
6632 | { |
2026 | int attr_len=orig->len-orig->clen-2; |
6633 | fprintf(stderr, "Failed reading from input file!\n"); |
2027 | processed_ways++; |
6634 | g_free(g_deflator); |
2028 | new.type=orig->type; |
6635 | return 0; |
2029 | new.clen=(last-first+1)*2; |
|
|
2030 | new.len=new.clen+attr_len+2; |
|
|
2031 | if (out_index) { |
|
|
2032 | long long idx[2]; |
|
|
2033 | idx[0]=item_bin_get_wayid(orig); |
|
|
2034 | idx[1]=ftell(out); |
|
|
2035 | if (way_hash) { |
|
|
2036 | if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long)idx[0], NULL, NULL))) |
|
|
2037 | g_hash_table_insert(way_hash, (gpointer)(long)idx[0], (gpointer)(long)idx[1]); |
|
|
2038 | } else { |
|
|
2039 | if (!last_id || *last_id != idx[0]) |
|
|
2040 | fwrite(idx, sizeof(idx), 1, out_index); |
|
|
2041 | if (last_id) |
|
|
2042 | *last_id=idx[0]; |
6636 | } |
2043 | } |
6637 | |
2044 | |
6638 | next_in = s_inbuf; |
|
|
6639 | avail_in = n; |
|
|
6640 | |
|
|
6641 | infile_remaining -= n; |
|
|
6642 | //printf("Input bytes remaining: %u\n", infile_remaining); |
|
|
6643 | } |
2045 | } |
6644 | |
2046 | #if 0 |
6645 | in_bytes = avail_in; |
2047 | fprintf(stderr,"first %d last %d type 0x%x len %d clen %d attr_len %d\n", first, last, new.type, new.len, new.clen, attr_len); |
6646 | out_bytes = avail_out; |
|
|
6647 | // Compress as much of the input as possible (or all of it) to the output buffer. |
|
|
6648 | status = tdefl_compress(g_deflator, next_in, &in_bytes, next_out, &out_bytes, infile_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH); |
|
|
6649 | |
|
|
6650 | next_in = (const char *)next_in + in_bytes; |
|
|
6651 | avail_in -= in_bytes; |
|
|
6652 | total_in += in_bytes; |
|
|
6653 | |
|
|
6654 | next_out = (char *)next_out + out_bytes; |
|
|
6655 | avail_out -= out_bytes; |
|
|
6656 | total_out += out_bytes; |
|
|
6657 | |
|
|
6658 | if ((status != TDEFL_STATUS_OKAY) || (!avail_out)) |
|
|
6659 | { |
|
|
6660 | // Output buffer is full, or compression is done or failed, so write buffer to output file. |
|
|
6661 | uint n = COMP_OUT_BUF_SIZE - (uint)avail_out; |
|
|
6662 | if (fwrite(s_outbuf, 1, n, out_compr) != n) |
|
|
6663 | { |
|
|
6664 | fprintf(stderr, "Failed writing to output file!\n"); |
|
|
6665 | g_free(g_deflator); |
|
|
6666 | return 0; |
|
|
6667 | } |
|
|
6668 | next_out = s_outbuf; |
|
|
6669 | avail_out = COMP_OUT_BUF_SIZE; |
|
|
6670 | } |
|
|
6671 | |
|
|
6672 | if (status == TDEFL_STATUS_DONE) |
|
|
6673 | { |
|
|
6674 | // Compression completed successfully. |
|
|
6675 | break; |
|
|
6676 | } |
|
|
6677 | else if (status != TDEFL_STATUS_OKAY) |
|
|
6678 | { |
|
|
6679 | // Compression somehow failed. |
|
|
6680 | fprintf(stderr, "tdefl_compress() failed with status %i!\n", status); |
|
|
6681 | g_free(g_deflator); |
|
|
6682 | return 0; |
|
|
6683 | } |
|
|
6684 | } |
|
|
6685 | |
|
|
6686 | fprintf(stderr, "Total input bytes: %u\n", (mz_uint32)total_in); |
|
|
6687 | fprintf(stderr, "Total output bytes: %u\n", (mz_uint32)total_out); |
|
|
6688 | |
|
|
6689 | out_size = (long long)total_out; |
|
|
6690 | |
|
|
6691 | fclose(in_uncompr); |
|
|
6692 | fclose(out_compr); |
|
|
6693 | |
|
|
6694 | if (keep_tempfile == 1) |
|
|
6695 | { |
|
|
6696 | char *in2; |
|
|
6697 | in2 = g_strdup_printf("%s.tmptmp", in); |
|
|
6698 | tempfile_rename("", in, in2); |
|
|
6699 | g_free(in2); |
|
|
6700 | tempfile_rename("", out, in); |
|
|
6701 | } |
|
|
6702 | else |
|
|
6703 | { |
|
|
6704 | tempfile_unlink("", in); |
|
|
6705 | tempfile_rename("", out, in); |
|
|
6706 | } |
|
|
6707 | |
|
|
6708 | g_free(g_deflator); |
|
|
6709 | |
|
|
6710 | return out_size; |
|
|
6711 | } |
|
|
6712 | #endif |
2048 | #endif |
6713 | |
2049 | fwrite(&new, sizeof(new), 1, out); |
6714 | void generate_combined_index_file(FILE *towni, FILE *streeti, FILE *out) |
2050 | fwrite(c+first, new.clen*4, 1, out); |
6715 | { |
2051 | fwrite(attr, attr_len*4, 1, out); |
6716 | #ifdef MAPTOOL_USE_SQL |
2052 | #if 0 |
6717 | fseek(towni, 0, SEEK_END); |
2053 | fwrite(&new, sizeof(new), 1, out_graph); |
6718 | fseek(streeti, 0, SEEK_END); |
2054 | fwrite(c+first, new.clen*4, 1, out_graph); |
6719 | long long towni_size = (long long)ftello(towni); |
2055 | fwrite(attr, attr_len*4, 1, out_graph); |
6720 | long long streeti_size = (long long)ftello(streeti); |
|
|
6721 | fprintf(stderr, "ftell towns=%lld\n", towni_size); |
|
|
6722 | fprintf(stderr, "ftell streets=%lld\n", streeti_size); |
|
|
6723 | |
|
|
6724 | fseek(towni, 0, SEEK_SET); |
|
|
6725 | fseek(streeti, 0, SEEK_SET); |
|
|
6726 | |
|
|
6727 | // size |
|
|
6728 | fwrite(&streeti_size, sizeof(long long), 1, out); |
|
|
6729 | // append street index file |
|
|
6730 | filecopy(streeti, out); |
|
|
6731 | // append town index file |
|
|
6732 | filecopy(towni, out); |
|
|
6733 | |
|
|
6734 | #endif |
2056 | #endif |
6735 | } |
2057 | } |
6736 | |
2058 | |
6737 | char* get_town_name_recursive(long long border_id, int level) |
2059 | int |
6738 | { |
|
|
6739 | char *ret = NULL; |
|
|
6740 | char *ret2 = NULL; |
|
|
6741 | char *str2 = NULL; |
|
|
6742 | int rc = 0; |
|
|
6743 | long long parent_rel_id = 0; |
|
|
6744 | |
|
|
6745 | //fprintf(stderr, "get town name:bid:%lld level:%d\n", border_id, level); |
|
|
6746 | |
|
|
6747 | // select this boundary |
|
|
6748 | sqlite3_bind_int64(stmt_bd_005, 1, border_id); |
|
|
6749 | rc = sqlite3_step(stmt_bd_005); |
|
|
6750 | switch (rc) |
|
|
6751 | { |
|
|
6752 | case SQLITE_DONE: |
|
|
6753 | break; |
|
|
6754 | case SQLITE_ROW: |
|
|
6755 | // rel_id, parent_rel_id, name |
|
|
6756 | parent_rel_id = sqlite3_column_int(stmt_bd_005, 1); |
|
|
6757 | ret = g_strdup_printf("%s", sqlite3_column_text(stmt_bd_005, 2)); |
|
|
6758 | sqlite3_reset(stmt_bd_005); |
|
|
6759 | |
|
|
6760 | //fprintf(stderr, "get town name:ret=%s\n", ret); |
|
|
6761 | |
|
|
6762 | if (level < 12) |
|
|
6763 | { |
|
|
6764 | str2 = get_town_name_recursive(parent_rel_id, (level + 1)); |
|
|
6765 | if (str2) |
|
|
6766 | { |
|
|
6767 | ret2 = g_strdup_printf("%s, %s", ret, str2); |
|
|
6768 | g_free(ret); |
|
|
6769 | g_free(str2); |
|
|
6770 | ret = ret2; |
|
|
6771 | } |
|
|
6772 | } |
|
|
6773 | break; |
|
|
6774 | default: |
|
|
6775 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
6776 | break; |
|
|
6777 | } |
|
|
6778 | |
|
|
6779 | if (level == 0) |
|
|
6780 | { |
|
|
6781 | sqlite3_reset(stmt_bd_005); |
|
|
6782 | } |
|
|
6783 | |
|
|
6784 | return ret; |
|
|
6785 | } |
|
|
6786 | |
|
|
6787 | void generate_town_index_file(FILE *out) |
|
|
6788 | { |
|
|
6789 | #ifdef MAPTOOL_USE_SQL |
|
|
6790 | |
|
|
6791 | struct town_index_data_block db; |
|
|
6792 | struct town_index_index_block_start is; |
|
|
6793 | struct town_index_index_block ib; |
|
|
6794 | char *townname = NULL; |
|
|
6795 | char *townname2 = NULL; |
|
|
6796 | long long last_len = 0; |
|
|
6797 | long long border_id = 0; |
|
|
6798 | int town_count = 0; |
|
|
6799 | int index_blocks; |
|
|
6800 | int index_block_towns; |
|
|
6801 | int i; |
|
|
6802 | int first; |
|
|
6803 | int rc = 0; |
|
|
6804 | int current_index_block; |
|
|
6805 | int current_index_block_old; |
|
|
6806 | char tmp_letter[TOWN_INDEX_TOWN_NAME_SIZE]; |
|
|
6807 | char *newfilename = NULL; |
|
|
6808 | char *newfilename_compr = NULL; |
|
|
6809 | |
|
|
6810 | int chunkSize; |
|
|
6811 | int stringLength; |
|
|
6812 | int ii22; |
|
|
6813 | |
|
|
6814 | FILE *town_index_index = NULL; |
|
|
6815 | FILE *town_index_index_data_block = NULL; |
|
|
6816 | |
|
|
6817 | |
|
|
6818 | // init compression for towns |
|
|
6819 | // init compression for towns |
|
|
6820 | IN_BUF_SIZE = t_IN_BUF_SIZE; |
|
|
6821 | s_inbuf = t_s_inbuf; |
|
|
6822 | OUT_BUF_SIZE = t_OUT_BUF_SIZE; |
|
|
6823 | s_outbuf = t_s_outbuf; |
|
|
6824 | COMP_OUT_BUF_SIZE = t_OUT_BUF_SIZE; |
|
|
6825 | // init compression for towns |
|
|
6826 | // init compression for towns |
|
|
6827 | |
|
|
6828 | |
|
|
6829 | sqlite3_step(stmt_town_sel006); |
|
|
6830 | town_count = sqlite3_column_int(stmt_town_sel006, 0); |
|
|
6831 | sqlite3_reset(stmt_town_sel006); |
|
|
6832 | |
|
|
6833 | // calculate number of index blocks |
|
|
6834 | index_blocks = 2; |
|
|
6835 | if (town_count > 1000000) |
|
|
6836 | { |
|
|
6837 | index_blocks = 100; |
|
|
6838 | } |
|
|
6839 | else if (town_count > 100000) |
|
|
6840 | { |
|
|
6841 | index_blocks = 50; |
|
|
6842 | } |
|
|
6843 | else if (town_count > 10000) |
|
|
6844 | { |
|
|
6845 | index_blocks = 10; |
|
|
6846 | } |
|
|
6847 | else if (town_count > 2000) |
|
|
6848 | { |
|
|
6849 | index_blocks = 5; |
|
|
6850 | } |
|
|
6851 | |
|
|
6852 | is.count_of_index_blocks = index_blocks; |
|
|
6853 | ib.offset = sizeof (is.count_of_index_blocks) + is.count_of_index_blocks * sizeof(struct town_index_index_block); // start offset = index size |
|
|
6854 | town_index_index = tempfile("", "town_index_index", 1); |
|
|
6855 | |
|
|
6856 | index_block_towns = (town_count / index_blocks); |
|
|
6857 | if ((index_block_towns * index_blocks) < town_count) |
|
|
6858 | { |
|
|
6859 | index_block_towns++; |
|
|
6860 | } |
|
|
6861 | |
|
|
6862 | fprintf(stderr, "towns per block=%d\n", index_block_towns); |
|
|
6863 | |
|
|
6864 | fprintf(stderr, "index size=%d\n", ib.offset); |
|
|
6865 | |
|
|
6866 | fprintf(stderr, "ftell=%d\n", ftell(town_index_index)); |
|
|
6867 | fwrite(&is, sizeof(struct town_index_index_block_start), 1, town_index_index); |
|
|
6868 | fprintf(stderr, "ftell=%d\n", ftell(town_index_index)); |
|
|
6869 | |
|
|
6870 | current_index_block = 1; |
|
|
6871 | current_index_block_old = 0; |
|
|
6872 | ib.len = 0; |
|
|
6873 | i = -1; |
|
|
6874 | first = 1; |
|
|
6875 | |
|
|
6876 | // loop thru all the towns |
|
|
6877 | do |
|
|
6878 | { |
|
|
6879 | rc = sqlite3_step(stmt_town_sel005); |
|
|
6880 | switch (rc) |
|
|
6881 | { |
|
|
6882 | case SQLITE_DONE: |
|
|
6883 | break; |
|
|
6884 | case SQLITE_ROW: |
|
|
6885 | i++; |
|
|
6886 | townname2 = NULL; |
|
|
6887 | db.town_id = sqlite3_column_int64(stmt_town_sel005, 0); |
|
|
6888 | db.country_id = sqlite3_column_int(stmt_town_sel005, 1); |
|
|
6889 | border_id = sqlite3_column_int64(stmt_town_sel005, 3); |
|
|
6890 | |
|
|
6891 | townname = get_town_name_recursive(border_id, 0); |
|
|
6892 | |
|
|
6893 | if (townname == NULL) |
|
|
6894 | { |
|
|
6895 | townname2 = g_strdup_printf("%s", sqlite3_column_text(stmt_town_sel005, 2)); |
|
|
6896 | } |
|
|
6897 | else |
|
|
6898 | { |
|
|
6899 | townname2 = townname; |
|
|
6900 | // townname2 = g_strdup_printf("%s", townname); // dont use the column result here, or string will be double! |
|
|
6901 | // g_free(townname); |
|
|
6902 | } |
|
|
6903 | //fprintf(stderr, "indextown:%s\n", townname2); |
|
|
6904 | |
|
|
6905 | //fprintf(stderr, "i=%d\n", i); |
|
|
6906 | //fprintf(stderr, "block=%d\n", current_index_block); |
|
|
6907 | if ((i + 1) > index_block_towns) |
|
|
6908 | { |
|
|
6909 | // start new index data block |
|
|
6910 | i = 0; |
|
|
6911 | current_index_block++; |
|
|
6912 | //fprintf(stderr, "incr block=%d\n", current_index_block); |
|
|
6913 | } |
|
|
6914 | |
|
|
6915 | if (current_index_block != current_index_block_old) |
|
|
6916 | { |
|
|
6917 | |
|
|
6918 | if (first != 1) |
|
|
6919 | { |
|
|
6920 | // close old datafile |
|
|
6921 | fclose(town_index_index_data_block); |
|
|
6922 | town_index_index_data_block = NULL; |
|
|
6923 | |
|
|
6924 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
6925 | { |
|
|
6926 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
6927 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
6928 | #endif |
|
|
6929 | } |
|
|
6930 | |
|
|
6931 | // append to indexfile |
|
|
6932 | fprintf(stderr, "first_id=%lld offset=%lld len=%lld\n", ib.first_id, ib.offset, ib.len); |
|
|
6933 | fwrite(&ib, sizeof(struct town_index_index_block), 1, town_index_index); |
|
|
6934 | |
|
|
6935 | if (newfilename) |
|
|
6936 | { |
|
|
6937 | g_free(newfilename); |
|
|
6938 | newfilename = NULL; |
|
|
6939 | } |
|
|
6940 | |
|
|
6941 | if (newfilename_compr) |
|
|
6942 | { |
|
|
6943 | g_free(newfilename_compr); |
|
|
6944 | newfilename_compr = NULL; |
|
|
6945 | } |
|
|
6946 | } |
|
|
6947 | |
|
|
6948 | current_index_block_old = current_index_block; |
|
|
6949 | ib.first_id = db.town_id; |
|
|
6950 | ib.offset = ib.offset + ib.len; |
|
|
6951 | |
|
|
6952 | // open new datafile |
|
|
6953 | newfilename = g_strdup_printf("town_index_index_%d", current_index_block); |
|
|
6954 | fprintf(stderr, "new data file: %s first_id=%lld\n", newfilename, ib.first_id); |
|
|
6955 | newfilename_compr = g_strdup_printf("town_index_index_compr_%d", current_index_block); |
|
|
6956 | town_index_index_data_block = tempfile("", newfilename, 1); |
|
|
6957 | fprintf(stderr, "town index file %d\n", current_index_block); |
|
|
6958 | |
|
|
6959 | ib.len = 0; |
|
|
6960 | } |
|
|
6961 | |
|
|
6962 | |
|
|
6963 | // now check if we need to split the string into parts |
|
|
6964 | if ((strlen(townname2) + 1) > TOWN_INDEX_TOWN_NAME_SIZE) |
|
|
6965 | { |
|
|
6966 | //fprintf(stderr, " block-split: START\n"); |
|
|
6967 | chunkSize = TOWN_INDEX_TOWN_NAME_SIZE - 1; |
|
|
6968 | stringLength = strlen(townname2); |
|
|
6969 | for (ii22 = 0; ii22 < stringLength ; ii22 += chunkSize) |
|
|
6970 | { |
|
|
6971 | if (ii22 + chunkSize > stringLength) |
|
|
6972 | { |
|
|
6973 | chunkSize = stringLength - ii22; |
|
|
6974 | db.town_name[chunkSize] = '\0'; // make sure string is terminated |
|
|
6975 | } |
|
|
6976 | strncpy(&db.town_name, (townname2 + ii22), chunkSize); |
|
|
6977 | db.town_name[TOWN_INDEX_TOWN_NAME_SIZE - 1] = '\0'; // make sure string is terminated |
|
|
6978 | if (ii22 > 0) |
|
|
6979 | { |
|
|
6980 | // set "split"-marker |
|
|
6981 | db.town_id = 0; |
|
|
6982 | db.country_id = 0; // setting this to zero is actually not needed |
|
|
6983 | } |
|
|
6984 | ib.len = ib.len + sizeof(struct town_index_data_block); |
|
|
6985 | //fprintf(stderr, "->block-split: town_id=%lld country_id=%d town_name=%s\n", db.town_id, db.country_id, db.town_name); |
|
|
6986 | fwrite(&db, sizeof(struct town_index_data_block), 1, town_index_index_data_block); |
|
|
6987 | } |
|
|
6988 | //fprintf(stderr, " block-split: END\n"); |
|
|
6989 | g_free(townname2); |
|
|
6990 | } |
|
|
6991 | else |
|
|
6992 | { |
|
|
6993 | strncpy(&db.town_name, townname2, TOWN_INDEX_TOWN_NAME_SIZE); |
|
|
6994 | g_free(townname2); |
|
|
6995 | db.town_name[TOWN_INDEX_TOWN_NAME_SIZE - 1]= '\0'; // make sure string is terminated |
|
|
6996 | |
|
|
6997 | ib.len = ib.len + sizeof(struct town_index_data_block); |
|
|
6998 | fwrite(&db, sizeof(struct town_index_data_block), 1, town_index_index_data_block); |
|
|
6999 | } |
|
|
7000 | |
|
|
7001 | if (first == 1) |
|
|
7002 | { |
|
|
7003 | first = 0; |
|
|
7004 | } |
|
|
7005 | |
|
|
7006 | break; |
|
|
7007 | default: |
|
|
7008 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7009 | break; |
|
|
7010 | } |
|
|
7011 | } |
|
|
7012 | while (rc == SQLITE_ROW); |
|
|
7013 | |
|
|
7014 | sqlite3_reset(stmt_town_sel005); |
|
|
7015 | |
|
|
7016 | // rest of the towns |
|
|
7017 | if (i > 0) |
|
|
7018 | { |
|
|
7019 | if (town_index_index_data_block) |
|
|
7020 | { |
|
|
7021 | fclose(town_index_index_data_block); |
|
|
7022 | town_index_index_data_block = NULL; |
|
|
7023 | } |
|
|
7024 | |
|
|
7025 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7026 | { |
|
|
7027 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7028 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7029 | #endif |
|
|
7030 | } |
|
|
7031 | |
|
|
7032 | // append to indexfile |
|
|
7033 | fprintf(stderr, "(last)first_id=%lld offset=%lld len=%lld\n", ib.first_id, ib.offset, ib.len); |
|
|
7034 | fwrite(&ib, sizeof(struct town_index_index_block), 1, town_index_index); |
|
|
7035 | } |
|
|
7036 | |
|
|
7037 | if (town_index_index != NULL) |
|
|
7038 | { |
|
|
7039 | fclose(town_index_index); |
|
|
7040 | } |
|
|
7041 | |
|
|
7042 | if (town_index_index_data_block != NULL) |
|
|
7043 | { |
|
|
7044 | fclose(town_index_index_data_block); |
|
|
7045 | } |
|
|
7046 | |
|
|
7047 | if (newfilename) |
|
|
7048 | { |
|
|
7049 | g_free(newfilename); |
|
|
7050 | newfilename = NULL; |
|
|
7051 | } |
|
|
7052 | |
|
|
7053 | if (newfilename_compr) |
|
|
7054 | { |
|
|
7055 | g_free(newfilename_compr); |
|
|
7056 | newfilename_compr = NULL; |
|
|
7057 | } |
|
|
7058 | |
|
|
7059 | |
|
|
7060 | |
|
|
7061 | |
|
|
7062 | |
|
|
7063 | // put all parts together |
|
|
7064 | town_index_index = tempfile("", "town_index_index", 0); |
|
|
7065 | filecopy(town_index_index, out); |
|
|
7066 | fclose(town_index_index); |
|
|
7067 | tempfile_unlink("", "town_index_index"); |
|
|
7068 | |
|
|
7069 | for (i=1;i < (current_index_block + 2);i++) |
|
|
7070 | { |
|
|
7071 | fprintf(stderr, "index block #%d\n", i); |
|
|
7072 | newfilename = g_strdup_printf("town_index_index_%d", i); |
|
|
7073 | town_index_index_data_block = tempfile("", newfilename, 0); |
|
|
7074 | |
|
|
7075 | if (town_index_index_data_block) |
|
|
7076 | { |
|
|
7077 | fprintf(stderr, "using: index block #%d in %s\n", i, newfilename); |
|
|
7078 | filecopy(town_index_index_data_block, out); |
|
|
7079 | fclose(town_index_index_data_block); |
|
|
7080 | tempfile_unlink("", newfilename); |
|
|
7081 | } |
|
|
7082 | |
|
|
7083 | if (newfilename) |
|
|
7084 | { |
|
|
7085 | g_free(newfilename); |
|
|
7086 | newfilename = NULL; |
|
|
7087 | } |
|
|
7088 | } |
|
|
7089 | |
|
|
7090 | |
|
|
7091 | |
|
|
7092 | #endif |
|
|
7093 | } |
|
|
7094 | |
|
|
7095 | void generate_street_index_file(FILE *out) |
|
|
7096 | { |
|
|
7097 | #ifdef MAPTOOL_USE_SQL |
|
|
7098 | int rc = 0; |
|
|
7099 | int i; |
|
|
7100 | struct streets_index_data_block db; |
|
|
7101 | struct streets_index_index_block_start is; |
|
|
7102 | struct streets_index_index_block ib; |
|
|
7103 | long long last_len = 0; |
|
|
7104 | static const char *alpha = "abcdefghijklmnopqrstuvwxyz"; |
|
|
7105 | char tmp_letter[STREET_INDEX_STREET_NAME_SIZE]; |
|
|
7106 | char *newfilename = NULL; |
|
|
7107 | char *newfilename_compr = NULL; |
|
|
7108 | int count_of_blocks; |
|
|
7109 | int do_rest; |
|
|
7110 | int num1; |
|
|
7111 | int num2; |
|
|
7112 | |
|
|
7113 | FILE *street_index_index; |
|
|
7114 | FILE *street_index_index_data_block; |
|
|
7115 | |
|
|
7116 | // init compression for streets |
|
|
7117 | // init compression for streets |
|
|
7118 | IN_BUF_SIZE = s_IN_BUF_SIZE; |
|
|
7119 | s_inbuf = s_s_inbuf; |
|
|
7120 | OUT_BUF_SIZE = s_OUT_BUF_SIZE; |
|
|
7121 | s_outbuf = s_s_outbuf; |
|
|
7122 | COMP_OUT_BUF_SIZE = s_OUT_BUF_SIZE; |
|
|
7123 | // init compression for streets |
|
|
7124 | // init compression for streets |
|
|
7125 | |
|
|
7126 | |
|
|
7127 | is.count_of_index_blocks = 703; // 26+1 letters ((26+1)*26 + 1) = 703 |
|
|
7128 | ib.offset = sizeof (is.count_of_index_blocks) + is.count_of_index_blocks * sizeof(struct streets_index_index_block); // start offset = index size |
|
|
7129 | street_index_index = tempfile("", "street_index_index", 1); |
|
|
7130 | fprintf(stderr, "index size=%d\n", ib.offset); |
|
|
7131 | |
|
|
7132 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7133 | fwrite(&is, sizeof(struct streets_index_index_block_start), 1, street_index_index); |
|
|
7134 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7135 | |
|
|
7136 | // fprintf(stderr, "len=%d\n", strlen(alpha)); |
|
|
7137 | |
|
|
7138 | count_of_blocks = 702; |
|
|
7139 | do_rest = 0; |
|
|
7140 | num1 = 1; |
|
|
7141 | num2 = 0; |
|
|
7142 | for (i=0; i < count_of_blocks; i++) |
|
|
7143 | { |
|
|
7144 | num2++; |
|
|
7145 | do_rest = 0; |
|
|
7146 | if (num2 == 27) |
|
|
7147 | { |
|
|
7148 | do_rest = 1; |
|
|
7149 | } |
|
|
7150 | else if (num2 > 27) |
|
|
7151 | { |
|
|
7152 | num2 = 1; |
|
|
7153 | num1++; |
|
|
7154 | } |
|
|
7155 | |
|
|
7156 | fprintf(stderr, "i=%d num1=%d num2=%d\n", i, num1, num2); |
|
|
7157 | |
|
|
7158 | if (do_rest) |
|
|
7159 | { |
|
|
7160 | sprintf(tmp_letter, "%c%%", alpha[num1 - 1]); |
|
|
7161 | } |
|
|
7162 | else |
|
|
7163 | { |
|
|
7164 | sprintf(tmp_letter, "%c%c%%", alpha[num1 - 1], alpha[num2 - 1]); |
|
|
7165 | } |
|
|
7166 | fprintf(stderr, "letter=%s\n", tmp_letter); |
|
|
7167 | |
|
|
7168 | ib.first_letter = alpha[num1 - 1]; |
|
|
7169 | ib.len = 0; |
|
|
7170 | |
|
|
7171 | newfilename = g_strdup_printf("street_index_index_%d", i); |
|
|
7172 | newfilename_compr = g_strdup_printf("street_index_index_compr_%d", i); |
|
|
7173 | street_index_index_data_block = tempfile("", newfilename, 1); |
|
|
7174 | |
|
|
7175 | // loop thru all the streets that match '<letter>...' |
|
|
7176 | sqlite3_bind_text(stmt_sel003, 1, tmp_letter, -1, SQLITE_STATIC); |
|
|
7177 | do |
|
|
7178 | { |
|
|
7179 | rc = sqlite3_step(stmt_sel003); |
|
|
7180 | switch (rc) |
|
|
7181 | { |
|
|
7182 | case SQLITE_DONE: |
|
|
7183 | break; |
|
|
7184 | case SQLITE_ROW: |
|
|
7185 | db.town_id = sqlite3_column_int64(stmt_sel003, 0); |
|
|
7186 | db.lat = transform_from_geo_lat(sqlite3_column_double(stmt_sel003, 1)); |
|
|
7187 | db.lon = transform_from_geo_lon(sqlite3_column_double(stmt_sel003, 2)); |
|
|
7188 | strncpy(&db.street_name, sqlite3_column_text(stmt_sel003, 3), STREET_INDEX_STREET_NAME_SIZE); |
|
|
7189 | db.street_name[STREET_INDEX_STREET_NAME_SIZE - 1]= '\0'; // make sure string is terminated |
|
|
7190 | |
|
|
7191 | ib.len = ib.len + sizeof(struct streets_index_data_block); |
|
|
7192 | |
|
|
7193 | // fprintf(stderr ,"gen_street_index id:%lld lat:%d lon:%d name:%s\n", db.town_id, db.lat, db.lon, db.street_name); |
|
|
7194 | fwrite(&db, sizeof(struct streets_index_data_block), 1, street_index_index_data_block); |
|
|
7195 | |
|
|
7196 | break; |
|
|
7197 | default: |
|
|
7198 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7199 | break; |
|
|
7200 | } |
|
|
7201 | } |
|
|
7202 | while (rc == SQLITE_ROW); |
|
|
7203 | |
|
|
7204 | sqlite3_reset(stmt_sel003); |
|
|
7205 | fclose(street_index_index_data_block); |
|
|
7206 | |
|
|
7207 | sqlite3_bind_int(stmt_sel003u, 1, (i + 1)); |
|
|
7208 | sqlite3_bind_text(stmt_sel003u, 2, tmp_letter, -1, SQLITE_STATIC); |
|
|
7209 | sqlite3_step(stmt_sel003u); |
|
|
7210 | sqlite3_reset(stmt_sel003u); |
|
|
7211 | // sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7212 | |
|
|
7213 | |
|
|
7214 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7215 | { |
|
|
7216 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7217 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7218 | #endif |
|
|
7219 | } |
|
|
7220 | |
|
|
7221 | last_len = ib.len; |
|
|
7222 | fprintf(stderr ,"letter=%c offset=%lld len=%lld\n", ib.first_letter, ib.offset, ib.len); |
|
|
7223 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7224 | fwrite(&ib, sizeof(struct streets_index_index_block), 1, street_index_index); |
|
|
7225 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7226 | ib.offset = ib.offset + last_len; |
|
|
7227 | |
|
|
7228 | if (newfilename) |
|
|
7229 | { |
|
|
7230 | g_free(newfilename); |
|
|
7231 | newfilename = NULL; |
|
|
7232 | } |
|
|
7233 | |
|
|
7234 | if (newfilename_compr) |
|
|
7235 | { |
|
|
7236 | g_free(newfilename_compr); |
|
|
7237 | newfilename_compr = NULL; |
|
|
7238 | } |
|
|
7239 | } |
|
|
7240 | |
|
|
7241 | // rest of the streets |
|
|
7242 | fprintf(stderr, "rest of letters\n"); |
|
|
7243 | |
|
|
7244 | ib.first_letter = 65; // dummy "A" |
|
|
7245 | ib.len = 0; |
|
|
7246 | |
|
|
7247 | newfilename = g_strdup_printf("street_index_index_%d", i); |
|
|
7248 | newfilename_compr = g_strdup_printf("street_index_index_compr_%d", i); |
|
|
7249 | street_index_index_data_block = tempfile("", newfilename, 1); |
|
|
7250 | |
|
|
7251 | do |
|
|
7252 | { |
|
|
7253 | rc = sqlite3_step(stmt_sel004); |
|
|
7254 | switch (rc) |
|
|
7255 | { |
|
|
7256 | case SQLITE_DONE: |
|
|
7257 | break; |
|
|
7258 | case SQLITE_ROW: |
|
|
7259 | db.town_id = sqlite3_column_int64(stmt_sel004, 0); |
|
|
7260 | db.lat = transform_from_geo_lat(sqlite3_column_double(stmt_sel004, 1)); |
|
|
7261 | db.lon = transform_from_geo_lon(sqlite3_column_double(stmt_sel004, 2)); |
|
|
7262 | strncpy(&db.street_name, sqlite3_column_text(stmt_sel004, 3), STREET_INDEX_STREET_NAME_SIZE); |
|
|
7263 | db.street_name[STREET_INDEX_STREET_NAME_SIZE - 1]= '\0'; // make sure string is terminated |
|
|
7264 | |
|
|
7265 | ib.len = ib.len + sizeof(struct streets_index_data_block); |
|
|
7266 | |
|
|
7267 | //fprintf(stderr ,"id:%lld lat:%d lon:%d name:%s\n", db.town_id, db.lat, db.lon, db.street_name); |
|
|
7268 | fwrite(&db, sizeof(struct streets_index_data_block), 1, street_index_index_data_block); |
|
|
7269 | |
|
|
7270 | break; |
|
|
7271 | default: |
|
|
7272 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7273 | break; |
|
|
7274 | } |
|
|
7275 | } |
|
|
7276 | while (rc == SQLITE_ROW); |
|
|
7277 | sqlite3_reset(stmt_sel004); |
|
|
7278 | fclose(street_index_index_data_block); |
|
|
7279 | |
|
|
7280 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7281 | { |
|
|
7282 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7283 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7284 | #endif |
|
|
7285 | } |
|
|
7286 | |
|
|
7287 | last_len = ib.len; |
|
|
7288 | fprintf(stderr ,"letter=%c offset=%lld len=%lld\n", ib.first_letter, ib.offset, ib.len); |
|
|
7289 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7290 | fwrite(&ib, sizeof(struct streets_index_index_block), 1, street_index_index); |
|
|
7291 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7292 | // ib.offset = ib.offset + last_len; |
|
|
7293 | |
|
|
7294 | |
|
|
7295 | fclose(street_index_index); |
|
|
7296 | |
|
|
7297 | if (newfilename) |
|
|
7298 | { |
|
|
7299 | g_free(newfilename); |
|
|
7300 | newfilename = NULL; |
|
|
7301 | } |
|
|
7302 | |
|
|
7303 | if (newfilename_compr) |
|
|
7304 | { |
|
|
7305 | g_free(newfilename_compr); |
|
|
7306 | newfilename_compr = NULL; |
|
|
7307 | } |
|
|
7308 | |
|
|
7309 | // put all parts together |
|
|
7310 | street_index_index = tempfile("", "street_index_index", 0); |
|
|
7311 | filecopy(street_index_index, out); |
|
|
7312 | fclose(street_index_index); |
|
|
7313 | tempfile_unlink("", "street_index_index"); |
|
|
7314 | |
|
|
7315 | for (i=0;i < (is.count_of_index_blocks + 1);i++) |
|
|
7316 | { |
|
|
7317 | fprintf(stderr, "cat #%d\n", i); |
|
|
7318 | newfilename = g_strdup_printf("street_index_index_%d", i); |
|
|
7319 | street_index_index_data_block = tempfile("", newfilename, 0); |
|
|
7320 | |
|
|
7321 | if (street_index_index_data_block) |
|
|
7322 | { |
|
|
7323 | filecopy(street_index_index_data_block, out); |
|
|
7324 | fclose(street_index_index_data_block); |
|
|
7325 | tempfile_unlink("", newfilename); |
|
|
7326 | } |
|
|
7327 | |
|
|
7328 | if (newfilename) |
|
|
7329 | { |
|
|
7330 | g_free(newfilename); |
|
|
7331 | newfilename = NULL; |
|
|
7332 | } |
|
|
7333 | } |
|
|
7334 | #endif |
|
|
7335 | } |
|
|
7336 | |
|
|
7337 | void remove_attr_str(struct item_bin *ib, int attr_type) |
|
|
7338 | { |
|
|
7339 | char *attr_str = item_bin_get_attr(ib, attr_type, NULL); |
|
|
7340 | if (attr_str) |
|
|
7341 | { |
|
|
7342 | item_bin_remove_attr(ib, attr_str); |
|
|
7343 | } |
|
|
7344 | } |
|
|
7345 | |
|
|
7346 | int remove_useless_tags_from_ways(FILE *in, FILE *out) |
|
|
7347 | { |
|
|
7348 | struct item_bin *ib; |
|
|
7349 | long long *wayid; |
|
|
7350 | int *dup; |
|
|
7351 | |
|
|
7352 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
|
|
7353 | { |
|
|
7354 | // attr_street_name_dummy |
|
|
7355 | remove_attr_str(ib, attr_street_name_dummy); |
|
|
7356 | // attr_house_number_dummy |
|
|
7357 | remove_attr_str(ib, attr_house_number_dummy); |
|
|
7358 | // attr_debug |
|
|
7359 | remove_attr_str(ib, attr_debug); |
|
|
7360 | |
|
|
7361 | // osm wayid |
|
|
7362 | //wayid = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
|
|
7363 | //if (wayid) |
|
|
7364 | //{ |
|
|
7365 | // item_bin_remove_attr(ib, wayid); |
|
|
7366 | //} |
|
|
7367 | |
|
|
7368 | // duplicate_way |
|
|
7369 | dup = item_bin_get_attr(ib, attr_duplicate_way, NULL); |
|
|
7370 | if (dup) |
|
|
7371 | { |
|
|
7372 | item_bin_remove_attr(ib, dup); |
|
|
7373 | } |
|
|
7374 | |
|
|
7375 | // write way to outfile |
|
|
7376 | item_bin_write(ib, out); |
|
|
7377 | } |
|
|
7378 | } |
|
|
7379 | |
|
|
7380 | int remove_useless_tags_from_nodes(FILE *in, FILE *out) |
|
|
7381 | { |
|
|
7382 | struct item_bin *ib; |
|
|
7383 | long long *nodeid; |
|
|
7384 | |
|
|
7385 | while ((ib = read_item(in, 0))) // loop thru all "nodes" from file "in" |
|
|
7386 | { |
|
|
7387 | // attr_debug |
|
|
7388 | remove_attr_str(ib, attr_debug); |
|
|
7389 | |
|
|
7390 | // osm nodeid |
|
|
7391 | nodeid = item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
|
|
7392 | if (nodeid) |
|
|
7393 | { |
|
|
7394 | item_bin_remove_attr(ib, nodeid); |
|
|
7395 | } |
|
|
7396 | |
|
|
7397 | // write node to outfile |
|
|
7398 | item_bin_write(ib, out); |
|
|
7399 | } |
|
|
7400 | } |
|
|
7401 | |
|
|
7402 | int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final) |
2060 | map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final) |
7403 | { |
2061 | { |
7404 | struct coord *c; |
2062 | struct coord *c; |
7405 | int i, ccount, last, remaining; |
2063 | int i,ccount,last,remaining; |
7406 | osmid ndref; |
2064 | osmid ndref; |
7407 | struct item_bin *ib; |
2065 | struct item_bin *ib; |
7408 | struct node_item *ni; |
2066 | struct node_item *ni; |
7409 | long long last_id = 0; |
2067 | long long last_id=0; |
7410 | long long ways_count = 0; |
|
|
7411 | |
2068 | |
7412 | processed_nodes = processed_nodes_out = processed_ways = processed_relations = processed_tiles = 0; |
2069 | processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0; |
7413 | //sig_alrm(0); |
2070 | sig_alrm(0); |
7414 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
2071 | while ((ib=read_item(in))) { |
7415 | { |
2072 | #if 0 |
7416 | |
|
|
7417 | //long long *id; |
|
|
7418 | //id = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
|
|
7419 | //if (id) |
|
|
7420 | //{ |
|
|
7421 | // fprintf(stderr,"wayid:%lld type:0x%x len:%d clen:%d\n", *id, ib->type, ib->len, (ib->clen / 2)); |
2073 | fprintf(stderr,"type 0x%x len %d clen %d\n", ib->type, ib->len, ib->clen); |
7422 | //} |
2074 | #endif |
7423 | |
|
|
7424 | ccount = ib->clen / 2; |
2075 | ccount=ib->clen/2; |
7425 | |
|
|
7426 | if (ccount <= 1) |
2076 | if (ccount <= 1) |
7427 | { |
|
|
7428 | continue; |
2077 | continue; |
7429 | } |
|
|
7430 | |
|
|
7431 | //fprintf(stderr,"********DUMP ww1***********\n"); |
|
|
7432 | //dump_itembin(ib); |
|
|
7433 | //fprintf(stderr,"********DUMP ww1***********\n"); |
|
|
7434 | |
|
|
7435 | |
|
|
7436 | ways_count++; |
|
|
7437 | if ((ways_count % 10000000) == 0) |
|
|
7438 | { |
|
|
7439 | fprintf(stderr, "ways: %lld\n", ways_count); |
|
|
7440 | } |
|
|
7441 | |
|
|
7442 | c = (struct coord *) (ib + 1); |
2078 | c=(struct coord *)(ib+1); |
7443 | last = 0; |
2079 | last=0; |
7444 | for (i = 0; i < ccount; i++) // loop thru all the coordinates (nodes) of this way |
2080 | for (i = 0 ; i < ccount ; i++) { |
7445 | { |
|
|
7446 | //fprintf(stderr, "i=%d ccount=%d\n", i, ccount); |
|
|
7447 | |
|
|
7448 | if (IS_REF(c[i])) |
2081 | if (IS_REF(c[i])) { |
7449 | { |
|
|
7450 | //fprintf(stderr, "is ref\n"); |
|
|
7451 | ndref = REF(c[i]); |
2082 | ndref=REF(c[i]); |
7452 | //fprintf(stderr, "ndref=%d\n", ndref); |
|
|
7453 | ni = node_item_get_fast(ndref, 0); |
2083 | ni=node_item_get(ndref); |
7454 | if (ni) |
2084 | if (ni) { |
7455 | { |
2085 | c[i]=ni->c; |
7456 | //fprintf(stderr, "ni TRUE\n"); |
|
|
7457 | |
|
|
7458 | c[i] = ni->c; // write "lat,long" from node into way !! |
|
|
7459 | if (ni->ref_way > 1 && i != 0 && i != ccount - 1 && i != last && item_get_default_flags(ib->type)) |
2086 | if (ni->ref_way > 1 && i != 0 && i != ccount-1 && i != last && item_get_default_flags(ib->type)) { |
7460 | { |
|
|
7461 | //fprintf(stderr, "wr i 001\n"); |
|
|
7462 | // if "ref_way > 1" , means this node belongs to more than 1 way, so it must be an intersection |
|
|
7463 | // *** write_item_part(out, out_index, out_graph, ib, last, i, &last_id); |
2087 | write_item_part(out, out_index, out_graph, ib, last, i, &last_id); |
7464 | write_item_part(out, NULL, out_graph, ib, last, i, &last_id); |
|
|
7465 | last = i; |
2088 | last=i; |
7466 | } |
2089 | } |
7467 | } |
|
|
7468 | else if (final) |
2090 | } else if (final) { |
7469 | { |
|
|
7470 | //fprintf(stderr, "wr i 002(f)\n"); |
|
|
7471 | |
|
|
7472 | //osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to "); |
2091 | osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to "); |
7473 | //osm_warning("node",ndref,1,"\n"); |
2092 | osm_warning("node",ndref,1,"\n"); |
7474 | remaining = (ib->len + 1) * 4 - sizeof(struct item_bin) - i * sizeof(struct coord); |
2093 | remaining=(ib->len+1)*4-sizeof(struct item_bin)-i*sizeof(struct coord); |
7475 | memmove(&c[i], &c[i + 1], remaining); |
2094 | memmove(&c[i], &c[i+1], remaining); |
7476 | ib->clen -= 2; |
2095 | ib->clen-=2; |
7477 | ib->len -= 2; |
2096 | ib->len-=2; |
7478 | i--; |
2097 | i--; |
7479 | ccount--; |
2098 | ccount--; |
7480 | } |
2099 | } |
7481 | } |
2100 | } |
7482 | } |
2101 | } |
7483 | |
|
|
7484 | if (ccount) |
2102 | if (ccount) { |
7485 | { |
|
|
7486 | //fprintf(stderr, "wr i 003(ccount)\n"); |
|
|
7487 | |
|
|
7488 | //fprintf(stderr,"*x*coastline*x*\n"); |
|
|
7489 | // ***** write_item_part(out, out_index, out_graph, ib, last, ccount - 1, &last_id); |
2103 | write_item_part(out, out_index, out_graph, ib, last, ccount-1, &last_id); |
7490 | write_item_part(out, NULL, out_graph, ib, last, ccount - 1, &last_id); |
|
|
7491 | if (final && ib->type == type_water_line && out_coastline) |
2104 | if (final && ib->type == type_water_line && out_coastline) { |
7492 | { |
|
|
7493 | //fprintf(stderr,"write out_coastline\n"); |
|
|
7494 | write_item_part(out_coastline, NULL, NULL, ib, last, ccount - 1, NULL); |
2105 | write_item_part(out_coastline, NULL, NULL, ib, last, ccount-1, NULL); |
7495 | } |
2106 | } |
7496 | } |
2107 | } |
7497 | } |
2108 | } |
7498 | //sig_alrm(0); |
2109 | sig_alrm(0); |
7499 | //sig_alrm_end(); |
2110 | sig_alrm_end(); |
7500 | return 0; |
2111 | return 0; |
7501 | } |
2112 | } |
7502 | |
2113 | |
|
|
2114 | static void |
7503 | static void index_country_add(struct zip_info *info, int country_id, int zipnum) |
2115 | index_country_add(struct zip_info *info, int country_id, int zipnum) |
7504 | { |
2116 | { |
7505 | struct item_bin *item_bin = init_item(type_countryindex, 0); |
2117 | struct item_bin *item_bin=init_item(type_countryindex); |
7506 | item_bin_add_attr_int(item_bin, attr_country_id, country_id); |
2118 | item_bin_add_attr_int(item_bin, attr_country_id, country_id); |
7507 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, zipnum); |
2119 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, zipnum); |
7508 | item_bin_write(item_bin, zip_get_index(info)); |
2120 | item_bin_write(item_bin, zip_get_index(info)); |
7509 | } |
2121 | } |
7510 | |
2122 | |
|
|
2123 | void |
7511 | void write_countrydir(struct zip_info *zip_info) |
2124 | write_countrydir(struct zip_info *zip_info) |
7512 | { |
2125 | { |
7513 | int i, zipnum, num; |
2126 | int i,zipnum,num; |
7514 | int max = 11; |
2127 | int max=11; |
7515 | char tilename[32]; |
2128 | char tilename[32]; |
7516 | char filename[32]; |
2129 | char filename[32]; |
7517 | char suffix[32]; |
2130 | char suffix[32]; |
7518 | struct country_table *co; |
2131 | struct country_table *co; |
7519 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
2132 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { |
7520 | { |
|
|
7521 | co = &country_table[i]; |
2133 | co=&country_table[i]; |
7522 | if (co->size) |
2134 | if (co->size) { |
7523 | { |
|
|
7524 | num = 0; |
2135 | num=0; |
7525 | do |
2136 | do { |
7526 | { |
|
|
7527 | tilename[0] = '\0'; |
2137 | tilename[0]='\0'; |
7528 | sprintf(suffix, "s%d", num); |
2138 | sprintf(suffix,"s%d", num); |
7529 | num++; |
2139 | num++; |
7530 | tile(&co->r, suffix, tilename, max, overlap, NULL); |
2140 | tile(&co->r, suffix, tilename, max, overlap, NULL); |
7531 | |
|
|
7532 | sprintf(filename, "country_%d.tmp", co->countryid); |
2141 | sprintf(filename,"country_%d.bin", co->countryid); |
7533 | if (debug_itembin(4)) |
|
|
7534 | { |
|
|
7535 | fprintf(stderr, "write_countrydir: tilename=%s country_%d.tmp\n", tilename, co->countryid); |
|
|
7536 | } |
|
|
7537 | zipnum = add_aux_tile(zip_info, tilename, filename, co->size); |
2142 | zipnum=add_aux_tile(zip_info, tilename, filename, co->size); |
7538 | } |
|
|
7539 | while (zipnum == -1); |
2143 | } while (zipnum == -1); |
7540 | index_country_add(zip_info, co->countryid, zipnum); |
2144 | index_country_add(zip_info,co->countryid,zipnum); |
7541 | } |
|
|
7542 | } |
|
|
7543 | } |
|
|
7544 | |
|
|
7545 | void load_countries(void) |
|
|
7546 | { |
|
|
7547 | char filename[32]; |
|
|
7548 | FILE *f; |
|
|
7549 | int i; |
|
|
7550 | struct country_table *co; |
|
|
7551 | |
|
|
7552 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
|
|
7553 | { |
|
|
7554 | co = &country_table[i]; |
|
|
7555 | sprintf(filename, "country_%d.tmp", co->countryid); |
|
|
7556 | if (debug_itembin(4)) |
|
|
7557 | { |
|
|
7558 | fprintf(stderr, "load_countries: country_%d.tmp\n", co->countryid); |
|
|
7559 | } |
|
|
7560 | |
|
|
7561 | f = fopen(filename, "rb"); |
|
|
7562 | if (f) |
|
|
7563 | { |
|
|
7564 | int i, first = 1; |
|
|
7565 | struct item_bin *ib; |
|
|
7566 | while ((ib = read_item(f, 0))) |
|
|
7567 | { |
|
|
7568 | struct coord *c = (struct coord *) (ib + 1); |
|
|
7569 | co->size += ib->len * 4 + 4; |
|
|
7570 | for (i = 0; i < ib->clen / 2; i++) |
|
|
7571 | { |
|
|
7572 | if (first) |
|
|
7573 | { |
|
|
7574 | co->r.l = c[i]; |
|
|
7575 | co->r.h = c[i]; |
|
|
7576 | first = 0; |
|
|
7577 | } |
|
|
7578 | else |
|
|
7579 | { |
|
|
7580 | bbox_extend(&c[i], &co->r); |
|
|
7581 | } |
|
|
7582 | } |
|
|
7583 | } |
2145 | } |
7584 | fseek(f, 0, SEEK_END); |
|
|
7585 | co->size = ftell(f); |
|
|
7586 | fclose(f); |
|
|
7587 | } |
2146 | } |
7588 | } |
|
|
7589 | } |
2147 | } |
7590 | |
2148 | |
|
|
2149 | void |
7591 | void remove_countryfiles(void) |
2150 | remove_countryfiles(void) |
7592 | { |
2151 | { |
7593 | int i; |
2152 | int i; |
7594 | char filename[32]; |
2153 | char filename[32]; |
7595 | struct country_table *co; |
2154 | struct country_table *co; |
7596 | |
2155 | |
7597 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
2156 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { |
7598 | { |
|
|
7599 | co = &country_table[i]; |
2157 | co=&country_table[i]; |
7600 | if (co->size) |
2158 | if (co->size) { |
7601 | { |
|
|
7602 | sprintf(filename, "country_%d.tmp", co->countryid); |
2159 | sprintf(filename,"country_%d.bin", co->countryid); |
7603 | unlink(filename); |
2160 | unlink(filename); |
7604 | } |
2161 | } |
7605 | } |
2162 | } |
7606 | } |
2163 | } |
7607 | |
2164 | |
7608 | void osm_init(FILE* rule_file) |
2165 | void osm_init(FILE* rule_file) |
7609 | { |
2166 | { |
7610 | build_attrmap(rule_file); |
2167 | build_attrmap(rule_file); |
7611 | build_countrytable(); |
2168 | build_countrytable(); |
7612 | } |
2169 | } |
7613 | |
2170 | |