|
|
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 | |
1 | /** |
20 | /** |
2 | * Navit, a modular navigation system. |
21 | * Navit, a modular navigation system. |
3 | * Copyright (C) 2005-2011 Navit Team |
22 | * Copyright (C) 2005-2011 Navit Team |
4 | * |
23 | * |
5 | * This program is free software; you can redistribute it and/or |
24 | * This program is free software; you can redistribute it and/or |
… | |
… | |
14 | * You should have received a copy of the GNU General Public License |
33 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the |
34 | * along with this program; if not, write to the |
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
35 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
36 | * Boston, MA 02110-1301, USA. |
18 | */ |
37 | */ |
|
|
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> |
19 | #include <unistd.h> |
111 | #include <unistd.h> |
|
|
112 | #include <time.h> |
|
|
113 | #include <stdio.h> |
20 | #include <string.h> |
114 | #include <string.h> |
21 | #include <stdlib.h> |
115 | #include <stdlib.h> |
22 | #include <math.h> |
116 | #include <math.h> |
23 | #include "maptool.h" |
|
|
24 | #include "debug.h" |
117 | #include "debug.h" |
25 | #include "linguistics.h" |
118 | #include "linguistics.h" |
26 | #include "country.h" |
119 | #include "country.h" |
27 | #include "file.h" |
120 | #include "file.h" |
28 | |
121 | |
|
|
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 | |
29 | #define _FILE_OFFSET_BITS 64 |
144 | #define _FILE_OFFSET_BITS 64 |
30 | #define _LARGEFILE_SOURCE |
145 | #define _LARGEFILE_SOURCE |
31 | #define _LARGEFILE64_SOURCE |
146 | #define _LARGEFILE64_SOURCE |
32 | |
147 | |
33 | extern int doway2poi; |
148 | extern int doway2poi; |
34 | |
149 | |
35 | static int in_way, in_node, in_relation; |
150 | static int in_way, in_node, in_relation; |
36 | static int nodeid,wayid; |
151 | static osmid nodeid, wayid; |
37 | long long current_id; |
152 | osmid current_id; |
38 | |
153 | |
39 | static GHashTable *attr_hash,*country_table_hash,*attr_hash; |
154 | static GHashTable *attr_hash, *country_table_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 | void add_waynode_to_db(osmid ref, int c_count); |
40 | |
158 | |
41 | static char *attr_present; |
159 | static char *attr_present; |
42 | static int attr_present_count; |
160 | static int attr_present_count; |
43 | |
161 | |
44 | static struct item_bin item; |
162 | static struct item_bin item; |
45 | |
163 | |
46 | |
|
|
47 | int maxspeed_attr_value; |
164 | int maxspeed_attr_value; |
48 | |
165 | |
49 | char debug_attr_buffer[BUFFER_SIZE]; |
166 | char debug_attr_buffer[BUFFER_SIZE]; |
50 | |
167 | |
51 | int flags[4]; |
168 | int flags[4]; |
52 | |
169 | |
53 | int flags_attr_value; |
170 | int flags_attr_value; |
54 | |
171 | |
55 | struct attr_bin osmid_attr; |
172 | struct attr_bin osmid_attr; |
56 | long int osmid_attr_value; |
173 | osmid osmid_attr_value; |
57 | |
174 | |
58 | char is_in_buffer[BUFFER_SIZE]; |
175 | char is_in_buffer[BUFFER_SIZE]; |
59 | |
176 | |
60 | char attr_strings_buffer[BUFFER_SIZE*16]; |
177 | char attr_strings_buffer[BUFFER_SIZE * 16]; |
61 | int attr_strings_buffer_len; |
178 | int attr_strings_buffer_len; |
62 | |
179 | int alt_name_found = 0; |
63 | |
180 | |
64 | struct coord coord_buffer[65536]; |
181 | struct coord coord_buffer[65536]; |
65 | |
182 | |
66 | struct attr_mapping { |
183 | struct attr_mapping |
|
|
184 | { |
67 | enum item_type type; |
185 | enum item_type type; |
68 | int attr_present_idx_count; |
186 | int attr_present_idx_count; |
69 | int attr_present_idx[0]; |
187 | int attr_present_idx[0]; |
70 | }; |
188 | }; |
71 | |
189 | |
72 | static void nodes_ref_item_bin(struct item_bin *ib); |
190 | static void nodes_ref_item_bin(struct item_bin *ib, int local_thread_num, osmid this_way_id); |
73 | |
|
|
74 | |
191 | |
75 | static struct attr_mapping **attr_mapping_node; |
192 | static struct attr_mapping **attr_mapping_node; |
76 | static int attr_mapping_node_count; |
193 | static int attr_mapping_node_count; |
77 | static struct attr_mapping **attr_mapping_way; |
194 | static struct attr_mapping **attr_mapping_way; |
78 | static int attr_mapping_way_count; |
195 | static int attr_mapping_way_count; |
… | |
… | |
80 | static int attr_mapping_way2poi_count; |
197 | static int attr_mapping_way2poi_count; |
81 | |
198 | |
82 | static char *attr_present; |
199 | static char *attr_present; |
83 | static int attr_present_count; |
200 | static int attr_present_count; |
84 | |
201 | |
|
|
202 | static long long seekpos1; |
85 | |
203 | |
86 | |
|
|
87 | enum attr_strings { |
204 | enum attr_strings |
88 | attr_string_phone, |
205 | { |
89 | attr_string_fax, |
206 | attr_string_phone, attr_string_fax, attr_string_email, attr_string_url, attr_string_street_name, attr_string_street_name_systematic, attr_string_house_number, attr_string_label, attr_string_label_alt, attr_string_postal, attr_string_population, attr_string_county_name, attr_string_colour_, attr_string_last, |
90 | attr_string_email, |
|
|
91 | attr_string_url, |
|
|
92 | attr_string_street_name, |
|
|
93 | attr_string_street_name_systematic, |
|
|
94 | attr_string_house_number, |
|
|
95 | attr_string_label, |
|
|
96 | attr_string_postal, |
|
|
97 | attr_string_population, |
|
|
98 | attr_string_county_name, |
|
|
99 | attr_string_last, |
|
|
100 | }; |
207 | }; |
101 | |
208 | |
102 | char *attr_strings[attr_string_last]; |
209 | char *attr_strings[attr_string_last]; |
103 | |
210 | |
104 | char *osm_types[]={"unknown","node","way","relation"}; |
211 | char *osm_types[] = { "unknown", "node", "way", "relation" }; |
105 | |
212 | |
106 | #define IS_REF(c) ((c).x >= (1 << 30)) |
213 | int transform_from_geo_lat(double lat); |
107 | #define REF(c) ((c).y) |
214 | int transform_from_geo_lon(double lon); |
108 | #define SET_REF(c,ref) do { (c).x = 1 << 30; (c).y = ref ; } while(0) |
|
|
109 | |
215 | |
|
|
216 | // #define REF_X 1073741834 --> maptool.h // lat |
|
|
217 | // #define REF_Y 240000000 --> maptool.h // lon |
|
|
218 | #define IS_REF(c) (check_decode_nodeid(c)) // --> new method |
|
|
219 | // #define IS_REF(c) ((c).x >= (1 << 30)) // --> old method again |
|
|
220 | |
|
|
221 | // #define SET_REF(c,ref) (encode_nodeid(c, ref)) |
|
|
222 | // #define REF(c) (decode_nodeid(c)) |
|
|
223 | |
|
|
224 | void encode_nodeid(struct coord *c, osmid ref) |
|
|
225 | { |
|
|
226 | //fprintf(stderr, "ref=%lld bb=%lld 1=%lld\n", ref, (1 << 31), ((1 << 31) >> 31)); |
|
|
227 | //fprintf(stderr, "11=%lld 22=%lld\n", (ref >> 31), (1 << 30)); |
|
|
228 | //fprintf(stderr, "encode_nodeid:ref=%lld\n", ref); |
|
|
229 | |
|
|
230 | if (ref > 0xffffffff) |
|
|
231 | { |
|
|
232 | c->x = (1 << 30) | (ref >> 32 ); |
|
|
233 | c->y = ref & (0xffffffff); |
|
|
234 | } |
|
|
235 | else |
|
|
236 | { |
|
|
237 | c->x = 1 << 30; |
|
|
238 | c->y = ref; |
|
|
239 | } |
|
|
240 | |
|
|
241 | #if 0 |
|
|
242 | // lat = y |
|
|
243 | int x = transform_from_geo_lat(-90); |
|
|
244 | fprintf(stderr, "y=%d %x\n", x, x); |
|
|
245 | x = transform_from_geo_lat(0); |
|
|
246 | fprintf(stderr, "y=%d %x\n", x, x); |
|
|
247 | x = transform_from_geo_lat(90); |
|
|
248 | fprintf(stderr, "y=%d %x\n", x, x); |
|
|
249 | |
|
|
250 | // lon = x |
|
|
251 | int y = transform_from_geo_lon(-180); |
|
|
252 | fprintf(stderr, "x=%d %x\n", y, y); |
|
|
253 | y = transform_from_geo_lon(0); |
|
|
254 | fprintf(stderr, "x=%d %x\n", y, y); |
|
|
255 | y = transform_from_geo_lon(180); |
|
|
256 | fprintf(stderr, "x=%d %x\n", y, y); |
|
|
257 | #endif |
|
|
258 | |
|
|
259 | //fprintf(stderr, "encode_nodeid:cx=%x cy=%x 30th bit=%x ref=%x\n", c->x, c->y, (1 << 30), (ref >> 32) ); |
|
|
260 | } |
|
|
261 | |
|
|
262 | int check_decode_nodeid(struct coord c) |
|
|
263 | { |
|
|
264 | // fprintf(stderr, "check_decode_nodeid:is ref=%d\n", ((c.x & (1 << 30)) == (1 << 30)) ); |
|
|
265 | // fprintf(stderr, "check_decode_nodeid:c.x=%d c.y=%d\n", c.x, c.y); |
|
|
266 | |
|
|
267 | // if ((c.x == REF_X) && (c.y == REF_Y)) |
|
|
268 | if (c.x == REF_X) |
|
|
269 | { |
|
|
270 | // this number is not a real coordiante, its just a dummy to know we need to lookup |
|
|
271 | return 1; |
|
|
272 | } |
|
|
273 | else |
|
|
274 | { |
|
|
275 | // this is is real GPS coordinate |
|
|
276 | // fprintf(stderr, "check_decode_nodeid:c.x=%d c.y=%d\n", c.x, c.y); |
|
|
277 | return 0; |
|
|
278 | } |
|
|
279 | |
|
|
280 | //return ((c.x & (1 << 30)) == (1 << 30)); |
|
|
281 | } |
|
|
282 | |
|
|
283 | osmid decode_nodeid(struct coord c) |
|
|
284 | { |
|
|
285 | osmid ret; |
|
|
286 | |
|
|
287 | //fprintf(stderr, "decode_nodeid:x=%x y=%x val=%x\n", c.x, c.y, ((long long)(c.x ^ 0x40000000)*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2)); |
|
|
288 | if ( (c.x & (1 << 30)) == (1 << 30) ) |
|
|
289 | { |
|
|
290 | ret = c.y; |
|
|
291 | //fprintf(stderr, "decode_nodeid:1=%x\n", ret); |
|
|
292 | ret = ret | ((long long)(c.x ^ 0x40000000)*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2); |
|
|
293 | } |
|
|
294 | else |
|
|
295 | { |
|
|
296 | ret = (osmid)c.y; |
|
|
297 | } |
|
|
298 | //fprintf(stderr, "decode_nodeid:ret=%lld\n", ret); |
|
|
299 | |
|
|
300 | return ret; |
|
|
301 | } |
|
|
302 | |
|
|
303 | |
|
|
304 | |
|
|
305 | |
110 | struct country_table { |
306 | struct country_table |
|
|
307 | { |
111 | int countryid; |
308 | int countryid; |
112 | char *names; |
309 | char *names; |
113 | char *admin_levels; |
310 | char *admin_levels; |
114 | FILE *file; |
311 | FILE *file; |
115 | int size; |
312 | int size; |
116 | struct rect r; |
313 | struct rect r; |
|
|
314 | } |
117 | } country_table[] = { |
315 | country_table[] = |
118 | { 4,"Afghanistan"}, |
316 | { { 4, "Afghanistan" }, { 8, "Albania" }, { 10, "Antarctica" }, { 12, "Algeria" }, { 16, "American Samoa" }, { 20, "Andorra" }, { 24, "Angola" }, { 28, "Antigua and Barbuda" }, { 31, "Azerbaijan" }, { 32, "Argentina,República Argentina,AR " }, { 36, "Australia,AUS" }, { 40, "Austria,Österreich,AUT" }, { 44, "Bahamas" }, { 48, "Bahrain" }, { 50, "Bangladesh" }, { 51, "Armenia" }, { 52, "Barbados" }, { 56, "Belgium,Belgique,Belgie,België,Belgien" }, { 60, "Bermuda" }, { 64, "Bhutan" }, { 68, "Bolivia, Plurinational State of" }, { 70, "Bosnia and Herzegovina,Bosna i Hercegovina,Босна и Херцеговина" }, { 72, "Botswana" }, { 74, "Bouvet Island" }, { 76, "Brazil" }, { 84, "Belize" }, { 86, "British Indian Ocean Territory" }, { 90, "Solomon Islands" }, { 92, "Virgin Islands, British" }, { 96, "Brunei Darussalam" }, { 100, "Bulgaria,България" }, { 104, "Myanmar" }, { 108, "Burundi" }, { 112, "Belarus" }, { 116, "Cambodia" }, { 120, "Cameroon" }, { 124, "Canada" }, { 132, "Cape Verde" }, { 136, "Cayman Islands" }, { 140, "Central African Republic" }, { 144, "Sri Lanka" }, { 148, "Chad" }, { 152, "Chile" }, { 156, "China" }, { 158, "Taiwan, Province of China" }, { 162, "Christmas Island" }, { 166, "Cocos (Keeling) Islands" }, { 170, "Colombia" }, { 174, "Comoros" }, { 175, "Mayotte" }, { 178, "Congo" }, { 180, "Congo, the Democratic Republic of the" }, { 184, "Cook Islands" }, { 188, "Costa Rica" }, { 191, "Croatia,Republika Hrvatska,HR" }, { 192, "Cuba" }, { 196, "Cyprus" }, { 203, "Czech Republic,Česká republika,CZ" }, { 204, "Benin" }, { 208, "Denmark,Danmark,DK" }, { 212, "Dominica" }, { 214, "Dominican Republic" }, { 218, "Ecuador" }, { 222, "El Salvador" }, { 226, "Equatorial Guinea" }, { 231, "Ethiopia" }, { 232, "Eritrea" }, { 233, "Estonia" }, { 234, "Faroe Islands,Føroyar" }, { 238, "Falkland Islands (Malvinas)" }, { 239, "South Georgia and the South Sandwich Islands" }, { 242, "Fiji" }, { 246, "Finland,Suomi" }, { 248, "Åland Islands" }, { 250, "France,République française,FR" }, { 254, "French Guiana" }, { 258, "French Polynesia" }, { 260, "French Southern Territories" }, { 262, "Djibouti" }, { 266, "Gabon" }, { 268, "Georgia" }, { 270, "Gambia" }, { 275, "Palestinian Territory, Occupied" }, { 276, "Germany,Deutschland,Bundesrepublik Deutschland", "345c7m" }, { 288, "Ghana" }, { 292, "Gibraltar" }, { 296, "Kiribati" }, { 300, "Greece" }, { 304, "Greenland" }, { 308, "Grenada" }, { 312, "Guadeloupe" }, { 316, "Guam" }, { 320, "Guatemala" }, { 324, "Guinea" }, { 328, "Guyana" }, { 332, "Haiti" }, { 334, "Heard Island and McDonald Islands" }, { 336, "Holy See (Vatican City State)" }, { 340, "Honduras" }, { 344, "Hong Kong" }, { 348, "Hungary,Magyarország" }, { 352, "Iceland" }, { 356, "India" }, { 360, "Indonesia" }, { 364, "Iran, Islamic Republic of" }, { 368, "Iraq" }, { 372, "Ireland" }, { 376, "Israel" }, { 380, "Italy,Italia" }, { 384, "Côte d'Ivoire" }, { 388, "Jamaica" }, { 392, "Japan" }, { 398, "Kazakhstan" }, { 400, "Jordan" }, { 404, "Kenya" }, { 408, "Korea, Democratic People's Republic of" }, { 410, "Korea, Republic of" }, { 414, "Kuwait" }, { 417, "Kyrgyzstan" }, { 418, "Lao People's Democratic Republic" }, { 422, "Lebanon" }, { 426, "Lesotho" }, { 428, "Latvia" }, { 430, "Liberia" }, { 434, "Libyan Arab Jamahiriya" }, { 438, "Liechtenstein" }, { 440, "Lithuania,Lietuva" }, { 442, "Luxembourg" }, { 446, "Macao" }, { 450, "Madagascar" }, { 454, "Malawi" }, { 458, "Malaysia" }, { 462, "Maldives" }, { 466, "Mali" }, { 470, "Malta" }, { 474, "Martinique" }, { 478, "Mauritania" }, { 480, "Mauritius" }, { 484, "Mexico" }, { 492, "Monaco" }, { 496, "Mongolia" }, { 498, "Moldova, Republic of" }, { 499, "Montenegro,Црна Гора,Crna Gora" }, { 500, "Montserrat" }, { 504, "Morocco" }, { 508, "Mozambique" }, { 512, "Oman" }, { 516, "Namibia" }, { 520, "Nauru" }, { 524, "Nepal" }, { 528, "Nederland,The Netherlands,Niederlande,NL,Netherlands" }, { 530, "Netherlands Antilles" }, { 533, "Aruba" }, { 540, "New Caledonia" }, { 548, "Vanuatu" }, { 554, "New Zealand" }, { 558, "Nicaragua" }, { 562, "Niger" }, { 566, "Nigeria" }, { 570, "Niue" }, { 574, "Norfolk Island" }, { 578, "Norway,Norge,Noreg,NO" }, { 580, "Northern Mariana Islands" }, { 581, "United States Minor Outlying Islands" }, { 583, "Micronesia, Federated States of" }, { 584, "Marshall Islands" }, { 585, "Palau" }, { 586, "Pakistan" }, { 591, "Panama" }, { 598, "Papua New Guinea" }, { 600, "Paraguay" }, { 604, "Peru" }, { 608, "Philippines" }, { 612, "Pitcairn" }, { 616, "Poland,Polska,PL" }, { 620, "Portugal" }, { 624, "Guinea-Bissau" }, { 626, "Timor-Leste" }, { 630, "Puerto Rico" }, { 634, "Qatar" }, { 638, "Réunion" }, { 642, "România,Romania,RO" }, { 643, "Россия,Российская Федерация,Russia,Russian Federation" }, { 646, "Rwanda" }, { 652, "Saint Barthélemy" }, { 654, "Saint Helena, Ascension and Tristan da Cunha" }, { 659, "Saint Kitts and Nevis" }, { 660, "Anguilla" }, { 662, "Saint Lucia" }, { 663, "Saint Martin (French part)" }, { 666, "Saint Pierre and Miquelon" }, { 670, "Saint Vincent and the Grenadines" }, { 674, "San Marino" }, { 678, "Sao Tome and Principe" }, { 682, "Saudi Arabia" }, { 686, "Senegal" }, { 688, "Srbija,Србија,Serbia" }, { 690, "Seychelles" }, { 694, "Sierra Leone" }, { 702, "Singapore" }, { 703, "Slovakia,Slovensko,SK" }, { 704, "Viet Nam" }, { 705, "Slovenia,Republika Slovenija,SI" }, { 706, "Somalia" }, { 710, "South Africa" }, { 716, "Zimbabwe" }, { 724, "Spain,Espana,España,Reino de Espana,Reino de España" }, { 732, "Western Sahara" }, { 736, "Sudan" }, { 740, "Suriname" }, { 744, "Svalbard and Jan Mayen" }, { 748, "Swaziland" }, { 752, "Sweden,Sverige,Konungariket Sverige,SE" }, { 756, "Switzerland,Schweiz" }, { 760, "Syrian Arab Republic" }, { 762, "Tajikistan" }, { 764, "Thailand" }, { 768, "Togo" }, { 772, "Tokelau" }, { 776, "Tonga" }, { 780, "Trinidad and Tobago" }, { 784, "United Arab Emirates" }, { 788, "Tunisia" }, { 792, "Turkey" }, { 795, "Turkmenistan" }, { 796, "Turks and Caicos Islands" }, { 798, "Tuvalu" }, { 800, "Uganda" }, { 804, "Ukraine" }, { 807, "Macedonia,Македонија" }, { 818, "Egypt" }, { 826, "United Kingdom,UK" }, { 831, "Guernsey" }, { 832, "Jersey" }, { 833, "Isle of Man" }, { 834, "Tanzania, United Republic of" }, { 840, "USA" }, { 850, "Virgin Islands, U.S." }, { 854, "Burkina Faso" }, { 858, "Uruguay" }, { 860, "Uzbekistan" }, { 862, "Venezuela, Bolivarian Republic of" }, { 876, "Wallis and Futuna" }, { 882, "Samoa" }, { 887, "Yemen" }, { 894, "Zambia" }, { 999, "Unknown" }, }; |
119 | { 8,"Albania"}, |
|
|
120 | { 10,"Antarctica"}, |
|
|
121 | { 12,"Algeria"}, |
|
|
122 | { 16,"American Samoa"}, |
|
|
123 | { 20,"Andorra"}, |
|
|
124 | { 24,"Angola"}, |
|
|
125 | { 28,"Antigua and Barbuda"}, |
|
|
126 | { 31,"Azerbaijan"}, |
|
|
127 | { 32,"Argentina,República Argentina,AR "}, |
|
|
128 | { 36,"Australia,AUS"}, |
|
|
129 | { 40,"Austria,Österreich,AUT"}, |
|
|
130 | { 44,"Bahamas"}, |
|
|
131 | { 48,"Bahrain"}, |
|
|
132 | { 50,"Bangladesh"}, |
|
|
133 | { 51,"Armenia"}, |
|
|
134 | { 52,"Barbados"}, |
|
|
135 | { 56,"Belgium,Belgique,Belgie,België,Belgien"}, |
|
|
136 | { 60,"Bermuda"}, |
|
|
137 | { 64,"Bhutan"}, |
|
|
138 | { 68,"Bolivia, Plurinational State of"}, |
|
|
139 | { 70,"Bosnia and Herzegovina,Bosna i Hercegovina,Босна и Херцеговина"}, |
|
|
140 | { 72,"Botswana"}, |
|
|
141 | { 74,"Bouvet Island"}, |
|
|
142 | { 76,"Brazil"}, |
|
|
143 | { 84,"Belize"}, |
|
|
144 | { 86,"British Indian Ocean Territory"}, |
|
|
145 | { 90,"Solomon Islands"}, |
|
|
146 | { 92,"Virgin Islands, British"}, |
|
|
147 | { 96,"Brunei Darussalam"}, |
|
|
148 | { 100,"Bulgaria,България"}, |
|
|
149 | { 104,"Myanmar"}, |
|
|
150 | { 108,"Burundi"}, |
|
|
151 | { 112,"Belarus"}, |
|
|
152 | { 116,"Cambodia"}, |
|
|
153 | { 120,"Cameroon"}, |
|
|
154 | { 124,"Canada"}, |
|
|
155 | { 132,"Cape Verde"}, |
|
|
156 | { 136,"Cayman Islands"}, |
|
|
157 | { 140,"Central African Republic"}, |
|
|
158 | { 144,"Sri Lanka"}, |
|
|
159 | { 148,"Chad"}, |
|
|
160 | { 152,"Chile"}, |
|
|
161 | { 156,"China"}, |
|
|
162 | { 158,"Taiwan, Province of China"}, |
|
|
163 | { 162,"Christmas Island"}, |
|
|
164 | { 166,"Cocos (Keeling) Islands"}, |
|
|
165 | { 170,"Colombia"}, |
|
|
166 | { 174,"Comoros"}, |
|
|
167 | { 175,"Mayotte"}, |
|
|
168 | { 178,"Congo"}, |
|
|
169 | { 180,"Congo, the Democratic Republic of the"}, |
|
|
170 | { 184,"Cook Islands"}, |
|
|
171 | { 188,"Costa Rica"}, |
|
|
172 | { 191,"Croatia,Republika Hrvatska,HR"}, |
|
|
173 | { 192,"Cuba"}, |
|
|
174 | { 196,"Cyprus"}, |
|
|
175 | { 203,"Czech Republic,Česká republika,CZ"}, |
|
|
176 | { 204,"Benin"}, |
|
|
177 | { 208,"Denmark,Danmark,DK"}, |
|
|
178 | { 212,"Dominica"}, |
|
|
179 | { 214,"Dominican Republic"}, |
|
|
180 | { 218,"Ecuador"}, |
|
|
181 | { 222,"El Salvador"}, |
|
|
182 | { 226,"Equatorial Guinea"}, |
|
|
183 | { 231,"Ethiopia"}, |
|
|
184 | { 232,"Eritrea"}, |
|
|
185 | { 233,"Estonia"}, |
|
|
186 | { 234,"Faroe Islands,Føroyar"}, |
|
|
187 | { 238,"Falkland Islands (Malvinas)"}, |
|
|
188 | { 239,"South Georgia and the South Sandwich Islands"}, |
|
|
189 | { 242,"Fiji"}, |
|
|
190 | { 246,"Finland,Suomi"}, |
|
|
191 | { 248,"Åland Islands"}, |
|
|
192 | { 250,"France,République française,FR"}, |
|
|
193 | { 254,"French Guiana"}, |
|
|
194 | { 258,"French Polynesia"}, |
|
|
195 | { 260,"French Southern Territories"}, |
|
|
196 | { 262,"Djibouti"}, |
|
|
197 | { 266,"Gabon"}, |
|
|
198 | { 268,"Georgia"}, |
|
|
199 | { 270,"Gambia"}, |
|
|
200 | { 275,"Palestinian Territory, Occupied"}, |
|
|
201 | { 276,"Germany,Deutschland,Bundesrepublik Deutschland","345c7m"}, |
|
|
202 | { 288,"Ghana"}, |
|
|
203 | { 292,"Gibraltar"}, |
|
|
204 | { 296,"Kiribati"}, |
|
|
205 | { 300,"Greece"}, |
|
|
206 | { 304,"Greenland"}, |
|
|
207 | { 308,"Grenada"}, |
|
|
208 | { 312,"Guadeloupe"}, |
|
|
209 | { 316,"Guam"}, |
|
|
210 | { 320,"Guatemala"}, |
|
|
211 | { 324,"Guinea"}, |
|
|
212 | { 328,"Guyana"}, |
|
|
213 | { 332,"Haiti"}, |
|
|
214 | { 334,"Heard Island and McDonald Islands"}, |
|
|
215 | { 336,"Holy See (Vatican City State)"}, |
|
|
216 | { 340,"Honduras"}, |
|
|
217 | { 344,"Hong Kong"}, |
|
|
218 | { 348,"Hungary,Magyarország"}, |
|
|
219 | { 352,"Iceland"}, |
|
|
220 | { 356,"India"}, |
|
|
221 | { 360,"Indonesia"}, |
|
|
222 | { 364,"Iran, Islamic Republic of"}, |
|
|
223 | { 368,"Iraq"}, |
|
|
224 | { 372,"Ireland"}, |
|
|
225 | { 376,"Israel"}, |
|
|
226 | { 380,"Italy,Italia"}, |
|
|
227 | { 384,"Côte d'Ivoire"}, |
|
|
228 | { 388,"Jamaica"}, |
|
|
229 | { 392,"Japan"}, |
|
|
230 | { 398,"Kazakhstan"}, |
|
|
231 | { 400,"Jordan"}, |
|
|
232 | { 404,"Kenya"}, |
|
|
233 | { 408,"Korea, Democratic People's Republic of"}, |
|
|
234 | { 410,"Korea, Republic of"}, |
|
|
235 | { 414,"Kuwait"}, |
|
|
236 | { 417,"Kyrgyzstan"}, |
|
|
237 | { 418,"Lao People's Democratic Republic"}, |
|
|
238 | { 422,"Lebanon"}, |
|
|
239 | { 426,"Lesotho"}, |
|
|
240 | { 428,"Latvia"}, |
|
|
241 | { 430,"Liberia"}, |
|
|
242 | { 434,"Libyan Arab Jamahiriya"}, |
|
|
243 | { 438,"Liechtenstein"}, |
|
|
244 | { 440,"Lithuania,Lietuva"}, |
|
|
245 | { 442,"Luxembourg"}, |
|
|
246 | { 446,"Macao"}, |
|
|
247 | { 450,"Madagascar"}, |
|
|
248 | { 454,"Malawi"}, |
|
|
249 | { 458,"Malaysia"}, |
|
|
250 | { 462,"Maldives"}, |
|
|
251 | { 466,"Mali"}, |
|
|
252 | { 470,"Malta"}, |
|
|
253 | { 474,"Martinique"}, |
|
|
254 | { 478,"Mauritania"}, |
|
|
255 | { 480,"Mauritius"}, |
|
|
256 | { 484,"Mexico"}, |
|
|
257 | { 492,"Monaco"}, |
|
|
258 | { 496,"Mongolia"}, |
|
|
259 | { 498,"Moldova, Republic of"}, |
|
|
260 | { 499,"Montenegro,Црна Гора,Crna Gora"}, |
|
|
261 | { 500,"Montserrat"}, |
|
|
262 | { 504,"Morocco"}, |
|
|
263 | { 508,"Mozambique"}, |
|
|
264 | { 512,"Oman"}, |
|
|
265 | { 516,"Namibia"}, |
|
|
266 | { 520,"Nauru"}, |
|
|
267 | { 524,"Nepal"}, |
|
|
268 | { 528,"Nederland,The Netherlands,Niederlande,NL,Netherlands"}, |
|
|
269 | { 530,"Netherlands Antilles"}, |
|
|
270 | { 533,"Aruba"}, |
|
|
271 | { 540,"New Caledonia"}, |
|
|
272 | { 548,"Vanuatu"}, |
|
|
273 | { 554,"New Zealand"}, |
|
|
274 | { 558,"Nicaragua"}, |
|
|
275 | { 562,"Niger"}, |
|
|
276 | { 566,"Nigeria"}, |
|
|
277 | { 570,"Niue"}, |
|
|
278 | { 574,"Norfolk Island"}, |
|
|
279 | { 578,"Norway,Norge,Noreg,NO"}, |
|
|
280 | { 580,"Northern Mariana Islands"}, |
|
|
281 | { 581,"United States Minor Outlying Islands"}, |
|
|
282 | { 583,"Micronesia, Federated States of"}, |
|
|
283 | { 584,"Marshall Islands"}, |
|
|
284 | { 585,"Palau"}, |
|
|
285 | { 586,"Pakistan"}, |
|
|
286 | { 591,"Panama"}, |
|
|
287 | { 598,"Papua New Guinea"}, |
|
|
288 | { 600,"Paraguay"}, |
|
|
289 | { 604,"Peru"}, |
|
|
290 | { 608,"Philippines"}, |
|
|
291 | { 612,"Pitcairn"}, |
|
|
292 | { 616,"Poland,Polska,PL"}, |
|
|
293 | { 620,"Portugal"}, |
|
|
294 | { 624,"Guinea-Bissau"}, |
|
|
295 | { 626,"Timor-Leste"}, |
|
|
296 | { 630,"Puerto Rico"}, |
|
|
297 | { 634,"Qatar"}, |
|
|
298 | { 638,"Réunion"}, |
|
|
299 | { 642,"România,Romania,RO"}, |
|
|
300 | { 643,"Россия,Российская Федерация,Russia,Russian Federation"}, |
|
|
301 | { 646,"Rwanda"}, |
|
|
302 | { 652,"Saint Barthélemy"}, |
|
|
303 | { 654,"Saint Helena, Ascension and Tristan da Cunha"}, |
|
|
304 | { 659,"Saint Kitts and Nevis"}, |
|
|
305 | { 660,"Anguilla"}, |
|
|
306 | { 662,"Saint Lucia"}, |
|
|
307 | { 663,"Saint Martin (French part)"}, |
|
|
308 | { 666,"Saint Pierre and Miquelon"}, |
|
|
309 | { 670,"Saint Vincent and the Grenadines"}, |
|
|
310 | { 674,"San Marino"}, |
|
|
311 | { 678,"Sao Tome and Principe"}, |
|
|
312 | { 682,"Saudi Arabia"}, |
|
|
313 | { 686,"Senegal"}, |
|
|
314 | { 688,"Srbija,Србија,Serbia"}, |
|
|
315 | { 690,"Seychelles"}, |
|
|
316 | { 694,"Sierra Leone"}, |
|
|
317 | { 702,"Singapore"}, |
|
|
318 | { 703,"Slovakia,Slovensko,SK"}, |
|
|
319 | { 704,"Viet Nam"}, |
|
|
320 | { 705,"Slovenia,Republika Slovenija,SI"}, |
|
|
321 | { 706,"Somalia"}, |
|
|
322 | { 710,"South Africa"}, |
|
|
323 | { 716,"Zimbabwe"}, |
|
|
324 | { 724,"Spain,Espana,España,Reino de Espana,Reino de España"}, |
|
|
325 | { 732,"Western Sahara"}, |
|
|
326 | { 736,"Sudan"}, |
|
|
327 | { 740,"Suriname"}, |
|
|
328 | { 744,"Svalbard and Jan Mayen"}, |
|
|
329 | { 748,"Swaziland"}, |
|
|
330 | { 752,"Sweden,Sverige,Konungariket Sverige,SE"}, |
|
|
331 | { 756,"Switzerland,Schweiz"}, |
|
|
332 | { 760,"Syrian Arab Republic"}, |
|
|
333 | { 762,"Tajikistan"}, |
|
|
334 | { 764,"Thailand"}, |
|
|
335 | { 768,"Togo"}, |
|
|
336 | { 772,"Tokelau"}, |
|
|
337 | { 776,"Tonga"}, |
|
|
338 | { 780,"Trinidad and Tobago"}, |
|
|
339 | { 784,"United Arab Emirates"}, |
|
|
340 | { 788,"Tunisia"}, |
|
|
341 | { 792,"Turkey"}, |
|
|
342 | { 795,"Turkmenistan"}, |
|
|
343 | { 796,"Turks and Caicos Islands"}, |
|
|
344 | { 798,"Tuvalu"}, |
|
|
345 | { 800,"Uganda"}, |
|
|
346 | { 804,"Ukraine"}, |
|
|
347 | { 807,"Macedonia,Македонија"}, |
|
|
348 | { 818,"Egypt"}, |
|
|
349 | { 826,"United Kingdom,UK"}, |
|
|
350 | { 831,"Guernsey"}, |
|
|
351 | { 832,"Jersey"}, |
|
|
352 | { 833,"Isle of Man"}, |
|
|
353 | { 834,"Tanzania, United Republic of"}, |
|
|
354 | { 840,"USA"}, |
|
|
355 | { 850,"Virgin Islands, U.S."}, |
|
|
356 | { 854,"Burkina Faso"}, |
|
|
357 | { 858,"Uruguay"}, |
|
|
358 | { 860,"Uzbekistan"}, |
|
|
359 | { 862,"Venezuela, Bolivarian Republic of"}, |
|
|
360 | { 876,"Wallis and Futuna"}, |
|
|
361 | { 882,"Samoa"}, |
|
|
362 | { 887,"Yemen"}, |
|
|
363 | { 894,"Zambia"}, |
|
|
364 | { 999,"Unknown"}, |
|
|
365 | }; |
|
|
366 | |
317 | |
367 | // first char - item type |
318 | // first char - item type |
368 | // =w - ways |
319 | // =w - ways |
369 | // =? - used both for nodes and ways |
320 | // =? - used both for nodes and ways |
370 | // otherwise - nodes |
321 | // otherwise - nodes |
371 | |
322 | |
372 | |
323 | |
373 | // for coastline-only map |
324 | // for coastline-only map |
374 | static char *attrmap_cl={ |
325 | static char *attrmap_cl = { "n *=* point_unkn\n" |
375 | "n *=* point_unkn\n" |
|
|
376 | "w *=* street_unkn\n" |
326 | "w *=* street_unkn\n" |
377 | "w natural=coastline water_line\n" |
327 | "w natural=coastline water_line\n" }; |
378 | }; |
|
|
379 | |
328 | |
380 | // for border-only map |
329 | // for border-only map |
381 | static char *attrmap_bo={ |
330 | static char *attrmap_bo = { "n *=* point_unkn\n" |
382 | "n *=* point_unkn\n" |
|
|
383 | "w *=* street_unkn\n" |
331 | "w *=* street_unkn\n" |
384 | "w boundary=administrative,admin_level=2 border_country\n" |
332 | "w boundary=administrative,admin_level=2 border_country\n" |
385 | "w boundary=territorial,admin_level=2 border_country\n" |
333 | "w boundary=territorial,admin_level=2 border_country\n" |
386 | "w boundary=maritime,admin_level=2 border_country\n" |
334 | "w boundary=maritime,admin_level=2 border_country\n" |
387 | "w administrative=boundary,admin_level=2 border_country\n" |
335 | "w administrative=boundary,admin_level=2 border_country\n" |
|
|
336 | "w boundary=administrative,maritime=yes,admin_level=2 border_country\n" |
388 | "w boundary=administrative,maritime=yes,admin_level=4 border_country\n" |
337 | "w boundary=administrative,maritime=yes,admin_level=4 border_country\n" |
389 | "w boundary=administrative,border_type=state,admin_level=4 border_country\n" |
338 | "w boundary=administrative,border_type=state,admin_level=4 border_country\n" }; |
390 | }; |
|
|
391 | |
339 | |
392 | // ========================== |
340 | // ========================== |
393 | // for USA |
341 | // for USA |
394 | // ========================== |
342 | // ========================== |
395 | // admin_level = 4 |
343 | // admin_level = 4 |
… | |
… | |
397 | // boundary = administrative |
345 | // boundary = administrative |
398 | // ========================== |
346 | // ========================== |
399 | |
347 | |
400 | |
348 | |
401 | // for normal map |
349 | // for normal map |
402 | static char *attrmap_normal={ |
350 | static char *attrmap_normal = { "n *=* point_unkn\n" |
403 | "n *=* point_unkn\n" |
|
|
404 | //// "n Annehmlichkeit=Hochsitz poi_hunting_stand\n" |
351 | //// "n Annehmlichkeit=Hochsitz poi_hunting_stand\n" |
405 | "n addr:housenumber=* house_number\n" |
352 | "n addr:housenumber=* house_number\n" |
406 | "n aeroway=aerodrome poi_airport\n" |
353 | "n aeroway=aerodrome poi_airport\n" |
407 | "n aeroway=airport poi_airport\n" |
354 | "n aeroway=airport poi_airport\n" |
408 | "n aeroway=helipad poi_heliport\n" |
355 | "n aeroway=helipad poi_heliport\n" |
409 | "n aeroway=terminal poi_airport\n" |
356 | "n aeroway=terminal poi_airport\n" |
410 | "n amenity=atm poi_bank\n" |
357 | "n amenity=atm poi_atm\n" |
411 | "n amenity=bank poi_bank\n" |
358 | "n amenity=bank poi_bank\n" |
412 | "n amenity=bar poi_bar\n" |
359 | "n amenity=bar poi_bar\n" |
413 | //"n amenity=bench poi_bench\n" |
360 | //"n amenity=bench poi_bench\n" |
414 | "n amenity=biergarten poi_biergarten\n" |
361 | "n amenity=biergarten poi_biergarten\n" |
415 | "n amenity=bus_station poi_bus_station\n" |
362 | "n amenity=bus_station poi_bus_station\n" |
… | |
… | |
436 | "n amenity=place_of_worship poi_worship\n" |
383 | "n amenity=place_of_worship poi_worship\n" |
437 | "n amenity=police poi_police\n" |
384 | "n amenity=police poi_police\n" |
438 | //"n amenity=post_box poi_post_box\n" |
385 | //"n amenity=post_box poi_post_box\n" |
439 | "n amenity=post_office poi_post_office\n" |
386 | "n amenity=post_office poi_post_office\n" |
440 | "n amenity=prison poi_prison\n" |
387 | "n amenity=prison poi_prison\n" |
441 | "n amenity=pub poi_pub\n" |
388 | //"n amenity=pub poi_pub\n" |
442 | "n amenity=public_building poi_public_office\n" |
389 | "n amenity=public_building poi_public_office\n" |
443 | //"n amenity=recycling poi_recycling\n" |
390 | //"n amenity=recycling poi_recycling\n" |
444 | "n amenity=restaurant,cuisine=fine_dining poi_dining\n" |
391 | "n amenity=restaurant,cuisine=fine_dining poi_dining\n" |
445 | "n amenity=restaurant poi_restaurant\n" |
392 | "n amenity=restaurant poi_restaurant\n" |
446 | "n amenity=school poi_school\n" |
393 | "n amenity=school poi_school\n" |
… | |
… | |
454 | "n amenity=university poi_school_university\n" |
401 | "n amenity=university poi_school_university\n" |
455 | //"n amenity=vending_machine poi_vending_machine\n" |
402 | //"n amenity=vending_machine poi_vending_machine\n" |
456 | "n barrier=bollard barrier_bollard\n" |
403 | "n barrier=bollard barrier_bollard\n" |
457 | "n barrier=cycle_barrier barrier_cycle\n" |
404 | "n barrier=cycle_barrier barrier_cycle\n" |
458 | "n barrier=lift_gate barrier_lift_gate\n" |
405 | "n barrier=lift_gate barrier_lift_gate\n" |
459 | //"n car=car_rental poi_car_rent\n" |
406 | "n car=car_rental poi_car_rent\n" |
460 | "n highway=bus_station poi_bus_station\n" |
407 | "n highway=bus_station poi_bus_station\n" |
461 | "n highway=bus_stop poi_bus_stop\n" |
408 | "n highway=bus_stop poi_bus_stop\n" |
462 | "n highway=mini_roundabout mini_roundabout\n" |
409 | "n highway=mini_roundabout mini_roundabout\n" |
463 | "n highway=motorway_junction highway_exit\n" |
410 | "n highway=motorway_junction highway_exit\n" |
464 | "n highway=stop traffic_sign_stop\n" |
411 | "n highway=stop traffic_sign_stop\n" |
… | |
… | |
468 | //"n historic=boundary_stone poi_boundary_stone\n" |
415 | //"n historic=boundary_stone poi_boundary_stone\n" |
469 | "n historic=castle poi_castle\n" |
416 | "n historic=castle poi_castle\n" |
470 | "n historic=memorial poi_memorial\n" |
417 | "n historic=memorial poi_memorial\n" |
471 | "n historic=monument poi_monument\n" |
418 | "n historic=monument poi_monument\n" |
472 | "n historic=ruins poi_ruins\n" |
419 | "n historic=ruins poi_ruins\n" |
473 | //// "n historic=* poi_ruins\n" |
420 | //// "n historic=* poi_ruins\n" |
474 | "n landuse=cemetery poi_cemetery\n" |
421 | "n landuse=cemetery poi_cemetery\n" |
475 | //"n leisure=fishing poi_fish\n" |
422 | //"n leisure=fishing poi_fish\n" |
476 | "n leisure=golf_course poi_golf\n" |
423 | "n leisure=golf_course poi_golf\n" |
477 | "n leisure=marina poi_marine\n" |
424 | "n leisure=marina poi_marine\n" |
478 | //"n leisure=playground poi_playground\n" |
425 | //"n leisure=playground poi_playground\n" |
479 | //"n leisure=slipway poi_boat_ramp\n" |
426 | //"n leisure=slipway poi_boat_ramp\n" |
480 | //"n leisure=sports_centre poi_sport\n" |
427 | "n leisure=sports_centre poi_sport\n" |
481 | "n leisure=stadium poi_stadium\n" |
428 | "n leisure=stadium poi_stadium\n" |
482 | //"n man_made=tower poi_tower\n" |
429 | //"n man_made=tower poi_tower\n" |
483 | "n military=airfield poi_military\n" |
430 | "n military=airfield poi_military\n" |
484 | //"n military=barracks poi_military\n" |
431 | "n military=barracks poi_military\n" |
485 | //"n military=bunker poi_military\n" |
432 | "n military=bunker poi_military\n" |
486 | "n military=danger_area poi_danger_area\n" |
433 | "n military=danger_area poi_danger_area\n" |
487 | "n military=range poi_military\n" |
434 | "n military=range poi_military\n" |
488 | "n natural=bay poi_bay\n" |
435 | "n natural=bay poi_bay\n" |
489 | "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation |
436 | "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation |
490 | //"n natural=tree poi_tree\n" |
437 | //"n natural=tree poi_tree\n" |
491 | "n place=city town_label_2e5\n" |
438 | "n place=city town_label_2e5\n" |
492 | "n place=hamlet town_label_2e2\n" |
439 | "n place=hamlet town_label_2e2\n" |
493 | "n place=locality town_label_2e0\n" |
440 | "n place=locality town_label_2e0\n" |
494 | "n place=suburb district_label\n" |
441 | "n place=suburb district_label\n" |
… | |
… | |
498 | //"n power=sub_station power_substation\n" |
445 | //"n power=sub_station power_substation\n" |
499 | "n railway=halt poi_rail_halt\n" |
446 | "n railway=halt poi_rail_halt\n" |
500 | "n railway=level_crossing poi_level_crossing\n" |
447 | "n railway=level_crossing poi_level_crossing\n" |
501 | "n railway=station poi_rail_station\n" |
448 | "n railway=station poi_rail_station\n" |
502 | "n railway=tram_stop poi_rail_tram_stop\n" |
449 | "n railway=tram_stop poi_rail_tram_stop\n" |
503 | //"n shop=baker poi_shop_baker\n" |
450 | "n shop=baker poi_shop_baker\n" |
504 | //"n shop=bakery poi_shop_baker\n" |
451 | "n shop=bakery poi_shop_baker\n" |
505 | //"n shop=beverages poi_shop_beverages\n" |
452 | "n shop=beverages poi_shop_beverages\n" |
506 | //"n shop=bicycle poi_shop_bicycle\n" |
453 | "n shop=bicycle poi_shop_bicycle\n" |
507 | //"n shop=butcher poi_shop_butcher\n" |
454 | "n shop=butcher poi_shop_butcher\n" |
508 | "n shop=car poi_car_dealer_parts\n" |
455 | "n shop=car poi_car_dealer_parts\n" |
509 | "n shop=car_repair poi_repair_service\n" |
456 | "n shop=car_repair poi_repair_service\n" |
510 | //"n shop=clothes poi_shop_apparel\n" |
457 | //"n shop=clothes poi_shop_apparel\n" |
511 | //"n shop=convenience poi_shop_grocery\n" |
458 | //"n shop=convenience poi_shop_grocery\n" |
512 | //"n shop=drogist poi_shop_drugstore\n" |
459 | //"n shop=drogist poi_shop_drugstore\n" |
513 | //"n shop=florist poi_shop_florist\n" |
460 | //"n shop=florist poi_shop_florist\n" |
514 | //"n shop=fruit poi_shop_fruit\n" |
461 | //"n shop=fruit poi_shop_fruit\n" |
515 | //"n shop=furniture poi_shop_furniture\n" |
462 | //"n shop=furniture poi_shop_furniture\n" |
516 | //"n shop=garden_centre poi_shop_handg\n" |
463 | //"n shop=garden_centre poi_shop_handg\n" |
517 | //"n shop=hardware poi_shop_handg\n" |
464 | //"n shop=hardware poi_shop_handg\n" |
518 | //"n shop=hairdresser poi_hairdresser\n" |
465 | "n shop=hairdresser poi_hairdresser\n" |
519 | //"n shop=kiosk poi_shop_kiosk\n" |
466 | //"n shop=kiosk poi_shop_kiosk\n" |
520 | //"n shop=optician poi_shop_optician\n" |
467 | //"n shop=optician poi_shop_optician\n" |
521 | //"n shop=parfum poi_shop_parfum\n" |
468 | //"n shop=parfum poi_shop_parfum\n" |
522 | //"n shop=photo poi_shop_photo\n" |
469 | //"n shop=photo poi_shop_photo\n" |
523 | //"n shop=shoes poi_shop_shoes\n" |
470 | "n shop=shoes poi_shop_shoes\n" |
524 | "n shop=supermarket poi_shopping\n" |
471 | "n shop=supermarket poi_shopping\n" |
525 | //"n sport=10pin poi_bowling\n" |
472 | //"n sport=10pin poi_bowling\n" |
526 | //"n sport=baseball poi_baseball\n" |
473 | //"n sport=baseball poi_baseball\n" |
527 | //"n sport=basketball poi_basketball\n" |
474 | //"n sport=basketball poi_basketball\n" |
528 | //"n sport=climbing poi_climbing\n" |
475 | //"n sport=climbing poi_climbing\n" |
529 | //"n sport=golf poi_golf\n" |
476 | "n sport=golf poi_golf\n" |
530 | //"n sport=motor_sports poi_motor_sport\n" |
477 | //"n sport=motor_sports poi_motor_sport\n" |
531 | //"n sport=skiing poi_skiing\n" |
478 | //"n sport=skiing poi_skiing\n" |
532 | //"n sport=soccer poi_soccer\n" |
479 | "n sport=soccer poi_soccer\n" |
533 | "n sport=stadium poi_stadium\n" |
480 | "n sport=stadium poi_stadium\n" |
534 | "n sport=swimming poi_swimming\n" |
481 | "n sport=swimming poi_swimming\n" |
535 | //"n sport=tennis poi_tennis\n" |
482 | "n sport=tennis poi_tennis\n" |
536 | "n tourism=attraction poi_attraction\n" |
483 | "n tourism=attraction poi_attraction\n" |
537 | "n tourism=camp_site poi_camp_rv\n" |
484 | "n tourism=camp_site poi_camp_rv\n" |
538 | "n tourism=caravan_site poi_camp_rv\n" |
485 | "n tourism=caravan_site poi_camp_rv\n" |
539 | "n tourism=guest_house poi_guesthouse\n" |
486 | "n tourism=guest_house poi_guesthouse\n" |
540 | "n tourism=hostel poi_hostel\n" |
487 | "n tourism=hostel poi_hostel\n" |
… | |
… | |
542 | "n tourism=information poi_information\n" |
489 | "n tourism=information poi_information\n" |
543 | "n tourism=motel poi_motel\n" |
490 | "n tourism=motel poi_motel\n" |
544 | "n tourism=museum poi_museum_history\n" |
491 | "n tourism=museum poi_museum_history\n" |
545 | //"n tourism=picnic_site poi_picnic\n" |
492 | //"n tourism=picnic_site poi_picnic\n" |
546 | "n tourism=theme_park poi_resort\n" |
493 | "n tourism=theme_park poi_resort\n" |
547 | //"n tourism=viewpoint poi_viewpoint\n" |
494 | "n tourism=viewpoint poi_viewpoint\n" |
548 | "n tourism=zoo poi_zoo\n" |
495 | "n tourism=zoo poi_zoo\n" |
549 | "n traffic_sign=city_limit traffic_sign_city_limit\n" |
496 | "n traffic_sign=city_limit traffic_sign_city_limit\n" |
550 | "n highway=speed_camera tec_common\n" |
497 | "n highway=speed_camera tec_common\n" |
551 | "w *=* street_unkn\n" |
498 | "w *=* street_unkn\n" |
552 | "w addr:interpolation=even house_number_interpolation_even\n" |
499 | "w addr:interpolation=even house_number_interpolation_even\n" |
… | |
… | |
691 | //"w leisure=sports_centre poly_sport\n" |
638 | //"w leisure=sports_centre poly_sport\n" |
692 | "w leisure=stadium poly_sports_stadium\n" |
639 | "w leisure=stadium poly_sports_stadium\n" |
693 | //"w leisure=track poly_sports_track\n" |
640 | //"w leisure=track poly_sports_track\n" |
694 | "w leisure=water_park poly_water_park\n" |
641 | "w leisure=water_park poly_water_park\n" |
695 | "w military=airfield poly_airfield\n" |
642 | "w military=airfield poly_airfield\n" |
696 | //"w military=barracks poly_barracks\n" |
643 | "w military=barracks poly_barracks\n" |
697 | "w military=danger_area poly_danger_area\n" |
644 | "w military=danger_area poly_danger_area\n" |
698 | "w military=naval_base poly_naval_base\n" |
645 | "w military=naval_base poly_naval_base\n" |
699 | //"w military=range poly_range\n" |
646 | "w military=range poly_range\n" |
700 | "w natural=beach poly_beach\n" |
647 | "w natural=beach poly_beach\n" |
701 | // "w natural=coastline water_line\n" --> in coastline map |
648 | // "w natural=coastline water_line\n" --> in coastline map |
702 | "w natural=fell poly_fell\n" |
649 | "w natural=fell poly_fell\n" |
703 | "w natural=glacier poly_glacier\n" |
650 | "w natural=glacier poly_glacier\n" |
704 | "w natural=heath poly_heath\n" |
651 | "w natural=heath poly_heath\n" |
… | |
… | |
723 | "w place=town poly_place5\n" |
670 | "w place=town poly_place5\n" |
724 | "w place=city poly_place6\n" |
671 | "w place=city poly_place6\n" |
725 | //"w power=line powerline\n" |
672 | //"w power=line powerline\n" |
726 | //"w railway=abandoned rail_abandoned\n" |
673 | //"w railway=abandoned rail_abandoned\n" |
727 | //"w railway=disused rail_disused\n" |
674 | //"w railway=disused rail_disused\n" |
728 | //"w railway=light_rail rail_light\n" |
675 | "w railway=light_rail rail_light\n" |
729 | //"w railway=monorail rail_mono\n" |
676 | "w railway=monorail rail_mono\n" |
730 | //"w railway=narrow_gauge rail_narrow_gauge\n" |
677 | "w railway=narrow_gauge rail_narrow_gauge\n" |
731 | //"w railway=preserved rail_preserved\n" |
678 | //"w railway=preserved rail_preserved\n" |
732 | "w railway=rail rail\n" |
679 | "w railway=rail rail\n" |
733 | "w railway=subway rail_subway\n" |
680 | "w railway=subway rail_subway\n" |
734 | "w railway=tram rail_tram\n" |
681 | "w railway=tram rail_tram\n" |
735 | "w route=ferry ferry\n" |
682 | "w route=ferry ferry\n" |
… | |
… | |
750 | "w barrier=ditch ditch\n" |
697 | "w barrier=ditch ditch\n" |
751 | "w barrier=hedge hedge\n" |
698 | "w barrier=hedge hedge\n" |
752 | "w barrier=fence fence\n" |
699 | "w barrier=fence fence\n" |
753 | "w barrier=wall wall\n" |
700 | "w barrier=wall wall\n" |
754 | "w barrier=retaining_wall retaining_wall\n" |
701 | "w barrier=retaining_wall retaining_wall\n" |
755 | "w barrier=city_wall city_wall\n" |
702 | "w barrier=city_wall city_wall\n" }; |
756 | }; |
|
|
757 | |
703 | |
758 | |
|
|
759 | |
|
|
760 | static void |
|
|
761 | build_attrmap_line(char *line) |
704 | static void build_attrmap_line(char *line) |
762 | { |
705 | { |
763 | char *t=NULL,*kvl=NULL,*i=NULL,*p,*kv; |
706 | char *t = NULL, *kvl = NULL, *i = NULL, *p, *kv; |
764 | struct attr_mapping *attr_mapping=g_malloc0(sizeof(struct attr_mapping)); |
707 | struct attr_mapping *attr_mapping = g_malloc0(sizeof(struct attr_mapping)); |
765 | int idx,attr_mapping_count=0; |
708 | int idx, attr_mapping_count = 0; |
766 | t=line; |
709 | t = line; |
767 | p=strchr(t,'\t'); |
710 | p = strchr(t, '\t'); |
768 | if (p) { |
711 | if (p) |
|
|
712 | { |
769 | while (*p == '\t') |
713 | while (*p == '\t') |
770 | *p++='\0'; |
714 | *p++ = '\0'; |
771 | kvl=p; |
715 | kvl = p; |
772 | p=strchr(kvl,'\t'); |
716 | p = strchr(kvl, '\t'); |
773 | } |
717 | } |
774 | if (p) { |
718 | if (p) |
|
|
719 | { |
775 | while (*p == '\t') |
720 | while (*p == '\t') |
776 | *p++='\0'; |
721 | *p++ = '\0'; |
777 | i=p; |
722 | i = p; |
778 | } |
723 | } |
779 | if (t[0] == 'w') { |
724 | if (t[0] == 'w') |
|
|
725 | { |
780 | if (! i) |
726 | if (!i) |
781 | i="street_unkn"; |
727 | i = "street_unkn"; |
782 | } else { |
728 | } |
|
|
729 | else |
|
|
730 | { |
783 | if (! i) |
731 | if (!i) |
784 | i="point_unkn"; |
732 | i = "point_unkn"; |
785 | } |
733 | } |
|
|
734 | |
786 | attr_mapping->type=item_from_name(i); |
735 | attr_mapping->type = item_from_name(i); |
|
|
736 | |
787 | if (!attr_mapping->type) { |
737 | if (!attr_mapping->type) |
|
|
738 | { |
788 | printf("no id found for '%s'\n",i); |
739 | printf("no id found for '%s'\n", i); |
789 | } |
740 | } |
|
|
741 | |
790 | while ((kv=strtok(kvl, ","))) { |
742 | while ((kv = strtok(kvl, ","))) |
|
|
743 | { |
791 | kvl=NULL; |
744 | kvl = NULL; |
792 | if (!(idx=(int)(long)g_hash_table_lookup(attr_hash, kv))) { |
745 | if (!(idx = (int) (long) g_hash_table_lookup(attr_hash, kv))) |
|
|
746 | { |
793 | idx=attr_present_count++; |
747 | idx = attr_present_count++; |
794 | g_hash_table_insert(attr_hash, kv, (gpointer)(long)idx); |
748 | g_hash_table_insert(attr_hash, kv, (gpointer) (long) idx); |
795 | } |
749 | } |
796 | attr_mapping=g_realloc(attr_mapping, sizeof(struct attr_mapping)+(attr_mapping_count+1)*sizeof(int)); |
750 | attr_mapping = g_realloc(attr_mapping, sizeof(struct attr_mapping) + (attr_mapping_count + 1) * sizeof(int)); |
797 | attr_mapping->attr_present_idx[attr_mapping_count++]=idx; |
751 | attr_mapping->attr_present_idx[attr_mapping_count++] = idx; |
798 | attr_mapping->attr_present_idx_count=attr_mapping_count; |
752 | attr_mapping->attr_present_idx_count = attr_mapping_count; |
799 | } |
753 | } |
800 | if (t[0]== 'w') { |
754 | if (t[0] == 'w') |
|
|
755 | { |
801 | attr_mapping_way=g_realloc(attr_mapping_way, sizeof(*attr_mapping_way)*(attr_mapping_way_count+1)); |
756 | attr_mapping_way = g_realloc(attr_mapping_way, sizeof(*attr_mapping_way) * (attr_mapping_way_count + 1)); |
802 | attr_mapping_way[attr_mapping_way_count++]=attr_mapping; |
757 | attr_mapping_way[attr_mapping_way_count++] = attr_mapping; |
803 | } |
758 | } |
804 | if (t[0]== '?' && doway2poi) { |
759 | if (t[0] == '?' && doway2poi) |
|
|
760 | { |
805 | attr_mapping_way2poi=g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi)*(attr_mapping_way2poi_count+1)); |
761 | attr_mapping_way2poi = g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi) * (attr_mapping_way2poi_count + 1)); |
806 | attr_mapping_way2poi[attr_mapping_way2poi_count++]=attr_mapping; |
762 | attr_mapping_way2poi[attr_mapping_way2poi_count++] = attr_mapping; |
807 | } |
763 | } |
808 | if (t[0]!= 'w') { |
764 | if (t[0] != 'w') |
|
|
765 | { |
809 | attr_mapping_node=g_realloc(attr_mapping_node, sizeof(*attr_mapping_node)*(attr_mapping_node_count+1)); |
766 | attr_mapping_node = g_realloc(attr_mapping_node, sizeof(*attr_mapping_node) * (attr_mapping_node_count + 1)); |
810 | attr_mapping_node[attr_mapping_node_count++]=attr_mapping; |
767 | attr_mapping_node[attr_mapping_node_count++] = attr_mapping; |
811 | } |
768 | } |
812 | |
769 | |
813 | } |
770 | } |
814 | |
771 | |
815 | static void |
|
|
816 | build_attrmap(FILE* rule_file) |
772 | static void build_attrmap(FILE* rule_file) |
817 | { |
773 | { |
818 | attr_hash=g_hash_table_new(g_str_hash, g_str_equal); |
774 | attr_hash = g_hash_table_new(g_str_hash, g_str_equal); |
819 | attr_present_count=1; |
775 | attr_present_count = 1; |
820 | |
776 | |
821 | // build attribute map from rule file if given |
777 | // build attribute map from rule file if given |
822 | if( rule_file ) |
778 | if (rule_file) |
823 | { |
779 | { |
824 | char buffer[200], *p; |
780 | char buffer[200], *p; |
825 | while (fgets( buffer, 200, rule_file )) { |
781 | while (fgets(buffer, 200, rule_file)) |
826 | p=strchr(buffer,'\n'); |
782 | { |
827 | if(p) |
783 | p = strchr(buffer, '\n'); |
828 | *p = 0; |
784 | if (p) |
|
|
785 | *p = 0; |
829 | build_attrmap_line( g_strdup( buffer ) ); |
786 | build_attrmap_line(g_strdup(buffer)); |
830 | } |
787 | } |
831 | fclose( rule_file ); |
788 | fclose(rule_file); |
832 | } |
789 | } |
833 | // use hardcoded default attributes |
790 | // use hardcoded default attributes |
834 | else |
791 | else |
835 | { |
792 | { |
836 | char *p,*map; |
793 | char *p, *map; |
837 | if (border_only_map==1) |
794 | if (border_only_map == 1) |
838 | { |
795 | { |
839 | map=g_strdup(attrmap_bo); |
796 | map = g_strdup(attrmap_bo); |
840 | } |
797 | } |
841 | else if (coastline_only_map==1) |
798 | else if (coastline_only_map == 1) |
842 | { |
799 | { |
843 | map=g_strdup(attrmap_cl); |
800 | map = g_strdup(attrmap_cl); |
844 | } |
801 | } |
845 | else |
802 | else |
846 | { |
803 | { |
847 | map=g_strdup(attrmap_normal); |
804 | map = g_strdup(attrmap_normal); |
848 | } |
805 | } |
849 | |
806 | |
850 | while (map) { |
807 | while (map) |
851 | p=strchr(map,'\n'); |
808 | { |
852 | if (p) |
809 | p = strchr(map, '\n'); |
853 | *p++='\0'; |
810 | if (p) |
854 | if (strlen(map)) |
811 | *p++ = '\0'; |
855 | build_attrmap_line(map); |
812 | if (strlen(map)) |
856 | map=p; |
813 | build_attrmap_line(map); |
857 | } |
814 | map = p; |
858 | } |
815 | } |
|
|
816 | } |
859 | |
817 | |
860 | attr_present=g_malloc0(sizeof(*attr_present)*attr_present_count); |
818 | attr_present = g_malloc0(sizeof(*attr_present) * attr_present_count); |
861 | } |
819 | } |
862 | |
820 | |
863 | static void |
|
|
864 | build_countrytable(void) |
821 | static void build_countrytable(void) |
865 | { |
822 | { |
866 | int i; |
823 | int i; |
867 | char *names,*str,*tok; |
824 | char *names, *str, *tok; |
868 | country_table_hash=g_hash_table_new(g_str_hash, g_str_equal); |
825 | country_table_hash = g_hash_table_new(g_str_hash, g_str_equal); |
869 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { |
826 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
|
|
827 | { |
870 | names=g_strdup(country_table[i].names); |
828 | names = g_strdup(country_table[i].names); |
871 | str=names; |
829 | str = names; |
872 | while ((tok=strtok(str, ","))) { |
830 | while ((tok = strtok(str, ","))) |
|
|
831 | { |
873 | str=NULL; |
832 | str = NULL; |
874 | g_hash_table_insert(country_table_hash, tok, (gpointer)&country_table[i]); |
833 | g_hash_table_insert(country_table_hash, tok, (gpointer) & country_table[i]); |
875 | } |
|
|
876 | } |
834 | } |
|
|
835 | } |
877 | } |
836 | } |
878 | |
837 | |
879 | void |
|
|
880 | osm_warning(char *type, long long id, int cont, char *fmt, ...) |
838 | void osm_warning(char *type, long long id, int cont, char *fmt, ...) |
881 | { |
839 | { |
882 | char str[4096]; |
840 | char str[4096]; |
883 | va_list ap; |
841 | va_list ap; |
884 | va_start(ap, fmt); |
842 | va_start(ap, fmt); |
885 | vsnprintf(str, sizeof(str), fmt, ap); |
843 | vsnprintf(str, sizeof(str), fmt, ap); |
886 | va_end(ap); |
844 | va_end(ap); |
887 | fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Warning:",type,id,str); |
845 | if (verbose_mode) fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Warning:",type,id,str); |
888 | } |
846 | } |
889 | |
847 | |
890 | void |
|
|
891 | osm_info(char *type, long long id, int cont, char *fmt, ...) |
848 | void osm_info(char *type, long long id, int cont, char *fmt, ...) |
892 | { |
849 | { |
893 | char str[4096]; |
850 | char str[4096]; |
894 | va_list ap; |
851 | va_list ap; |
895 | va_start(ap, fmt); |
852 | va_start(ap, fmt); |
896 | vsnprintf(str, sizeof(str), fmt, ap); |
853 | vsnprintf(str, sizeof(str), fmt, ap); |
897 | va_end(ap); |
854 | va_end(ap); |
898 | fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Info:",type,id,str); |
855 | if (verbose_mode) fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Info:",type,id,str); |
899 | } |
856 | } |
900 | |
857 | |
901 | static void |
|
|
902 | attr_strings_clear(void) |
858 | static void attr_strings_clear(void) |
903 | { |
859 | { |
|
|
860 | alt_name_found = 0; |
904 | attr_strings_buffer_len=0; |
861 | attr_strings_buffer_len = 0; |
905 | memset(attr_strings, 0, sizeof(attr_strings)); |
862 | memset(attr_strings, 0, sizeof(attr_strings)); |
906 | } |
863 | } |
907 | |
864 | |
908 | static void |
|
|
909 | attr_strings_save(enum attr_strings id, char *str) |
865 | static void attr_strings_save(enum attr_strings id, char *str) |
910 | { |
866 | { |
911 | attr_strings[id]=attr_strings_buffer+attr_strings_buffer_len; |
867 | attr_strings[id] = attr_strings_buffer + attr_strings_buffer_len; |
912 | strcpy(attr_strings[id], str); |
868 | strcpy(attr_strings[id], str); |
913 | attr_strings_buffer_len+=strlen(str)+1; |
869 | attr_strings_buffer_len += strlen(str) + 1; |
914 | } |
870 | } |
915 | |
871 | |
916 | long long |
|
|
917 | item_bin_get_nodeid(struct item_bin *ib) |
872 | long long item_bin_get_nodeid(struct item_bin *ib) |
918 | { |
873 | { |
919 | long long *ret=item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
874 | long long *ret = item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
920 | if (ret) |
875 | if (ret) |
|
|
876 | { |
921 | return *ret; |
877 | return *ret; |
|
|
878 | } |
922 | return 0; |
879 | return 0; |
923 | } |
880 | } |
924 | |
881 | |
925 | long long |
|
|
926 | item_bin_get_wayid(struct item_bin *ib) |
882 | long long item_bin_get_wayid(struct item_bin *ib) |
927 | { |
883 | { |
928 | long long *ret=item_bin_get_attr(ib, attr_osm_wayid, NULL); |
884 | long long *ret = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
929 | if (ret) |
885 | if (ret) |
|
|
886 | { |
930 | return *ret; |
887 | return *ret; |
|
|
888 | } |
931 | return 0; |
889 | return 0; |
932 | } |
890 | } |
933 | |
891 | |
934 | long long |
|
|
935 | item_bin_get_relationid(struct item_bin *ib) |
892 | long long item_bin_get_relationid(struct item_bin *ib) |
936 | { |
893 | { |
937 | long long *ret=item_bin_get_attr(ib, attr_osm_relationid, NULL); |
894 | long long *ret = item_bin_get_attr(ib, attr_osm_relationid, NULL); |
938 | if (ret) |
895 | if (ret) |
|
|
896 | { |
939 | return *ret; |
897 | return *ret; |
|
|
898 | } |
940 | return 0; |
899 | return 0; |
941 | } |
900 | } |
942 | |
901 | |
943 | long long |
|
|
944 | item_bin_get_id(struct item_bin *ib) |
902 | long long item_bin_get_id(struct item_bin *ib) |
945 | { |
903 | { |
946 | long long ret; |
904 | long long ret; |
947 | if (ib->type < 0x80000000) |
905 | if (ib->type < 0x80000000) |
|
|
906 | { |
948 | return item_bin_get_nodeid(ib); |
907 | return item_bin_get_nodeid(ib); |
|
|
908 | } |
949 | ret=item_bin_get_wayid(ib); |
909 | ret = item_bin_get_wayid(ib); |
950 | if (!ret) |
910 | if (!ret) |
|
|
911 | { |
951 | ret=item_bin_get_relationid(ib); |
912 | ret = item_bin_get_relationid(ib); |
|
|
913 | } |
952 | return ret; |
914 | return ret; |
953 | } |
915 | } |
954 | |
916 | |
955 | static int node_is_tagged; |
917 | static int node_is_tagged; |
956 | static void relation_add_tag(char *k, char *v); |
918 | static void relation_add_tag(char *k, char *v); |
957 | |
919 | |
958 | static int |
|
|
959 | access_value(char *v) |
920 | static int access_value(char *v) |
960 | { |
921 | { |
961 | if (!strcmp(v,"1")) |
922 | if (!strcmp(v, "1")) |
962 | return 1; |
923 | return 1; |
963 | if (!strcmp(v,"yes")) |
924 | if (!strcmp(v, "yes")) |
964 | return 1; |
925 | return 1; |
965 | if (!strcmp(v,"designated")) |
926 | if (!strcmp(v, "designated")) |
966 | return 1; |
927 | return 1; |
967 | if (!strcmp(v,"official")) |
928 | if (!strcmp(v, "official")) |
968 | return 1; |
929 | return 1; |
969 | if (!strcmp(v,"permissive")) |
930 | if (!strcmp(v, "permissive")) |
970 | return 1; |
931 | return 1; |
971 | if (!strcmp(v,"0")) |
932 | if (!strcmp(v, "0")) |
972 | return 2; |
933 | return 2; |
973 | if (!strcmp(v,"no")) |
934 | if (!strcmp(v, "no")) |
974 | return 2; |
935 | return 2; |
975 | if (!strcmp(v,"agricultural")) |
936 | if (!strcmp(v, "agricultural")) |
976 | return 2; |
937 | return 2; |
977 | if (!strcmp(v,"forestry")) |
938 | if (!strcmp(v, "forestry")) |
978 | return 2; |
939 | return 2; |
979 | if (!strcmp(v,"private")) |
940 | if (!strcmp(v, "private")) |
980 | return 2; |
941 | return 2; |
981 | if (!strcmp(v,"delivery")) |
942 | if (!strcmp(v, "delivery")) |
982 | return 2; |
943 | return 2; |
983 | if (!strcmp(v,"destination")) |
944 | if (!strcmp(v, "destination")) |
984 | return 2; |
945 | return 2; |
985 | return 3; |
946 | return 3; |
986 | } |
947 | } |
987 | |
948 | |
988 | void |
|
|
989 | osm_add_tag(char *k, char *v) |
949 | void osm_add_tag(char *k, char *v) |
990 | { |
950 | { |
991 | int idx,level=2; |
951 | int idx, level = 2; |
992 | char buffer[BUFFER_SIZE*2+2]; |
952 | char buffer[BUFFER_SIZE * 2 + 2]; |
|
|
953 | |
993 | if (in_relation) { |
954 | if (in_relation) |
|
|
955 | { |
994 | relation_add_tag(k,v); |
956 | relation_add_tag(k, v); |
995 | return; |
957 | return; |
996 | } |
958 | } |
|
|
959 | |
997 | if (! strcmp(k,"ele")) |
960 | if (!strcmp(k, "ele")) |
998 | level=9; |
961 | level = 9; |
999 | if (! strcmp(k,"time")) |
962 | if (!strcmp(k, "time")) |
1000 | level=9; |
963 | level = 9; |
1001 | if (! strcmp(k,"created_by")) |
964 | if (!strcmp(k, "created_by")) |
1002 | level=9; |
965 | level = 9; |
1003 | if (! strncmp(k,"tiger:",6) || !strcmp(k,"AND_nodes")) |
966 | if (!strncmp(k, "tiger:", 6) || !strcmp(k, "AND_nodes")) |
1004 | level=9; |
967 | level = 9; |
1005 | if (! strcmp(k,"converted_by") || ! strcmp(k,"source")) |
968 | if (!strcmp(k, "converted_by") || !strcmp(k, "source")) |
1006 | level=8; |
969 | level = 8; |
1007 | if (! strncmp(k,"osmarender:",11) || !strncmp(k,"svg:",4)) |
970 | if (!strncmp(k, "osmarender:", 11) || !strncmp(k, "svg:", 4)) |
1008 | level=8; |
971 | level = 8; |
1009 | if (! strcmp(k,"layer")) |
972 | if (!strcmp(k, "layer")) |
1010 | level=7; |
973 | level = 7; |
1011 | if (! strcasecmp(v,"true") || ! strcasecmp(v,"yes")) |
974 | if (!strcasecmp(v, "true") || !strcasecmp(v, "yes")) |
1012 | v="1"; |
975 | v = "1"; |
1013 | if (! strcasecmp(v,"false") || ! strcasecmp(v,"no")) |
976 | if (!strcasecmp(v, "false") || !strcasecmp(v, "no")) |
1014 | v="0"; |
977 | v = "0"; |
1015 | if (! strcmp(k,"oneway")) { |
978 | if (!strcmp(k, "oneway")) |
|
|
979 | { |
1016 | if (!strcmp(v,"1")) { |
980 | if (!strcmp(v, "1")) |
|
|
981 | { |
1017 | flags[0] |= AF_ONEWAY | AF_ROUNDABOUT_VALID; |
982 | flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT_VALID; |
1018 | } |
983 | } |
1019 | if (! strcmp(v,"-1")) { |
984 | if (!strcmp(v, "-1")) |
|
|
985 | { |
1020 | flags[0] |= AF_ONEWAYREV | AF_ROUNDABOUT_VALID; |
986 | flags[0] |= NAVIT_AF_ONEWAYREV | NAVIT_AF_ROUNDABOUT_VALID; |
1021 | } |
987 | } |
1022 | if (!in_way) |
988 | if (!in_way) |
1023 | level=6; |
989 | level = 6; |
1024 | else |
990 | else |
1025 | level=5; |
991 | level = 5; |
1026 | } |
992 | } |
1027 | if (! strcmp(k,"junction")) { |
993 | if (!strcmp(k, "junction")) |
|
|
994 | { |
1028 | if (! strcmp(v,"roundabout")) |
995 | if (!strcmp(v, "roundabout")) |
1029 | flags[0] |= AF_ONEWAY | AF_ROUNDABOUT | AF_ROUNDABOUT_VALID; |
996 | flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT | NAVIT_AF_ROUNDABOUT_VALID; |
1030 | } |
997 | } |
1031 | if (! strcmp(k,"maxspeed")) { |
998 | if (!strcmp(k, "maxspeed")) |
|
|
999 | { |
1032 | if (strstr(v, "mph")) { |
1000 | if (strstr(v, "mph")) |
|
|
1001 | { |
1033 | maxspeed_attr_value = (int)floor(atof(v) * 1.609344); |
1002 | maxspeed_attr_value = (int) floor(atof(v) * 1.609344); |
|
|
1003 | } |
1034 | } else { |
1004 | else |
|
|
1005 | { |
1035 | maxspeed_attr_value = atoi(v); |
1006 | maxspeed_attr_value = atoi(v); |
1036 | } |
1007 | } |
1037 | if (maxspeed_attr_value) |
1008 | if (maxspeed_attr_value) |
1038 | flags[0] |= AF_SPEED_LIMIT; |
1009 | flags[0] |= NAVIT_AF_SPEED_LIMIT; |
1039 | level=5; |
1010 | level = 5; |
1040 | } |
1011 | } |
1041 | if (! strcmp(k,"toll")) { |
1012 | if (!strcmp(k, "toll")) |
|
|
1013 | { |
1042 | if (!strcmp(v,"1")) { |
1014 | if (!strcmp(v, "1")) |
|
|
1015 | { |
1043 | flags[0] |= AF_TOLL; |
1016 | flags[0] |= NAVIT_AF_TOLL; |
1044 | } |
|
|
1045 | } |
1017 | } |
|
|
1018 | } |
1046 | if (! strcmp(k,"access")) { |
1019 | if (!strcmp(k, "access")) |
1047 | flags[access_value(v)] |= AF_DANGEROUS_GOODS|AF_EMERGENCY_VEHICLES|AF_TRANSPORT_TRUCK|AF_DELIVERY_TRUCK|AF_PUBLIC_BUS|AF_TAXI|AF_HIGH_OCCUPANCY_CAR|AF_CAR|AF_MOTORCYCLE|AF_MOPED|AF_HORSE|AF_BIKE|AF_PEDESTRIAN; |
1020 | { |
|
|
1021 | flags[access_value(v)] |= NAVIT_AF_DANGEROUS_GOODS | NAVIT_AF_EMERGENCY_VEHICLES | NAVIT_AF_TRANSPORT_TRUCK | NAVIT_AF_DELIVERY_TRUCK | NAVIT_AF_PUBLIC_BUS | NAVIT_AF_TAXI | NAVIT_AF_HIGH_OCCUPANCY_CAR | NAVIT_AF_CAR | NAVIT_AF_MOTORCYCLE | NAVIT_AF_MOPED | NAVIT_AF_HORSE | NAVIT_AF_BIKE | NAVIT_AF_PEDESTRIAN; |
1048 | level=5; |
1022 | level = 5; |
1049 | } |
1023 | } |
1050 | if (! strcmp(k,"vehicle")) { |
1024 | if (!strcmp(k, "vehicle")) |
1051 | 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; |
1025 | { |
|
|
1026 | flags[access_value(v)] |= NAVIT_AF_DANGEROUS_GOODS | NAVIT_AF_EMERGENCY_VEHICLES | NAVIT_AF_TRANSPORT_TRUCK | NAVIT_AF_DELIVERY_TRUCK | NAVIT_AF_PUBLIC_BUS | NAVIT_AF_TAXI | NAVIT_AF_HIGH_OCCUPANCY_CAR | NAVIT_AF_CAR | NAVIT_AF_MOTORCYCLE | NAVIT_AF_MOPED | NAVIT_AF_BIKE; |
1052 | level=5; |
1027 | level = 5; |
1053 | } |
1028 | } |
1054 | if (! strcmp(k,"motorvehicle")) { |
1029 | if (!strcmp(k, "motorvehicle")) |
1055 | 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; |
1030 | { |
|
|
1031 | flags[access_value(v)] |= NAVIT_AF_DANGEROUS_GOODS | NAVIT_AF_EMERGENCY_VEHICLES | NAVIT_AF_TRANSPORT_TRUCK | NAVIT_AF_DELIVERY_TRUCK | NAVIT_AF_PUBLIC_BUS | NAVIT_AF_TAXI | NAVIT_AF_HIGH_OCCUPANCY_CAR | NAVIT_AF_CAR | NAVIT_AF_MOTORCYCLE | NAVIT_AF_MOPED; |
1056 | level=5; |
1032 | level = 5; |
1057 | } |
1033 | } |
1058 | if (! strcmp(k,"bicycle")) { |
1034 | if (!strcmp(k, "bicycle")) |
|
|
1035 | { |
1059 | flags[access_value(v)] |= AF_BIKE; |
1036 | flags[access_value(v)] |= NAVIT_AF_BIKE; |
1060 | level=5; |
1037 | level = 5; |
1061 | } |
1038 | } |
1062 | if (! strcmp(k,"foot")) { |
1039 | if (!strcmp(k, "foot")) |
|
|
1040 | { |
1063 | flags[access_value(v)] |= AF_PEDESTRIAN; |
1041 | flags[access_value(v)] |= NAVIT_AF_PEDESTRIAN; |
1064 | level=5; |
1042 | level = 5; |
1065 | } |
1043 | } |
1066 | if (! strcmp(k,"horse")) { |
1044 | if (!strcmp(k, "horse")) |
|
|
1045 | { |
1067 | flags[access_value(v)] |= AF_HORSE; |
1046 | flags[access_value(v)] |= NAVIT_AF_HORSE; |
1068 | level=5; |
1047 | level = 5; |
1069 | } |
1048 | } |
1070 | if (! strcmp(k,"moped")) { |
1049 | if (!strcmp(k, "moped")) |
|
|
1050 | { |
1071 | flags[access_value(v)] |= AF_MOPED; |
1051 | flags[access_value(v)] |= NAVIT_AF_MOPED; |
1072 | level=5; |
1052 | level = 5; |
1073 | } |
1053 | } |
1074 | if (! strcmp(k,"motorcycle")) { |
1054 | if (!strcmp(k, "motorcycle")) |
|
|
1055 | { |
1075 | flags[access_value(v)] |= AF_MOTORCYCLE; |
1056 | flags[access_value(v)] |= NAVIT_AF_MOTORCYCLE; |
1076 | level=5; |
1057 | level = 5; |
1077 | } |
1058 | } |
1078 | if (! strcmp(k,"motorcar")) { |
1059 | if (!strcmp(k, "motorcar")) |
|
|
1060 | { |
1079 | flags[access_value(v)] |= AF_CAR; |
1061 | flags[access_value(v)] |= NAVIT_AF_CAR; |
1080 | level=5; |
1062 | level = 5; |
1081 | } |
1063 | } |
1082 | if (! strcmp(k,"hov")) { |
1064 | if (!strcmp(k, "hov")) |
|
|
1065 | { |
1083 | flags[access_value(v)] |= AF_HIGH_OCCUPANCY_CAR; |
1066 | flags[access_value(v)] |= NAVIT_AF_HIGH_OCCUPANCY_CAR; |
1084 | level=5; |
1067 | level = 5; |
1085 | } |
1068 | } |
1086 | if (! strcmp(k,"bus")) { |
1069 | if (!strcmp(k, "bus")) |
|
|
1070 | { |
1087 | flags[access_value(v)] |= AF_PUBLIC_BUS; |
1071 | flags[access_value(v)] |= NAVIT_AF_PUBLIC_BUS; |
1088 | level=5; |
1072 | level = 5; |
1089 | } |
1073 | } |
1090 | if (! strcmp(k,"taxi")) { |
1074 | if (!strcmp(k, "taxi")) |
|
|
1075 | { |
1091 | flags[access_value(v)] |= AF_TAXI; |
1076 | flags[access_value(v)] |= NAVIT_AF_TAXI; |
1092 | level=5; |
1077 | level = 5; |
1093 | } |
1078 | } |
1094 | if (! strcmp(k,"goods")) { |
1079 | if (!strcmp(k, "goods")) |
|
|
1080 | { |
1095 | flags[access_value(v)] |= AF_DELIVERY_TRUCK; |
1081 | flags[access_value(v)] |= NAVIT_AF_DELIVERY_TRUCK; |
1096 | level=5; |
1082 | level = 5; |
1097 | } |
1083 | } |
1098 | if (! strcmp(k,"hgv")) { |
1084 | if (!strcmp(k, "hgv")) |
|
|
1085 | { |
1099 | flags[access_value(v)] |= AF_TRANSPORT_TRUCK; |
1086 | flags[access_value(v)] |= NAVIT_AF_TRANSPORT_TRUCK; |
1100 | level=5; |
1087 | level = 5; |
1101 | } |
1088 | } |
1102 | if (! strcmp(k,"emergency")) { |
1089 | if (!strcmp(k, "emergency")) |
|
|
1090 | { |
1103 | flags[access_value(v)] |= AF_EMERGENCY_VEHICLES; |
1091 | flags[access_value(v)] |= NAVIT_AF_EMERGENCY_VEHICLES; |
1104 | level=5; |
1092 | level = 5; |
1105 | } |
1093 | } |
1106 | if (! strcmp(k,"hazmat")) { |
1094 | if (!strcmp(k, "hazmat")) |
|
|
1095 | { |
1107 | flags[access_value(v)] |= AF_DANGEROUS_GOODS; |
1096 | flags[access_value(v)] |= NAVIT_AF_DANGEROUS_GOODS; |
1108 | level=5; |
1097 | level = 5; |
1109 | } |
1098 | } |
1110 | if (! strcmp(k,"tunnel") && !strcmp(v,"1")) { |
1099 | if (!strcmp(k, "tunnel") && !strcmp(v, "1")) |
|
|
1100 | { |
1111 | flags[0] |= AF_UNDERGROUND; |
1101 | flags[0] |= NAVIT_AF_UNDERGROUND; |
1112 | } |
1102 | } |
|
|
1103 | if (!strcmp(k, "bridge") && !strcmp(v, "1")) |
|
|
1104 | { |
|
|
1105 | flags[0] |= NAVIT_AF_BRIDGE; |
|
|
1106 | } |
1113 | if (! strcmp(k,"note")) |
1107 | if (!strcmp(k, "note")) |
1114 | level=5; |
1108 | level = 5; |
1115 | if (! strcmp(k,"name")) { |
1109 | if (!strcmp(k, "name")) |
|
|
1110 | { |
1116 | attr_strings_save(attr_string_label, v); |
1111 | attr_strings_save(attr_string_label, v); |
1117 | level=5; |
1112 | level = 5; |
1118 | } |
1113 | } |
|
|
1114 | |
|
|
1115 | if ((!strcmp(k, "name:en")) && (alt_name_found == 0)) |
|
|
1116 | { |
|
|
1117 | attr_strings_save(attr_string_label_alt, v); |
|
|
1118 | alt_name_found = 1; |
|
|
1119 | level = 5; |
|
|
1120 | } |
|
|
1121 | if ((!strcmp(k, "alt_name:en")) && (alt_name_found < 2)) |
|
|
1122 | { |
|
|
1123 | // only use "alt_name:en" if we dont have "alt_name" |
|
|
1124 | attr_strings_save(attr_string_label_alt, v); |
|
|
1125 | alt_name_found = 2; |
|
|
1126 | level = 5; |
|
|
1127 | } |
|
|
1128 | if (!strcmp(k, "alt_name")) |
|
|
1129 | { |
|
|
1130 | attr_strings_save(attr_string_label_alt, v); |
|
|
1131 | alt_name_found = 3; |
|
|
1132 | level = 5; |
|
|
1133 | } |
1119 | if (! strcmp(k,"addr:email")) { |
1134 | if (!strcmp(k, "addr:email")) |
|
|
1135 | { |
1120 | attr_strings_save(attr_string_email, v); |
1136 | attr_strings_save(attr_string_email, v); |
1121 | level=5; |
1137 | level = 5; |
1122 | } |
1138 | } |
1123 | if (! strcmp(k,"addr:housenumber")) { |
1139 | if (!strcmp(k, "addr:housenumber")) |
|
|
1140 | { |
1124 | attr_strings_save(attr_string_house_number, v); |
1141 | attr_strings_save(attr_string_house_number, v); |
1125 | level=5; |
1142 | level = 5; |
1126 | } |
1143 | } |
1127 | if (! strcmp(k,"addr:street")) { |
1144 | if (!strcmp(k, "addr:street")) |
|
|
1145 | { |
1128 | attr_strings_save(attr_string_street_name, v); |
1146 | attr_strings_save(attr_string_street_name, v); |
1129 | level=5; |
1147 | level = 5; |
1130 | } |
1148 | } |
|
|
1149 | if (!strcmp(k, "colour")) |
|
|
1150 | { |
|
|
1151 | attr_strings_save(attr_string_colour_, v); |
|
|
1152 | level = 5; |
|
|
1153 | } |
1131 | if (! strcmp(k,"phone")) { |
1154 | if (!strcmp(k, "phone")) |
|
|
1155 | { |
1132 | attr_strings_save(attr_string_phone, v); |
1156 | attr_strings_save(attr_string_phone, v); |
1133 | level=5; |
1157 | level = 5; |
1134 | } |
1158 | } |
1135 | if (! strcmp(k,"fax")) { |
1159 | if (!strcmp(k, "fax")) |
|
|
1160 | { |
1136 | attr_strings_save(attr_string_fax, v); |
1161 | attr_strings_save(attr_string_fax, v); |
1137 | level=5; |
1162 | level = 5; |
1138 | } |
1163 | } |
1139 | if (! strcmp(k,"postal_code")) { |
1164 | if (!strcmp(k, "postal_code")) |
|
|
1165 | { |
1140 | attr_strings_save(attr_string_postal, v); |
1166 | attr_strings_save(attr_string_postal, v); |
1141 | level=5; |
1167 | level = 5; |
1142 | } |
1168 | } |
1143 | if (! strcmp(k,"openGeoDB:postal_codes") && !attr_strings[attr_string_postal]) { |
1169 | if (!strcmp(k, "openGeoDB:postal_codes") && !attr_strings[attr_string_postal]) |
|
|
1170 | { |
1144 | attr_strings_save(attr_string_postal, v); |
1171 | attr_strings_save(attr_string_postal, v); |
1145 | level=5; |
1172 | level = 5; |
1146 | } |
1173 | } |
1147 | if (! strcmp(k,"population")) { |
1174 | if (!strcmp(k, "population")) |
|
|
1175 | { |
1148 | attr_strings_save(attr_string_population, v); |
1176 | attr_strings_save(attr_string_population, v); |
1149 | level=5; |
1177 | level = 5; |
1150 | } |
1178 | } |
1151 | if (! strcmp(k,"openGeoDB:population") && !attr_strings[attr_string_population]) { |
1179 | if (!strcmp(k, "openGeoDB:population") && !attr_strings[attr_string_population]) |
|
|
1180 | { |
1152 | attr_strings_save(attr_string_population, v); |
1181 | attr_strings_save(attr_string_population, v); |
1153 | level=5; |
1182 | level = 5; |
1154 | } |
1183 | } |
1155 | if (! strcmp(k,"ref")) { |
1184 | if (!strcmp(k, "ref")) |
|
|
1185 | { |
1156 | if (in_way) |
1186 | if (in_way) |
1157 | attr_strings_save(attr_string_street_name_systematic, v); |
1187 | attr_strings_save(attr_string_street_name_systematic, v); |
1158 | level=5; |
1188 | level = 5; |
1159 | } |
1189 | } |
1160 | if (! strcmp(k,"openGeoDB:is_in")) { |
1190 | if (!strcmp(k, "openGeoDB:is_in")) |
1161 | if (!is_in_buffer[0]) |
1191 | { |
1162 | strcpy(is_in_buffer, v); |
|
|
1163 | level=5; |
|
|
1164 | } |
|
|
1165 | if (! strcmp(k,"is_in")) { |
|
|
1166 | if (!is_in_buffer[0]) |
1192 | if (!is_in_buffer[0]) |
1167 | strcpy(is_in_buffer, v); |
1193 | strcpy(is_in_buffer, v); |
1168 | level=5; |
1194 | level = 5; |
1169 | } |
1195 | } |
|
|
1196 | if (!strcmp(k, "is_in")) |
|
|
1197 | { |
|
|
1198 | if (!is_in_buffer[0]) |
|
|
1199 | strcpy(is_in_buffer, v); |
|
|
1200 | level = 5; |
|
|
1201 | } |
1170 | if (! strcmp(k,"is_in:country")) { |
1202 | if (!strcmp(k, "is_in:country")) |
|
|
1203 | { |
1171 | /** |
1204 | /** |
1172 | * Sometimes there is no is_in tag, only is_in:country. |
1205 | * Sometimes there is no is_in tag, only is_in:country. |
1173 | * I put this here so it can be overwritten by the previous if clause if there IS an is_in tag. |
1206 | * I put this here so it can be overwritten by the previous if clause if there IS an is_in tag. |
1174 | */ |
1207 | */ |
1175 | strcpy(is_in_buffer, v); |
1208 | strcpy(is_in_buffer, v); |
1176 | level=5; |
1209 | level = 5; |
1177 | } |
1210 | } |
1178 | if (! strcmp(k,"place_county")) { |
1211 | if (!strcmp(k, "place_county")) |
|
|
1212 | { |
1179 | /** |
1213 | /** |
1180 | * Ireland uses the place_county OSM tag to describe what county a town is in. |
1214 | * Ireland uses the place_county OSM tag to describe what county a town is in. |
1181 | * This would be equivalent to is_in: Town; Locality; Country |
1215 | * This would be equivalent to is_in: Town; Locality; Country |
1182 | * A real world example would be Node: Moycullen (52234625) |
1216 | * A real world example would be Node: Moycullen (52234625) |
1183 | * The tag is processed as Moycullen; Galway; Ireland |
1217 | * The tag is processed as Moycullen; Galway; Ireland |
1184 | * where Galway is the county |
1218 | * where Galway is the county |
1185 | */ |
1219 | */ |
1186 | strcpy(is_in_buffer, "Ireland"); |
1220 | strcpy(is_in_buffer, "Ireland"); |
1187 | attr_strings_save(attr_string_county_name, v); |
1221 | attr_strings_save(attr_string_county_name, v); |
1188 | level=5; |
1222 | level = 5; |
1189 | } |
1223 | } |
1190 | if (! strcmp(k,"gnis:ST_alpha")) { |
1224 | if (!strcmp(k, "gnis:ST_alpha")) |
|
|
1225 | { |
1191 | /* assume a gnis tag means it is part of the USA: |
1226 | /* assume a gnis tag means it is part of the USA: |
1192 | http://en.wikipedia.org/wiki/Geographic_Names_Information_System |
1227 | http://en.wikipedia.org/wiki/Geographic_Names_Information_System |
1193 | many US towns do not have is_in tags |
1228 | many US towns do not have is_in tags |
1194 | */ |
1229 | */ |
1195 | strcpy(is_in_buffer, "USA"); |
1230 | strcpy(is_in_buffer, "USA"); |
1196 | level=5; |
1231 | level = 5; |
1197 | } |
1232 | } |
1198 | if (! strcmp(k,"lanes")) { |
1233 | if (!strcmp(k, "lanes")) |
|
|
1234 | { |
1199 | level=5; |
1235 | level = 5; |
1200 | } |
1236 | } |
1201 | if (attr_debug_level >= level) { |
1237 | if (attr_debug_level >= level) |
|
|
1238 | { |
1202 | int bytes_left = sizeof( debug_attr_buffer ) - strlen(debug_attr_buffer) - 1; |
1239 | int bytes_left = sizeof(debug_attr_buffer) - strlen(debug_attr_buffer) - 1; |
1203 | if ( bytes_left > 0 ) |
1240 | if (bytes_left > 0) |
1204 | { |
1241 | { |
1205 | snprintf(debug_attr_buffer+strlen(debug_attr_buffer), bytes_left, " %s=%s", k, v); |
1242 | snprintf(debug_attr_buffer + strlen(debug_attr_buffer), bytes_left, " %s=%s", k, v); |
1206 | debug_attr_buffer[ sizeof( debug_attr_buffer ) - 1 ] = '\0'; |
1243 | debug_attr_buffer[sizeof(debug_attr_buffer) - 1] = '\0'; |
1207 | node_is_tagged=1; |
1244 | node_is_tagged = 1; |
1208 | } |
|
|
1209 | } |
1245 | } |
|
|
1246 | } |
|
|
1247 | |
1210 | if (level < 6) |
1248 | if (level < 6) |
|
|
1249 | { |
1211 | node_is_tagged=1; |
1250 | node_is_tagged = 1; |
|
|
1251 | } |
1212 | |
1252 | |
1213 | strcpy(buffer,"*=*"); |
1253 | strcpy(buffer, "*=*"); |
1214 | if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) |
1254 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1215 | attr_present[idx]=1; |
1255 | attr_present[idx] = 1; |
1216 | |
1256 | |
1217 | sprintf(buffer,"%s=*", k); |
1257 | sprintf(buffer, "%s=*", k); |
1218 | if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) |
1258 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1219 | attr_present[idx]=2; |
1259 | attr_present[idx] = 2; |
1220 | |
1260 | |
1221 | sprintf(buffer,"*=%s", v); |
1261 | sprintf(buffer, "*=%s", v); |
1222 | if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) |
1262 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1223 | attr_present[idx]=2; |
1263 | attr_present[idx] = 2; |
1224 | |
1264 | |
1225 | sprintf(buffer,"%s=%s", k, v); |
1265 | sprintf(buffer, "%s=%s", k, v); |
1226 | if ((idx=(int)(long)g_hash_table_lookup(attr_hash, buffer))) |
1266 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1227 | attr_present[idx]=4; |
1267 | attr_present[idx] = 4; |
1228 | } |
1268 | } |
1229 | |
1269 | |
1230 | int coord_count; |
1270 | int coord_count; |
1231 | |
1271 | |
1232 | static void |
|
|
1233 | extend_buffer(struct buffer *b) |
1272 | static void extend_buffer(struct buffer *b) |
1234 | { |
1273 | { |
1235 | b->malloced+=b->malloced_step; |
1274 | b->malloced += b->malloced_step; |
1236 | b->base=realloc(b->base, (size_t)b->malloced); |
1275 | b->base = realloc(b->base, (size_t) b->malloced); |
|
|
1276 | |
1237 | if (b->base == NULL) { |
1277 | if (b->base == NULL) |
|
|
1278 | { |
1238 | fprintf(stderr,"realloc of %d bytes failed\n",(int)b->malloced); |
1279 | fprintf(stderr, "realloc of "LONGLONG_FMT" bytes failed\n", (size_t) b->malloced); |
1239 | exit(1); |
1280 | exit(1); |
1240 | } |
1281 | } |
1241 | |
1282 | |
|
|
1283 | if (verbose_mode) fprintf(stderr, "extend_buffer: "LONGLONG_FMT" bytes\n", (size_t) b->malloced); |
1242 | } |
1284 | } |
1243 | |
1285 | |
1244 | int nodeid_last; |
1286 | osmid nodeid_last; |
1245 | GHashTable *node_hash,*way_hash; |
1287 | GHashTable *way_hash, *waytag_hash; |
|
|
1288 | cfuhash_table_t *way_hash_cfu = NULL; |
1246 | |
1289 | |
1247 | static void |
1290 | typedef struct dummy_cfuhash_entry { |
1248 | node_buffer_to_hash(void) |
1291 | long long key; |
|
|
1292 | int data; |
|
|
1293 | struct dummy_cfuhash_entry *next; |
|
|
1294 | } dummy_cfuhash_entry; |
|
|
1295 | |
|
|
1296 | static void node_buffer_to_hash(int local_thread_num) |
1249 | { |
1297 | { |
|
|
1298 | if (verbose_mode) |
|
|
1299 | fprintf(stderr, "node_buffer_to_hash t:%d nb->size:%lu\n", local_thread_num, node_buffer[local_thread_num].size); |
|
|
1300 | if (verbose_mode) |
|
|
1301 | fprintf(stderr, "node_buffer_to_hash t:%d nb->base:%lu\n", local_thread_num, node_buffer[local_thread_num].base); |
|
|
1302 | if (verbose_mode) |
|
|
1303 | fprintf(stderr, "node_buffer_to_hash t:%d nh:%p\n", local_thread_num, node_hash[local_thread_num]); |
|
|
1304 | |
|
|
1305 | int i = 0; |
1250 | int i,count=node_buffer.size/sizeof(struct node_item); |
1306 | int count2 = node_buffer[local_thread_num].size / sizeof(struct node_item); |
1251 | struct node_item *ni=(struct node_item *)node_buffer.base; |
1307 | struct node_item *ni = (struct node_item *) node_buffer[local_thread_num].base; |
|
|
1308 | |
|
|
1309 | fprintf(stderr, "[THREAD] #%d fill hash node: count=%d size=%d\n", local_thread_num, count2, sizeof(dummy_cfuhash_entry)); |
|
|
1310 | |
|
|
1311 | for (i = 0; i < count2; i++) |
|
|
1312 | { |
|
|
1313 | /* |
|
|
1314 | if (i % 5000) |
|
|
1315 | { |
|
|
1316 | fprintf(stderr, "thread #%d fill #%d\n", local_thread_num, i); |
|
|
1317 | } |
|
|
1318 | */ |
|
|
1319 | // g_hash_table_insert(node_hash[local_thread_num], (gpointer) (long) (ni[i].id), (gpointer) (long) i); |
|
|
1320 | //cfuhash_put(node_hash_cfu[local_thread_num], &(long long)ni[i].id, xxx); |
|
|
1321 | |
|
|
1322 | //fprintf(stderr, "node id:%lld i:%d\n", (long long)ni[i].id, i); |
|
|
1323 | cfuhash_put_data(node_hash_cfu[local_thread_num], (long long)ni[i].id, sizeof(long long), i, sizeof(int), NULL); |
|
|
1324 | } |
|
|
1325 | |
|
|
1326 | if (verbose_mode) |
|
|
1327 | { |
|
|
1328 | fprintf(stderr, "node_buffer_to_hash ready\n"); |
|
|
1329 | } |
|
|
1330 | } |
|
|
1331 | |
|
|
1332 | static void waytag_buffer_to_hash(void) |
|
|
1333 | { |
|
|
1334 | int i, count = waytag_buffer.size / sizeof(struct way_tag); |
|
|
1335 | struct way_tag *wt = (struct way_tag *) waytag_buffer.base; |
1252 | for (i = 0 ; i < count ; i++) |
1336 | for (i = 0; i < count; i++) |
|
|
1337 | { |
|
|
1338 | // fprintf(stderr, "waytag_hash insert:%lu %lu\n", (long) (wt[i].way_id), (long) i); |
1253 | g_hash_table_insert(node_hash, (gpointer)(long)(ni[i].id), (gpointer)(long)i); |
1339 | g_hash_table_insert(waytag_hash, (gpointer) (long) (wt[i].way_id), (gpointer) (long) i); |
|
|
1340 | } |
1254 | } |
1341 | } |
1255 | |
1342 | |
1256 | static struct node_item *ni; |
1343 | static struct node_item *ni; |
1257 | |
1344 | |
1258 | void |
1345 | void init_node_hash(int threads, int clear) |
1259 | flush_nodes(int final) |
|
|
1260 | { |
1346 | { |
|
|
1347 | int i; |
|
|
1348 | for (i = 0; i < threads; i++) |
|
|
1349 | { |
|
|
1350 | //if (clear) |
|
|
1351 | //{ |
|
|
1352 | //*node_hash[i] = NULL; |
|
|
1353 | //} |
|
|
1354 | //else |
|
|
1355 | //{ |
|
|
1356 | //*node_hash[i] = g_hash_table_new(NULL, NULL); |
|
|
1357 | //} |
|
|
1358 | node_hash_cfu[i] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
|
|
1359 | cfuhash_set_flag(node_hash_cfu[i], CFUHASH_FROZEN); |
|
|
1360 | } |
|
|
1361 | } |
|
|
1362 | |
|
|
1363 | void fill_hash_node(int local_thread_num) |
|
|
1364 | { |
|
|
1365 | //fprintf(stderr, "001t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1366 | |
|
|
1367 | if (verbose_mode) |
|
|
1368 | fprintf(stderr, "fill_hash_node - START\n"); |
|
|
1369 | //if (node_hash[local_thread_num]) |
|
|
1370 | if (node_hash_cfu[local_thread_num]) |
|
|
1371 | { |
|
|
1372 | //g_hash_table_destroy(node_hash[local_thread_num]); |
|
|
1373 | //node_hash[local_thread_num] = NULL; |
|
|
1374 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
|
|
1375 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
|
|
1376 | node_hash_cfu[local_thread_num] = NULL; |
|
|
1377 | } |
|
|
1378 | |
|
|
1379 | // node_hash[local_thread_num] = g_hash_table_new(NULL, NULL); |
|
|
1380 | node_hash_cfu[local_thread_num] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
|
|
1381 | cfuhash_set_flag(node_hash_cfu[local_thread_num], CFUHASH_FROZEN); |
|
|
1382 | |
|
|
1383 | //fprintf(stderr, "002t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1384 | node_buffer_to_hash(local_thread_num); |
|
|
1385 | //fprintf(stderr, "003t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1386 | if (verbose_mode) |
|
|
1387 | fprintf(stderr, "fill_hash_node - END\n"); |
|
|
1388 | } |
|
|
1389 | |
|
|
1390 | void flush_nodes(int final, int local_thread_num) |
|
|
1391 | { |
|
|
1392 | save_buffer("coords.tmp", &node_buffer[local_thread_num], slices * slice_size); |
|
|
1393 | //fprintf(stderr, "004t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1394 | |
|
|
1395 | if (verbose_mode) |
|
|
1396 | { |
1261 | fprintf(stderr,"flush_nodes %d\n",final); |
1397 | fprintf(stderr, "flush_nodes %d\n", final); |
1262 | save_buffer("coords.tmp",&node_buffer,slices*slice_size); |
1398 | } |
|
|
1399 | |
1263 | if (!final) { |
1400 | if (!final) |
1264 | node_buffer.size=0; |
1401 | { |
|
|
1402 | //fprintf(stderr, "005t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1403 | node_buffer[local_thread_num].size = 0; |
|
|
1404 | //fprintf(stderr, "006t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1405 | |
|
|
1406 | //if (node_hash[local_thread_num]) |
|
|
1407 | if (node_hash_cfu[local_thread_num]) |
|
|
1408 | { |
|
|
1409 | if (verbose_mode) fprintf(stderr,"node_hash size="LONGLONG_FMT"\n", g_hash_table_size (node_hash[local_thread_num])); |
|
|
1410 | //g_hash_table_destroy(node_hash[local_thread_num]); |
|
|
1411 | //node_hash[local_thread_num] = NULL; |
|
|
1412 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
|
|
1413 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
|
|
1414 | node_hash_cfu[local_thread_num] = NULL; |
1265 | } |
1415 | } |
|
|
1416 | } |
|
|
1417 | |
|
|
1418 | if (verbose_mode) fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer[local_thread_num].size); |
|
|
1419 | if (verbose_mode) fprintf(stderr,"node: node_buffer malloced="LONGLONG_FMT"\n", node_buffer[local_thread_num].malloced); |
|
|
1420 | //fprintf(stderr, "007t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
|
|
1421 | |
1266 | slices++; |
1422 | slices++; |
1267 | } |
1423 | } |
1268 | |
1424 | |
1269 | void |
1425 | double transform_to_geo_lat(int y) |
|
|
1426 | { |
|
|
1427 | double lat = navit_atan(exp(y / 6371000.0)) / M_PI * 360 - 90; |
|
|
1428 | return lat; |
|
|
1429 | } |
|
|
1430 | |
|
|
1431 | double transform_to_geo_lon(int x) |
|
|
1432 | { |
|
|
1433 | double lon = (x * 0.00000899322); |
|
|
1434 | return lon; |
|
|
1435 | } |
|
|
1436 | |
|
|
1437 | int transform_from_geo_lat(double lat) |
|
|
1438 | { |
|
|
1439 | /* slower */ |
|
|
1440 | // int ret = log(tan(M_PI_4 + lat * M_PI / 360)) * 6371000.0; |
|
|
1441 | //fprintf(stderr, "y=%d\n", ret); |
|
|
1442 | /* slower */ |
|
|
1443 | |
|
|
1444 | /* fast */ |
|
|
1445 | int ret = log(tan(M_PI_4 + lat * 0.008726646259971647884618)) * 6371000.0; // already calced (M_PI/360) |
|
|
1446 | /* fast */ |
|
|
1447 | |
|
|
1448 | return ret; |
|
|
1449 | } |
|
|
1450 | |
|
|
1451 | int transform_from_geo_lon(double lon) |
|
|
1452 | { |
|
|
1453 | /* slower */ |
|
|
1454 | //int ret = lon * 6371000.0 * M_PI / 180; |
|
|
1455 | // fprintf(stderr, "x=%d\n", ret); |
|
|
1456 | /* slower */ |
|
|
1457 | |
|
|
1458 | /* fast */ |
|
|
1459 | int ret = lon * 111194.9266445587373; // already calced (6371000.0*M_PI/180) |
|
|
1460 | /* fast */ |
|
|
1461 | |
|
|
1462 | return ret; |
|
|
1463 | } |
|
|
1464 | |
1270 | osm_add_node(osmid id, double lat, double lon) |
1465 | void osm_add_node(osmid id, double lat, double lon) |
1271 | { |
1466 | { |
1272 | in_node=1; |
1467 | in_node = 1; |
1273 | if (node_buffer.size + sizeof(struct node_item) > node_buffer.malloced) |
1468 | if (node_buffer[0].size + sizeof(struct node_item) > node_buffer[0].malloced) |
|
|
1469 | { |
1274 | extend_buffer(&node_buffer); |
1470 | extend_buffer(&node_buffer[0]); |
|
|
1471 | } |
1275 | attr_strings_clear(); |
1472 | attr_strings_clear(); |
1276 | node_is_tagged=0; |
1473 | node_is_tagged = 0; |
1277 | nodeid=id; |
1474 | nodeid = id; |
1278 | item.type=type_point_unkn; |
1475 | item.type = type_point_unkn; |
1279 | debug_attr_buffer[0]='\0'; |
1476 | debug_attr_buffer[0] = '\0'; |
1280 | is_in_buffer[0]='\0'; |
1477 | is_in_buffer[0] = '\0'; |
1281 | debug_attr_buffer[0]='\0'; |
1478 | debug_attr_buffer[0] = '\0'; |
1282 | osmid_attr.type=attr_osm_nodeid; |
1479 | osmid_attr.type = attr_osm_nodeid; |
1283 | osmid_attr.len=3; |
1480 | osmid_attr.len = 3; |
1284 | osmid_attr_value=id; |
1481 | osmid_attr_value = id; |
1285 | if (node_buffer.size + sizeof(struct node_item) > slice_size) { |
1482 | if (node_buffer[0].size + sizeof(struct node_item) > slice_size) |
|
|
1483 | { |
1286 | flush_nodes(0); |
1484 | flush_nodes(0, 0); |
1287 | } |
1485 | } |
1288 | ni=(struct node_item *)(node_buffer.base+node_buffer.size); |
1486 | ni = (struct node_item *) (node_buffer[0].base + node_buffer[0].size); |
1289 | ni->id=id; |
1487 | ni->id = id; |
1290 | ni->ref_node=0; |
1488 | ni->ref_node = 0; |
1291 | ni->ref_way=0; |
1489 | ni->ref_way = 0; |
1292 | ni->ref_ref=0; |
1490 | ni->ref_ref = 0; |
1293 | ni->dummy=0; |
1491 | ni->dummy = 0; |
|
|
1492 | |
|
|
1493 | /* slower */ |
1294 | ni->c.x=lon*6371000.0*M_PI/180; |
1494 | // ni->c.x = lon * 6371000.0 * M_PI / 180; |
1295 | ni->c.y=log(tan(M_PI_4+lat*M_PI/360))*6371000.0; |
1495 | // ni->c.y = log(tan(M_PI_4 + lat * M_PI / 360)) * 6371000.0; |
|
|
1496 | /* slower */ |
|
|
1497 | |
|
|
1498 | /* fast */ |
|
|
1499 | ni->c.x = lon * 111194.9266445587373; // already calced (6371000.0*M_PI/180) |
|
|
1500 | ni->c.y = log(tan(M_PI_4 + lat * 0.008726646259971647884618)) * 6371000.0; // already calced (M_PI/360) |
|
|
1501 | /* fast */ |
|
|
1502 | |
|
|
1503 | #ifdef MAPTOOL_USE_SQL |
|
|
1504 | |
|
|
1505 | if (sql_counter2 == 0) |
|
|
1506 | { |
|
|
1507 | sqlite3_exec(sql_handle002a, "BEGIN", 0, 0, 0); |
|
|
1508 | sqlite3_exec(sql_handle003a, "BEGIN", 0, 0, 0); |
|
|
1509 | sqlite3_exec(sql_handle002b, "BEGIN", 0, 0, 0); |
|
|
1510 | sqlite3_exec(sql_handle003b, "BEGIN", 0, 0, 0); |
|
|
1511 | } |
|
|
1512 | sql_counter2++; |
|
|
1513 | |
|
|
1514 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
1515 | if (nodeid % 2) |
|
|
1516 | { |
|
|
1517 | if ((nodeid & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
1518 | { |
|
|
1519 | sqlite3_bind_int64(stmt_node__2a, 1, nodeid); |
|
|
1520 | sqlite3_bind_double(stmt_node__2a, 2, lat); |
|
|
1521 | sqlite3_bind_double(stmt_node__2a, 3, lon); |
|
|
1522 | sqlite3_step(stmt_node__2a); |
|
|
1523 | sqlite3_reset(stmt_node__2a); |
|
|
1524 | } |
|
|
1525 | else |
|
|
1526 | { |
|
|
1527 | sqlite3_bind_int64(stmt_node__2b, 1, nodeid); |
|
|
1528 | sqlite3_bind_double(stmt_node__2b, 2, lat); |
|
|
1529 | sqlite3_bind_double(stmt_node__2b, 3, lon); |
|
|
1530 | sqlite3_step(stmt_node__2b); |
|
|
1531 | sqlite3_reset(stmt_node__2b); |
|
|
1532 | } |
|
|
1533 | } |
|
|
1534 | else |
|
|
1535 | { |
|
|
1536 | if ((nodeid & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
1537 | { |
|
|
1538 | #endif |
|
|
1539 | sqlite3_bind_int64(stmt_nodea, 1, nodeid); |
|
|
1540 | sqlite3_bind_double(stmt_nodea, 2, lat); |
|
|
1541 | sqlite3_bind_double(stmt_nodea, 3, lon); |
|
|
1542 | sqlite3_step(stmt_nodea); |
|
|
1543 | sqlite3_reset(stmt_nodea); |
|
|
1544 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
1545 | } |
|
|
1546 | else |
|
|
1547 | { |
|
|
1548 | sqlite3_bind_int64(stmt_nodeb, 1, nodeid); |
|
|
1549 | sqlite3_bind_double(stmt_nodeb, 2, lat); |
|
|
1550 | sqlite3_bind_double(stmt_nodeb, 3, lon); |
|
|
1551 | sqlite3_step(stmt_nodeb); |
|
|
1552 | sqlite3_reset(stmt_nodeb); |
|
|
1553 | } |
|
|
1554 | } |
|
|
1555 | #endif |
|
|
1556 | |
|
|
1557 | if (sql_counter2 > MAX_ROWS_WO_COMMIT) |
|
|
1558 | { |
|
|
1559 | sql_counter2 = 0; |
|
|
1560 | sqlite3_exec(sql_handle002a, "COMMIT", 0, 0, 0); |
|
|
1561 | sqlite3_exec(sql_handle003a, "COMMIT", 0, 0, 0); |
|
|
1562 | sqlite3_exec(sql_handle002b, "COMMIT", 0, 0, 0); |
|
|
1563 | sqlite3_exec(sql_handle003b, "COMMIT", 0, 0, 0); |
|
|
1564 | //fprintf(stderr, "SQL: COMMIT\n"); |
|
|
1565 | } |
|
|
1566 | |
|
|
1567 | #endif |
|
|
1568 | |
|
|
1569 | //fprintf(stderr,"node: %d %d\n", ni->c.x, ni->c.y); |
|
|
1570 | //fprintf(stderr,"node: %f %f\n", lat, lon); |
|
|
1571 | |
|
|
1572 | |
1296 | node_buffer.size+=sizeof(struct node_item); |
1573 | node_buffer[0].size += sizeof(struct node_item); |
|
|
1574 | //fprintf(stderr,"node: inc node_buffer by %d\n", sizeof(struct node_item)); |
|
|
1575 | //fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer.size); |
|
|
1576 | |
|
|
1577 | #if 0 |
1297 | if (! node_hash) { |
1578 | //if (!node_hash[0]) |
|
|
1579 | if (!node_hash_cfu[0]) |
|
|
1580 | { |
1298 | if (ni->id > nodeid_last) { |
1581 | if (ni->id > nodeid_last) |
|
|
1582 | { |
1299 | nodeid_last=ni->id; |
1583 | nodeid_last = ni->id; |
|
|
1584 | } |
1300 | } else { |
1585 | else |
|
|
1586 | { |
1301 | //fprintf(stderr,"INFO: Nodes out of sequence (new %d vs old %d), adding hash\n", ni->id, nodeid_last); |
1587 | //fprintf(stderr,"INFO: Nodes out of sequence (new %d vs old %d), adding hash\n", ni->id, nodeid_last); |
1302 | node_hash=g_hash_table_new(NULL, NULL); |
1588 | //node_hash[0] = g_hash_table_new(NULL, NULL); |
|
|
1589 | |
|
|
1590 | node_hash_cfu[0] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_OTHER); |
|
|
1591 | cfuhash_set_flag(node_hash_cfu[0], CFUHASH_FROZEN); |
|
|
1592 | |
1303 | node_buffer_to_hash(); |
1593 | node_buffer_to_hash(0); |
|
|
1594 | } |
1304 | } |
1595 | } |
1305 | } else |
|
|
1306 | if (!g_hash_table_lookup(node_hash, (gpointer)(long)(ni->id))) |
1596 | //else if (!g_hash_table_lookup(node_hash[0], (gpointer) (long) (ni->id))) |
|
|
1597 | // else if (!cfuhash_exists(node_hash_cfu[0], (long long) ni->id )) |
|
|
1598 | |
|
|
1599 | else if (!cfuhash_exists_data(node_hash_cfu[0], (long long) ni->id, sizeof(long long))) |
|
|
1600 | { |
1307 | g_hash_table_insert(node_hash, (gpointer)(long)(ni->id), (gpointer)(long)(ni-(struct node_item *)node_buffer.base)); |
1601 | //g_hash_table_insert(node_hash[0], (gpointer) (long) (ni->id), (gpointer) (long) (ni - (struct node_item *) node_buffer[0].base)); |
|
|
1602 | //cfuhash_put(node_hash_cfu[0], (gpointer)ni->id, (gpointer)(long) (ni - (struct node_item *) node_buffer[0].base) ); |
|
|
1603 | 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); |
|
|
1604 | |
|
|
1605 | } |
1308 | else { |
1606 | else |
|
|
1607 | { |
1309 | node_buffer.size-=sizeof(struct node_item); |
1608 | node_buffer[0].size -= sizeof(struct node_item); |
|
|
1609 | if (verbose_mode) |
|
|
1610 | fprintf(stderr, "node: Decr. node_buffer by %d\n", sizeof(struct node_item)); |
|
|
1611 | if (verbose_mode) fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer[0].size); |
1310 | nodeid=0; |
1612 | nodeid = 0; |
1311 | } |
1613 | } |
|
|
1614 | #endif |
1312 | |
1615 | |
1313 | } |
1616 | } |
1314 | |
1617 | |
1315 | void |
|
|
1316 | clear_node_item_buffer(void) |
1618 | void clear_node_item_buffer(void) |
1317 | { |
1619 | { |
1318 | int j,count=node_buffer.size/sizeof(struct node_item); |
1620 | int j, count = node_buffer[0].size / sizeof(struct node_item); |
1319 | struct node_item *ni=(struct node_item *)(node_buffer.base); |
1621 | struct node_item *ni = (struct node_item *) (node_buffer[0].base); |
1320 | for (j = 0 ; j < count ; j++) { |
1622 | for (j = 0; j < count; j++) |
|
|
1623 | { |
1321 | ni[j].ref_way=0; |
1624 | ni[j].ref_way = 0; |
1322 | } |
1625 | } |
1323 | } |
1626 | } |
1324 | |
1627 | |
1325 | static struct node_item * |
1628 | static struct node_item * |
1326 | node_item_get(int id) |
1629 | node_item_get_fast(osmid id, int local_thread_num) |
1327 | { |
1630 | { |
1328 | struct node_item *ni=(struct node_item *)(node_buffer.base); |
|
|
1329 | int count=node_buffer.size/sizeof(struct node_item); |
|
|
1330 | int interval=count/4; |
|
|
1331 | int p=count/2; |
|
|
1332 | if(interval==0) { |
|
|
1333 | // If fewer than 4 nodes defined so far set interval to 1 to |
|
|
1334 | // avoid infinite loop |
|
|
1335 | interval = 1; |
|
|
1336 | } |
|
|
1337 | if (node_hash) { |
|
|
1338 | int i; |
1631 | int i; |
1339 | i=(int)(long)(g_hash_table_lookup(node_hash, (gpointer)(long)id)); |
1632 | void *p_tmp; |
|
|
1633 | int rr; |
|
|
1634 | size_t data_size2 = sizeof(int); |
|
|
1635 | struct node_item *ni = (struct node_item *) (node_buffer[local_thread_num].base); |
|
|
1636 | |
|
|
1637 | //if (node_hash[local_thread_num]) |
|
|
1638 | if (node_hash_cfu[local_thread_num]) |
|
|
1639 | { |
|
|
1640 | //p_tmp = (gpointer)(g_hash_table_lookup(node_hash[local_thread_num], (gpointer) (long) id)); |
|
|
1641 | rr = cfuhash_get_data(node_hash_cfu[local_thread_num], (long long) id, sizeof(long long), &p_tmp, &data_size2); |
|
|
1642 | if (rr == 1) |
|
|
1643 | { |
|
|
1644 | //fprintf(stderr, "got key=%lld value=%d\n", (long long) id, p_tmp); |
|
|
1645 | i = p_tmp; |
1340 | return ni+i; |
1646 | return ni + i; |
1341 | } |
1647 | } |
1342 | if (ni[0].id > id) |
1648 | |
|
|
1649 | //if (p_tmp != NULL) |
|
|
1650 | //{ |
|
|
1651 | // // only if node is found in hash! |
|
|
1652 | // i = (int) (long) (p_tmp); |
|
|
1653 | // return ni + i; |
|
|
1654 | //} |
|
|
1655 | } |
1343 | return NULL; |
1656 | return NULL; |
1344 | if (ni[count-1].id < id) |
|
|
1345 | return NULL; |
|
|
1346 | while (ni[p].id != id) { |
|
|
1347 | #if 0 |
|
|
1348 | fprintf(stderr,"p=%d count=%d interval=%d id=%d ni[p].id=%d\n", p, count, interval, id, ni[p].id); |
|
|
1349 | #endif |
|
|
1350 | if (ni[p].id < id) { |
|
|
1351 | p+=interval; |
|
|
1352 | if (interval == 1) { |
|
|
1353 | if (p >= count) |
|
|
1354 | return NULL; |
|
|
1355 | if (ni[p].id > id) |
|
|
1356 | return NULL; |
|
|
1357 | } else { |
|
|
1358 | if (p >= count) |
|
|
1359 | p=count-1; |
|
|
1360 | } |
|
|
1361 | } else { |
|
|
1362 | p-=interval; |
|
|
1363 | if (interval == 1) { |
|
|
1364 | if (p < 0) |
|
|
1365 | return NULL; |
|
|
1366 | if (ni[p].id < id) |
|
|
1367 | return NULL; |
|
|
1368 | } else { |
|
|
1369 | if (p < 0) |
|
|
1370 | p=0; |
|
|
1371 | } |
|
|
1372 | } |
|
|
1373 | if (interval > 1) |
|
|
1374 | interval/=2; |
|
|
1375 | } |
|
|
1376 | return &ni[p]; |
|
|
1377 | } |
1657 | } |
1378 | |
1658 | |
1379 | static int |
|
|
1380 | load_node(FILE *coords, int p, struct node_item *ret) |
1659 | static int load_node(FILE *coords, int p, struct node_item *ret) |
1381 | { |
1660 | { |
1382 | fseek(coords, p*sizeof(struct node_item), SEEK_SET); |
1661 | fseek(coords, p * sizeof(struct node_item), SEEK_SET); |
1383 | if (fread(ret, sizeof(*ret), 1, coords) != 1) { |
1662 | if (fread(ret, sizeof(*ret), 1, coords) != 1) |
|
|
1663 | { |
1384 | fprintf(stderr,"read failed\n"); |
1664 | fprintf(stderr, "read failed\n"); |
1385 | return 0; |
1665 | return 0; |
1386 | } |
1666 | } |
1387 | return 1; |
1667 | return 1; |
1388 | } |
1668 | } |
1389 | |
1669 | |
1390 | static int |
1670 | static osmid first_node_of_current_way; |
1391 | node_item_get_from_file(FILE *coords, int id, struct node_item *ret) |
|
|
1392 | { |
|
|
1393 | int count; |
|
|
1394 | int interval; |
|
|
1395 | int p; |
|
|
1396 | if (node_hash) { |
|
|
1397 | int i; |
|
|
1398 | i=(int)(long)(g_hash_table_lookup(node_hash, (gpointer)(long)id)); |
|
|
1399 | fseek(coords, i*sizeof(*ret), SEEK_SET); |
|
|
1400 | if (fread(ret, sizeof(*ret), 1, coords) == 1) |
|
|
1401 | return 1; |
|
|
1402 | else |
|
|
1403 | return 0; |
|
|
1404 | } |
|
|
1405 | |
1671 | |
1406 | fseek(coords, 0, SEEK_END); |
|
|
1407 | count=ftell(coords)/sizeof(struct node_item); |
|
|
1408 | interval=count/4; |
|
|
1409 | p=count/2; |
|
|
1410 | if(interval==0) { |
|
|
1411 | // If fewer than 4 nodes defined so far set interval to 1 to |
|
|
1412 | // avoid infinite loop |
|
|
1413 | interval = 1; |
|
|
1414 | } |
|
|
1415 | if (!load_node(coords, p, ret)) |
|
|
1416 | return 0; |
|
|
1417 | for (;;) { |
|
|
1418 | if (ret->id == id) |
|
|
1419 | return 1; |
|
|
1420 | if (ret->id < id) { |
|
|
1421 | p+=interval; |
|
|
1422 | if (interval == 1) { |
|
|
1423 | if (p >= count) |
|
|
1424 | return 0; |
|
|
1425 | if (!load_node(coords, p, ret)) |
|
|
1426 | return 0; |
|
|
1427 | if (ret->id > id) |
|
|
1428 | return 0; |
|
|
1429 | } else { |
|
|
1430 | if (p >= count) |
|
|
1431 | p=count-1; |
|
|
1432 | if (!load_node(coords, p, ret)) |
|
|
1433 | return 0; |
|
|
1434 | } |
|
|
1435 | } else { |
|
|
1436 | p-=interval; |
|
|
1437 | if (interval == 1) { |
|
|
1438 | if (p < 0) |
|
|
1439 | return 0; |
|
|
1440 | if (!load_node(coords, p, ret)) |
|
|
1441 | return 0; |
|
|
1442 | if (ret->id < id) |
|
|
1443 | return 0; |
|
|
1444 | } else { |
|
|
1445 | if (p < 0) |
|
|
1446 | p=0; |
|
|
1447 | if (!load_node(coords, p, ret)) |
|
|
1448 | return 0; |
|
|
1449 | } |
|
|
1450 | } |
|
|
1451 | if (interval > 1) |
|
|
1452 | interval/=2; |
|
|
1453 | } |
|
|
1454 | } |
|
|
1455 | |
|
|
1456 | void |
|
|
1457 | osm_add_way(osmid id) |
1672 | void osm_add_way(osmid id) |
1458 | { |
1673 | { |
1459 | static int wayid_last; |
1674 | static osmid wayid_last; |
1460 | |
1675 | |
1461 | in_way=1; |
1676 | in_way = 1; |
1462 | wayid=id; |
1677 | wayid = id; |
1463 | coord_count=0; |
1678 | coord_count = 0; |
1464 | attr_strings_clear(); |
1679 | attr_strings_clear(); |
1465 | item.type=type_street_unkn; |
1680 | item.type = type_street_unkn; |
1466 | debug_attr_buffer[0]='\0'; |
1681 | debug_attr_buffer[0] = '\0'; |
1467 | maxspeed_attr_value=0; |
1682 | maxspeed_attr_value = 0; |
1468 | flags_attr_value = 0; |
1683 | flags_attr_value = 0; |
1469 | memset(flags, 0, sizeof(flags)); |
1684 | memset(flags, 0, sizeof(flags)); |
1470 | debug_attr_buffer[0]='\0'; |
1685 | debug_attr_buffer[0] = '\0'; |
1471 | osmid_attr_value=id; |
1686 | osmid_attr_value = id; |
1472 | if (wayid < wayid_last && !way_hash) { |
1687 | if (wayid < wayid_last && !way_hash_cfu) |
|
|
1688 | { |
|
|
1689 | if (verbose_mode) |
|
|
1690 | { |
1473 | fprintf(stderr,"INFO: Ways out of sequence (new %d vs old %d), adding hash\n", wayid, wayid_last); |
1691 | fprintf(stderr, "INFO: Ways out of sequence (new %d vs old %d), adding hash\n", wayid, wayid_last); |
|
|
1692 | } |
1474 | way_hash=g_hash_table_new(NULL, NULL); |
1693 | // way_hash = g_hash_table_new(NULL, NULL); |
|
|
1694 | way_hash_cfu = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_WAYS); |
|
|
1695 | cfuhash_set_flag(node_hash_cfu, CFUHASH_FROZEN); |
|
|
1696 | |
1475 | } |
1697 | } |
1476 | wayid_last=wayid; |
1698 | wayid_last = wayid; |
1477 | } |
1699 | } |
1478 | |
1700 | |
1479 | char relation_type[BUFFER_SIZE]; |
1701 | char relation_type[BUFFER_SIZE]; |
1480 | char iso_code[BUFFER_SIZE]; |
1702 | char iso_code[BUFFER_SIZE]; |
1481 | int admin_level; |
1703 | int admin_level; |
1482 | int boundary; |
1704 | int boundary; |
1483 | |
1705 | |
1484 | void |
|
|
1485 | osm_add_relation(osmid id) |
1706 | void osm_add_relation(osmid id) |
1486 | { |
1707 | { |
1487 | current_id=id; |
1708 | current_id = id; |
1488 | in_relation=1; |
1709 | in_relation = 1; |
1489 | debug_attr_buffer[0]='\0'; |
1710 | debug_attr_buffer[0] = '\0'; |
1490 | relation_type[0]='\0'; |
1711 | relation_type[0] = '\0'; |
1491 | iso_code[0]='\0'; |
1712 | iso_code[0] = '\0'; |
1492 | admin_level=-1; |
1713 | admin_level = -1; |
1493 | boundary=0; |
1714 | boundary = 0; |
1494 | item_bin_init(item_bin, type_none); |
1715 | item_bin_init(item_bin_2, type_none); |
1495 | item_bin_add_attr_longlong(item_bin, attr_osm_relationid, current_id); |
1716 | item_bin_add_attr_longlong(item_bin_2, attr_osm_relationid, current_id); |
1496 | } |
1717 | } |
1497 | |
1718 | |
1498 | static int |
|
|
1499 | country_id_from_iso2(char *iso) |
1719 | static int country_id_from_iso2(char *iso) |
1500 | { |
1720 | { |
1501 | int ret=0; |
1721 | int ret = 0; |
1502 | if (iso) |
1722 | if (iso) |
1503 | { |
1723 | { |
1504 | // make lowercase |
1724 | // make lowercase |
1505 | int i99; |
1725 | int i99; |
1506 | for (i99 = 0; iso[i99]; i99++) |
1726 | for (i99 = 0; iso[i99]; i99++) |
1507 | { |
1727 | { |
1508 | iso[i99] = tolower(iso[i99]); |
1728 | iso[i99] = tolower(iso[i99]); |
1509 | } |
1729 | } |
1510 | struct country_search *search; |
1730 | struct country_search *search; |
1511 | struct attr country_iso2,country_id; |
1731 | struct attr country_iso2, country_id; |
1512 | struct item *item; |
1732 | struct item *item; |
1513 | country_iso2.type=attr_country_iso2; |
1733 | country_iso2.type = attr_country_iso2; |
1514 | country_iso2.u.str=iso; |
1734 | country_iso2.u.str = iso; |
1515 | search=country_search_new(&country_iso2,0); |
1735 | search = country_search_new(&country_iso2, 0); |
1516 | if ((item=country_search_get_item(search)) && item_attr_get(item, attr_country_id, &country_id)) |
1736 | if ((item = country_search_get_item(search)) && item_attr_get(item, attr_country_id, &country_id)) |
1517 | { |
1737 | { |
1518 | ret=country_id.u.num; |
1738 | ret = country_id.u.num; |
1519 | if (debug_itembin(3)) |
1739 | if (debug_itembin(3)) |
1520 | { |
1740 | { |
1521 | fprintf(stderr,"country id(1)=%d\n", ret); |
1741 | fprintf(stderr, "country id(1)=%d\n", ret); |
1522 | } |
1742 | } |
1523 | } |
1743 | } |
1524 | else |
1744 | else |
1525 | { |
1745 | { |
1526 | if (debug_itembin(3)) |
1746 | if (debug_itembin(3)) |
1527 | { |
1747 | { |
1528 | fprintf(stderr,"country id(2)=%d\n", ret); |
1748 | fprintf(stderr, "country id(2)=%d\n", ret); |
1529 | } |
1749 | } |
1530 | } |
1750 | } |
1531 | country_search_destroy(search); |
1751 | country_search_destroy(search); |
1532 | } |
1752 | } |
1533 | return ret; |
1753 | return ret; |
… | |
… | |
1535 | |
1755 | |
1536 | static struct country_table * |
1756 | static struct country_table * |
1537 | country_from_countryid(int id) |
1757 | country_from_countryid(int id) |
1538 | { |
1758 | { |
1539 | int i; |
1759 | int i; |
1540 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) |
1760 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
1541 | { |
1761 | { |
1542 | //if (debug_itembin(3)) |
1762 | //if (debug_itembin(3)) |
1543 | //{ |
1763 | //{ |
1544 | // fprintf(stderr,"== country_from_countryid: %d ==\n", country_table[i].countryid); |
1764 | // fprintf(stderr,"== country_from_countryid: %d ==\n", country_table[i].countryid); |
1545 | //} |
1765 | //} |
… | |
… | |
1562 | country_from_iso2(char *iso) |
1782 | country_from_iso2(char *iso) |
1563 | { |
1783 | { |
1564 | return country_from_countryid(country_id_from_iso2(iso)); |
1784 | return country_from_countryid(country_id_from_iso2(iso)); |
1565 | } |
1785 | } |
1566 | |
1786 | |
1567 | |
1787 | static int get_relation_member(char *str, struct relation_member *memb) |
1568 | void |
|
|
1569 | osm_end_relation(struct maptool_osm *osm) |
|
|
1570 | { |
1788 | { |
1571 | in_relation=0; |
1789 | int len; |
1572 | if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) { |
1790 | sscanf(str,"%d:"LONGLONG_FMT":%n",&memb->type,&memb->id,&len); |
|
|
1791 | memb->role = str + len; |
|
|
1792 | return 1; |
|
|
1793 | } |
|
|
1794 | |
1573 | #if 0 |
1795 | #if 0 |
|
|
1796 | void report(io, markers, reporttriangles, reportneighbors, reportsegments, reportedges, reportnorms) |
|
|
1797 | struct triangulateio *io;int markers;int reporttriangles;int reportneighbors;int reportsegments;int reportedges;int reportnorms; |
|
|
1798 | { |
|
|
1799 | int i, j; |
|
|
1800 | |
|
|
1801 | for (i = 0; i < io->numberofpoints; i++) |
|
|
1802 | { |
|
|
1803 | fprintf(stderr, "Point %4d:", i); |
|
|
1804 | for (j = 0; j < 2; j++) |
|
|
1805 | { |
|
|
1806 | fprintf(stderr, " %.6g", io->pointlist[i * 2 + j]); |
|
|
1807 | } |
|
|
1808 | if (io->numberofpointattributes > 0) |
|
|
1809 | { |
|
|
1810 | fprintf(stderr, " attributes"); |
|
|
1811 | } |
|
|
1812 | for (j = 0; j < io->numberofpointattributes; j++) |
|
|
1813 | { |
|
|
1814 | fprintf(stderr, " %.6g", io->pointattributelist[i * io->numberofpointattributes + j]); |
|
|
1815 | } |
|
|
1816 | if (markers) |
|
|
1817 | { |
|
|
1818 | fprintf(stderr, " marker %d\n", io->pointmarkerlist[i]); |
|
|
1819 | } |
|
|
1820 | else |
|
|
1821 | { |
|
|
1822 | fprintf(stderr, "\n"); |
|
|
1823 | } |
|
|
1824 | } |
|
|
1825 | fprintf(stderr, "\n"); |
|
|
1826 | |
|
|
1827 | if (reporttriangles || reportneighbors) |
|
|
1828 | { |
|
|
1829 | for (i = 0; i < io->numberoftriangles; i++) |
|
|
1830 | { |
|
|
1831 | if (reporttriangles) |
|
|
1832 | { |
|
|
1833 | fprintf(stderr, "Triangle %4d points:", i); |
|
|
1834 | for (j = 0; j < io->numberofcorners; j++) |
|
|
1835 | { |
|
|
1836 | fprintf(stderr, " %4d", io->trianglelist[i * io->numberofcorners + j]); |
|
|
1837 | } |
|
|
1838 | if (io->numberoftriangleattributes > 0) |
|
|
1839 | { |
|
|
1840 | fprintf(stderr, " attributes"); |
|
|
1841 | } |
|
|
1842 | for (j = 0; j < io->numberoftriangleattributes; j++) |
|
|
1843 | { |
|
|
1844 | fprintf(stderr, " %.6g", io->triangleattributelist[i * io->numberoftriangleattributes + j]); |
|
|
1845 | } |
|
|
1846 | fprintf(stderr, "\n"); |
|
|
1847 | } |
|
|
1848 | if (reportneighbors) |
|
|
1849 | { |
|
|
1850 | fprintf(stderr, "Triangle %4d neighbors:", i); |
|
|
1851 | for (j = 0; j < 3; j++) |
|
|
1852 | { |
|
|
1853 | fprintf(stderr, " %4d", io->neighborlist[i * 3 + j]); |
|
|
1854 | } |
|
|
1855 | fprintf(stderr, "\n"); |
|
|
1856 | } |
|
|
1857 | } |
|
|
1858 | fprintf(stderr, "\n"); |
|
|
1859 | } |
|
|
1860 | |
|
|
1861 | if (reportsegments) |
|
|
1862 | { |
|
|
1863 | for (i = 0; i < io->numberofsegments; i++) |
|
|
1864 | { |
|
|
1865 | fprintf(stderr, "Segment %4d points:", i); |
|
|
1866 | for (j = 0; j < 2; j++) |
|
|
1867 | { |
|
|
1868 | fprintf(stderr, " %4d", io->segmentlist[i * 2 + j]); |
|
|
1869 | } |
|
|
1870 | if (markers) |
|
|
1871 | { |
|
|
1872 | fprintf(stderr, " marker %d\n", io->segmentmarkerlist[i]); |
|
|
1873 | } |
|
|
1874 | else |
|
|
1875 | { |
|
|
1876 | fprintf(stderr, "\n"); |
|
|
1877 | } |
|
|
1878 | } |
|
|
1879 | fprintf(stderr, "\n"); |
|
|
1880 | } |
|
|
1881 | |
|
|
1882 | if (reportedges) |
|
|
1883 | { |
|
|
1884 | for (i = 0; i < io->numberofedges; i++) |
|
|
1885 | { |
|
|
1886 | fprintf(stderr, "Edge %4d points:", i); |
|
|
1887 | for (j = 0; j < 2; j++) |
|
|
1888 | { |
|
|
1889 | fprintf(stderr, " %4d", io->edgelist[i * 2 + j]); |
|
|
1890 | } |
|
|
1891 | if (reportnorms && (io->edgelist[i * 2 + 1] == -1)) |
|
|
1892 | { |
|
|
1893 | for (j = 0; j < 2; j++) |
|
|
1894 | { |
|
|
1895 | fprintf(stderr, " %.6g", io->normlist[i * 2 + j]); |
|
|
1896 | } |
|
|
1897 | } |
|
|
1898 | if (markers) |
|
|
1899 | { |
|
|
1900 | fprintf(stderr, " marker %d\n", io->edgemarkerlist[i]); |
|
|
1901 | } |
|
|
1902 | else |
|
|
1903 | { |
|
|
1904 | fprintf(stderr, "\n"); |
|
|
1905 | } |
|
|
1906 | } |
|
|
1907 | fprintf(stderr, "\n"); |
|
|
1908 | } |
|
|
1909 | } |
|
|
1910 | |
|
|
1911 | #endif |
|
|
1912 | |
|
|
1913 | void get_lat_lon_for_node(long long nd, struct node_lat_lon *node); |
|
|
1914 | |
|
|
1915 | void get_lat_lon_way_first_node(long long way_id, struct node_lat_lon *node) |
|
|
1916 | { |
|
|
1917 | int rc2; |
|
|
1918 | sqlite3_stmt *st; |
|
|
1919 | long long nd = 0; |
|
|
1920 | |
|
|
1921 | |
|
|
1922 | node->valid = 0; |
|
|
1923 | |
|
|
1924 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
1925 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
|
|
1926 | { |
|
|
1927 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
1928 | { |
|
|
1929 | #endif |
|
|
1930 | st = stmt_sel001; |
|
|
1931 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
1932 | } |
|
|
1933 | else |
|
|
1934 | { |
|
|
1935 | st = stmt_sel001b; |
|
|
1936 | } |
|
|
1937 | } |
|
|
1938 | else |
|
|
1939 | { |
|
|
1940 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
1941 | { |
|
|
1942 | st = stmt_sel001__2; |
|
|
1943 | } |
|
|
1944 | else |
|
|
1945 | { |
|
|
1946 | st = stmt_sel001__2b; |
|
|
1947 | } |
|
|
1948 | } |
|
|
1949 | #endif |
|
|
1950 | sqlite3_bind_int64(st, 1, way_id); |
|
|
1951 | |
|
|
1952 | // execute the statement |
|
|
1953 | rc2 = sqlite3_step(st); |
|
|
1954 | switch (rc2) |
|
|
1955 | { |
|
|
1956 | case SQLITE_DONE: |
|
|
1957 | break; |
|
|
1958 | case SQLITE_ROW: |
|
|
1959 | nd = sqlite3_column_int64(st, 0); |
|
|
1960 | break; |
|
|
1961 | default: |
|
|
1962 | fprintf(stderr, "Error: %d\n", rc2); |
|
|
1963 | break; |
|
|
1964 | } |
|
|
1965 | sqlite3_reset(st); |
|
|
1966 | |
|
|
1967 | if (nd != 0) |
|
|
1968 | { |
|
|
1969 | get_lat_lon_for_node(nd, node); |
|
|
1970 | } |
|
|
1971 | } |
|
|
1972 | |
|
|
1973 | void get_lat_lon_for_node(long long nd, struct node_lat_lon *node) |
|
|
1974 | { |
|
|
1975 | int rc2; |
|
|
1976 | |
|
|
1977 | // now read the coords of this node |
|
|
1978 | node->valid = 0; |
|
|
1979 | |
|
|
1980 | #ifdef MAPTOOL_USE_SQL |
|
|
1981 | |
|
|
1982 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
1983 | if (nd % 2) |
|
|
1984 | { |
|
|
1985 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
1986 | { |
|
|
1987 | sqlite3_bind_int64(stmt_sel002__2a, 1, nd); |
|
|
1988 | } |
|
|
1989 | else |
|
|
1990 | { |
|
|
1991 | sqlite3_bind_int64(stmt_sel002__2b, 1, nd); |
|
|
1992 | } |
|
|
1993 | } |
|
|
1994 | else |
|
|
1995 | { |
|
|
1996 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
1997 | { |
|
|
1998 | #endif |
|
|
1999 | sqlite3_bind_int64(stmt_sel002a, 1, nd); |
|
|
2000 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2001 | } |
|
|
2002 | else |
|
|
2003 | { |
|
|
2004 | sqlite3_bind_int64(stmt_sel002b, 1, nd); |
|
|
2005 | } |
|
|
2006 | } |
|
|
2007 | #endif |
|
|
2008 | |
|
|
2009 | rc2 = 0; |
|
|
2010 | //do |
|
|
2011 | //{ |
|
|
2012 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2013 | if (nd % 2) |
|
|
2014 | { |
|
|
2015 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2016 | { |
|
|
2017 | rc2 = sqlite3_step(stmt_sel002__2a); |
|
|
2018 | } |
|
|
2019 | else |
|
|
2020 | { |
|
|
2021 | rc2 = sqlite3_step(stmt_sel002__2b); |
|
|
2022 | } |
|
|
2023 | } |
|
|
2024 | else |
|
|
2025 | { |
|
|
2026 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2027 | { |
|
|
2028 | #endif |
|
|
2029 | rc2 = sqlite3_step(stmt_sel002a); |
|
|
2030 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2031 | } |
|
|
2032 | else |
|
|
2033 | { |
|
|
2034 | rc2 = sqlite3_step(stmt_sel002b); |
|
|
2035 | } |
|
|
2036 | } |
|
|
2037 | #endif |
|
|
2038 | //cols2 = sqlite3_column_count(stmt_sel002); |
|
|
2039 | switch (rc2) |
|
|
2040 | { |
|
|
2041 | //case SQLITE_DONE: |
|
|
2042 | // break; |
|
|
2043 | case SQLITE_ROW: |
|
|
2044 | |
|
|
2045 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2046 | if (nd % 2) |
|
|
2047 | { |
|
|
2048 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2049 | { |
|
|
2050 | node->lat = (double) sqlite3_column_double(stmt_sel002__2a, 0); |
|
|
2051 | node->lon = (double) sqlite3_column_double(stmt_sel002__2a, 1); |
|
|
2052 | } |
|
|
2053 | else |
|
|
2054 | { |
|
|
2055 | node->lat = (double) sqlite3_column_double(stmt_sel002__2b, 0); |
|
|
2056 | node->lon = (double) sqlite3_column_double(stmt_sel002__2b, 1); |
|
|
2057 | } |
|
|
2058 | } |
|
|
2059 | else |
|
|
2060 | { |
|
|
2061 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2062 | { |
|
|
2063 | #endif |
|
|
2064 | node->lat = (double) sqlite3_column_double(stmt_sel002a, 0); |
|
|
2065 | node->lon = (double) sqlite3_column_double(stmt_sel002a, 1); |
|
|
2066 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2067 | } |
|
|
2068 | else |
|
|
2069 | { |
|
|
2070 | node->lat = (double) sqlite3_column_double(stmt_sel002b, 0); |
|
|
2071 | node->lon = (double) sqlite3_column_double(stmt_sel002b, 1); |
|
|
2072 | } |
|
|
2073 | } |
|
|
2074 | #endif |
|
|
2075 | node->valid = 1; |
|
|
2076 | break; |
|
|
2077 | default: |
|
|
2078 | fprintf(stderr, "get_lat_lon_for_node:SQL Error: %d nodeid:%lld\n", rc2, nd); |
|
|
2079 | break; |
|
|
2080 | } |
|
|
2081 | //} |
|
|
2082 | //while (rc2 == SQLITE_ROW); |
|
|
2083 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2084 | if (nd % 2) |
|
|
2085 | { |
|
|
2086 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2087 | { |
|
|
2088 | sqlite3_reset(stmt_sel002__2a); |
|
|
2089 | } |
|
|
2090 | else |
|
|
2091 | { |
|
|
2092 | sqlite3_reset(stmt_sel002__2b); |
|
|
2093 | } |
|
|
2094 | } |
|
|
2095 | else |
|
|
2096 | { |
|
|
2097 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2098 | { |
|
|
2099 | #endif |
|
|
2100 | sqlite3_reset(stmt_sel002a); |
|
|
2101 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2102 | } |
|
|
2103 | else |
|
|
2104 | { |
|
|
2105 | sqlite3_reset(stmt_sel002b); |
|
|
2106 | } |
|
|
2107 | } |
|
|
2108 | #endif |
|
|
2109 | #endif |
|
|
2110 | |
|
|
2111 | } |
|
|
2112 | |
|
|
2113 | void catch_signal(int param) |
|
|
2114 | { |
|
|
2115 | // fprintf (stderr, "Terminating program...\n"); |
|
|
2116 | fprintf(stderr, "****** got SIGSEGV ******\n"); |
|
|
2117 | THROW(MAPTOOL_00002_EXCEPTION); |
|
|
2118 | // exit(1); |
|
|
2119 | } |
|
|
2120 | |
|
|
2121 | struct way_and_endnodes |
|
|
2122 | { |
|
|
2123 | unsigned long long way_id; |
|
|
2124 | unsigned long long first_node_id; |
|
|
2125 | unsigned long long last_node_id; |
|
|
2126 | int reverse; |
|
|
2127 | int role; |
|
|
2128 | GList *nodes; |
|
|
2129 | }; |
|
|
2130 | |
|
|
2131 | // if same value -> 0 |
|
|
2132 | // otherwise -> 1 |
|
|
2133 | gint comp_func(gconstpointer item1, gconstpointer item2) |
|
|
2134 | { |
|
|
2135 | long long a; |
|
|
2136 | long long b; |
|
|
2137 | |
|
|
2138 | a = *((long long *) item1); |
|
|
2139 | b = *((long long *) item2); |
|
|
2140 | |
|
|
2141 | //fprintf(stderr," item1=%lld\n", a); |
|
|
2142 | //fprintf(stderr," item2=%lld\n", b); |
|
|
2143 | |
|
|
2144 | if (a == b) |
|
|
2145 | { |
|
|
2146 | return 0; |
|
|
2147 | } |
|
|
2148 | |
|
|
2149 | return 1; |
|
|
2150 | } |
|
|
2151 | |
|
|
2152 | // return 0 if item is not found in GList |
|
|
2153 | int glist_find_already_inside(GList* list, gconstpointer item) |
|
|
2154 | { |
|
|
2155 | if (g_list_find_custom(list, item, (GCompareFunc) comp_func) == NULL) |
|
|
2156 | { |
|
|
2157 | return 0; |
|
|
2158 | } |
|
|
2159 | return 1; |
|
|
2160 | } |
|
|
2161 | |
|
|
2162 | void osm_end_relation(struct maptool_osm *osm) |
|
|
2163 | { |
|
|
2164 | //fprintf(stderr, "XXX000\n"); |
|
|
2165 | |
|
|
2166 | struct item_bin *item_bin_tri; |
|
|
2167 | struct coord coord_tri; |
|
|
2168 | struct node_lat_lon node_coords; |
|
|
2169 | int i9; |
|
|
2170 | int j9; |
|
|
2171 | int tmp9; |
|
|
2172 | |
|
|
2173 | int save_relation = 0; |
|
|
2174 | int save_relations_other_method = 0; |
|
|
2175 | int tag_id = 1; |
|
|
2176 | char *str = NULL; |
|
|
2177 | int triangulate_not_done = 1; |
|
|
2178 | int problem = 0; |
|
|
2179 | struct relation_member memb; |
|
|
2180 | struct relation_member memb2; |
|
|
2181 | struct way_and_endnodes *way_nodes1; |
|
|
2182 | struct way_and_endnodes *way_nodes2; |
|
|
2183 | int found_new_way = 0; |
|
|
2184 | gpointer *gptr; |
|
|
2185 | int rc = 0; |
|
|
2186 | int rc2 = 0; |
|
|
2187 | int cols; |
|
|
2188 | int col; |
|
|
2189 | int first_node_found = 0; |
|
|
2190 | long long nd; |
|
|
2191 | long long first_nd; |
|
|
2192 | long long search_nd; |
|
|
2193 | long long *ndptr; |
|
|
2194 | |
|
|
2195 | /* |
|
|
2196 | long lat_nd; |
|
|
2197 | long lon_nd; |
|
|
2198 | */ |
|
|
2199 | |
|
|
2200 | double lat_nd; |
|
|
2201 | double lon_nd; |
|
|
2202 | |
|
|
2203 | int number_of_points_in_poly = 0; |
|
|
2204 | int number_of_points_current_poly = 0; |
|
|
2205 | int exception = 0; |
|
|
2206 | int role_ = 0; |
|
|
2207 | |
|
|
2208 | double factor = 10000000; |
|
|
2209 | |
|
|
2210 | // triangulate vars |
|
|
2211 | #if 0 |
|
|
2212 | struct triangulateio in, mid, out, vorout; |
|
|
2213 | #endif |
|
|
2214 | |
|
|
2215 | #ifdef MAPTOOL_TRIANGULATE |
|
|
2216 | GPtrArray *current_points; |
|
|
2217 | GPtrArray *current_hole; |
|
|
2218 | P2tCDT *cdt; |
|
|
2219 | P2trCDT *rcdt; |
|
|
2220 | P2trRefiner *refiner; |
|
|
2221 | P2tTrianglePtrArray triangles; |
|
|
2222 | gint refine_max_steps = 1000; |
|
|
2223 | double x; |
|
|
2224 | double y; |
|
|
2225 | int i; |
|
|
2226 | int j; |
|
|
2227 | GHashTable *point_map; |
|
|
2228 | P2trCDT *rmesh; |
|
|
2229 | #endif |
|
|
2230 | GList *all_holes; |
|
|
2231 | |
|
|
2232 | int count_of_outer_ways = 0; |
|
|
2233 | |
|
|
2234 | GList *unsorted_outer_ways = NULL; |
|
|
2235 | GList *unsorted_inner_ways = NULL; |
|
|
2236 | GList *sorted_outer_ways = NULL; |
|
|
2237 | GList *temp_nodes_list = NULL; |
|
|
2238 | all_holes = NULL; |
|
|
2239 | |
|
|
2240 | // -- save relations for riverbanks -- |
|
|
2241 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_tag, str))) |
|
|
2242 | { |
|
|
2243 | |
|
|
2244 | if (!strcmp(str, "waterway=riverbank")) |
|
|
2245 | { |
|
|
2246 | // fprintf(stderr,"k:v=%s\n", str); |
|
|
2247 | save_relation = 1; |
|
|
2248 | save_relations_other_method = 0; |
|
|
2249 | tag_id = 1; |
|
|
2250 | } |
|
|
2251 | else if (!strcmp(str, "natural=water")) |
|
|
2252 | { |
|
|
2253 | save_relation = 1; |
|
|
2254 | save_relations_other_method = 0; |
|
|
2255 | tag_id = 2; |
|
|
2256 | } |
|
|
2257 | /* |
|
|
2258 | else if (!strcmp(str, "water=river")) |
|
|
2259 | { |
|
|
2260 | save_relation = 1; |
|
|
2261 | tag_id = 3; |
|
|
2262 | } |
|
|
2263 | */ |
|
|
2264 | else if (!strcmp(str, "natural=lake")) |
|
|
2265 | { |
|
|
2266 | save_relation = 1; |
|
|
2267 | save_relations_other_method = 0; |
|
|
2268 | tag_id = 4; |
|
|
2269 | } |
|
|
2270 | else if (!strcmp(str, "landuse=forest")) |
|
|
2271 | { |
|
|
2272 | // ------ DISABLED ------ |
|
|
2273 | // save_relation = 1; |
|
|
2274 | // save_relations_other_method = 1; |
|
|
2275 | // tag_id = 5; |
|
|
2276 | // ------ DISABLED ------ |
|
|
2277 | } |
|
|
2278 | else if (!strcmp(str, "natural=wood")) |
|
|
2279 | { |
|
|
2280 | // ------ DISABLED ------ |
|
|
2281 | // save_relation = 1; |
|
|
2282 | // save_relations_other_method = 1; |
|
|
2283 | // tag_id = 6; |
|
|
2284 | // ------ DISABLED ------ |
|
|
2285 | } |
|
|
2286 | else if (!strcmp(str, "building=yes")) |
|
|
2287 | { |
|
|
2288 | save_relation = 1; |
|
|
2289 | save_relations_other_method = 0; |
|
|
2290 | tag_id = 9; |
|
|
2291 | //fprintf(stderr,"k:v=%s id=%lld\n", str, current_id); |
|
|
2292 | } |
|
|
2293 | |
|
|
2294 | } |
|
|
2295 | |
|
|
2296 | if (save_relation == 1) |
|
|
2297 | { |
|
|
2298 | |
|
|
2299 | #ifdef MAPTOOL_TRIANGULATE |
|
|
2300 | |
|
|
2301 | if (save_relations_other_method == 0) |
|
|
2302 | { |
|
|
2303 | |
|
|
2304 | //fprintf(stderr, "START relation id=%lld tag=%d\n", current_id, tag_id); |
|
|
2305 | |
|
|
2306 | sqlite3_stmt *st; |
|
|
2307 | |
|
|
2308 | triangulate_not_done = 1; |
|
|
2309 | str = NULL; |
|
|
2310 | number_of_points_in_poly = 0; |
|
|
2311 | count_of_outer_ways = 0; |
|
|
2312 | //fprintf(stderr, "\n\n----------START---------\n"); |
|
|
2313 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
2314 | { |
|
|
2315 | if (get_relation_member(str, &memb)) |
|
|
2316 | { |
|
|
2317 | if (!strcmp(memb.role, "outer")) |
|
|
2318 | { |
|
|
2319 | if (memb.type == 2) |
|
|
2320 | { |
|
|
2321 | count_of_outer_ways++; |
|
|
2322 | } |
|
|
2323 | } |
|
|
2324 | } |
|
|
2325 | } |
|
|
2326 | //fprintf(stderr, "number of outer ways: %d\n", count_of_outer_ways); |
|
|
2327 | |
|
|
2328 | str = NULL; |
|
|
2329 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
2330 | { |
|
|
2331 | if (get_relation_member(str, &memb)) |
|
|
2332 | { |
|
|
2333 | role_=0; |
|
|
2334 | if (!strcmp(memb.role, "outer")) |
|
|
2335 | { |
|
|
2336 | role_=1; |
|
|
2337 | //fprintf(stderr, "1:role=%s id=%lld\n", memb.role, memb.id); |
|
|
2338 | } |
|
|
2339 | else if (!strcmp(memb.role, "inner")) |
|
|
2340 | { |
|
|
2341 | role_=2; |
|
|
2342 | //fprintf(stderr, "2:role=%s id=%lld\n", memb.role, memb.id); |
|
|
2343 | } |
|
|
2344 | |
|
|
2345 | if ((memb.type == 2) && ( (role_ == 1)||(role_ == 2) )) // use "outer" and "inner" ways |
|
|
2346 | { |
|
|
2347 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
|
|
2348 | way_nodes1->nodes = NULL; |
|
|
2349 | // get id for last and first nodes |
|
|
2350 | |
|
|
2351 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
2352 | if ((memb.id & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
|
|
2353 | { |
|
|
2354 | if ((memb.id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
2355 | { |
|
|
2356 | #endif |
|
|
2357 | st = stmt_sel001; |
|
|
2358 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
2359 | } |
|
|
2360 | else |
|
|
2361 | { |
|
|
2362 | st = stmt_sel001b; |
|
|
2363 | } |
|
|
2364 | } |
|
|
2365 | else |
|
|
2366 | { |
|
|
2367 | if ((memb.id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
2368 | { |
|
|
2369 | st = stmt_sel001__2; |
|
|
2370 | } |
|
|
2371 | else |
|
|
2372 | { |
|
|
2373 | st = stmt_sel001__2b; |
|
|
2374 | } |
|
|
2375 | } |
|
|
2376 | #endif |
|
|
2377 | sqlite3_bind_int64(st, 1, memb.id); |
|
|
2378 | |
|
|
2379 | first_node_found = 0; |
|
|
2380 | way_nodes1->first_node_id = 0; |
|
|
2381 | nd = 0; |
|
|
2382 | number_of_points_current_poly = 0; |
|
|
2383 | // execute the statement |
|
|
2384 | do |
|
|
2385 | { |
|
|
2386 | rc = sqlite3_step(st); |
|
|
2387 | // cols = sqlite3_column_count(st); |
|
|
2388 | switch (rc) |
|
|
2389 | { |
|
|
2390 | case SQLITE_DONE: |
|
|
2391 | break; |
|
|
2392 | case SQLITE_ROW: |
|
|
2393 | nd = sqlite3_column_int64(st, 0); |
|
|
2394 | number_of_points_current_poly++; |
|
|
2395 | //fprintf(stderr, "------ %s = %d\n", sqlite3_column_name(st, 0), nd ? nd : "NULL"); |
|
|
2396 | if (first_node_found == 0) |
|
|
2397 | { |
|
|
2398 | way_nodes1->first_node_id = nd; |
|
|
2399 | way_nodes1->role = role_; |
|
|
2400 | first_node_found = 1; |
|
|
2401 | //fprintf(stderr, "------ first node found\n"); |
|
|
2402 | } |
|
|
2403 | ndptr = malloc(sizeof(long long)); |
|
|
2404 | *ndptr = nd; |
|
|
2405 | way_nodes1->nodes = g_list_append(way_nodes1->nodes, ndptr); |
|
|
2406 | break; |
|
|
2407 | default: |
|
|
2408 | fprintf(stderr, "Error: %d\n", rc); |
|
|
2409 | break; |
|
|
2410 | } |
|
|
2411 | } |
|
|
2412 | while (rc == SQLITE_ROW); |
|
|
2413 | |
|
|
2414 | // dont count the last node of each way |
|
|
2415 | number_of_points_current_poly--; |
|
|
2416 | |
|
|
2417 | sqlite3_reset(st); |
|
|
2418 | |
|
|
2419 | way_nodes1->last_node_id = nd; |
|
|
2420 | way_nodes1->way_id = memb.id; |
|
|
2421 | |
|
|
2422 | if (way_nodes1->last_node_id == 0) |
|
|
2423 | { |
|
|
2424 | if (way_nodes1->nodes) |
|
|
2425 | { |
|
|
2426 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2427 | while (way_nodes1->nodes) |
|
|
2428 | { |
|
|
2429 | ndptr = way_nodes1->nodes->data; |
|
|
2430 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
2431 | g_free(ndptr); |
|
|
2432 | ndptr = NULL; |
|
|
2433 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
2434 | } |
|
|
2435 | } |
|
|
2436 | g_free(way_nodes1); |
|
|
2437 | } |
|
|
2438 | else if (way_nodes1->last_node_id == way_nodes1->first_node_id) |
|
|
2439 | { |
|
|
2440 | //fprintf(stderr, "ln id=%lld, fn id=%lld\n", way_nodes1->last_node_id, way_nodes1->first_node_id); |
|
|
2441 | |
|
|
2442 | if (way_nodes1->nodes) |
|
|
2443 | { |
|
|
2444 | if (role_ == 2) |
|
|
2445 | { |
|
|
2446 | //fprintf(stderr, "role=2\n"); |
|
|
2447 | unsorted_inner_ways = g_list_append(unsorted_inner_ways, way_nodes1); |
|
|
2448 | } |
|
|
2449 | else if (role_ == 1) |
|
|
2450 | { |
|
|
2451 | if (count_of_outer_ways == 1) |
|
|
2452 | { |
|
|
2453 | // we have only 1 outer way, it must be a closed loop. add it |
|
|
2454 | unsorted_outer_ways = g_list_append(unsorted_outer_ways, way_nodes1); |
|
|
2455 | number_of_points_in_poly = number_of_points_in_poly + number_of_points_current_poly; |
|
|
2456 | //fprintf(stderr, "w,sn,en %lld,%lld,%lld\n", way_nodes1->way_id, way_nodes1->first_node_id, way_nodes1->last_node_id); |
|
|
2457 | //fprintf(stderr, "num points=%d\n", number_of_points_current_poly); |
|
|
2458 | //fprintf(stderr, "SUM points=%d\n", number_of_points_in_poly); |
|
|
2459 | } |
|
|
2460 | else |
|
|
2461 | { |
|
|
2462 | // we have an outer way that is a loop (remove it) |
|
|
2463 | //fprintf(stderr, "remove node ... start\n"); |
|
|
2464 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2465 | while (way_nodes1->nodes) |
|
|
2466 | { |
|
|
2467 | //fprintf(stderr, "remove node\n"); |
|
|
2468 | ndptr = way_nodes1->nodes->data; |
|
|
2469 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
2470 | g_free(ndptr); |
|
|
2471 | ndptr = NULL; |
|
|
2472 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
2473 | } |
|
|
2474 | g_free(way_nodes1); |
|
|
2475 | //fprintf(stderr, "remove node ... ready\n"); |
|
|
2476 | } |
|
|
2477 | } |
|
|
2478 | } |
|
|
2479 | } |
|
|
2480 | else |
|
|
2481 | { |
|
|
2482 | if (role_ == 1) |
|
|
2483 | { |
|
|
2484 | unsorted_outer_ways = g_list_append(unsorted_outer_ways, way_nodes1); |
|
|
2485 | number_of_points_in_poly = number_of_points_in_poly + number_of_points_current_poly; |
|
|
2486 | } |
|
|
2487 | //fprintf(stderr, "w,sn,en %lld,%lld,%lld\n", way_nodes1->way_id, way_nodes1->first_node_id, way_nodes1->last_node_id); |
|
|
2488 | //fprintf(stderr, "num points=%d\n", number_of_points_current_poly); |
|
|
2489 | //fprintf(stderr, "SUM points=%d\n", number_of_points_in_poly); |
|
|
2490 | } |
|
|
2491 | } |
|
|
2492 | } |
|
|
2493 | } |
|
|
2494 | |
|
|
2495 | // now sort ways to have a linked polygon |
|
|
2496 | if (unsorted_outer_ways) |
|
|
2497 | { |
|
|
2498 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
2499 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
|
|
2500 | way_nodes2 = (struct way_and_endnodes *) unsorted_outer_ways->data; |
|
|
2501 | way_nodes1->way_id = way_nodes2->way_id; |
|
|
2502 | //fprintf(stderr, "(START)way id=%llu\n", way_nodes1->way_id); |
|
|
2503 | way_nodes1->last_node_id = way_nodes2->last_node_id; |
|
|
2504 | way_nodes1->first_node_id = way_nodes2->first_node_id; |
|
|
2505 | // only copy over the pointer to the node list!! |
|
|
2506 | way_nodes1->nodes = way_nodes2->nodes; |
|
|
2507 | // first node is always in the right order |
|
|
2508 | way_nodes1->reverse = 0; |
|
|
2509 | |
|
|
2510 | gptr = unsorted_outer_ways->data; |
|
|
2511 | sorted_outer_ways = g_list_append(sorted_outer_ways, way_nodes1); |
|
|
2512 | // save the very first node of the poly |
|
|
2513 | first_nd = way_nodes1->first_node_id; |
|
|
2514 | // what node we want to find |
|
|
2515 | search_nd = way_nodes1->last_node_id; |
|
|
2516 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, gptr); |
|
|
2517 | g_free(gptr); |
|
|
2518 | gptr = NULL; |
|
|
2519 | |
|
|
2520 | //fprintf(stderr,"remaining=%d sorted=%d\n", g_list_length(unsorted_outer_ways), g_list_length(sorted_outer_ways)); |
|
|
2521 | } |
|
|
2522 | |
|
|
2523 | if (unsorted_outer_ways) |
|
|
2524 | { |
|
|
2525 | |
|
|
2526 | problem = 0; |
|
|
2527 | //fprintf(stderr, "start length unsorted_outer_ways=%d\n", g_list_length(unsorted_outer_ways)); |
|
|
2528 | |
|
|
2529 | while ((g_list_length(unsorted_outer_ways) > 0) && (problem == 0)) |
|
|
2530 | { |
|
|
2531 | //fprintf(stderr, "loop thru remaining ways 1\n"); |
|
|
2532 | |
|
|
2533 | // loop thru all the remaining ways |
|
|
2534 | found_new_way = 0; |
|
|
2535 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
2536 | while (unsorted_outer_ways) |
|
|
2537 | { |
|
|
2538 | //fprintf(stderr, "loop thru remaining ways 2 search=%lld\n", search_nd); |
|
|
2539 | |
|
|
2540 | if (unsorted_outer_ways->data) |
|
|
2541 | { |
|
|
2542 | way_nodes2 = (struct way_and_endnodes *) unsorted_outer_ways->data; |
|
|
2543 | if (way_nodes2->first_node_id == search_nd) |
|
|
2544 | { |
|
|
2545 | |
|
|
2546 | if (way_nodes2->last_node_id == first_nd) |
|
|
2547 | { |
|
|
2548 | if (g_list_length(unsorted_outer_ways) > 1) |
|
|
2549 | { |
|
|
2550 | // we have closed the poly, but there are still "ways" left |
|
|
2551 | // sounds broken |
|
|
2552 | problem = 1; |
|
|
2553 | break; |
|
|
2554 | } |
|
|
2555 | } |
|
|
2556 | |
|
|
2557 | // what node we want to find |
|
|
2558 | search_nd = way_nodes2->last_node_id; |
|
|
2559 | |
|
|
2560 | // now move the way from unsorted to sorted list |
|
|
2561 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
|
|
2562 | way_nodes1->way_id = way_nodes2->way_id; |
|
|
2563 | |
|
|
2564 | // ok next way found |
|
|
2565 | //fprintf(stderr, "(F)way id=%llu\n", way_nodes1->way_id); |
|
|
2566 | //fprintf(stderr, "now search id=%llu\n", search_nd); |
|
|
2567 | |
|
|
2568 | way_nodes1->last_node_id = way_nodes2->last_node_id; |
|
|
2569 | way_nodes1->first_node_id = way_nodes2->first_node_id; |
|
|
2570 | // only copy over the pointer to the node list!! |
|
|
2571 | way_nodes1->nodes = way_nodes2->nodes; |
|
|
2572 | // first node is always in the right order |
|
|
2573 | way_nodes1->reverse = 0; |
|
|
2574 | sorted_outer_ways = g_list_append(sorted_outer_ways, way_nodes1); |
|
|
2575 | if (unsorted_outer_ways) |
|
|
2576 | { |
|
|
2577 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
2578 | } |
|
|
2579 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, way_nodes2); |
|
|
2580 | g_free(way_nodes2); |
|
|
2581 | way_nodes2 = NULL; |
|
|
2582 | |
|
|
2583 | found_new_way = 1; |
|
|
2584 | //fprintf(stderr, "length unsorted_outer_ways=%d\n", g_list_length(unsorted_outer_ways)); |
|
|
2585 | break; |
|
|
2586 | } |
|
|
2587 | else if (way_nodes2->last_node_id == search_nd) |
|
|
2588 | { |
|
|
2589 | if (way_nodes2->first_node_id == first_nd) |
|
|
2590 | { |
|
|
2591 | if (g_list_length(unsorted_outer_ways) > 1) |
|
|
2592 | { |
|
|
2593 | // we have closed the poly, but there are still "ways" left |
|
|
2594 | // sounds broken |
|
|
2595 | problem = 1; |
|
|
2596 | break; |
|
|
2597 | } |
|
|
2598 | } |
|
|
2599 | |
|
|
2600 | // what node we want to find |
|
|
2601 | search_nd = way_nodes2->first_node_id; |
|
|
2602 | |
|
|
2603 | // now move the way from unsorted to sorted list |
|
|
2604 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
|
|
2605 | way_nodes1->way_id = way_nodes2->way_id; |
|
|
2606 | |
|
|
2607 | // ok next way found |
|
|
2608 | //fprintf(stderr, "(R)way id=%llu\n", way_nodes1->way_id); |
|
|
2609 | //fprintf(stderr, "now search id=%llu\n", search_nd); |
|
|
2610 | |
|
|
2611 | way_nodes1->first_node_id = way_nodes2->last_node_id; |
|
|
2612 | way_nodes1->last_node_id = way_nodes2->first_node_id; |
|
|
2613 | // only copy over the pointer to the node list!! |
|
|
2614 | way_nodes1->nodes = way_nodes2->nodes; |
|
|
2615 | way_nodes1->nodes = g_list_reverse(way_nodes1->nodes); |
|
|
2616 | // first node is always in the right order |
|
|
2617 | way_nodes1->reverse = 1; |
|
|
2618 | sorted_outer_ways = g_list_append(sorted_outer_ways, way_nodes1); |
|
|
2619 | if (unsorted_outer_ways) |
|
|
2620 | { |
|
|
2621 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
2622 | } |
|
|
2623 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, way_nodes2); |
|
|
2624 | g_free(way_nodes2); |
|
|
2625 | way_nodes2 = NULL; |
|
|
2626 | |
|
|
2627 | found_new_way = 1; |
|
|
2628 | //fprintf(stderr, "length unsorted_outer_ways=%d\n", g_list_length(unsorted_outer_ways)); |
|
|
2629 | break; |
|
|
2630 | } |
|
|
2631 | } |
|
|
2632 | unsorted_outer_ways = g_list_next(unsorted_outer_ways); |
|
|
2633 | } |
|
|
2634 | //fprintf(stderr, "after while loop 2\n"); |
|
|
2635 | |
|
|
2636 | if (found_new_way == 0) |
|
|
2637 | { |
|
|
2638 | // some problem with this multipolygon |
|
|
2639 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2640 | fprintf(stderr, "some problem with this multipolygon\n"); |
|
|
2641 | triangulate_not_done = 1; |
|
|
2642 | problem = 1; |
|
|
2643 | break; |
|
|
2644 | } |
|
|
2645 | } |
|
|
2646 | //fprintf(stderr, "after while loop 1\n"); |
|
|
2647 | |
|
|
2648 | } |
|
|
2649 | |
|
|
2650 | // now at last check if very first node matches the last found node |
|
|
2651 | // and less than xxx 1000 points in polygon |
|
|
2652 | // if ((search_nd == first_nd) && (number_of_points_in_poly > 2) && (number_of_points_in_poly < 1000)) |
|
|
2653 | if ((problem == 0) && ((search_nd == first_nd) && (number_of_points_in_poly > 2) && (number_of_points_in_poly < 30000))) |
|
|
2654 | { |
|
|
2655 | |
|
|
2656 | //fprintf(stderr, "in relation id=%lld\n", current_id); |
|
|
2657 | |
|
|
2658 | point_map = g_hash_table_new(g_direct_hash, g_direct_equal); |
|
|
2659 | current_points = g_ptr_array_new(); |
|
|
2660 | |
|
|
2661 | number_of_points_in_poly = 0; |
|
|
2662 | |
|
|
2663 | sorted_outer_ways = g_list_first(sorted_outer_ways); |
|
|
2664 | while (sorted_outer_ways) |
|
|
2665 | { |
|
|
2666 | if (sorted_outer_ways->data) |
|
|
2667 | { |
|
|
2668 | way_nodes1 = (struct way_and_endnodes *) sorted_outer_ways->data; |
|
|
2669 | // now read all the nodes of this way |
|
|
2670 | //**alread in GList** //sqlite3_bind_int64(stmt_sel001, 1, way_nodes1->way_id); |
|
|
2671 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2672 | first_node_found = 0; |
|
|
2673 | while (way_nodes1->nodes) |
|
|
2674 | { |
|
|
2675 | ndptr = (long long *) way_nodes1->nodes->data; |
|
|
2676 | nd = *ndptr; |
|
|
2677 | |
|
|
2678 | get_lat_lon_for_node(nd, &node_coords); |
|
|
2679 | if (node_coords.valid == 1) |
|
|
2680 | { |
|
|
2681 | // lat |
|
|
2682 | lat_nd = node_coords.lat; |
|
|
2683 | // lon |
|
|
2684 | lon_nd = node_coords.lon; |
|
|
2685 | |
|
|
2686 | if (first_node_found == 0) |
|
|
2687 | { |
|
|
2688 | first_node_found = 1; |
|
|
2689 | } |
|
|
2690 | else |
|
|
2691 | { |
|
|
2692 | y = lat_nd * factor; |
|
|
2693 | x = lon_nd * factor; |
|
|
2694 | |
|
|
2695 | // ------ ok use this node and coords for triangulation ---- |
|
|
2696 | //fprintf(stderr, "nd,lat,lon %lld,%f,%f\n", nd,lat_nd,lon_nd); |
|
|
2697 | //fprintf(stderr, "x,y %f,%f\n", x, y); |
|
|
2698 | |
|
|
2699 | g_ptr_array_add(current_points, p2t_point_new_dd(x, y)); |
|
|
2700 | } |
|
|
2701 | } |
|
|
2702 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
2703 | } |
|
|
2704 | } |
|
|
2705 | //sqlite3_reset(st); |
|
|
2706 | |
|
|
2707 | sorted_outer_ways = g_list_next(sorted_outer_ways); |
|
|
2708 | } |
|
|
2709 | |
|
|
2710 | //fprintf(stderr, "after sorting ways\n"); |
|
|
2711 | |
|
|
2712 | |
|
|
2713 | exception = 0; |
|
|
2714 | |
|
|
2715 | TRY |
|
|
2716 | { |
|
|
2717 | // catch SIGSEGV !! |
|
|
2718 | signal(SIGSEGV, catch_signal); |
|
|
2719 | |
|
|
2720 | // alternate signal stack ------------ |
|
|
2721 | //ss.ss_size = SIGSTKSZ; |
|
|
2722 | //ss.ss_sp = stack; |
|
|
2723 | //sa.sa_handler = catch_signal; |
|
|
2724 | //sa.sa_flags = SA_ONSTACK; |
|
|
2725 | //sigfillset(&sa.sa_mask); |
|
|
2726 | |
|
|
2727 | //sigaltstack(&ss, 0); |
|
|
2728 | //sigfillset(&sa.sa_mask); |
|
|
2729 | //sigaction(SIGSEGV, &sa, 0); |
|
|
2730 | // alternate signal stack ------------ |
|
|
2731 | |
|
|
2732 | // catch SIGSEGV !! |
|
|
2733 | |
|
|
2734 | //fprintf(stderr, "In Try Statement (p2t_cdt_new)\n"); |
|
|
2735 | cdt = p2t_cdt_new(current_points); |
|
|
2736 | //fprintf(stderr, "all OK (p2t_cdt_new)\n"); |
|
|
2737 | } |
|
|
2738 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
2739 | { |
|
|
2740 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2741 | fprintf(stderr, "Got Exception 1!\n"); |
|
|
2742 | exception = 1; |
|
|
2743 | } |
|
|
2744 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
2745 | { |
|
|
2746 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2747 | fprintf(stderr, "Got segv Exception 1!\n"); |
|
|
2748 | exception = 1; |
|
|
2749 | } |
|
|
2750 | FINALLY |
|
|
2751 | { |
|
|
2752 | // set default |
|
|
2753 | signal (SIGSEGV, SIG_DFL); |
|
|
2754 | // set default |
|
|
2755 | |
|
|
2756 | //fprintf(stderr, "finally\n"); |
|
|
2757 | } |
|
|
2758 | ETRY; |
|
|
2759 | |
|
|
2760 | //fprintf(stderr, "after cdt_new\n"); |
|
|
2761 | |
|
|
2762 | GList* save = unsorted_inner_ways; |
|
|
2763 | |
|
|
2764 | int no_holes = 0; |
|
|
2765 | if (exception == 0) |
|
|
2766 | { |
|
|
2767 | |
|
|
2768 | // first run a check loop |
|
|
2769 | int number_of_nodes_in_this_way; |
|
|
2770 | int cur_node_count_in_way; |
|
|
2771 | unsorted_inner_ways = g_list_first(unsorted_inner_ways); |
|
|
2772 | |
|
|
2773 | int number_of_nodes_in_this_way3 = g_list_length(unsorted_inner_ways); |
|
|
2774 | //fprintf(stderr, "uiw 001.0 c=%d\n", number_of_nodes_in_this_way3); |
|
|
2775 | while (unsorted_inner_ways) |
|
|
2776 | { |
|
|
2777 | if ((unsorted_inner_ways->data)&&(no_holes == 0)) |
|
|
2778 | { |
|
|
2779 | way_nodes1 = (struct way_and_endnodes *) unsorted_inner_ways->data; |
|
|
2780 | number_of_nodes_in_this_way = g_list_length(way_nodes1->nodes); |
|
|
2781 | // now read all the nodes of this "hole"-way |
|
|
2782 | GList* save0 = way_nodes1->nodes; |
|
|
2783 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2784 | first_node_found = 0; |
|
|
2785 | cur_node_count_in_way = 1; |
|
|
2786 | while (way_nodes1->nodes) |
|
|
2787 | { |
|
|
2788 | ndptr = (long long *) way_nodes1->nodes->data; |
|
|
2789 | // fprintf(stderr, "hole node:%lld\n", (long long)*ndptr); |
|
|
2790 | |
|
|
2791 | if (temp_nodes_list != NULL) |
|
|
2792 | { |
|
|
2793 | //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); |
|
|
2794 | // the last node should always be same as first node (for now we only support holes that dont span over multiple ways!) |
|
|
2795 | if (cur_node_count_in_way < number_of_nodes_in_this_way) |
|
|
2796 | { |
|
|
2797 | if (glist_find_already_inside(temp_nodes_list, ndptr) != 0) |
|
|
2798 | { |
|
|
2799 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2800 | fprintf(stderr, "problem with hole!\n"); |
|
|
2801 | no_holes = 1; |
|
|
2802 | break; |
|
|
2803 | } |
|
|
2804 | else |
|
|
2805 | { |
|
|
2806 | //fprintf(stderr, "hole check ok\n"); |
|
|
2807 | } |
|
|
2808 | } |
|
|
2809 | } |
|
|
2810 | |
|
|
2811 | temp_nodes_list = g_list_append(temp_nodes_list, ndptr); |
|
|
2812 | |
|
|
2813 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
2814 | cur_node_count_in_way++; |
|
|
2815 | } |
|
|
2816 | way_nodes1->nodes = save0; |
|
|
2817 | } |
|
|
2818 | unsorted_inner_ways = g_list_next(unsorted_inner_ways); |
|
|
2819 | } |
|
|
2820 | |
|
|
2821 | } |
|
|
2822 | |
|
|
2823 | unsorted_inner_ways = save; |
|
|
2824 | |
|
|
2825 | //fprintf(stderr, "ex=%d nohole=%d\n", exception, no_holes); |
|
|
2826 | |
|
|
2827 | |
|
|
2828 | |
|
|
2829 | if ((exception == 0) && (no_holes == 0)) |
|
|
2830 | { |
|
|
2831 | //fprintf(stderr, "uiw 000\n"); |
|
|
2832 | |
|
|
2833 | // now do the real loop |
|
|
2834 | int number_of_added_holes = 0; |
|
|
2835 | |
|
|
2836 | unsorted_inner_ways = g_list_first(unsorted_inner_ways); |
|
|
2837 | //int number_of_nodes_in_this_way4 = g_list_length(unsorted_inner_ways); |
|
|
2838 | //fprintf(stderr, "uiw 001.2 c=%d\n", number_of_nodes_in_this_way4); |
|
|
2839 | while (unsorted_inner_ways) |
|
|
2840 | { |
|
|
2841 | //fprintf(stderr, "uiw 001\n"); |
|
|
2842 | |
|
|
2843 | if (unsorted_inner_ways->data) |
|
|
2844 | { |
|
|
2845 | //fprintf(stderr, "uiw 002\n"); |
|
|
2846 | |
|
|
2847 | current_hole = g_ptr_array_new(); |
|
|
2848 | |
|
|
2849 | //fprintf(stderr, "uiw 003\n"); |
|
|
2850 | |
|
|
2851 | way_nodes1 = (struct way_and_endnodes *) unsorted_inner_ways->data; |
|
|
2852 | // now read all the nodes of this "hole"-way |
|
|
2853 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
2854 | first_node_found = 0; |
|
|
2855 | while (way_nodes1->nodes) |
|
|
2856 | { |
|
|
2857 | //fprintf(stderr, "uiw 004\n"); |
|
|
2858 | |
|
|
2859 | ndptr = (long long *) way_nodes1->nodes->data; |
|
|
2860 | nd = *ndptr; |
|
|
2861 | |
|
|
2862 | // now read the coords of this node |
|
|
2863 | |
|
|
2864 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2865 | if (nd % 2) |
|
|
2866 | { |
|
|
2867 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2868 | { |
|
|
2869 | sqlite3_bind_int64(stmt_sel002__2a, 1, nd); |
|
|
2870 | } |
|
|
2871 | else |
|
|
2872 | { |
|
|
2873 | sqlite3_bind_int64(stmt_sel002__2b, 1, nd); |
|
|
2874 | } |
|
|
2875 | } |
|
|
2876 | else |
|
|
2877 | { |
|
|
2878 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2879 | { |
|
|
2880 | #endif |
|
|
2881 | sqlite3_bind_int64(stmt_sel002a, 1, nd); |
|
|
2882 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2883 | } |
|
|
2884 | else |
|
|
2885 | { |
|
|
2886 | sqlite3_bind_int64(stmt_sel002b, 1, nd); |
|
|
2887 | } |
|
|
2888 | } |
|
|
2889 | #endif |
|
|
2890 | rc2 = 0; |
|
|
2891 | do |
|
|
2892 | { |
|
|
2893 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2894 | if (nd % 2) |
|
|
2895 | { |
|
|
2896 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2897 | { |
|
|
2898 | rc2 = sqlite3_step(stmt_sel002__2a); |
|
|
2899 | } |
|
|
2900 | else |
|
|
2901 | { |
|
|
2902 | rc2 = sqlite3_step(stmt_sel002__2b); |
|
|
2903 | } |
|
|
2904 | } |
|
|
2905 | else |
|
|
2906 | { |
|
|
2907 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2908 | { |
|
|
2909 | #endif |
|
|
2910 | rc2 = sqlite3_step(stmt_sel002a); |
|
|
2911 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2912 | } |
|
|
2913 | else |
|
|
2914 | { |
|
|
2915 | rc2 = sqlite3_step(stmt_sel002b); |
|
|
2916 | } |
|
|
2917 | } |
|
|
2918 | #endif |
|
|
2919 | |
|
|
2920 | switch (rc2) |
|
|
2921 | { |
|
|
2922 | case SQLITE_DONE: |
|
|
2923 | break; |
|
|
2924 | case SQLITE_ROW: |
|
|
2925 | |
|
|
2926 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2927 | if (nd % 2) |
|
|
2928 | { |
|
|
2929 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2930 | { |
|
|
2931 | lat_nd = (double) sqlite3_column_double(stmt_sel002__2a, 0); |
|
|
2932 | lon_nd = (double) sqlite3_column_double(stmt_sel002__2a, 1); |
|
|
2933 | } |
|
|
2934 | else |
|
|
2935 | { |
|
|
2936 | lat_nd = (double) sqlite3_column_double(stmt_sel002__2b, 0); |
|
|
2937 | lon_nd = (double) sqlite3_column_double(stmt_sel002__2b, 1); |
|
|
2938 | } |
|
|
2939 | } |
|
|
2940 | else |
|
|
2941 | { |
|
|
2942 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
2943 | { |
|
|
2944 | #endif |
|
|
2945 | lat_nd = (double) sqlite3_column_double(stmt_sel002a, 0); |
|
|
2946 | lon_nd = (double) sqlite3_column_double(stmt_sel002a, 1); |
|
|
2947 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
2948 | } |
|
|
2949 | else |
|
|
2950 | { |
|
|
2951 | lat_nd = (double) sqlite3_column_double(stmt_sel002b, 0); |
|
|
2952 | lon_nd = (double) sqlite3_column_double(stmt_sel002b, 1); |
|
|
2953 | } |
|
|
2954 | } |
|
|
2955 | #endif |
|
|
2956 | |
|
|
2957 | if (first_node_found == 0) |
|
|
2958 | { |
|
|
2959 | first_node_found = 1; |
|
|
2960 | } |
|
|
2961 | else |
|
|
2962 | { |
|
|
2963 | // ------ ok use this node and coords for triangulation ---- |
|
|
2964 | //fprintf(stderr, "HOLE:nd,lat,lon %lld,%f,%f\n", nd,lat_nd,lon_nd); |
|
|
2965 | |
|
|
2966 | //fprintf(stderr, "np=%d\n", number_of_points_in_poly); |
|
|
2967 | //in.pointlist[number_of_points_in_poly] = (REAL) (lat_nd*10); |
|
|
2968 | //number_of_points_in_poly++; |
|
|
2969 | //fprintf(stderr, "np=%d\n", number_of_points_in_poly); |
|
|
2970 | //in.pointlist[number_of_points_in_poly] = (REAL) (lon_nd*10); |
|
|
2971 | //number_of_points_in_poly++; |
|
|
2972 | #if 1 |
|
|
2973 | y = lat_nd * factor; |
|
|
2974 | x = lon_nd * factor; |
|
|
2975 | |
|
|
2976 | TRY |
|
|
2977 | { |
|
|
2978 | signal(SIGSEGV, catch_signal); |
|
|
2979 | |
|
|
2980 | // hole complete, now add it |
|
|
2981 | //fprintf(stderr, "hole new\n"); |
|
|
2982 | g_ptr_array_add(current_hole, p2t_point_new_dd(x, y)); |
|
|
2983 | //fprintf(stderr, "hole new done\n"); |
|
|
2984 | } |
|
|
2985 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
2986 | { |
|
|
2987 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2988 | fprintf(stderr, "Got Exception A!\n"); |
|
|
2989 | exception = 1; |
|
|
2990 | } |
|
|
2991 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
2992 | { |
|
|
2993 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
2994 | fprintf(stderr, "Got segv Exception A!\n"); |
|
|
2995 | exception = 1; |
|
|
2996 | } |
|
|
2997 | FINALLY |
|
|
2998 | { |
|
|
2999 | // set default |
|
|
3000 | signal (SIGSEGV, SIG_DFL); |
|
|
3001 | // set default |
|
|
3002 | |
|
|
3003 | //fprintf(stderr, "finally\n"); |
|
|
3004 | } |
|
|
3005 | ETRY; |
|
|
3006 | |
|
|
3007 | #endif |
|
|
3008 | } |
|
|
3009 | break; |
|
|
3010 | default: |
|
|
3011 | fprintf(stderr, "Error: %d\n", rc2); |
|
|
3012 | break; |
|
|
3013 | } |
|
|
3014 | } |
|
|
3015 | while (rc2 == SQLITE_ROW); |
|
|
3016 | |
|
|
3017 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
3018 | if (nd % 2) |
|
|
3019 | { |
|
|
3020 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
3021 | { |
|
|
3022 | sqlite3_reset(stmt_sel002__2a); |
|
|
3023 | } |
|
|
3024 | else |
|
|
3025 | { |
|
|
3026 | sqlite3_reset(stmt_sel002__2b); |
|
|
3027 | } |
|
|
3028 | } |
|
|
3029 | else |
|
|
3030 | { |
|
|
3031 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
|
|
3032 | { |
|
|
3033 | #endif |
|
|
3034 | sqlite3_reset(stmt_sel002a); |
|
|
3035 | #ifdef MAPTOOL_SPLIT_NODE_DB |
|
|
3036 | } |
|
|
3037 | else |
|
|
3038 | { |
|
|
3039 | sqlite3_reset(stmt_sel002b); |
|
|
3040 | } |
|
|
3041 | } |
|
|
3042 | #endif |
|
|
3043 | |
|
|
3044 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
3045 | } |
|
|
3046 | |
|
|
3047 | //fprintf(stderr, "uiw 005\n"); |
|
|
3048 | |
|
|
3049 | // remember the pointer, to free the memory later |
|
|
3050 | all_holes = g_list_append(all_holes, current_hole); |
|
|
3051 | |
|
|
3052 | //fprintf(stderr, "uiw 005.1\n"); |
|
|
3053 | |
|
|
3054 | TRY |
|
|
3055 | { |
|
|
3056 | signal(SIGSEGV, catch_signal); |
|
|
3057 | |
|
|
3058 | // hole complete, now add it |
|
|
3059 | //fprintf(stderr, "adding hole\n"); |
|
|
3060 | if (number_of_added_holes < MAX_HOLES_PER_POLY) |
|
|
3061 | { |
|
|
3062 | p2t_cdt_add_hole(cdt, current_hole); |
|
|
3063 | number_of_added_holes++; |
|
|
3064 | } |
|
|
3065 | //fprintf(stderr, "adding done\n"); |
|
|
3066 | } |
|
|
3067 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3068 | { |
|
|
3069 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3070 | fprintf(stderr, "Got Exception 8!\n"); |
|
|
3071 | exception = 1; |
|
|
3072 | } |
|
|
3073 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3074 | { |
|
|
3075 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3076 | fprintf(stderr, "Got segv Exception 8!\n"); |
|
|
3077 | exception = 1; |
|
|
3078 | } |
|
|
3079 | FINALLY |
|
|
3080 | { |
|
|
3081 | // set default |
|
|
3082 | signal (SIGSEGV, SIG_DFL); |
|
|
3083 | // set default |
|
|
3084 | |
|
|
3085 | //fprintf(stderr, "finally\n"); |
|
|
3086 | } |
|
|
3087 | ETRY; |
|
|
3088 | |
|
|
3089 | } |
|
|
3090 | |
|
|
3091 | //fprintf(stderr, "uiw 006\n"); |
|
|
3092 | unsorted_inner_ways = g_list_next(unsorted_inner_ways); |
|
|
3093 | |
|
|
3094 | } |
|
|
3095 | //sqlite3_reset(st); |
|
|
3096 | |
|
|
3097 | //fprintf(stderr, "uiw 007\n"); |
|
|
3098 | } |
|
|
3099 | |
|
|
3100 | //fprintf(stderr, "after adding holes\n"); |
|
|
3101 | |
|
|
3102 | #if 1 |
|
|
3103 | |
|
|
3104 | if (exception == 0) |
|
|
3105 | { |
|
|
3106 | exception = 0; |
|
|
3107 | |
|
|
3108 | TRY |
|
|
3109 | { |
|
|
3110 | // catch SIGSEGV !! |
|
|
3111 | signal(SIGSEGV, catch_signal); |
|
|
3112 | //signal(SIGILL, catch_signal); |
|
|
3113 | |
|
|
3114 | // alternate signal stack ------------ |
|
|
3115 | //ss.ss_size = SIGSTKSZ; |
|
|
3116 | //ss.ss_sp = stack; |
|
|
3117 | //sa.sa_handler = catch_signal; |
|
|
3118 | //sa.sa_flags = SA_ONSTACK; |
|
|
3119 | //sigfillset(&sa.sa_mask); |
|
|
3120 | |
|
|
3121 | //sigaltstack(&ss, 0); |
|
|
3122 | //sigfillset(&sa.sa_mask); |
|
|
3123 | //sigaction(SIGSEGV, &sa, 0); |
|
|
3124 | // alternate signal stack ------------ |
|
|
3125 | |
|
|
3126 | // catch SIGSEGV !! |
|
|
3127 | |
|
|
3128 | //fprintf(stderr, "triangulate start ...\n"); |
|
|
3129 | p2t_cdt_triangulate(cdt); |
|
|
3130 | //fprintf(stderr, "triangulate end\n"); |
|
|
3131 | } |
|
|
3132 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3133 | { |
|
|
3134 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3135 | fprintf(stderr, "Got Exception 2! (in triangulate)\n"); |
|
|
3136 | exception = 1; |
|
|
3137 | } |
|
|
3138 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3139 | { |
|
|
3140 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3141 | fprintf(stderr, "Got segv Exception 2! (in triangulate)\n"); |
|
|
3142 | exception = 1; |
|
|
3143 | } |
|
|
3144 | FINALLY |
|
|
3145 | { |
|
|
3146 | //fprintf(stderr, "finally 2 (in triangulate)\n"); |
|
|
3147 | |
|
|
3148 | //sa.sa_handler = SIG_DFL; |
|
|
3149 | // sigfillset(&sa.sa_mask); |
|
|
3150 | //sigaction(SIGSEGV, &sa, 0); |
|
|
3151 | |
|
|
3152 | // set default |
|
|
3153 | signal (SIGSEGV, SIG_DFL); |
|
|
3154 | // set default |
|
|
3155 | } |
|
|
3156 | ETRY; |
|
|
3157 | |
|
|
3158 | if (exception == 0) |
|
|
3159 | { |
|
|
3160 | rmesh = g_slice_new (P2trCDT); |
|
|
3161 | rmesh->mesh = p2tr_mesh_new (); |
|
|
3162 | // rmesh->outline = p2tr_pslg_new (); |
|
|
3163 | |
|
|
3164 | /* First iteration over the CDT - create all the points */ |
|
|
3165 | //fprintf(stderr, "trinew 006\n"); |
|
|
3166 | triangles = p2t_cdt_get_triangles(cdt); |
|
|
3167 | //fprintf(stderr, "trinew 007\n"); |
|
|
3168 | for (i = 0; i < triangles->len; i++) |
|
|
3169 | { |
|
|
3170 | P2tTriangle *cdt_tri = triangle_index (triangles, i); |
|
|
3171 | for (j = 0; j < 3; j++) |
|
|
3172 | { |
|
|
3173 | P2tPoint *cdt_pt = p2t_triangle_get_point(cdt_tri, j); |
|
|
3174 | P2trPoint *new_pt = (P2trPoint*) g_hash_table_lookup (point_map, cdt_pt); |
|
|
3175 | |
|
|
3176 | if (new_pt == NULL) |
|
|
3177 | { |
|
|
3178 | //fprintf(stderr, "p1 x=%d, y=%d\n",(int)cdt_pt->x, (int)cdt_pt->y); |
|
|
3179 | new_pt = p2tr_mesh_new_point2 (rmesh->mesh, (cdt_pt->x / factor), (cdt_pt->y / factor)); |
|
|
3180 | g_hash_table_insert (point_map, cdt_pt, new_pt); |
|
|
3181 | } |
|
|
3182 | } |
|
|
3183 | } |
|
|
3184 | |
|
|
3185 | for (i = 0; i < triangles->len; i++) |
|
|
3186 | { |
|
|
3187 | P2tTriangle *cdt_tri = triangle_index(triangles, i); |
|
|
3188 | //fprintf(stderr, "tri# %d\n", i); |
|
|
3189 | gboolean ii = p2t_triangle_is_interior(cdt_tri); |
|
|
3190 | //fprintf(stderr, "is int=%d\n", ii); |
|
|
3191 | |
|
|
3192 | P2trPoint *pt1 = (P2trPoint*) g_hash_table_lookup (point_map, p2t_triangle_get_point (cdt_tri, 0)); |
|
|
3193 | P2trPoint *pt2 = (P2trPoint*) g_hash_table_lookup (point_map, p2t_triangle_get_point (cdt_tri, 1)); |
|
|
3194 | P2trPoint *pt3 = (P2trPoint*) g_hash_table_lookup (point_map, p2t_triangle_get_point (cdt_tri, 2)); |
|
|
3195 | |
|
|
3196 | //fprintf(stderr, "0 x=%f, y=%f\n",pt1->c.x, pt1->c.y); |
|
|
3197 | //fprintf(stderr, "1 x=%f, y=%f\n",pt2->c.x, pt2->c.y); |
|
|
3198 | //fprintf(stderr, "2 x=%f, y=%f\n",pt3->c.x, pt3->c.y); |
|
|
3199 | |
|
|
3200 | // make item and write it to ways file ------------------- |
|
|
3201 | // make item and write it to ways file ------------------- |
|
|
3202 | if (tag_id == 1) |
|
|
3203 | { |
|
|
3204 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
|
|
3205 | //fprintf(stderr, "T:water\n"); |
|
|
3206 | } |
|
|
3207 | else if (tag_id == 2) |
|
|
3208 | { |
|
|
3209 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
|
|
3210 | //fprintf(stderr, "T:water\n"); |
|
|
3211 | } |
|
|
3212 | else if (tag_id == 4) |
|
|
3213 | { |
|
|
3214 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
|
|
3215 | //fprintf(stderr, "T:water\n"); |
|
|
3216 | } |
|
|
3217 | else if (tag_id == 5) |
|
|
3218 | { |
|
|
3219 | item_bin_tri = init_item(type_poly_wood_from_triang, 0); |
|
|
3220 | //fprintf(stderr, "T:forest\n"); |
|
|
3221 | } |
|
|
3222 | else if (tag_id == 6) |
|
|
3223 | { |
|
|
3224 | item_bin_tri = init_item(type_poly_wood_from_triang, 0); |
|
|
3225 | //fprintf(stderr, "T:forest\n"); |
|
|
3226 | } |
|
|
3227 | else if (tag_id == 9) |
|
|
3228 | { |
|
|
3229 | item_bin_tri = init_item(type_poly_building_from_triang, 0); |
|
|
3230 | //fprintf(stderr, "T:building\n"); |
|
|
3231 | } |
|
|
3232 | else |
|
|
3233 | { |
|
|
3234 | // default |
|
|
3235 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
|
|
3236 | //fprintf(stderr, "T:water\n"); |
|
|
3237 | } |
|
|
3238 | |
|
|
3239 | // add dummy osm wayid |
|
|
3240 | item_bin_add_attr_longlong(item_bin_tri, attr_osm_wayid, current_id); |
|
|
3241 | coord_tri.x = transform_from_geo_lon(pt1->c.x); |
|
|
3242 | coord_tri.y = transform_from_geo_lat(pt1->c.y); |
|
|
3243 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
|
|
3244 | coord_tri.x = transform_from_geo_lon(pt2->c.x); |
|
|
3245 | coord_tri.y = transform_from_geo_lat(pt2->c.y); |
|
|
3246 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
|
|
3247 | coord_tri.x = transform_from_geo_lon(pt3->c.x); |
|
|
3248 | coord_tri.y = transform_from_geo_lat(pt3->c.y); |
|
|
3249 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
|
|
3250 | |
|
|
3251 | item_bin_write(item_bin_tri, osm->ways_with_coords); |
|
|
3252 | // make item and write it to ways file ------------------- |
|
|
3253 | // make item and write it to ways file ------------------- |
|
|
3254 | |
|
|
3255 | } |
|
|
3256 | |
|
|
3257 | //fprintf(stderr, "trinew 091\n"); |
|
|
3258 | |
|
|
3259 | } |
|
|
3260 | |
|
|
3261 | //fprintf(stderr, "trinew 092.0\n"); |
|
|
3262 | |
|
|
3263 | |
|
|
3264 | TRY |
|
|
3265 | { |
|
|
3266 | signal(SIGSEGV, catch_signal); |
|
|
3267 | |
|
|
3268 | /* Now finally unref the points we added into the map */ |
|
|
3269 | if (point_map != NULL) |
|
|
3270 | { |
|
|
3271 | GHashTableIter iter; |
|
|
3272 | P2trPoint *pt_iter = NULL; |
|
|
3273 | g_hash_table_iter_init (&iter, point_map); |
|
|
3274 | while (g_hash_table_iter_next (&iter, NULL, (gpointer*)&pt_iter)) |
|
|
3275 | { |
|
|
3276 | p2tr_point_unref(pt_iter); |
|
|
3277 | } |
|
|
3278 | g_hash_table_destroy(point_map); |
|
|
3279 | } |
|
|
3280 | } |
|
|
3281 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3282 | { |
|
|
3283 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3284 | fprintf(stderr, "Got Exception 3!\n"); |
|
|
3285 | exception = 1; |
|
|
3286 | } |
|
|
3287 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3288 | { |
|
|
3289 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3290 | fprintf(stderr, "Got segv Exception 3!\n"); |
|
|
3291 | exception = 1; |
|
|
3292 | } |
|
|
3293 | FINALLY |
|
|
3294 | { |
|
|
3295 | signal (SIGSEGV, SIG_DFL); |
|
|
3296 | } |
|
|
3297 | ETRY; |
|
|
3298 | |
|
|
3299 | //fprintf(stderr, "trinew 092.1\n"); |
|
|
3300 | |
|
|
3301 | |
|
|
3302 | TRY |
|
|
3303 | { |
|
|
3304 | signal(SIGSEGV, catch_signal); |
|
|
3305 | // p2tr_mesh_clear(rmesh->mesh); |
|
|
3306 | // --- maybe need this?? --- p2tr_mesh_unref(rmesh->mesh); |
|
|
3307 | } |
|
|
3308 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3309 | { |
|
|
3310 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3311 | fprintf(stderr, "Got Exception 4!\n"); |
|
|
3312 | exception = 1; |
|
|
3313 | } |
|
|
3314 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3315 | { |
|
|
3316 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3317 | fprintf(stderr, "Got segv Exception 4!\n"); |
|
|
3318 | exception = 1; |
|
|
3319 | } |
|
|
3320 | FINALLY |
|
|
3321 | { |
|
|
3322 | signal (SIGSEGV, SIG_DFL); |
|
|
3323 | } |
|
|
3324 | ETRY; |
|
|
3325 | |
|
|
3326 | //fprintf(stderr, "trinew 092.2\n"); |
|
|
3327 | |
|
|
3328 | TRY |
|
|
3329 | { |
|
|
3330 | signal(SIGSEGV, catch_signal); |
|
|
3331 | p2t_cdt_free(cdt); |
|
|
3332 | } |
|
|
3333 | CATCH( MAPTOOL_00001_EXCEPTION ) |
|
|
3334 | { |
|
|
3335 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3336 | fprintf(stderr, "Got Exception 5!\n"); |
|
|
3337 | exception = 1; |
|
|
3338 | } |
|
|
3339 | CATCH( MAPTOOL_00002_EXCEPTION ) |
|
|
3340 | { |
|
|
3341 | fprintf(stderr, "relation id=%lld\n", current_id); |
|
|
3342 | fprintf(stderr, "Got segv Exception 5!\n"); |
|
|
3343 | exception = 1; |
|
|
3344 | } |
|
|
3345 | FINALLY |
|
|
3346 | { |
|
|
3347 | signal (SIGSEGV, SIG_DFL); |
|
|
3348 | } |
|
|
3349 | ETRY; |
|
|
3350 | |
|
|
3351 | //fprintf(stderr, "trinew 092.3\n"); |
|
|
3352 | |
|
|
3353 | } // exception == 0 ? -- END |
|
|
3354 | |
|
|
3355 | // rcdt = p2tr_cdt_new(cdt); |
|
|
3356 | /* |
|
|
3357 | if (refine_max_steps > 0) |
|
|
3358 | { |
|
|
3359 | fprintf(stderr, "Refining the mesh!\n"); |
|
|
3360 | refiner = p2tr_refiner_new(G_PI / 6, p2tr_refiner_false_too_big, rcdt); |
|
|
3361 | p2tr_refiner_refine(refiner, refine_max_steps, NULL); |
|
|
3362 | p2tr_refiner_free(refiner); |
|
|
3363 | |
|
|
3364 | p2tr_cdt_validate_edges(rcdt); |
|
|
3365 | } |
|
|
3366 | */ |
|
|
3367 | |
|
|
3368 | //fprintf(stderr, "free holes\n"); |
|
|
3369 | |
|
|
3370 | if (all_holes) |
|
|
3371 | { |
|
|
3372 | all_holes = g_list_first(all_holes); |
|
|
3373 | while (all_holes) |
|
|
3374 | { |
|
|
3375 | current_hole = all_holes->data; |
|
|
3376 | for (i = 0; i < current_hole->len; ++i) |
|
|
3377 | { |
|
|
3378 | p2t_point_free(g_ptr_array_index(current_hole, i)); |
|
|
3379 | } |
|
|
3380 | g_ptr_array_free(current_hole, TRUE); |
|
|
3381 | |
|
|
3382 | all_holes = g_list_next(all_holes); |
|
|
3383 | } |
|
|
3384 | g_list_free(all_holes); |
|
|
3385 | all_holes = NULL; |
|
|
3386 | } |
|
|
3387 | |
|
|
3388 | //fprintf(stderr, "free points\n"); |
|
|
3389 | |
|
|
3390 | for (i = 0; i < current_points->len; ++i) |
|
|
3391 | { |
|
|
3392 | p2t_point_free(g_ptr_array_index(current_points, i)); |
|
|
3393 | } |
|
|
3394 | g_ptr_array_free(current_points, TRUE); |
|
|
3395 | |
|
|
3396 | // p2tr_cdt_free(rcdt); |
|
|
3397 | |
|
|
3398 | #endif |
|
|
3399 | |
|
|
3400 | #if 0 |
|
|
3401 | item_bin_write(item_bin_tri, osm->ways_with_coords); |
|
|
3402 | #endif |
|
|
3403 | triangulate_not_done = 0; |
|
|
3404 | } |
|
|
3405 | |
|
|
3406 | // free everything!! ---------------- |
|
|
3407 | if (unsorted_outer_ways) |
|
|
3408 | { |
|
|
3409 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
|
|
3410 | while (unsorted_outer_ways) |
|
|
3411 | { |
|
|
3412 | gptr = unsorted_outer_ways->data; |
|
|
3413 | way_nodes1 = unsorted_outer_ways->data; |
|
|
3414 | if (way_nodes1->nodes) |
|
|
3415 | { |
|
|
3416 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
3417 | while (way_nodes1->nodes) |
|
|
3418 | { |
|
|
3419 | ndptr = way_nodes1->nodes->data; |
|
|
3420 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
3421 | g_free(ndptr); |
|
|
3422 | ndptr = NULL; |
|
|
3423 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
3424 | } |
|
|
3425 | } |
|
|
3426 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, gptr); |
|
|
3427 | g_free(gptr); |
|
|
3428 | gptr = NULL; |
|
|
3429 | unsorted_outer_ways = g_list_next(unsorted_outer_ways); |
|
|
3430 | } |
|
|
3431 | } |
|
|
3432 | |
|
|
3433 | if (unsorted_inner_ways) |
|
|
3434 | { |
|
|
3435 | unsorted_inner_ways = g_list_first(unsorted_inner_ways); |
|
|
3436 | while (unsorted_inner_ways) |
|
|
3437 | { |
|
|
3438 | gptr = unsorted_inner_ways->data; |
|
|
3439 | way_nodes1 = unsorted_inner_ways->data; |
|
|
3440 | if (way_nodes1->nodes) |
|
|
3441 | { |
|
|
3442 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
3443 | while (way_nodes1->nodes) |
|
|
3444 | { |
|
|
3445 | ndptr = way_nodes1->nodes->data; |
|
|
3446 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
3447 | g_free(ndptr); |
|
|
3448 | ndptr = NULL; |
|
|
3449 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
3450 | } |
|
|
3451 | } |
|
|
3452 | unsorted_inner_ways = g_list_remove(unsorted_inner_ways, gptr); |
|
|
3453 | g_free(gptr); |
|
|
3454 | gptr = NULL; |
|
|
3455 | unsorted_inner_ways = g_list_next(unsorted_inner_ways); |
|
|
3456 | } |
|
|
3457 | } |
|
|
3458 | |
|
|
3459 | if (sorted_outer_ways) |
|
|
3460 | { |
|
|
3461 | sorted_outer_ways = g_list_first(sorted_outer_ways); |
|
|
3462 | while (sorted_outer_ways) |
|
|
3463 | { |
|
|
3464 | gptr = sorted_outer_ways->data; |
|
|
3465 | way_nodes1 = sorted_outer_ways->data; |
|
|
3466 | if (way_nodes1->nodes) |
|
|
3467 | { |
|
|
3468 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
|
|
3469 | while (way_nodes1->nodes) |
|
|
3470 | { |
|
|
3471 | ndptr = way_nodes1->nodes->data; |
|
|
3472 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
|
|
3473 | g_free(ndptr); |
|
|
3474 | ndptr = NULL; |
|
|
3475 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
|
|
3476 | } |
|
|
3477 | } |
|
|
3478 | sorted_outer_ways = g_list_remove(sorted_outer_ways, gptr); |
|
|
3479 | g_free(gptr); |
|
|
3480 | gptr = NULL; |
|
|
3481 | sorted_outer_ways = g_list_next(sorted_outer_ways); |
|
|
3482 | } |
|
|
3483 | } |
|
|
3484 | // free everything!! ---------------- |
|
|
3485 | } |
|
|
3486 | // save relations other method -------------- |
|
|
3487 | |
|
|
3488 | #endif |
|
|
3489 | |
|
|
3490 | if (triangulate_not_done == 1) |
|
|
3491 | { |
|
|
3492 | str = NULL; |
|
|
3493 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3494 | { |
|
|
3495 | if (get_relation_member(str, &memb)) |
|
|
3496 | { |
|
|
3497 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) // use only "outer" "ways" here!! |
|
|
3498 | { |
|
|
3499 | struct way_tag wt; |
|
|
3500 | wt.way_id = memb.id; |
|
|
3501 | wt.tag_id = tag_id; |
|
|
3502 | // only use "water" related ways here |
|
|
3503 | if ((tag_id == 1) || (tag_id == 2) || (tag_id == 4) || (tag_id == 5) || (tag_id == 6)) |
|
|
3504 | { |
|
|
3505 | //fprintf(stderr,"rel way=%llu\n", memb.id); |
|
|
3506 | fwrite(&wt, sizeof(struct way_tag), 1, osm->relations_riverbank); |
|
|
3507 | } |
|
|
3508 | } |
|
|
3509 | else if ((memb.type == 2) && (!strcmp(memb.role, "inner"))) // use only "outer" "ways" here!! |
|
|
3510 | { |
|
|
3511 | struct way_tag wt; |
|
|
3512 | wt.way_id = memb.id; |
|
|
3513 | wt.tag_id = tag_id; |
|
|
3514 | // only use "water" related ways here |
|
|
3515 | if (tag_id == 6) |
|
|
3516 | { |
|
|
3517 | wt.tag_id = 8; |
|
|
3518 | //fprintf(stderr,"rel way(8)=%llu\n", memb.id); |
|
|
3519 | fwrite(&wt, sizeof(struct way_tag), 1, osm->relations_riverbank); |
|
|
3520 | } |
|
|
3521 | else if (tag_id == 5) |
|
|
3522 | { |
|
|
3523 | wt.tag_id = 7; |
|
|
3524 | //fprintf(stderr,"rel way(7)=%llu\n", memb.id); |
|
|
3525 | fwrite(&wt, sizeof(struct way_tag), 1, osm->relations_riverbank); |
|
|
3526 | } |
|
|
3527 | } |
|
|
3528 | |
|
|
3529 | } |
|
|
3530 | } |
|
|
3531 | } |
|
|
3532 | } |
|
|
3533 | // -- save relations for riverbanks -- |
|
|
3534 | |
|
|
3535 | |
|
|
3536 | in_relation = 0; |
|
|
3537 | |
|
|
3538 | if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) |
|
|
3539 | { |
|
|
3540 | int found_town_rel = 0; |
|
|
3541 | |
|
|
3542 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
|
|
3543 | { |
|
|
3544 | // save relation id for towns into DB |
|
|
3545 | str = NULL; |
|
|
3546 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3547 | { |
|
|
3548 | if (get_relation_member(str, &memb)) |
|
|
3549 | { |
|
|
3550 | if (memb.type == 1) |
|
|
3551 | { |
|
|
3552 | //fprintf(stderr, "role=%s\n", memb.role); |
|
|
3553 | |
|
|
3554 | if (!strcmp(memb.role, "label")) |
|
|
3555 | { |
|
|
3556 | fprintf(stderr, "town to relation 1: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
|
|
3557 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3558 | // fprintf(stderr, "ret=%d\n", rr); |
|
|
3559 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
|
|
3560 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
|
|
3561 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
|
|
3562 | sqlite3_step(stmt_town_sel008); |
|
|
3563 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3564 | sqlite3_reset(stmt_town_sel008); |
|
|
3565 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3566 | |
|
|
3567 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3568 | |
|
|
3569 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
|
|
3570 | sqlite3_bind_int(stmt_town, 2, 999); |
|
|
3571 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
|
|
3572 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
|
|
3573 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
|
|
3574 | sqlite3_bind_int64(stmt_town, 8, current_id); |
|
|
3575 | sqlite3_step(stmt_town); |
|
|
3576 | sqlite3_reset(stmt_town); |
|
|
3577 | dummy_town_id--; |
|
|
3578 | |
|
|
3579 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3580 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3581 | |
|
|
3582 | found_town_rel = 1; |
|
|
3583 | } |
|
|
3584 | } |
|
|
3585 | } |
|
|
3586 | } |
|
|
3587 | } |
|
|
3588 | |
|
|
3589 | |
|
|
3590 | |
|
|
3591 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
|
|
3592 | { |
|
|
3593 | // save relation id for towns into DB |
|
|
3594 | str = NULL; |
|
|
3595 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3596 | { |
|
|
3597 | if (get_relation_member(str, &memb)) |
|
|
3598 | { |
|
|
3599 | if (memb.type == 1) |
|
|
3600 | { |
|
|
3601 | //fprintf(stderr, "role=%s\n", memb.role); |
|
|
3602 | |
|
|
3603 | if (!strcmp(memb.role, "admin_centre")) |
|
|
3604 | { |
|
|
3605 | fprintf(stderr, "town to relation 2: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
|
|
3606 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3607 | // fprintf(stderr, "ret=%d\n", rr); |
|
|
3608 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
|
|
3609 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
|
|
3610 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
|
|
3611 | sqlite3_step(stmt_town_sel008); |
|
|
3612 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3613 | sqlite3_reset(stmt_town_sel008); |
|
|
3614 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3615 | |
|
|
3616 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3617 | |
|
|
3618 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
|
|
3619 | sqlite3_bind_int(stmt_town, 2, 999); |
|
|
3620 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
|
|
3621 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
|
|
3622 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
|
|
3623 | sqlite3_bind_int64(stmt_town, 8, current_id); |
|
|
3624 | sqlite3_step(stmt_town); |
|
|
3625 | sqlite3_reset(stmt_town); |
|
|
3626 | dummy_town_id--; |
|
|
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 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
|
|
3639 | { |
|
|
3640 | // save relation id for towns into DB |
|
|
3641 | str = NULL; |
|
|
3642 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3643 | { |
|
|
3644 | if (get_relation_member(str, &memb)) |
|
|
3645 | { |
|
|
3646 | if (memb.type == 1) |
|
|
3647 | { |
|
|
3648 | //fprintf(stderr, "role=%s\n", memb.role); |
|
|
3649 | |
|
|
3650 | if (!strcmp(memb.role, "admin_center")) |
|
|
3651 | { |
|
|
3652 | fprintf(stderr, "town to relation 3: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
|
|
3653 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3654 | // fprintf(stderr, "ret=%d\n", rr); |
|
|
3655 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
|
|
3656 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
|
|
3657 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
|
|
3658 | sqlite3_step(stmt_town_sel008); |
|
|
3659 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3660 | sqlite3_reset(stmt_town_sel008); |
|
|
3661 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3662 | |
|
|
3663 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3664 | |
|
|
3665 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
|
|
3666 | sqlite3_bind_int(stmt_town, 2, 999); |
|
|
3667 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
|
|
3668 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
|
|
3669 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
|
|
3670 | sqlite3_bind_int64(stmt_town, 8, current_id); |
|
|
3671 | sqlite3_step(stmt_town); |
|
|
3672 | sqlite3_reset(stmt_town); |
|
|
3673 | dummy_town_id--; |
|
|
3674 | |
|
|
3675 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3676 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3677 | |
|
|
3678 | found_town_rel = 1; |
|
|
3679 | } |
|
|
3680 | } |
|
|
3681 | } |
|
|
3682 | } |
|
|
3683 | } |
|
|
3684 | |
|
|
3685 | |
|
|
3686 | |
|
|
3687 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
|
|
3688 | { |
|
|
3689 | // save relation id for towns into DB (use dummy town data) |
|
|
3690 | fprintf(stderr, "town to relation(*): rel-name:%s admlevel:%d r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), admin_level, current_id, dummy_town_id); |
|
|
3691 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3692 | // fprintf(stderr, "ret=%d\n", rr); |
|
|
3693 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
|
|
3694 | sqlite3_bind_int64(stmt_town_sel008, 2, dummy_town_id); |
|
|
3695 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
|
|
3696 | sqlite3_step(stmt_town_sel008); |
|
|
3697 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3698 | sqlite3_reset(stmt_town_sel008); |
|
|
3699 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3700 | |
|
|
3701 | |
|
|
3702 | str = NULL; |
|
|
3703 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3704 | { |
|
|
3705 | if (get_relation_member(str, &memb)) |
|
|
3706 | { |
|
|
3707 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) |
|
|
3708 | { |
|
|
3709 | // way-id is "memb.id" |
|
|
3710 | // use the first nodes coords |
|
|
3711 | get_lat_lon_way_first_node(memb.id, &node_coords); |
|
|
3712 | if (node_coords.valid == 1) |
|
|
3713 | { |
|
|
3714 | sqlite3_bind_double(stmt_town, 6, node_coords.lat); |
|
|
3715 | sqlite3_bind_double(stmt_town, 7, node_coords.lon); |
|
|
3716 | } |
|
|
3717 | |
|
|
3718 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3719 | |
|
|
3720 | break; |
|
|
3721 | } |
|
|
3722 | } |
|
|
3723 | } |
|
|
3724 | |
|
|
3725 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
|
|
3726 | sqlite3_bind_int(stmt_town, 2, 999); |
|
|
3727 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
|
|
3728 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
|
|
3729 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
|
|
3730 | sqlite3_bind_int64(stmt_town, 8, current_id); |
|
|
3731 | sqlite3_step(stmt_town); |
|
|
3732 | sqlite3_reset(stmt_town); |
|
|
3733 | |
|
|
3734 | found_town_rel = 1; |
|
|
3735 | |
|
|
3736 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3737 | //fprintf(stderr, "ret=%d\n", rr); |
|
|
3738 | |
|
|
3739 | dummy_town_id--; |
|
|
3740 | } |
|
|
3741 | |
|
|
3742 | // rest of the boundaries!!! |
|
|
3743 | if (found_town_rel == 0) |
|
|
3744 | { |
|
|
3745 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3746 | |
|
|
3747 | str = NULL; |
|
|
3748 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
|
|
3749 | { |
|
|
3750 | if (get_relation_member(str, &memb)) |
|
|
3751 | { |
|
|
3752 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) |
|
|
3753 | { |
|
|
3754 | fprintf(stderr, "town to relation(+): rel-name:%s admlevel:%d r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), admin_level, current_id, 9797979797); |
|
|
3755 | |
|
|
3756 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
|
|
3757 | break; |
|
|
3758 | } |
|
|
3759 | } |
|
|
3760 | } |
|
|
3761 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3762 | |
|
|
3763 | found_town_rel = 0; |
|
|
3764 | } |
|
|
3765 | |
|
|
3766 | |
|
|
3767 | #if 0 |
1574 | if (admin_level == 2) { |
3768 | if (admin_level == 2) |
|
|
3769 | { |
1575 | FILE *f; |
3770 | FILE *f; |
1576 | fprintf(stderr,"Multipolygon for %s\n", iso_code); |
3771 | fprintf(stderr,"Multipolygon for %s\n", iso_code); |
1577 | char *name=g_strdup_printf("country_%s.tmp",iso_code); |
3772 | char *name=g_strdup_printf("country_%s.tmp",iso_code); |
1578 | f=fopen(name,"w"); |
3773 | f=fopen(name,"w"); |
1579 | item_bin_write(item_bin, f); |
3774 | item_bin_write(item_bin_2, f); |
1580 | fclose(f); |
3775 | fclose(f); |
1581 | } |
3776 | } |
1582 | #endif |
3777 | #endif |
1583 | item_bin_write(item_bin, osm->boundaries); |
3778 | item_bin_write(item_bin_2, osm->boundaries); |
1584 | } |
3779 | } |
1585 | |
3780 | |
1586 | if (!strcmp(relation_type, "restriction") && (item_bin->type == type_street_turn_restriction_no || item_bin->type == type_street_turn_restriction_only)) |
3781 | if (!strcmp(relation_type, "restriction") && (item_bin_2->type == type_street_turn_restriction_no || item_bin_2->type == type_street_turn_restriction_only)) |
|
|
3782 | { |
1587 | item_bin_write(item_bin, osm->turn_restrictions); |
3783 | item_bin_write(item_bin_2, osm->turn_restrictions); |
|
|
3784 | } |
1588 | } |
3785 | } |
1589 | |
3786 | |
1590 | void |
3787 | |
|
|
3788 | void correct_boundary_ref_point(GList *bl) |
|
|
3789 | { |
|
|
3790 | long long rid; |
|
|
3791 | int retval; |
|
|
3792 | int rc = 0; |
|
|
3793 | int commit_after = 20000; |
|
|
3794 | int count = 0; |
|
|
3795 | int admin_l = 99; |
|
|
3796 | double lat, lon; |
|
|
3797 | struct coord c; |
|
|
3798 | GList *l = NULL; |
|
|
3799 | GList *l2 = NULL; |
|
|
3800 | GList *match = NULL; |
|
|
3801 | struct boundary *b; |
|
|
3802 | int admin_l_boundary; |
|
|
3803 | int max_admin_l; |
|
|
3804 | |
|
|
3805 | // loop thru all the boundaries |
|
|
3806 | do |
|
|
3807 | { |
|
|
3808 | rc = sqlite3_step(stmt_bd_002); |
|
|
3809 | switch (rc) |
|
|
3810 | { |
|
|
3811 | case SQLITE_DONE: |
|
|
3812 | break; |
|
|
3813 | case SQLITE_ROW: |
|
|
3814 | |
|
|
3815 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
|
|
3816 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
|
|
3817 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
|
|
3818 | lat = sqlite3_column_double(stmt_bd_002, 2); |
|
|
3819 | lon = sqlite3_column_double(stmt_bd_002, 3); |
|
|
3820 | c.x = transform_from_geo_lon(lon); |
|
|
3821 | c.y = transform_from_geo_lat(lat); |
|
|
3822 | |
|
|
3823 | //fprintf(stderr, "correct_boundary_ref_point: relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
|
|
3824 | |
|
|
3825 | // find this boundary in list |
|
|
3826 | l = bl; |
|
|
3827 | match = NULL; |
|
|
3828 | while (l) |
|
|
3829 | { |
|
|
3830 | b = l->data; |
|
|
3831 | //fprintf(stderr, "correct_boundary_ref_point: %lld %lld\n", item_bin_get_relationid(b->ib), rid); |
|
|
3832 | if (item_bin_get_relationid(b->ib) == rid) |
|
|
3833 | { |
|
|
3834 | match = l; |
|
|
3835 | break; |
|
|
3836 | } |
|
|
3837 | l = g_list_next(l); |
|
|
3838 | } |
|
|
3839 | |
|
|
3840 | if (match) |
|
|
3841 | { |
|
|
3842 | b = match->data; |
|
|
3843 | //fprintf(stderr, "correct_boundary_ref_point: relid:%lld(%d) parentid:%lld(%d)\n", rid, admin_l, item_bin_get_relationid(b->ib), max_admin_l); |
|
|
3844 | |
|
|
3845 | // ------------------------------------------- |
|
|
3846 | /* |
|
|
3847 | GList *sl; |
|
|
3848 | sl = b->sorted_segments; |
|
|
3849 | if (sl) |
|
|
3850 | { |
|
|
3851 | struct geom_poly_segment *gs = sl->data; |
|
|
3852 | struct coord *c2 = gs->first; |
|
|
3853 | fprintf(stderr, "1a c=%d y=%d\n", c2->x, c2->y); |
|
|
3854 | } |
|
|
3855 | */ |
|
|
3856 | // ------------------------------------------- |
|
|
3857 | |
|
|
3858 | if (find_correct_point_in_boundary(match, &lat, &lon) == 1) |
|
|
3859 | { |
|
|
3860 | sqlite3_bind_double(stmt_bd_004, 1, lat); |
|
|
3861 | sqlite3_bind_double(stmt_bd_004, 2, lon); |
|
|
3862 | sqlite3_bind_int64(stmt_bd_004, 3, rid); |
|
|
3863 | sqlite3_step(stmt_bd_004); |
|
|
3864 | sqlite3_reset(stmt_bd_004); |
|
|
3865 | } |
|
|
3866 | } |
|
|
3867 | |
|
|
3868 | |
|
|
3869 | if (count == 0) |
|
|
3870 | { |
|
|
3871 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
3872 | } |
|
|
3873 | count++; |
|
|
3874 | |
|
|
3875 | if (count > commit_after) |
|
|
3876 | { |
|
|
3877 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3878 | count = 0; |
|
|
3879 | } |
|
|
3880 | |
|
|
3881 | break; |
|
|
3882 | default: |
|
|
3883 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
3884 | break; |
|
|
3885 | } |
|
|
3886 | } |
|
|
3887 | while (rc == SQLITE_ROW); |
|
|
3888 | sqlite3_reset(stmt_bd_002); |
|
|
3889 | |
|
|
3890 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
3891 | |
|
|
3892 | } |
|
|
3893 | |
|
|
3894 | |
|
|
3895 | int find_correct_point_in_boundary(GList *bl, double* lat, double* lon) |
|
|
3896 | { |
|
|
3897 | double lat2, lon2; |
|
|
3898 | struct coord c; |
|
|
3899 | struct boundary *b; |
|
|
3900 | GList *matches; |
|
|
3901 | double lat_d = 0.00006; |
|
|
3902 | double lon_d = 0.00006; |
|
|
3903 | |
|
|
3904 | lat2 = *lat; |
|
|
3905 | lon2 = *lon; |
|
|
3906 | |
|
|
3907 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
3908 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
3909 | //fprintf(stderr, "2 c=%d y=%d\n", c.x, c.y); |
|
|
3910 | matches = NULL; |
|
|
3911 | matches = boundary_find_matches_single(bl, &c); |
|
|
3912 | if (g_list_length(matches) > 0) |
|
|
3913 | { |
|
|
3914 | *lon = lon2 + lon_d; |
|
|
3915 | *lat = lat2 + lat_d; |
|
|
3916 | return 1; |
|
|
3917 | } |
|
|
3918 | |
|
|
3919 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
3920 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
3921 | //fprintf(stderr, "3 c=%d y=%d\n", c.x, c.y); |
|
|
3922 | matches = NULL; |
|
|
3923 | matches = boundary_find_matches_single(bl, &c); |
|
|
3924 | if (g_list_length(matches) > 0) |
|
|
3925 | { |
|
|
3926 | *lon = lon2 + lon_d; |
|
|
3927 | *lat = lat2 - lat_d; |
|
|
3928 | return 1; |
|
|
3929 | } |
|
|
3930 | |
|
|
3931 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
3932 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
3933 | //fprintf(stderr, "4 c=%d y=%d\n", c.x, c.y); |
|
|
3934 | matches = NULL; |
|
|
3935 | matches = boundary_find_matches_single(bl, &c); |
|
|
3936 | if (g_list_length(matches) > 0) |
|
|
3937 | { |
|
|
3938 | *lon = lon2 - lon_d; |
|
|
3939 | *lat = lat2 + lat_d; |
|
|
3940 | return 1; |
|
|
3941 | } |
|
|
3942 | |
|
|
3943 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
3944 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
3945 | //fprintf(stderr, "5 c=%d y=%d\n", c.x, c.y); |
|
|
3946 | matches = NULL; |
|
|
3947 | matches = boundary_find_matches_single(bl, &c); |
|
|
3948 | if (g_list_length(matches) > 0) |
|
|
3949 | { |
|
|
3950 | *lon = lon2 - lon_d; |
|
|
3951 | *lat = lat2 - lat_d; |
|
|
3952 | return 1; |
|
|
3953 | } |
|
|
3954 | |
|
|
3955 | |
|
|
3956 | c.x = transform_from_geo_lon(lon2 + lon_d); |
|
|
3957 | c.y = transform_from_geo_lat(lat2); |
|
|
3958 | //fprintf(stderr, "6 c=%d y=%d\n", c.x, c.y); |
|
|
3959 | matches = NULL; |
|
|
3960 | matches = boundary_find_matches_single(bl, &c); |
|
|
3961 | if (g_list_length(matches) > 0) |
|
|
3962 | { |
|
|
3963 | *lon = lon2 - lon_d; |
|
|
3964 | *lat = lat2; |
|
|
3965 | return 1; |
|
|
3966 | } |
|
|
3967 | |
|
|
3968 | c.x = transform_from_geo_lon(lon2 - lon_d); |
|
|
3969 | c.y = transform_from_geo_lat(lat2); |
|
|
3970 | //fprintf(stderr, "7 c=%d y=%d\n", c.x, c.y); |
|
|
3971 | matches = NULL; |
|
|
3972 | matches = boundary_find_matches_single(bl, &c); |
|
|
3973 | if (g_list_length(matches) > 0) |
|
|
3974 | { |
|
|
3975 | *lon = lon2 - lon_d; |
|
|
3976 | *lat = lat2; |
|
|
3977 | return 1; |
|
|
3978 | } |
|
|
3979 | |
|
|
3980 | c.x = transform_from_geo_lon(lon2); |
|
|
3981 | c.y = transform_from_geo_lat(lat2 + lat_d); |
|
|
3982 | //fprintf(stderr, "8 c=%d y=%d\n", c.x, c.y); |
|
|
3983 | matches = NULL; |
|
|
3984 | matches = boundary_find_matches_single(bl, &c); |
|
|
3985 | if (g_list_length(matches) > 0) |
|
|
3986 | { |
|
|
3987 | *lon = lon2; |
|
|
3988 | *lat = lat2 + lat_d; |
|
|
3989 | return 1; |
|
|
3990 | } |
|
|
3991 | |
|
|
3992 | |
|
|
3993 | c.x = transform_from_geo_lon(lon2); |
|
|
3994 | c.y = transform_from_geo_lat(lat2 - lat_d); |
|
|
3995 | //fprintf(stderr, "9 c=%d y=%d\n", c.x, c.y); |
|
|
3996 | matches = NULL; |
|
|
3997 | matches = boundary_find_matches_single(bl, &c); |
|
|
3998 | if (g_list_length(matches) > 0) |
|
|
3999 | { |
|
|
4000 | *lon = lon2; |
|
|
4001 | *lat = lat2 - lat_d; |
|
|
4002 | return 1; |
|
|
4003 | } |
|
|
4004 | |
|
|
4005 | return 0; |
|
|
4006 | |
|
|
4007 | } |
|
|
4008 | |
|
|
4009 | void build_boundary_tree(GList *bl) |
|
|
4010 | { |
|
|
4011 | long long rid; |
|
|
4012 | int retval; |
|
|
4013 | int rc = 0; |
|
|
4014 | int commit_after = 20000; |
|
|
4015 | int count = 0; |
|
|
4016 | int admin_l = 99; |
|
|
4017 | double lat, lon; |
|
|
4018 | struct coord c; |
|
|
4019 | GList *l = NULL; |
|
|
4020 | GList *l2 = NULL; |
|
|
4021 | GList *match = NULL; |
|
|
4022 | struct boundary *b; |
|
|
4023 | int admin_l_boundary; |
|
|
4024 | int max_admin_l; |
|
|
4025 | |
|
|
4026 | // loop thru all the boundaries |
|
|
4027 | do |
|
|
4028 | { |
|
|
4029 | rc = sqlite3_step(stmt_bd_002); |
|
|
4030 | switch (rc) |
|
|
4031 | { |
|
|
4032 | case SQLITE_DONE: |
|
|
4033 | break; |
|
|
4034 | case SQLITE_ROW: |
|
|
4035 | |
|
|
4036 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
|
|
4037 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
|
|
4038 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
|
|
4039 | lat = sqlite3_column_double(stmt_bd_002, 2); |
|
|
4040 | lon = sqlite3_column_double(stmt_bd_002, 3); |
|
|
4041 | c.x = transform_from_geo_lon(lon); |
|
|
4042 | c.y = transform_from_geo_lat(lat); |
|
|
4043 | |
|
|
4044 | //fprintf(stderr, "relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
|
|
4045 | |
|
|
4046 | max_admin_l = 0; |
|
|
4047 | l2 = boundary_find_matches_level(bl, &c, 0, (admin_l - 1)); |
|
|
4048 | l = l2; |
|
|
4049 | match = NULL; |
|
|
4050 | while (l) |
|
|
4051 | { |
|
|
4052 | b = l->data; |
|
|
4053 | char *admin_l_boundary_str = osm_tag_value(b->ib, "admin_level"); |
|
|
4054 | if (!admin_l_boundary_str) |
|
|
4055 | { |
|
|
4056 | admin_l_boundary = 9999; |
|
|
4057 | } |
|
|
4058 | else |
|
|
4059 | { |
|
|
4060 | admin_l_boundary = atoi(admin_l_boundary_str); |
|
|
4061 | } |
|
|
4062 | |
|
|
4063 | if (admin_l_boundary < 2) |
|
|
4064 | { |
|
|
4065 | admin_l_boundary = 9999; |
|
|
4066 | } |
|
|
4067 | |
|
|
4068 | //fprintf(stderr, "b=%d\n", admin_l_boundary); |
|
|
4069 | if (admin_l_boundary > max_admin_l) |
|
|
4070 | { |
|
|
4071 | max_admin_l = admin_l_boundary; |
|
|
4072 | match = l; |
|
|
4073 | //fprintf(stderr, "b2=%d\n", max_admin_l); |
|
|
4074 | } |
|
|
4075 | l = g_list_next(l); |
|
|
4076 | } |
|
|
4077 | |
|
|
4078 | if (match) |
|
|
4079 | { |
|
|
4080 | b = match->data; |
|
|
4081 | //fprintf(stderr, "relid:%lld(%d) parentid:%lld(%d)\n", rid, admin_l, item_bin_get_relationid(b->ib), max_admin_l); |
|
|
4082 | |
|
|
4083 | sqlite3_bind_int64(stmt_bd_003, 1, item_bin_get_relationid(b->ib)); |
|
|
4084 | sqlite3_bind_int64(stmt_bd_003, 2, rid); |
|
|
4085 | sqlite3_step(stmt_bd_003); |
|
|
4086 | sqlite3_reset(stmt_bd_003); |
|
|
4087 | } |
|
|
4088 | |
|
|
4089 | |
|
|
4090 | if (count == 0) |
|
|
4091 | { |
|
|
4092 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
4093 | } |
|
|
4094 | count++; |
|
|
4095 | |
|
|
4096 | if (count > commit_after) |
|
|
4097 | { |
|
|
4098 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4099 | count = 0; |
|
|
4100 | } |
|
|
4101 | |
|
|
4102 | break; |
|
|
4103 | default: |
|
|
4104 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
4105 | break; |
|
|
4106 | } |
|
|
4107 | } |
|
|
4108 | while (rc == SQLITE_ROW); |
|
|
4109 | sqlite3_reset(stmt_bd_002); |
|
|
4110 | |
|
|
4111 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4112 | } |
|
|
4113 | |
|
|
4114 | void add_boundary_to_db(long long current_id, int admin_level, struct item_bin *item_bin_3, struct relation_member *memb) |
|
|
4115 | { |
|
|
4116 | char *str = NULL; |
|
|
4117 | struct node_lat_lon node_coords; |
|
|
4118 | |
|
|
4119 | sqlite3_bind_int64(stmt_bd_001, 1, current_id); |
|
|
4120 | |
|
|
4121 | if (admin_level < 2) |
|
|
4122 | { |
|
|
4123 | sqlite3_bind_int(stmt_bd_001, 2, 9999); |
|
|
4124 | } |
|
|
4125 | else |
|
|
4126 | { |
|
|
4127 | sqlite3_bind_int(stmt_bd_001, 2, admin_level); |
|
|
4128 | } |
|
|
4129 | |
|
|
4130 | while ((str = item_bin_get_attr(item_bin_3, attr_osm_member, str))) |
|
|
4131 | { |
|
|
4132 | if (get_relation_member(str, memb)) |
|
|
4133 | { |
|
|
4134 | if (memb->type == 2) |
|
|
4135 | { |
|
|
4136 | // way-id is "memb.id" |
|
|
4137 | // use the first nodes coords |
|
|
4138 | get_lat_lon_way_first_node(memb->id, &node_coords); |
|
|
4139 | if (node_coords.valid == 1) |
|
|
4140 | { |
|
|
4141 | sqlite3_bind_double(stmt_bd_001, 3, node_coords.lat); |
|
|
4142 | sqlite3_bind_double(stmt_bd_001, 4, node_coords.lon); |
|
|
4143 | } |
|
|
4144 | break; |
|
|
4145 | } |
|
|
4146 | } |
|
|
4147 | } |
|
|
4148 | sqlite3_bind_text(stmt_bd_001, 5, osm_tag_value(item_bin_3, "name"), -1, SQLITE_STATIC); |
|
|
4149 | sqlite3_step(stmt_bd_001); |
|
|
4150 | sqlite3_reset(stmt_bd_001); |
|
|
4151 | } |
|
|
4152 | |
|
|
4153 | |
1591 | osm_add_member(int type, osmid ref, char *role) |
4154 | void osm_add_member(int type, osmid ref, char *role) |
1592 | { |
4155 | { |
1593 | char member_buffer[BUFFER_SIZE*3+3]; |
4156 | char member_buffer[BUFFER_SIZE * 3 + 3]; |
1594 | struct attr memberattr = { attr_osm_member }; |
4157 | struct attr memberattr = { attr_osm_member }; |
1595 | |
4158 | |
1596 | sprintf(member_buffer,"%d:"LONGLONG_FMT":%s", type, (long long) ref, role); |
4159 | sprintf(member_buffer,"%d:"LONGLONG_FMT":%s", type, (long long) ref, role); |
1597 | memberattr.u.str=member_buffer; |
4160 | memberattr.u.str = member_buffer; |
1598 | item_bin_add_attr(item_bin, &memberattr); |
4161 | item_bin_add_attr(item_bin_2, &memberattr); |
1599 | } |
4162 | } |
1600 | |
4163 | |
1601 | static void |
|
|
1602 | relation_add_tag(char *k, char *v) |
4164 | static void relation_add_tag(char *k, char *v) |
1603 | { |
4165 | { |
1604 | int add_tag=1; |
4166 | int add_tag = 1; |
1605 | #if 0 |
4167 | #if 0 |
1606 | fprintf(stderr,"add tag %s %s\n",k,v); |
4168 | fprintf(stderr,"add tag %s %s\n",k,v); |
1607 | #endif |
4169 | #endif |
1608 | if (!strcmp(k,"type")) { |
4170 | if (!strcmp(k, "type")) |
|
|
4171 | { |
1609 | strcpy(relation_type, v); |
4172 | strcpy(relation_type, v); |
1610 | add_tag=0; |
4173 | add_tag = 0; |
1611 | } |
4174 | } |
1612 | else if (!strcmp(k,"restriction")) { |
4175 | else if (!strcmp(k, "restriction")) |
|
|
4176 | { |
1613 | if (!strncmp(v,"no_",3)) { |
4177 | if (!strncmp(v, "no_", 3)) |
|
|
4178 | { |
1614 | item_bin->type=type_street_turn_restriction_no; |
4179 | item_bin_2->type = type_street_turn_restriction_no; |
1615 | add_tag=0; |
4180 | add_tag = 0; |
|
|
4181 | } |
1616 | } else if (!strncmp(v,"only_",5)) { |
4182 | else if (!strncmp(v, "only_", 5)) |
|
|
4183 | { |
1617 | item_bin->type=type_street_turn_restriction_only; |
4184 | item_bin_2->type = type_street_turn_restriction_only; |
1618 | add_tag=0; |
4185 | add_tag = 0; |
|
|
4186 | } |
1619 | } else { |
4187 | else |
|
|
4188 | { |
1620 | item_bin->type=type_none; |
4189 | item_bin_2->type = type_none; |
1621 | osm_warning("relation", current_id, 0, "Unknown restriction %s\n",v); |
4190 | //osm_warning("relation", current_id, 0, "Unknown restriction %s\n", v); |
|
|
4191 | } |
1622 | } |
4192 | } |
1623 | } else if (!strcmp(k,"admin_level")) { |
4193 | else if (!strcmp(k, "admin_level")) |
|
|
4194 | { |
1624 | admin_level=atoi(v); |
4195 | admin_level = atoi(v); |
|
|
4196 | } |
1625 | } else if (!strcmp(k,"boundary")) { |
4197 | else if (!strcmp(k, "boundary")) |
|
|
4198 | { |
1626 | if (!strcmp(v,"administrative") || (experimental && !strcmp(v,"postal_code"))) { |
4199 | if (!strcmp(v, "administrative") || (experimental && !strcmp(v, "postal_code"))) |
|
|
4200 | { |
1627 | boundary=1; |
4201 | boundary = 1; |
|
|
4202 | } |
1628 | } |
4203 | } |
1629 | } else if (!strcmp(k,"ISO3166-1")) { |
4204 | else if (!strcmp(k, "ISO3166-1")) |
|
|
4205 | { |
1630 | strcpy(iso_code, v); |
4206 | strcpy(iso_code, v); |
1631 | } |
4207 | } |
|
|
4208 | |
1632 | if (add_tag) { |
4209 | if (add_tag) |
|
|
4210 | { |
|
|
4211 | //fprintf(stderr,"*TAG*%s=%s\n", k, v); |
1633 | char tag[strlen(k)+strlen(v)+2]; |
4212 | char tag[strlen(k) + strlen(v) + 2]; |
1634 | sprintf(tag,"%s=%s",k,v); |
4213 | sprintf(tag, "%s=%s", k, v); |
1635 | item_bin_add_attr_string(item_bin, attr_osm_tag, tag); |
4214 | item_bin_add_attr_string(item_bin_2, attr_osm_tag, tag); |
1636 | } |
4215 | } |
1637 | } |
4216 | } |
1638 | |
4217 | |
1639 | |
|
|
1640 | static int |
|
|
1641 | attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count) |
4218 | static int attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count) |
1642 | { |
4219 | { |
1643 | int i,j,longest=0,ret=0,sum,val; |
4220 | int i, j, longest = 0, ret = 0, sum, val; |
1644 | struct attr_mapping *curr; |
4221 | struct attr_mapping *curr; |
1645 | for (i = 0 ; i < mapping_count ; i++) { |
4222 | for (i = 0; i < mapping_count; i++) |
|
|
4223 | { |
1646 | sum=0; |
4224 | sum = 0; |
1647 | curr=mapping[i]; |
4225 | curr = mapping[i]; |
1648 | for (j = 0 ; j < curr->attr_present_idx_count ; j++) { |
4226 | for (j = 0; j < curr->attr_present_idx_count; j++) |
|
|
4227 | { |
1649 | val=attr_present[curr->attr_present_idx[j]]; |
4228 | val = attr_present[curr->attr_present_idx[j]]; |
1650 | if (val) |
4229 | if (val) |
1651 | sum+=val; |
4230 | sum += val; |
1652 | else { |
4231 | else |
|
|
4232 | { |
1653 | sum=-1; |
4233 | sum = -1; |
1654 | break; |
4234 | break; |
1655 | } |
4235 | } |
1656 | } |
4236 | } |
1657 | if (sum > longest) { |
4237 | if (sum > longest) |
|
|
4238 | { |
1658 | longest=sum; |
4239 | longest = sum; |
1659 | ret=0; |
4240 | ret = 0; |
1660 | } |
4241 | } |
1661 | if (sum > 0 && sum == longest && ret < types_count) |
4242 | if (sum > 0 && sum == longest && ret < types_count) |
1662 | types[ret++]=curr->type; |
4243 | types[ret++] = curr->type; |
1663 | } |
4244 | } |
1664 | return ret; |
4245 | return ret; |
1665 | } |
4246 | } |
1666 | |
4247 | |
1667 | static void |
|
|
1668 | attr_longest_match_clear(void) |
4248 | static void attr_longest_match_clear(void) |
1669 | { |
4249 | { |
1670 | memset(attr_present, 0, sizeof(*attr_present)*attr_present_count); |
4250 | memset(attr_present, 0, sizeof(*attr_present) * attr_present_count); |
1671 | } |
4251 | } |
1672 | |
4252 | |
1673 | void |
4253 | char* remove_all_spaces_non_utf8(char *str) |
|
|
4254 | { |
|
|
4255 | char *write = str, *read = str; |
|
|
4256 | |
|
|
4257 | if (str == NULL) |
|
|
4258 | { |
|
|
4259 | return NULL; |
|
|
4260 | } |
|
|
4261 | |
|
|
4262 | do |
|
|
4263 | { |
|
|
4264 | if (!g_ascii_isspace(*read)) |
|
|
4265 | { |
|
|
4266 | *write++ = *read; |
|
|
4267 | } |
|
|
4268 | } while (*read++); |
|
|
4269 | |
|
|
4270 | return str; |
|
|
4271 | } |
|
|
4272 | |
|
|
4273 | |
|
|
4274 | char* get_index_for_string(const char *in) |
|
|
4275 | { |
|
|
4276 | // first letters for indexing faster later |
|
|
4277 | char *sub = g_strndup(in, 2); |
|
|
4278 | |
|
|
4279 | |
|
|
4280 | // check first letter |
|
|
4281 | if (strlen(sub) > 0) |
|
|
4282 | { |
|
|
4283 | if ((sub[0] < 97) || (sub[0]) > 122) |
|
|
4284 | { |
|
|
4285 | sub[0]='\0'; |
|
|
4286 | // fprintf(stderr, "(1)in=%s sub=%s\n", in, sub); |
|
|
4287 | return sub; |
|
|
4288 | } |
|
|
4289 | } |
|
|
4290 | |
|
|
4291 | // if second letter != a-z then delete it from index |
|
|
4292 | if (strlen(sub) > 1) |
|
|
4293 | { |
|
|
4294 | // 'a' 'z' |
|
|
4295 | if ((sub[1] < 97) || (sub[1]) > 122) |
|
|
4296 | { |
|
|
4297 | sub[1]='\0'; |
|
|
4298 | } |
|
|
4299 | } |
|
|
4300 | |
|
|
4301 | // fprintf(stderr, "(2)in=%s sub=%s\n", in, sub); |
|
|
4302 | return sub; |
|
|
4303 | } |
|
|
4304 | |
1674 | osm_end_way(struct maptool_osm *osm) |
4305 | void osm_end_way(struct maptool_osm *osm) |
1675 | { |
4306 | { |
1676 | int i,count; |
4307 | int i, count; |
1677 | int *def_flags,add_flags; |
4308 | int *def_flags, add_flags; |
1678 | enum item_type types[10]; |
4309 | enum item_type types[10]; |
1679 | struct item_bin *item_bin; |
4310 | struct item_bin *item_bin; |
1680 | int count_lines=0, count_areas=0; |
4311 | int count_lines = 0, count_areas = 0; |
|
|
4312 | int dont_save_to_db = 1; |
|
|
4313 | int first = 1; |
|
|
4314 | int retval; |
|
|
4315 | char *name_folded = NULL; |
|
|
4316 | char *name_folded2 = NULL; |
|
|
4317 | struct node_lat_lon node_coords; |
|
|
4318 | osmid w_node; |
1681 | |
4319 | |
1682 | in_way=0; |
4320 | in_way = 0; |
1683 | |
4321 | |
1684 | if (! osm->ways) |
4322 | if (!osm->ways) |
1685 | { |
4323 | { |
1686 | return; |
4324 | return; |
1687 | } |
4325 | } |
1688 | |
4326 | |
1689 | if (dedupe_ways_hash) |
4327 | ways_processed_count++; |
1690 | { |
|
|
1691 | if (g_hash_table_lookup(dedupe_ways_hash, (gpointer)(long)wayid)) |
|
|
1692 | return; |
|
|
1693 | g_hash_table_insert(dedupe_ways_hash, (gpointer)(long)wayid, (gpointer)1); |
|
|
1694 | } |
|
|
1695 | |
4328 | |
1696 | count=attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types)/sizeof(enum item_type)); |
4329 | count = attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types) / sizeof(enum item_type)); |
1697 | if (!count) |
4330 | if (!count) |
1698 | { |
4331 | { |
1699 | count=1; |
4332 | count = 1; |
1700 | types[0]=type_street_unkn; |
4333 | types[0] = type_street_unkn; |
1701 | } |
4334 | } |
|
|
4335 | |
1702 | if (count >= 10) |
4336 | if (count >= 10) |
1703 | { |
4337 | { |
1704 | fprintf(stderr,"way id %ld\n",osmid_attr_value); |
4338 | fprintf(stderr, "way id %lld\n", osmid_attr_value); |
1705 | dbg_assert(count < 10); |
4339 | dbg_assert(count < 10); |
1706 | } |
4340 | } |
1707 | for (i = 0 ; i < count ; i++) |
4341 | |
|
|
4342 | if (attr_strings[attr_string_label] != NULL) |
|
|
4343 | { |
|
|
4344 | if (strlen(attr_strings[attr_string_label]) > 0) |
1708 | { |
4345 | { |
|
|
4346 | dont_save_to_db = 0; |
|
|
4347 | } |
|
|
4348 | } |
|
|
4349 | |
|
|
4350 | // required for fread to work! |
|
|
4351 | fseeko(ways_ref_file, 0L, SEEK_CUR); |
|
|
4352 | |
|
|
4353 | for (i = 0; i < count; i++) // loop thru all the attributes of this way (and add a way for every attribute known -> so ways get duplicated here!!) |
|
|
4354 | { |
1709 | add_flags=0; |
4355 | add_flags = 0; |
1710 | if (types[i] == type_none) |
4356 | if (types[i] == type_none) |
|
|
4357 | { |
1711 | continue; |
4358 | continue; |
|
|
4359 | } |
|
|
4360 | |
1712 | if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) |
4361 | //if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) |
|
|
4362 | // continue; |
|
|
4363 | |
|
|
4364 | // DO NOT exclude unknown streets here, or city-to-countrypolygon matching won't work!! |
|
|
4365 | if (ignore_unkown && (types[i] == type_point_unkn)) |
|
|
4366 | { |
1713 | continue; |
4367 | continue; |
|
|
4368 | } |
|
|
4369 | |
1714 | if (types[i] != type_street_unkn) |
4370 | if (types[i] != type_street_unkn) |
1715 | { |
4371 | { |
1716 | if(types[i]<type_area) |
4372 | if (types[i] < type_area) |
|
|
4373 | { |
1717 | count_lines++; |
4374 | count_lines++; |
|
|
4375 | } |
1718 | else |
4376 | else |
|
|
4377 | { |
1719 | count_areas++; |
4378 | count_areas++; |
1720 | } |
4379 | } |
|
|
4380 | } |
1721 | item_bin=init_item(types[i]); |
4381 | item_bin = init_item(types[i], 0); |
1722 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
4382 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
1723 | nodes_ref_item_bin(item_bin); |
|
|
1724 | def_flags=item_get_default_flags(types[i]); |
4383 | def_flags = item_get_default_flags(types[i]); |
|
|
4384 | |
|
|
4385 | // save nodes of way ----------------- |
|
|
4386 | // save nodes of way ----------------- |
|
|
4387 | if (first == 1) |
|
|
4388 | { |
|
|
4389 | first = 0; |
|
|
4390 | int i788 = 0; |
|
|
4391 | struct coord *c788 = (struct coord *) (item_bin + 1); // set pointer to coord struct of this item |
|
|
4392 | for (i788 = 0; i788 < item_bin->clen / 2; i788++) |
|
|
4393 | { |
|
|
4394 | if (dont_save_to_db == 0) |
|
|
4395 | { |
|
|
4396 | // save lat,lon of first node of this way |
|
|
4397 | if (i788 == 0) |
|
|
4398 | { |
|
|
4399 | #ifdef MAPTOOL_USE_SQL |
|
|
4400 | //fprintf(stderr, "insert -w\n"); |
|
|
4401 | //fprintf(stderr, "ways DEBUG: wid:%ld\n", osmid_attr_value); |
|
|
4402 | //fprintf(stderr, "ways DEBUG: nid:%lld\n", first_node_of_current_way); |
|
|
4403 | get_lat_lon_for_node(first_node_of_current_way, &node_coords); |
|
|
4404 | |
|
|
4405 | if (sql_counter == 0) |
|
|
4406 | { |
|
|
4407 | retval = sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
4408 | if ((retval > 0) && (retval < 100)) |
|
|
4409 | { |
|
|
4410 | fprintf(stderr, "begin: ways code:%d\n", retval); |
|
|
4411 | } |
|
|
4412 | else |
|
|
4413 | { |
|
|
4414 | //fprintf(stderr, "begin: ways\n"); |
|
|
4415 | } |
|
|
4416 | } |
|
|
4417 | |
|
|
4418 | sql_counter++; |
|
|
4419 | |
|
|
4420 | sqlite3_bind_int64(stmt_way, 1, osmid_attr_value); |
|
|
4421 | sqlite3_bind_text(stmt_way, 2, attr_strings[attr_string_label], -1, SQLITE_STATIC); |
|
|
4422 | |
|
|
4423 | // streetname folded for later sort/search |
|
|
4424 | char *sub = NULL; |
|
|
4425 | name_folded = linguistics_casefold(attr_strings[attr_string_label]); |
|
|
4426 | if (name_folded) |
|
|
4427 | { |
|
|
4428 | name_folded2 = linguistics_remove_all_specials(name_folded); |
|
|
4429 | if (name_folded2) |
|
|
4430 | { |
|
|
4431 | g_free(name_folded); |
|
|
4432 | name_folded = name_folded2; |
|
|
4433 | } |
|
|
4434 | |
|
|
4435 | name_folded2 = linguistics_expand_special(name_folded, 1); |
|
|
4436 | if (name_folded2) |
|
|
4437 | { |
|
|
4438 | sqlite3_bind_text(stmt_way, 6, name_folded2, -1, SQLITE_STATIC); |
|
|
4439 | sub = get_index_for_string(name_folded2); |
|
|
4440 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
4441 | } |
|
|
4442 | else |
|
|
4443 | { |
|
|
4444 | sqlite3_bind_text(stmt_way, 6, name_folded, -1, SQLITE_STATIC); |
|
|
4445 | sub = get_index_for_string(name_folded); |
|
|
4446 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
4447 | } |
|
|
4448 | } |
|
|
4449 | else |
|
|
4450 | { |
|
|
4451 | // use original string |
|
|
4452 | sqlite3_bind_text(stmt_way, 6, attr_strings[attr_string_label], -1, SQLITE_STATIC); |
|
|
4453 | sub = get_index_for_string(attr_strings[attr_string_label]); |
|
|
4454 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
|
|
4455 | } |
|
|
4456 | |
|
|
4457 | // town id |
|
|
4458 | sqlite3_bind_int(stmt_way, 3, -1); |
|
|
4459 | |
|
|
4460 | if (node_coords.valid == 1) |
|
|
4461 | { |
|
|
4462 | // lat |
|
|
4463 | sqlite3_bind_double(stmt_way, 4, node_coords.lat); |
|
|
4464 | // lon |
|
|
4465 | sqlite3_bind_double(stmt_way, 5, node_coords.lon); |
|
|
4466 | } |
|
|
4467 | |
|
|
4468 | // retval = |
|
|
4469 | sqlite3_step(stmt_way); |
|
|
4470 | //if ((retval > 0) && (retval < 100)) |
|
|
4471 | //{ |
|
|
4472 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
|
|
4473 | //} |
|
|
4474 | sqlite3_reset(stmt_way); |
|
|
4475 | |
|
|
4476 | if (name_folded) |
|
|
4477 | { |
|
|
4478 | g_free(name_folded); |
|
|
4479 | } |
|
|
4480 | |
|
|
4481 | if (name_folded2) |
|
|
4482 | { |
|
|
4483 | g_free(name_folded2); |
|
|
4484 | } |
|
|
4485 | |
|
|
4486 | if (sub) |
|
|
4487 | { |
|
|
4488 | g_free(sub); |
|
|
4489 | } |
|
|
4490 | |
|
|
4491 | if (sql_counter > MAX_ROWS_WO_COMMIT_3) |
|
|
4492 | { |
|
|
4493 | sql_counter = 0; |
|
|
4494 | retval = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
4495 | if ((retval > 0) && (retval < 100)) |
|
|
4496 | { |
|
|
4497 | fprintf(stderr, "ways: %lld code:%d\n", ways_processed_count, retval); |
|
|
4498 | } |
|
|
4499 | else |
|
|
4500 | { |
|
|
4501 | //fprintf(stderr, "ways: %lld\n", ways_processed_count); |
|
|
4502 | } |
|
|
4503 | } |
|
|
4504 | #endif |
|
|
4505 | // set ref file to start of waynodes of current way |
|
|
4506 | // fprintf(stderr, "w seek1 pos=%lld\n", seekpos1); |
|
|
4507 | fseeko(ways_ref_file, (off_t)seekpos1, SEEK_SET); |
|
|
4508 | } |
|
|
4509 | // save all the way nodes for streets |
|
|
4510 | int fret = (int)fread(&w_node, sizeof(osmid), 1, ways_ref_file); |
|
|
4511 | if (fret == 0) |
|
|
4512 | { |
|
|
4513 | fprintf(stderr, "**ERROR** at fread 001a: wayid:%lld count=%d\n", osmid_attr_value, (int)i788); |
|
|
4514 | } |
|
|
4515 | else if ((osmid)w_node > 4994968164L) |
|
|
4516 | { |
|
|
4517 | fprintf(stderr, "**ERROR** at fread 001b: wayid:%lld count=%d w_node=%lld\n", osmid_attr_value, (int)i788, (osmid)w_node); |
|
|
4518 | } |
|
|
4519 | // fprintf(stderr, "at fread: w_node:%lld\n", (osmid)w_node); |
|
|
4520 | add_waynode_to_db((osmid)w_node, (int)i788); |
|
|
4521 | } |
|
|
4522 | else |
|
|
4523 | { |
|
|
4524 | // save all the waynodes to db |
|
|
4525 | if (i788 == 0) |
|
|
4526 | { |
|
|
4527 | // set ref file to start of waynodes of current way |
|
|
4528 | // fprintf(stderr, "w seek1.1 pos=%lld\n", seekpos1); |
|
|
4529 | fseeko(ways_ref_file, (off_t)seekpos1, SEEK_SET); |
|
|
4530 | } |
|
|
4531 | |
|
|
4532 | int fret = (int)fread(&w_node, sizeof(osmid), 1, ways_ref_file); |
|
|
4533 | if (fret == 0) |
|
|
4534 | { |
|
|
4535 | fprintf(stderr, "**ERROR** at fread 001.1a: wayid:%lld count=%d\n", osmid_attr_value, (int)i788); |
|
|
4536 | } |
|
|
4537 | else if ((osmid)w_node > 4994968164L) |
|
|
4538 | { |
|
|
4539 | fprintf(stderr, "**ERROR** at fread 001.1b: wayid:%lld count=%d w_node=%lld\n", osmid_attr_value, (int)i788, (osmid)w_node); |
|
|
4540 | } |
|
|
4541 | add_waynode_to_db((osmid)w_node, (int)i788); |
|
|
4542 | } |
|
|
4543 | } |
|
|
4544 | |
|
|
4545 | if (dont_save_to_db == 0) |
|
|
4546 | { |
|
|
4547 | // seek to end of file (this should not be needed, because we read values until EOF anyway) |
|
|
4548 | // fprintf(stderr, "w seek2\n"); |
|
|
4549 | fseeko(ways_ref_file, 0, SEEK_END); |
|
|
4550 | } |
|
|
4551 | } |
|
|
4552 | // save nodes of way ----------------- |
|
|
4553 | // save nodes of way ----------------- |
|
|
4554 | |
|
|
4555 | |
1725 | if (def_flags) |
4556 | if (def_flags) |
1726 | { |
4557 | { |
1727 | flags_attr_value=(*def_flags | flags[0] | flags[1]) & ~flags[2]; |
4558 | flags_attr_value = (*def_flags | flags[0] | flags[1]) & ~flags[2]; |
|
|
4559 | // only add flags if they differ from the default flags!! |
1728 | if (flags_attr_value != *def_flags) |
4560 | if (flags_attr_value != *def_flags) |
|
|
4561 | { |
1729 | add_flags=1; |
4562 | add_flags = 1; |
|
|
4563 | } |
|
|
4564 | } |
|
|
4565 | else // maybe should explicitly specify which "types" to consider? now its all "types" |
|
|
4566 | { |
|
|
4567 | def_flags = 0; |
|
|
4568 | flags_attr_value = (flags[0] | flags[1]) & ~flags[2]; |
|
|
4569 | |
|
|
4570 | // only add flags if we really have a value |
|
|
4571 | if (flags_attr_value != 0) |
|
|
4572 | { |
|
|
4573 | add_flags = 1; |
|
|
4574 | } |
1730 | } |
4575 | } |
1731 | item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]); |
4576 | item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]); |
|
|
4577 | |
|
|
4578 | // housenumber from buildings -------------------- |
|
|
4579 | if (types[i] == type_poly_building) |
|
|
4580 | { |
|
|
4581 | // addr:street |
|
|
4582 | item_bin_add_attr_string(item_bin, attr_street_name_dummy, attr_strings[attr_string_street_name]); |
|
|
4583 | // fprintf(stderr, "addr:street :%s\n", attr_strings[attr_string_street_name]); |
|
|
4584 | // addr:housenumber |
|
|
4585 | item_bin_add_attr_string(item_bin, attr_house_number_dummy, attr_strings[attr_string_house_number]); |
|
|
4586 | // fprintf(stderr, "addr:housenumber:%s\n", attr_strings[attr_string_house_number]); |
|
|
4587 | } |
|
|
4588 | // housenumber from buildings -------------------- |
|
|
4589 | |
|
|
4590 | |
|
|
4591 | if (attr_strings[attr_string_label_alt]) |
|
|
4592 | { |
|
|
4593 | item_bin_add_attr_string(item_bin, attr_street_name_match, attr_strings[attr_string_label_alt]); |
|
|
4594 | if (debug_itembin(ib)) |
|
|
4595 | { |
|
|
4596 | fprintf(stderr, "street name : %s\n", attr_strings[attr_string_label]); |
|
|
4597 | fprintf(stderr, "street name sys: %s\n", attr_strings[attr_string_street_name_systematic]); |
|
|
4598 | fprintf(stderr, "street name alt: %s\n", attr_strings[attr_string_label_alt]); |
|
|
4599 | } |
|
|
4600 | } |
1732 | item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]); |
4601 | item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]); |
|
|
4602 | |
1733 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
4603 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
1734 | if (debug_attr_buffer[0]) |
4604 | if (debug_attr_buffer[0]) |
1735 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
4605 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
1736 | if (add_flags) |
4606 | if (add_flags) |
1737 | item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); |
4607 | item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); |
1738 | if (maxspeed_attr_value) |
4608 | if (maxspeed_attr_value) |
1739 | item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); |
4609 | item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); |
1740 | |
4610 | |
1741 | // with special match |
4611 | |
1742 | // **buggy** item_bin_write_match(item_bin, attr_street_name, attr_street_name_match, osm->ways); |
4612 | // custom color attribute |
1743 | // just original string |
4613 | if (attr_strings[attr_string_colour_]) |
|
|
4614 | { |
|
|
4615 | unsigned int cc = color_int_value_from_string(attr_strings[attr_string_colour_]); |
|
|
4616 | //fprintf(stderr, "col:ret=%d\n", cc); |
|
|
4617 | if (cc != 0) |
|
|
4618 | { |
|
|
4619 | cc = (cc >> 8); |
|
|
4620 | //fprintf(stderr, "col:in map=%d\n", (int)cc); |
|
|
4621 | item_bin_add_attr_int(item_bin, attr_colour2, (int)cc); |
|
|
4622 | } |
|
|
4623 | } |
|
|
4624 | |
|
|
4625 | // if we duplicated this way here (because of multiple attributes), then set "duplicate_way" attr |
|
|
4626 | if (i > 0) |
|
|
4627 | { |
|
|
4628 | item_bin_add_attr_int(item_bin, attr_duplicate_way, 1); |
|
|
4629 | //fprintf(stderr, "attr_duplicate_way:1: dup=true wayid=%lld\n", item_bin_get_wayid(item_bin)); |
|
|
4630 | } |
|
|
4631 | |
1744 | item_bin_write(item_bin,osm->ways); |
4632 | item_bin_write(item_bin, osm->ways); |
|
|
4633 | |
|
|
4634 | if (border_only_map_as_xml == 1) |
|
|
4635 | { |
|
|
4636 | item_bin_write_xml(item_bin, "borders.xml"); |
|
|
4637 | } |
1745 | } |
4638 | } |
1746 | |
4639 | |
1747 | /* |
4640 | /* |
1748 | if(osm->line2poi) { |
4641 | if(osm->line2poi) { |
1749 | count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type)); |
4642 | count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type)); |
1750 | dbg_assert(count < 10); |
4643 | dbg_assert(count < 10); |
1751 | for (i = 0 ; i < count ; i++) { |
4644 | for (i = 0 ; i < count ; i++) { |
1752 | if (types[i] == type_none || types[i] == type_point_unkn) |
4645 | if (types[i] == type_none || types[i] == type_point_unkn) |
1753 | continue; |
4646 | continue; |
1754 | item_bin=init_item(types[i]); |
4647 | item_bin=init_item(types[i], 0); |
1755 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
4648 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
1756 | item_bin_add_attr_string(item_bin, attr_label, attr_strings[attr_string_label]); |
4649 | item_bin_add_attr_string(item_bin, attr_label, attr_strings[attr_string_label]); |
1757 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
4650 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
1758 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
4651 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
1759 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
4652 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
1760 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
4653 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
1761 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
4654 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
1762 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
4655 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
1763 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
4656 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
1764 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
4657 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
1765 | item_bin_write(item_bin, count_areas<count_lines?osm->line2poi:osm->poly2poi); |
4658 | item_bin_write(item_bin, count_areas<count_lines?osm->line2poi:osm->poly2poi); |
1766 | } |
|
|
1767 | } |
4659 | } |
|
|
4660 | } |
1768 | */ |
4661 | */ |
1769 | |
4662 | |
1770 | attr_longest_match_clear(); |
4663 | attr_longest_match_clear(); |
1771 | } |
4664 | } |
1772 | |
4665 | |
1773 | void |
4666 | static struct css_color css_cols[]= { |
|
|
4667 | {"aliceblue",0xf0f8ff}, |
|
|
4668 | {"antiquewhite",0xfaebd7}, |
|
|
4669 | {"aqua",0x00ffff}, |
|
|
4670 | {"aquamarine",0x7fffd4}, |
|
|
4671 | {"azure",0xf0ffff}, |
|
|
4672 | {"beige",0xf5f5dc}, |
|
|
4673 | {"bisque",0xffe4c4}, |
|
|
4674 | {"black",0x000000}, |
|
|
4675 | {"blanchedalmond",0xffebcd}, |
|
|
4676 | {"blue",0x0000ff}, |
|
|
4677 | {"blueviolet",0x8a2be2}, |
|
|
4678 | {"brown",0xa52a2a}, |
|
|
4679 | {"burlywood",0xdeb887}, |
|
|
4680 | {"cadetblue",0x5f9ea0}, |
|
|
4681 | {"chartreuse",0x7fff00}, |
|
|
4682 | {"chocolate",0xd2691e}, |
|
|
4683 | {"coral",0xff7f50}, |
|
|
4684 | {"cornflowerblue",0x6495ed}, |
|
|
4685 | {"cornsilk",0xfff8dc}, |
|
|
4686 | {"crimson",0xdc143c}, |
|
|
4687 | {"cyan",0x00ffff}, |
|
|
4688 | {"darkblue",0x00008b}, |
|
|
4689 | {"darkcyan",0x008b8b}, |
|
|
4690 | {"darkgoldenrod",0xb8860b}, |
|
|
4691 | {"darkgray",0xa9a9a9}, |
|
|
4692 | {"darkgreen",0x006400}, |
|
|
4693 | {"darkkhaki",0xbdb76b}, |
|
|
4694 | {"darkmagenta",0x8b008b}, |
|
|
4695 | {"darkolivegreen",0x556b2f}, |
|
|
4696 | {"darkorange",0xff8c00}, |
|
|
4697 | {"darkorchid",0x9932cc}, |
|
|
4698 | {"darkred",0x8b0000}, |
|
|
4699 | {"darksalmon",0xe9967a}, |
|
|
4700 | {"darkseagreen",0x8fbc8f}, |
|
|
4701 | {"darkslateblue",0x483d8b}, |
|
|
4702 | {"darkslategray",0x2f4f4f}, |
|
|
4703 | {"darkturquoise",0x00ced1}, |
|
|
4704 | {"darkviolet",0x9400d3}, |
|
|
4705 | {"deeppink",0xff1493}, |
|
|
4706 | {"deepskyblue",0x00bfff}, |
|
|
4707 | {"dimgray",0x696969}, |
|
|
4708 | {"dodgerblue",0x1e90ff}, |
|
|
4709 | {"firebrick",0xb22222}, |
|
|
4710 | {"floralwhite",0xfffaf0}, |
|
|
4711 | {"forestgreen",0x228b22}, |
|
|
4712 | {"fuchsia",0xff00ff}, |
|
|
4713 | {"gainsboro",0xdcdcdc}, |
|
|
4714 | {"ghostwhite",0xf8f8ff}, |
|
|
4715 | {"gold",0xffd700}, |
|
|
4716 | {"goldenrod",0xdaa520}, |
|
|
4717 | {"gray",0x808080}, |
|
|
4718 | {"green",0x008000}, |
|
|
4719 | {"greenyellow",0xadff2f}, |
|
|
4720 | {"honeydew",0xf0fff0}, |
|
|
4721 | {"hotpink",0xff69b4}, |
|
|
4722 | {"indianred",0xcd5c5c}, |
|
|
4723 | {"indigo",0x4b0082}, |
|
|
4724 | {"ivory",0xfffff0}, |
|
|
4725 | {"khaki",0xf0e68c}, |
|
|
4726 | {"lavender",0xe6e6fa}, |
|
|
4727 | {"lavenderblush",0xfff0f5}, |
|
|
4728 | {"lawngreen",0x7cfc00}, |
|
|
4729 | {"lemonchiffon",0xfffacd}, |
|
|
4730 | {"lightblue",0xadd8e6}, |
|
|
4731 | {"lightcoral",0xf08080}, |
|
|
4732 | {"lightcyan",0xe0ffff}, |
|
|
4733 | {"lightgoldenrodyellow",0xfafad2}, |
|
|
4734 | {"lightgrey",0xd3d3d3}, |
|
|
4735 | {"lightgreen",0x90ee90}, |
|
|
4736 | {"lightpink",0xffb6c1}, |
|
|
4737 | {"lightsalmon",0xffa07a}, |
|
|
4738 | {"lightseagreen",0x20b2aa}, |
|
|
4739 | {"lightskyblue",0x87cefa}, |
|
|
4740 | {"lightslategray",0x778899}, |
|
|
4741 | {"lightsteelblue",0xb0c4de}, |
|
|
4742 | {"lightyellow",0xffffe0}, |
|
|
4743 | {"lime",0x00ff00}, |
|
|
4744 | {"limegreen",0x32cd32}, |
|
|
4745 | {"linen",0xfaf0e6}, |
|
|
4746 | {"magenta",0xff00ff}, |
|
|
4747 | {"maroon",0x800000}, |
|
|
4748 | {"mediumaquamarine",0x66cdaa}, |
|
|
4749 | {"mediumblue",0x0000cd}, |
|
|
4750 | {"mediumorchid",0xba55d3}, |
|
|
4751 | {"mediumpurple",0x9370d8}, |
|
|
4752 | {"mediumseagreen",0x3cb371}, |
|
|
4753 | {"mediumslateblue",0x7b68ee}, |
|
|
4754 | {"mediumspringgreen",0x00fa9a}, |
|
|
4755 | {"mediumturquoise",0x48d1cc}, |
|
|
4756 | {"mediumvioletred",0xc71585}, |
|
|
4757 | {"midnightblue",0x191970}, |
|
|
4758 | {"mintcream",0xf5fffa}, |
|
|
4759 | {"mistyrose",0xffe4e1}, |
|
|
4760 | {"moccasin",0xffe4b5}, |
|
|
4761 | {"navajowhite",0xffdead}, |
|
|
4762 | {"navy",0x000080}, |
|
|
4763 | {"oldlace",0xfdf5e6}, |
|
|
4764 | {"olive",0x808000}, |
|
|
4765 | {"olivedrab",0x6b8e23}, |
|
|
4766 | {"orange",0xffa500}, |
|
|
4767 | {"orangered",0xff4500}, |
|
|
4768 | {"orchid",0xda70d6}, |
|
|
4769 | {"palegoldenrod",0xeee8aa}, |
|
|
4770 | {"palegreen",0x98fb98}, |
|
|
4771 | {"paleturquoise",0xafeeee}, |
|
|
4772 | {"palevioletred",0xd87093}, |
|
|
4773 | {"papayawhip",0xffefd5}, |
|
|
4774 | {"peachpuff",0xffdab9}, |
|
|
4775 | {"peru",0xcd853f}, |
|
|
4776 | {"pink",0xffc0cb}, |
|
|
4777 | {"plum",0xdda0dd}, |
|
|
4778 | {"powderblue",0xb0e0e6}, |
|
|
4779 | {"purple",0x800080}, |
|
|
4780 | {"red",0xff0000}, |
|
|
4781 | {"rosybrown",0xbc8f8f}, |
|
|
4782 | {"royalblue",0x4169e1}, |
|
|
4783 | {"saddlebrown",0x8b4513}, |
|
|
4784 | {"salmon",0xfa8072}, |
|
|
4785 | {"sandybrown",0xf4a460}, |
|
|
4786 | {"seagreen",0x2e8b57}, |
|
|
4787 | {"seashell",0xfff5ee}, |
|
|
4788 | {"sienna",0xa0522d}, |
|
|
4789 | {"silver",0xc0c0c0}, |
|
|
4790 | {"skyblue",0x87ceeb}, |
|
|
4791 | {"slateblue",0x6a5acd}, |
|
|
4792 | {"slategray",0x708090}, |
|
|
4793 | {"snow",0xfffafa}, |
|
|
4794 | {"springgreen",0x00ff7f}, |
|
|
4795 | {"steelblue",0x4682b4}, |
|
|
4796 | {"tan",0xd2b48c}, |
|
|
4797 | {"teal",0x008080}, |
|
|
4798 | {"thistle",0xd8bfd8}, |
|
|
4799 | {"tomato",0xff6347}, |
|
|
4800 | {"turquoise",0x40e0d0}, |
|
|
4801 | {"violet",0xee82ee}, |
|
|
4802 | {"wheat",0xf5deb3}, |
|
|
4803 | {"white",0xffffff}, |
|
|
4804 | {"whitesmoke",0xf5f5f5}, |
|
|
4805 | {"yellow",0xffff00}, |
|
|
4806 | {"yellowgreen",0x9acd32}, |
|
|
4807 | }; |
|
|
4808 | |
|
|
4809 | |
|
|
4810 | unsigned int color_int_value_from_string(char* color_str) |
|
|
4811 | { |
|
|
4812 | int count = 0; |
|
|
4813 | unsigned int ret = 0; // 0 -> invalid color! |
|
|
4814 | struct css_color* c; |
|
|
4815 | |
|
|
4816 | for (count = 0;count < (sizeof(css_cols)/sizeof(struct css_color));count++) |
|
|
4817 | { |
|
|
4818 | c = &css_cols[count]; |
|
|
4819 | if (!strcmp(c->col_name, color_str)) |
|
|
4820 | { |
|
|
4821 | //fprintf(stderr, "col=%d\n", c->col_value); |
|
|
4822 | ret = (c->col_value << 8) | 0x1; // set alpha to 0x1 |
|
|
4823 | //fprintf(stderr, "col ret1=%d\n", ret); |
|
|
4824 | return ret; |
|
|
4825 | } |
|
|
4826 | } |
|
|
4827 | |
|
|
4828 | return ret; |
|
|
4829 | } |
|
|
4830 | |
|
|
4831 | |
|
|
4832 | void osm_append_housenumber_node(FILE *out, struct coord *c, char *house_number, char *street_name) |
|
|
4833 | { |
|
|
4834 | struct item_bin *item_bin; |
|
|
4835 | item_bin = init_item(type_house_number, 0); |
|
|
4836 | // item_bin->type = type_house_number; |
|
|
4837 | |
|
|
4838 | item_bin_add_coord(item_bin, c, 1); |
|
|
4839 | item_bin_add_attr_string(item_bin, attr_house_number, house_number); |
|
|
4840 | item_bin_add_attr_string(item_bin, attr_street_name, street_name); |
|
|
4841 | |
|
|
4842 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
4843 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
4844 | // dump_itembin(item_bin); |
|
|
4845 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
4846 | // DEBUG -- DEBUG -- DEBUG -- |
|
|
4847 | |
|
|
4848 | item_bin_write(item_bin, out); |
|
|
4849 | } |
|
|
4850 | |
1774 | osm_end_node(struct maptool_osm *osm) |
4851 | void osm_end_node(struct maptool_osm *osm) |
1775 | { |
4852 | { |
1776 | int count,i; |
4853 | int count, i; |
1777 | char *postal; |
4854 | char *postal; |
1778 | enum item_type types[10]; |
4855 | enum item_type types[10]; |
1779 | struct item_bin *item_bin; |
4856 | struct item_bin *item_bin; |
1780 | in_node=0; |
4857 | in_node = 0; |
1781 | |
4858 | |
1782 | if (!osm->nodes || ! node_is_tagged || ! nodeid) |
4859 | if (!osm->nodes || !node_is_tagged || !nodeid) |
1783 | return; |
4860 | return; |
|
|
4861 | |
1784 | count=attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types)/sizeof(enum item_type)); |
4862 | count = attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types) / sizeof(enum item_type)); |
|
|
4863 | |
1785 | if (!count) { |
4864 | if (!count) |
|
|
4865 | { |
1786 | types[0]=type_point_unkn; |
4866 | types[0] = type_point_unkn; |
1787 | count=1; |
4867 | count = 1; |
1788 | } |
4868 | } |
|
|
4869 | |
1789 | dbg_assert(count < 10); |
4870 | dbg_assert(count < 10); |
|
|
4871 | |
1790 | for (i = 0 ; i < count ; i++) { |
4872 | for (i = 0; i < count; i++) |
|
|
4873 | { |
1791 | if (types[i] == type_none) |
4874 | if (types[i] == type_none) |
|
|
4875 | { |
1792 | continue; |
4876 | continue; |
|
|
4877 | } |
|
|
4878 | |
1793 | if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) |
4879 | //if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) |
|
|
4880 | // continue; |
|
|
4881 | |
|
|
4882 | if (ignore_unkown && (types[i] == type_point_unkn)) |
|
|
4883 | { |
1794 | continue; |
4884 | continue; |
|
|
4885 | } |
|
|
4886 | |
1795 | item_bin=init_item(types[i]); |
4887 | item_bin = init_item(types[i], 0); |
1796 | |
4888 | |
1797 | if (item_is_town(*item_bin) && attr_strings[attr_string_label]) |
4889 | if (item_is_town(*item_bin) && attr_strings[attr_string_label]) |
1798 | { |
4890 | { |
1799 | if (debug_itembin(ib)) |
4891 | if (debug_itembin(ib)) |
1800 | { |
4892 | { |
1801 | fprintf(stderr,"osm_end_node: have town: %s\n", attr_strings[attr_string_label]); |
4893 | fprintf(stderr, "osm_end_node: have town: %s\n", attr_strings[attr_string_label]); |
|
|
4894 | } |
|
|
4895 | } |
|
|
4896 | |
|
|
4897 | if (item_is_district(*item_bin) && attr_strings[attr_string_label]) |
|
|
4898 | { |
|
|
4899 | if (debug_itembin(ib)) |
|
|
4900 | { |
|
|
4901 | fprintf(stderr, "osm_end_node: have district: %s\n", attr_strings[attr_string_label]); |
1802 | } |
4902 | } |
1803 | } |
4903 | } |
1804 | |
4904 | |
1805 | if (item_is_town(*item_bin) && attr_strings[attr_string_population]) |
4905 | if (item_is_town(*item_bin) && attr_strings[attr_string_population]) |
|
|
4906 | { |
1806 | item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population])); |
4907 | item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population])); |
|
|
4908 | } |
|
|
4909 | |
|
|
4910 | // dont forget to qualify districts |
|
|
4911 | if (item_is_district(*item_bin) && attr_strings[attr_string_population]) |
|
|
4912 | { |
|
|
4913 | item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population])); |
|
|
4914 | } |
|
|
4915 | |
1807 | item_bin_add_coord(item_bin, &ni->c, 1); |
4916 | item_bin_add_coord(item_bin, &ni->c, 1); |
1808 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]); |
4917 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]); |
1809 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
4918 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
1810 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
4919 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
1811 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
4920 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
1812 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
4921 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
1813 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
4922 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
1814 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
4923 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
1815 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
4924 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
1816 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
4925 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
1817 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
4926 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
|
|
4927 | |
1818 | postal=attr_strings[attr_string_postal]; |
4928 | postal = attr_strings[attr_string_postal]; |
1819 | if (postal) { |
4929 | if (postal) |
|
|
4930 | { |
1820 | char *sep=strchr(postal,','); |
4931 | char *sep = strchr(postal, ','); |
1821 | if (sep) |
4932 | if (sep) |
|
|
4933 | { |
1822 | *sep='\0'; |
4934 | *sep = '\0'; |
|
|
4935 | } |
1823 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal); |
4936 | item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal); |
1824 | } |
4937 | } |
|
|
4938 | |
1825 | item_bin_write(item_bin,osm->nodes); |
4939 | item_bin_write(item_bin, osm->nodes); |
|
|
4940 | |
1826 | if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) { |
4941 | if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) |
|
|
4942 | { |
1827 | item_bin=init_item(item_bin->type); |
4943 | item_bin = init_item(item_bin->type, 0); |
1828 | item_bin_add_coord(item_bin, &ni->c, 1); |
4944 | item_bin_add_coord(item_bin, &ni->c, 1); |
1829 | item_bin_add_attr_string(item_bin, attr_osm_is_in, is_in_buffer); |
4945 | item_bin_add_attr_string(item_bin, attr_osm_is_in, is_in_buffer); |
1830 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
4946 | item_bin_add_attr_longlong(item_bin, attr_osm_nodeid, osmid_attr_value); |
1831 | item_bin_add_attr_string(item_bin, attr_town_postal, postal); |
4947 | item_bin_add_attr_string(item_bin, attr_town_postal, postal); |
1832 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
4948 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
1833 | item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]); |
4949 | item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]); |
|
|
4950 | |
|
|
4951 | if (attr_strings[attr_string_label_alt]) |
|
|
4952 | { |
|
|
4953 | item_bin_add_attr_string(item_bin, attr_town_name_match, attr_strings[attr_string_label_alt]); |
|
|
4954 | if (debug_itembin(item_bin)) |
|
|
4955 | { |
|
|
4956 | fprintf(stderr, "town name : %s\n", attr_strings[attr_string_label]); |
|
|
4957 | fprintf(stderr, "town name alt: %s\n", attr_strings[attr_string_label_alt]); |
|
|
4958 | } |
|
|
4959 | } |
|
|
4960 | |
1834 | item_bin_write(item_bin, osm->towns); |
4961 | item_bin_write(item_bin, osm->towns); |
1835 | } |
4962 | } |
|
|
4963 | |
|
|
4964 | //fprintf(stderr,"********DUMP nd1***********\n"); |
|
|
4965 | //if (types[i] == type_house_number) |
|
|
4966 | //{ |
|
|
4967 | // dump_itembin(item_bin); |
|
|
4968 | //} |
|
|
4969 | //fprintf(stderr,"********DUMP nd1***********\n"); |
|
|
4970 | |
1836 | } |
4971 | } |
1837 | processed_nodes_out++; |
4972 | processed_nodes_out++; |
1838 | attr_longest_match_clear(); |
4973 | attr_longest_match_clear(); |
1839 | } |
4974 | } |
1840 | |
4975 | |
1841 | static struct country_table * |
4976 | static struct country_table * |
1842 | osm_process_town_unknown_country(void) |
4977 | osm_process_town_unknown_country(void) |
1843 | { |
4978 | { |
1844 | static struct country_table *unknown; |
4979 | static struct country_table *unknown; |
1845 | unknown=country_from_countryid(999); |
4980 | unknown = country_from_countryid(999); |
1846 | return unknown; |
4981 | return unknown; |
1847 | } |
4982 | } |
1848 | |
4983 | |
1849 | static struct country_table * |
4984 | static struct country_table * |
1850 | osm_process_item_fixed_country(void) |
4985 | osm_process_item_fixed_country(void) |
1851 | { |
4986 | { |
1852 | static struct country_table *fixed; |
4987 | static struct country_table *fixed; |
1853 | fixed=country_from_countryid(global_fixed_country_id); |
4988 | fixed = country_from_countryid(global_fixed_country_id); |
1854 | return fixed; |
4989 | return fixed; |
1855 | } |
4990 | } |
1856 | |
4991 | |
1857 | static struct country_table * |
4992 | static struct country_table * |
1858 | osm_process_town_by_is_in(struct item_bin *ib,char *is_in) |
4993 | osm_process_town_by_is_in(struct item_bin *ib, char *is_in) |
1859 | { |
4994 | { |
1860 | struct country_table *result=NULL, *lookup; |
4995 | struct country_table *result = NULL, *lookup; |
1861 | char *tok,*dup=g_strdup(is_in),*buf=dup; |
4996 | char *tok, *dup = g_strdup(is_in), *buf = dup; |
1862 | int conflict; |
4997 | int conflict; |
1863 | |
4998 | |
1864 | while ((tok=strtok(buf, ",;"))) |
4999 | while ((tok = strtok(buf, ",;"))) |
1865 | { |
5000 | { |
1866 | while (*tok==' ') |
5001 | while (*tok == ' ') |
1867 | { |
5002 | { |
1868 | tok++; |
5003 | tok++; |
1869 | } |
5004 | } |
1870 | lookup=g_hash_table_lookup(country_table_hash,tok); |
5005 | lookup = g_hash_table_lookup(country_table_hash, tok); |
1871 | if (lookup) |
5006 | if (lookup) |
1872 | { |
5007 | { |
1873 | if (result && result->countryid != lookup->countryid) |
5008 | if (result && result->countryid != lookup->countryid) |
1874 | { |
5009 | { |
1875 | char *label=item_bin_get_attr(ib, attr_town_name, NULL); |
5010 | //char *label = item_bin_get_attr(ib, attr_town_name, NULL); |
1876 | osm_warning("node",item_bin_get_nodeid(ib),0,"conflict for %s is_in=%s country %d vs %d\n", label, is_in, lookup->countryid, result->countryid); |
5011 | //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); |
1877 | conflict=1; |
5012 | conflict = 1; |
1878 | } |
5013 | } |
1879 | result=lookup; |
5014 | result = lookup; |
1880 | } |
5015 | } |
1881 | buf=NULL; |
5016 | buf = NULL; |
1882 | } |
5017 | } |
1883 | g_free(dup); |
5018 | g_free(dup); |
1884 | return result; |
5019 | return result; |
1885 | } |
5020 | } |
1886 | |
5021 | |
|
|
5022 | static int osm_process_street_by_boundary(GList *bl, long long town_osm_id, long long town_relation_id, struct coord *c) |
|
|
5023 | { |
|
|
5024 | GList *matches = NULL; |
|
|
5025 | |
|
|
5026 | matches = boundary_find_matches_single(bl, c); |
|
|
5027 | if (g_list_length(matches) > 0) |
|
|
5028 | { |
|
|
5029 | return 1; |
|
|
5030 | } |
|
|
5031 | |
|
|
5032 | return 0; |
|
|
5033 | } |
|
|
5034 | |
|
|
5035 | |
1887 | static struct country_table * |
5036 | static struct country_table * |
1888 | osm_process_town_by_boundary(GList *bl, struct item_bin *ib, struct coord *c, struct attr *attrs) |
5037 | osm_process_town_by_boundary(GList *bl, struct item_bin *ib, struct coord *c, struct attr *attrs) |
1889 | { |
5038 | { |
1890 | GList *l,*matches=boundary_find_matches(bl, c); |
5039 | GList *l, *matches = boundary_find_matches(bl, c); |
1891 | struct boundary *match=NULL; |
5040 | struct boundary *match = NULL; |
1892 | |
5041 | |
|
|
5042 | //fprintf(stderr,"town_by_boundary:001\n"); |
|
|
5043 | |
1893 | l=matches; |
5044 | l = matches; |
1894 | while (l) { |
5045 | while (l) |
|
|
5046 | { |
|
|
5047 | //fprintf(stderr,"town_by_boundary:002\n"); |
1895 | struct boundary *b=l->data; |
5048 | struct boundary *b = l->data; |
1896 | if (b->country) { |
5049 | if (b->country) |
|
|
5050 | { |
|
|
5051 | //fprintf(stderr,"town_by_boundary:003\n"); |
1897 | if (match) { |
5052 | //if (match) |
|
|
5053 | //{ |
1898 | //osm_warning("node",item_bin_get_nodeid(ib),0,"node (0x%x,0x%x) conflict country ", c->x, c->y); |
5054 | //osm_warning("node", item_bin_get_nodeid(ib), 0, "node (x=0x%x,y=0x%x) conflict country ", c->x, c->y); |
1899 | //osm_warning("relation",boundary_relid(match),1,"country %d vs ",match->country->countryid); |
5055 | //osm_warning("relation", boundary_relid(match), 1, "country %d vs ", match->country->countryid); |
1900 | //osm_warning("relation",boundary_relid(b),1,"country %d\n",b->country->countryid); |
5056 | //osm_warning("relation", boundary_relid(b), 1, "country %d\n", b->country->countryid); |
1901 | } |
5057 | //} |
1902 | match=b; |
5058 | match = b; |
1903 | } |
5059 | } |
1904 | l=g_list_next(l); |
5060 | l = g_list_next(l); |
1905 | } |
5061 | } |
|
|
5062 | |
|
|
5063 | //fprintf(stderr,"town_by_boundary:004\n"); |
|
|
5064 | |
1906 | if (match) { |
5065 | if (match) |
|
|
5066 | { |
|
|
5067 | //fprintf(stderr,"town_by_boundary:005\n"); |
1907 | if (match && match->country && match->country->admin_levels) { |
5068 | if (match && match->country && match->country->admin_levels) |
|
|
5069 | { |
|
|
5070 | //fprintf(stderr,"town_by_boundary:006\n"); |
1908 | l=matches; |
5071 | l = matches; |
1909 | while (l) { |
5072 | while (l) |
|
|
5073 | { |
|
|
5074 | //fprintf(stderr,"town_by_boundary:007\n"); |
|
|
5075 | |
1910 | struct boundary *b=l->data; |
5076 | struct boundary *b = l->data; |
1911 | char *admin_level=osm_tag_value(b->ib, "admin_level"); |
5077 | char *admin_level = osm_tag_value(b->ib, "admin_level"); |
1912 | char *postal=osm_tag_value(b->ib, "postal_code"); |
5078 | char *postal = osm_tag_value(b->ib, "postal_code"); |
1913 | if (admin_level) { |
5079 | if (admin_level) |
|
|
5080 | { |
|
|
5081 | //fprintf(stderr,"town_by_boundary:008\n"); |
|
|
5082 | |
1914 | int a=atoi(admin_level); |
5083 | int a = atoi(admin_level); |
1915 | int end=strlen(match->country->admin_levels)+3; |
5084 | int end = strlen(match->country->admin_levels) + 3; |
1916 | char *name; |
5085 | char *name; |
1917 | if (a > 2 && a < end) { |
5086 | if (a > 2 && a < end) |
|
|
5087 | { |
|
|
5088 | //fprintf(stderr,"town_by_boundary:009\n"); |
|
|
5089 | |
1918 | enum attr_type attr_type=attr_none; |
5090 | enum attr_type attr_type = attr_none; |
1919 | switch(match->country->admin_levels[a-3]) { |
5091 | switch (match->country->admin_levels[a - 3]) |
|
|
5092 | { |
1920 | case 's': |
5093 | case 's': |
1921 | attr_type=attr_state_name; |
5094 | attr_type = attr_state_name; |
1922 | break; |
5095 | break; |
1923 | case 'c': |
5096 | case 'c': |
1924 | attr_type=attr_county_name; |
5097 | attr_type = attr_county_name; |
1925 | break; |
5098 | break; |
1926 | case 'm': |
5099 | case 'm': |
1927 | attr_type=attr_municipality_name; |
5100 | attr_type = attr_municipality_name; |
1928 | break; |
5101 | break; |
1929 | } |
5102 | } |
1930 | name=osm_tag_value(b->ib, "name"); |
5103 | name = osm_tag_value(b->ib, "name"); |
1931 | if (name && attr_type != attr_none) { |
5104 | if (name && attr_type != attr_none) |
|
|
5105 | { |
|
|
5106 | //fprintf(stderr,"town_by_boundary:010\n"); |
1932 | attrs[a-2].type=attr_type; |
5107 | attrs[a - 2].type = attr_type; |
1933 | attrs[a-2].u.str=name; |
5108 | attrs[a - 2].u.str = name; |
1934 | } |
5109 | } |
1935 | } |
5110 | } |
1936 | } |
5111 | } |
1937 | if (postal) { |
5112 | if (postal) |
|
|
5113 | { |
|
|
5114 | //fprintf(stderr,"town_by_boundary:011\n"); |
1938 | attrs[0].type=attr_town_postal; |
5115 | attrs[0].type = attr_town_postal; |
1939 | attrs[0].u.str=postal; |
5116 | attrs[0].u.str = postal; |
1940 | } |
5117 | } |
1941 | l=g_list_next(l); |
5118 | l = g_list_next(l); |
1942 | } |
|
|
1943 | } |
5119 | } |
|
|
5120 | } |
1944 | return match->country; |
5121 | return match->country; |
|
|
5122 | } |
1945 | } else |
5123 | else |
|
|
5124 | { |
|
|
5125 | //fprintf(stderr,"town_by_boundary:099\n"); |
1946 | return NULL; |
5126 | return NULL; |
|
|
5127 | } |
1947 | } |
5128 | } |
1948 | |
5129 | |
1949 | void |
5130 | int town_size_estimate(int type) |
|
|
5131 | { |
|
|
5132 | int size = 0; // default -> not use this area as a town! |
|
|
5133 | |
|
|
5134 | switch (type) |
|
|
5135 | { |
|
|
5136 | case type_town_label_1e7: |
|
|
5137 | case type_town_label_5e6: |
|
|
5138 | case type_town_label_2e6: |
|
|
5139 | case type_town_label_1e6: |
|
|
5140 | case type_town_label_5e5: |
|
|
5141 | case type_town_label_2e5: |
|
|
5142 | size = 10000; |
|
|
5143 | break; |
|
|
5144 | case type_town_label_1e5: |
|
|
5145 | case type_town_label_5e4: |
|
|
5146 | case type_town_label_2e4: |
|
|
5147 | size = 3100; |
|
|
5148 | break; |
|
|
5149 | case type_town_label_1e4: |
|
|
5150 | case type_town_label_5e3: |
|
|
5151 | case type_town_label_2e3: |
|
|
5152 | size = 1460; |
|
|
5153 | break; |
|
|
5154 | case type_town_label_1e3: |
|
|
5155 | case type_town_label_5e2: |
|
|
5156 | // case type_town_label_2e2: |
|
|
5157 | case type_town_label_1e2: |
|
|
5158 | case type_town_label_5e1: |
|
|
5159 | case type_town_label_2e1: |
|
|
5160 | case type_town_label_1e1: |
|
|
5161 | case type_town_label_5e0: |
|
|
5162 | // case type_town_label_2e0: |
|
|
5163 | case type_town_label_1e0: |
|
|
5164 | case type_town_label_0e0: |
|
|
5165 | size = 660; |
|
|
5166 | break; |
|
|
5167 | default: |
|
|
5168 | break; |
|
|
5169 | } |
|
|
5170 | |
|
|
5171 | // size = size * global_search_street_size_factor; |
|
|
5172 | |
|
|
5173 | // lat factor 0.072 |
|
|
5174 | // lon factor 0.101 |
|
|
5175 | |
|
|
5176 | // size = 10000 |
|
|
5177 | // lat lon size = size / 100000 |
|
|
5178 | |
|
|
5179 | /* |
|
|
5180 | sel->u.c_rect.lu.x = c->x - size; |
|
|
5181 | sel->u.c_rect.lu.y = c->y + size; |
|
|
5182 | sel->u.c_rect.rl.x = c->x + size; |
|
|
5183 | sel->u.c_rect.rl.y = c->y - size; |
|
|
5184 | */ |
|
|
5185 | return size; |
|
|
5186 | } |
|
|
5187 | |
|
|
5188 | void assign_town_to_streets_v1(); |
|
|
5189 | void assign_town_to_streets_by_boundary(GList *bl); |
|
|
5190 | void copy_town_border_data(); |
|
|
5191 | |
|
|
5192 | void assign_town_to_streets(GList *bl) |
|
|
5193 | { |
|
|
5194 | int skipped = 0; |
|
|
5195 | |
|
|
5196 | copy_town_border_data(); |
|
|
5197 | assign_town_to_streets_by_boundary(bl); |
|
|
5198 | |
|
|
5199 | // now process all the left over towns |
|
|
5200 | assign_town_to_streets_v1(1); |
|
|
5201 | assign_town_to_streets_v1(2); // make townsize double on second pass |
|
|
5202 | } |
|
|
5203 | |
|
|
5204 | |
|
|
5205 | void copy_town_border_data() |
|
|
5206 | { |
|
|
5207 | long long bid; |
|
|
5208 | long long tid; |
|
|
5209 | int retval; |
|
|
5210 | int rc = 0; |
|
|
5211 | int commit_after = 20000; |
|
|
5212 | int count = 0; |
|
|
5213 | int admin_l = 99; |
|
|
5214 | |
|
|
5215 | sqlite3_stmt *stmt_d_1; |
|
|
5216 | sqlite3_stmt *stmt_d_2; |
|
|
5217 | retval = sqlite3_prepare_v2(sql_handle, "select border_id, id, admin_level from town2;", -1, &stmt_d_1, NULL); |
|
|
5218 | // fprintf(stderr, "prep:%d\n", retval); |
|
|
5219 | retval = sqlite3_prepare_v2(sql_handle, "update town set border_id = ?, size = ? where id = ?;", -1, &stmt_d_2, NULL); |
|
|
5220 | // fprintf(stderr, "prep:%d\n", retval); |
|
|
5221 | |
|
|
5222 | // loop thru all the towns |
|
|
5223 | do |
|
|
5224 | { |
|
|
5225 | rc = sqlite3_step(stmt_d_1); |
|
|
5226 | switch (rc) |
|
|
5227 | { |
|
|
5228 | case SQLITE_DONE: |
|
|
5229 | break; |
|
|
5230 | case SQLITE_ROW: |
|
|
5231 | bid = sqlite3_column_int64(stmt_d_1, 0); |
|
|
5232 | tid = sqlite3_column_int64(stmt_d_1, 1); |
|
|
5233 | admin_l = sqlite3_column_int(stmt_d_1, 2); |
|
|
5234 | |
|
|
5235 | // fprintf(stderr, "bid=%lld tid=%lld amdin_level=%d\n", bid, tid, admin_l); |
|
|
5236 | |
|
|
5237 | if (count == 0) |
|
|
5238 | { |
|
|
5239 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5240 | } |
|
|
5241 | count++; |
|
|
5242 | |
|
|
5243 | sqlite3_bind_int64(stmt_d_2, 1, bid); |
|
|
5244 | sqlite3_bind_int64(stmt_d_2, 2, tid); |
|
|
5245 | sqlite3_bind_int(stmt_d_2, 3, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_l) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
|
|
5246 | sqlite3_step(stmt_d_2); |
|
|
5247 | sqlite3_reset(stmt_d_2); |
|
|
5248 | |
|
|
5249 | if (count > commit_after) |
|
|
5250 | { |
|
|
5251 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5252 | count = 0; |
|
|
5253 | } |
|
|
5254 | |
|
|
5255 | break; |
|
|
5256 | default: |
|
|
5257 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
5258 | break; |
|
|
5259 | } |
|
|
5260 | } |
|
|
5261 | while (rc == SQLITE_ROW); |
|
|
5262 | sqlite3_reset(stmt_d_1); |
|
|
5263 | |
|
|
5264 | retval = sqlite3_finalize(stmt_d_2); |
|
|
5265 | // fprintf(stderr, "fin:%d\n", retval); |
|
|
5266 | retval = sqlite3_finalize(stmt_d_1); |
|
|
5267 | // fprintf(stderr, "fin:%d\n", retval); |
|
|
5268 | |
|
|
5269 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5270 | |
|
|
5271 | } |
|
|
5272 | |
|
|
5273 | void assign_town_to_streets_by_boundary(GList *bl) |
|
|
5274 | { |
|
|
5275 | long long nd; |
|
|
5276 | long long wid; |
|
|
5277 | long long town_rel_id; |
|
|
5278 | int size; |
|
|
5279 | double lat; |
|
|
5280 | double lon; |
|
|
5281 | double temp; |
|
|
5282 | double lat_min; |
|
|
5283 | double lat_max; |
|
|
5284 | double lon_min; |
|
|
5285 | double lon_max; |
|
|
5286 | int rc; |
|
|
5287 | int rc2; |
|
|
5288 | long long town_count; |
|
|
5289 | long long town_processed_count; |
|
|
5290 | int town_steps = 1; |
|
|
5291 | int result = 0; |
|
|
5292 | struct boundary *bound_temp; |
|
|
5293 | |
|
|
5294 | sql_counter = 0; |
|
|
5295 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5296 | |
|
|
5297 | // number of towns in DB |
|
|
5298 | sqlite3_reset(stmt_town_sel002); |
|
|
5299 | sqlite3_step(stmt_town_sel002); |
|
|
5300 | town_count = sqlite3_column_int64(stmt_town_sel002, 0); |
|
|
5301 | town_processed_count = 0; |
|
|
5302 | |
|
|
5303 | fprintf(stderr, "towns0: %lld/%lld\n", town_processed_count, town_count); |
|
|
5304 | |
|
|
5305 | if (town_count == 0) |
|
|
5306 | { |
|
|
5307 | sqlite3_reset(stmt_town_sel002); |
|
|
5308 | return; |
|
|
5309 | } |
|
|
5310 | |
|
|
5311 | sql_counter = 0; |
|
|
5312 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5313 | |
|
|
5314 | if (town_count > 1000000) |
|
|
5315 | { |
|
|
5316 | town_steps = 500; |
|
|
5317 | } |
|
|
5318 | else if (town_count > 100000) |
|
|
5319 | { |
|
|
5320 | town_steps = 100; |
|
|
5321 | } |
|
|
5322 | else if (town_count > 10000) |
|
|
5323 | { |
|
|
5324 | town_steps = 10; |
|
|
5325 | } |
|
|
5326 | |
|
|
5327 | // DEBUG |
|
|
5328 | // town_steps = 1; |
|
|
5329 | // DEBUG |
|
|
5330 | |
|
|
5331 | // loop thru all the towns |
|
|
5332 | do |
|
|
5333 | { |
|
|
5334 | rc = sqlite3_step(stmt_town_sel001); |
|
|
5335 | switch (rc) |
|
|
5336 | { |
|
|
5337 | case SQLITE_DONE: |
|
|
5338 | break; |
|
|
5339 | case SQLITE_ROW: |
|
|
5340 | nd = sqlite3_column_int64(stmt_town_sel001, 0); |
|
|
5341 | town_rel_id = sqlite3_column_int64(stmt_town_sel001, 5); |
|
|
5342 | //size = sqlite3_column_int(stmt_town_sel001, 1); |
|
|
5343 | //lat = sqlite3_column_double(stmt_town_sel001, 2); |
|
|
5344 | //lon = sqlite3_column_double(stmt_town_sel001, 3); |
|
|
5345 | |
|
|
5346 | |
|
|
5347 | GList *match_town = NULL; |
|
|
5348 | GList *l = bl; |
|
|
5349 | int has_found = 0; |
|
|
5350 | |
|
|
5351 | if (town_rel_id != 0) |
|
|
5352 | { |
|
|
5353 | // fprintf(stderr ,"processing town name:%s id:%lld border_id:%lld\n", sqlite3_column_text(stmt_town_sel001, 4), nd, town_rel_id); |
|
|
5354 | |
|
|
5355 | while (l) |
|
|
5356 | { |
|
|
5357 | struct boundary *b = l->data; |
|
|
5358 | //fprintf(stderr, "bid=%lld tid=%lld\n", item_bin_get_relationid(b->ib), town_rel_id); |
|
|
5359 | if (item_bin_get_relationid(b->ib) == town_rel_id) |
|
|
5360 | { |
|
|
5361 | match_town = l; |
|
|
5362 | has_found = 1; |
|
|
5363 | //fprintf(stderr, "bid=%lld tid=%lld\n", item_bin_get_relationid(b->ib), town_rel_id); |
|
|
5364 | //fprintf(stderr, "*** town border found***\n"); |
|
|
5365 | break; |
|
|
5366 | } |
|
|
5367 | l = g_list_next(l); |
|
|
5368 | } |
|
|
5369 | } |
|
|
5370 | |
|
|
5371 | if (has_found == 1) |
|
|
5372 | { |
|
|
5373 | // now run thru all the ways |
|
|
5374 | do |
|
|
5375 | { |
|
|
5376 | // only select ways that are in the bounding box of boundary! |
|
|
5377 | |
|
|
5378 | bound_temp = match_town->data; |
|
|
5379 | lat_min = transform_to_geo_lat(bound_temp->r.l.y); |
|
|
5380 | lat_max = transform_to_geo_lat(bound_temp->r.h.y); |
|
|
5381 | lon_min = transform_to_geo_lon(bound_temp->r.l.x); |
|
|
5382 | lon_max = transform_to_geo_lon(bound_temp->r.h.x); |
|
|
5383 | |
|
|
5384 | //fprintf(stderr, "lat min:%f max:%f lon min:%f max:%f \n", lat_min, lat_max, lon_min, lon_max); |
|
|
5385 | |
|
|
5386 | sqlite3_bind_double(stmt_way3a, 1, lat_min); |
|
|
5387 | sqlite3_bind_double(stmt_way3a, 2, lat_max); |
|
|
5388 | sqlite3_bind_double(stmt_way3a, 3, lon_min); |
|
|
5389 | sqlite3_bind_double(stmt_way3a, 4, lon_max); |
|
|
5390 | rc2 = sqlite3_step(stmt_way3a); |
|
|
5391 | switch (rc2) |
|
|
5392 | { |
|
|
5393 | case SQLITE_DONE: |
|
|
5394 | break; |
|
|
5395 | case SQLITE_ROW: |
|
|
5396 | wid = sqlite3_column_int64(stmt_way3a, 0); |
|
|
5397 | lat = sqlite3_column_double(stmt_way3a, 1); |
|
|
5398 | lon = sqlite3_column_double(stmt_way3a, 2); |
|
|
5399 | |
|
|
5400 | struct coord c; |
|
|
5401 | c.x = transform_from_geo_lon(lon); |
|
|
5402 | c.y = transform_from_geo_lat(lat); |
|
|
5403 | |
|
|
5404 | //fprintf(stderr,"== street by boundary == x:%d y:%d ==\n", c.x, c.y); |
|
|
5405 | |
|
|
5406 | if (town_rel_id != 0) |
|
|
5407 | { |
|
|
5408 | // fprintf(stderr, "town:%lld\n", nd); |
|
|
5409 | // fprintf(stderr,"== street by boundary == x:%d y:%d ==\n", c.x, c.y); |
|
|
5410 | result = osm_process_street_by_boundary(match_town, nd, town_rel_id, &c); |
|
|
5411 | if (result == 1) |
|
|
5412 | { |
|
|
5413 | //fprintf(stderr,"== street by boundary == wid:%lld townid:%lld ==\n", wid, nd); |
|
|
5414 | // write "town id" to "way" |
|
|
5415 | if (sql_counter == 0) |
|
|
5416 | { |
|
|
5417 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5418 | } |
|
|
5419 | sql_counter++; |
|
|
5420 | sqlite3_bind_int64(stmt_way3b, 1, nd); |
|
|
5421 | sqlite3_bind_int64(stmt_way3b, 2, wid); |
|
|
5422 | sqlite3_step(stmt_way3b); |
|
|
5423 | sqlite3_reset(stmt_way3b); |
|
|
5424 | if (sql_counter > MAX_ROWS_WO_COMMIT_2b) |
|
|
5425 | { |
|
|
5426 | sql_counter = 0; |
|
|
5427 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5428 | } |
|
|
5429 | } |
|
|
5430 | } |
|
|
5431 | |
|
|
5432 | break; |
|
|
5433 | default: |
|
|
5434 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
5435 | break; |
|
|
5436 | } |
|
|
5437 | } |
|
|
5438 | while (rc2 == SQLITE_ROW); |
|
|
5439 | sqlite3_reset(stmt_way3a); |
|
|
5440 | |
|
|
5441 | |
|
|
5442 | // mark town as "done" |
|
|
5443 | if (sql_counter == 0) |
|
|
5444 | { |
|
|
5445 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5446 | } |
|
|
5447 | sql_counter++; |
|
|
5448 | sqlite3_bind_int64(stmt_town_sel007, 1, nd); |
|
|
5449 | sqlite3_step(stmt_town_sel007); |
|
|
5450 | sqlite3_reset(stmt_town_sel007); |
|
|
5451 | if (sql_counter > MAX_ROWS_WO_COMMIT_2b) |
|
|
5452 | { |
|
|
5453 | sql_counter = 0; |
|
|
5454 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5455 | } |
|
|
5456 | |
|
|
5457 | } |
|
|
5458 | |
|
|
5459 | town_processed_count++; |
|
|
5460 | if ((town_processed_count % town_steps) == 0) |
|
|
5461 | { |
|
|
5462 | fprintf(stderr, "towns0: %lld/%lld\n", town_processed_count, town_count); |
|
|
5463 | } |
|
|
5464 | |
|
|
5465 | break; |
|
|
5466 | default: |
|
|
5467 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
5468 | break; |
|
|
5469 | } |
|
|
5470 | } |
|
|
5471 | while (rc == SQLITE_ROW); |
|
|
5472 | sqlite3_reset(stmt_town_sel001); |
|
|
5473 | |
|
|
5474 | sql_counter = 0; |
|
|
5475 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5476 | } |
|
|
5477 | |
|
|
5478 | |
|
|
5479 | void assign_town_to_streets_v1(int pass_num) |
|
|
5480 | { |
|
|
5481 | |
|
|
5482 | long long nd; |
|
|
5483 | int size; |
|
|
5484 | double lat; |
|
|
5485 | double lon; |
|
|
5486 | double lat_min; |
|
|
5487 | double lat_max; |
|
|
5488 | double lon_min; |
|
|
5489 | double lon_max; |
|
|
5490 | double temp; |
|
|
5491 | int rc; |
|
|
5492 | long long town_count; |
|
|
5493 | long long town_processed_count; |
|
|
5494 | int town_steps = 1; |
|
|
5495 | |
|
|
5496 | sql_counter = 0; |
|
|
5497 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5498 | |
|
|
5499 | // number of towns in DB |
|
|
5500 | sqlite3_reset(stmt_town_sel002); |
|
|
5501 | sqlite3_step(stmt_town_sel002); |
|
|
5502 | town_count = sqlite3_column_int64(stmt_town_sel002, 0); |
|
|
5503 | town_processed_count = 0; |
|
|
5504 | |
|
|
5505 | fprintf(stderr, "towns1-%d: %lld/%lld\n", pass_num, town_processed_count, town_count); |
|
|
5506 | |
|
|
5507 | if (town_count == 0) |
|
|
5508 | { |
|
|
5509 | sqlite3_reset(stmt_town_sel002); |
|
|
5510 | return; |
|
|
5511 | } |
|
|
5512 | |
|
|
5513 | sql_counter = 0; |
|
|
5514 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5515 | |
|
|
5516 | if (town_count > 1000000) |
|
|
5517 | { |
|
|
5518 | town_steps = 500; |
|
|
5519 | } |
|
|
5520 | else if (town_count > 100000) |
|
|
5521 | { |
|
|
5522 | town_steps = 100; |
|
|
5523 | } |
|
|
5524 | else if (town_count > 10000) |
|
|
5525 | { |
|
|
5526 | town_steps = 10; |
|
|
5527 | } |
|
|
5528 | |
|
|
5529 | // DEBUG |
|
|
5530 | // town_steps = 1; |
|
|
5531 | // DEBUG |
|
|
5532 | |
|
|
5533 | // loop thru all the towns |
|
|
5534 | do |
|
|
5535 | { |
|
|
5536 | rc = sqlite3_step(stmt_town_sel001); |
|
|
5537 | switch (rc) |
|
|
5538 | { |
|
|
5539 | case SQLITE_DONE: |
|
|
5540 | break; |
|
|
5541 | case SQLITE_ROW: |
|
|
5542 | nd = sqlite3_column_int64(stmt_town_sel001, 0); |
|
|
5543 | size = sqlite3_column_int(stmt_town_sel001, 1); |
|
|
5544 | lat = sqlite3_column_double(stmt_town_sel001, 2); |
|
|
5545 | lon = sqlite3_column_double(stmt_town_sel001, 3); |
|
|
5546 | //fprintf(stderr ,"processing (size:%d) town name:%s id:%lld\n", size, sqlite3_column_text(stmt_town_sel001, 4), nd); |
|
|
5547 | |
|
|
5548 | // now update the ways |
|
|
5549 | if (sql_counter == 0) |
|
|
5550 | { |
|
|
5551 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5552 | } |
|
|
5553 | |
|
|
5554 | sqlite3_bind_int64(stmt_way3, 1, nd); |
|
|
5555 | |
|
|
5556 | if ((pass_num == 2) && (size > 0)) |
|
|
5557 | { |
|
|
5558 | size = size * 3; |
|
|
5559 | } |
|
|
5560 | |
|
|
5561 | temp = ((double) size) / 100000; |
|
|
5562 | lat_min = lat - temp; |
|
|
5563 | lat_max = lat + temp; |
|
|
5564 | lon_min = lon - temp; |
|
|
5565 | lon_max = lon + temp; |
|
|
5566 | sqlite3_bind_double(stmt_way3, 2, lat_min); |
|
|
5567 | sqlite3_bind_double(stmt_way3, 3, lat_max); |
|
|
5568 | sqlite3_bind_double(stmt_way3, 4, lon_min); |
|
|
5569 | sqlite3_bind_double(stmt_way3, 5, lon_max); |
|
|
5570 | //fprintf(stderr, "size korr:%f %f %f %f %f\n", temp, lat_min, lat_max, lon_min, lon_max); |
|
|
5571 | |
|
|
5572 | sqlite3_step(stmt_way3); |
|
|
5573 | sqlite3_reset(stmt_way3); |
|
|
5574 | |
|
|
5575 | sql_counter++; |
|
|
5576 | if (sql_counter > MAX_ROWS_WO_COMMIT_2a) |
|
|
5577 | { |
|
|
5578 | sql_counter = 0; |
|
|
5579 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5580 | } |
|
|
5581 | town_processed_count++; |
|
|
5582 | |
|
|
5583 | if ((town_processed_count % town_steps) == 0) |
|
|
5584 | { |
|
|
5585 | fprintf(stderr, "towns1-%d: %lld/%lld\n", pass_num, town_processed_count, town_count); |
|
|
5586 | } |
|
|
5587 | |
|
|
5588 | break; |
|
|
5589 | default: |
|
|
5590 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
5591 | break; |
|
|
5592 | } |
|
|
5593 | } |
|
|
5594 | while (rc == SQLITE_ROW); |
|
|
5595 | sqlite3_reset(stmt_town_sel001); |
|
|
5596 | |
|
|
5597 | sql_counter = 0; |
|
|
5598 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5599 | |
|
|
5600 | } |
|
|
5601 | |
|
|
5602 | |
|
|
5603 | int lat_lon_inside_rect(struct node_lat_lon *n, struct rect_lat_lon *r) |
|
|
5604 | { |
|
|
5605 | if ((n->lat >= r->lu_lat) && (n->lon >= r->lu_lon) && (n->lat <= r->rl_lat) && (n->lon <= r->rl_lon)) |
|
|
5606 | { |
|
|
5607 | return 1; |
|
|
5608 | } |
|
|
5609 | |
|
|
5610 | return 0; |
|
|
5611 | } |
|
|
5612 | |
1950 | osm_process_towns(FILE *in, FILE *boundaries, FILE *ways) |
5613 | GList* osm_process_towns(FILE *in, FILE *coords, FILE *boundaries, FILE *ways) |
1951 | { |
5614 | { |
1952 | struct item_bin *ib; |
5615 | struct item_bin *ib; |
1953 | GList *bl=NULL; |
5616 | GList *bl = NULL; |
1954 | struct attr attrs[10]; |
5617 | struct attr attrs[10]; |
|
|
5618 | time_t start_tt, end_tt; |
|
|
5619 | double diff_tt; |
|
|
5620 | double diff2_tt; |
|
|
5621 | long long size_in; |
|
|
5622 | long long pos_in; |
|
|
5623 | struct node_lat_lon node_coords; |
1955 | |
5624 | |
1956 | if (debug_itembin(1)) |
5625 | if (debug_itembin(1)) |
1957 | { |
5626 | { |
1958 | fprintf(stderr,"osm_process_towns == START ==\n"); |
5627 | fprintf(stderr, "osm_process_towns == START ==\n"); |
1959 | } |
5628 | } |
1960 | |
5629 | |
|
|
5630 | //fprintf(stderr,"osm_process_towns == PB 001 %p,%p ==\n", boundaries, ways); |
|
|
5631 | |
|
|
5632 | time(&start_tt); |
1961 | bl=process_boundaries(boundaries, ways); |
5633 | bl = process_boundaries(boundaries, coords, ways); |
|
|
5634 | time(&end_tt); |
|
|
5635 | diff_tt = difftime(end_tt, start_tt); |
|
|
5636 | char outstring[200]; |
|
|
5637 | char outstring2[200]; |
|
|
5638 | char outstring3[200]; |
|
|
5639 | convert_to_human_time(diff_tt, outstring); |
|
|
5640 | fprintf(stderr, "-RUNTIME-BOUNDARIES: %s\n", outstring); |
|
|
5641 | |
|
|
5642 | int _c = 0; |
|
|
5643 | int _e = 10000; |
|
|
5644 | |
|
|
5645 | //fprintf(stderr,"osm_process_towns == PB 002 ==\n"); |
|
|
5646 | |
|
|
5647 | long long pos_now = ftello(in); // 64bit |
|
|
5648 | fseeko(in, 0, SEEK_END); |
|
|
5649 | size_in = ftello(in); // 64bit |
|
|
5650 | fseeko(in, (off_t)pos_now, SEEK_SET); |
|
|
5651 | |
|
|
5652 | // reset timer |
|
|
5653 | diff2_tt = 0; |
|
|
5654 | _c = 0; |
|
|
5655 | time(&start_tt); |
|
|
5656 | |
1962 | while ((ib=read_item(in))) |
5657 | while ((ib = read_item(in, 0))) |
1963 | { |
5658 | { |
1964 | struct coord *c=(struct coord *)(ib+1); |
5659 | struct coord *c = (struct coord *) (ib + 1); |
1965 | struct country_table *result=NULL; |
5660 | struct country_table *result = NULL; |
1966 | char *is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL); |
5661 | char *is_in = item_bin_get_attr(ib, attr_osm_is_in, NULL); |
1967 | int i; |
5662 | int i; |
1968 | |
5663 | |
|
|
5664 | _c++; |
|
|
5665 | |
1969 | if (debug_itembin(ib)) |
5666 | if (debug_itembin(ib)) |
1970 | { |
5667 | { |
1971 | fprintf(stderr,"== item ==\n"); |
5668 | fprintf(stderr, "== item ==\n"); |
1972 | dump_itembin(ib); |
5669 | dump_itembin(ib); |
1973 | } |
5670 | } |
1974 | |
5671 | |
1975 | memset(attrs, 0, sizeof(attrs)); |
5672 | memset(attrs, 0, sizeof(attrs)); |
1976 | if (debug_itembin(ib)) |
5673 | if (debug_itembin(ib)) |
1977 | { |
5674 | { |
1978 | fprintf(stderr,"== osm_process_town_by_boundary ==\n"); |
5675 | fprintf(stderr, "== osm_process_town_by_boundary ==\n"); |
1979 | } |
5676 | } |
1980 | |
5677 | |
1981 | if (use_global_fixed_country_id == 1) |
5678 | if (use_global_fixed_country_id == 1) |
1982 | { |
5679 | { |
1983 | result=osm_process_item_fixed_country(); |
5680 | result = osm_process_item_fixed_country(); |
1984 | if (debug_itembin(ib)) |
5681 | if (debug_itembin(ib)) |
1985 | { |
5682 | { |
1986 | if (result==NULL) |
5683 | if (result == NULL) |
1987 | { |
5684 | { |
1988 | fprintf(stderr,"== osm_process_item_fixed_country == #NULL# ==\n"); |
5685 | fprintf(stderr, "== osm_process_item_fixed_country == #NULL# ==\n"); |
1989 | } |
5686 | } |
1990 | else |
5687 | else |
1991 | { |
5688 | { |
1992 | fprintf(stderr,"== osm_process_item_fixed_country == %d ==\n",result->countryid); |
5689 | fprintf(stderr, "== osm_process_item_fixed_country == %d %s ==\n", result->countryid, result->names); |
1993 | } |
5690 | } |
1994 | } |
5691 | } |
1995 | } |
5692 | } |
1996 | |
5693 | |
1997 | if (!result) |
5694 | if (!result) |
1998 | { |
5695 | { |
|
|
5696 | //char *name=item_bin_get_attr(ib, attr_town_name, NULL); |
|
|
5697 | //fprintf(stderr,"== town by boundary == t:%s ==\n", name); |
|
|
5698 | |
1999 | result=osm_process_town_by_boundary(bl, ib, c, attrs); |
5699 | result = osm_process_town_by_boundary(bl, ib, c, attrs); |
|
|
5700 | if (result) // DEBUG |
|
|
5701 | { |
|
|
5702 | //fprintf(stderr,"== town by boundary == country_id:%d country_name:%s ==\n", result->countryid, result->names); |
|
|
5703 | } |
2000 | } |
5704 | } |
2001 | |
5705 | |
2002 | if (!result) |
5706 | if (!result) |
2003 | { |
5707 | { |
2004 | if (debug_itembin(ib)) |
5708 | if (debug_itembin(ib)) |
2005 | { |
5709 | { |
2006 | fprintf(stderr,"== osm_process_town_by_is_in == %s ==\n",is_in); |
5710 | fprintf(stderr, "== osm_process_town_by_is_in == %s ==\n", is_in); |
2007 | } |
5711 | } |
2008 | result=osm_process_town_by_is_in(ib, is_in); |
5712 | result = osm_process_town_by_is_in(ib, is_in); |
|
|
5713 | if (result) // DEBUG |
|
|
5714 | { |
|
|
5715 | // fprintf(stderr,"== town by is_in == country_id:%d country_name:%s ==\n", result->countryid, result->names); |
|
|
5716 | } |
2009 | } |
5717 | } |
2010 | |
5718 | |
2011 | if (!result && unknown_country) |
5719 | if (!result && unknown_country) |
2012 | { |
5720 | { |
2013 | if (debug_itembin(ib)) |
5721 | if (debug_itembin(ib)) |
2014 | { |
5722 | { |
2015 | fprintf(stderr,"== osm_process_town_unknown_country ==\n"); |
5723 | fprintf(stderr, "== osm_process_town_unknown_country ==\n"); |
2016 | } |
5724 | } |
2017 | result=osm_process_town_unknown_country(); |
5725 | result = osm_process_town_unknown_country(); |
2018 | } |
5726 | } |
2019 | |
5727 | |
2020 | if (result) |
5728 | if (result) |
2021 | { |
5729 | { |
2022 | if (!result->file) |
5730 | if (!result->file) |
2023 | { |
5731 | { |
2024 | char *name=g_strdup_printf("country_%d.unsorted.tmp", result->countryid); |
5732 | char *name = g_strdup_printf("country_%d.unsorted.tmp", result->countryid); |
2025 | result->file=fopen(name,"wb"); |
5733 | result->file = fopen(name, "wb"); |
2026 | |
5734 | |
2027 | if (debug_itembin(ib)) |
5735 | if (debug_itembin(ib)) |
2028 | { |
5736 | { |
2029 | fprintf(stderr,"== create: country_%d.unsorted.tmp == FILEP: %p ==\n", result->countryid, result->file); |
5737 | fprintf(stderr, "== create: country_%d.unsorted.tmp == FILEP: %p ==\n", result->countryid, result->file); |
2030 | } |
5738 | } |
2031 | |
5739 | |
2032 | g_free(name); |
5740 | g_free(name); |
2033 | } |
5741 | } |
2034 | |
5742 | |
2035 | if (result->file) |
5743 | if (result->file) |
2036 | { |
5744 | { |
2037 | long long *nodeid; |
5745 | long long *nodeid; |
|
|
5746 | long long nd_id = item_bin_get_nodeid(ib); |
2038 | if (is_in) |
5747 | if (is_in) |
|
|
5748 | { |
2039 | item_bin_remove_attr(ib, is_in); |
5749 | item_bin_remove_attr(ib, is_in); |
|
|
5750 | } |
2040 | nodeid=item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
5751 | nodeid = item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
2041 | if (nodeid) |
5752 | if (nodeid) |
|
|
5753 | { |
2042 | item_bin_remove_attr(ib, nodeid); |
5754 | item_bin_remove_attr(ib, nodeid); |
2043 | if (attrs[0].type != attr_none) |
5755 | } |
|
|
5756 | |
|
|
5757 | char *postal = NULL; |
|
|
5758 | char *postal2 = NULL; |
|
|
5759 | //if (attrs[0].type != attr_none) // what does this line do?? |
|
|
5760 | //{ |
|
|
5761 | postal = item_bin_get_attr(ib, attr_town_postal, NULL); |
|
|
5762 | if (postal) |
2044 | { |
5763 | { |
2045 | char *postal=item_bin_get_attr(ib, attr_town_postal, NULL); |
5764 | postal2 = g_strdup_printf("%s", postal); |
2046 | if (postal) |
|
|
2047 | item_bin_remove_attr(ib, postal); |
5765 | // --- item_bin_remove_attr(ib, postal); |
|
|
5766 | // fprintf(stderr, "town postal:%s\n", postal2); |
2048 | } |
5767 | } |
|
|
5768 | //} |
|
|
5769 | |
2049 | for (i = 0 ; i < 10 ; i++) |
5770 | for (i = 0; i < 10; i++) |
2050 | { |
5771 | { |
2051 | if (attrs[i].type != attr_none) |
5772 | if (attrs[i].type != attr_none) |
|
|
5773 | { |
2052 | item_bin_add_attr(ib, &attrs[i]); |
5774 | item_bin_add_attr(ib, &attrs[i]); |
|
|
5775 | } |
2053 | } |
5776 | } |
|
|
5777 | |
|
|
5778 | if (sql_counter == 0) |
|
|
5779 | { |
|
|
5780 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
|
|
5781 | } |
|
|
5782 | |
|
|
5783 | if (nd_id) |
|
|
5784 | { |
|
|
5785 | // town size (will later be translated into radius) |
|
|
5786 | int twn_size = town_size_estimate(ib->type); |
|
|
5787 | |
|
|
5788 | if (twn_size > 0) |
|
|
5789 | { |
|
|
5790 | |
|
|
5791 | sqlite3_bind_int64(stmt_town, 1, nd_id); |
|
|
5792 | if (result->countryid) |
|
|
5793 | { |
|
|
5794 | sqlite3_bind_int(stmt_town, 2, result->countryid); |
|
|
5795 | } |
|
|
5796 | else |
|
|
5797 | { |
|
|
5798 | sqlite3_bind_int(stmt_town, 2, 999); |
|
|
5799 | } |
|
|
5800 | |
|
|
5801 | sqlite3_bind_int(stmt_town, 4, twn_size); |
|
|
5802 | |
|
|
5803 | char *label_t = item_bin_get_attr(ib, attr_town_name, NULL); |
|
|
5804 | //fprintf(stderr, "town: %lld,%d,%s\n", nd_id, result->countryid, label_t); |
|
|
5805 | |
|
|
5806 | sqlite3_bind_text(stmt_town, 3, label_t, -1, SQLITE_STATIC); |
|
|
5807 | |
|
|
5808 | if (postal2) |
|
|
5809 | { |
|
|
5810 | sqlite3_bind_text(stmt_town, 5, postal2, -1, SQLITE_STATIC); |
|
|
5811 | } |
|
|
5812 | else |
|
|
5813 | { |
|
|
5814 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
|
|
5815 | } |
|
|
5816 | |
|
|
5817 | get_lat_lon_for_node(nd_id, &node_coords); |
|
|
5818 | if (node_coords.valid == 1) |
|
|
5819 | { |
|
|
5820 | sqlite3_bind_double(stmt_town, 6, node_coords.lat); |
|
|
5821 | sqlite3_bind_double(stmt_town, 7, node_coords.lon); |
|
|
5822 | } |
|
|
5823 | |
|
|
5824 | sqlite3_step(stmt_town); |
|
|
5825 | sqlite3_reset(stmt_town); |
|
|
5826 | sql_counter++; |
|
|
5827 | |
|
|
5828 | if (postal2) |
|
|
5829 | { |
|
|
5830 | g_free(postal2); |
|
|
5831 | } |
|
|
5832 | |
|
|
5833 | } |
|
|
5834 | } |
|
|
5835 | |
|
|
5836 | if (sql_counter > MAX_ROWS_WO_COMMIT_5) |
|
|
5837 | { |
|
|
5838 | sql_counter = 0; |
|
|
5839 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
5840 | //fprintf(stderr, "SQL: COMMIT\n"); |
|
|
5841 | } |
|
|
5842 | |
2054 | // ** used until 2011-11-06 seems bad ** item_bin_write_match(ib, attr_town_name, attr_town_name_match, result->file); |
5843 | // ** used until 2011-11-06 seems bad ** item_bin_write_match(ib, attr_town_name, attr_town_name_match, result->file); |
2055 | item_bin_town_write_match(ib, attr_town_name, attr_town_name_match, result->file); |
5844 | item_bin_town_write_match(ib, attr_town_name, attr_town_name_match, result->file); |
2056 | // ** origname ** item_bin_write(ib,result->file); |
5845 | // ** origname ** item_bin_write(ib,result->file); |
2057 | } |
5846 | } |
2058 | } |
5847 | } |
2059 | else |
5848 | else |
2060 | { |
5849 | { |
2061 | if (debug_itembin(ib)) |
5850 | if (debug_itembin(ib)) |
2062 | { |
5851 | { |
2063 | fprintf(stderr,"== no result ==\n"); |
5852 | fprintf(stderr, "== no result ==\n"); |
|
|
5853 | } |
|
|
5854 | } |
|
|
5855 | |
|
|
5856 | if (_c > _e) |
|
|
5857 | { |
|
|
5858 | _c = 0; |
|
|
5859 | |
|
|
5860 | pos_in = ftello(in); // 64bit |
|
|
5861 | time(&end_tt); |
|
|
5862 | diff_tt = difftime(end_tt, start_tt); |
|
|
5863 | convert_to_human_time(diff_tt, outstring); |
|
|
5864 | convert_to_human_bytes(pos_in, outstring2); |
|
|
5865 | convert_to_human_bytes(size_in, outstring3); |
|
|
5866 | fprintf(stderr, "-RUNTIME-LOOP-TOWN: %s elapsed (POS:%s of %s)\n", outstring, outstring2, outstring3); |
|
|
5867 | if (pos_in > 0) |
|
|
5868 | { |
|
|
5869 | double eta_time = ((diff_tt / (pos_in)) * (size_in)) - diff_tt; |
|
|
5870 | convert_to_human_time(eta_time, outstring); |
|
|
5871 | fprintf(stderr, "-RUNTIME-LOOP-TOWN: %s left\n", outstring); |
2064 | } |
5872 | } |
2065 | } |
5873 | } |
2066 | } |
5874 | } |
2067 | |
5875 | |
2068 | if (debug_itembin(1)) |
5876 | if (debug_itembin(1)) |
2069 | { |
5877 | { |
2070 | fprintf(stderr,"osm_process_towns == END ==\n"); |
5878 | fprintf(stderr, "osm_process_towns == END ==\n"); |
2071 | } |
5879 | } |
2072 | |
5880 | |
2073 | } |
5881 | return bl; |
2074 | |
5882 | |
2075 | void |
5883 | } |
|
|
5884 | |
2076 | sort_countries(int keep_tmpfiles) |
5885 | void sort_countries(int keep_tmpfiles) |
2077 | { |
5886 | { |
2078 | int i; |
5887 | int i; |
2079 | struct country_table *co; |
5888 | struct country_table *co; |
2080 | char *name_in,*name_out; |
5889 | char *name_in, *name_out; |
2081 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { |
5890 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
|
|
5891 | { |
2082 | co=&country_table[i]; |
5892 | co = &country_table[i]; |
2083 | if (co->file) { |
5893 | if (co->file) |
|
|
5894 | { |
2084 | fclose(co->file); |
5895 | fclose(co->file); |
2085 | co->file=NULL; |
5896 | co->file = NULL; |
2086 | } |
5897 | } |
2087 | name_in=g_strdup_printf("country_%d.unsorted.tmp", co->countryid); |
5898 | name_in = g_strdup_printf("country_%d.unsorted.tmp", co->countryid); |
2088 | name_out=g_strdup_printf("country_%d.tmp", co->countryid); |
5899 | name_out = g_strdup_printf("country_%d.tmp", co->countryid); |
2089 | |
5900 | |
2090 | if (debug_itembin(2)) |
5901 | if (debug_itembin(2)) |
2091 | { |
5902 | { |
2092 | fprintf(stderr,"in=country_%d.unsorted.tmp\n", co->countryid); |
5903 | fprintf(stderr, "in=country_%d.unsorted.tmp\n", co->countryid); |
2093 | fprintf(stderr,"out=country_%d.tmp\n", co->countryid); |
5904 | fprintf(stderr, "out=country_%d.tmp\n", co->countryid); |
2094 | } |
5905 | } |
2095 | |
5906 | |
2096 | co->r=world_bbox; |
5907 | co->r = world_bbox; |
2097 | item_bin_sort_file(name_in, name_out, &co->r, &co->size); |
5908 | item_bin_sort_file(name_in, name_out, &co->r, &co->size); |
2098 | if (!keep_tmpfiles) |
5909 | if (!keep_tmpfiles) |
|
|
5910 | { |
2099 | unlink(name_in); |
5911 | unlink(name_in); |
|
|
5912 | } |
2100 | g_free(name_in); |
5913 | g_free(name_in); |
2101 | g_free(name_out); |
5914 | g_free(name_out); |
2102 | } |
5915 | } |
2103 | } |
5916 | } |
2104 | |
5917 | |
2105 | struct relation_member { |
|
|
2106 | int type; |
|
|
2107 | long long id; |
|
|
2108 | char *role; |
|
|
2109 | }; |
|
|
2110 | |
|
|
2111 | static int |
|
|
2112 | get_relation_member(char *str, struct relation_member *memb) |
|
|
2113 | { |
|
|
2114 | int len; |
|
|
2115 | sscanf(str,"%d:"LONGLONG_FMT":%n",&memb->type,&memb->id,&len); |
|
|
2116 | memb->role=str+len; |
|
|
2117 | return 1; |
|
|
2118 | } |
|
|
2119 | |
|
|
2120 | static int |
|
|
2121 | search_relation_member(struct item_bin *ib, char *role, struct relation_member *memb, int *min_count) |
5918 | static int search_relation_member(struct item_bin *ib, char *role, struct relation_member *memb, int *min_count) |
2122 | { |
5919 | { |
2123 | char *str=NULL; |
5920 | char *str = NULL; |
2124 | int count=0; |
5921 | int count = 0; |
2125 | while ((str=item_bin_get_attr(ib, attr_osm_member, str))) { |
5922 | while ((str = item_bin_get_attr(ib, attr_osm_member, str))) |
|
|
5923 | { |
2126 | if (!get_relation_member(str, memb)) |
5924 | if (!get_relation_member(str, memb)) |
2127 | return 0; |
5925 | return 0; |
2128 | count++; |
5926 | count++; |
2129 | if (!strcmp(memb->role, role) && (!min_count || *min_count < count)) { |
5927 | if (!strcmp(memb->role, role) && (!min_count || *min_count < count)) |
|
|
5928 | { |
2130 | if (min_count) |
5929 | if (min_count) |
2131 | *min_count=count; |
5930 | *min_count = count; |
2132 | return 1; |
5931 | return 1; |
2133 | } |
5932 | } |
2134 | } |
5933 | } |
2135 | return 0; |
5934 | return 0; |
2136 | } |
5935 | } |
2137 | |
5936 | |
2138 | static int |
|
|
2139 | load_way_index(FILE *ways_index, int p, long long *idx) |
5937 | static int load_way_index(FILE *ways_index, int p, long long *idx) |
2140 | { |
5938 | { |
2141 | int step=sizeof(*idx)*2; |
5939 | int step = sizeof(*idx) * 2; |
2142 | fseek(ways_index, p*step, SEEK_SET); |
5940 | fseek(ways_index, p * step, SEEK_SET); |
2143 | if (fread(idx, step, 1, ways_index) != 1) { |
5941 | if (fread(idx, step, 1, ways_index) != 1) |
|
|
5942 | { |
2144 | fprintf(stderr,"read failed\n"); |
5943 | fprintf(stderr, "read failed\n"); |
2145 | return 0; |
5944 | return 0; |
2146 | } |
5945 | } |
2147 | return 1; |
5946 | return 1; |
2148 | } |
5947 | } |
2149 | |
5948 | |
2150 | |
|
|
2151 | static int |
|
|
2152 | seek_to_way(FILE *way, FILE *ways_index, long long wayid) |
5949 | static int seek_to_way(FILE *way, FILE *ways_index, long long wayid) |
2153 | { |
5950 | { |
2154 | long offset; |
5951 | long offset; |
2155 | long long idx[2]; |
5952 | long long idx[2]; |
2156 | int count,interval,p; |
5953 | int count, interval, p; |
|
|
5954 | void *p_tmp; |
|
|
5955 | int rr; |
|
|
5956 | size_t data_size2 = sizeof(int); |
|
|
5957 | |
|
|
5958 | fprintf(stderr, "seek_to_way ---\n"); |
|
|
5959 | |
2157 | if (way_hash) { |
5960 | if (way_hash_cfu) |
|
|
5961 | { |
2158 | if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long)wayid, NULL, (gpointer)&offset))) |
5962 | //if (!(g_hash_table_lookup_extended(way_hash, (gpointer) (long) wayid, NULL, (gpointer) & offset))) |
|
|
5963 | //{ |
|
|
5964 | // return 0; |
|
|
5965 | //} |
|
|
5966 | |
|
|
5967 | rr = cfuhash_get_data(way_hash_cfu, (long long) wayid, sizeof(long long), &p_tmp, &data_size2); |
|
|
5968 | if (rr == 0) |
|
|
5969 | { |
2159 | return 0; |
5970 | return 0; |
|
|
5971 | } |
|
|
5972 | |
|
|
5973 | // printf("got value %ld\n", p_tmp); |
|
|
5974 | offset = p_tmp; |
|
|
5975 | |
2160 | fseek(way, offset, SEEK_SET); |
5976 | fseek(way, offset, SEEK_SET); |
2161 | return 1; |
5977 | return 1; |
2162 | } |
5978 | } |
|
|
5979 | |
|
|
5980 | fprintf(stderr, "**BAD**WAYSTUFF**\n"); |
|
|
5981 | |
2163 | fseek(ways_index, 0, SEEK_END); |
5982 | fseek(ways_index, 0, SEEK_END); |
2164 | count=ftell(ways_index)/sizeof(idx); |
5983 | count = ftell(ways_index) / sizeof(idx); |
2165 | interval=count/4; |
5984 | interval = count / 4; |
2166 | p=count/2; |
5985 | p = count / 2; |
2167 | if(interval==0) { |
5986 | if (interval == 0) |
|
|
5987 | { |
2168 | // If fewer than 4 nodes defined so far set interval to 1 to |
5988 | // If fewer than 4 nodes defined so far set interval to 1 to |
2169 | // avoid infinite loop |
5989 | // avoid infinite loop |
2170 | interval = 1; |
5990 | interval = 1; |
2171 | } |
5991 | } |
2172 | if (!load_way_index(ways_index, p, idx)) |
5992 | if (!load_way_index(ways_index, p, idx)) |
2173 | return 0; |
5993 | return 0; |
2174 | for (;;) { |
5994 | for (;;) |
|
|
5995 | { |
2175 | if (idx[0] == wayid) { |
5996 | if (idx[0] == wayid) |
|
|
5997 | { |
2176 | fseek(way, idx[1], SEEK_SET); |
5998 | fseek(way, idx[1], SEEK_SET); |
2177 | return 1; |
5999 | return 1; |
2178 | } |
6000 | } |
2179 | if (idx[0] < wayid) { |
6001 | if (idx[0] < wayid) |
|
|
6002 | { |
2180 | p+=interval; |
6003 | p += interval; |
2181 | if (interval == 1) { |
6004 | if (interval == 1) |
|
|
6005 | { |
2182 | if (p >= count) |
6006 | if (p >= count) |
2183 | return 0; |
6007 | return 0; |
2184 | if (!load_way_index(ways_index, p, idx)) |
6008 | if (!load_way_index(ways_index, p, idx)) |
2185 | return 0; |
6009 | return 0; |
2186 | if (idx[0] > wayid) |
6010 | if (idx[0] > wayid) |
2187 | return 0; |
6011 | return 0; |
|
|
6012 | } |
2188 | } else { |
6013 | else |
|
|
6014 | { |
2189 | if (p >= count) |
6015 | if (p >= count) |
2190 | p=count-1; |
6016 | p = count - 1; |
2191 | if (!load_way_index(ways_index, p, idx)) |
6017 | if (!load_way_index(ways_index, p, idx)) |
2192 | return 0; |
6018 | return 0; |
2193 | } |
6019 | } |
|
|
6020 | } |
2194 | } else { |
6021 | else |
|
|
6022 | { |
2195 | p-=interval; |
6023 | p -= interval; |
2196 | if (interval == 1) { |
6024 | if (interval == 1) |
|
|
6025 | { |
2197 | if (p < 0) |
6026 | if (p < 0) |
2198 | return 0; |
6027 | return 0; |
2199 | if (!load_way_index(ways_index, p, idx)) |
6028 | if (!load_way_index(ways_index, p, idx)) |
2200 | return 0; |
6029 | return 0; |
2201 | if (idx[0] < wayid) |
6030 | if (idx[0] < wayid) |
2202 | return 0; |
6031 | return 0; |
|
|
6032 | } |
2203 | } else { |
6033 | else |
|
|
6034 | { |
2204 | if (p < 0) |
6035 | if (p < 0) |
2205 | p=0; |
6036 | p = 0; |
2206 | if (!load_way_index(ways_index, p, idx)) |
6037 | if (!load_way_index(ways_index, p, idx)) |
2207 | return 0; |
6038 | return 0; |
2208 | } |
6039 | } |
2209 | } |
6040 | } |
2210 | if (interval > 1) |
6041 | if (interval > 1) |
2211 | interval/=2; |
6042 | interval /= 2; |
2212 | } |
6043 | } |
2213 | } |
6044 | } |
2214 | |
|
|
2215 | |
6045 | |
2216 | static struct coord * |
6046 | static struct coord * |
2217 | get_way(FILE *way, FILE *ways_index, struct coord *c, long long wayid, struct item_bin *ret, int debug) |
6047 | get_way(FILE *way, FILE *ways_index, struct coord *c, long long wayid, struct item_bin *ret, int debug) |
2218 | { |
6048 | { |
2219 | long long currid; |
6049 | long long currid; |
2220 | int last; |
6050 | int last; |
2221 | struct coord *ic; |
6051 | struct coord *ic; |
2222 | if (!seek_to_way(way, ways_index, wayid)) { |
6052 | if (!seek_to_way(way, ways_index, wayid)) |
|
|
6053 | { |
2223 | if (debug) |
6054 | if (debug) |
|
|
6055 | { |
2224 | fprintf(stderr,"not found in index"); |
6056 | fprintf(stderr, "not found in index"); |
|
|
6057 | } |
2225 | return NULL; |
6058 | return NULL; |
2226 | } |
6059 | } |
|
|
6060 | |
2227 | while (item_bin_read(ret, way)) { |
6061 | while (item_bin_read(ret, way)) |
|
|
6062 | { |
2228 | currid=item_bin_get_wayid(ret); |
6063 | currid = item_bin_get_wayid(ret); |
2229 | if (debug) |
6064 | if (debug) |
2230 | fprintf(stderr,LONGLONG_FMT":",currid); |
6065 | fprintf(stderr,LONGLONG_FMT":",currid); |
2231 | if (currid != wayid) |
6066 | if (currid != wayid) |
2232 | return NULL; |
6067 | return NULL; |
2233 | ic=(struct coord *)(ret+1); |
6068 | ic = (struct coord *) (ret + 1); |
2234 | last=ret->clen/2-1; |
6069 | last = ret->clen / 2 - 1; |
2235 | if (debug) |
6070 | if (debug) |
2236 | fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)",ic[0].x,ic[0].y,ic[last].x,ic[last].y); |
6071 | fprintf(stderr, "(0x%x,0x%x)-(0x%x,0x%x)", ic[0].x, ic[0].y, ic[last].x, ic[last].y); |
2237 | if (!c) |
6072 | if (!c) |
2238 | return &ic[0]; |
6073 | return &ic[0]; |
2239 | if (ic[0].x == c->x && ic[0].y == c->y) |
6074 | if (ic[0].x == c->x && ic[0].y == c->y) |
2240 | return &ic[last]; |
6075 | return &ic[last]; |
2241 | if (ic[last].x == c->x && ic[last].y == c->y) |
6076 | if (ic[last].x == c->x && ic[last].y == c->y) |
2242 | return &ic[0]; |
6077 | return &ic[0]; |
2243 | } |
6078 | } |
2244 | return NULL; |
6079 | return NULL; |
2245 | } |
6080 | } |
2246 | |
6081 | |
2247 | struct turn_restriction { |
6082 | struct turn_restriction |
|
|
6083 | { |
2248 | osmid relid; |
6084 | osmid relid; |
2249 | enum item_type type; |
6085 | enum item_type type; |
2250 | struct coord *c[3]; |
6086 | struct coord *c[3]; |
2251 | int c_count[3]; |
6087 | int c_count[3]; |
2252 | }; |
6088 | }; |
2253 | |
6089 | |
2254 | static void |
|
|
2255 | process_turn_restrictions_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) |
6090 | static void process_turn_restrictions_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) |
2256 | { |
6091 | { |
2257 | int count,type=(long)member_priv; |
6092 | int count, type = (long) member_priv; |
2258 | struct turn_restriction *turn_restriction=relation_priv; |
6093 | struct turn_restriction *turn_restriction = relation_priv; |
2259 | struct coord *c=(struct coord *)(member+1); |
6094 | struct coord *c = (struct coord *) (member + 1); |
2260 | int ccount=member->clen/2; |
6095 | int ccount = member->clen / 2; |
2261 | |
6096 | |
2262 | if (member->type < type_line) |
6097 | if (member->type < type_line) |
|
|
6098 | { |
2263 | count=1; |
6099 | count = 1; |
|
|
6100 | } |
2264 | else |
6101 | else |
|
|
6102 | { |
2265 | count=2; |
6103 | count = 2; |
2266 | turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count); |
6104 | }turn_restriction->c[type]=g_renew(struct coord, turn_restriction->c[type], turn_restriction->c_count[type]+count); |
2267 | turn_restriction->c[type][turn_restriction->c_count[type]++]=c[0]; |
6105 | turn_restriction->c[type][turn_restriction->c_count[type]++] = c[0]; |
2268 | if (count > 1) |
6106 | if (count > 1) |
|
|
6107 | { |
2269 | turn_restriction->c[type][turn_restriction->c_count[type]++]=c[ccount-1]; |
6108 | turn_restriction->c[type][turn_restriction->c_count[type]++] = c[ccount - 1]; |
|
|
6109 | } |
2270 | } |
6110 | } |
2271 | |
6111 | |
2272 | static void |
|
|
2273 | process_turn_restrictions_fromto(struct turn_restriction *t, int type, struct coord **c) |
6112 | static void process_turn_restrictions_fromto(struct turn_restriction *t, int type, struct coord **c) |
2274 | { |
6113 | { |
2275 | int i,j; |
6114 | int i, j; |
2276 | for (i = 0 ; i < t->c_count[type] ; i+=2) { |
6115 | for (i = 0; i < t->c_count[type]; i += 2) |
|
|
6116 | { |
2277 | for (j = 0 ; j < t->c_count[1] ; j++) { |
6117 | for (j = 0; j < t->c_count[1]; j++) |
|
|
6118 | { |
2278 | if (coord_is_equal(t->c[type][i],t->c[1][j])) { |
6119 | if (coord_is_equal(t->c[type][i], t->c[1][j])) |
|
|
6120 | { |
2279 | c[0]=&t->c[type][i+1]; |
6121 | c[0] = &t->c[type][i + 1]; |
2280 | c[1]=&t->c[type][i]; |
6122 | c[1] = &t->c[type][i]; |
2281 | return; |
6123 | return; |
2282 | } |
6124 | } |
2283 | if (coord_is_equal(t->c[type][i+1],t->c[1][j])) { |
6125 | if (coord_is_equal(t->c[type][i + 1], t->c[1][j])) |
|
|
6126 | { |
2284 | c[0]=&t->c[type][i]; |
6127 | c[0] = &t->c[type][i]; |
2285 | c[1]=&t->c[type][i+1]; |
6128 | c[1] = &t->c[type][i + 1]; |
2286 | return; |
6129 | return; |
2287 | } |
6130 | } |
2288 | } |
6131 | } |
2289 | } |
6132 | } |
2290 | } |
6133 | } |
2291 | |
6134 | |
2292 | static void |
|
|
2293 | process_turn_restrictions_dump_coord(struct coord *c, int count) |
6135 | static void process_turn_restrictions_dump_coord(struct coord *c, int count) |
2294 | { |
6136 | { |
2295 | int i; |
6137 | int i; |
2296 | for (i = 0 ; i < count ; i++) { |
6138 | for (i = 0; i < count; i++) |
|
|
6139 | { |
2297 | fprintf(stderr,"(0x%x,0x%x)",c[i].x,c[i].y); |
6140 | fprintf(stderr, "(0x%x,0x%x)", c[i].x, c[i].y); |
2298 | } |
6141 | } |
2299 | } |
6142 | } |
2300 | |
6143 | |
2301 | static void |
|
|
2302 | process_turn_restrictions_finish(GList *tr, FILE *out) |
6144 | static void process_turn_restrictions_finish(GList *tr, FILE *out) |
2303 | { |
6145 | { |
2304 | GList *l=tr; |
6146 | GList *l = tr; |
2305 | while (l) { |
6147 | while (l) |
|
|
6148 | { |
2306 | struct turn_restriction *t=l->data; |
6149 | struct turn_restriction *t = l->data; |
2307 | struct coord *c[4]; |
6150 | struct coord *c[4]; |
2308 | struct item_bin *ib=item_bin; |
6151 | struct item_bin *ib = item_bin_2; |
2309 | |
6152 | |
|
|
6153 | // init array |
|
|
6154 | c[0] = NULL; |
|
|
6155 | c[1] = NULL; |
|
|
6156 | c[2] = NULL; |
|
|
6157 | c[3] = NULL; |
|
|
6158 | |
2310 | if (!t->c_count[0]) { |
6159 | if (!t->c_count[0]) |
|
|
6160 | { |
2311 | //osm_warning("relation",t->relid,0,"turn restriction: from member not found\n"); |
6161 | //osm_warning("relation",t->relid,0,"turn restriction: from member not found\n"); |
|
|
6162 | } |
2312 | } else if (!t->c_count[1]) { |
6163 | else if (!t->c_count[1]) |
|
|
6164 | { |
2313 | //osm_warning("relation",t->relid,0,"turn restriction: via member not found\n"); |
6165 | //osm_warning("relation",t->relid,0,"turn restriction: via member not found\n"); |
|
|
6166 | } |
2314 | } else if (!t->c_count[2]) { |
6167 | else if (!t->c_count[2]) |
|
|
6168 | { |
2315 | //osm_warning("relation",t->relid,0,"turn restriction: to member not found\n"); |
6169 | //osm_warning("relation",t->relid,0,"turn restriction: to member not found\n"); |
|
|
6170 | } |
2316 | } else { |
6171 | else |
|
|
6172 | { |
2317 | process_turn_restrictions_fromto(t, 0, c); |
6173 | process_turn_restrictions_fromto(t, 0, c); |
2318 | process_turn_restrictions_fromto(t, 2, c+2); |
6174 | process_turn_restrictions_fromto(t, 2, c + 2); |
2319 | if (!c[0] || !c[2]) { |
6175 | if (!c[0] || !c[2]) |
|
|
6176 | { |
2320 | //osm_warning("relation",t->relid,0,"turn restriction: via ("); |
6177 | //osm_warning("relation",t->relid,0,"turn restriction: via ("); |
2321 | //process_turn_restrictions_dump_coord(t->c[1], t->c_count[1]); |
6178 | //process_turn_restrictions_dump_coord(t->c[1], t->c_count[1]); |
2322 | //fprintf(stderr,")"); |
6179 | //fprintf(stderr,")"); |
2323 | if (!c[0]) { |
6180 | if (!c[0]) |
|
|
6181 | { |
2324 | //fprintf(stderr," failed to connect to from ("); |
6182 | //fprintf(stderr," failed to connect to from ("); |
2325 | //process_turn_restrictions_dump_coord(t->c[0], t->c_count[0]); |
6183 | //process_turn_restrictions_dump_coord(t->c[0], t->c_count[0]); |
2326 | //fprintf(stderr,")"); |
6184 | //fprintf(stderr,")"); |
2327 | } |
6185 | } |
2328 | if (!c[2]) { |
6186 | if (!c[2]) |
|
|
6187 | { |
2329 | //fprintf(stderr," failed to connect to to ("); |
6188 | //fprintf(stderr," failed to connect to to ("); |
2330 | //process_turn_restrictions_dump_coord(t->c[2], t->c_count[2]); |
6189 | //process_turn_restrictions_dump_coord(t->c[2], t->c_count[2]); |
2331 | //fprintf(stderr,")"); |
6190 | //fprintf(stderr,")"); |
2332 | } |
6191 | } |
2333 | //fprintf(stderr,"\n"); |
6192 | //fprintf(stderr,"\n"); |
|
|
6193 | } |
2334 | } else { |
6194 | else |
|
|
6195 | { |
2335 | if (t->c_count[1] <= 2) { |
6196 | if (t->c_count[1] <= 2) |
|
|
6197 | { |
2336 | item_bin_init(ib,t->type); |
6198 | item_bin_init(ib, t->type); |
2337 | item_bin_add_coord(ib, c[0], 1); |
6199 | item_bin_add_coord(ib, c[0], 1); |
2338 | item_bin_add_coord(ib, c[1], 1); |
6200 | item_bin_add_coord(ib, c[1], 1); |
2339 | if (t->c_count[1] > 1) |
6201 | if (t->c_count[1] > 1) |
|
|
6202 | { |
2340 | item_bin_add_coord(ib, c[3], 1); |
6203 | item_bin_add_coord(ib, c[3], 1); |
|
|
6204 | } |
2341 | item_bin_add_coord(ib, c[2], 1); |
6205 | item_bin_add_coord(ib, c[2], 1); |
2342 | item_bin_write(ib, out); |
6206 | item_bin_write(ib, out); |
2343 | } |
6207 | } |
2344 | |
6208 | |
2345 | } |
6209 | } |
2346 | } |
6210 | } |
2347 | g_free(t); |
6211 | g_free(t); |
2348 | l=g_list_next(l); |
6212 | l = g_list_next(l); |
2349 | } |
6213 | } |
2350 | g_list_free(tr); |
6214 | g_list_free(tr); |
2351 | } |
6215 | } |
2352 | |
6216 | |
2353 | static GList * |
6217 | static GList * |
2354 | process_turn_restrictions_setup(FILE *in, struct relations *relations) |
6218 | process_turn_restrictions_setup(FILE *in, struct relations *relations) |
2355 | { |
6219 | { |
2356 | struct relation_member fromm,tom,viam,tmpm; |
6220 | struct relation_member fromm, tom, viam, tmpm; |
2357 | long long relid; |
6221 | long long relid; |
2358 | struct item_bin *ib; |
6222 | struct item_bin *ib; |
2359 | struct relations_func *relations_func; |
6223 | struct relations_func *relations_func; |
2360 | int min_count; |
6224 | int min_count; |
2361 | GList *turn_restrictions=NULL; |
6225 | GList *turn_restrictions = NULL; |
2362 | |
6226 | |
2363 | fseek(in, 0, SEEK_SET); |
6227 | fseek(in, 0, SEEK_SET); |
2364 | relations_func=relations_func_new(process_turn_restrictions_member, NULL); |
6228 | relations_func = relations_func_new(process_turn_restrictions_member, NULL); |
2365 | while ((ib=read_item(in))) { |
6229 | while ((ib = read_item(in, 0))) |
|
|
6230 | { |
2366 | struct turn_restriction *turn_restriction=g_new0(struct turn_restriction, 1); |
6231 | struct turn_restriction *turn_restriction=g_new0(struct turn_restriction, 1); |
2367 | relid=item_bin_get_relationid(ib); |
6232 | relid = item_bin_get_relationid(ib); |
2368 | turn_restriction->relid=relid; |
6233 | turn_restriction->relid = relid; |
2369 | turn_restriction->type=ib->type; |
6234 | turn_restriction->type = ib->type; |
2370 | min_count=0; |
6235 | min_count = 0; |
2371 | if (!search_relation_member(ib, "from",&fromm,&min_count)) { |
6236 | if (!search_relation_member(ib, "from", &fromm, &min_count)) |
|
|
6237 | { |
2372 | //osm_warning("relation",relid,0,"turn restriction: from member missing\n"); |
6238 | osm_warning("relation", relid, 0, "turn restriction: from member missing\n"); |
2373 | continue; |
6239 | continue; |
2374 | } |
6240 | } |
2375 | if (search_relation_member(ib, "from",&tmpm,&min_count)) { |
6241 | if (search_relation_member(ib, "from", &tmpm, &min_count)) |
|
|
6242 | { |
2376 | //osm_warning("relation",relid,0,"turn restriction: multiple from members\n"); |
6243 | osm_warning("relation", relid, 0, "turn restriction: multiple from members\n"); |
2377 | continue; |
6244 | continue; |
2378 | } |
6245 | } |
2379 | min_count=0; |
6246 | min_count = 0; |
2380 | if (!search_relation_member(ib, "to",&tom,&min_count)) { |
6247 | if (!search_relation_member(ib, "to", &tom, &min_count)) |
|
|
6248 | { |
2381 | //osm_warning("relation",relid,0,"turn restriction: to member missing\n"); |
6249 | osm_warning("relation", relid, 0, "turn restriction: to member missing\n"); |
2382 | continue; |
6250 | continue; |
2383 | } |
6251 | } |
2384 | if (search_relation_member(ib, "to",&tmpm,&min_count)) { |
6252 | if (search_relation_member(ib, "to", &tmpm, &min_count)) |
|
|
6253 | { |
2385 | //osm_warning("relation",relid,0,"turn restriction: multiple to members\n"); |
6254 | osm_warning("relation", relid, 0, "turn restriction: multiple to members\n"); |
2386 | continue; |
6255 | continue; |
2387 | } |
6256 | } |
2388 | min_count=0; |
6257 | min_count = 0; |
2389 | if (!search_relation_member(ib, "via",&viam,&min_count)) { |
6258 | if (!search_relation_member(ib, "via", &viam, &min_count)) |
|
|
6259 | { |
2390 | //osm_warning("relation",relid,0,"turn restriction: via member missing\n"); |
6260 | osm_warning("relation", relid, 0, "turn restriction: via member missing\n"); |
2391 | continue; |
6261 | continue; |
2392 | } |
6262 | } |
2393 | if (search_relation_member(ib, "via",&tmpm,&min_count)) { |
6263 | if (search_relation_member(ib, "via", &tmpm, &min_count)) |
|
|
6264 | { |
2394 | //osm_warning("relation",relid,0,"turn restriction: multiple via member\n"); |
6265 | osm_warning("relation", relid, 0, "turn restriction: multiple via member\n"); |
2395 | continue; |
6266 | continue; |
2396 | } |
6267 | } |
2397 | if (fromm.type != 2) { |
6268 | if (fromm.type != 2) |
|
|
6269 | { |
2398 | //osm_warning("relation",relid,0,"turn restriction: wrong type for from member "); |
6270 | osm_warning("relation", relid, 0, "turn restriction: wrong type for from member "); |
2399 | //osm_warning(osm_types[fromm.type],fromm.id,1,"\n"); |
6271 | osm_warning(osm_types[fromm.type], fromm.id, 1, "\n"); |
2400 | continue; |
6272 | continue; |
2401 | } |
6273 | } |
2402 | if (tom.type != 2) { |
6274 | if (tom.type != 2) |
|
|
6275 | { |
2403 | //osm_warning("relation",relid,0,"turn restriction: wrong type for to member "); |
6276 | osm_warning("relation", relid, 0, "turn restriction: wrong type for to member "); |
2404 | //osm_warning(osm_types[tom.type],tom.id,1,"\n"); |
6277 | osm_warning(osm_types[tom.type], tom.id, 1, "\n"); |
2405 | continue; |
6278 | continue; |
2406 | } |
6279 | } |
2407 | if (viam.type != 1 && viam.type != 2) { |
6280 | if (viam.type != 1 && viam.type != 2) |
|
|
6281 | { |
2408 | //osm_warning("relation",relid,0,"turn restriction: wrong type for via member "); |
6282 | osm_warning("relation", relid, 0, "turn restriction: wrong type for via member "); |
2409 | //osm_warning(osm_types[viam.type],viam.id,1,"\n"); |
6283 | osm_warning(osm_types[viam.type], viam.id, 1, "\n"); |
2410 | continue; |
6284 | continue; |
2411 | } |
6285 | } |
2412 | relations_add_func(relations, relations_func, turn_restriction, (gpointer) 0, fromm.type, fromm.id); |
6286 | relations_add_func(relations, relations_func, turn_restriction, (gpointer) 0, fromm.type, fromm.id); |
2413 | relations_add_func(relations, relations_func, turn_restriction, (gpointer) 1, viam.type, viam.id); |
6287 | relations_add_func(relations, relations_func, turn_restriction, (gpointer) 1, viam.type, viam.id); |
2414 | relations_add_func(relations, relations_func, turn_restriction, (gpointer) 2, tom.type, tom.id); |
6288 | relations_add_func(relations, relations_func, turn_restriction, (gpointer) 2, tom.type, tom.id); |
2415 | turn_restrictions=g_list_append(turn_restrictions, turn_restriction); |
6289 | turn_restrictions = g_list_append(turn_restrictions, turn_restriction); |
2416 | } |
6290 | } |
2417 | return turn_restrictions; |
6291 | return turn_restrictions; |
2418 | } |
6292 | } |
2419 | |
6293 | |
2420 | void |
|
|
2421 | process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) |
6294 | void process_turn_restrictions(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) |
2422 | { |
6295 | { |
2423 | struct relations *relations=relations_new(); |
6296 | struct relations *relations = relations_new(); |
2424 | GList *turn_restrictions; |
6297 | GList *turn_restrictions; |
2425 | fseek(in, 0, SEEK_SET); |
6298 | fseek(in, 0, SEEK_SET); |
|
|
6299 | if (verbose_mode) |
|
|
6300 | fprintf(stderr, "process_turn_restrictions A1\n"); |
2426 | turn_restrictions=process_turn_restrictions_setup(in, relations); |
6301 | turn_restrictions = process_turn_restrictions_setup(in, relations); |
|
|
6302 | if (verbose_mode) |
|
|
6303 | fprintf(stderr, "process_turn_restrictions B2\n"); |
2427 | relations_process(relations, coords, ways, NULL); |
6304 | relations_process(relations, coords, ways, NULL); |
|
|
6305 | if (verbose_mode) |
|
|
6306 | fprintf(stderr, "process_turn_restrictions C3\n"); |
2428 | process_turn_restrictions_finish(turn_restrictions, out); |
6307 | process_turn_restrictions_finish(turn_restrictions, out); |
|
|
6308 | if (verbose_mode) |
|
|
6309 | fprintf(stderr, "process_turn_restrictions D4\n"); |
2429 | } |
6310 | } |
2430 | |
6311 | |
2431 | void |
6312 | static void node_ref_way(osmid node, int local_thread_num) |
2432 | process_turn_restrictions_old(FILE *in, FILE *coords, FILE *ways, FILE *ways_index, FILE *out) |
|
|
2433 | { |
6313 | { |
2434 | struct relation_member fromm,tom,viam,tmpm; |
|
|
2435 | struct node_item ni; |
6314 | struct node_item *ni; |
|
|
6315 | ni = node_item_get_fast(node, local_thread_num); |
|
|
6316 | if (ni) |
|
|
6317 | { |
|
|
6318 | ni->ref_way++; |
|
|
6319 | } |
|
|
6320 | } |
|
|
6321 | |
|
|
6322 | static void nodes_ref_item_bin(struct item_bin *ib, int local_thread_num, osmid this_way_id) |
|
|
6323 | { |
|
|
6324 | int i; |
|
|
6325 | osmid way_node; |
|
|
6326 | struct coord *c = (struct coord *) (ib + 1); // set pointer to coord struct of this item |
|
|
6327 | for (i = 0; i < ib->clen / 2; i++) |
|
|
6328 | { |
|
|
6329 | way_node = get_waynode_num(this_way_id, i, local_thread_num); |
|
|
6330 | node_ref_way(way_node, local_thread_num); |
|
|
6331 | //fprintf(stderr, "ref2=%lld this_way_id=%lld\n", way_node, this_way_id); |
|
|
6332 | } |
|
|
6333 | |
|
|
6334 | //fprintf(stderr,"********DUMP rw ***********\n"); |
|
|
6335 | //dump_itembin(ib); |
|
|
6336 | //fprintf(stderr,"********DUMP rw ***********\n"); |
|
|
6337 | |
|
|
6338 | } |
|
|
6339 | |
|
|
6340 | osmid get_waynode_num(osmid way_id, int coord_num, int local_thread_num) |
|
|
6341 | { |
|
|
6342 | int rc2; |
|
|
6343 | sqlite3_stmt *st; |
|
|
6344 | osmid nd; |
|
|
6345 | long long seekpos_waynode2; |
|
|
6346 | #define __USE_WAYNODEFILE_CACHE__ 1 |
|
|
6347 | |
|
|
6348 | //fprintf(stderr, "get_waynode_num:w=%lld cnum=%d\n", way_id, (coord_num + 1)); |
|
|
6349 | |
|
|
6350 | if (last_seek_wayid[local_thread_num] != way_id) |
|
|
6351 | { |
|
|
6352 | |
|
|
6353 | last_seek_wayid[local_thread_num] = way_id; |
|
|
6354 | |
|
|
6355 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
6356 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
|
|
6357 | { |
|
|
6358 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
6359 | { |
|
|
6360 | #endif |
|
|
6361 | st = stmt_sel0012_tt[local_thread_num]; |
|
|
6362 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
6363 | } |
|
|
6364 | else |
|
|
6365 | { |
|
|
6366 | st = stmt_sel0012b_tt[local_thread_num]; |
|
|
6367 | } |
|
|
6368 | } |
|
|
6369 | else |
|
|
6370 | { |
|
|
6371 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
6372 | { |
|
|
6373 | st = stmt_sel0012__2_tt[local_thread_num]; |
|
|
6374 | } |
|
|
6375 | else |
|
|
6376 | { |
|
|
6377 | st = stmt_sel0012__2b_tt[local_thread_num]; |
|
|
6378 | } |
|
|
6379 | } |
|
|
6380 | #endif |
|
|
6381 | |
|
|
6382 | sqlite3_bind_int64(st, 1, way_id); |
|
|
6383 | sqlite3_bind_int(st, 2, (int)1); |
|
|
6384 | |
|
|
6385 | // execute the statement |
|
|
6386 | rc2 = sqlite3_step(st); |
|
|
6387 | switch (rc2) |
|
|
6388 | { |
|
|
6389 | case SQLITE_DONE: |
|
|
6390 | break; |
|
|
6391 | case SQLITE_ROW: |
|
|
6392 | seekpos_waynode[local_thread_num] = sqlite3_column_int64(st, 1); |
|
|
6393 | break; |
|
|
6394 | default: |
|
|
6395 | fprintf(stderr, "Error: %d\n", rc2); |
|
|
6396 | break; |
|
|
6397 | } |
|
|
6398 | sqlite3_reset(st); |
|
|
6399 | } |
|
|
6400 | |
|
|
6401 | seekpos_waynode2 = seekpos_waynode[local_thread_num] + (sizeof(osmid) * coord_num); // seek to coord in way |
|
|
6402 | |
|
|
6403 | if ((! __USE_WAYNODEFILE_CACHE__) || (seekpos_waynode2 != last_seekpos_waynode[local_thread_num])) |
|
|
6404 | { |
|
|
6405 | //fprintf(stderr, "w seek3 seekpos_waynode=%lld last_seekpos_waynode=%lld\n", seekpos_waynode[local_thread_num], last_seekpos_waynode[local_thread_num]); |
|
|
6406 | fseeko(ways_ref_file_thread[local_thread_num], (off_t)seekpos_waynode2, SEEK_SET); |
|
|
6407 | } |
|
|
6408 | //else |
|
|
6409 | //{ |
|
|
6410 | // fprintf(stderr, "w seek3:NO SEEK\n"); |
|
|
6411 | //} |
|
|
6412 | |
|
|
6413 | int fret = (int)fread(&nd, sizeof(osmid), 1, ways_ref_file_thread[local_thread_num]); |
|
|
6414 | if (fret == 0) |
|
|
6415 | { |
|
|
6416 | fprintf(stderr, "**ERROR** at fread 002b: wayid:%lld count=%d\n", way_id, coord_num); |
|
|
6417 | } |
|
|
6418 | else if ((osmid)nd > 4994968164L) |
|
|
6419 | { |
|
|
6420 | fprintf(stderr, "**ERROR** at fread 002b: wayid:%lld count=%d w_node=%lld\n", way_id, coord_num, (osmid)nd); |
|
|
6421 | } |
|
|
6422 | |
|
|
6423 | |
|
|
6424 | last_seekpos_waynode[local_thread_num] = seekpos_waynode2 + sizeof(osmid); |
|
|
6425 | // fprintf(stderr, "get_waynode_num:result node=%lld last_seekpos_waynode=%lld\n", nd, last_seekpos_waynode[local_thread_num]); |
|
|
6426 | |
|
|
6427 | return nd; |
|
|
6428 | } |
|
|
6429 | |
|
|
6430 | void add_waynode_to_db(osmid ref, int c_count) |
|
|
6431 | { |
|
|
6432 | // ------- save way node to SQL db ------------ |
|
|
6433 | #ifdef MAPTOOL_USE_SQL |
|
|
6434 | |
|
|
6435 | if (sql_counter4 == 0) |
|
|
6436 | { |
|
|
6437 | sqlite3_exec(sql_handle004, "BEGIN", 0, 0, 0); |
|
|
6438 | sqlite3_exec(sql_handle005, "BEGIN", 0, 0, 0); |
|
|
6439 | sqlite3_exec(sql_handle006, "BEGIN", 0, 0, 0); |
|
|
6440 | sqlite3_exec(sql_handle007, "BEGIN", 0, 0, 0); |
|
|
6441 | //fprintf(stderr, "begin: way nodes\n"); |
|
|
6442 | } |
|
|
6443 | sql_counter4++; |
|
|
6444 | //fprintf(stderr, "insert #WN:wid=%lld ccount=%d ref=%lld\n", osmid_attr_value, c_count + 1, ref); |
|
|
6445 | |
|
|
6446 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
6447 | if ((osmid_attr_value & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
|
|
6448 | { |
|
|
6449 | if ((osmid_attr_value & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
6450 | { |
|
|
6451 | #endif |
|
|
6452 | sqlite3_bind_int64(stmt_way_node, 1, osmid_attr_value); |
|
|
6453 | sqlite3_bind_int64(stmt_way_node, 2, ref); |
|
|
6454 | sqlite3_bind_int(stmt_way_node, 3, c_count + 1); |
|
|
6455 | sqlite3_bind_int64(stmt_way_node, 4, seekpos1); |
|
|
6456 | sqlite3_step(stmt_way_node); |
|
|
6457 | sqlite3_reset(stmt_way_node); |
|
|
6458 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
|
|
6459 | } |
|
|
6460 | else |
|
|
6461 | { |
|
|
6462 | sqlite3_bind_int64(stmt_way_nodeb, 1, osmid_attr_value); |
|
|
6463 | sqlite3_bind_int64(stmt_way_nodeb, 2, ref); |
|
|
6464 | sqlite3_bind_int(stmt_way_nodeb, 3, c_count + 1); |
|
|
6465 | sqlite3_bind_int64(stmt_way_nodeb, 4, seekpos1); |
|
|
6466 | sqlite3_step(stmt_way_nodeb); |
|
|
6467 | sqlite3_reset(stmt_way_nodeb); |
|
|
6468 | } |
|
|
6469 | } |
|
|
6470 | else |
|
|
6471 | { |
|
|
6472 | if ((osmid_attr_value & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
|
|
6473 | { |
|
|
6474 | sqlite3_bind_int64(stmt_way_node__2, 1, osmid_attr_value); |
|
|
6475 | sqlite3_bind_int64(stmt_way_node__2, 2, ref); |
|
|
6476 | sqlite3_bind_int(stmt_way_node__2, 3, c_count + 1); |
|
|
6477 | sqlite3_bind_int64(stmt_way_node__2, 4, seekpos1); |
|
|
6478 | sqlite3_step(stmt_way_node__2); |
|
|
6479 | sqlite3_reset(stmt_way_node__2); |
|
|
6480 | } |
|
|
6481 | else |
|
|
6482 | { |
|
|
6483 | sqlite3_bind_int64(stmt_way_node__2b, 1, osmid_attr_value); |
|
|
6484 | sqlite3_bind_int64(stmt_way_node__2b, 2, ref); |
|
|
6485 | sqlite3_bind_int(stmt_way_node__2b, 3, c_count + 1); |
|
|
6486 | sqlite3_bind_int64(stmt_way_node__2b, 4, seekpos1); |
|
|
6487 | sqlite3_step(stmt_way_node__2b); |
|
|
6488 | sqlite3_reset(stmt_way_node__2b); |
|
|
6489 | } |
|
|
6490 | } |
|
|
6491 | #endif |
|
|
6492 | |
|
|
6493 | if (sql_counter4 > MAX_ROWS_WO_COMMIT_4) |
|
|
6494 | { |
|
|
6495 | sqlite3_exec(sql_handle004, "COMMIT", 0, 0, 0); |
|
|
6496 | sqlite3_exec(sql_handle005, "COMMIT", 0, 0, 0); |
|
|
6497 | sqlite3_exec(sql_handle006, "COMMIT", 0, 0, 0); |
|
|
6498 | sqlite3_exec(sql_handle007, "COMMIT", 0, 0, 0); |
|
|
6499 | //fprintf(stderr, "COMMIT:way nodes: %lld\n", sql_counter4); |
|
|
6500 | sql_counter4 = 0; |
|
|
6501 | } |
|
|
6502 | #endif |
|
|
6503 | // ------- save way node to SQL db ------------ |
|
|
6504 | |
|
|
6505 | |
|
|
6506 | // fprintf(stderr, "osm_add_nd:FIN\n"); |
|
|
6507 | |
|
|
6508 | } |
|
|
6509 | |
|
|
6510 | void osm_add_nd(osmid ref) |
|
|
6511 | { |
|
|
6512 | // SET_REF(&coord_buffer[coord_count], ref); |
|
|
6513 | |
|
|
6514 | //fprintf(stderr, "osm_add_nd:result way=%lld node=%lld\n", osmid_attr_value, ref); |
|
|
6515 | |
|
|
6516 | // put lat, lon into &coord_buffer[coord_count] -------- START ---------- |
|
|
6517 | struct coord *c = &coord_buffer[coord_count]; |
|
|
6518 | c->x = REF_X; |
|
|
6519 | // c->y = REF_Y; |
|
|
6520 | c->y = coord_count; // number of this node in the way (starting at zero) |
|
|
6521 | // put lat, lon into &coord_buffer[coord_count] -------- START ---------- |
|
|
6522 | |
|
|
6523 | if (coord_count == 0) |
|
|
6524 | { |
|
|
6525 | first_node_of_current_way = ref; |
|
|
6526 | //fprintf(stderr, "w ftell1\n"); |
|
|
6527 | seekpos1 = (long long)ftello(ways_ref_file); // 64bit |
|
|
6528 | } |
|
|
6529 | |
|
|
6530 | //fprintf(stderr, "write:wid=%lld nd=%lld seekpos1=%lld\n", osmid_attr_value, ref, seekpos1); |
|
|
6531 | fwrite(&ref, sizeof(osmid), 1, ways_ref_file); // write way node to ref file |
|
|
6532 | //ftello(ways_ref_file); // --> sometimes this is needed!! |
|
|
6533 | //fprintf(stderr, "coord_count=%d filepos after write=%lld\n", coord_count, (long long)ff); |
|
|
6534 | |
|
|
6535 | coord_count++; |
|
|
6536 | if (coord_count > 65536) |
|
|
6537 | { |
|
|
6538 | fprintf(stderr, "ERROR: Overflow\n"); |
|
|
6539 | exit(1); |
|
|
6540 | } |
|
|
6541 | } |
|
|
6542 | |
|
|
6543 | 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) |
|
|
6544 | { |
|
|
6545 | struct item_bin new; |
|
|
6546 | struct coord *c = (struct coord *) (orig + 1); |
|
|
6547 | char *attr = (char *) (c + orig->clen / 2); |
|
|
6548 | int attr_len = orig->len - orig->clen - 2; |
|
|
6549 | processed_ways++; |
|
|
6550 | new.type = orig->type; |
|
|
6551 | new.clen = (last - first + 1) * 2; |
|
|
6552 | new.len = new.clen + attr_len + 2; |
|
|
6553 | |
|
|
6554 | if (out_index) |
|
|
6555 | { |
2436 | long long relid; |
6556 | long long idx[2]; |
2437 | char from_buffer[65536],to_buffer[65536],via_buffer[65536]; |
6557 | idx[0] = item_bin_get_wayid(orig); |
2438 | struct item_bin *ib,*from=(struct item_bin *)from_buffer,*to=(struct item_bin *)to_buffer,*via=(struct item_bin *)via_buffer; |
6558 | idx[1] = ftello(out); |
2439 | struct coord *fromc,*toc,*viafrom,*viato,*tmp; |
6559 | if (way_hash_cfu) |
2440 | int min_count; |
6560 | { |
|
|
6561 | //if (!(g_hash_table_lookup_extended(way_hash, (gpointer) (long) idx[0], NULL, NULL))) |
|
|
6562 | //{ |
|
|
6563 | // g_hash_table_insert(way_hash, (gpointer) (long) idx[0], (gpointer) (long) idx[1]); |
|
|
6564 | // // fprintf(stderr,"way_hash size="LONGLONG_FMT"\n", g_hash_table_size(way_hash)); |
|
|
6565 | //} |
|
|
6566 | |
|
|
6567 | if (!cfuhash_exists_data(way_hash_cfu, (long long) idx[0], sizeof(long long))) |
|
|
6568 | { |
|
|
6569 | cfuhash_put_data(way_hash_cfu, (long long) idx[0], sizeof(long long), (int) idx[1], sizeof(int), NULL); |
|
|
6570 | } |
|
|
6571 | } |
|
|
6572 | else |
|
|
6573 | { |
|
|
6574 | if (!last_id || *last_id != idx[0]) |
|
|
6575 | { |
|
|
6576 | fwrite(idx, sizeof(idx), 1, out_index); |
|
|
6577 | } |
|
|
6578 | |
|
|
6579 | if (last_id) |
|
|
6580 | { |
|
|
6581 | *last_id = idx[0]; |
|
|
6582 | } |
|
|
6583 | } |
|
|
6584 | |
|
|
6585 | } |
|
|
6586 | |
|
|
6587 | fwrite(&new, sizeof(new), 1, out); |
|
|
6588 | fwrite(c + first, new.clen * 4, 1, out); |
|
|
6589 | fwrite(attr, attr_len * 4, 1, out); |
|
|
6590 | } |
|
|
6591 | |
|
|
6592 | void ref_ways(FILE *in, int local_thread_num) |
|
|
6593 | { |
|
|
6594 | struct item_bin *ib; |
|
|
6595 | |
|
|
6596 | long long ways_count = 0; |
|
|
6597 | osmid *this_way_id; |
|
|
6598 | |
|
|
6599 | // ---------- reset the cached values ---------- |
|
|
6600 | seekpos_waynode[local_thread_num] = -1; |
|
|
6601 | last_seekpos_waynode[local_thread_num] = -1; |
|
|
6602 | last_seek_wayid[local_thread_num] = -1; |
|
|
6603 | fseeko(ways_ref_file_thread[local_thread_num], (off_t)0, SEEK_SET); |
|
|
6604 | // ---------- reset the cached values ---------- |
|
|
6605 | |
|
|
6606 | |
|
|
6607 | fseek(in, 0, SEEK_SET); |
|
|
6608 | while ((ib = read_item(in, local_thread_num))) // loop all "ways" from file "in" |
|
|
6609 | { |
|
|
6610 | this_way_id = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
|
|
6611 | if (this_way_id) |
|
|
6612 | { |
|
|
6613 | nodes_ref_item_bin(ib, local_thread_num, *this_way_id); |
|
|
6614 | } |
|
|
6615 | else |
|
|
6616 | { |
|
|
6617 | // no "way id"? so we do nothing |
|
|
6618 | // nodes_ref_item_bin(ib, local_thread_num, 0); |
|
|
6619 | } |
|
|
6620 | ways_count++; |
|
|
6621 | |
|
|
6622 | if ((ways_count % 1000000) == 0) |
|
|
6623 | { |
|
|
6624 | fprintf(stderr, "[THREAD] #%d ways: %lld\n", local_thread_num, ways_count); |
|
|
6625 | } |
|
|
6626 | } |
|
|
6627 | } |
|
|
6628 | |
|
|
6629 | |
|
|
6630 | /** |
|
|
6631 | * Get POI coordinates from line coordinates. |
|
|
6632 | * @param in *in input file with line coordinates. |
|
|
6633 | * @param in *out output file with POI coordinates |
|
|
6634 | * @param in type input file original contents type: type_line or type_area |
|
|
6635 | * @returns nothing |
|
|
6636 | */ |
|
|
6637 | void process_way2poi_housenumber(FILE *in, FILE *out) |
|
|
6638 | { |
|
|
6639 | struct item_bin *ib; |
|
|
6640 | // char *house_number = NULL; |
|
|
6641 | // char *street_name = NULL; |
|
|
6642 | |
2441 | while ((ib=read_item(in))) { |
6643 | while ((ib = read_item(in, 0))) |
2442 | relid=item_bin_get_relationid(ib); |
6644 | { |
2443 | min_count=0; |
6645 | int count = ib->clen / 2; |
2444 | if (!search_relation_member(ib, "from",&fromm,&min_count)) { |
6646 | if (count > 1 && ib->type == type_poly_building) |
2445 | osm_warning("relation",relid,0,"turn restriction: from member missing\n"); |
6647 | { |
|
|
6648 | struct coord *c = (struct coord *) (ib + 1), c1, c2; |
|
|
6649 | int done = 0; |
|
|
6650 | //if (ib->type == type_area) // --> buildings are "lines" now, not polys |
|
|
6651 | //{ |
|
|
6652 | if (count < 3) |
|
|
6653 | { |
|
|
6654 | osm_warning("way", item_bin_get_wayid(ib), 0, "Broken polygon, less than 3 points defined\n"); |
|
|
6655 | } |
|
|
6656 | else if (!geom_poly_centroid(c, count, &c1)) |
|
|
6657 | { |
|
|
6658 | osm_warning("way", item_bin_get_wayid(ib), 0, "Broken polygon, area is 0\n"); |
|
|
6659 | } |
|
|
6660 | else |
|
|
6661 | { |
|
|
6662 | if (geom_poly_point_inside(c, count, &c1)) |
|
|
6663 | { |
|
|
6664 | //fprintf(stderr, "geom_poly_point_inside\n"); |
|
|
6665 | c[0] = c1; |
|
|
6666 | } |
|
|
6667 | else |
|
|
6668 | { |
|
|
6669 | //fprintf(stderr, "geom_poly_closest_point\n"); |
|
|
6670 | geom_poly_closest_point(c, count, &c1, &c2); |
|
|
6671 | c[0] = c2; |
|
|
6672 | } |
|
|
6673 | done = 1; |
|
|
6674 | } |
|
|
6675 | //} |
|
|
6676 | |
|
|
6677 | if (!done) |
|
|
6678 | { |
|
|
6679 | //fprintf(stderr, "geom_line_middle\n"); |
|
|
6680 | geom_line_middle(c, count, &c1); |
|
|
6681 | c[0] = c1; |
|
|
6682 | } |
|
|
6683 | |
|
|
6684 | char *street_name = item_bin_get_attr(ib, attr_street_name_dummy, NULL); |
|
|
6685 | char *house_number = item_bin_get_attr(ib, attr_house_number_dummy, NULL); |
|
|
6686 | if ((street_name != NULL) && (house_number != NULL)) |
|
|
6687 | { |
|
|
6688 | osm_append_housenumber_node(out, c, house_number, street_name); |
|
|
6689 | } |
|
|
6690 | } |
|
|
6691 | } |
|
|
6692 | } |
|
|
6693 | |
|
|
6694 | void fill_hash_waytag(void) |
|
|
6695 | { |
|
|
6696 | if (verbose_mode) |
|
|
6697 | fprintf(stderr, "fill_hash_waytag - START\n"); |
|
|
6698 | if (waytag_hash) |
|
|
6699 | { |
|
|
6700 | g_hash_table_destroy(waytag_hash); |
|
|
6701 | waytag_hash = NULL; |
|
|
6702 | } |
|
|
6703 | waytag_hash = g_hash_table_new(NULL, NULL); |
|
|
6704 | waytag_buffer_to_hash(); |
|
|
6705 | if (verbose_mode) |
|
|
6706 | fprintf(stderr, "fill_hash_waytag - END\n"); |
|
|
6707 | } |
|
|
6708 | |
|
|
6709 | void append_pre_resolved_ways(FILE *out, struct maptool_osm *osm2) |
|
|
6710 | { |
|
|
6711 | struct item_bin *ib; |
|
|
6712 | |
|
|
6713 | // fseek(out, 0, SEEK_END); // seek to the end of current way-file |
|
|
6714 | rewind(osm2->ways_with_coords); // start with the first "way" |
|
|
6715 | |
|
|
6716 | while ((ib = read_item(osm2->ways_with_coords, 0))) // loop thru all "ways" from file "in" |
|
|
6717 | { |
|
|
6718 | // write way to outfile |
|
|
6719 | item_bin_write(ib, out); |
|
|
6720 | } |
|
|
6721 | } |
|
|
6722 | |
|
|
6723 | int copy_tags_to_ways(FILE *in, FILE *out, FILE *tags_in) |
|
|
6724 | { |
|
|
6725 | struct item_bin *ib; |
|
|
6726 | |
|
|
6727 | long long slice_size2 = sizeof(struct way_tag) * 1024 * 1024; // xx MByte |
|
|
6728 | long long final_slice_size2; |
|
|
6729 | struct way_tag *wt3; |
|
|
6730 | int slices2 = 0; |
|
|
6731 | int i; |
|
|
6732 | struct stat st; |
|
|
6733 | int final_slice = 0; |
|
|
6734 | long long size2; |
|
|
6735 | |
|
|
6736 | fseek(tags_in, 0, SEEK_END); |
|
|
6737 | size2 = ftello(tags_in); // 64bit |
|
|
6738 | |
|
|
6739 | slices2 = (size2 / slice_size2) + 1; |
|
|
6740 | final_slice_size2 = size2 - ((slices2 - 1) * slice_size2); |
|
|
6741 | |
|
|
6742 | if (slices2 == 1) |
|
|
6743 | { |
|
|
6744 | final_slice_size2 = size2; |
|
|
6745 | } |
|
|
6746 | |
|
|
6747 | if (verbose_mode) fprintf(stderr, "relationsfile size="LONGLONG_FMT" bytes\n", size2); |
|
|
6748 | if (verbose_mode) fprintf(stderr, "final_slice_size2="LONGLONG_FMT" bytes\n", final_slice_size2); |
|
|
6749 | if (verbose_mode) |
|
|
6750 | fprintf(stderr, "slices=%d\n", slices2); |
|
|
6751 | |
|
|
6752 | for (i = 0; i < slices2; i++) |
|
|
6753 | { |
|
|
6754 | if (i == (slices2 - 1)) |
|
|
6755 | { |
|
|
6756 | final_slice = 1; |
|
|
6757 | } |
|
|
6758 | |
|
|
6759 | if (final_slice == 1) |
|
|
6760 | { |
|
|
6761 | load_buffer_fp(tags_in, &waytag_buffer, i * slice_size2, final_slice_size2); // load in the relations |
|
|
6762 | } |
|
|
6763 | else |
|
|
6764 | { |
|
|
6765 | load_buffer_fp(tags_in, &waytag_buffer, i * slice_size2, slice_size2); // load in the relations |
|
|
6766 | } |
|
|
6767 | fill_hash_waytag(); |
|
|
6768 | struct way_tag *wt2 = (struct way_tag *) (waytag_buffer.base); |
|
|
6769 | |
|
|
6770 | rewind(in); // start with the first "way" |
|
|
6771 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
|
|
6772 | { |
|
|
6773 | if (waytag_hash) |
|
|
6774 | { |
|
|
6775 | int tag_start_pointer; |
|
|
6776 | long long wid = item_bin_get_wayid(ib); |
|
|
6777 | |
|
|
6778 | //fprintf(stderr,"looking for wid=%lu\n", wid); |
|
|
6779 | |
|
|
6780 | long long p_tmp = 0; |
|
|
6781 | int ret = 0; |
|
|
6782 | ret = g_hash_table_lookup_extended(waytag_hash, (gpointer) (long long) wid, NULL, (gpointer) & p_tmp); |
|
|
6783 | //fprintf(stderr,"ret=%d\n", ret); |
|
|
6784 | if (ret == 1) |
|
|
6785 | { |
|
|
6786 | // only if wayid is found in hash! |
|
|
6787 | tag_start_pointer = (int) (long long) (p_tmp); |
|
|
6788 | wt3 = wt2 + tag_start_pointer; |
|
|
6789 | |
|
|
6790 | if ((long long) wt3->way_id == (long long) wid) |
|
|
6791 | { |
|
|
6792 | if (wt3->tag_id == 1) |
|
|
6793 | { |
|
|
6794 | // add "type" to "way" |
|
|
6795 | // ## char tag[strlen("waterway") + strlen("riverbank") + 2]; |
|
|
6796 | // ## sprintf(tag, "%s=%s", "waterway", "riverbank"); |
|
|
6797 | // ## item_bin_add_attr_string(ib, attr_osm_tag, tag); |
|
|
6798 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6799 | { |
|
|
6800 | item_bin_set_type(ib, type_poly_water_from_relations); |
|
|
6801 | } |
|
|
6802 | else |
|
|
6803 | { |
|
|
6804 | item_bin_set_type(ib, type_water_river); |
|
|
6805 | } |
|
|
6806 | } |
|
|
6807 | else if (wt3->tag_id == 2) |
|
|
6808 | { |
|
|
6809 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6810 | { |
|
|
6811 | item_bin_set_type(ib, type_poly_water_from_relations); |
|
|
6812 | } |
|
|
6813 | else |
|
|
6814 | { |
|
|
6815 | item_bin_set_type(ib, type_water_river); |
|
|
6816 | } |
|
|
6817 | } |
|
|
6818 | else if (wt3->tag_id == 4) |
|
|
6819 | { |
|
|
6820 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6821 | { |
|
|
6822 | item_bin_set_type(ib, type_poly_water_from_relations); |
|
|
6823 | } |
|
|
6824 | else |
|
|
6825 | { |
|
|
6826 | item_bin_set_type(ib, type_water_river); |
|
|
6827 | } |
|
|
6828 | } |
|
|
6829 | else if (wt3->tag_id == 5) |
|
|
6830 | { |
|
|
6831 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6832 | { |
|
|
6833 | item_bin_set_type(ib, type_poly_wood_from_triang); |
|
|
6834 | } |
|
|
6835 | else |
|
|
6836 | { |
|
|
6837 | //fprintf(stderr, "wood_from_relations(5)\n"); |
|
|
6838 | item_bin_set_type(ib, type_wood_from_relations); |
|
|
6839 | } |
|
|
6840 | } |
|
|
6841 | else if (wt3->tag_id == 6) |
|
|
6842 | { |
|
|
6843 | if (item_bin_is_closed_poly(ib) == 1) |
|
|
6844 | { |
|
|
6845 | item_bin_set_type(ib, type_poly_wood_from_triang); |
|
|
6846 | } |
|
|
6847 | else |
|
|
6848 | { |
|
|
6849 | //fprintf(stderr, "wood_from_relations(6)\n"); |
|
|
6850 | item_bin_set_type(ib, type_wood_from_relations); |
|
|
6851 | } |
|
|
6852 | } |
|
|
6853 | else if (wt3->tag_id == 7) |
|
|
6854 | { |
|
|
6855 | // "inner" way |
|
|
6856 | //fprintf(stderr, "wood_from_relations(7)\n"); |
|
|
6857 | item_bin_set_type(ib, type_wood_from_relations); |
|
|
6858 | } |
|
|
6859 | else if (wt3->tag_id == 8) |
|
|
6860 | { |
|
|
6861 | // "inner" way |
|
|
6862 | //fprintf(stderr, "wood_from_relations(8)\n"); |
|
|
6863 | item_bin_set_type(ib, type_wood_from_relations); |
|
|
6864 | } |
|
|
6865 | } |
|
|
6866 | } |
|
|
6867 | } |
|
|
6868 | // write way to outfile |
|
|
6869 | item_bin_write(ib, out); |
|
|
6870 | } |
|
|
6871 | |
|
|
6872 | } |
|
|
6873 | } |
|
|
6874 | |
|
|
6875 | /* filecopy: copy file ifp to file ofp */ |
|
|
6876 | void filecopy(FILE *ifp, FILE *ofp) |
|
|
6877 | { |
|
|
6878 | int c; |
|
|
6879 | while ((c = getc(ifp)) != EOF) |
|
|
6880 | { |
|
|
6881 | putc(c, ofp); |
|
|
6882 | } |
|
|
6883 | } |
|
|
6884 | |
|
|
6885 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
6886 | typedef unsigned char uint8; |
|
|
6887 | typedef unsigned short uint16; |
|
|
6888 | typedef unsigned int uint; |
|
|
6889 | |
|
|
6890 | #define MZ_MIN(a,b) (((a)<(b))?(a):(b)) |
|
|
6891 | #define my_min(a,b) (((a) < (b)) ? (a) : (b)) |
|
|
6892 | |
|
|
6893 | |
|
|
6894 | |
|
|
6895 | |
|
|
6896 | // ------------------------------- |
|
|
6897 | // ------------------------------- |
|
|
6898 | |
|
|
6899 | int IN_BUF_SIZE; |
|
|
6900 | static uint8* s_inbuf; |
|
|
6901 | int OUT_BUF_SIZE; |
|
|
6902 | static uint8* s_outbuf; |
|
|
6903 | int COMP_OUT_BUF_SIZE; |
|
|
6904 | |
|
|
6905 | int s_IN_BUF_SIZE = sizeof(struct streets_index_data_block) * 1024; |
|
|
6906 | int t_IN_BUF_SIZE = sizeof(struct town_index_data_block) * 1024; |
|
|
6907 | static uint8 s_s_inbuf[(sizeof(struct streets_index_data_block) * 1024)]; |
|
|
6908 | static uint8 t_s_inbuf[(sizeof(struct town_index_data_block) * 1024)]; |
|
|
6909 | |
|
|
6910 | int s_OUT_BUF_SIZE = sizeof(struct streets_index_data_block) * 1024; |
|
|
6911 | int t_OUT_BUF_SIZE = sizeof(struct town_index_data_block) * 1024; |
|
|
6912 | static uint8 s_s_outbuf[(sizeof(struct streets_index_data_block) * 1024)]; |
|
|
6913 | static uint8 t_s_outbuf[(sizeof(struct town_index_data_block) * 1024)]; |
|
|
6914 | |
|
|
6915 | int s_COMP_OUT_BUF_SIZE; |
|
|
6916 | int t_COMP_OUT_BUF_SIZE; |
|
|
6917 | |
|
|
6918 | // IN_BUF_SIZE is the size of the file read buffer. |
|
|
6919 | // IN_BUF_SIZE must be >= 1 |
|
|
6920 | //**#define IN_BUF_SIZE (1024*512) |
|
|
6921 | //**static uint8 s_inbuf[IN_BUF_SIZE]; |
|
|
6922 | |
|
|
6923 | // COMP_OUT_BUF_SIZE is the size of the output buffer used during compression. |
|
|
6924 | // COMP_OUT_BUF_SIZE must be >= 1 and <= OUT_BUF_SIZE |
|
|
6925 | //**#define COMP_OUT_BUF_SIZE (1024*512) |
|
|
6926 | |
|
|
6927 | // OUT_BUF_SIZE is the size of the output buffer used during decompression. |
|
|
6928 | // OUT_BUF_SIZE must be a power of 2 >= TINFL_LZ_DICT_SIZE (because the low-level decompressor not only writes, but reads from the output buffer as it decompresses) |
|
|
6929 | //#define OUT_BUF_SIZE (TINFL_LZ_DICT_SIZE) |
|
|
6930 | //*#define OUT_BUF_SIZE (1024*512) |
|
|
6931 | //*static uint8 s_outbuf[OUT_BUF_SIZE]; |
|
|
6932 | |
|
|
6933 | // ------------------------------- |
|
|
6934 | // ------------------------------- |
|
|
6935 | |
|
|
6936 | |
|
|
6937 | // compression level |
|
|
6938 | int street_index_compress_level = 9; // = MZ_BEST_COMPRESSION |
|
|
6939 | |
|
|
6940 | long long compress_file(char *in, char *out, int keep_tempfile) |
|
|
6941 | { |
|
|
6942 | long long out_size = 0; |
|
|
6943 | // compress structure |
|
|
6944 | tdefl_compressor *g_deflator; |
|
|
6945 | g_deflator = g_new0(tdefl_compressor, 1); |
|
|
6946 | // compress structure |
|
|
6947 | |
|
|
6948 | // ok now compress the block (file) ------------------------------- |
|
|
6949 | const void *next_in = s_inbuf; |
|
|
6950 | size_t avail_in = 0; |
|
|
6951 | void *next_out = s_outbuf; |
|
|
6952 | size_t avail_out = OUT_BUF_SIZE; |
|
|
6953 | size_t total_in = 0, total_out = 0; |
|
|
6954 | |
|
|
6955 | FILE *in_uncompr = tempfile("", in, 0); |
|
|
6956 | FILE *out_compr = NULL; |
|
|
6957 | out_compr = tempfile("", out, 1); |
|
|
6958 | |
|
|
6959 | // Determine input file's size. |
|
|
6960 | fseek(in_uncompr, 0, SEEK_END); |
|
|
6961 | long file_loc = ftell(in_uncompr); |
|
|
6962 | fseek(in_uncompr, 0, SEEK_SET); |
|
|
6963 | uint infile_size = (uint)file_loc; |
|
|
6964 | |
|
|
6965 | // The number of dictionary probes to use at each compression level (0-10). 0=implies fastest/minimal possible probing. |
|
|
6966 | static const mz_uint s_tdefl_num_probes[11] = |
|
|
6967 | { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500}; |
|
|
6968 | |
|
|
6969 | tdefl_status status; |
|
|
6970 | uint infile_remaining = infile_size; |
|
|
6971 | |
|
|
6972 | // create tdefl() compatible flags (we have to compose the low-level flags ourselves, or use tdefl_create_comp_flags_from_zip_params() but that means MINIZ_NO_ZLIB_APIS can't be defined). |
|
|
6973 | mz_uint comp_flags = TDEFL_WRITE_ZLIB_HEADER | s_tdefl_num_probes[MZ_MIN(10, street_index_compress_level)] | ((street_index_compress_level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0); |
|
|
6974 | if (!street_index_compress_level) |
|
|
6975 | { |
|
|
6976 | comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS; |
|
|
6977 | } |
|
|
6978 | |
|
|
6979 | // Initialize the low-level compressor. |
|
|
6980 | status = tdefl_init(g_deflator, NULL, NULL, comp_flags); |
|
|
6981 | if (status != TDEFL_STATUS_OKAY) |
|
|
6982 | { |
|
|
6983 | fprintf(stderr, "tdefl_init() failed!\n"); |
|
|
6984 | g_free(g_deflator); |
|
|
6985 | return 0; |
|
|
6986 | } |
|
|
6987 | avail_out = COMP_OUT_BUF_SIZE; |
|
|
6988 | |
|
|
6989 | // Compression. |
|
|
6990 | for (;; ) |
|
|
6991 | { |
|
|
6992 | size_t in_bytes, out_bytes; |
|
|
6993 | |
|
|
6994 | if (!avail_in) |
|
|
6995 | { |
|
|
6996 | // Input buffer is empty, so read more bytes from input file. |
|
|
6997 | uint n = my_min(IN_BUF_SIZE, infile_remaining); |
|
|
6998 | |
|
|
6999 | if (fread(s_inbuf, 1, n, in_uncompr) != n) |
|
|
7000 | { |
|
|
7001 | fprintf(stderr, "Failed reading from input file!\n"); |
|
|
7002 | g_free(g_deflator); |
|
|
7003 | return 0; |
|
|
7004 | } |
|
|
7005 | |
|
|
7006 | next_in = s_inbuf; |
|
|
7007 | avail_in = n; |
|
|
7008 | |
|
|
7009 | infile_remaining -= n; |
|
|
7010 | //printf("Input bytes remaining: %u\n", infile_remaining); |
|
|
7011 | } |
|
|
7012 | |
|
|
7013 | in_bytes = avail_in; |
|
|
7014 | out_bytes = avail_out; |
|
|
7015 | // Compress as much of the input as possible (or all of it) to the output buffer. |
|
|
7016 | status = tdefl_compress(g_deflator, next_in, &in_bytes, next_out, &out_bytes, infile_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH); |
|
|
7017 | |
|
|
7018 | next_in = (const char *)next_in + in_bytes; |
|
|
7019 | avail_in -= in_bytes; |
|
|
7020 | total_in += in_bytes; |
|
|
7021 | |
|
|
7022 | next_out = (char *)next_out + out_bytes; |
|
|
7023 | avail_out -= out_bytes; |
|
|
7024 | total_out += out_bytes; |
|
|
7025 | |
|
|
7026 | if ((status != TDEFL_STATUS_OKAY) || (!avail_out)) |
|
|
7027 | { |
|
|
7028 | // Output buffer is full, or compression is done or failed, so write buffer to output file. |
|
|
7029 | uint n = COMP_OUT_BUF_SIZE - (uint)avail_out; |
|
|
7030 | if (fwrite(s_outbuf, 1, n, out_compr) != n) |
|
|
7031 | { |
|
|
7032 | fprintf(stderr, "Failed writing to output file!\n"); |
|
|
7033 | g_free(g_deflator); |
|
|
7034 | return 0; |
|
|
7035 | } |
|
|
7036 | next_out = s_outbuf; |
|
|
7037 | avail_out = COMP_OUT_BUF_SIZE; |
|
|
7038 | } |
|
|
7039 | |
|
|
7040 | if (status == TDEFL_STATUS_DONE) |
|
|
7041 | { |
|
|
7042 | // Compression completed successfully. |
|
|
7043 | break; |
|
|
7044 | } |
|
|
7045 | else if (status != TDEFL_STATUS_OKAY) |
|
|
7046 | { |
|
|
7047 | // Compression somehow failed. |
|
|
7048 | fprintf(stderr, "tdefl_compress() failed with status %i!\n", status); |
|
|
7049 | g_free(g_deflator); |
|
|
7050 | return 0; |
|
|
7051 | } |
|
|
7052 | } |
|
|
7053 | |
|
|
7054 | fprintf(stderr, "Total input bytes: %u\n", (mz_uint32)total_in); |
|
|
7055 | fprintf(stderr, "Total output bytes: %u\n", (mz_uint32)total_out); |
|
|
7056 | |
|
|
7057 | out_size = (long long)total_out; |
|
|
7058 | |
|
|
7059 | fclose(in_uncompr); |
|
|
7060 | fclose(out_compr); |
|
|
7061 | |
|
|
7062 | if (keep_tempfile == 1) |
|
|
7063 | { |
|
|
7064 | char *in2; |
|
|
7065 | in2 = g_strdup_printf("%s.tmptmp", in); |
|
|
7066 | tempfile_rename("", in, in2); |
|
|
7067 | g_free(in2); |
|
|
7068 | tempfile_rename("", out, in); |
|
|
7069 | } |
|
|
7070 | else |
|
|
7071 | { |
|
|
7072 | tempfile_unlink("", in); |
|
|
7073 | tempfile_rename("", out, in); |
|
|
7074 | } |
|
|
7075 | |
|
|
7076 | g_free(g_deflator); |
|
|
7077 | |
|
|
7078 | return out_size; |
|
|
7079 | } |
|
|
7080 | #endif |
|
|
7081 | |
|
|
7082 | void generate_combined_index_file(FILE *towni, FILE *streeti, FILE *out) |
|
|
7083 | { |
|
|
7084 | #ifdef MAPTOOL_USE_SQL |
|
|
7085 | fseek(towni, 0, SEEK_END); |
|
|
7086 | fseek(streeti, 0, SEEK_END); |
|
|
7087 | long long towni_size = (long long)ftello(towni); |
|
|
7088 | long long streeti_size = (long long)ftello(streeti); |
|
|
7089 | fprintf(stderr, "ftell towns=%lld\n", towni_size); |
|
|
7090 | fprintf(stderr, "ftell streets=%lld\n", streeti_size); |
|
|
7091 | |
|
|
7092 | fseek(towni, 0, SEEK_SET); |
|
|
7093 | fseek(streeti, 0, SEEK_SET); |
|
|
7094 | |
|
|
7095 | // size |
|
|
7096 | fwrite(&streeti_size, sizeof(long long), 1, out); |
|
|
7097 | // append street index file |
|
|
7098 | filecopy(streeti, out); |
|
|
7099 | // append town index file |
|
|
7100 | filecopy(towni, out); |
|
|
7101 | |
|
|
7102 | #endif |
|
|
7103 | } |
|
|
7104 | |
|
|
7105 | char* get_town_name_recursive(long long border_id, int level) |
|
|
7106 | { |
|
|
7107 | char *ret = NULL; |
|
|
7108 | char *ret2 = NULL; |
|
|
7109 | char *str2 = NULL; |
|
|
7110 | int rc = 0; |
|
|
7111 | long long parent_rel_id = 0; |
|
|
7112 | |
|
|
7113 | //fprintf(stderr, "get town name:bid:%lld level:%d\n", border_id, level); |
|
|
7114 | |
|
|
7115 | // select this boundary |
|
|
7116 | sqlite3_bind_int64(stmt_bd_005, 1, border_id); |
|
|
7117 | rc = sqlite3_step(stmt_bd_005); |
|
|
7118 | switch (rc) |
|
|
7119 | { |
|
|
7120 | case SQLITE_DONE: |
|
|
7121 | break; |
|
|
7122 | case SQLITE_ROW: |
|
|
7123 | // rel_id, parent_rel_id, name |
|
|
7124 | parent_rel_id = sqlite3_column_int(stmt_bd_005, 1); |
|
|
7125 | ret = g_strdup_printf("%s", sqlite3_column_text(stmt_bd_005, 2)); |
|
|
7126 | sqlite3_reset(stmt_bd_005); |
|
|
7127 | |
|
|
7128 | //fprintf(stderr, "get town name:ret=%s\n", ret); |
|
|
7129 | |
|
|
7130 | if (level < 12) |
|
|
7131 | { |
|
|
7132 | str2 = get_town_name_recursive(parent_rel_id, (level + 1)); |
|
|
7133 | if (str2) |
|
|
7134 | { |
|
|
7135 | ret2 = g_strdup_printf("%s, %s", ret, str2); |
|
|
7136 | g_free(ret); |
|
|
7137 | g_free(str2); |
|
|
7138 | ret = ret2; |
|
|
7139 | } |
|
|
7140 | } |
|
|
7141 | break; |
|
|
7142 | default: |
|
|
7143 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7144 | break; |
|
|
7145 | } |
|
|
7146 | |
|
|
7147 | if (level == 0) |
|
|
7148 | { |
|
|
7149 | sqlite3_reset(stmt_bd_005); |
|
|
7150 | } |
|
|
7151 | |
|
|
7152 | return ret; |
|
|
7153 | } |
|
|
7154 | |
|
|
7155 | void generate_town_index_file(FILE *out) |
|
|
7156 | { |
|
|
7157 | #ifdef MAPTOOL_USE_SQL |
|
|
7158 | |
|
|
7159 | struct town_index_data_block db; |
|
|
7160 | struct town_index_index_block_start is; |
|
|
7161 | struct town_index_index_block ib; |
|
|
7162 | char *townname = NULL; |
|
|
7163 | char *townname2 = NULL; |
|
|
7164 | long long last_len = 0; |
|
|
7165 | long long border_id = 0; |
|
|
7166 | int town_count = 0; |
|
|
7167 | int index_blocks; |
|
|
7168 | int index_block_towns; |
|
|
7169 | int i; |
|
|
7170 | int first; |
|
|
7171 | int rc = 0; |
|
|
7172 | int current_index_block; |
|
|
7173 | int current_index_block_old; |
|
|
7174 | char tmp_letter[TOWN_INDEX_TOWN_NAME_SIZE]; |
|
|
7175 | char *newfilename = NULL; |
|
|
7176 | char *newfilename_compr = NULL; |
|
|
7177 | |
|
|
7178 | int chunkSize; |
|
|
7179 | int stringLength; |
|
|
7180 | int ii22; |
|
|
7181 | |
|
|
7182 | FILE *town_index_index = NULL; |
|
|
7183 | FILE *town_index_index_data_block = NULL; |
|
|
7184 | |
|
|
7185 | |
|
|
7186 | // init compression for towns |
|
|
7187 | // init compression for towns |
|
|
7188 | IN_BUF_SIZE = t_IN_BUF_SIZE; |
|
|
7189 | s_inbuf = t_s_inbuf; |
|
|
7190 | OUT_BUF_SIZE = t_OUT_BUF_SIZE; |
|
|
7191 | s_outbuf = t_s_outbuf; |
|
|
7192 | COMP_OUT_BUF_SIZE = t_OUT_BUF_SIZE; |
|
|
7193 | // init compression for towns |
|
|
7194 | // init compression for towns |
|
|
7195 | |
|
|
7196 | |
|
|
7197 | sqlite3_step(stmt_town_sel006); |
|
|
7198 | town_count = sqlite3_column_int(stmt_town_sel006, 0); |
|
|
7199 | sqlite3_reset(stmt_town_sel006); |
|
|
7200 | |
|
|
7201 | // calculate number of index blocks |
|
|
7202 | index_blocks = 2; |
|
|
7203 | if (town_count > 1000000) |
|
|
7204 | { |
|
|
7205 | index_blocks = 100; |
|
|
7206 | } |
|
|
7207 | else if (town_count > 100000) |
|
|
7208 | { |
|
|
7209 | index_blocks = 50; |
|
|
7210 | } |
|
|
7211 | else if (town_count > 10000) |
|
|
7212 | { |
|
|
7213 | index_blocks = 10; |
|
|
7214 | } |
|
|
7215 | else if (town_count > 2000) |
|
|
7216 | { |
|
|
7217 | index_blocks = 5; |
|
|
7218 | } |
|
|
7219 | |
|
|
7220 | is.count_of_index_blocks = index_blocks; |
|
|
7221 | ib.offset = sizeof (is.count_of_index_blocks) + is.count_of_index_blocks * sizeof(struct town_index_index_block); // start offset = index size |
|
|
7222 | town_index_index = tempfile("", "town_index_index", 1); |
|
|
7223 | |
|
|
7224 | index_block_towns = (town_count / index_blocks); |
|
|
7225 | if ((index_block_towns * index_blocks) < town_count) |
|
|
7226 | { |
|
|
7227 | index_block_towns++; |
|
|
7228 | } |
|
|
7229 | |
|
|
7230 | fprintf(stderr, "towns per block=%d\n", index_block_towns); |
|
|
7231 | |
|
|
7232 | fprintf(stderr, "index size=%d\n", ib.offset); |
|
|
7233 | |
|
|
7234 | fprintf(stderr, "ftell=%d\n", ftell(town_index_index)); |
|
|
7235 | fwrite(&is, sizeof(struct town_index_index_block_start), 1, town_index_index); |
|
|
7236 | fprintf(stderr, "ftell=%d\n", ftell(town_index_index)); |
|
|
7237 | |
|
|
7238 | current_index_block = 1; |
|
|
7239 | current_index_block_old = 0; |
|
|
7240 | ib.len = 0; |
|
|
7241 | i = -1; |
|
|
7242 | first = 1; |
|
|
7243 | |
|
|
7244 | // loop thru all the towns |
|
|
7245 | do |
|
|
7246 | { |
|
|
7247 | rc = sqlite3_step(stmt_town_sel005); |
|
|
7248 | switch (rc) |
|
|
7249 | { |
|
|
7250 | case SQLITE_DONE: |
|
|
7251 | break; |
|
|
7252 | case SQLITE_ROW: |
|
|
7253 | i++; |
|
|
7254 | townname2 = NULL; |
|
|
7255 | db.town_id = sqlite3_column_int64(stmt_town_sel005, 0); |
|
|
7256 | db.country_id = sqlite3_column_int(stmt_town_sel005, 1); |
|
|
7257 | border_id = sqlite3_column_int64(stmt_town_sel005, 3); |
|
|
7258 | |
|
|
7259 | townname = get_town_name_recursive(border_id, 0); |
|
|
7260 | |
|
|
7261 | if (townname == NULL) |
|
|
7262 | { |
|
|
7263 | townname2 = g_strdup_printf("%s", sqlite3_column_text(stmt_town_sel005, 2)); |
|
|
7264 | } |
|
|
7265 | else |
|
|
7266 | { |
|
|
7267 | townname2 = townname; |
|
|
7268 | // townname2 = g_strdup_printf("%s", townname); // dont use the column result here, or string will be double! |
|
|
7269 | // g_free(townname); |
|
|
7270 | } |
|
|
7271 | //fprintf(stderr, "indextown:%s\n", townname2); |
|
|
7272 | |
|
|
7273 | //fprintf(stderr, "i=%d\n", i); |
|
|
7274 | //fprintf(stderr, "block=%d\n", current_index_block); |
|
|
7275 | if ((i + 1) > index_block_towns) |
|
|
7276 | { |
|
|
7277 | // start new index data block |
|
|
7278 | i = 0; |
|
|
7279 | current_index_block++; |
|
|
7280 | //fprintf(stderr, "incr block=%d\n", current_index_block); |
|
|
7281 | } |
|
|
7282 | |
|
|
7283 | if (current_index_block != current_index_block_old) |
|
|
7284 | { |
|
|
7285 | |
|
|
7286 | if (first != 1) |
|
|
7287 | { |
|
|
7288 | // close old datafile |
|
|
7289 | fclose(town_index_index_data_block); |
|
|
7290 | town_index_index_data_block = NULL; |
|
|
7291 | |
|
|
7292 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7293 | { |
|
|
7294 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7295 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7296 | #endif |
|
|
7297 | } |
|
|
7298 | |
|
|
7299 | // append to indexfile |
|
|
7300 | fprintf(stderr, "first_id=%lld offset=%lld len=%lld\n", ib.first_id, ib.offset, ib.len); |
|
|
7301 | fwrite(&ib, sizeof(struct town_index_index_block), 1, town_index_index); |
|
|
7302 | |
|
|
7303 | if (newfilename) |
|
|
7304 | { |
|
|
7305 | g_free(newfilename); |
|
|
7306 | newfilename = NULL; |
|
|
7307 | } |
|
|
7308 | |
|
|
7309 | if (newfilename_compr) |
|
|
7310 | { |
|
|
7311 | g_free(newfilename_compr); |
|
|
7312 | newfilename_compr = NULL; |
|
|
7313 | } |
|
|
7314 | } |
|
|
7315 | |
|
|
7316 | current_index_block_old = current_index_block; |
|
|
7317 | ib.first_id = db.town_id; |
|
|
7318 | ib.offset = ib.offset + ib.len; |
|
|
7319 | |
|
|
7320 | // open new datafile |
|
|
7321 | newfilename = g_strdup_printf("town_index_index_%d", current_index_block); |
|
|
7322 | fprintf(stderr, "new data file: %s first_id=%lld\n", newfilename, ib.first_id); |
|
|
7323 | newfilename_compr = g_strdup_printf("town_index_index_compr_%d", current_index_block); |
|
|
7324 | town_index_index_data_block = tempfile("", newfilename, 1); |
|
|
7325 | fprintf(stderr, "town index file %d\n", current_index_block); |
|
|
7326 | |
|
|
7327 | ib.len = 0; |
|
|
7328 | } |
|
|
7329 | |
|
|
7330 | |
|
|
7331 | // now check if we need to split the string into parts |
|
|
7332 | if ((strlen(townname2) + 1) > TOWN_INDEX_TOWN_NAME_SIZE) |
|
|
7333 | { |
|
|
7334 | //fprintf(stderr, " block-split: START\n"); |
|
|
7335 | chunkSize = TOWN_INDEX_TOWN_NAME_SIZE - 1; |
|
|
7336 | stringLength = strlen(townname2); |
|
|
7337 | for (ii22 = 0; ii22 < stringLength ; ii22 += chunkSize) |
|
|
7338 | { |
|
|
7339 | if (ii22 + chunkSize > stringLength) |
|
|
7340 | { |
|
|
7341 | chunkSize = stringLength - ii22; |
|
|
7342 | db.town_name[chunkSize] = '\0'; // make sure string is terminated |
|
|
7343 | } |
|
|
7344 | strncpy(&db.town_name, (townname2 + ii22), chunkSize); |
|
|
7345 | db.town_name[TOWN_INDEX_TOWN_NAME_SIZE - 1] = '\0'; // make sure string is terminated |
|
|
7346 | if (ii22 > 0) |
|
|
7347 | { |
|
|
7348 | // set "split"-marker |
|
|
7349 | db.town_id = 0; |
|
|
7350 | db.country_id = 0; // setting this to zero is actually not needed |
|
|
7351 | } |
|
|
7352 | ib.len = ib.len + sizeof(struct town_index_data_block); |
|
|
7353 | //fprintf(stderr, "->block-split: town_id=%lld country_id=%d town_name=%s\n", db.town_id, db.country_id, db.town_name); |
|
|
7354 | fwrite(&db, sizeof(struct town_index_data_block), 1, town_index_index_data_block); |
|
|
7355 | } |
|
|
7356 | //fprintf(stderr, " block-split: END\n"); |
|
|
7357 | g_free(townname2); |
|
|
7358 | } |
|
|
7359 | else |
|
|
7360 | { |
|
|
7361 | strncpy(&db.town_name, townname2, TOWN_INDEX_TOWN_NAME_SIZE); |
|
|
7362 | g_free(townname2); |
|
|
7363 | db.town_name[TOWN_INDEX_TOWN_NAME_SIZE - 1]= '\0'; // make sure string is terminated |
|
|
7364 | |
|
|
7365 | ib.len = ib.len + sizeof(struct town_index_data_block); |
|
|
7366 | fwrite(&db, sizeof(struct town_index_data_block), 1, town_index_index_data_block); |
|
|
7367 | } |
|
|
7368 | |
|
|
7369 | if (first == 1) |
|
|
7370 | { |
|
|
7371 | first = 0; |
|
|
7372 | } |
|
|
7373 | |
|
|
7374 | break; |
|
|
7375 | default: |
|
|
7376 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7377 | break; |
|
|
7378 | } |
|
|
7379 | } |
|
|
7380 | while (rc == SQLITE_ROW); |
|
|
7381 | |
|
|
7382 | sqlite3_reset(stmt_town_sel005); |
|
|
7383 | |
|
|
7384 | // rest of the towns |
|
|
7385 | if (i > 0) |
|
|
7386 | { |
|
|
7387 | if (town_index_index_data_block) |
|
|
7388 | { |
|
|
7389 | fclose(town_index_index_data_block); |
|
|
7390 | town_index_index_data_block = NULL; |
|
|
7391 | } |
|
|
7392 | |
|
|
7393 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7394 | { |
|
|
7395 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7396 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7397 | #endif |
|
|
7398 | } |
|
|
7399 | |
|
|
7400 | // append to indexfile |
|
|
7401 | fprintf(stderr, "(last)first_id=%lld offset=%lld len=%lld\n", ib.first_id, ib.offset, ib.len); |
|
|
7402 | fwrite(&ib, sizeof(struct town_index_index_block), 1, town_index_index); |
|
|
7403 | } |
|
|
7404 | |
|
|
7405 | if (town_index_index != NULL) |
|
|
7406 | { |
|
|
7407 | fclose(town_index_index); |
|
|
7408 | } |
|
|
7409 | |
|
|
7410 | if (town_index_index_data_block != NULL) |
|
|
7411 | { |
|
|
7412 | fclose(town_index_index_data_block); |
|
|
7413 | } |
|
|
7414 | |
|
|
7415 | if (newfilename) |
|
|
7416 | { |
|
|
7417 | g_free(newfilename); |
|
|
7418 | newfilename = NULL; |
|
|
7419 | } |
|
|
7420 | |
|
|
7421 | if (newfilename_compr) |
|
|
7422 | { |
|
|
7423 | g_free(newfilename_compr); |
|
|
7424 | newfilename_compr = NULL; |
|
|
7425 | } |
|
|
7426 | |
|
|
7427 | |
|
|
7428 | |
|
|
7429 | |
|
|
7430 | |
|
|
7431 | // put all parts together |
|
|
7432 | town_index_index = tempfile("", "town_index_index", 0); |
|
|
7433 | filecopy(town_index_index, out); |
|
|
7434 | fclose(town_index_index); |
|
|
7435 | tempfile_unlink("", "town_index_index"); |
|
|
7436 | |
|
|
7437 | for (i=1;i < (current_index_block + 2);i++) |
|
|
7438 | { |
|
|
7439 | fprintf(stderr, "index block #%d\n", i); |
|
|
7440 | newfilename = g_strdup_printf("town_index_index_%d", i); |
|
|
7441 | town_index_index_data_block = tempfile("", newfilename, 0); |
|
|
7442 | |
|
|
7443 | if (town_index_index_data_block) |
|
|
7444 | { |
|
|
7445 | fprintf(stderr, "using: index block #%d in %s\n", i, newfilename); |
|
|
7446 | filecopy(town_index_index_data_block, out); |
|
|
7447 | fclose(town_index_index_data_block); |
|
|
7448 | tempfile_unlink("", newfilename); |
|
|
7449 | } |
|
|
7450 | |
|
|
7451 | if (newfilename) |
|
|
7452 | { |
|
|
7453 | g_free(newfilename); |
|
|
7454 | newfilename = NULL; |
|
|
7455 | } |
|
|
7456 | } |
|
|
7457 | |
|
|
7458 | |
|
|
7459 | |
|
|
7460 | #endif |
|
|
7461 | } |
|
|
7462 | |
|
|
7463 | void generate_street_index_file(FILE *out) |
|
|
7464 | { |
|
|
7465 | #ifdef MAPTOOL_USE_SQL |
|
|
7466 | int rc = 0; |
|
|
7467 | int i; |
|
|
7468 | struct streets_index_data_block db; |
|
|
7469 | struct streets_index_index_block_start is; |
|
|
7470 | struct streets_index_index_block ib; |
|
|
7471 | long long last_len = 0; |
|
|
7472 | static const char *alpha = "abcdefghijklmnopqrstuvwxyz"; |
|
|
7473 | char tmp_letter[STREET_INDEX_STREET_NAME_SIZE]; |
|
|
7474 | char *newfilename = NULL; |
|
|
7475 | char *newfilename_compr = NULL; |
|
|
7476 | int count_of_blocks; |
|
|
7477 | int do_rest; |
|
|
7478 | int num1; |
|
|
7479 | int num2; |
|
|
7480 | |
|
|
7481 | FILE *street_index_index; |
|
|
7482 | FILE *street_index_index_data_block; |
|
|
7483 | |
|
|
7484 | // init compression for streets |
|
|
7485 | // init compression for streets |
|
|
7486 | IN_BUF_SIZE = s_IN_BUF_SIZE; |
|
|
7487 | s_inbuf = s_s_inbuf; |
|
|
7488 | OUT_BUF_SIZE = s_OUT_BUF_SIZE; |
|
|
7489 | s_outbuf = s_s_outbuf; |
|
|
7490 | COMP_OUT_BUF_SIZE = s_OUT_BUF_SIZE; |
|
|
7491 | // init compression for streets |
|
|
7492 | // init compression for streets |
|
|
7493 | |
|
|
7494 | |
|
|
7495 | is.count_of_index_blocks = 703; // 26+1 letters ((26+1)*26 + 1) = 703 |
|
|
7496 | ib.offset = sizeof (is.count_of_index_blocks) + is.count_of_index_blocks * sizeof(struct streets_index_index_block); // start offset = index size |
|
|
7497 | street_index_index = tempfile("", "street_index_index", 1); |
|
|
7498 | fprintf(stderr, "index size=%d\n", ib.offset); |
|
|
7499 | |
|
|
7500 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7501 | fwrite(&is, sizeof(struct streets_index_index_block_start), 1, street_index_index); |
|
|
7502 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7503 | |
|
|
7504 | // fprintf(stderr, "len=%d\n", strlen(alpha)); |
|
|
7505 | |
|
|
7506 | count_of_blocks = 702; |
|
|
7507 | do_rest = 0; |
|
|
7508 | num1 = 1; |
|
|
7509 | num2 = 0; |
|
|
7510 | for (i=0; i < count_of_blocks; i++) |
|
|
7511 | { |
|
|
7512 | num2++; |
|
|
7513 | do_rest = 0; |
|
|
7514 | if (num2 == 27) |
|
|
7515 | { |
|
|
7516 | do_rest = 1; |
|
|
7517 | } |
|
|
7518 | else if (num2 > 27) |
|
|
7519 | { |
|
|
7520 | num2 = 1; |
|
|
7521 | num1++; |
|
|
7522 | } |
|
|
7523 | |
|
|
7524 | fprintf(stderr, "i=%d num1=%d num2=%d\n", i, num1, num2); |
|
|
7525 | |
|
|
7526 | if (do_rest) |
|
|
7527 | { |
|
|
7528 | sprintf(tmp_letter, "%c", alpha[num1 - 1]); |
|
|
7529 | } |
|
|
7530 | else |
|
|
7531 | { |
|
|
7532 | sprintf(tmp_letter, "%c%c", alpha[num1 - 1], alpha[num2 - 1]); |
|
|
7533 | } |
|
|
7534 | fprintf(stderr, "letter=%s\n", tmp_letter); |
|
|
7535 | |
|
|
7536 | ib.first_letter = alpha[num1 - 1]; |
|
|
7537 | ib.len = 0; |
|
|
7538 | |
|
|
7539 | newfilename = g_strdup_printf("street_index_index_%d", i); |
|
|
7540 | newfilename_compr = g_strdup_printf("street_index_index_compr_%d", i); |
|
|
7541 | street_index_index_data_block = tempfile("", newfilename, 1); |
|
|
7542 | |
|
|
7543 | |
|
|
7544 | // ------ TIMER ------- |
|
|
7545 | time_t start_tt_4, end_tt_4; |
|
|
7546 | double diff_tt_4; |
|
|
7547 | char outstring_4[200]; |
|
|
7548 | // ------ TIMER ------- |
|
|
7549 | |
|
|
7550 | // ------ TIMER ------- |
|
|
7551 | time(&start_tt_4); |
|
|
7552 | // ------ TIMER ------- |
|
|
7553 | |
|
|
7554 | // loop thru all the streets that match '<letter>...' |
|
|
7555 | sqlite3_bind_text(stmt_sel003, 1, tmp_letter, -1, SQLITE_STATIC); |
|
|
7556 | do |
|
|
7557 | { |
|
|
7558 | rc = sqlite3_step(stmt_sel003); |
|
|
7559 | switch (rc) |
|
|
7560 | { |
|
|
7561 | case SQLITE_DONE: |
|
|
7562 | break; |
|
|
7563 | case SQLITE_ROW: |
|
|
7564 | db.town_id = sqlite3_column_int64(stmt_sel003, 0); |
|
|
7565 | db.lat = transform_from_geo_lat(sqlite3_column_double(stmt_sel003, 1)); |
|
|
7566 | db.lon = transform_from_geo_lon(sqlite3_column_double(stmt_sel003, 2)); |
|
|
7567 | strncpy(&db.street_name, sqlite3_column_text(stmt_sel003, 3), STREET_INDEX_STREET_NAME_SIZE); |
|
|
7568 | db.street_name[STREET_INDEX_STREET_NAME_SIZE - 1]= '\0'; // make sure string is terminated |
|
|
7569 | |
|
|
7570 | ib.len = ib.len + sizeof(struct streets_index_data_block); |
|
|
7571 | |
|
|
7572 | // fprintf(stderr ,"gen_street_index id:%lld lat:%d lon:%d name:%s\n", db.town_id, db.lat, db.lon, db.street_name); |
|
|
7573 | fwrite(&db, sizeof(struct streets_index_data_block), 1, street_index_index_data_block); |
|
|
7574 | |
|
|
7575 | break; |
|
|
7576 | default: |
|
|
7577 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7578 | break; |
|
|
7579 | } |
|
|
7580 | } |
|
|
7581 | while (rc == SQLITE_ROW); |
|
|
7582 | |
|
|
7583 | sqlite3_reset(stmt_sel003); |
|
|
7584 | fclose(street_index_index_data_block); |
|
|
7585 | |
|
|
7586 | // ------ TIMER ------- |
|
|
7587 | time(&end_tt_4); |
|
|
7588 | diff_tt_4 = difftime(end_tt_4, start_tt_4); |
|
|
7589 | convert_to_human_time(diff_tt_4, outstring_4); |
|
|
7590 | fprintf(stderr, "-TIME-IND-001: %s\n", outstring_4); |
|
|
7591 | // ------ TIMER ------- |
|
|
7592 | |
|
|
7593 | |
|
|
7594 | // ------ TIMER ------- |
|
|
7595 | time(&start_tt_4); |
|
|
7596 | // ------ TIMER ------- |
|
|
7597 | |
|
|
7598 | sqlite3_bind_int(stmt_sel003u, 1, (i + 1)); |
|
|
7599 | sqlite3_bind_text(stmt_sel003u, 2, tmp_letter, -1, SQLITE_STATIC); |
|
|
7600 | sqlite3_step(stmt_sel003u); |
|
|
7601 | sqlite3_reset(stmt_sel003u); |
|
|
7602 | // sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
|
|
7603 | |
|
|
7604 | |
|
|
7605 | // ------ TIMER ------- |
|
|
7606 | time(&end_tt_4); |
|
|
7607 | diff_tt_4 = difftime(end_tt_4, start_tt_4); |
|
|
7608 | convert_to_human_time(diff_tt_4, outstring_4); |
|
|
7609 | fprintf(stderr, "-TIME-IND-002: %s\n", outstring_4); |
|
|
7610 | // ------ TIMER ------- |
|
|
7611 | |
|
|
7612 | |
|
|
7613 | // ------ TIMER ------- |
|
|
7614 | time(&start_tt_4); |
|
|
7615 | // ------ TIMER ------- |
|
|
7616 | |
|
|
7617 | |
|
|
7618 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7619 | { |
|
|
7620 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7621 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7622 | #endif |
|
|
7623 | } |
|
|
7624 | |
|
|
7625 | // ------ TIMER ------- |
|
|
7626 | time(&end_tt_4); |
|
|
7627 | diff_tt_4 = difftime(end_tt_4, start_tt_4); |
|
|
7628 | convert_to_human_time(diff_tt_4, outstring_4); |
|
|
7629 | fprintf(stderr, "-TIME-IND-COMPR: %s\n", outstring_4); |
|
|
7630 | // ------ TIMER ------- |
|
|
7631 | |
|
|
7632 | |
|
|
7633 | last_len = ib.len; |
|
|
7634 | fprintf(stderr ,"letter=%c offset=%lld len=%lld\n", ib.first_letter, ib.offset, ib.len); |
|
|
7635 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7636 | fwrite(&ib, sizeof(struct streets_index_index_block), 1, street_index_index); |
|
|
7637 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7638 | ib.offset = ib.offset + last_len; |
|
|
7639 | |
|
|
7640 | if (newfilename) |
|
|
7641 | { |
|
|
7642 | g_free(newfilename); |
|
|
7643 | newfilename = NULL; |
|
|
7644 | } |
|
|
7645 | |
|
|
7646 | if (newfilename_compr) |
|
|
7647 | { |
|
|
7648 | g_free(newfilename_compr); |
|
|
7649 | newfilename_compr = NULL; |
|
|
7650 | } |
|
|
7651 | } |
|
|
7652 | |
|
|
7653 | // rest of the streets |
|
|
7654 | fprintf(stderr, "rest of letters\n"); |
|
|
7655 | |
|
|
7656 | ib.first_letter = 65; // dummy "A" |
|
|
7657 | ib.len = 0; |
|
|
7658 | |
|
|
7659 | newfilename = g_strdup_printf("street_index_index_%d", i); |
|
|
7660 | newfilename_compr = g_strdup_printf("street_index_index_compr_%d", i); |
|
|
7661 | street_index_index_data_block = tempfile("", newfilename, 1); |
|
|
7662 | |
|
|
7663 | do |
|
|
7664 | { |
|
|
7665 | rc = sqlite3_step(stmt_sel004); |
|
|
7666 | switch (rc) |
|
|
7667 | { |
|
|
7668 | case SQLITE_DONE: |
|
|
7669 | break; |
|
|
7670 | case SQLITE_ROW: |
|
|
7671 | db.town_id = sqlite3_column_int64(stmt_sel004, 0); |
|
|
7672 | db.lat = transform_from_geo_lat(sqlite3_column_double(stmt_sel004, 1)); |
|
|
7673 | db.lon = transform_from_geo_lon(sqlite3_column_double(stmt_sel004, 2)); |
|
|
7674 | strncpy(&db.street_name, sqlite3_column_text(stmt_sel004, 3), STREET_INDEX_STREET_NAME_SIZE); |
|
|
7675 | db.street_name[STREET_INDEX_STREET_NAME_SIZE - 1]= '\0'; // make sure string is terminated |
|
|
7676 | |
|
|
7677 | ib.len = ib.len + sizeof(struct streets_index_data_block); |
|
|
7678 | |
|
|
7679 | //fprintf(stderr ,"id:%lld lat:%d lon:%d name:%s\n", db.town_id, db.lat, db.lon, db.street_name); |
|
|
7680 | fwrite(&db, sizeof(struct streets_index_data_block), 1, street_index_index_data_block); |
|
|
7681 | |
|
|
7682 | break; |
|
|
7683 | default: |
|
|
7684 | fprintf(stderr, "SQL Error: %d\n", rc); |
|
|
7685 | break; |
|
|
7686 | } |
|
|
7687 | } |
|
|
7688 | while (rc == SQLITE_ROW); |
|
|
7689 | sqlite3_reset(stmt_sel004); |
|
|
7690 | fclose(street_index_index_data_block); |
|
|
7691 | |
|
|
7692 | if (USE_STREET_INDEX_COMPRESSION == 1) |
|
|
7693 | { |
|
|
7694 | #ifdef MAPTOOL_USE_STRINDEX_COMPRESSION |
|
|
7695 | ib.len = compress_file(newfilename, newfilename_compr, 0); |
|
|
7696 | #endif |
|
|
7697 | } |
|
|
7698 | |
|
|
7699 | last_len = ib.len; |
|
|
7700 | fprintf(stderr ,"letter=%c offset=%lld len=%lld\n", ib.first_letter, ib.offset, ib.len); |
|
|
7701 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7702 | fwrite(&ib, sizeof(struct streets_index_index_block), 1, street_index_index); |
|
|
7703 | fprintf(stderr, "ftell=%d\n", ftell(street_index_index)); |
|
|
7704 | // ib.offset = ib.offset + last_len; |
|
|
7705 | |
|
|
7706 | |
|
|
7707 | fclose(street_index_index); |
|
|
7708 | |
|
|
7709 | if (newfilename) |
|
|
7710 | { |
|
|
7711 | g_free(newfilename); |
|
|
7712 | newfilename = NULL; |
|
|
7713 | } |
|
|
7714 | |
|
|
7715 | if (newfilename_compr) |
|
|
7716 | { |
|
|
7717 | g_free(newfilename_compr); |
|
|
7718 | newfilename_compr = NULL; |
|
|
7719 | } |
|
|
7720 | |
|
|
7721 | // put all parts together |
|
|
7722 | street_index_index = tempfile("", "street_index_index", 0); |
|
|
7723 | filecopy(street_index_index, out); |
|
|
7724 | fclose(street_index_index); |
|
|
7725 | tempfile_unlink("", "street_index_index"); |
|
|
7726 | |
|
|
7727 | for (i=0;i < (is.count_of_index_blocks + 1);i++) |
|
|
7728 | { |
|
|
7729 | fprintf(stderr, "cat #%d\n", i); |
|
|
7730 | newfilename = g_strdup_printf("street_index_index_%d", i); |
|
|
7731 | street_index_index_data_block = tempfile("", newfilename, 0); |
|
|
7732 | |
|
|
7733 | if (street_index_index_data_block) |
|
|
7734 | { |
|
|
7735 | filecopy(street_index_index_data_block, out); |
|
|
7736 | fclose(street_index_index_data_block); |
|
|
7737 | tempfile_unlink("", newfilename); |
|
|
7738 | } |
|
|
7739 | |
|
|
7740 | if (newfilename) |
|
|
7741 | { |
|
|
7742 | g_free(newfilename); |
|
|
7743 | newfilename = NULL; |
|
|
7744 | } |
|
|
7745 | } |
|
|
7746 | #endif |
|
|
7747 | } |
|
|
7748 | |
|
|
7749 | void remove_attr_str(struct item_bin *ib, int attr_type) |
|
|
7750 | { |
|
|
7751 | char *attr_str = item_bin_get_attr(ib, attr_type, NULL); |
|
|
7752 | if (attr_str) |
|
|
7753 | { |
|
|
7754 | item_bin_remove_attr(ib, attr_str); |
|
|
7755 | } |
|
|
7756 | } |
|
|
7757 | |
|
|
7758 | int remove_useless_tags_from_ways(FILE *in, FILE *out) |
|
|
7759 | { |
|
|
7760 | struct item_bin *ib; |
|
|
7761 | long long *wayid; |
|
|
7762 | int *dup; |
|
|
7763 | |
|
|
7764 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
|
|
7765 | { |
|
|
7766 | // attr_street_name_dummy |
|
|
7767 | remove_attr_str(ib, attr_street_name_dummy); |
|
|
7768 | // attr_house_number_dummy |
|
|
7769 | remove_attr_str(ib, attr_house_number_dummy); |
|
|
7770 | // attr_debug |
|
|
7771 | remove_attr_str(ib, attr_debug); |
|
|
7772 | |
|
|
7773 | // osm wayid |
|
|
7774 | //wayid = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
|
|
7775 | //if (wayid) |
|
|
7776 | //{ |
|
|
7777 | // item_bin_remove_attr(ib, wayid); |
|
|
7778 | //} |
|
|
7779 | |
|
|
7780 | // duplicate_way |
|
|
7781 | dup = item_bin_get_attr(ib, attr_duplicate_way, NULL); |
|
|
7782 | if (dup) |
|
|
7783 | { |
|
|
7784 | item_bin_remove_attr(ib, dup); |
|
|
7785 | //fprintf(stderr, "attr_duplicate_way:2: dup=true wayid=%lld\n", item_bin_get_wayid(ib)); |
|
|
7786 | } |
|
|
7787 | |
|
|
7788 | // write way to outfile |
|
|
7789 | item_bin_write(ib, out); |
|
|
7790 | } |
|
|
7791 | } |
|
|
7792 | |
|
|
7793 | int remove_useless_tags_from_nodes(FILE *in, FILE *out) |
|
|
7794 | { |
|
|
7795 | struct item_bin *ib; |
|
|
7796 | long long *nodeid; |
|
|
7797 | |
|
|
7798 | while ((ib = read_item(in, 0))) // loop thru all "nodes" from file "in" |
|
|
7799 | { |
|
|
7800 | // attr_debug |
|
|
7801 | remove_attr_str(ib, attr_debug); |
|
|
7802 | |
|
|
7803 | // osm nodeid |
|
|
7804 | nodeid = item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
|
|
7805 | if (nodeid) |
|
|
7806 | { |
|
|
7807 | item_bin_remove_attr(ib, nodeid); |
|
|
7808 | } |
|
|
7809 | |
|
|
7810 | // write node to outfile |
|
|
7811 | item_bin_write(ib, out); |
|
|
7812 | } |
|
|
7813 | } |
|
|
7814 | |
|
|
7815 | void map_find_housenumbers_interpolation(FILE *in, FILE *out) |
|
|
7816 | { |
|
|
7817 | int ccount; |
|
|
7818 | struct item_bin *ib; |
|
|
7819 | long long ways_count = 0; |
|
|
7820 | struct coord c; |
|
|
7821 | |
|
|
7822 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
|
|
7823 | { |
|
|
7824 | ways_count++; |
|
|
7825 | if ((ways_count % 10000000) == 0) |
|
|
7826 | { |
|
|
7827 | fprintf(stderr, "ways: %lld\n", ways_count); |
|
|
7828 | } |
|
|
7829 | |
|
|
7830 | // we need at least 2 points in way |
|
|
7831 | if (ccount <= 1) |
|
|
7832 | { |
2446 | continue; |
7833 | continue; |
2447 | } |
7834 | } |
2448 | if (search_relation_member(ib, "from",&tmpm,&min_count)) { |
7835 | |
2449 | osm_warning("relation",relid,0,"turn restriction: multiple from members\n"); |
7836 | // only type "house_number_interpolate*" |
|
|
7837 | if ( |
|
|
7838 | (ib->type != type_house_number_interpolation_even) && |
|
|
7839 | (ib->type != type_house_number_interpolation_odd) && |
|
|
7840 | (ib->type != type_house_number_interpolation_all) && |
|
|
7841 | (ib->type != type_house_number_interpolation_alphabetic) |
|
|
7842 | ) |
|
|
7843 | { |
2450 | continue; |
7844 | continue; |
2451 | } |
7845 | } |
2452 | min_count=0; |
7846 | |
2453 | if (!search_relation_member(ib, "to",&tom,&min_count)) { |
7847 | ccount = ib->clen / 2; |
2454 | osm_warning("relation",relid,0,"turn restriction: to member missing\n"); |
7848 | |
2455 | continue; |
7849 | // set coord of housenumber here |
2456 | } |
7850 | c.x = 0; |
2457 | if (search_relation_member(ib, "to",&tmpm,&min_count)) { |
7851 | c.y = 0; |
2458 | osm_warning("relation",relid,0,"turn restriction: multiple to members\n"); |
7852 | // set coord of housenumber here |
2459 | continue; |
7853 | char *street_name = item_bin_get_attr(ib, attr_street_name_dummy, NULL); |
2460 | } |
7854 | char *house_number = item_bin_get_attr(ib, attr_house_number_dummy, NULL); |
2461 | min_count=0; |
7855 | if ((street_name != NULL) && (house_number != NULL)) |
2462 | if (!search_relation_member(ib, "via",&viam,&min_count)) { |
7856 | { |
2463 | osm_warning("relation",relid,0,"turn restriction: via member missing\n"); |
7857 | //fprintf(stderr, "ADDR:Interpolate:%s, %s\n", house_number, street_name); |
2464 | continue; |
7858 | osm_append_housenumber_node(out, &c, house_number, street_name); |
2465 | } |
|
|
2466 | if (search_relation_member(ib, "via",&tmpm,&min_count)) { |
|
|
2467 | osm_warning("relation",relid,0,"turn restriction: multiple via member\n"); |
|
|
2468 | continue; |
|
|
2469 | } |
|
|
2470 | if (fromm.type != 2) { |
|
|
2471 | osm_warning("relation",relid,0,"turn restriction: wrong type for from member "); |
|
|
2472 | osm_warning(osm_types[fromm.type],fromm.id,1,"\n"); |
|
|
2473 | continue; |
|
|
2474 | } |
|
|
2475 | if (tom.type != 2) { |
|
|
2476 | osm_warning("relation",relid,0,"turn restriction: wrong type for to member "); |
|
|
2477 | osm_warning(osm_types[tom.type],tom.id,1,"\n"); |
|
|
2478 | continue; |
|
|
2479 | } |
|
|
2480 | if (viam.type != 1 && viam.type != 2) { |
|
|
2481 | osm_warning("relation",relid,0,"turn restriction: wrong type for via member "); |
|
|
2482 | osm_warning(osm_types[viam.type],viam.id,1,"\n"); |
|
|
2483 | continue; |
|
|
2484 | } |
|
|
2485 | if (viam.type == 1) { |
|
|
2486 | if (!node_item_get_from_file(coords, viam.id, &ni)) { |
|
|
2487 | osm_warning("relation",relid,0,"turn restriction: failed to get via member "); |
|
|
2488 | osm_warning(osm_types[viam.type],viam.id,1,"\n"); |
|
|
2489 | continue; |
|
|
2490 | } |
7859 | } |
2491 | viafrom=&ni.c; |
|
|
2492 | viato=&ni.c; |
|
|
2493 | } else { |
|
|
2494 | if (!(viafrom=get_way(ways, ways_index, NULL, viam.id, via, 0))) { |
|
|
2495 | osm_warning("relation",relid,0,"turn restriction: failed to get first via coordinate from "); |
|
|
2496 | osm_warning(osm_types[viam.type],viam.id,1,"\n"); |
|
|
2497 | continue; |
|
|
2498 | } |
|
|
2499 | if (!(viato=get_way(ways, ways_index, viafrom, viam.id, via, 0))) { |
|
|
2500 | osm_warning("relation",relid,0,"turn restriction: failed to get last via coordinate from "); |
|
|
2501 | osm_warning(osm_types[viam.type],viam.id,1,"\n"); |
|
|
2502 | continue; |
|
|
2503 | } |
|
|
2504 | |
|
|
2505 | } |
7860 | } |
2506 | #if 0 |
|
|
2507 | fprintf(stderr,"via "LONGLONG_FMT" vs %d\n",viam.id, ni.id); |
|
|
2508 | fprintf(stderr,"coord 0x%x,0x%x\n",ni.c.x,ni.c.y); |
|
|
2509 | fprintf(stderr,"Lookup "LONGLONG_FMT"\n",fromm.id); |
|
|
2510 | #endif |
|
|
2511 | if (!(fromc=get_way(ways, ways_index, viafrom, fromm.id, from, 0))) { |
|
|
2512 | if (viam.type == 1 || !(fromc=get_way(ways, ways_index, viato, fromm.id, from, 0))) { |
|
|
2513 | //osm_warning("relation",relid,0,"turn restriction: failed to connect via "); |
|
|
2514 | //osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to from member ",viafrom->x,viafrom->y,viato->x,viato->y); |
|
|
2515 | //osm_warning(osm_types[fromm.type],fromm.id,1," ("); |
|
|
2516 | //get_way(ways, ways_index, viafrom, fromm.id, from, 1); |
|
|
2517 | //fprintf(stderr,")\n"); |
|
|
2518 | continue; |
|
|
2519 | } else { |
|
|
2520 | tmp=viato; |
|
|
2521 | viato=viafrom; |
|
|
2522 | viafrom=tmp; |
|
|
2523 | } |
|
|
2524 | } |
|
|
2525 | if (!(toc=get_way(ways, ways_index, viato, tom.id, to, 0))) { |
|
|
2526 | //osm_warning("relation",relid,0,"turn restriction: failed to connect via "); |
|
|
2527 | //osm_warning(osm_types[viam.type],viam.id,1," 0x%x,0x%x-0x%x,0x%x to to member ",viafrom->x,viafrom->y,viato->x,viato->y); |
|
|
2528 | //osm_warning(osm_types[tom.type],tom.id,1," ("); |
|
|
2529 | //get_way(ways, ways_index, viato, tom.id, to, 1); |
|
|
2530 | //fprintf(stderr,")\n"); |
|
|
2531 | continue; |
|
|
2532 | } |
|
|
2533 | #if 0 |
|
|
2534 | fprintf(stderr,"(0x%x,0x%x)-(0x%x,0x%x)-(0x%x,0x%x)\n",fromc->x,fromc->y, ni.c.x, ni.c.y, toc->x, toc->y); |
|
|
2535 | #endif |
|
|
2536 | item_bin_init(ib,ib->type); |
|
|
2537 | item_bin_add_coord(ib, fromc, 1); |
|
|
2538 | item_bin_add_coord(ib, viafrom, 1); |
|
|
2539 | if (viam.type == 2) |
|
|
2540 | item_bin_add_coord(ib, viato, 1); |
|
|
2541 | item_bin_add_coord(ib, toc, 1); |
|
|
2542 | item_bin_write(item_bin, out); |
|
|
2543 | } |
|
|
2544 | } |
7861 | } |
2545 | |
7862 | |
2546 | #if 0 |
7863 | int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final) |
2547 | static void |
|
|
2548 | process_countries(FILE *way, FILE *ways_index) |
|
|
2549 | { |
7864 | { |
2550 | FILE *in=fopen("country_de.tmp","r"); |
|
|
2551 | struct item_bin *ib; |
|
|
2552 | char buffer2[400000]; |
|
|
2553 | struct item_bin *ib2=(struct item_bin *)buffer2; |
|
|
2554 | GList *segments=NULL,*sort_segments; |
|
|
2555 | fseek(in, 0, SEEK_SET); |
|
|
2556 | while ((ib=read_item(in))) { |
|
|
2557 | char *str=NULL; |
|
|
2558 | struct relation_member member; |
|
|
2559 | while ((str=item_bin_get_attr(ib, attr_osm_member, str))) { |
|
|
2560 | if (!get_relation_member(str, &member)) |
|
|
2561 | break; |
|
|
2562 | if (member.type == 2) { |
|
|
2563 | if (!seek_to_way(way, ways_index, member.id)) { |
|
|
2564 | fprintf(stderr,"not found in index"); |
|
|
2565 | break; |
|
|
2566 | } |
|
|
2567 | while (item_bin_read(ib2, way)) { |
|
|
2568 | if (item_bin_get_wayid(ib2) != member.id) |
|
|
2569 | break; |
|
|
2570 | segments=g_list_prepend(segments,item_bin_to_poly_segment(ib2, geom_poly_segment_type_way_unknown)); |
|
|
2571 | break; |
|
|
2572 | } |
|
|
2573 | } |
|
|
2574 | } |
|
|
2575 | } |
|
|
2576 | sort_segments=geom_poly_segments_sort(segments, geom_poly_segment_type_way_left_side); |
|
|
2577 | FILE *tmp=fopen("tst.txt","w"); |
|
|
2578 | while (sort_segments) { |
|
|
2579 | struct geom_poly_segment *seg=sort_segments->data; |
|
|
2580 | if (!seg) { |
|
|
2581 | fprintf(stderr,"is null\n"); |
|
|
2582 | } else { |
|
|
2583 | 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)); |
|
|
2584 | } |
|
|
2585 | #if 0 |
|
|
2586 | int count=seg->last-seg->first+1; |
|
|
2587 | item_bin_init(ib, type_border_country); |
|
|
2588 | item_bin_add_coord(ib, seg->first, count); |
|
|
2589 | item_bin_dump(ib, tmp); |
|
|
2590 | #endif |
|
|
2591 | |
|
|
2592 | sort_segments=g_list_next(sort_segments); |
|
|
2593 | } |
|
|
2594 | fclose(tmp); |
|
|
2595 | fclose(in); |
|
|
2596 | } |
|
|
2597 | #endif |
|
|
2598 | |
|
|
2599 | static void |
|
|
2600 | node_ref_way(osmid node) |
|
|
2601 | { |
|
|
2602 | struct node_item *ni; |
|
|
2603 | ni=node_item_get(node); |
|
|
2604 | if (ni) |
|
|
2605 | ni->ref_way++; |
|
|
2606 | } |
|
|
2607 | |
|
|
2608 | static void |
|
|
2609 | nodes_ref_item_bin(struct item_bin *ib) |
|
|
2610 | { |
|
|
2611 | int i; |
|
|
2612 | struct coord *c=(struct coord *)(ib+1); |
|
|
2613 | for (i = 0 ; i < ib->clen/2 ; i++) |
|
|
2614 | node_ref_way(REF(c[i])); |
|
|
2615 | } |
|
|
2616 | |
|
|
2617 | |
|
|
2618 | void |
|
|
2619 | osm_add_nd(osmid ref) |
|
|
2620 | { |
|
|
2621 | SET_REF(coord_buffer[coord_count], ref); |
|
|
2622 | coord_count++; |
|
|
2623 | if (coord_count > 65536) { |
|
|
2624 | fprintf(stderr,"ERROR: Overflow\n"); |
|
|
2625 | exit(1); |
|
|
2626 | } |
|
|
2627 | } |
|
|
2628 | |
|
|
2629 | static void |
|
|
2630 | write_item_part(FILE *out, FILE *out_index, FILE *out_graph, struct item_bin *orig, int first, int last, long long *last_id) |
|
|
2631 | { |
|
|
2632 | struct item_bin new; |
|
|
2633 | struct coord *c=(struct coord *)(orig+1); |
|
|
2634 | char *attr=(char *)(c+orig->clen/2); |
|
|
2635 | int attr_len=orig->len-orig->clen-2; |
|
|
2636 | processed_ways++; |
|
|
2637 | new.type=orig->type; |
|
|
2638 | new.clen=(last-first+1)*2; |
|
|
2639 | new.len=new.clen+attr_len+2; |
|
|
2640 | if (out_index) { |
|
|
2641 | long long idx[2]; |
|
|
2642 | idx[0]=item_bin_get_wayid(orig); |
|
|
2643 | idx[1]=ftell(out); |
|
|
2644 | if (way_hash) { |
|
|
2645 | if (!(g_hash_table_lookup_extended(way_hash, (gpointer)(long)idx[0], NULL, NULL))) |
|
|
2646 | g_hash_table_insert(way_hash, (gpointer)(long)idx[0], (gpointer)(long)idx[1]); |
|
|
2647 | } else { |
|
|
2648 | if (!last_id || *last_id != idx[0]) |
|
|
2649 | fwrite(idx, sizeof(idx), 1, out_index); |
|
|
2650 | if (last_id) |
|
|
2651 | *last_id=idx[0]; |
|
|
2652 | } |
|
|
2653 | |
|
|
2654 | } |
|
|
2655 | #if 0 |
|
|
2656 | 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); |
|
|
2657 | #endif |
|
|
2658 | fwrite(&new, sizeof(new), 1, out); |
|
|
2659 | fwrite(c+first, new.clen*4, 1, out); |
|
|
2660 | fwrite(attr, attr_len*4, 1, out); |
|
|
2661 | #if 0 |
|
|
2662 | fwrite(&new, sizeof(new), 1, out_graph); |
|
|
2663 | fwrite(c+first, new.clen*4, 1, out_graph); |
|
|
2664 | fwrite(attr, attr_len*4, 1, out_graph); |
|
|
2665 | #endif |
|
|
2666 | } |
|
|
2667 | |
|
|
2668 | void |
|
|
2669 | ref_ways(FILE *in) |
|
|
2670 | { |
|
|
2671 | struct item_bin *ib; |
|
|
2672 | |
|
|
2673 | fseek(in, 0, SEEK_SET); |
|
|
2674 | while ((ib=read_item(in))) |
|
|
2675 | nodes_ref_item_bin(ib); |
|
|
2676 | } |
|
|
2677 | |
|
|
2678 | void |
|
|
2679 | resolve_ways(FILE *in, FILE *out) |
|
|
2680 | { |
|
|
2681 | struct item_bin *ib; |
|
|
2682 | struct coord *c; |
7865 | struct coord *c; |
2683 | int i; |
|
|
2684 | struct node_item *ni; |
|
|
2685 | |
|
|
2686 | fseek(in, 0, SEEK_SET); |
|
|
2687 | while ((ib=read_item(in))) { |
|
|
2688 | c=(struct coord *)(ib+1); |
|
|
2689 | for (i = 0 ; i < ib->clen/2 ; i++) { |
|
|
2690 | if(!IS_REF(c[i])) |
|
|
2691 | continue; |
|
|
2692 | ni=node_item_get(REF(c[i])); |
|
|
2693 | if(ni) { |
|
|
2694 | c[i].x=ni->c.x; |
|
|
2695 | c[i].y=ni->c.y; |
|
|
2696 | } |
|
|
2697 | } |
|
|
2698 | item_bin_write(ib,out); |
|
|
2699 | } |
|
|
2700 | } |
|
|
2701 | |
|
|
2702 | FILE * |
|
|
2703 | resolve_ways_file(FILE *in, char *suffix, char *filename) |
|
|
2704 | { |
|
|
2705 | char *newfilename=g_strdup_printf("%s_new",filename); |
|
|
2706 | FILE *new=tempfile(suffix,newfilename,1); |
|
|
2707 | resolve_ways(in, new); |
|
|
2708 | fclose(in); |
|
|
2709 | fclose(new); |
|
|
2710 | tempfile_rename(suffix,newfilename,filename); |
|
|
2711 | g_free(newfilename); |
|
|
2712 | return tempfile(suffix,filename,0); |
|
|
2713 | } |
|
|
2714 | |
|
|
2715 | /** |
|
|
2716 | * Get POI coordinates from area/line coordinates. |
|
|
2717 | * @param in *in input file with area/line coordinates. |
|
|
2718 | * @param in *out output file with POI coordinates |
|
|
2719 | * @param in type input file original contents type: type_line or type_area |
|
|
2720 | * @returns nothing |
|
|
2721 | */ |
|
|
2722 | void |
|
|
2723 | process_way2poi(FILE *in, FILE *out, int type) |
|
|
2724 | { |
|
|
2725 | struct item_bin *ib; |
|
|
2726 | while ((ib=read_item(in))) { |
|
|
2727 | int count=ib->clen/2; |
|
|
2728 | if(count>1 && ib->type<type_line) { |
|
|
2729 | struct coord *c=(struct coord *)(ib+1), c1, c2; |
|
|
2730 | int done=0; |
|
|
2731 | if(type==type_area) { |
|
|
2732 | if(count<3) { |
|
|
2733 | osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, less than 3 points defined\n"); |
|
|
2734 | } else if(!geom_poly_centroid(c, count, &c1)) { |
|
|
2735 | osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, area is 0\n"); |
|
|
2736 | } else { |
|
|
2737 | if(geom_poly_point_inside(c, count, &c1)) { |
|
|
2738 | c[0]=c1; |
|
|
2739 | } else { |
|
|
2740 | geom_poly_closest_point(c, count, &c1, &c2); |
|
|
2741 | c[0]=c2; |
|
|
2742 | } |
|
|
2743 | done=1; |
|
|
2744 | } |
|
|
2745 | } |
|
|
2746 | if(!done) { |
|
|
2747 | geom_line_middle(c,count,&c1); |
|
|
2748 | c[0]=c1; |
|
|
2749 | } |
|
|
2750 | write_item_part(out, NULL, NULL, ib, 0, 0, NULL); |
|
|
2751 | } |
|
|
2752 | } |
|
|
2753 | } |
|
|
2754 | |
|
|
2755 | |
|
|
2756 | int |
|
|
2757 | map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final) |
|
|
2758 | { |
|
|
2759 | struct coord *c; |
|
|
2760 | int i,ccount,last,remaining; |
7866 | int i, ccount, last, remaining; |
2761 | osmid ndref; |
7867 | osmid ndref; |
2762 | struct item_bin *ib; |
7868 | struct item_bin *ib; |
2763 | struct node_item *ni; |
7869 | struct node_item *ni; |
2764 | long long last_id=0; |
7870 | long long last_id = 0; |
|
|
7871 | long long ways_count = 0; |
|
|
7872 | osmid *this_way_id; |
|
|
7873 | osmid this_way_id_real; |
|
|
7874 | int i_real = -1; |
2765 | |
7875 | |
2766 | processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0; |
7876 | processed_nodes = processed_nodes_out = processed_ways = processed_relations = processed_tiles = 0; |
2767 | sig_alrm(0); |
7877 | |
2768 | while ((ib=read_item(in))) { |
7878 | // ---------- reset the cached values ---------- |
2769 | #if 0 |
7879 | seekpos_waynode[0] = -1; |
|
|
7880 | last_seekpos_waynode[0] = -1; |
|
|
7881 | last_seek_wayid[0] = -1; |
|
|
7882 | fseeko(ways_ref_file_thread[0], (off_t)0, SEEK_SET); |
|
|
7883 | // ---------- reset the cached values ---------- |
|
|
7884 | |
|
|
7885 | |
|
|
7886 | while ((ib = read_item(in, 0))) // loop thru all "ways" from file "in" |
|
|
7887 | { |
|
|
7888 | |
|
|
7889 | this_way_id = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
|
|
7890 | if (this_way_id) |
|
|
7891 | { |
|
|
7892 | this_way_id_real = *this_way_id; |
2770 | fprintf(stderr,"type 0x%x len %d clen %d\n", ib->type, ib->len, ib->clen); |
7893 | // fprintf(stderr,"wayid:%lld type:0x%x len:%d clen:%d\n", *this_way_id, ib->type, ib->len, (ib->clen / 2)); |
2771 | #endif |
7894 | } |
|
|
7895 | |
2772 | ccount=ib->clen/2; |
7896 | ccount = ib->clen / 2; |
|
|
7897 | |
2773 | if (ccount <= 1) |
7898 | if (ccount <= 1) |
|
|
7899 | { |
2774 | continue; |
7900 | continue; |
|
|
7901 | } |
|
|
7902 | |
|
|
7903 | //fprintf(stderr,"********DUMP ww1***********\n"); |
|
|
7904 | //dump_itembin(ib); |
|
|
7905 | //fprintf(stderr,"********DUMP ww1***********\n"); |
|
|
7906 | |
|
|
7907 | |
|
|
7908 | ways_count++; |
|
|
7909 | if ((ways_count % 10000000) == 0) |
|
|
7910 | { |
|
|
7911 | fprintf(stderr, "ways: %lld\n", ways_count); |
|
|
7912 | } |
|
|
7913 | |
2775 | c=(struct coord *)(ib+1); |
7914 | c = (struct coord *) (ib + 1); |
2776 | last=0; |
7915 | last = 0; |
2777 | for (i = 0 ; i < ccount ; i++) { |
7916 | i_real = -1; |
|
|
7917 | for (i = 0; i < ccount; i++) // loop thru all the coordinates (nodes) of this way |
|
|
7918 | { |
|
|
7919 | //if (this_way_id_real != 0) |
|
|
7920 | //{ |
|
|
7921 | // fprintf(stderr, "this_way_id_real=%lld this_way_id=%lld i=%d ccount=%d\n", this_way_id_real, *this_way_id, i, ccount); |
|
|
7922 | //} |
|
|
7923 | |
2778 | if (IS_REF(c[i])) { |
7924 | if (IS_REF(c[i])) |
2779 | ndref=REF(c[i]); |
7925 | { |
|
|
7926 | //fprintf(stderr, "is ref\n"); |
|
|
7927 | if (this_way_id_real != 0) |
|
|
7928 | { |
|
|
7929 | i_real = c[i].y; // number of this node in the way (starting at zero) |
|
|
7930 | ndref = get_waynode_num(this_way_id_real, i_real, 0); |
|
|
7931 | //fprintf(stderr, "wayid:%lld wid(p)=%p i_real=%d i=%d ndref(1)=%lld\n", this_way_id_real, this_way_id, i_real, i, ndref); |
2780 | ni=node_item_get(ndref); |
7932 | ni = node_item_get_fast(ndref, 0); |
|
|
7933 | //fprintf(stderr, "ni(1)=%p\n", ni); |
|
|
7934 | } |
|
|
7935 | else |
|
|
7936 | { |
|
|
7937 | ni = NULL; |
|
|
7938 | } |
|
|
7939 | |
|
|
7940 | //fprintf(stderr, "ndref(2)=%lld\n", ndref); |
|
|
7941 | |
2781 | if (ni) { |
7942 | if (ni) |
2782 | c[i]=ni->c; |
7943 | { |
|
|
7944 | //fprintf(stderr, "ni TRUE\n"); |
|
|
7945 | |
|
|
7946 | c[i] = ni->c; // write "lat,long" from node into way !! |
2783 | if (ni->ref_way > 1 && i != 0 && i != ccount-1 && i != last && item_get_default_flags(ib->type)) { |
7947 | if (ni->ref_way > 1 && i != 0 && i != ccount - 1 && i != last && item_get_default_flags(ib->type)) |
|
|
7948 | { |
|
|
7949 | //fprintf(stderr, "wr i 001\n"); |
|
|
7950 | // if "ref_way > 1" , means this node belongs to more than 1 way, so it must be an intersection |
2784 | write_item_part(out, out_index, out_graph, ib, last, i, &last_id); |
7951 | // *** write_item_part(out, out_index, out_graph, ib, last, i, &last_id); |
|
|
7952 | write_item_part(out, NULL, out_graph, ib, last, i, &last_id); |
2785 | last=i; |
7953 | last = i; |
2786 | } |
7954 | } |
|
|
7955 | } |
2787 | } else if (final) { |
7956 | else if (final) |
|
|
7957 | { |
|
|
7958 | //fprintf(stderr, "wr i 002(f)\n"); |
|
|
7959 | |
2788 | //osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to "); |
7960 | //osm_warning("way",item_bin_get_wayid(ib),0,"Non-existing reference to "); |
2789 | //osm_warning("node",ndref,1,"\n"); |
7961 | //osm_warning("node",ndref,1,"\n"); |
2790 | remaining=(ib->len+1)*4-sizeof(struct item_bin)-i*sizeof(struct coord); |
7962 | remaining = (ib->len + 1) * 4 - sizeof(struct item_bin) - i * sizeof(struct coord); |
2791 | memmove(&c[i], &c[i+1], remaining); |
7963 | memmove(&c[i], &c[i + 1], remaining); |
2792 | ib->clen-=2; |
7964 | ib->clen -= 2; |
2793 | ib->len-=2; |
7965 | ib->len -= 2; |
2794 | i--; |
7966 | i--; |
2795 | ccount--; |
7967 | ccount--; |
2796 | } |
7968 | } |
2797 | } |
7969 | } |
|
|
7970 | //else |
|
|
7971 | //{ |
|
|
7972 | // fprintf(stderr, "is NOT ref\n"); |
|
|
7973 | //} |
2798 | } |
7974 | } |
|
|
7975 | |
2799 | if (ccount) { |
7976 | if (ccount) |
|
|
7977 | { |
|
|
7978 | //fprintf(stderr, "wr i 003(ccount)\n"); |
|
|
7979 | |
|
|
7980 | //fprintf(stderr,"*x*coastline*x*\n"); |
2800 | write_item_part(out, out_index, out_graph, ib, last, ccount-1, &last_id); |
7981 | // ***** write_item_part(out, out_index, out_graph, ib, last, ccount - 1, &last_id); |
|
|
7982 | write_item_part(out, NULL, out_graph, ib, last, ccount - 1, &last_id); |
2801 | if (final && ib->type == type_water_line && out_coastline) { |
7983 | if (final && ib->type == type_water_line && out_coastline) |
|
|
7984 | { |
|
|
7985 | //fprintf(stderr,"write out_coastline\n"); |
2802 | write_item_part(out_coastline, NULL, NULL, ib, last, ccount-1, NULL); |
7986 | write_item_part(out_coastline, NULL, NULL, ib, last, ccount - 1, NULL); |
2803 | } |
|
|
2804 | } |
7987 | } |
2805 | } |
7988 | } |
2806 | sig_alrm(0); |
7989 | } |
2807 | sig_alrm_end(); |
7990 | |
2808 | return 0; |
7991 | return 0; |
2809 | } |
7992 | } |
2810 | |
7993 | |
2811 | static void |
|
|
2812 | index_country_add(struct zip_info *info, int country_id, int zipnum) |
7994 | static void index_country_add(struct zip_info *info, int country_id, int zipnum) |
2813 | { |
7995 | { |
2814 | struct item_bin *item_bin=init_item(type_countryindex); |
7996 | struct item_bin *item_bin = init_item(type_countryindex, 0); |
2815 | item_bin_add_attr_int(item_bin, attr_country_id, country_id); |
7997 | item_bin_add_attr_int(item_bin, attr_country_id, country_id); |
2816 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, zipnum); |
7998 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, zipnum); |
2817 | item_bin_write(item_bin, zip_get_index(info)); |
7999 | item_bin_write(item_bin, zip_get_index(info)); |
2818 | } |
8000 | } |
2819 | |
8001 | |
2820 | void |
|
|
2821 | write_countrydir(struct zip_info *zip_info) |
8002 | void write_countrydir(struct zip_info *zip_info) |
2822 | { |
8003 | { |
2823 | int i,zipnum,num; |
8004 | int i, zipnum, num; |
2824 | int max=11; |
8005 | int max = 11; |
2825 | char tilename[32]; |
8006 | char tilename[32]; |
2826 | char filename[32]; |
8007 | char filename[32]; |
2827 | char suffix[32]; |
8008 | char suffix[32]; |
2828 | struct country_table *co; |
8009 | struct country_table *co; |
2829 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { |
8010 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
|
|
8011 | { |
2830 | co=&country_table[i]; |
8012 | co = &country_table[i]; |
2831 | if (co->size) { |
8013 | if (co->size) |
|
|
8014 | { |
2832 | num=0; |
8015 | num = 0; |
2833 | do { |
8016 | do |
|
|
8017 | { |
2834 | tilename[0]='\0'; |
8018 | tilename[0] = '\0'; |
2835 | sprintf(suffix,"s%d", num); |
8019 | sprintf(suffix, "s%d", num); |
2836 | num++; |
8020 | num++; |
2837 | tile(&co->r, suffix, tilename, max, overlap, NULL); |
8021 | tile(&co->r, suffix, tilename, max, overlap, NULL); |
2838 | |
8022 | |
2839 | sprintf(filename,"country_%d.tmp", co->countryid); |
8023 | sprintf(filename, "country_%d.tmp", co->countryid); |
2840 | if (debug_itembin(4)) |
8024 | if (debug_itembin(4)) |
2841 | { |
8025 | { |
2842 | fprintf(stderr,"write_countrydir: tilename=%s country_%d.tmp\n", tilename ,co->countryid); |
8026 | fprintf(stderr, "write_countrydir: tilename=%s country_%d.tmp\n", tilename, co->countryid); |
2843 | } |
8027 | } |
2844 | zipnum=add_aux_tile(zip_info, tilename, filename, co->size); |
8028 | zipnum = add_aux_tile(zip_info, tilename, filename, co->size); |
|
|
8029 | } |
2845 | } while (zipnum == -1); |
8030 | while (zipnum == -1); |
2846 | index_country_add(zip_info,co->countryid,zipnum); |
8031 | index_country_add(zip_info, co->countryid, zipnum); |
2847 | } |
|
|
2848 | } |
8032 | } |
|
|
8033 | } |
2849 | } |
8034 | } |
2850 | |
8035 | |
2851 | void |
|
|
2852 | load_countries(void) |
8036 | void load_countries(void) |
2853 | { |
8037 | { |
2854 | char filename[32]; |
8038 | char filename[32]; |
2855 | FILE *f; |
8039 | FILE *f; |
2856 | int i; |
8040 | int i; |
2857 | struct country_table *co; |
8041 | struct country_table *co; |
2858 | |
8042 | |
2859 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { |
8043 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
|
|
8044 | { |
2860 | co=&country_table[i]; |
8045 | co = &country_table[i]; |
2861 | sprintf(filename,"country_%d.tmp", co->countryid); |
8046 | sprintf(filename, "country_%d.tmp", co->countryid); |
2862 | if (debug_itembin(4)) |
8047 | if (debug_itembin(4)) |
2863 | { |
8048 | { |
2864 | fprintf(stderr,"load_countries: country_%d.tmp\n", co->countryid); |
8049 | fprintf(stderr, "load_countries: country_%d.tmp\n", co->countryid); |
2865 | } |
8050 | } |
2866 | |
8051 | |
2867 | f=fopen(filename,"rb"); |
8052 | f = fopen(filename, "rb"); |
2868 | if (f) { |
8053 | if (f) |
|
|
8054 | { |
2869 | int i,first=1; |
8055 | int i, first = 1; |
2870 | struct item_bin *ib; |
8056 | struct item_bin *ib; |
2871 | while ((ib=read_item(f))) { |
8057 | while ((ib = read_item(f, 0))) |
|
|
8058 | { |
2872 | struct coord *c=(struct coord *)(ib+1); |
8059 | struct coord *c = (struct coord *) (ib + 1); |
2873 | co->size+=ib->len*4+4; |
8060 | co->size += ib->len * 4 + 4; |
2874 | for (i = 0 ; i < ib->clen/2 ; i++) { |
8061 | for (i = 0; i < ib->clen / 2; i++) |
|
|
8062 | { |
2875 | if (first) { |
8063 | if (first) |
|
|
8064 | { |
2876 | co->r.l=c[i]; |
8065 | co->r.l = c[i]; |
2877 | co->r.h=c[i]; |
8066 | co->r.h = c[i]; |
2878 | first=0; |
8067 | first = 0; |
|
|
8068 | } |
2879 | } else |
8069 | else |
|
|
8070 | { |
2880 | bbox_extend(&c[i], &co->r); |
8071 | bbox_extend(&c[i], &co->r); |
|
|
8072 | } |
2881 | } |
8073 | } |
2882 | } |
8074 | } |
2883 | fseek(f, 0, SEEK_END); |
8075 | fseek(f, 0, SEEK_END); |
2884 | co->size=ftell(f); |
8076 | co->size = ftell(f); |
2885 | fclose(f); |
8077 | fclose(f); |
2886 | } |
8078 | } |
2887 | } |
8079 | } |
2888 | } |
8080 | } |
2889 | |
8081 | |
2890 | void |
|
|
2891 | remove_countryfiles(void) |
8082 | void remove_countryfiles(void) |
2892 | { |
8083 | { |
2893 | int i; |
8084 | int i; |
2894 | char filename[32]; |
8085 | char filename[32]; |
2895 | struct country_table *co; |
8086 | struct country_table *co; |
2896 | |
8087 | |
2897 | for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { |
8088 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
|
|
8089 | { |
2898 | co=&country_table[i]; |
8090 | co = &country_table[i]; |
2899 | if (co->size) { |
8091 | if (co->size) |
|
|
8092 | { |
2900 | sprintf(filename,"country_%d.tmp", co->countryid); |
8093 | sprintf(filename, "country_%d.tmp", co->countryid); |
2901 | unlink(filename); |
8094 | unlink(filename); |
2902 | } |
8095 | } |
2903 | } |
8096 | } |
2904 | } |
8097 | } |
2905 | |
8098 | |
2906 | void osm_init(FILE* rule_file) |
8099 | void osm_init(FILE* rule_file) |
2907 | { |
8100 | { |
2908 | build_attrmap(rule_file); |
8101 | build_attrmap(rule_file); |
2909 | build_countrytable(); |
8102 | build_countrytable(); |
2910 | } |
8103 | } |
2911 | |
8104 | |