Parent Directory
|
Revision Log
updates
1 | /** |
2 | * ZANavi, Zoff Android Navigation system. |
3 | * Copyright (C) 2011-2013 Zoff <zoff@zoff.cc> |
4 | * |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License |
7 | * version 2 as published by the Free Software Foundation. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the |
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | /** |
21 | * Navit, a modular navigation system. |
22 | * Copyright (C) 2005-2011 Navit Team |
23 | * |
24 | * This program is free software; you can redistribute it and/or |
25 | * modify it under the terms of the GNU General Public License |
26 | * version 2 as published by the Free Software Foundation. |
27 | * |
28 | * This program is distributed in the hope that it will be useful, |
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31 | * GNU General Public License for more details. |
32 | * |
33 | * You should have received a copy of the GNU General Public License |
34 | * along with this program; if not, write to the |
35 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
36 | * Boston, MA 02110-1301, USA. |
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> |
111 | #include <unistd.h> |
112 | #include <time.h> |
113 | #include <stdio.h> |
114 | #include <string.h> |
115 | #include <stdlib.h> |
116 | #include <math.h> |
117 | #include "debug.h" |
118 | #include "linguistics.h" |
119 | #include "country.h" |
120 | #include "file.h" |
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 | |
144 | #define _FILE_OFFSET_BITS 64 |
145 | #define _LARGEFILE_SOURCE |
146 | #define _LARGEFILE64_SOURCE |
147 | |
148 | |
149 | |
150 | |
151 | #include "osm_countrytable.h" |
152 | |
153 | |
154 | // function def -- |
155 | static long long osm_process_street_by_manual_country_borders(GList *bl_manual, struct coord *c); |
156 | static int osm_check_all_inner_polys_of_country_id(int country_id, struct coord *c); |
157 | // function def -- |
158 | |
159 | |
160 | extern int doway2poi; |
161 | |
162 | static int in_way, in_node, in_relation; |
163 | static osmid nodeid, wayid; |
164 | osmid current_id; |
165 | |
166 | static GHashTable *attr_hash, *country_table_hash; |
167 | |
168 | void add_boundary_to_db(long long current_id, int admin_level, struct item_bin *item_bin_3, struct relation_member *memb); |
169 | void add_waynode_to_db(osmid ref, int c_count); |
170 | |
171 | static char *attr_present; |
172 | static int attr_present_count; |
173 | |
174 | static struct item_bin item; |
175 | |
176 | int maxspeed_attr_value; |
177 | |
178 | char debug_attr_buffer[BUFFER_SIZE]; |
179 | |
180 | int flags[4]; |
181 | |
182 | int flags_attr_value; |
183 | |
184 | struct attr_bin osmid_attr; |
185 | osmid osmid_attr_value; |
186 | |
187 | char is_in_buffer[BUFFER_SIZE]; |
188 | |
189 | char attr_strings_buffer[BUFFER_SIZE * 16]; |
190 | int attr_strings_buffer_len; |
191 | int alt_name_found = 0; |
192 | int real_alt_name_found = 0; |
193 | |
194 | struct coord coord_buffer[65536]; |
195 | struct coord coord_buffer_3[65536]; |
196 | |
197 | struct attr_mapping |
198 | { |
199 | enum item_type type; |
200 | int attr_present_idx_count; |
201 | int attr_present_idx[0]; |
202 | }; |
203 | |
204 | static void nodes_ref_item_bin(struct item_bin *ib, int local_thread_num, osmid this_way_id); |
205 | |
206 | static struct attr_mapping **attr_mapping_node; |
207 | static int attr_mapping_node_count; |
208 | static struct attr_mapping **attr_mapping_way; |
209 | static int attr_mapping_way_count; |
210 | static struct attr_mapping **attr_mapping_way2poi; |
211 | static int attr_mapping_way2poi_count; |
212 | |
213 | static char *attr_present; |
214 | static int attr_present_count; |
215 | |
216 | static long long seekpos1; |
217 | |
218 | enum attr_strings |
219 | { |
220 | attr_string_phone, attr_string_fax, attr_string_email, attr_string_url, attr_string_street_name, attr_string_street_name_systematic, attr_string_house_number, attr_string_label, attr_string_label_alt, attr_string_label_real_alt, attr_string_postal, |
221 | attr_string_population, attr_string_county_name, attr_string_colour_, attr_string_capacity, |
222 | attr_string_street_name_systematic_nat, |
223 | attr_string_street_name_systematic_int, |
224 | attr_string_ref, |
225 | attr_string_exit_to, |
226 | attr_string_street_destination, |
227 | attr_string_street_lanes, |
228 | // ---------- |
229 | attr_string_street_lanes_forward, |
230 | attr_string_street_turn_lanes, |
231 | attr_string_street_destination_lanes, |
232 | // ----- last ---- |
233 | attr_string_last, |
234 | }; |
235 | |
236 | char *attr_strings[attr_string_last]; |
237 | |
238 | char *osm_types[] = { "unknown", "node", "way", "relation" }; |
239 | |
240 | double save_node_lat; |
241 | double save_node_lon; |
242 | |
243 | // #define REF_X 1073741834 --> maptool.h // lat |
244 | // #define REF_Y 240000000 --> maptool.h // lon |
245 | #define IS_REF(c) (check_decode_nodeid(c)) // --> new method |
246 | // #define IS_REF(c) ((c).x >= (1 << 30)) // --> old method again |
247 | |
248 | // #define SET_REF(c,ref) (encode_nodeid(c, ref)) |
249 | // #define REF(c) (decode_nodeid(c)) |
250 | |
251 | void encode_nodeid(struct coord *c, osmid ref) |
252 | { |
253 | //fprintf(stderr, "ref=%lld bb=%lld 1=%lld\n", ref, (1 << 31), ((1 << 31) >> 31)); |
254 | //fprintf(stderr, "11=%lld 22=%lld\n", (ref >> 31), (1 << 30)); |
255 | //fprintf(stderr, "encode_nodeid:ref=%lld\n", ref); |
256 | |
257 | if (ref > 0xffffffff) |
258 | { |
259 | c->x = (1 << 30) | (ref >> 32 ); |
260 | c->y = ref & (0xffffffff); |
261 | } |
262 | else |
263 | { |
264 | c->x = 1 << 30; |
265 | c->y = ref; |
266 | } |
267 | |
268 | #if 0 |
269 | // lat = y |
270 | int x = transform_from_geo_lat(-90); |
271 | fprintf(stderr, "y=%d %x\n", x, x); |
272 | x = transform_from_geo_lat(0); |
273 | fprintf(stderr, "y=%d %x\n", x, x); |
274 | x = transform_from_geo_lat(90); |
275 | fprintf(stderr, "y=%d %x\n", x, x); |
276 | |
277 | // lon = x |
278 | int y = transform_from_geo_lon(-180); |
279 | fprintf(stderr, "x=%d %x\n", y, y); |
280 | y = transform_from_geo_lon(0); |
281 | fprintf(stderr, "x=%d %x\n", y, y); |
282 | y = transform_from_geo_lon(180); |
283 | fprintf(stderr, "x=%d %x\n", y, y); |
284 | #endif |
285 | |
286 | //fprintf(stderr, "encode_nodeid:cx=%x cy=%x 30th bit=%x ref=%x\n", c->x, c->y, (1 << 30), (ref >> 32) ); |
287 | } |
288 | |
289 | int check_decode_nodeid(struct coord c) |
290 | { |
291 | // fprintf(stderr, "check_decode_nodeid:is ref=%d\n", ((c.x & (1 << 30)) == (1 << 30)) ); |
292 | // fprintf(stderr, "check_decode_nodeid:c.x=%d c.y=%d\n", c.x, c.y); |
293 | |
294 | // if ((c.x == REF_X) && (c.y == REF_Y)) |
295 | if (c.x == REF_X) |
296 | { |
297 | // this number is not a real coordiante, its just a dummy to know we need to lookup |
298 | return 1; |
299 | } |
300 | else |
301 | { |
302 | // this is is real GPS coordinate |
303 | // fprintf(stderr, "check_decode_nodeid:c.x=%d c.y=%d\n", c.x, c.y); |
304 | return 0; |
305 | } |
306 | |
307 | //return ((c.x & (1 << 30)) == (1 << 30)); |
308 | } |
309 | |
310 | osmid decode_nodeid(struct coord c) |
311 | { |
312 | osmid ret; |
313 | |
314 | //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)); |
315 | if ( (c.x & (1 << 30)) == (1 << 30) ) |
316 | { |
317 | ret = c.y; |
318 | //fprintf(stderr, "decode_nodeid:1=%x\n", ret); |
319 | 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); |
320 | } |
321 | else |
322 | { |
323 | ret = (osmid)c.y; |
324 | } |
325 | //fprintf(stderr, "decode_nodeid:ret=%lld\n", ret); |
326 | |
327 | return ret; |
328 | } |
329 | |
330 | |
331 | |
332 | // first char - item type |
333 | // =w - ways |
334 | // =? - used both for nodes and ways |
335 | // otherwise - nodes |
336 | |
337 | |
338 | // for coastline-only map |
339 | static char *attrmap_cl = { "n *=* point_unkn\n" |
340 | "w *=* street_unkn\n" |
341 | "w natural=coastline water_line\n" }; |
342 | |
343 | // for border-only map |
344 | static char *attrmap_bo = { "n *=* point_unkn\n" |
345 | "w *=* street_unkn\n" |
346 | "w boundary=administrative,admin_level=2 border_country\n" |
347 | "w boundary=territorial,admin_level=2 border_country\n" |
348 | "w boundary=maritime,admin_level=2 border_country\n" |
349 | "w administrative=boundary,admin_level=2 border_country\n" |
350 | "w boundary=administrative,maritime=yes,admin_level=2 border_country\n" |
351 | "w boundary=administrative,maritime=yes,admin_level=4 border_country\n" |
352 | "w boundary=administrative,border_type=state,admin_level=4 border_country\n" }; |
353 | |
354 | // ========================== |
355 | // for USA |
356 | // ========================== |
357 | // admin_level = 4 |
358 | // border_type = state |
359 | // boundary = administrative |
360 | // ========================== |
361 | |
362 | |
363 | // for normal map |
364 | static char *attrmap_normal = { "n *=* point_unkn\n" |
365 | //// "n Annehmlichkeit=Hochsitz poi_hunting_stand\n" |
366 | "n addr:housenumber=* house_number\n" |
367 | "n aeroway=aerodrome poi_airport\n" |
368 | "n aeroway=airport poi_airport\n" |
369 | "n aeroway=helipad poi_heliport\n" |
370 | "n aeroway=terminal poi_airport\n" |
371 | "n amenity=atm poi_atm\n" |
372 | "n amenity=bank poi_bank\n" |
373 | "n amenity=bar poi_bar\n" |
374 | //"n amenity=bench poi_bench\n" |
375 | "n amenity=biergarten poi_biergarten\n" |
376 | "n amenity=bus_station poi_bus_station\n" |
377 | "n amenity=cafe poi_cafe\n" |
378 | "n amenity=car_wash poi_car_wash\n" |
379 | "n amenity=cinema poi_cinema\n" |
380 | "n amenity=college poi_school_college\n" |
381 | "n amenity=courthouse poi_justice\n" |
382 | //"n amenity=drinking_water poi_potable_water\n" |
383 | "n amenity=fast_food poi_fastfood\n" |
384 | "n amenity=fire_station poi_firebrigade\n" |
385 | //"n amenity=fountain poi_fountain\n" |
386 | "n amenity=fuel poi_fuel\n" |
387 | "n amenity=grave_yard poi_cemetery\n" |
388 | "n amenity=hospital poi_hospital\n" |
389 | //"n amenity=hunting_stand poi_hunting_stand\n" |
390 | "n amenity=kindergarten poi_kindergarten\n" |
391 | "n amenity=library poi_library\n" |
392 | "n amenity=nightclub poi_nightclub\n" |
393 | //"n amenity=park_bench poi_bench\n" |
394 | "n amenity=parking poi_car_parking\n" |
395 | "n amenity=bicycle_parking poi_bicycle_parking\n" |
396 | "n amenity=bicycle_rental poi_bicycle_rental\n" |
397 | "n amenity=pharmacy poi_pharmacy\n" |
398 | "n amenity=place_of_worship,religion=christian poi_church\n" |
399 | "n amenity=place_of_worship poi_worship\n" |
400 | "n amenity=police poi_police\n" |
401 | //"n amenity=post_box poi_post_box\n" |
402 | "n amenity=post_office poi_post_office\n" |
403 | "n amenity=prison poi_prison\n" |
404 | //"n amenity=pub poi_pub\n" |
405 | "n amenity=public_building poi_public_office\n" |
406 | //"n amenity=recycling poi_recycling\n" |
407 | "n amenity=restaurant,cuisine=fine_dining poi_dining\n" |
408 | "n amenity=restaurant poi_restaurant\n" |
409 | "n amenity=school poi_school\n" |
410 | //"n amenity=shelter poi_shelter\n" |
411 | "n amenity=taxi poi_taxi\n" |
412 | //"n amenity=tec_common tec_common\n" |
413 | //"n amenity=telephone poi_telephone\n" |
414 | "n amenity=theatre poi_theater\n" |
415 | "n amenity=toilets poi_restroom\n" |
416 | "n amenity=townhall poi_townhall\n" |
417 | "n amenity=university poi_school_university\n" |
418 | //"n amenity=vending_machine poi_vending_machine\n" |
419 | "n barrier=bollard barrier_bollard\n" |
420 | "n barrier=cycle_barrier barrier_cycle\n" |
421 | "n barrier=lift_gate barrier_lift_gate\n" |
422 | "n car=car_rental poi_car_rent\n" |
423 | "n highway=bus_station poi_bus_station\n" |
424 | "n highway=bus_stop poi_bus_stop\n" |
425 | "n highway=mini_roundabout mini_roundabout\n" |
426 | "n highway=motorway_junction highway_exit\n" |
427 | "n highway=stop traffic_sign_stop\n" |
428 | "n highway=toll_booth poi_toll_booth\n" |
429 | "n highway=crossing,crossing=traffic_signals traffic_crossing_signal\n" |
430 | "n highway=crossing,crossing=uncontrolled traffic_crossing_uncontrolled\n" |
431 | "n highway=crossing traffic_crossing_uncontrolled\n" |
432 | "n highway=traffic_signals traffic_signals\n" |
433 | "n highway=turning_circle turning_circle\n" |
434 | //"n historic=boundary_stone poi_boundary_stone\n" |
435 | "n historic=castle poi_castle\n" |
436 | "n historic=memorial poi_memorial\n" |
437 | "n historic=monument poi_monument\n" |
438 | "n historic=ruins poi_ruins\n" |
439 | //// "n historic=* poi_ruins\n" |
440 | "n landuse=cemetery poi_cemetery\n" |
441 | //"n leisure=fishing poi_fish\n" |
442 | "n leisure=golf_course poi_golf\n" |
443 | "n leisure=marina poi_marine\n" |
444 | //"n leisure=playground poi_playground\n" |
445 | //"n leisure=slipway poi_boat_ramp\n" |
446 | "n leisure=sports_centre poi_sport\n" |
447 | "n leisure=stadium poi_stadium\n" |
448 | //"n man_made=tower poi_tower\n" |
449 | "n military=airfield poi_military\n" |
450 | "n military=barracks poi_military\n" |
451 | "n military=bunker poi_military\n" |
452 | "n military=danger_area poi_danger_area\n" |
453 | "n military=range poi_military\n" |
454 | "n natural=bay poi_bay\n" |
455 | "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation |
456 | //"n natural=tree poi_tree\n" |
457 | "n place=city town_label_2e5\n" |
458 | "n place=town town_label_2e4\n" |
459 | "n place=village town_label_2e3\n" |
460 | "n place=hamlet town_label_2e2\n" |
461 | "n place=locality town_label_2e0\n" |
462 | "n place=suburb district_label\n" |
463 | "n place=quarter district_label_1e2\n" |
464 | "n place=neighbourhood district_label_1e1\n" |
465 | //"n power=tower power_tower\n" |
466 | //"n power=sub_station power_substation\n" |
467 | "n railway=halt poi_rail_halt\n" |
468 | "n railway=level_crossing poi_level_crossing\n" |
469 | "n railway=station poi_rail_station\n" |
470 | "n railway=tram_stop poi_rail_tram_stop\n" |
471 | "n shop=baker poi_shop_baker\n" |
472 | "n shop=bakery poi_shop_baker\n" |
473 | "n shop=beverages poi_shop_beverages\n" |
474 | "n shop=bicycle poi_shop_bicycle\n" |
475 | "n shop=butcher poi_shop_butcher\n" |
476 | "n shop=car poi_car_dealer_parts\n" |
477 | "n shop=car_repair poi_repair_service\n" |
478 | //"n shop=clothes poi_shop_apparel\n" |
479 | //"n shop=convenience poi_shop_grocery\n" |
480 | //"n shop=drogist poi_shop_drugstore\n" |
481 | //"n shop=florist poi_shop_florist\n" |
482 | //"n shop=fruit poi_shop_fruit\n" |
483 | //"n shop=furniture poi_shop_furniture\n" |
484 | //"n shop=garden_centre poi_shop_handg\n" |
485 | //"n shop=hardware poi_shop_handg\n" |
486 | "n shop=hairdresser poi_hairdresser\n" |
487 | //"n shop=kiosk poi_shop_kiosk\n" |
488 | //"n shop=optician poi_shop_optician\n" |
489 | //"n shop=parfum poi_shop_parfum\n" |
490 | //"n shop=photo poi_shop_photo\n" |
491 | "n shop=shoes poi_shop_shoes\n" |
492 | "n shop=supermarket poi_shopping\n" |
493 | //"n sport=10pin poi_bowling\n" |
494 | //"n sport=baseball poi_baseball\n" |
495 | //"n sport=basketball poi_basketball\n" |
496 | //"n sport=climbing poi_climbing\n" |
497 | "n sport=golf poi_golf\n" |
498 | //"n sport=motor_sports poi_motor_sport\n" |
499 | //"n sport=skiing poi_skiing\n" |
500 | "n sport=soccer poi_soccer\n" |
501 | "n sport=stadium poi_stadium\n" |
502 | "n sport=swimming poi_swimming\n" |
503 | "n sport=tennis poi_tennis\n" |
504 | "n tourism=attraction poi_attraction\n" |
505 | "n tourism=camp_site poi_camp_rv\n" |
506 | "n tourism=caravan_site poi_camp_rv\n" |
507 | "n tourism=guest_house poi_guesthouse\n" |
508 | "n tourism=hostel poi_hostel\n" |
509 | "n tourism=hotel poi_hotel\n" |
510 | "n tourism=information poi_information\n" |
511 | "n tourism=motel poi_motel\n" |
512 | "n tourism=museum poi_museum_history\n" |
513 | //"n tourism=picnic_site poi_picnic\n" |
514 | "n tourism=theme_park poi_resort\n" |
515 | "n tourism=viewpoint poi_viewpoint\n" |
516 | "n tourism=zoo poi_zoo\n" |
517 | "n traffic_sign=city_limit traffic_sign_city_limit\n" |
518 | "n highway=speed_camera tec_common\n" |
519 | "w *=* street_unkn\n" |
520 | "w addr:interpolation=even house_number_interpolation_even\n" |
521 | "w addr:interpolation=odd house_number_interpolation_odd\n" |
522 | "w addr:interpolation=all house_number_interpolation_all\n" |
523 | "w addr:interpolation=alphabetic house_number_interpolation_alphabetic\n" |
524 | //"w aerialway=cable_car lift_cable_car\n" |
525 | //"w aerialway=chair_lift lift_chair\n" |
526 | //"w aerialway=drag_lift lift_drag\n" |
527 | "w aeroway=aerodrome poly_airport\n" |
528 | "w aeroway=apron poly_apron\n" |
529 | "w aeroway=runway aeroway_runway\n" |
530 | "w aeroway=taxiway aeroway_taxiway\n" |
531 | "w aeroway=terminal poly_terminal\n" |
532 | "w amenity=college poly_college\n" |
533 | //"w amenity=grave_yard poly_cemetery\n" |
534 | "w amenity=parking poly_car_parking\n" |
535 | "w amenity=place_of_worship poly_building\n" |
536 | "w amenity=university poly_university\n" |
537 | // "w boundary=administrative,admin_level=2 border_country\n" --> in border map |
538 | //"w boundary=civil border_civil\n" |
539 | "w boundary=national_park border_national_park\n" |
540 | "w boundary=political border_political\n" |
541 | "w building=* poly_building\n" |
542 | "w contour_ext=elevation_major height_line_1\n" |
543 | "w contour_ext=elevation_medium height_line_2\n" |
544 | "w contour_ext=elevation_minor height_line_3\n" |
545 | "w highway=bridleway bridleway\n" |
546 | "w highway=bus_guideway bus_guideway\n" |
547 | "w highway=construction street_construction\n" |
548 | "w highway=cyclepath cycleway\n" |
549 | "w highway=cycleway cycleway\n" |
550 | "w highway=footway footway\n" |
551 | "w highway=footway,piste:type=nordic footway_and_piste_nordic\n" |
552 | "w highway=living_street living_street\n" |
553 | "w highway=minor street_1_land\n" |
554 | "w highway=parking_lane street_parking_lane\n" |
555 | "w highway=path path\n" |
556 | "w highway=path,bicycle=designated cycleway\n" |
557 | "w highway=path,bicycle=official cycleway\n" |
558 | "w highway=path,foot=designated footway\n" |
559 | "w highway=path,foot=official footway\n" |
560 | "w highway=path,horse=designated bridleway\n" |
561 | "w highway=path,horse=official bridleway\n" |
562 | //"w highway=path,sac_scale=alpine_hiking hiking_alpine\n" |
563 | //"w highway=path,sac_scale=demanding_alpine_hiking hiking_alpine_demanding\n" |
564 | //"w highway=path,sac_scale=demanding_mountain_hiking hiking_mountain_demanding\n" |
565 | //"w highway=path,sac_scale=difficult_alpine_hiking hiking_alpine_difficult\n" |
566 | //"w highway=path,sac_scale=hiking hiking\n" |
567 | //"w highway=path,sac_scale=mountain_hiking hiking_mountain\n" |
568 | "w highway=pedestrian street_pedestrian\n" |
569 | "w highway=pedestrian,area=1 poly_pedestrian\n" |
570 | "w highway=plaza poly_plaza\n" |
571 | "w highway=motorway highway_land\n" |
572 | "w highway=motorway,rural=0 highway_city\n" |
573 | "w highway=motorway_link ramp_highway_land\n" |
574 | "w highway=trunk street_n_lanes\n" |
575 | "w highway=trunk,name=*,rural=1 street_4_land\n" |
576 | "w highway=trunk,name=* street_n_lanes\n" |
577 | "w highway=trunk,rural=0 street_n_lanes\n" |
578 | "w highway=trunk_link ramp_street_4_city\n" |
579 | "w highway=primary street_4_land\n" |
580 | "w highway=primary,name=*,rural=1 street_4_land\n" |
581 | "w highway=primary,name=* street_4_city\n" |
582 | "w highway=primary,rural=0 street_4_city\n" |
583 | "w highway=primary_link ramp_street_4_city\n" |
584 | "w highway=secondary street_3_land\n" |
585 | "w highway=secondary,name=*,rural=1 street_3_land\n" |
586 | "w highway=secondary,name=* street_3_city\n" |
587 | "w highway=secondary,rural=0 street_3_city\n" |
588 | "w highway=secondary,area=1 poly_street_3\n" |
589 | "w highway=secondary_link ramp_street_3_city\n" |
590 | "w highway=tertiary street_2_land\n" |
591 | "w highway=tertiary,name=*,rural=1 street_2_land\n" |
592 | "w highway=tertiary,name=* street_2_city\n" |
593 | "w highway=tertiary,rural=0 street_2_city\n" |
594 | "w highway=tertiary,area=1 poly_street_2\n" |
595 | "w highway=tertiary_link ramp_street_2_city\n" |
596 | "w highway=residential street_1_city\n" |
597 | "w highway=residential,area=1 poly_street_1\n" |
598 | "w highway=unclassified street_1_city\n" |
599 | "w highway=unclassified,area=1 poly_street_1\n" |
600 | "w highway=road street_1_city\n" |
601 | "w highway=service street_service\n" |
602 | "w highway=service,area=1 poly_service\n" |
603 | "w highway=service,service=parking_aisle street_parking_lane\n" |
604 | "w highway=track track_gravelled\n" |
605 | "w highway=track,surface=grass track_grass\n" |
606 | "w highway=track,surface=gravel track_gravelled\n" |
607 | "w highway=track,surface=ground track_ground\n" |
608 | "w highway=track,surface=paved track_paved\n" |
609 | "w highway=track,surface=unpaved track_unpaved\n" |
610 | "w highway=track,tracktype=grade1 track_paved\n" |
611 | "w highway=track,tracktype=grade2 track_gravelled\n" |
612 | "w highway=track,tracktype=grade3 track_unpaved\n" |
613 | "w highway=track,tracktype=grade4 track_ground\n" |
614 | "w highway=track,tracktype=grade5 track_grass\n" |
615 | "w highway=track,surface=paved,tracktype=grade1 track_paved\n" |
616 | "w highway=track,surface=gravel,tracktype=grade2 track_gravelled\n" |
617 | "w highway=track,surface=unpaved,tracktype=grade3 track_unpaved\n" |
618 | "w highway=track,surface=ground,tracktype=grade4 track_ground\n" |
619 | "w highway=track,surface=grass,tracktype=grade5 track_grass\n" |
620 | "w highway=unsurfaced track_gravelled\n" |
621 | "w highway=steps steps\n" |
622 | "w historic=archaeological_site poly_archaeological_site\n" |
623 | "w historic=battlefield poly_battlefield\n" |
624 | "w historic=ruins poly_ruins\n" |
625 | "w historic=town gate poly_building\n" |
626 | //"w landuse=allotments poly_allotments\n" |
627 | //"w landuse=basin poly_basin\n" |
628 | //"w landuse=brownfield poly_brownfield\n" |
629 | "w landuse=cemetery poly_cemetery\n" |
630 | //"w landuse=commercial poly_commercial\n" |
631 | //"w landuse=construction poly_construction\n" |
632 | //"w landuse=farm poly_farm\n" |
633 | //"w landuse=farmland poly_farm\n" |
634 | //"w landuse=farmyard poly_town\n" |
635 | "w landuse=forest poly_wood\n" |
636 | "w landuse=greenfield poly_greenfield\n" |
637 | //"w landuse=industrial poly_industry\n" |
638 | //"w landuse=landfill poly_landfill\n" |
639 | "w landuse=military poly_military\n" |
640 | "w landuse=plaza poly_plaza\n" |
641 | //"w landuse=quarry poly_quarry\n" |
642 | "w landuse=railway poly_railway\n" |
643 | //"w landuse=recreation_ground poly_recreation_ground\n" |
644 | "w landuse=reservoir poly_reservoir\n" |
645 | //"w landuse=residential poly_town\n" |
646 | //"w landuse=residential,area=1 poly_town\n" |
647 | //"w landuse=retail poly_retail\n" |
648 | //"w landuse=village_green poly_village_green\n" |
649 | //"w landuse=vineyard poly_farm\n" |
650 | //"w leisure=common poly_common\n" |
651 | //"w leisure=fishing poly_fishing\n" |
652 | //"w leisure=garden poly_garden\n" |
653 | //"w leisure=golf_course poly_golf_course\n" |
654 | //"w leisure=marina poly_marina\n" |
655 | //"w leisure=nature_reserve poly_nature_reserve\n" |
656 | "w leisure=park poly_park\n" |
657 | //"w leisure=pitch poly_sports_pitch\n" |
658 | "w leisure=playground poly_playground\n" |
659 | //"w leisure=sports_centre poly_sport\n" |
660 | "w leisure=stadium poly_sports_stadium\n" |
661 | //"w leisure=track poly_sports_track\n" |
662 | "w leisure=water_park poly_water_park\n" |
663 | "w military=airfield poly_airfield\n" |
664 | "w military=barracks poly_barracks\n" |
665 | "w military=danger_area poly_danger_area\n" |
666 | "w military=naval_base poly_naval_base\n" |
667 | "w military=range poly_range\n" |
668 | "w natural=beach poly_beach\n" |
669 | // "w natural=coastline water_line\n" --> in coastline map |
670 | "w natural=fell poly_fell\n" |
671 | "w natural=glacier poly_glacier\n" |
672 | "w natural=heath poly_heath\n" |
673 | "w natural=land poly_land\n" |
674 | "w natural=marsh poly_marsh\n" |
675 | "w natural=mud poly_mud\n" |
676 | "w natural=scree poly_scree\n" |
677 | "w natural=scrub poly_scrub\n" |
678 | "w natural=water poly_water\n" |
679 | "w natural=wood poly_wood\n" |
680 | //"w piste:type=downhill,piste:difficulty=advanced piste_downhill_advanced\n" |
681 | //"w piste:type=downhill,piste:difficulty=easy piste_downhill_easy\n" |
682 | //"w piste:type=downhill,piste:difficulty=expert piste_downhill_expert\n" |
683 | //"w piste:type=downhill,piste:difficulty=freeride piste_downhill_freeride\n" |
684 | //"w piste:type=downhill,piste:difficulty=intermediate piste_downhill_intermediate\n" |
685 | //"w piste:type=downhill,piste:difficulty=novice piste_downhill_novice\n" |
686 | //"w piste:type=nordic piste_nordic\n" |
687 | "w place=suburb poly_place1\n" |
688 | "w place=hamlet poly_place2\n" |
689 | "w place=village poly_place3\n" |
690 | "w place=municipality poly_place4\n" |
691 | "w place=town poly_place5\n" |
692 | "w place=city poly_place6\n" |
693 | //"w power=line powerline\n" |
694 | //"w railway=abandoned rail_abandoned\n" |
695 | //"w railway=disused rail_disused\n" |
696 | "w railway=light_rail rail_light\n" |
697 | "w railway=monorail rail_mono\n" |
698 | "w railway=narrow_gauge rail_narrow_gauge\n" |
699 | //"w railway=preserved rail_preserved\n" |
700 | "w railway=rail rail\n" |
701 | "w railway=subway rail_subway\n" |
702 | "w railway=tram rail_tram\n" |
703 | "w route=ferry ferry\n" |
704 | //"w route=ski piste_nordic\n" |
705 | //"w sport=* poly_sport\n" |
706 | "w tourism=artwork poly_artwork\n" |
707 | "w tourism=attraction poly_attraction\n" |
708 | "w tourism=camp_site poly_camp_site\n" |
709 | "w tourism=caravan_site poly_caravan_site\n" |
710 | "w tourism=picnic_site poly_picnic_site\n" |
711 | "w tourism=theme_park poly_theme_park\n" |
712 | "w tourism=zoo poly_zoo\n" |
713 | "w waterway=canal water_canal\n" |
714 | "w waterway=drain water_drain\n" |
715 | "w waterway=river water_river\n" |
716 | "w waterway=riverbank poly_water\n" |
717 | "w waterway=stream water_stream\n" |
718 | "w barrier=ditch ditch\n" |
719 | "w barrier=hedge hedge\n" |
720 | "w barrier=fence fence\n" |
721 | "w barrier=wall wall\n" |
722 | "w barrier=retaining_wall retaining_wall\n" |
723 | "w barrier=city_wall city_wall\n" }; |
724 | |
725 | static void build_attrmap_line(char *line) |
726 | { |
727 | char *t = NULL, *kvl = NULL, *i = NULL, *p, *kv; |
728 | struct attr_mapping *attr_mapping = g_malloc0(sizeof(struct attr_mapping)); |
729 | int idx, attr_mapping_count = 0; |
730 | t = line; |
731 | p = strchr(t, '\t'); |
732 | if (p) |
733 | { |
734 | while (*p == '\t') |
735 | *p++ = '\0'; |
736 | kvl = p; |
737 | p = strchr(kvl, '\t'); |
738 | } |
739 | if (p) |
740 | { |
741 | while (*p == '\t') |
742 | *p++ = '\0'; |
743 | i = p; |
744 | } |
745 | if (t[0] == 'w') |
746 | { |
747 | if (!i) |
748 | i = "street_unkn"; |
749 | } |
750 | else |
751 | { |
752 | if (!i) |
753 | i = "point_unkn"; |
754 | } |
755 | |
756 | attr_mapping->type = item_from_name(i); |
757 | |
758 | if (!attr_mapping->type) |
759 | { |
760 | printf("no id found for '%s'\n", i); |
761 | } |
762 | |
763 | while ((kv = strtok(kvl, ","))) |
764 | { |
765 | kvl = NULL; |
766 | if (!(idx = (int) (long) g_hash_table_lookup(attr_hash, kv))) |
767 | { |
768 | idx = attr_present_count++; |
769 | g_hash_table_insert(attr_hash, kv, (gpointer) (long) idx); |
770 | } |
771 | attr_mapping = g_realloc(attr_mapping, sizeof(struct attr_mapping) + (attr_mapping_count + 1) * sizeof(int)); |
772 | attr_mapping->attr_present_idx[attr_mapping_count++] = idx; |
773 | attr_mapping->attr_present_idx_count = attr_mapping_count; |
774 | } |
775 | if (t[0] == 'w') |
776 | { |
777 | attr_mapping_way = g_realloc(attr_mapping_way, sizeof(*attr_mapping_way) * (attr_mapping_way_count + 1)); |
778 | attr_mapping_way[attr_mapping_way_count++] = attr_mapping; |
779 | } |
780 | if (t[0] == '?' && doway2poi) |
781 | { |
782 | attr_mapping_way2poi = g_realloc(attr_mapping_way2poi, sizeof(*attr_mapping_way2poi) * (attr_mapping_way2poi_count + 1)); |
783 | attr_mapping_way2poi[attr_mapping_way2poi_count++] = attr_mapping; |
784 | } |
785 | if (t[0] != 'w') |
786 | { |
787 | attr_mapping_node = g_realloc(attr_mapping_node, sizeof(*attr_mapping_node) * (attr_mapping_node_count + 1)); |
788 | attr_mapping_node[attr_mapping_node_count++] = attr_mapping; |
789 | } |
790 | |
791 | } |
792 | |
793 | static void build_attrmap(FILE* rule_file) |
794 | { |
795 | attr_hash = g_hash_table_new(g_str_hash, g_str_equal); |
796 | attr_present_count = 1; |
797 | |
798 | // build attribute map from rule file if given |
799 | if (rule_file) |
800 | { |
801 | char buffer[200], *p; |
802 | while (fgets(buffer, 200, rule_file)) |
803 | { |
804 | p = strchr(buffer, '\n'); |
805 | if (p) |
806 | *p = 0; |
807 | build_attrmap_line(g_strdup(buffer)); |
808 | } |
809 | fclose(rule_file); |
810 | } |
811 | // use hardcoded default attributes |
812 | else |
813 | { |
814 | char *p, *map; |
815 | if (border_only_map == 1) |
816 | { |
817 | map = g_strdup(attrmap_bo); |
818 | } |
819 | else if (coastline_only_map == 1) |
820 | { |
821 | map = g_strdup(attrmap_cl); |
822 | } |
823 | else |
824 | { |
825 | map = g_strdup(attrmap_normal); |
826 | } |
827 | |
828 | while (map) |
829 | { |
830 | p = strchr(map, '\n'); |
831 | if (p) |
832 | *p++ = '\0'; |
833 | |
834 | if (strlen(map)) |
835 | build_attrmap_line(map); |
836 | |
837 | map = p; |
838 | } |
839 | } |
840 | |
841 | attr_present = g_malloc0(sizeof(*attr_present) * attr_present_count); |
842 | } |
843 | |
844 | static void build_countrytable(void) |
845 | { |
846 | int i; |
847 | char *names, *str, *tok; |
848 | country_table_hash = g_hash_table_new(g_str_hash, g_str_equal); |
849 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
850 | { |
851 | names = g_strdup(country_table[i].names); |
852 | str = names; |
853 | while ((tok = strtok(str, ","))) |
854 | { |
855 | str = NULL; |
856 | g_hash_table_insert(country_table_hash, tok, (gpointer) & country_table[i]); |
857 | } |
858 | } |
859 | } |
860 | |
861 | int string_endswith2(const char* ending, const char* instring) |
862 | { |
863 | int l1; |
864 | int l2; |
865 | |
866 | if (!ending) |
867 | { |
868 | return 0; |
869 | } |
870 | |
871 | if (!instring) |
872 | { |
873 | return 0; |
874 | } |
875 | |
876 | l1 = strlen(ending); |
877 | l2 = strlen(instring); |
878 | |
879 | if (l1 < 1) |
880 | { |
881 | return 0; |
882 | } |
883 | |
884 | if (l1 > l2) |
885 | { |
886 | return 0; |
887 | } |
888 | |
889 | int ret = strcmp(ending, instring + (l2 - l1)); |
890 | //dbg(0, "ending=%s in=%s ret=%d\n", ending, instring + (l2 - l1), (ret == 0)); |
891 | return (ret == 0); |
892 | } |
893 | |
894 | |
895 | void osm_warning(char *type, long long id, int cont, char *fmt, ...) |
896 | { |
897 | char str[4096]; |
898 | va_list ap; |
899 | va_start(ap, fmt); |
900 | vsnprintf(str, sizeof(str), fmt, ap); |
901 | va_end(ap); |
902 | if (verbose_mode) fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Warning:",type,id,str); |
903 | } |
904 | |
905 | void osm_info(char *type, long long id, int cont, char *fmt, ...) |
906 | { |
907 | char str[4096]; |
908 | va_list ap; |
909 | va_start(ap, fmt); |
910 | vsnprintf(str, sizeof(str), fmt, ap); |
911 | va_end(ap); |
912 | if (verbose_mode) fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Info:",type,id,str); |
913 | } |
914 | |
915 | static void attr_strings_clear(void) |
916 | { |
917 | alt_name_found = 0; |
918 | real_alt_name_found = 0; |
919 | attr_strings_buffer_len = 0; |
920 | memset(attr_strings, 0, sizeof(attr_strings)); |
921 | } |
922 | |
923 | static void attr_strings_save(enum attr_strings id, char *str) |
924 | { |
925 | attr_strings[id] = attr_strings_buffer + attr_strings_buffer_len; |
926 | strcpy(attr_strings[id], str); |
927 | attr_strings_buffer_len += strlen(str) + 1; |
928 | } |
929 | |
930 | long long item_bin_get_nodeid(struct item_bin *ib) |
931 | { |
932 | long long *ret = item_bin_get_attr(ib, attr_osm_nodeid, NULL); |
933 | if (ret) |
934 | { |
935 | return *ret; |
936 | } |
937 | return 0; |
938 | } |
939 | |
940 | long long item_bin_get_wayid(struct item_bin *ib) |
941 | { |
942 | long long *ret = item_bin_get_attr(ib, attr_osm_wayid, NULL); |
943 | if (ret) |
944 | { |
945 | return *ret; |
946 | } |
947 | return 0; |
948 | } |
949 | |
950 | long long item_bin_get_relationid(struct item_bin *ib) |
951 | { |
952 | long long *ret = item_bin_get_attr(ib, attr_osm_relationid, NULL); |
953 | if (ret) |
954 | { |
955 | return *ret; |
956 | } |
957 | return 0; |
958 | } |
959 | |
960 | long long item_bin_get_id(struct item_bin *ib) |
961 | { |
962 | long long ret; |
963 | if (ib->type < 0x80000000) |
964 | { |
965 | return item_bin_get_nodeid(ib); |
966 | } |
967 | ret = item_bin_get_wayid(ib); |
968 | if (!ret) |
969 | { |
970 | ret = item_bin_get_relationid(ib); |
971 | } |
972 | return ret; |
973 | } |
974 | |
975 | static int node_is_tagged; |
976 | static void relation_add_tag(char *k, char *v); |
977 | osmid get_waynode_num_have_seekpos(osmid way_id, int coord_num, int local_thread_num, off_t seek_pos); |
978 | |
979 | |
980 | static int access_value(char *v) |
981 | { |
982 | if (!strcmp(v, "1")) |
983 | return 1; |
984 | if (!strcmp(v, "yes")) |
985 | return 1; |
986 | if (!strcmp(v, "designated")) |
987 | return 1; |
988 | if (!strcmp(v, "official")) |
989 | return 1; |
990 | if (!strcmp(v, "permissive")) |
991 | return 1; |
992 | if (!strcmp(v, "0")) |
993 | return 2; |
994 | if (!strcmp(v, "no")) |
995 | return 2; |
996 | if (!strcmp(v, "agricultural")) |
997 | return 2; |
998 | if (!strcmp(v, "forestry")) |
999 | return 2; |
1000 | if (!strcmp(v, "private")) |
1001 | return 2; |
1002 | if (!strcmp(v, "delivery")) |
1003 | return 2; |
1004 | if (!strcmp(v, "destination")) |
1005 | return 2; |
1006 | return 3; |
1007 | } |
1008 | |
1009 | void osm_add_tag(char *k, char *v) |
1010 | { |
1011 | int idx, level = 2; |
1012 | char buffer[BUFFER_SIZE * 2 + 2]; |
1013 | |
1014 | if (in_relation) |
1015 | { |
1016 | relation_add_tag(k, v); |
1017 | return; |
1018 | } |
1019 | |
1020 | if (!strcmp(k, "ele")) |
1021 | level = 9; |
1022 | |
1023 | if (!strcmp(k, "time")) |
1024 | level = 9; |
1025 | |
1026 | if (!strcmp(k, "created_by")) |
1027 | level = 9; |
1028 | |
1029 | if (!strncmp(k, "tiger:", 6) || !strcmp(k, "AND_nodes")) |
1030 | level = 9; |
1031 | |
1032 | if (!strcmp(k, "converted_by") || !strcmp(k, "source")) |
1033 | level = 8; |
1034 | |
1035 | if (!strncmp(k, "osmarender:", 11) || !strncmp(k, "svg:", 4)) |
1036 | level = 8; |
1037 | |
1038 | if (!strcmp(k, "layer")) |
1039 | level = 7; |
1040 | |
1041 | if (!strcasecmp(v, "true") || !strcasecmp(v, "yes")) |
1042 | v = "1"; |
1043 | |
1044 | if (!strcasecmp(v, "false") || !strcasecmp(v, "no")) |
1045 | v = "0"; |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | if (!strcmp(k, "oneway")) |
1052 | { |
1053 | if (!strcmp(v, "1")) |
1054 | { |
1055 | flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT_VALID; |
1056 | } |
1057 | |
1058 | if (!strcmp(v, "-1")) |
1059 | { |
1060 | flags[0] |= NAVIT_AF_ONEWAYREV | NAVIT_AF_ROUNDABOUT_VALID; |
1061 | } |
1062 | |
1063 | if (!in_way) |
1064 | { |
1065 | level = 6; |
1066 | } |
1067 | else |
1068 | { |
1069 | level = 5; |
1070 | } |
1071 | } |
1072 | |
1073 | if (!strcmp(k, "cycleway")) |
1074 | { |
1075 | if (!strcmp(v, "opposite")) |
1076 | { |
1077 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_NO; |
1078 | } |
1079 | if (!strcmp(v, "opposite_lane")) |
1080 | { |
1081 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_NO; |
1082 | } |
1083 | |
1084 | if (!in_way) |
1085 | { |
1086 | level = 6; |
1087 | } |
1088 | else |
1089 | { |
1090 | level = 5; |
1091 | } |
1092 | } |
1093 | |
1094 | |
1095 | if (!strcmp(k, "bicycle:oneway")) |
1096 | { |
1097 | if (!strcmp(v, "0")) |
1098 | { |
1099 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_NO; |
1100 | } |
1101 | if (!strcmp(v, "1")) |
1102 | { |
1103 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_YES; |
1104 | } |
1105 | |
1106 | if (!in_way) |
1107 | { |
1108 | level = 6; |
1109 | } |
1110 | else |
1111 | { |
1112 | level = 5; |
1113 | } |
1114 | } |
1115 | |
1116 | if (!strcmp(k, "oneway:bicycle")) |
1117 | { |
1118 | if (!strcmp(v, "0")) |
1119 | { |
1120 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_NO; |
1121 | } |
1122 | if (!strcmp(v, "1")) |
1123 | { |
1124 | flags[0] |= NAVIT_AF_ONEWAY_BICYCLE_YES; |
1125 | } |
1126 | |
1127 | if (!in_way) |
1128 | { |
1129 | level = 6; |
1130 | } |
1131 | else |
1132 | { |
1133 | level = 5; |
1134 | } |
1135 | } |
1136 | |
1137 | |
1138 | /* |
1139 | blue: cycleway=lane + oneway=yes |
1140 | blue: cycleway=lane + oneway=yes + bicycle=yes |
1141 | |
1142 | xxxx: cycleway=opposite_lane + cycleway:left=lane + oneway=yes |
1143 | xxxx: bicycle=yes + cycleway:right=lane + oneway=yes |
1144 | xxxx: cycleway:left=track + cycleway:right=lane + oneway=yes + oneway:bicycle=no |
1145 | xxxx: cycleway:left=share_busway + cycleway:right=lane + oneway=yes + oneway:bicycle=no |
1146 | |
1147 | dots: cycleway=track + oneway=yes |
1148 | dots: cycleway=track |
1149 | |
1150 | xxxx: cycleway:left=track + oneway=yes |
1151 | xxxx: cycleway:right=track + oneway=yes |
1152 | |
1153 | xxxx: cycleway:right=track |
1154 | xxxx: cycleway:right=track + cycleway:right:oneway=no |
1155 | */ |
1156 | |
1157 | if (!strcmp(k, "cycleway")) |
1158 | { |
1159 | if (!strcmp(v, "track")) |
1160 | { |
1161 | flags[0] |= NAVIT_AF_BICYCLE_TRACK; |
1162 | } |
1163 | |
1164 | if (!in_way) |
1165 | { |
1166 | level = 6; |
1167 | } |
1168 | else |
1169 | { |
1170 | level = 5; |
1171 | } |
1172 | } |
1173 | |
1174 | |
1175 | |
1176 | /* |
1177 | cycleway=lane |
1178 | cycleway:right=lane |
1179 | cycleway:left=lane |
1180 | |
1181 | cycleway=opposite_lane |
1182 | cycleway:left=opposite_lane |
1183 | cycleway:right=opposite_lane |
1184 | */ |
1185 | |
1186 | if (!strcmp(k, "cycleway")) |
1187 | { |
1188 | if (!strcmp(v, "lane")) |
1189 | { |
1190 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
1191 | } |
1192 | else if (!strcmp(v, "opposite_lane")) |
1193 | { |
1194 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
1195 | } |
1196 | |
1197 | if (!in_way) |
1198 | { |
1199 | level = 6; |
1200 | } |
1201 | else |
1202 | { |
1203 | level = 5; |
1204 | } |
1205 | } |
1206 | |
1207 | |
1208 | if (!strcmp(k, "cycleway:left")) |
1209 | { |
1210 | if (!strcmp(v, "lane")) |
1211 | { |
1212 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
1213 | } |
1214 | else if (!strcmp(v, "opposite_lane")) |
1215 | { |
1216 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
1217 | } |
1218 | |
1219 | if (!in_way) |
1220 | { |
1221 | level = 6; |
1222 | } |
1223 | else |
1224 | { |
1225 | level = 5; |
1226 | } |
1227 | } |
1228 | |
1229 | if (!strcmp(k, "cycleway:right")) |
1230 | { |
1231 | if (!strcmp(v, "lane")) |
1232 | { |
1233 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
1234 | } |
1235 | else if (!strcmp(v, "opposite_lane")) |
1236 | { |
1237 | flags[0] |= NAVIT_AF_BICYCLE_LANE; |
1238 | } |
1239 | |
1240 | if (!in_way) |
1241 | { |
1242 | level = 6; |
1243 | } |
1244 | else |
1245 | { |
1246 | level = 5; |
1247 | } |
1248 | } |
1249 | |
1250 | |
1251 | |
1252 | |
1253 | if (!strcmp(k, "junction")) |
1254 | { |
1255 | if (!strcmp(v, "roundabout")) |
1256 | flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT | NAVIT_AF_ROUNDABOUT_VALID; |
1257 | } |
1258 | |
1259 | if (!strcmp(k, "maxspeed")) |
1260 | { |
1261 | if (strstr(v, "mph")) |
1262 | { |
1263 | maxspeed_attr_value = (int) floor(atof(v) * 1.609344); |
1264 | } |
1265 | else |
1266 | { |
1267 | maxspeed_attr_value = atoi(v); |
1268 | } |
1269 | |
1270 | if (maxspeed_attr_value) |
1271 | |
1272 | flags[0] |= NAVIT_AF_SPEED_LIMIT; |
1273 | level = 5; |
1274 | } |
1275 | if (!strcmp(k, "toll")) |
1276 | { |
1277 | if (!strcmp(v, "1")) |
1278 | { |
1279 | flags[0] |= NAVIT_AF_TOLL; |
1280 | } |
1281 | } |
1282 | if (!strcmp(k, "access")) |
1283 | { |
1284 | 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; |
1285 | level = 5; |
1286 | } |
1287 | if (!strcmp(k, "vehicle")) |
1288 | { |
1289 | 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; |
1290 | level = 5; |
1291 | } |
1292 | if (!strcmp(k, "motorvehicle")) |
1293 | { |
1294 | 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; |
1295 | level = 5; |
1296 | } |
1297 | if (!strcmp(k, "bicycle")) |
1298 | { |
1299 | flags[access_value(v)] |= NAVIT_AF_BIKE; |
1300 | level = 5; |
1301 | } |
1302 | if (!strcmp(k, "foot")) |
1303 | { |
1304 | flags[access_value(v)] |= NAVIT_AF_PEDESTRIAN; |
1305 | level = 5; |
1306 | } |
1307 | if (!strcmp(k, "horse")) |
1308 | { |
1309 | flags[access_value(v)] |= NAVIT_AF_HORSE; |
1310 | level = 5; |
1311 | } |
1312 | if (!strcmp(k, "moped")) |
1313 | { |
1314 | flags[access_value(v)] |= NAVIT_AF_MOPED; |
1315 | level = 5; |
1316 | } |
1317 | if (!strcmp(k, "motorcycle")) |
1318 | { |
1319 | flags[access_value(v)] |= NAVIT_AF_MOTORCYCLE; |
1320 | level = 5; |
1321 | } |
1322 | if (!strcmp(k, "motorcar")) |
1323 | { |
1324 | flags[access_value(v)] |= NAVIT_AF_CAR; |
1325 | level = 5; |
1326 | } |
1327 | if (!strcmp(k, "hov")) |
1328 | { |
1329 | flags[access_value(v)] |= NAVIT_AF_HIGH_OCCUPANCY_CAR; |
1330 | level = 5; |
1331 | } |
1332 | if (!strcmp(k, "bus")) |
1333 | { |
1334 | flags[access_value(v)] |= NAVIT_AF_PUBLIC_BUS; |
1335 | level = 5; |
1336 | } |
1337 | if (!strcmp(k, "taxi")) |
1338 | { |
1339 | flags[access_value(v)] |= NAVIT_AF_TAXI; |
1340 | level = 5; |
1341 | } |
1342 | if (!strcmp(k, "goods")) |
1343 | { |
1344 | flags[access_value(v)] |= NAVIT_AF_DELIVERY_TRUCK; |
1345 | level = 5; |
1346 | } |
1347 | if (!strcmp(k, "hgv")) |
1348 | { |
1349 | flags[access_value(v)] |= NAVIT_AF_TRANSPORT_TRUCK; |
1350 | level = 5; |
1351 | } |
1352 | if (!strcmp(k, "emergency")) |
1353 | { |
1354 | flags[access_value(v)] |= NAVIT_AF_EMERGENCY_VEHICLES; |
1355 | level = 5; |
1356 | } |
1357 | if (!strcmp(k, "hazmat")) |
1358 | { |
1359 | flags[access_value(v)] |= NAVIT_AF_DANGEROUS_GOODS; |
1360 | level = 5; |
1361 | } |
1362 | if (!strcmp(k, "tunnel") && !strcmp(v, "1")) |
1363 | { |
1364 | flags[0] |= NAVIT_AF_UNDERGROUND; |
1365 | } |
1366 | if (!strcmp(k, "bridge") && !strcmp(v, "1")) |
1367 | { |
1368 | flags[0] |= NAVIT_AF_BRIDGE; |
1369 | } |
1370 | |
1371 | if (!strcmp(k, "note")) |
1372 | { |
1373 | level = 5; |
1374 | } |
1375 | |
1376 | if (!strcmp(k, "name")) |
1377 | { |
1378 | attr_strings_save(attr_string_label, v); |
1379 | level = 5; |
1380 | } |
1381 | |
1382 | if (!strcmp(k, "capacity")) |
1383 | { |
1384 | attr_strings_save(attr_string_capacity, v); |
1385 | level = 5; |
1386 | } |
1387 | |
1388 | if (!strcmp(k, "alt_name")) |
1389 | { |
1390 | // alternative name for some places (is sometimes what people call it in the local area) |
1391 | attr_strings_save(attr_string_label_real_alt, v); |
1392 | real_alt_name_found = 1; |
1393 | level = 5; |
1394 | } |
1395 | |
1396 | if ((!strcmp(k, "int_name")) && (alt_name_found == 0)) |
1397 | { |
1398 | // only use "int_name" if we dont have "name:en" |
1399 | attr_strings_save(attr_string_label_alt, v); |
1400 | alt_name_found = 1; // lowest priority |
1401 | level = 5; |
1402 | } |
1403 | if (!strcmp(k, "name:en")) |
1404 | { |
1405 | attr_strings_save(attr_string_label_alt, v); |
1406 | alt_name_found = 2; // highest priority |
1407 | level = 5; |
1408 | } |
1409 | if (!strcmp(k, "addr:email")) |
1410 | { |
1411 | attr_strings_save(attr_string_email, v); |
1412 | level = 5; |
1413 | } |
1414 | if (!strcmp(k, "addr:housenumber")) |
1415 | { |
1416 | attr_strings_save(attr_string_house_number, v); |
1417 | level = 5; |
1418 | } |
1419 | if (!strcmp(k, "addr:street")) |
1420 | { |
1421 | attr_strings_save(attr_string_street_name, v); |
1422 | level = 5; |
1423 | } |
1424 | if (!strcmp(k, "colour")) |
1425 | { |
1426 | attr_strings_save(attr_string_colour_, v); |
1427 | level = 5; |
1428 | } |
1429 | if (!strcmp(k, "phone")) |
1430 | { |
1431 | attr_strings_save(attr_string_phone, v); |
1432 | level = 5; |
1433 | } |
1434 | if (!strcmp(k, "fax")) |
1435 | { |
1436 | attr_strings_save(attr_string_fax, v); |
1437 | level = 5; |
1438 | } |
1439 | if (!strcmp(k, "postal_code")) |
1440 | { |
1441 | attr_strings_save(attr_string_postal, v); |
1442 | level = 5; |
1443 | } |
1444 | if (!strcmp(k, "openGeoDB:postal_codes") && !attr_strings[attr_string_postal]) |
1445 | { |
1446 | attr_strings_save(attr_string_postal, v); |
1447 | level = 5; |
1448 | } |
1449 | if (!strcmp(k, "population")) |
1450 | { |
1451 | attr_strings_save(attr_string_population, v); |
1452 | level = 5; |
1453 | } |
1454 | if (!strcmp(k, "openGeoDB:population") && !attr_strings[attr_string_population]) |
1455 | { |
1456 | attr_strings_save(attr_string_population, v); |
1457 | level = 5; |
1458 | } |
1459 | if (!strcmp(k, "ref")) |
1460 | { |
1461 | if (in_way) |
1462 | { |
1463 | attr_strings_save(attr_string_street_name_systematic, v); |
1464 | } |
1465 | else |
1466 | { |
1467 | attr_strings_save(attr_string_ref, v); |
1468 | } |
1469 | level = 5; |
1470 | } |
1471 | if (! strcmp(k,"nat_ref")) |
1472 | { |
1473 | if (in_way) |
1474 | { |
1475 | attr_strings_save(attr_string_street_name_systematic_nat, v); |
1476 | //fprintf(stderr, "XYZ123!?:nat_ref=%s\n", v); |
1477 | } |
1478 | level=5; |
1479 | } |
1480 | if (! strcmp(k,"int_ref")) |
1481 | { |
1482 | if (in_way) |
1483 | { |
1484 | attr_strings_save(attr_string_street_name_systematic_int, v); |
1485 | //fprintf(stderr, "XYZ123!?:int_ref=%s\n", v); |
1486 | } |
1487 | level=5; |
1488 | } |
1489 | if (! strcmp(k,"destination:lanes")) |
1490 | { |
1491 | if (in_way) |
1492 | { |
1493 | attr_strings_save(attr_string_street_destination_lanes, v); |
1494 | //fprintf(stderr, "XYZ123!?:destination:lanes=%s\n", v); |
1495 | } |
1496 | level=5; |
1497 | } |
1498 | if (! strcmp(k,"destination")) |
1499 | { |
1500 | if (in_way) |
1501 | { |
1502 | attr_strings_save(attr_string_street_destination, v); |
1503 | //fprintf(stderr, "XYZ123!?:destination=%s\n", v); |
1504 | } |
1505 | level=5; |
1506 | } |
1507 | if (! strcmp(k,"exit_to")) |
1508 | { |
1509 | attr_strings_save(attr_string_exit_to, v); |
1510 | //fprintf(stderr, "XYZ123!?:exit_to=%s\n", v); |
1511 | level=5; |
1512 | } |
1513 | if (!strcmp(k, "openGeoDB:is_in")) |
1514 | { |
1515 | if (!is_in_buffer[0]) |
1516 | { |
1517 | strcpy(is_in_buffer, v); |
1518 | } |
1519 | level = 5; |
1520 | } |
1521 | if (!strcmp(k, "is_in")) |
1522 | { |
1523 | if (!is_in_buffer[0]) |
1524 | { |
1525 | strcpy(is_in_buffer, v); |
1526 | } |
1527 | level = 5; |
1528 | } |
1529 | if (!strcmp(k, "is_in:country")) |
1530 | { |
1531 | /** |
1532 | * Sometimes there is no is_in tag, only is_in:country. |
1533 | * I put this here so it can be overwritten by the previous if clause if there IS an is_in tag. |
1534 | */ |
1535 | strcpy(is_in_buffer, v); |
1536 | level = 5; |
1537 | } |
1538 | if (!strcmp(k, "place_county")) |
1539 | { |
1540 | /** |
1541 | * Ireland uses the place_county OSM tag to describe what county a town is in. |
1542 | * This would be equivalent to is_in: Town; Locality; Country |
1543 | * A real world example would be Node: Moycullen (52234625) |
1544 | * The tag is processed as Moycullen; Galway; Ireland |
1545 | * where Galway is the county |
1546 | */ |
1547 | strcpy(is_in_buffer, "Ireland"); |
1548 | attr_strings_save(attr_string_county_name, v); |
1549 | level = 5; |
1550 | } |
1551 | if (!strcmp(k, "gnis:ST_alpha")) |
1552 | { |
1553 | /* assume a gnis tag means it is part of the USA: |
1554 | http://en.wikipedia.org/wiki/Geographic_Names_Information_System |
1555 | many US towns do not have is_in tags |
1556 | */ |
1557 | strcpy(is_in_buffer, "USA"); |
1558 | level = 5; |
1559 | } |
1560 | |
1561 | if (!strcmp(k, "turn:lanes")) |
1562 | { |
1563 | if (in_way) |
1564 | { |
1565 | attr_strings_save(attr_string_street_turn_lanes, v); |
1566 | //fprintf(stderr, "XYZ123!?:turn:lanes=%s\n", v); |
1567 | } |
1568 | level = 5; |
1569 | } |
1570 | |
1571 | |
1572 | if (!strcmp(k, "lanes:forward")) |
1573 | { |
1574 | if (in_way) |
1575 | { |
1576 | attr_strings_save(attr_string_street_lanes_forward, v); |
1577 | //fprintf(stderr, "XYZ123!?:lanes:forward=%s\n", v); |
1578 | } |
1579 | level = 5; |
1580 | } |
1581 | |
1582 | if (!strcmp(k, "lanes")) |
1583 | { |
1584 | if (in_way) |
1585 | { |
1586 | attr_strings_save(attr_string_street_lanes, v); |
1587 | //fprintf(stderr, "XYZ123!?:lanes=%s\n", v); |
1588 | } |
1589 | level = 5; |
1590 | } |
1591 | |
1592 | |
1593 | if (attr_debug_level >= level) |
1594 | { |
1595 | int bytes_left = sizeof(debug_attr_buffer) - strlen(debug_attr_buffer) - 1; |
1596 | if (bytes_left > 0) |
1597 | { |
1598 | snprintf(debug_attr_buffer + strlen(debug_attr_buffer), bytes_left, " %s=%s", k, v); |
1599 | debug_attr_buffer[sizeof(debug_attr_buffer) - 1] = '\0'; |
1600 | node_is_tagged = 1; |
1601 | } |
1602 | } |
1603 | |
1604 | if (level < 6) |
1605 | { |
1606 | node_is_tagged = 1; |
1607 | } |
1608 | |
1609 | strcpy(buffer, "*=*"); |
1610 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1611 | { |
1612 | attr_present[idx] = 1; |
1613 | } |
1614 | |
1615 | sprintf(buffer, "%s=*", k); |
1616 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1617 | { |
1618 | attr_present[idx] = 2; |
1619 | } |
1620 | |
1621 | sprintf(buffer, "*=%s", v); |
1622 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1623 | { |
1624 | attr_present[idx] = 2; |
1625 | } |
1626 | |
1627 | sprintf(buffer, "%s=%s", k, v); |
1628 | if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer))) |
1629 | { |
1630 | attr_present[idx] = 4; |
1631 | } |
1632 | } |
1633 | |
1634 | int coord_count; |
1635 | |
1636 | static void extend_buffer(struct buffer *b) |
1637 | { |
1638 | b->malloced += b->malloced_step; |
1639 | b->base = realloc(b->base, (size_t) b->malloced); |
1640 | |
1641 | if (b->base == NULL) |
1642 | { |
1643 | fprintf(stderr, "realloc of "LONGLONG_FMT" bytes failed\n", (size_t) b->malloced); |
1644 | exit(1); |
1645 | } |
1646 | |
1647 | if (verbose_mode) fprintf(stderr, "extend_buffer: "LONGLONG_FMT" bytes\n", (size_t) b->malloced); |
1648 | } |
1649 | |
1650 | osmid nodeid_last; |
1651 | GHashTable *way_hash, *waytag_hash; |
1652 | cfuhash_table_t *way_hash_cfu = NULL; |
1653 | |
1654 | typedef struct dummy_cfuhash_entry |
1655 | { |
1656 | long long key; |
1657 | int data; |
1658 | struct dummy_cfuhash_entry *next; |
1659 | } dummy_cfuhash_entry; |
1660 | |
1661 | static void node_buffer_to_hash(int local_thread_num) |
1662 | { |
1663 | if (verbose_mode) |
1664 | { |
1665 | fprintf(stderr, "node_buffer_to_hash t:%d nb->size:%lu\n", local_thread_num, node_buffer[local_thread_num].size); |
1666 | fprintf(stderr, "node_buffer_to_hash t:%d nb->base:%lu\n", local_thread_num, node_buffer[local_thread_num].base); |
1667 | fprintf(stderr, "node_buffer_to_hash t:%d nh:%p\n", local_thread_num, node_hash[local_thread_num]); |
1668 | } |
1669 | |
1670 | int i = 0; |
1671 | int count2 = node_buffer[local_thread_num].size / sizeof(struct node_item); |
1672 | struct node_item *ni = (struct node_item *) node_buffer[local_thread_num].base; |
1673 | |
1674 | #if 0 |
1675 | fprintf(stderr, "[THREAD] #%d fill hash node: count=%d size=%d\n", local_thread_num, count2, sizeof(dummy_cfuhash_entry)); |
1676 | #endif |
1677 | |
1678 | struct dummy_dummy_entry |
1679 | { |
1680 | long long key; |
1681 | int value_ptr; |
1682 | }; |
1683 | |
1684 | fprintf_(stderr, "[THREAD] #%d fill hash node: count=%d size=%d\n", local_thread_num, count2, sizeof(struct dummy_dummy_entry)); |
1685 | |
1686 | for (i = 0; i < count2; i++) |
1687 | { |
1688 | /* |
1689 | if (i % 5000) |
1690 | { |
1691 | } |
1692 | */ |
1693 | |
1694 | // fprintf_(stderr, "thread #%d fill #%d/%d\n", local_thread_num, i, count2); |
1695 | |
1696 | // g_hash_table_insert(node_hash[local_thread_num], (gpointer) (long) (ni[i].id), (gpointer) (long) i); |
1697 | //cfuhash_put(node_hash_cfu[local_thread_num], &(long long)ni[i].id, xxx); |
1698 | |
1699 | #if 0 |
1700 | //fprintf(stderr, "node id:%lld i:%d\n", (long long)ni[i].id, i); |
1701 | cfuhash_put_data(node_hash_cfu[local_thread_num], (long long)ni[i].id, sizeof(long long), i, sizeof(int), NULL); |
1702 | #endif |
1703 | |
1704 | // fprintf(stderr, "node id:%lld mem:%p\n", (long long)ni->id, ni); |
1705 | quick_hash_add_entry(node_hash_cfu[local_thread_num], (long long)ni[i].id, i); |
1706 | // ni++; |
1707 | } |
1708 | |
1709 | // fprintf_(stderr, "thread #%d node_buffer_to_hash ready\n", local_thread_num); |
1710 | |
1711 | if (verbose_mode) |
1712 | { |
1713 | fprintf(stderr, "node_buffer_to_hash ready\n"); |
1714 | } |
1715 | } |
1716 | |
1717 | static void waytag_buffer_to_hash(void) |
1718 | { |
1719 | int i, count = waytag_buffer.size / sizeof(struct way_tag); |
1720 | struct way_tag *wt = (struct way_tag *) waytag_buffer.base; |
1721 | for (i = 0; i < count; i++) |
1722 | { |
1723 | // fprintf(stderr, "waytag_hash insert:%lu %lu\n", (long) (wt[i].way_id), (long) i); |
1724 | g_hash_table_insert(waytag_hash, (gpointer) (long) (wt[i].way_id), (gpointer) (long) i); |
1725 | } |
1726 | } |
1727 | |
1728 | static struct node_item *ni; |
1729 | |
1730 | void init_node_hash(int threads, int clear) |
1731 | { |
1732 | int i; |
1733 | for (i = 0; i < threads; i++) |
1734 | { |
1735 | //if (clear) |
1736 | //{ |
1737 | //*node_hash[i] = NULL; |
1738 | //} |
1739 | //else |
1740 | //{ |
1741 | //*node_hash[i] = g_hash_table_new(NULL, NULL); |
1742 | //} |
1743 | #if 0 |
1744 | node_hash_cfu[i] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
1745 | cfuhash_set_flag(node_hash_cfu[i], CFUHASH_FROZEN); |
1746 | #endif |
1747 | node_hash_cfu[i] = quick_hash_init(CFUHASH_BUCKETS_NODES); |
1748 | } |
1749 | } |
1750 | |
1751 | void fill_hash_node(int local_thread_num) |
1752 | { |
1753 | //fprintf(stderr, "001t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1754 | |
1755 | if (verbose_mode) |
1756 | { |
1757 | fprintf(stderr, "fill_hash_node - START\n"); |
1758 | } |
1759 | //if (node_hash[local_thread_num]) |
1760 | if (node_hash_cfu[local_thread_num]) |
1761 | { |
1762 | #if 0 |
1763 | //g_hash_table_destroy(node_hash[local_thread_num]); |
1764 | //node_hash[local_thread_num] = NULL; |
1765 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
1766 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
1767 | node_hash_cfu[local_thread_num] = NULL; |
1768 | #endif |
1769 | quick_hash_destroy(node_hash_cfu[local_thread_num]); |
1770 | node_hash_cfu[local_thread_num] = NULL; |
1771 | } |
1772 | |
1773 | #if 0 |
1774 | // node_hash[local_thread_num] = g_hash_table_new(NULL, NULL); |
1775 | node_hash_cfu[local_thread_num] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES); |
1776 | cfuhash_set_flag(node_hash_cfu[local_thread_num], CFUHASH_FROZEN); |
1777 | #endif |
1778 | node_hash_cfu[local_thread_num] = quick_hash_init(CFUHASH_BUCKETS_NODES); |
1779 | |
1780 | |
1781 | //fprintf(stderr, "002t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1782 | node_buffer_to_hash(local_thread_num); |
1783 | |
1784 | quick_hash_print_stats(node_hash_cfu[local_thread_num]); |
1785 | |
1786 | //fprintf(stderr, "003t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1787 | if (verbose_mode) |
1788 | { |
1789 | fprintf(stderr, "fill_hash_node - END\n"); |
1790 | } |
1791 | } |
1792 | |
1793 | void flush_nodes(int final, int local_thread_num) |
1794 | { |
1795 | save_buffer("coords.tmp", &node_buffer[local_thread_num], slices * slice_size); |
1796 | //fprintf(stderr, "004t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1797 | |
1798 | if (verbose_mode) |
1799 | { |
1800 | fprintf(stderr, "flush_nodes %d\n", final); |
1801 | } |
1802 | |
1803 | if (!final) |
1804 | { |
1805 | //fprintf(stderr, "005t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1806 | node_buffer[local_thread_num].size = 0; |
1807 | //fprintf(stderr, "006t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1808 | |
1809 | //if (node_hash[local_thread_num]) |
1810 | if (node_hash_cfu[local_thread_num]) |
1811 | { |
1812 | if (verbose_mode) fprintf(stderr,"node_hash size="LONGLONG_FMT"\n", g_hash_table_size (node_hash[local_thread_num])); |
1813 | #if 0 |
1814 | //g_hash_table_destroy(node_hash[local_thread_num]); |
1815 | //node_hash[local_thread_num] = NULL; |
1816 | cfuhash_clear(node_hash_cfu[local_thread_num]); |
1817 | cfuhash_destroy(node_hash_cfu[local_thread_num]); |
1818 | node_hash_cfu[local_thread_num] = NULL; |
1819 | #endif |
1820 | quick_hash_destroy(node_hash_cfu[local_thread_num]); |
1821 | node_hash_cfu[local_thread_num] = NULL; |
1822 | } |
1823 | } |
1824 | |
1825 | if (verbose_mode) fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer[local_thread_num].size); |
1826 | if (verbose_mode) fprintf(stderr,"node: node_buffer malloced="LONGLONG_FMT"\n", node_buffer[local_thread_num].malloced); |
1827 | //fprintf(stderr, "007t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]); |
1828 | |
1829 | slices++; |
1830 | } |
1831 | |
1832 | |
1833 | |
1834 | inline double transform_to_geo_lat(int y) |
1835 | { |
1836 | /* ZZ GEO TRANS ZZ */ |
1837 | return TO_GEO_LAT_(y); |
1838 | } |
1839 | |
1840 | inline double transform_to_geo_lon(int x) |
1841 | { |
1842 | /* ZZ GEO TRANS ZZ */ |
1843 | return TO_GEO_LON_(x); |
1844 | } |
1845 | |
1846 | inline int transform_from_geo_lat(double lat) |
1847 | { |
1848 | /* ZZ GEO TRANS ZZ */ |
1849 | return FROM_GEO_LAT_(lat); |
1850 | } |
1851 | |
1852 | inline int transform_from_geo_lon(double lon) |
1853 | { |
1854 | /* ZZ GEO TRANS ZZ */ |
1855 | return FROM_GEO_LON_(lon); |
1856 | } |
1857 | |
1858 | void osm_add_node(osmid id, double lat, double lon) |
1859 | { |
1860 | in_node = 1; |
1861 | if (node_buffer[0].size + sizeof(struct node_item) > node_buffer[0].malloced) |
1862 | { |
1863 | extend_buffer(&node_buffer[0]); |
1864 | } |
1865 | attr_strings_clear(); |
1866 | node_is_tagged = 0; |
1867 | nodeid = id; |
1868 | item.type = type_point_unkn; |
1869 | debug_attr_buffer[0] = '\0'; |
1870 | is_in_buffer[0] = '\0'; |
1871 | debug_attr_buffer[0] = '\0'; |
1872 | osmid_attr.type = attr_osm_nodeid; |
1873 | osmid_attr.len = 3; |
1874 | osmid_attr_value = id; |
1875 | if (node_buffer[0].size + sizeof(struct node_item) > slice_size) |
1876 | { |
1877 | flush_nodes(0, 0); |
1878 | } |
1879 | ni = (struct node_item *) (node_buffer[0].base + node_buffer[0].size); |
1880 | ni->id = id; |
1881 | ni->ref_node = 0; |
1882 | ni->ref_way = 0; |
1883 | ni->ref_ref = 0; |
1884 | ni->dummy = 0; |
1885 | |
1886 | // fprintf(stderr, "NNDD:000:%f %f\n", lat, lon); |
1887 | |
1888 | /* ZZ GEO TRANS ZZ */ |
1889 | ni->c.x = FROM_GEO_LON_(lon); |
1890 | ni->c.y = FROM_GEO_LAT_(lat); |
1891 | /* ZZ GEO TRANS ZZ */ |
1892 | |
1893 | // fprintf(stderr, "NNDD:002:%d %d\n", ni->c.x, ni->c.y); |
1894 | |
1895 | |
1896 | // save values ----- |
1897 | save_node_lat = lat; |
1898 | save_node_lon = lon; |
1899 | // save values ----- |
1900 | |
1901 | |
1902 | #ifdef MAPTOOL_USE_SQL |
1903 | |
1904 | if (sql_counter2 == 0) |
1905 | { |
1906 | sqlite3_exec(sql_handle002a, "BEGIN", 0, 0, 0); |
1907 | sqlite3_exec(sql_handle003a, "BEGIN", 0, 0, 0); |
1908 | sqlite3_exec(sql_handle002b, "BEGIN", 0, 0, 0); |
1909 | sqlite3_exec(sql_handle003b, "BEGIN", 0, 0, 0); |
1910 | } |
1911 | sql_counter2++; |
1912 | |
1913 | #ifdef MAPTOOL_SPLIT_NODE_DB |
1914 | if (nodeid % 2) |
1915 | { |
1916 | if ((nodeid & MAPTOOL_SPLIT_NODE_BIT) > 0) |
1917 | { |
1918 | sqlite3_bind_int64(stmt_node__2a, 1, nodeid); |
1919 | sqlite3_bind_double(stmt_node__2a, 2, lat); |
1920 | sqlite3_bind_double(stmt_node__2a, 3, lon); |
1921 | sqlite3_step(stmt_node__2a); |
1922 | sqlite3_reset(stmt_node__2a); |
1923 | } |
1924 | else |
1925 | { |
1926 | sqlite3_bind_int64(stmt_node__2b, 1, nodeid); |
1927 | sqlite3_bind_double(stmt_node__2b, 2, lat); |
1928 | sqlite3_bind_double(stmt_node__2b, 3, lon); |
1929 | sqlite3_step(stmt_node__2b); |
1930 | sqlite3_reset(stmt_node__2b); |
1931 | } |
1932 | } |
1933 | else |
1934 | { |
1935 | if ((nodeid & MAPTOOL_SPLIT_NODE_BIT) > 0) |
1936 | { |
1937 | #endif |
1938 | sqlite3_bind_int64(stmt_nodea, 1, nodeid); |
1939 | sqlite3_bind_double(stmt_nodea, 2, lat); |
1940 | sqlite3_bind_double(stmt_nodea, 3, lon); |
1941 | sqlite3_step(stmt_nodea); |
1942 | sqlite3_reset(stmt_nodea); |
1943 | #ifdef MAPTOOL_SPLIT_NODE_DB |
1944 | } |
1945 | else |
1946 | { |
1947 | sqlite3_bind_int64(stmt_nodeb, 1, nodeid); |
1948 | sqlite3_bind_double(stmt_nodeb, 2, lat); |
1949 | sqlite3_bind_double(stmt_nodeb, 3, lon); |
1950 | sqlite3_step(stmt_nodeb); |
1951 | sqlite3_reset(stmt_nodeb); |
1952 | } |
1953 | } |
1954 | #endif |
1955 | |
1956 | if (sql_counter2 > MAX_ROWS_WO_COMMIT) |
1957 | { |
1958 | sql_counter2 = 0; |
1959 | sqlite3_exec(sql_handle002a, "COMMIT", 0, 0, 0); |
1960 | sqlite3_exec(sql_handle003a, "COMMIT", 0, 0, 0); |
1961 | sqlite3_exec(sql_handle002b, "COMMIT", 0, 0, 0); |
1962 | sqlite3_exec(sql_handle003b, "COMMIT", 0, 0, 0); |
1963 | //fprintf(stderr, "SQL: COMMIT\n"); |
1964 | } |
1965 | |
1966 | #endif |
1967 | |
1968 | //fprintf(stderr,"node: %d %d\n", ni->c.x, ni->c.y); |
1969 | //fprintf(stderr,"node: %f %f\n", lat, lon); |
1970 | |
1971 | |
1972 | node_buffer[0].size += sizeof(struct node_item); |
1973 | //fprintf(stderr,"node: inc node_buffer by %d\n", sizeof(struct node_item)); |
1974 | //fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer.size); |
1975 | |
1976 | #if 0 |
1977 | //if (!node_hash[0]) |
1978 | if (!node_hash_cfu[0]) |
1979 | { |
1980 | if (ni->id > nodeid_last) |
1981 | { |
1982 | nodeid_last = ni->id; |
1983 | } |
1984 | else |
1985 | { |
1986 | //fprintf(stderr,"INFO: Nodes out of sequence (new %d vs old %d), adding hash\n", ni->id, nodeid_last); |
1987 | //node_hash[0] = g_hash_table_new(NULL, NULL); |
1988 | |
1989 | node_hash_cfu[0] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_OTHER); |
1990 | cfuhash_set_flag(node_hash_cfu[0], CFUHASH_FROZEN); |
1991 | |
1992 | node_buffer_to_hash(0); |
1993 | } |
1994 | } |
1995 | //else if (!g_hash_table_lookup(node_hash[0], (gpointer) (long) (ni->id))) |
1996 | // else if (!cfuhash_exists(node_hash_cfu[0], (long long) ni->id )) |
1997 | |
1998 | else if (!cfuhash_exists_data(node_hash_cfu[0], (long long) ni->id, sizeof(long long))) |
1999 | { |
2000 | //g_hash_table_insert(node_hash[0], (gpointer) (long) (ni->id), (gpointer) (long) (ni - (struct node_item *) node_buffer[0].base)); |
2001 | //cfuhash_put(node_hash_cfu[0], (gpointer)ni->id, (gpointer)(long) (ni - (struct node_item *) node_buffer[0].base) ); |
2002 | 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); |
2003 | |
2004 | } |
2005 | else |
2006 | { |
2007 | node_buffer[0].size -= sizeof(struct node_item); |
2008 | if (verbose_mode) |
2009 | fprintf(stderr, "node: Decr. node_buffer by %d\n", sizeof(struct node_item)); |
2010 | if (verbose_mode) fprintf(stderr,"node: node_buffer size="LONGLONG_FMT"\n", node_buffer[0].size); |
2011 | nodeid = 0; |
2012 | } |
2013 | #endif |
2014 | |
2015 | } |
2016 | |
2017 | void clear_node_item_buffer(void) |
2018 | { |
2019 | int j, count = node_buffer[0].size / sizeof(struct node_item); |
2020 | struct node_item *ni = (struct node_item *) (node_buffer[0].base); |
2021 | for (j = 0; j < count; j++) |
2022 | { |
2023 | ni[j].ref_way = 0; |
2024 | } |
2025 | } |
2026 | |
2027 | static struct node_item * |
2028 | node_item_get_fast(osmid id, int local_thread_num) |
2029 | { |
2030 | #if 1 |
2031 | int i; |
2032 | //void *p_tmp; |
2033 | //int rr; |
2034 | //size_t data_size2 = sizeof(int); |
2035 | struct node_item *ni = (struct node_item *) (node_buffer[local_thread_num].base); |
2036 | #endif |
2037 | |
2038 | //if (node_hash[local_thread_num]) |
2039 | if (node_hash_cfu[local_thread_num]) |
2040 | { |
2041 | #if 0 |
2042 | //p_tmp = (gpointer)(g_hash_table_lookup(node_hash[local_thread_num], (gpointer) (long) id)); |
2043 | rr = cfuhash_get_data(node_hash_cfu[local_thread_num], (long long) id, sizeof(long long), &p_tmp, &data_size2); |
2044 | if (rr == 1) |
2045 | { |
2046 | //fprintf(stderr, "got key=%lld value=%d\n", (long long) id, p_tmp); |
2047 | i = p_tmp; |
2048 | return ni + i; |
2049 | } |
2050 | #endif |
2051 | |
2052 | //struct node_item *ni = quick_hash_lookup(node_hash_cfu[local_thread_num], id); |
2053 | //fprintf(stderr, "got key=%lld value=%p\n", (long long)id, ni); |
2054 | //if (ni) |
2055 | //{ |
2056 | // fprintf(stderr, "x=%d y=%d\n", ni->c.x, ni->c.y); |
2057 | //} |
2058 | i = quick_hash_lookup(node_hash_cfu[local_thread_num], id); |
2059 | if (i != -1) |
2060 | { |
2061 | return ni + i; // move pointer "i" number of items forward |
2062 | } |
2063 | |
2064 | //if (p_tmp != NULL) |
2065 | //{ |
2066 | // // only if node is found in hash! |
2067 | // i = (int) (long) (p_tmp); |
2068 | // return ni + i; |
2069 | //} |
2070 | } |
2071 | return NULL; |
2072 | } |
2073 | |
2074 | static int load_node(FILE *coords, int p, struct node_item *ret) |
2075 | { |
2076 | fseek(coords, p * sizeof(struct node_item), SEEK_SET); |
2077 | if (fread(ret, sizeof(*ret), 1, coords) != 1) |
2078 | { |
2079 | fprintf(stderr, "read failed\n"); |
2080 | return 0; |
2081 | } |
2082 | return 1; |
2083 | } |
2084 | |
2085 | static osmid first_node_of_current_way; |
2086 | |
2087 | void osm_add_way(osmid id) |
2088 | { |
2089 | static osmid wayid_last; |
2090 | |
2091 | in_way = 1; |
2092 | wayid = id; |
2093 | coord_count = 0; |
2094 | attr_strings_clear(); |
2095 | item.type = type_street_unkn; |
2096 | debug_attr_buffer[0] = '\0'; |
2097 | maxspeed_attr_value = 0; |
2098 | flags_attr_value = 0; |
2099 | memset(flags, 0, sizeof(flags)); |
2100 | debug_attr_buffer[0] = '\0'; |
2101 | osmid_attr_value = id; |
2102 | |
2103 | if (wayid < wayid_last && !way_hash_cfu) |
2104 | { |
2105 | if (verbose_mode) |
2106 | { |
2107 | fprintf(stderr, "INFO: Ways out of sequence (new %d vs old %d), adding hash\n", wayid, wayid_last); |
2108 | } |
2109 | // way_hash = g_hash_table_new(NULL, NULL); |
2110 | way_hash_cfu = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_WAYS); |
2111 | cfuhash_set_flag(way_hash_cfu, CFUHASH_FROZEN); |
2112 | |
2113 | } |
2114 | wayid_last = wayid; |
2115 | } |
2116 | |
2117 | char relation_type[BUFFER_SIZE]; |
2118 | char iso_code[BUFFER_SIZE]; |
2119 | int admin_level; |
2120 | int boundary; |
2121 | |
2122 | void osm_add_relation(osmid id) |
2123 | { |
2124 | current_id = id; |
2125 | in_relation = 1; |
2126 | debug_attr_buffer[0] = '\0'; |
2127 | relation_type[0] = '\0'; |
2128 | iso_code[0] = '\0'; |
2129 | admin_level = -1; |
2130 | boundary = 0; |
2131 | |
2132 | // zero out buffer ----------------------- |
2133 | // bzero(item_bin_2, MAX_ITEMBIN_BYTES_); |
2134 | // zero out buffer ----------------------- |
2135 | |
2136 | item_bin_init(item_bin_2, type_none); |
2137 | item_bin_add_attr_longlong(item_bin_2, attr_osm_relationid, current_id); |
2138 | } |
2139 | |
2140 | static int country_id_from_iso2(char *iso) |
2141 | { |
2142 | int ret = 0; |
2143 | if (iso) |
2144 | { |
2145 | // make uppercase |
2146 | int i99; |
2147 | for (i99 = 0; iso[i99]; i99++) |
2148 | { |
2149 | iso[i99] = toupper(iso[i99]); |
2150 | } |
2151 | struct country_search *search; |
2152 | struct attr country_iso2, country_id; |
2153 | struct item *item; |
2154 | country_iso2.type = attr_country_iso2; |
2155 | country_iso2.u.str = iso; |
2156 | search = country_search_new(&country_iso2, 0); |
2157 | if ((item = country_search_get_item(search)) && item_attr_get(item, attr_country_id, &country_id)) |
2158 | { |
2159 | ret = country_id.u.num; |
2160 | if (debug_itembin(3)) |
2161 | { |
2162 | fprintf(stderr, "country id(1)=%d\n", ret); |
2163 | } |
2164 | } |
2165 | else |
2166 | { |
2167 | if (debug_itembin(3)) |
2168 | { |
2169 | fprintf(stderr, "country id(2)=%d\n", ret); |
2170 | } |
2171 | } |
2172 | country_search_destroy(search); |
2173 | } |
2174 | return ret; |
2175 | } |
2176 | |
2177 | struct country_table *country_from_countryid(int id) |
2178 | { |
2179 | int i; |
2180 | for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++) |
2181 | { |
2182 | //if (debug_itembin(3)) |
2183 | //{ |
2184 | // fprintf(stderr,"== country_from_countryid: %d ==\n", country_table[i].countryid); |
2185 | //} |
2186 | |
2187 | if (country_table[i].countryid == id) |
2188 | { |
2189 | return &country_table[i]; |
2190 | } |
2191 | } |
2192 | |
2193 | //if (debug_itembin(3)) |
2194 | //{ |
2195 | // fprintf(stderr,"== country_from_countryid: return NULL ==\n"); |
2196 | //} |
2197 | |
2198 | return NULL; |
2199 | } |
2200 | |
2201 | struct country_table * |
2202 | country_from_iso2(char *iso) |
2203 | { |
2204 | return country_from_countryid(country_id_from_iso2(iso)); |
2205 | } |
2206 | |
2207 | static int get_relation_member(char *str, struct relation_member *memb) |
2208 | { |
2209 | int len; |
2210 | sscanf(str,"%d:"LONGLONG_FMT":%n",&memb->type,&memb->id,&len); |
2211 | memb->role = str + len; |
2212 | return 1; |
2213 | } |
2214 | |
2215 | #if 0 |
2216 | void report(io, markers, reporttriangles, reportneighbors, reportsegments, reportedges, reportnorms) |
2217 | struct triangulateio *io;int markers;int reporttriangles;int reportneighbors;int reportsegments;int reportedges;int reportnorms; |
2218 | { |
2219 | int i, j; |
2220 | |
2221 | for (i = 0; i < io->numberofpoints; i++) |
2222 | { |
2223 | fprintf(stderr, "Point %4d:", i); |
2224 | for (j = 0; j < 2; j++) |
2225 | { |
2226 | fprintf(stderr, " %.6g", io->pointlist[i * 2 + j]); |
2227 | } |
2228 | if (io->numberofpointattributes > 0) |
2229 | { |
2230 | fprintf(stderr, " attributes"); |
2231 | } |
2232 | for (j = 0; j < io->numberofpointattributes; j++) |
2233 | { |
2234 | fprintf(stderr, " %.6g", io->pointattributelist[i * io->numberofpointattributes + j]); |
2235 | } |
2236 | if (markers) |
2237 | { |
2238 | fprintf(stderr, " marker %d\n", io->pointmarkerlist[i]); |
2239 | } |
2240 | else |
2241 | { |
2242 | fprintf(stderr, "\n"); |
2243 | } |
2244 | } |
2245 | fprintf(stderr, "\n"); |
2246 | |
2247 | if (reporttriangles || reportneighbors) |
2248 | { |
2249 | for (i = 0; i < io->numberoftriangles; i++) |
2250 | { |
2251 | if (reporttriangles) |
2252 | { |
2253 | fprintf(stderr, "Triangle %4d points:", i); |
2254 | for (j = 0; j < io->numberofcorners; j++) |
2255 | { |
2256 | fprintf(stderr, " %4d", io->trianglelist[i * io->numberofcorners + j]); |
2257 | } |
2258 | if (io->numberoftriangleattributes > 0) |
2259 | { |
2260 | fprintf(stderr, " attributes"); |
2261 | } |
2262 | for (j = 0; j < io->numberoftriangleattributes; j++) |
2263 | { |
2264 | fprintf(stderr, " %.6g", io->triangleattributelist[i * io->numberoftriangleattributes + j]); |
2265 | } |
2266 | fprintf(stderr, "\n"); |
2267 | } |
2268 | if (reportneighbors) |
2269 | { |
2270 | fprintf(stderr, "Triangle %4d neighbors:", i); |
2271 | for (j = 0; j < 3; j++) |
2272 | { |
2273 | fprintf(stderr, " %4d", io->neighborlist[i * 3 + j]); |
2274 | } |
2275 | fprintf(stderr, "\n"); |
2276 | } |
2277 | } |
2278 | fprintf(stderr, "\n"); |
2279 | } |
2280 | |
2281 | if (reportsegments) |
2282 | { |
2283 | for (i = 0; i < io->numberofsegments; i++) |
2284 | { |
2285 | fprintf(stderr, "Segment %4d points:", i); |
2286 | for (j = 0; j < 2; j++) |
2287 | { |
2288 | fprintf(stderr, " %4d", io->segmentlist[i * 2 + j]); |
2289 | } |
2290 | if (markers) |
2291 | { |
2292 | fprintf(stderr, " marker %d\n", io->segmentmarkerlist[i]); |
2293 | } |
2294 | else |
2295 | { |
2296 | fprintf(stderr, "\n"); |
2297 | } |
2298 | } |
2299 | fprintf(stderr, "\n"); |
2300 | } |
2301 | |
2302 | if (reportedges) |
2303 | { |
2304 | for (i = 0; i < io->numberofedges; i++) |
2305 | { |
2306 | fprintf(stderr, "Edge %4d points:", i); |
2307 | for (j = 0; j < 2; j++) |
2308 | { |
2309 | fprintf(stderr, " %4d", io->edgelist[i * 2 + j]); |
2310 | } |
2311 | if (reportnorms && (io->edgelist[i * 2 + 1] == -1)) |
2312 | { |
2313 | for (j = 0; j < 2; j++) |
2314 | { |
2315 | fprintf(stderr, " %.6g", io->normlist[i * 2 + j]); |
2316 | } |
2317 | } |
2318 | if (markers) |
2319 | { |
2320 | fprintf(stderr, " marker %d\n", io->edgemarkerlist[i]); |
2321 | } |
2322 | else |
2323 | { |
2324 | fprintf(stderr, "\n"); |
2325 | } |
2326 | } |
2327 | fprintf(stderr, "\n"); |
2328 | } |
2329 | } |
2330 | |
2331 | #endif |
2332 | |
2333 | void get_lat_lon_for_node(long long nd, struct node_lat_lon *node); |
2334 | |
2335 | void get_lat_lon_way_first_node(long long way_id, struct node_lat_lon *node) |
2336 | { |
2337 | int rc2; |
2338 | sqlite3_stmt *st; |
2339 | long long nd = 0; |
2340 | |
2341 | |
2342 | node->valid = 0; |
2343 | |
2344 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
2345 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
2346 | { |
2347 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
2348 | { |
2349 | #endif |
2350 | st = stmt_sel001; |
2351 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
2352 | } |
2353 | else |
2354 | { |
2355 | st = stmt_sel001b; |
2356 | } |
2357 | } |
2358 | else |
2359 | { |
2360 | if ((way_id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
2361 | { |
2362 | st = stmt_sel001__2; |
2363 | } |
2364 | else |
2365 | { |
2366 | st = stmt_sel001__2b; |
2367 | } |
2368 | } |
2369 | #endif |
2370 | sqlite3_bind_int64(st, 1, way_id); |
2371 | |
2372 | // execute the statement |
2373 | rc2 = sqlite3_step(st); |
2374 | switch (rc2) |
2375 | { |
2376 | case SQLITE_DONE: |
2377 | break; |
2378 | case SQLITE_ROW: |
2379 | nd = sqlite3_column_int64(st, 0); |
2380 | break; |
2381 | default: |
2382 | fprintf(stderr, "Error: %d\n", rc2); |
2383 | break; |
2384 | } |
2385 | sqlite3_reset(st); |
2386 | // sqlite3_finalize(st); |
2387 | |
2388 | if (nd != 0) |
2389 | { |
2390 | get_lat_lon_for_node(nd, node); |
2391 | } |
2392 | } |
2393 | |
2394 | void get_lat_lon_for_node(long long nd, struct node_lat_lon *node) |
2395 | { |
2396 | int rc2; |
2397 | |
2398 | // now read the coords of this node |
2399 | node->valid = 0; |
2400 | |
2401 | #ifdef MAPTOOL_USE_SQL |
2402 | |
2403 | #ifdef MAPTOOL_SPLIT_NODE_DB |
2404 | if (nd % 2) |
2405 | { |
2406 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
2407 | { |
2408 | sqlite3_bind_int64(stmt_sel002__2a, 1, nd); |
2409 | } |
2410 | else |
2411 | { |
2412 | sqlite3_bind_int64(stmt_sel002__2b, 1, nd); |
2413 | } |
2414 | } |
2415 | else |
2416 | { |
2417 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
2418 | { |
2419 | #endif |
2420 | sqlite3_bind_int64(stmt_sel002a, 1, nd); |
2421 | #ifdef MAPTOOL_SPLIT_NODE_DB |
2422 | } |
2423 | else |
2424 | { |
2425 | sqlite3_bind_int64(stmt_sel002b, 1, nd); |
2426 | } |
2427 | } |
2428 | #endif |
2429 | |
2430 | rc2 = 0; |
2431 | //do |
2432 | //{ |
2433 | #ifdef MAPTOOL_SPLIT_NODE_DB |
2434 | if (nd % 2) |
2435 | { |
2436 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
2437 | { |
2438 | rc2 = sqlite3_step(stmt_sel002__2a); |
2439 | } |
2440 | else |
2441 | { |
2442 | rc2 = sqlite3_step(stmt_sel002__2b); |
2443 | } |
2444 | } |
2445 | else |
2446 | { |
2447 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
2448 | { |
2449 | #endif |
2450 | rc2 = sqlite3_step(stmt_sel002a); |
2451 | #ifdef MAPTOOL_SPLIT_NODE_DB |
2452 | } |
2453 | else |
2454 | { |
2455 | rc2 = sqlite3_step(stmt_sel002b); |
2456 | } |
2457 | } |
2458 | #endif |
2459 | //cols2 = sqlite3_column_count(stmt_sel002); |
2460 | switch (rc2) |
2461 | { |
2462 | //case SQLITE_DONE: |
2463 | // break; |
2464 | case SQLITE_ROW: |
2465 | |
2466 | #ifdef MAPTOOL_SPLIT_NODE_DB |
2467 | if (nd % 2) |
2468 | { |
2469 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
2470 | { |
2471 | node->lat = (double) sqlite3_column_double(stmt_sel002__2a, 0); |
2472 | node->lon = (double) sqlite3_column_double(stmt_sel002__2a, 1); |
2473 | } |
2474 | else |
2475 | { |
2476 | node->lat = (double) sqlite3_column_double(stmt_sel002__2b, 0); |
2477 | node->lon = (double) sqlite3_column_double(stmt_sel002__2b, 1); |
2478 | } |
2479 | } |
2480 | else |
2481 | { |
2482 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
2483 | { |
2484 | #endif |
2485 | node->lat = (double) sqlite3_column_double(stmt_sel002a, 0); |
2486 | node->lon = (double) sqlite3_column_double(stmt_sel002a, 1); |
2487 | #ifdef MAPTOOL_SPLIT_NODE_DB |
2488 | } |
2489 | else |
2490 | { |
2491 | node->lat = (double) sqlite3_column_double(stmt_sel002b, 0); |
2492 | node->lon = (double) sqlite3_column_double(stmt_sel002b, 1); |
2493 | } |
2494 | } |
2495 | #endif |
2496 | node->valid = 1; |
2497 | break; |
2498 | default: |
2499 | fprintf(stderr, "get_lat_lon_for_node:SQL Error: %d nodeid:%lld\n", rc2, nd); |
2500 | break; |
2501 | } |
2502 | //} |
2503 | //while (rc2 == SQLITE_ROW); |
2504 | #ifdef MAPTOOL_SPLIT_NODE_DB |
2505 | if (nd % 2) |
2506 | { |
2507 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
2508 | { |
2509 | sqlite3_reset(stmt_sel002__2a); |
2510 | } |
2511 | else |
2512 | { |
2513 | sqlite3_reset(stmt_sel002__2b); |
2514 | } |
2515 | } |
2516 | else |
2517 | { |
2518 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
2519 | { |
2520 | #endif |
2521 | sqlite3_reset(stmt_sel002a); |
2522 | #ifdef MAPTOOL_SPLIT_NODE_DB |
2523 | } |
2524 | else |
2525 | { |
2526 | sqlite3_reset(stmt_sel002b); |
2527 | } |
2528 | } |
2529 | #endif |
2530 | #endif |
2531 | |
2532 | } |
2533 | |
2534 | void catch_signal(int param) |
2535 | { |
2536 | // fprintf (stderr, "Terminating program...\n"); |
2537 | fprintf(stderr, "****** got SIGSEGV ******\n"); |
2538 | THROW(MAPTOOL_00002_EXCEPTION); |
2539 | // exit(1); |
2540 | } |
2541 | |
2542 | struct way_and_endnodes |
2543 | { |
2544 | unsigned long long way_id; |
2545 | unsigned long long first_node_id; |
2546 | unsigned long long last_node_id; |
2547 | int reverse; |
2548 | int role; |
2549 | GList *nodes; |
2550 | }; |
2551 | |
2552 | // if same value -> 0 |
2553 | // otherwise -> 1 |
2554 | gint comp_func(gconstpointer item1, gconstpointer item2) |
2555 | { |
2556 | long long a; |
2557 | long long b; |
2558 | |
2559 | a = *((long long *) item1); |
2560 | b = *((long long *) item2); |
2561 | |
2562 | //fprintf(stderr," item1=%lld\n", a); |
2563 | //fprintf(stderr," item2=%lld\n", b); |
2564 | |
2565 | if (a == b) |
2566 | { |
2567 | return 0; |
2568 | } |
2569 | |
2570 | return 1; |
2571 | } |
2572 | |
2573 | // return 0 if item is not found in GList |
2574 | int glist_find_already_inside(GList* list, gconstpointer item) |
2575 | { |
2576 | if (g_list_find_custom(list, item, (GCompareFunc) comp_func) == NULL) |
2577 | { |
2578 | return 0; |
2579 | } |
2580 | return 1; |
2581 | } |
2582 | |
2583 | void osm_end_relation(struct maptool_osm *osm) |
2584 | { |
2585 | //fprintf(stderr, "XXX000\n"); |
2586 | |
2587 | struct item_bin *item_bin_tri; |
2588 | struct coord coord_tri; |
2589 | struct node_lat_lon node_coords; |
2590 | int i9; |
2591 | int j9; |
2592 | int tmp9; |
2593 | |
2594 | int save_relation = 0; |
2595 | int save_relations_other_method = 0; |
2596 | int tag_id = 1; |
2597 | char *str = NULL; |
2598 | int triangulate_not_done = 1; |
2599 | int problem = 0; |
2600 | struct relation_member memb; |
2601 | struct relation_member memb2; |
2602 | struct way_and_endnodes *way_nodes1; |
2603 | struct way_and_endnodes *way_nodes2; |
2604 | int found_new_way = 0; |
2605 | gpointer *gptr; |
2606 | int rc = 0; |
2607 | int rc2 = 0; |
2608 | int cols; |
2609 | int col; |
2610 | int first_node_found = 0; |
2611 | long long nd; |
2612 | long long first_nd; |
2613 | long long search_nd; |
2614 | long long *ndptr; |
2615 | |
2616 | /* |
2617 | long lat_nd; |
2618 | long lon_nd; |
2619 | */ |
2620 | |
2621 | double lat_nd; |
2622 | double lon_nd; |
2623 | |
2624 | int number_of_points_in_poly = 0; |
2625 | int number_of_points_current_poly = 0; |
2626 | int exception = 0; |
2627 | int role_ = 0; |
2628 | |
2629 | double factor = 10000000; |
2630 | |
2631 | struct node_lat_lon* lat_lon_c; |
2632 | |
2633 | // triangulate vars |
2634 | #if 0 |
2635 | struct triangulateio in, mid, out, vorout; |
2636 | #endif |
2637 | |
2638 | #ifdef MAPTOOL_TRIANGULATE |
2639 | GPtrArray *current_points; |
2640 | GPtrArray *current_hole; |
2641 | P2tCDT *cdt; |
2642 | P2trCDT *rcdt; |
2643 | P2trRefiner *refiner; |
2644 | P2tTrianglePtrArray triangles; |
2645 | gint refine_max_steps = 1000; |
2646 | double x; |
2647 | double y; |
2648 | int i; |
2649 | int j; |
2650 | GHashTable *point_map; |
2651 | P2trCDT *rmesh; |
2652 | #endif |
2653 | GList *all_holes; |
2654 | |
2655 | int count_of_outer_ways = 0; |
2656 | |
2657 | GList *unsorted_outer_ways = NULL; |
2658 | GList *unsorted_inner_ways = NULL; |
2659 | GList *sorted_outer_ways = NULL; |
2660 | GList *temp_nodes_list = NULL; |
2661 | all_holes = NULL; |
2662 | |
2663 | // -- save relations for riverbanks -- |
2664 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_tag, str))) |
2665 | { |
2666 | |
2667 | if (!strcmp(str, "waterway=riverbank")) |
2668 | { |
2669 | // fprintf(stderr,"k:v=%s\n", str); |
2670 | save_relation = 1; |
2671 | save_relations_other_method = 0; |
2672 | tag_id = 1; |
2673 | } |
2674 | else if (!strcmp(str, "natural=water")) |
2675 | { |
2676 | save_relation = 1; |
2677 | save_relations_other_method = 0; |
2678 | tag_id = 2; |
2679 | } |
2680 | /* |
2681 | else if (!strcmp(str, "water=river")) |
2682 | { |
2683 | save_relation = 1; |
2684 | tag_id = 3; |
2685 | } |
2686 | */ |
2687 | else if (!strcmp(str, "natural=lake")) |
2688 | { |
2689 | save_relation = 1; |
2690 | save_relations_other_method = 0; |
2691 | tag_id = 4; |
2692 | } |
2693 | else if (!strcmp(str, "landuse=forest")) |
2694 | { |
2695 | // ------ DISABLED ------ |
2696 | // save_relation = 1; |
2697 | // save_relations_other_method = 1; |
2698 | // tag_id = 5; |
2699 | // ------ DISABLED ------ |
2700 | } |
2701 | else if (!strcmp(str, "natural=wood")) |
2702 | { |
2703 | // ------ DISABLED ------ |
2704 | // save_relation = 1; |
2705 | // save_relations_other_method = 1; |
2706 | // tag_id = 6; |
2707 | // ------ DISABLED ------ |
2708 | } |
2709 | else if (!strcmp(str, "building=yes")) |
2710 | { |
2711 | save_relation = 1; |
2712 | save_relations_other_method = 0; |
2713 | tag_id = 9; |
2714 | //fprintf(stderr,"k:v=%s id=%lld\n", str, current_id); |
2715 | } |
2716 | |
2717 | } |
2718 | |
2719 | if (save_relation == 1) |
2720 | { |
2721 | |
2722 | #ifdef MAPTOOL_TRIANGULATE |
2723 | |
2724 | if (save_relations_other_method == 0) |
2725 | { |
2726 | |
2727 | //fprintf(stderr, "START relation id=%lld tag=%d\n", current_id, tag_id); |
2728 | |
2729 | sqlite3_stmt *st; |
2730 | |
2731 | triangulate_not_done = 1; |
2732 | str = NULL; |
2733 | number_of_points_in_poly = 0; |
2734 | count_of_outer_ways = 0; |
2735 | //fprintf(stderr, "\n\n----------START---------\n"); |
2736 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
2737 | { |
2738 | if (get_relation_member(str, &memb)) |
2739 | { |
2740 | if (!strcmp(memb.role, "outer")) |
2741 | { |
2742 | if (memb.type == 2) |
2743 | { |
2744 | count_of_outer_ways++; |
2745 | } |
2746 | } |
2747 | } |
2748 | } |
2749 | //fprintf(stderr, "number of outer ways: %d\n", count_of_outer_ways); |
2750 | |
2751 | str = NULL; |
2752 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
2753 | { |
2754 | if (get_relation_member(str, &memb)) |
2755 | { |
2756 | role_=0; |
2757 | if (!strcmp(memb.role, "outer")) |
2758 | { |
2759 | role_=1; |
2760 | //fprintf(stderr, "1:role=%s id=%lld\n", memb.role, memb.id); |
2761 | } |
2762 | else if (!strcmp(memb.role, "inner")) |
2763 | { |
2764 | role_=2; |
2765 | //fprintf(stderr, "2:role=%s id=%lld\n", memb.role, memb.id); |
2766 | } |
2767 | |
2768 | if ((memb.type == 2) && ( (role_ == 1)||(role_ == 2) )) // use "outer" and "inner" ways |
2769 | { |
2770 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
2771 | way_nodes1->nodes = NULL; |
2772 | // get id for last and first nodes |
2773 | |
2774 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
2775 | if ((memb.id & MAPTOOL_SPLIT_WAYNODE_BIT) > 0) |
2776 | { |
2777 | if ((memb.id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
2778 | { |
2779 | #endif |
2780 | st = stmt_sel001; |
2781 | #ifdef MAPTOOL_SPLIT_WAYNODE_DB |
2782 | } |
2783 | else |
2784 | { |
2785 | st = stmt_sel001b; |
2786 | } |
2787 | } |
2788 | else |
2789 | { |
2790 | if ((memb.id & MAPTOOL_SPLIT_WAYNODE_BIT2) > 0) |
2791 | { |
2792 | st = stmt_sel001__2; |
2793 | } |
2794 | else |
2795 | { |
2796 | st = stmt_sel001__2b; |
2797 | } |
2798 | } |
2799 | #endif |
2800 | sqlite3_bind_int64(st, 1, memb.id); |
2801 | |
2802 | first_node_found = 0; |
2803 | way_nodes1->first_node_id = 0; |
2804 | nd = 0; |
2805 | number_of_points_current_poly = 0; |
2806 | // execute the statement |
2807 | do |
2808 | { |
2809 | rc = sqlite3_step(st); |
2810 | // cols = sqlite3_column_count(st); |
2811 | switch (rc) |
2812 | { |
2813 | case SQLITE_DONE: |
2814 | break; |
2815 | case SQLITE_ROW: |
2816 | nd = sqlite3_column_int64(st, 0); |
2817 | number_of_points_current_poly++; |
2818 | //fprintf(stderr, "------ %s = %d\n", sqlite3_column_name(st, 0), nd ? nd : "NULL"); |
2819 | if (first_node_found == 0) |
2820 | { |
2821 | way_nodes1->first_node_id = nd; |
2822 | way_nodes1->role = role_; |
2823 | first_node_found = 1; |
2824 | //fprintf(stderr, "------ first node found\n"); |
2825 | } |
2826 | ndptr = malloc(sizeof(long long)); |
2827 | *ndptr = nd; |
2828 | way_nodes1->nodes = g_list_append(way_nodes1->nodes, ndptr); |
2829 | break; |
2830 | default: |
2831 | fprintf(stderr, "Error: %d\n", rc); |
2832 | break; |
2833 | } |
2834 | } |
2835 | while (rc == SQLITE_ROW); |
2836 | |
2837 | // dont count the last node of each way |
2838 | number_of_points_current_poly--; |
2839 | |
2840 | sqlite3_reset(st); |
2841 | |
2842 | way_nodes1->last_node_id = nd; |
2843 | way_nodes1->way_id = memb.id; |
2844 | |
2845 | if (way_nodes1->last_node_id == 0) |
2846 | { |
2847 | if (way_nodes1->nodes) |
2848 | { |
2849 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
2850 | while (way_nodes1->nodes) |
2851 | { |
2852 | ndptr = way_nodes1->nodes->data; |
2853 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
2854 | g_free(ndptr); |
2855 | ndptr = NULL; |
2856 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
2857 | } |
2858 | } |
2859 | g_free(way_nodes1); |
2860 | } |
2861 | else if (way_nodes1->last_node_id == way_nodes1->first_node_id) |
2862 | { |
2863 | //fprintf(stderr, "ln id=%lld, fn id=%lld\n", way_nodes1->last_node_id, way_nodes1->first_node_id); |
2864 | |
2865 | if (way_nodes1->nodes) |
2866 | { |
2867 | if (role_ == 2) |
2868 | { |
2869 | //fprintf(stderr, "role=2\n"); |
2870 | unsorted_inner_ways = g_list_append(unsorted_inner_ways, way_nodes1); |
2871 | } |
2872 | else if (role_ == 1) |
2873 | { |
2874 | if (count_of_outer_ways == 1) |
2875 | { |
2876 | // we have only 1 outer way, it must be a closed loop. add it |
2877 | unsorted_outer_ways = g_list_append(unsorted_outer_ways, way_nodes1); |
2878 | number_of_points_in_poly = number_of_points_in_poly + number_of_points_current_poly; |
2879 | //fprintf(stderr, "w,sn,en %lld,%lld,%lld\n", way_nodes1->way_id, way_nodes1->first_node_id, way_nodes1->last_node_id); |
2880 | //fprintf(stderr, "num points=%d\n", number_of_points_current_poly); |
2881 | //fprintf(stderr, "SUM points=%d\n", number_of_points_in_poly); |
2882 | } |
2883 | else |
2884 | { |
2885 | // we have an outer way that is a loop (remove it) |
2886 | //fprintf(stderr, "remove node ... start\n"); |
2887 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
2888 | while (way_nodes1->nodes) |
2889 | { |
2890 | //fprintf(stderr, "remove node\n"); |
2891 | ndptr = way_nodes1->nodes->data; |
2892 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
2893 | g_free(ndptr); |
2894 | ndptr = NULL; |
2895 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
2896 | } |
2897 | g_free(way_nodes1); |
2898 | //fprintf(stderr, "remove node ... ready\n"); |
2899 | } |
2900 | } |
2901 | } |
2902 | } |
2903 | else |
2904 | { |
2905 | if (role_ == 1) |
2906 | { |
2907 | unsorted_outer_ways = g_list_append(unsorted_outer_ways, way_nodes1); |
2908 | number_of_points_in_poly = number_of_points_in_poly + number_of_points_current_poly; |
2909 | } |
2910 | //fprintf(stderr, "w,sn,en %lld,%lld,%lld\n", way_nodes1->way_id, way_nodes1->first_node_id, way_nodes1->last_node_id); |
2911 | //fprintf(stderr, "num points=%d\n", number_of_points_current_poly); |
2912 | //fprintf(stderr, "SUM points=%d\n", number_of_points_in_poly); |
2913 | } |
2914 | } |
2915 | } |
2916 | } |
2917 | |
2918 | // now sort ways to have a linked polygon |
2919 | if (unsorted_outer_ways) |
2920 | { |
2921 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
2922 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
2923 | way_nodes2 = (struct way_and_endnodes *) unsorted_outer_ways->data; |
2924 | way_nodes1->way_id = way_nodes2->way_id; |
2925 | //fprintf(stderr, "(START)way id=%llu\n", way_nodes1->way_id); |
2926 | way_nodes1->last_node_id = way_nodes2->last_node_id; |
2927 | way_nodes1->first_node_id = way_nodes2->first_node_id; |
2928 | // only copy over the pointer to the node list!! |
2929 | way_nodes1->nodes = way_nodes2->nodes; |
2930 | // first node is always in the right order |
2931 | way_nodes1->reverse = 0; |
2932 | |
2933 | gptr = unsorted_outer_ways->data; |
2934 | sorted_outer_ways = g_list_append(sorted_outer_ways, way_nodes1); |
2935 | // save the very first node of the poly |
2936 | first_nd = way_nodes1->first_node_id; |
2937 | // what node we want to find |
2938 | search_nd = way_nodes1->last_node_id; |
2939 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, gptr); |
2940 | g_free(gptr); |
2941 | gptr = NULL; |
2942 | |
2943 | //fprintf(stderr,"remaining=%d sorted=%d\n", g_list_length(unsorted_outer_ways), g_list_length(sorted_outer_ways)); |
2944 | } |
2945 | |
2946 | if (unsorted_outer_ways) |
2947 | { |
2948 | |
2949 | problem = 0; |
2950 | //fprintf(stderr, "start length unsorted_outer_ways=%d\n", g_list_length(unsorted_outer_ways)); |
2951 | |
2952 | while ((g_list_length(unsorted_outer_ways) > 0) && (problem == 0)) |
2953 | { |
2954 | //fprintf(stderr, "loop thru remaining ways 1\n"); |
2955 | |
2956 | // loop thru all the remaining ways |
2957 | found_new_way = 0; |
2958 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
2959 | while (unsorted_outer_ways) |
2960 | { |
2961 | //fprintf(stderr, "loop thru remaining ways 2 search=%lld\n", search_nd); |
2962 | |
2963 | if (unsorted_outer_ways->data) |
2964 | { |
2965 | way_nodes2 = (struct way_and_endnodes *) unsorted_outer_ways->data; |
2966 | if (way_nodes2->first_node_id == search_nd) |
2967 | { |
2968 | |
2969 | if (way_nodes2->last_node_id == first_nd) |
2970 | { |
2971 | if (g_list_length(unsorted_outer_ways) > 1) |
2972 | { |
2973 | // we have closed the poly, but there are still "ways" left |
2974 | // sounds broken |
2975 | problem = 1; |
2976 | break; |
2977 | } |
2978 | } |
2979 | |
2980 | // what node we want to find |
2981 | search_nd = way_nodes2->last_node_id; |
2982 | |
2983 | // now move the way from unsorted to sorted list |
2984 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
2985 | way_nodes1->way_id = way_nodes2->way_id; |
2986 | |
2987 | // ok next way found |
2988 | //fprintf(stderr, "(F)way id=%llu\n", way_nodes1->way_id); |
2989 | //fprintf(stderr, "now search id=%llu\n", search_nd); |
2990 | |
2991 | way_nodes1->last_node_id = way_nodes2->last_node_id; |
2992 | way_nodes1->first_node_id = way_nodes2->first_node_id; |
2993 | // only copy over the pointer to the node list!! |
2994 | way_nodes1->nodes = way_nodes2->nodes; |
2995 | // first node is always in the right order |
2996 | way_nodes1->reverse = 0; |
2997 | sorted_outer_ways = g_list_append(sorted_outer_ways, way_nodes1); |
2998 | if (unsorted_outer_ways) |
2999 | { |
3000 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
3001 | } |
3002 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, way_nodes2); |
3003 | g_free(way_nodes2); |
3004 | way_nodes2 = NULL; |
3005 | |
3006 | found_new_way = 1; |
3007 | //fprintf(stderr, "length unsorted_outer_ways=%d\n", g_list_length(unsorted_outer_ways)); |
3008 | break; |
3009 | } |
3010 | else if (way_nodes2->last_node_id == search_nd) |
3011 | { |
3012 | if (way_nodes2->first_node_id == first_nd) |
3013 | { |
3014 | if (g_list_length(unsorted_outer_ways) > 1) |
3015 | { |
3016 | // we have closed the poly, but there are still "ways" left |
3017 | // sounds broken |
3018 | problem = 1; |
3019 | break; |
3020 | } |
3021 | } |
3022 | |
3023 | // what node we want to find |
3024 | search_nd = way_nodes2->first_node_id; |
3025 | |
3026 | // now move the way from unsorted to sorted list |
3027 | way_nodes1 = (struct way_and_endnodes *) malloc(sizeof(struct way_and_endnodes)); |
3028 | way_nodes1->way_id = way_nodes2->way_id; |
3029 | |
3030 | // ok next way found |
3031 | //fprintf(stderr, "(R)way id=%llu\n", way_nodes1->way_id); |
3032 | //fprintf(stderr, "now search id=%llu\n", search_nd); |
3033 | |
3034 | way_nodes1->first_node_id = way_nodes2->last_node_id; |
3035 | way_nodes1->last_node_id = way_nodes2->first_node_id; |
3036 | // only copy over the pointer to the node list!! |
3037 | way_nodes1->nodes = way_nodes2->nodes; |
3038 | way_nodes1->nodes = g_list_reverse(way_nodes1->nodes); |
3039 | // first node is always in the right order |
3040 | way_nodes1->reverse = 1; |
3041 | sorted_outer_ways = g_list_append(sorted_outer_ways, way_nodes1); |
3042 | if (unsorted_outer_ways) |
3043 | { |
3044 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
3045 | } |
3046 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, way_nodes2); |
3047 | g_free(way_nodes2); |
3048 | way_nodes2 = NULL; |
3049 | |
3050 | found_new_way = 1; |
3051 | //fprintf(stderr, "length unsorted_outer_ways=%d\n", g_list_length(unsorted_outer_ways)); |
3052 | break; |
3053 | } |
3054 | } |
3055 | unsorted_outer_ways = g_list_next(unsorted_outer_ways); |
3056 | } |
3057 | //fprintf(stderr, "after while loop 2\n"); |
3058 | |
3059 | if (found_new_way == 0) |
3060 | { |
3061 | // some problem with this multipolygon |
3062 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3063 | fprintf_(stderr, "some problem with this multipolygon\n"); |
3064 | triangulate_not_done = 1; |
3065 | problem = 1; |
3066 | break; |
3067 | } |
3068 | } |
3069 | //fprintf(stderr, "after while loop 1\n"); |
3070 | |
3071 | } |
3072 | |
3073 | // now at last check if very first node matches the last found node |
3074 | // and less than xxx 1000 points in polygon |
3075 | // if ((search_nd == first_nd) && (number_of_points_in_poly > 2) && (number_of_points_in_poly < 1000)) |
3076 | if ((problem == 0) && ((search_nd == first_nd) && (number_of_points_in_poly > 2) && (number_of_points_in_poly < 30000))) |
3077 | { |
3078 | |
3079 | //fprintf(stderr, "in relation id=%lld\n", current_id); |
3080 | |
3081 | point_map = g_hash_table_new(g_direct_hash, g_direct_equal); |
3082 | current_points = g_ptr_array_new(); |
3083 | |
3084 | number_of_points_in_poly = 0; |
3085 | |
3086 | sorted_outer_ways = g_list_first(sorted_outer_ways); |
3087 | while (sorted_outer_ways) |
3088 | { |
3089 | if (sorted_outer_ways->data) |
3090 | { |
3091 | way_nodes1 = (struct way_and_endnodes *) sorted_outer_ways->data; |
3092 | // now read all the nodes of this way |
3093 | //**alread in GList** //sqlite3_bind_int64(stmt_sel001, 1, way_nodes1->way_id); |
3094 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
3095 | first_node_found = 0; |
3096 | while (way_nodes1->nodes) |
3097 | { |
3098 | ndptr = (long long *) way_nodes1->nodes->data; |
3099 | nd = *ndptr; |
3100 | |
3101 | get_lat_lon_for_node(nd, &node_coords); |
3102 | if (node_coords.valid == 1) |
3103 | { |
3104 | // lat |
3105 | lat_nd = node_coords.lat; |
3106 | // lon |
3107 | lon_nd = node_coords.lon; |
3108 | |
3109 | if (first_node_found == 0) |
3110 | { |
3111 | first_node_found = 1; |
3112 | } |
3113 | else |
3114 | { |
3115 | y = lat_nd * factor; |
3116 | x = lon_nd * factor; |
3117 | |
3118 | // ------ ok use this node and coords for triangulation ---- |
3119 | //fprintf(stderr, "nd,lat,lon %lld,%f,%f\n", nd,lat_nd,lon_nd); |
3120 | //fprintf(stderr, "x,y %f,%f\n", x, y); |
3121 | |
3122 | g_ptr_array_add(current_points, p2t_point_new_dd(x, y)); |
3123 | } |
3124 | } |
3125 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
3126 | } |
3127 | } |
3128 | //sqlite3_reset(st); |
3129 | |
3130 | sorted_outer_ways = g_list_next(sorted_outer_ways); |
3131 | } |
3132 | |
3133 | //fprintf(stderr, "after sorting ways\n"); |
3134 | |
3135 | |
3136 | exception = 0; |
3137 | |
3138 | TRY |
3139 | { |
3140 | // catch SIGSEGV !! |
3141 | signal(SIGSEGV, catch_signal); |
3142 | |
3143 | // alternate signal stack ------------ |
3144 | //ss.ss_size = SIGSTKSZ; |
3145 | //ss.ss_sp = stack; |
3146 | //sa.sa_handler = catch_signal; |
3147 | //sa.sa_flags = SA_ONSTACK; |
3148 | //sigfillset(&sa.sa_mask); |
3149 | |
3150 | //sigaltstack(&ss, 0); |
3151 | //sigfillset(&sa.sa_mask); |
3152 | //sigaction(SIGSEGV, &sa, 0); |
3153 | // alternate signal stack ------------ |
3154 | |
3155 | // catch SIGSEGV !! |
3156 | |
3157 | //fprintf(stderr, "In Try Statement (p2t_cdt_new)\n"); |
3158 | cdt = p2t_cdt_new(current_points); |
3159 | //fprintf(stderr, "all OK (p2t_cdt_new)\n"); |
3160 | } |
3161 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3162 | { |
3163 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3164 | fprintf_(stderr, "Got Exception 1!\n"); |
3165 | exception = 1; |
3166 | } |
3167 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3168 | { |
3169 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3170 | fprintf_(stderr, "Got segv Exception 1!\n"); |
3171 | exception = 1; |
3172 | } |
3173 | FINALLY |
3174 | { |
3175 | // set default |
3176 | signal (SIGSEGV, SIG_DFL); |
3177 | // set default |
3178 | |
3179 | //fprintf(stderr, "finally\n"); |
3180 | } |
3181 | ETRY; |
3182 | |
3183 | //fprintf(stderr, "after cdt_new\n"); |
3184 | |
3185 | GList* save = unsorted_inner_ways; |
3186 | |
3187 | int no_holes = 0; |
3188 | if (exception == 0) |
3189 | { |
3190 | |
3191 | // first run a check loop |
3192 | int number_of_nodes_in_this_way; |
3193 | int cur_node_count_in_way; |
3194 | unsorted_inner_ways = g_list_first(unsorted_inner_ways); |
3195 | |
3196 | int number_of_nodes_in_this_way3 = g_list_length(unsorted_inner_ways); |
3197 | //fprintf(stderr, "uiw 001.0 c=%d\n", number_of_nodes_in_this_way3); |
3198 | while (unsorted_inner_ways) |
3199 | { |
3200 | if ((unsorted_inner_ways->data)&&(no_holes == 0)) |
3201 | { |
3202 | way_nodes1 = (struct way_and_endnodes *) unsorted_inner_ways->data; |
3203 | number_of_nodes_in_this_way = g_list_length(way_nodes1->nodes); |
3204 | // now read all the nodes of this "hole"-way |
3205 | GList* save0 = way_nodes1->nodes; |
3206 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
3207 | first_node_found = 0; |
3208 | cur_node_count_in_way = 1; |
3209 | while (way_nodes1->nodes) |
3210 | { |
3211 | ndptr = (long long *) way_nodes1->nodes->data; |
3212 | // fprintf(stderr, "hole node:%lld\n", (long long)*ndptr); |
3213 | |
3214 | if (temp_nodes_list != NULL) |
3215 | { |
3216 | //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); |
3217 | // the last node should always be same as first node (for now we only support holes that dont span over multiple ways!) |
3218 | if (cur_node_count_in_way < number_of_nodes_in_this_way) |
3219 | { |
3220 | if (glist_find_already_inside(temp_nodes_list, ndptr) != 0) |
3221 | { |
3222 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3223 | fprintf_(stderr, "problem with hole!\n"); |
3224 | no_holes = 1; |
3225 | break; |
3226 | } |
3227 | else |
3228 | { |
3229 | //fprintf(stderr, "hole check ok\n"); |
3230 | } |
3231 | } |
3232 | } |
3233 | |
3234 | temp_nodes_list = g_list_append(temp_nodes_list, ndptr); |
3235 | |
3236 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
3237 | cur_node_count_in_way++; |
3238 | } |
3239 | way_nodes1->nodes = save0; |
3240 | } |
3241 | unsorted_inner_ways = g_list_next(unsorted_inner_ways); |
3242 | } |
3243 | |
3244 | } |
3245 | |
3246 | unsorted_inner_ways = save; |
3247 | |
3248 | //fprintf(stderr, "ex=%d nohole=%d\n", exception, no_holes); |
3249 | |
3250 | |
3251 | |
3252 | if ((exception == 0) && (no_holes == 0)) |
3253 | { |
3254 | //fprintf(stderr, "uiw 000\n"); |
3255 | |
3256 | // now do the real loop |
3257 | int number_of_added_holes = 0; |
3258 | |
3259 | unsorted_inner_ways = g_list_first(unsorted_inner_ways); |
3260 | //int number_of_nodes_in_this_way4 = g_list_length(unsorted_inner_ways); |
3261 | //fprintf(stderr, "uiw 001.2 c=%d\n", number_of_nodes_in_this_way4); |
3262 | while (unsorted_inner_ways) |
3263 | { |
3264 | //fprintf(stderr, "uiw 001\n"); |
3265 | |
3266 | if (unsorted_inner_ways->data) |
3267 | { |
3268 | //fprintf(stderr, "uiw 002\n"); |
3269 | |
3270 | current_hole = g_ptr_array_new(); |
3271 | |
3272 | //fprintf(stderr, "uiw 003\n"); |
3273 | |
3274 | way_nodes1 = (struct way_and_endnodes *) unsorted_inner_ways->data; |
3275 | // now read all the nodes of this "hole"-way |
3276 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
3277 | first_node_found = 0; |
3278 | while (way_nodes1->nodes) |
3279 | { |
3280 | //fprintf(stderr, "uiw 004\n"); |
3281 | |
3282 | ndptr = (long long *) way_nodes1->nodes->data; |
3283 | nd = *ndptr; |
3284 | |
3285 | // now read the coords of this node |
3286 | |
3287 | #ifdef MAPTOOL_SPLIT_NODE_DB |
3288 | if (nd % 2) |
3289 | { |
3290 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
3291 | { |
3292 | sqlite3_bind_int64(stmt_sel002__2a, 1, nd); |
3293 | } |
3294 | else |
3295 | { |
3296 | sqlite3_bind_int64(stmt_sel002__2b, 1, nd); |
3297 | } |
3298 | } |
3299 | else |
3300 | { |
3301 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
3302 | { |
3303 | #endif |
3304 | sqlite3_bind_int64(stmt_sel002a, 1, nd); |
3305 | #ifdef MAPTOOL_SPLIT_NODE_DB |
3306 | } |
3307 | else |
3308 | { |
3309 | sqlite3_bind_int64(stmt_sel002b, 1, nd); |
3310 | } |
3311 | } |
3312 | #endif |
3313 | rc2 = 0; |
3314 | do |
3315 | { |
3316 | #ifdef MAPTOOL_SPLIT_NODE_DB |
3317 | if (nd % 2) |
3318 | { |
3319 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
3320 | { |
3321 | rc2 = sqlite3_step(stmt_sel002__2a); |
3322 | } |
3323 | else |
3324 | { |
3325 | rc2 = sqlite3_step(stmt_sel002__2b); |
3326 | } |
3327 | } |
3328 | else |
3329 | { |
3330 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
3331 | { |
3332 | #endif |
3333 | rc2 = sqlite3_step(stmt_sel002a); |
3334 | #ifdef MAPTOOL_SPLIT_NODE_DB |
3335 | } |
3336 | else |
3337 | { |
3338 | rc2 = sqlite3_step(stmt_sel002b); |
3339 | } |
3340 | } |
3341 | #endif |
3342 | |
3343 | switch (rc2) |
3344 | { |
3345 | case SQLITE_DONE: |
3346 | break; |
3347 | case SQLITE_ROW: |
3348 | |
3349 | #ifdef MAPTOOL_SPLIT_NODE_DB |
3350 | if (nd % 2) |
3351 | { |
3352 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
3353 | { |
3354 | lat_nd = (double) sqlite3_column_double(stmt_sel002__2a, 0); |
3355 | lon_nd = (double) sqlite3_column_double(stmt_sel002__2a, 1); |
3356 | } |
3357 | else |
3358 | { |
3359 | lat_nd = (double) sqlite3_column_double(stmt_sel002__2b, 0); |
3360 | lon_nd = (double) sqlite3_column_double(stmt_sel002__2b, 1); |
3361 | } |
3362 | } |
3363 | else |
3364 | { |
3365 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
3366 | { |
3367 | #endif |
3368 | lat_nd = (double) sqlite3_column_double(stmt_sel002a, 0); |
3369 | lon_nd = (double) sqlite3_column_double(stmt_sel002a, 1); |
3370 | #ifdef MAPTOOL_SPLIT_NODE_DB |
3371 | } |
3372 | else |
3373 | { |
3374 | lat_nd = (double) sqlite3_column_double(stmt_sel002b, 0); |
3375 | lon_nd = (double) sqlite3_column_double(stmt_sel002b, 1); |
3376 | } |
3377 | } |
3378 | #endif |
3379 | |
3380 | if (first_node_found == 0) |
3381 | { |
3382 | first_node_found = 1; |
3383 | } |
3384 | else |
3385 | { |
3386 | // ------ ok use this node and coords for triangulation ---- |
3387 | //fprintf(stderr, "HOLE:nd,lat,lon %lld,%f,%f\n", nd,lat_nd,lon_nd); |
3388 | |
3389 | //fprintf(stderr, "np=%d\n", number_of_points_in_poly); |
3390 | //in.pointlist[number_of_points_in_poly] = (REAL) (lat_nd*10); |
3391 | //number_of_points_in_poly++; |
3392 | //fprintf(stderr, "np=%d\n", number_of_points_in_poly); |
3393 | //in.pointlist[number_of_points_in_poly] = (REAL) (lon_nd*10); |
3394 | //number_of_points_in_poly++; |
3395 | #if 1 |
3396 | y = lat_nd * factor; |
3397 | x = lon_nd * factor; |
3398 | |
3399 | TRY |
3400 | { |
3401 | signal(SIGSEGV, catch_signal); |
3402 | |
3403 | // hole complete, now add it |
3404 | //fprintf(stderr, "hole new\n"); |
3405 | g_ptr_array_add(current_hole, p2t_point_new_dd(x, y)); |
3406 | //fprintf(stderr, "hole new done\n"); |
3407 | } |
3408 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3409 | { |
3410 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3411 | fprintf_(stderr, "Got Exception A!\n"); |
3412 | exception = 1; |
3413 | } |
3414 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3415 | { |
3416 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3417 | fprintf_(stderr, "Got segv Exception A!\n"); |
3418 | exception = 1; |
3419 | } |
3420 | FINALLY |
3421 | { |
3422 | // set default |
3423 | signal (SIGSEGV, SIG_DFL); |
3424 | // set default |
3425 | |
3426 | //fprintf(stderr, "finally\n"); |
3427 | } |
3428 | ETRY; |
3429 | |
3430 | #endif |
3431 | } |
3432 | break; |
3433 | default: |
3434 | fprintf(stderr, "Error: %d\n", rc2); |
3435 | break; |
3436 | } |
3437 | } |
3438 | while (rc2 == SQLITE_ROW); |
3439 | |
3440 | #ifdef MAPTOOL_SPLIT_NODE_DB |
3441 | if (nd % 2) |
3442 | { |
3443 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
3444 | { |
3445 | sqlite3_reset(stmt_sel002__2a); |
3446 | } |
3447 | else |
3448 | { |
3449 | sqlite3_reset(stmt_sel002__2b); |
3450 | } |
3451 | } |
3452 | else |
3453 | { |
3454 | if ((nd & MAPTOOL_SPLIT_NODE_BIT) > 0) |
3455 | { |
3456 | #endif |
3457 | sqlite3_reset(stmt_sel002a); |
3458 | #ifdef MAPTOOL_SPLIT_NODE_DB |
3459 | } |
3460 | else |
3461 | { |
3462 | sqlite3_reset(stmt_sel002b); |
3463 | } |
3464 | } |
3465 | #endif |
3466 | |
3467 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
3468 | } |
3469 | |
3470 | //fprintf(stderr, "uiw 005\n"); |
3471 | |
3472 | // remember the pointer, to free the memory later |
3473 | all_holes = g_list_append(all_holes, current_hole); |
3474 | |
3475 | //fprintf(stderr, "uiw 005.1\n"); |
3476 | |
3477 | TRY |
3478 | { |
3479 | signal(SIGSEGV, catch_signal); |
3480 | |
3481 | // hole complete, now add it |
3482 | //fprintf(stderr, "adding hole\n"); |
3483 | if (number_of_added_holes < MAX_HOLES_PER_POLY) |
3484 | { |
3485 | p2t_cdt_add_hole(cdt, current_hole); |
3486 | number_of_added_holes++; |
3487 | } |
3488 | //fprintf(stderr, "adding done\n"); |
3489 | } |
3490 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3491 | { |
3492 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3493 | fprintf_(stderr, "Got Exception 8!\n"); |
3494 | exception = 1; |
3495 | } |
3496 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3497 | { |
3498 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3499 | fprintf_(stderr, "Got segv Exception 8!\n"); |
3500 | exception = 1; |
3501 | } |
3502 | FINALLY |
3503 | { |
3504 | // set default |
3505 | signal (SIGSEGV, SIG_DFL); |
3506 | // set default |
3507 | |
3508 | //fprintf(stderr, "finally\n"); |
3509 | } |
3510 | ETRY; |
3511 | |
3512 | } |
3513 | |
3514 | //fprintf(stderr, "uiw 006\n"); |
3515 | unsorted_inner_ways = g_list_next(unsorted_inner_ways); |
3516 | |
3517 | } |
3518 | //sqlite3_reset(st); |
3519 | |
3520 | //fprintf(stderr, "uiw 007\n"); |
3521 | } |
3522 | |
3523 | //fprintf(stderr, "after adding holes\n"); |
3524 | |
3525 | #if 1 |
3526 | |
3527 | if (exception == 0) |
3528 | { |
3529 | exception = 0; |
3530 | |
3531 | TRY |
3532 | { |
3533 | // catch SIGSEGV !! |
3534 | signal(SIGSEGV, catch_signal); |
3535 | //signal(SIGILL, catch_signal); |
3536 | |
3537 | // alternate signal stack ------------ |
3538 | //ss.ss_size = SIGSTKSZ; |
3539 | //ss.ss_sp = stack; |
3540 | //sa.sa_handler = catch_signal; |
3541 | //sa.sa_flags = SA_ONSTACK; |
3542 | //sigfillset(&sa.sa_mask); |
3543 | |
3544 | //sigaltstack(&ss, 0); |
3545 | //sigfillset(&sa.sa_mask); |
3546 | //sigaction(SIGSEGV, &sa, 0); |
3547 | // alternate signal stack ------------ |
3548 | |
3549 | // catch SIGSEGV !! |
3550 | |
3551 | //fprintf(stderr, "triangulate start ...\n"); |
3552 | p2t_cdt_triangulate(cdt); |
3553 | //fprintf(stderr, "triangulate end\n"); |
3554 | } |
3555 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3556 | { |
3557 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3558 | fprintf_(stderr, "Got Exception 2! (in triangulate)\n"); |
3559 | exception = 1; |
3560 | } |
3561 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3562 | { |
3563 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3564 | fprintf_(stderr, "Got segv Exception 2! (in triangulate)\n"); |
3565 | exception = 1; |
3566 | } |
3567 | FINALLY |
3568 | { |
3569 | //fprintf(stderr, "finally 2 (in triangulate)\n"); |
3570 | |
3571 | //sa.sa_handler = SIG_DFL; |
3572 | // sigfillset(&sa.sa_mask); |
3573 | //sigaction(SIGSEGV, &sa, 0); |
3574 | |
3575 | // set default |
3576 | signal (SIGSEGV, SIG_DFL); |
3577 | // set default |
3578 | } |
3579 | ETRY; |
3580 | |
3581 | if (exception == 0) |
3582 | { |
3583 | rmesh = g_slice_new (P2trCDT); |
3584 | rmesh->mesh = p2tr_mesh_new (); |
3585 | // rmesh->outline = p2tr_pslg_new (); |
3586 | |
3587 | /* First iteration over the CDT - create all the points */ |
3588 | //fprintf(stderr, "trinew 006\n"); |
3589 | triangles = p2t_cdt_get_triangles(cdt); |
3590 | //fprintf(stderr, "trinew 007\n"); |
3591 | for (i = 0; i < triangles->len; i++) |
3592 | { |
3593 | P2tTriangle *cdt_tri = triangle_index (triangles, i); |
3594 | for (j = 0; j < 3; j++) |
3595 | { |
3596 | P2tPoint *cdt_pt = p2t_triangle_get_point(cdt_tri, j); |
3597 | P2trPoint *new_pt = (P2trPoint*) g_hash_table_lookup (point_map, cdt_pt); |
3598 | |
3599 | if (new_pt == NULL) |
3600 | { |
3601 | //fprintf(stderr, "p1 x=%d, y=%d\n",(int)cdt_pt->x, (int)cdt_pt->y); |
3602 | new_pt = p2tr_mesh_new_point2 (rmesh->mesh, (cdt_pt->x / factor), (cdt_pt->y / factor)); |
3603 | g_hash_table_insert (point_map, cdt_pt, new_pt); |
3604 | } |
3605 | } |
3606 | } |
3607 | |
3608 | for (i = 0; i < triangles->len; i++) |
3609 | { |
3610 | P2tTriangle *cdt_tri = triangle_index(triangles, i); |
3611 | //fprintf(stderr, "tri# %d\n", i); |
3612 | gboolean ii = p2t_triangle_is_interior(cdt_tri); |
3613 | //fprintf(stderr, "is int=%d\n", ii); |
3614 | |
3615 | P2trPoint *pt1 = (P2trPoint*) g_hash_table_lookup (point_map, p2t_triangle_get_point (cdt_tri, 0)); |
3616 | P2trPoint *pt2 = (P2trPoint*) g_hash_table_lookup (point_map, p2t_triangle_get_point (cdt_tri, 1)); |
3617 | P2trPoint *pt3 = (P2trPoint*) g_hash_table_lookup (point_map, p2t_triangle_get_point (cdt_tri, 2)); |
3618 | |
3619 | //fprintf(stderr, "0 x=%f, y=%f\n",pt1->c.x, pt1->c.y); |
3620 | //fprintf(stderr, "1 x=%f, y=%f\n",pt2->c.x, pt2->c.y); |
3621 | //fprintf(stderr, "2 x=%f, y=%f\n",pt3->c.x, pt3->c.y); |
3622 | |
3623 | // make item and write it to ways file ------------------- |
3624 | // make item and write it to ways file ------------------- |
3625 | if (tag_id == 1) |
3626 | { |
3627 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
3628 | //fprintf(stderr, "T:water\n"); |
3629 | } |
3630 | else if (tag_id == 2) |
3631 | { |
3632 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
3633 | //fprintf(stderr, "T:water\n"); |
3634 | } |
3635 | else if (tag_id == 4) |
3636 | { |
3637 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
3638 | //fprintf(stderr, "T:water\n"); |
3639 | } |
3640 | else if (tag_id == 5) |
3641 | { |
3642 | item_bin_tri = init_item(type_poly_wood_from_triang, 0); |
3643 | //fprintf(stderr, "T:forest\n"); |
3644 | } |
3645 | else if (tag_id == 6) |
3646 | { |
3647 | item_bin_tri = init_item(type_poly_wood_from_triang, 0); |
3648 | //fprintf(stderr, "T:forest\n"); |
3649 | } |
3650 | else if (tag_id == 9) |
3651 | { |
3652 | item_bin_tri = init_item(type_poly_building_from_triang, 0); |
3653 | //fprintf(stderr, "T:building\n"); |
3654 | } |
3655 | else |
3656 | { |
3657 | // default |
3658 | item_bin_tri = init_item(type_poly_water_from_triang, 0); |
3659 | //fprintf(stderr, "T:water\n"); |
3660 | } |
3661 | |
3662 | // first add coords |
3663 | coord_tri.x = transform_from_geo_lon(pt1->c.x); |
3664 | coord_tri.y = transform_from_geo_lat(pt1->c.y); |
3665 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
3666 | coord_tri.x = transform_from_geo_lon(pt2->c.x); |
3667 | coord_tri.y = transform_from_geo_lat(pt2->c.y); |
3668 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
3669 | coord_tri.x = transform_from_geo_lon(pt3->c.x); |
3670 | coord_tri.y = transform_from_geo_lat(pt3->c.y); |
3671 | item_bin_add_coord(item_bin_tri, &coord_tri, 1); |
3672 | // now add dummy osm wayid |
3673 | item_bin_add_attr_longlong(item_bin_tri, attr_osm_wayid, current_id); |
3674 | |
3675 | // DEBUG -- DEBUG -- DEBUG -- |
3676 | // DEBUG -- DEBUG -- DEBUG -- |
3677 | // dump_itembin(item_bin_tri); |
3678 | // DEBUG -- DEBUG -- DEBUG -- |
3679 | // DEBUG -- DEBUG -- DEBUG -- |
3680 | item_bin_write(item_bin_tri, osm->ways_with_coords); |
3681 | |
3682 | // make item and write it to ways file ------------------- |
3683 | // make item and write it to ways file ------------------- |
3684 | |
3685 | } |
3686 | |
3687 | //fprintf(stderr, "trinew 091\n"); |
3688 | |
3689 | } |
3690 | |
3691 | //fprintf(stderr, "trinew 092.0\n"); |
3692 | |
3693 | |
3694 | TRY |
3695 | { |
3696 | signal(SIGSEGV, catch_signal); |
3697 | |
3698 | /* Now finally unref the points we added into the map */ |
3699 | if (point_map != NULL) |
3700 | { |
3701 | GHashTableIter iter; |
3702 | P2trPoint *pt_iter = NULL; |
3703 | g_hash_table_iter_init (&iter, point_map); |
3704 | while (g_hash_table_iter_next (&iter, NULL, (gpointer*)&pt_iter)) |
3705 | { |
3706 | p2tr_point_unref(pt_iter); |
3707 | } |
3708 | g_hash_table_destroy(point_map); |
3709 | } |
3710 | } |
3711 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3712 | { |
3713 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3714 | fprintf_(stderr, "Got Exception 3!\n"); |
3715 | exception = 1; |
3716 | } |
3717 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3718 | { |
3719 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3720 | fprintf_(stderr, "Got segv Exception 3!\n"); |
3721 | exception = 1; |
3722 | } |
3723 | FINALLY |
3724 | { |
3725 | signal (SIGSEGV, SIG_DFL); |
3726 | } |
3727 | ETRY; |
3728 | |
3729 | //fprintf(stderr, "trinew 092.1\n"); |
3730 | |
3731 | |
3732 | TRY |
3733 | { |
3734 | signal(SIGSEGV, catch_signal); |
3735 | // p2tr_mesh_clear(rmesh->mesh); |
3736 | // --- maybe need this?? --- p2tr_mesh_unref(rmesh->mesh); |
3737 | } |
3738 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3739 | { |
3740 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3741 | fprintf_(stderr, "Got Exception 4!\n"); |
3742 | exception = 1; |
3743 | } |
3744 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3745 | { |
3746 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3747 | fprintf_(stderr, "Got segv Exception 4!\n"); |
3748 | exception = 1; |
3749 | } |
3750 | FINALLY |
3751 | { |
3752 | signal (SIGSEGV, SIG_DFL); |
3753 | } |
3754 | ETRY; |
3755 | |
3756 | //fprintf(stderr, "trinew 092.2\n"); |
3757 | |
3758 | TRY |
3759 | { |
3760 | signal(SIGSEGV, catch_signal); |
3761 | p2t_cdt_free(cdt); |
3762 | } |
3763 | CATCH( MAPTOOL_00001_EXCEPTION ) |
3764 | { |
3765 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3766 | fprintf_(stderr, "Got Exception 5!\n"); |
3767 | exception = 1; |
3768 | } |
3769 | CATCH( MAPTOOL_00002_EXCEPTION ) |
3770 | { |
3771 | fprintf_(stderr, "relation id=%lld\n", current_id); |
3772 | fprintf_(stderr, "Got segv Exception 5!\n"); |
3773 | exception = 1; |
3774 | } |
3775 | FINALLY |
3776 | { |
3777 | signal (SIGSEGV, SIG_DFL); |
3778 | } |
3779 | ETRY; |
3780 | |
3781 | //fprintf(stderr, "trinew 092.3\n"); |
3782 | |
3783 | } // exception == 0 ? -- END |
3784 | |
3785 | // rcdt = p2tr_cdt_new(cdt); |
3786 | /* |
3787 | if (refine_max_steps > 0) |
3788 | { |
3789 | fprintf(stderr, "Refining the mesh!\n"); |
3790 | refiner = p2tr_refiner_new(G_PI / 6, p2tr_refiner_false_too_big, rcdt); |
3791 | p2tr_refiner_refine(refiner, refine_max_steps, NULL); |
3792 | p2tr_refiner_free(refiner); |
3793 | |
3794 | p2tr_cdt_validate_edges(rcdt); |
3795 | } |
3796 | */ |
3797 | |
3798 | //fprintf(stderr, "free holes\n"); |
3799 | |
3800 | if (all_holes) |
3801 | { |
3802 | all_holes = g_list_first(all_holes); |
3803 | while (all_holes) |
3804 | { |
3805 | current_hole = all_holes->data; |
3806 | for (i = 0; i < current_hole->len; ++i) |
3807 | { |
3808 | p2t_point_free(g_ptr_array_index(current_hole, i)); |
3809 | } |
3810 | g_ptr_array_free(current_hole, TRUE); |
3811 | |
3812 | all_holes = g_list_next(all_holes); |
3813 | } |
3814 | g_list_free(all_holes); |
3815 | all_holes = NULL; |
3816 | } |
3817 | |
3818 | //fprintf(stderr, "free points\n"); |
3819 | |
3820 | for (i = 0; i < current_points->len; ++i) |
3821 | { |
3822 | p2t_point_free(g_ptr_array_index(current_points, i)); |
3823 | } |
3824 | g_ptr_array_free(current_points, TRUE); |
3825 | |
3826 | // p2tr_cdt_free(rcdt); |
3827 | |
3828 | #endif |
3829 | |
3830 | #if 0 |
3831 | item_bin_write(item_bin_tri, osm->ways_with_coords); |
3832 | #endif |
3833 | triangulate_not_done = 0; |
3834 | } |
3835 | |
3836 | // free everything!! ---------------- |
3837 | if (unsorted_outer_ways) |
3838 | { |
3839 | unsorted_outer_ways = g_list_first(unsorted_outer_ways); |
3840 | while (unsorted_outer_ways) |
3841 | { |
3842 | gptr = unsorted_outer_ways->data; |
3843 | way_nodes1 = unsorted_outer_ways->data; |
3844 | if (way_nodes1->nodes) |
3845 | { |
3846 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
3847 | while (way_nodes1->nodes) |
3848 | { |
3849 | ndptr = way_nodes1->nodes->data; |
3850 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
3851 | g_free(ndptr); |
3852 | ndptr = NULL; |
3853 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
3854 | } |
3855 | } |
3856 | unsorted_outer_ways = g_list_remove(unsorted_outer_ways, gptr); |
3857 | g_free(gptr); |
3858 | gptr = NULL; |
3859 | unsorted_outer_ways = g_list_next(unsorted_outer_ways); |
3860 | } |
3861 | } |
3862 | |
3863 | if (unsorted_inner_ways) |
3864 | { |
3865 | unsorted_inner_ways = g_list_first(unsorted_inner_ways); |
3866 | while (unsorted_inner_ways) |
3867 | { |
3868 | gptr = unsorted_inner_ways->data; |
3869 | way_nodes1 = unsorted_inner_ways->data; |
3870 | if (way_nodes1->nodes) |
3871 | { |
3872 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
3873 | while (way_nodes1->nodes) |
3874 | { |
3875 | ndptr = way_nodes1->nodes->data; |
3876 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
3877 | g_free(ndptr); |
3878 | ndptr = NULL; |
3879 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
3880 | } |
3881 | } |
3882 | unsorted_inner_ways = g_list_remove(unsorted_inner_ways, gptr); |
3883 | g_free(gptr); |
3884 | gptr = NULL; |
3885 | unsorted_inner_ways = g_list_next(unsorted_inner_ways); |
3886 | } |
3887 | } |
3888 | |
3889 | if (sorted_outer_ways) |
3890 | { |
3891 | sorted_outer_ways = g_list_first(sorted_outer_ways); |
3892 | while (sorted_outer_ways) |
3893 | { |
3894 | gptr = sorted_outer_ways->data; |
3895 | way_nodes1 = sorted_outer_ways->data; |
3896 | if (way_nodes1->nodes) |
3897 | { |
3898 | way_nodes1->nodes = g_list_first(way_nodes1->nodes); |
3899 | while (way_nodes1->nodes) |
3900 | { |
3901 | ndptr = way_nodes1->nodes->data; |
3902 | way_nodes1->nodes = g_list_remove(way_nodes1->nodes, ndptr); |
3903 | g_free(ndptr); |
3904 | ndptr = NULL; |
3905 | way_nodes1->nodes = g_list_next(way_nodes1->nodes); |
3906 | } |
3907 | } |
3908 | sorted_outer_ways = g_list_remove(sorted_outer_ways, gptr); |
3909 | g_free(gptr); |
3910 | gptr = NULL; |
3911 | sorted_outer_ways = g_list_next(sorted_outer_ways); |
3912 | } |
3913 | } |
3914 | // free everything!! ---------------- |
3915 | } |
3916 | // save relations other method -------------- |
3917 | |
3918 | #endif |
3919 | |
3920 | if (triangulate_not_done == 1) |
3921 | { |
3922 | str = NULL; |
3923 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
3924 | { |
3925 | if (get_relation_member(str, &memb)) |
3926 | { |
3927 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) // use only "outer" "ways" here!! |
3928 | { |
3929 | struct way_tag wt; |
3930 | wt.way_id = memb.id; |
3931 | wt.tag_id = tag_id; |
3932 | // only use "water" related ways here |
3933 | if ((tag_id == 1) || (tag_id == 2) || (tag_id == 4) || (tag_id == 5) || (tag_id == 6)) |
3934 | { |
3935 | //fprintf(stderr,"rel way=%llu\n", memb.id); |
3936 | fwrite(&wt, sizeof(struct way_tag), 1, osm->relations_riverbank); |
3937 | } |
3938 | } |
3939 | else if ((memb.type == 2) && (!strcmp(memb.role, "inner"))) // use only "outer" "ways" here!! |
3940 | { |
3941 | struct way_tag wt; |
3942 | wt.way_id = memb.id; |
3943 | wt.tag_id = tag_id; |
3944 | // only use "water" related ways here |
3945 | if (tag_id == 6) |
3946 | { |
3947 | wt.tag_id = 8; |
3948 | //fprintf(stderr,"rel way(8)=%llu\n", memb.id); |
3949 | fwrite(&wt, sizeof(struct way_tag), 1, osm->relations_riverbank); |
3950 | } |
3951 | else if (tag_id == 5) |
3952 | { |
3953 | wt.tag_id = 7; |
3954 | //fprintf(stderr,"rel way(7)=%llu\n", memb.id); |
3955 | fwrite(&wt, sizeof(struct way_tag), 1, osm->relations_riverbank); |
3956 | } |
3957 | } |
3958 | |
3959 | } |
3960 | } |
3961 | } |
3962 | } |
3963 | // -- save relations for riverbanks -- |
3964 | |
3965 | |
3966 | in_relation = 0; |
3967 | |
3968 | if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) |
3969 | { |
3970 | int found_town_rel = 0; |
3971 | |
3972 | fprintf_(stderr, "town to relation 00: r:%lld\n", current_id); |
3973 | |
3974 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
3975 | { |
3976 | // save relation id for towns into DB |
3977 | str = NULL; |
3978 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
3979 | { |
3980 | if (get_relation_member(str, &memb)) |
3981 | { |
3982 | if (memb.type == 1) |
3983 | { |
3984 | fprintf_(stderr, "role=%s\n", memb.role); |
3985 | |
3986 | if (!strcmp(memb.role, "label")) |
3987 | { |
3988 | fprintf_(stderr, "town to relation 1: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
3989 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
3990 | // fprintf(stderr, "ret=%d\n", rr); |
3991 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
3992 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
3993 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
3994 | sqlite3_step(stmt_town_sel008); |
3995 | //fprintf(stderr, "ret=%d\n", rr); |
3996 | sqlite3_reset(stmt_town_sel008); |
3997 | //fprintf(stderr, "ret=%d\n", rr); |
3998 | |
3999 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
4000 | |
4001 | lat_lon_c = get_first_coord_of_boundary(item_bin_2, &memb); |
4002 | if (lat_lon_c) |
4003 | { |
4004 | sqlite3_bind_double(stmt_town, 6, lat_lon_c->lat); |
4005 | sqlite3_bind_double(stmt_town, 7, lat_lon_c->lon); |
4006 | g_free(lat_lon_c); |
4007 | } |
4008 | |
4009 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
4010 | sqlite3_bind_int(stmt_town, 2, 999); |
4011 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
4012 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
4013 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
4014 | sqlite3_bind_int64(stmt_town, 8, current_id); |
4015 | sqlite3_step(stmt_town); |
4016 | sqlite3_reset(stmt_town); |
4017 | dummy_town_id--; |
4018 | |
4019 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4020 | //fprintf(stderr, "ret=%d\n", rr); |
4021 | |
4022 | found_town_rel = 1; |
4023 | } |
4024 | } |
4025 | } |
4026 | } |
4027 | } |
4028 | |
4029 | |
4030 | |
4031 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
4032 | { |
4033 | // save relation id for towns into DB |
4034 | str = NULL; |
4035 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
4036 | { |
4037 | if (get_relation_member(str, &memb)) |
4038 | { |
4039 | if (memb.type == 1) |
4040 | { |
4041 | fprintf_(stderr, "role=%s\n", memb.role); |
4042 | |
4043 | if (!strcmp(memb.role, "admin_centre")) |
4044 | { |
4045 | fprintf_(stderr, "town to relation 2: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
4046 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4047 | // fprintf(stderr, "ret=%d\n", rr); |
4048 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
4049 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
4050 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
4051 | sqlite3_step(stmt_town_sel008); |
4052 | //fprintf(stderr, "ret=%d\n", rr); |
4053 | sqlite3_reset(stmt_town_sel008); |
4054 | //fprintf(stderr, "ret=%d\n", rr); |
4055 | |
4056 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
4057 | |
4058 | lat_lon_c = get_first_coord_of_boundary(item_bin_2, &memb); |
4059 | if (lat_lon_c) |
4060 | { |
4061 | sqlite3_bind_double(stmt_town, 6, lat_lon_c->lat); |
4062 | sqlite3_bind_double(stmt_town, 7, lat_lon_c->lon); |
4063 | g_free(lat_lon_c); |
4064 | } |
4065 | |
4066 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
4067 | sqlite3_bind_int(stmt_town, 2, 999); |
4068 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
4069 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
4070 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
4071 | sqlite3_bind_int64(stmt_town, 8, current_id); |
4072 | sqlite3_step(stmt_town); |
4073 | sqlite3_reset(stmt_town); |
4074 | dummy_town_id--; |
4075 | |
4076 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4077 | //fprintf(stderr, "ret=%d\n", rr); |
4078 | |
4079 | found_town_rel = 1; |
4080 | } |
4081 | } |
4082 | } |
4083 | } |
4084 | } |
4085 | |
4086 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
4087 | { |
4088 | // save relation id for towns into DB |
4089 | str = NULL; |
4090 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
4091 | { |
4092 | if (get_relation_member(str, &memb)) |
4093 | { |
4094 | if (memb.type == 1) |
4095 | { |
4096 | //fprintf(stderr, "role=%s\n", memb.role); |
4097 | |
4098 | if (!strcmp(memb.role, "admin_center")) |
4099 | { |
4100 | fprintf_(stderr, "town to relation 3: rel-name:%s r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), current_id, memb.id); |
4101 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4102 | // fprintf(stderr, "ret=%d\n", rr); |
4103 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
4104 | sqlite3_bind_int64(stmt_town_sel008, 2, memb.id); |
4105 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
4106 | sqlite3_step(stmt_town_sel008); |
4107 | //fprintf(stderr, "ret=%d\n", rr); |
4108 | sqlite3_reset(stmt_town_sel008); |
4109 | //fprintf(stderr, "ret=%d\n", rr); |
4110 | |
4111 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
4112 | |
4113 | lat_lon_c = get_first_coord_of_boundary(item_bin_2, &memb); |
4114 | if (lat_lon_c) |
4115 | { |
4116 | sqlite3_bind_double(stmt_town, 6, lat_lon_c->lat); |
4117 | sqlite3_bind_double(stmt_town, 7, lat_lon_c->lon); |
4118 | g_free(lat_lon_c); |
4119 | } |
4120 | |
4121 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
4122 | sqlite3_bind_int(stmt_town, 2, 999); |
4123 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
4124 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
4125 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
4126 | sqlite3_bind_int64(stmt_town, 8, current_id); |
4127 | sqlite3_step(stmt_town); |
4128 | sqlite3_reset(stmt_town); |
4129 | dummy_town_id--; |
4130 | |
4131 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4132 | //fprintf(stderr, "ret=%d\n", rr); |
4133 | |
4134 | found_town_rel = 1; |
4135 | } |
4136 | } |
4137 | } |
4138 | } |
4139 | } |
4140 | |
4141 | |
4142 | |
4143 | if ((found_town_rel == 0) && (admin_level >= TOWN_ADMIN_LEVEL_START)) |
4144 | { |
4145 | // save relation id for towns into DB (use dummy town data) |
4146 | fprintf_(stderr, "town to relation(*): rel-name:%s admlevel:%d r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), admin_level, current_id, dummy_town_id); |
4147 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4148 | // fprintf(stderr, "ret=%d\n", rr); |
4149 | sqlite3_bind_int64(stmt_town_sel008, 1, current_id); |
4150 | sqlite3_bind_int64(stmt_town_sel008, 2, dummy_town_id); |
4151 | sqlite3_bind_int(stmt_town_sel008, 3, admin_level); |
4152 | sqlite3_step(stmt_town_sel008); |
4153 | //fprintf(stderr, "ret=%d\n", rr); |
4154 | sqlite3_reset(stmt_town_sel008); |
4155 | //fprintf(stderr, "ret=%d\n", rr); |
4156 | |
4157 | int did_write_boundary_to_db = 0; |
4158 | str = NULL; |
4159 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
4160 | { |
4161 | if (get_relation_member(str, &memb)) |
4162 | { |
4163 | if ((memb.type == 2) && (strcmp(memb.role, "inner"))) |
4164 | { |
4165 | // way-id is "memb.id" |
4166 | // use the first nodes coords |
4167 | //get_lat_lon_way_first_node(memb.id, &node_coords); |
4168 | //if (node_coords.valid == 1) |
4169 | //{ |
4170 | // sqlite3_bind_double(stmt_town, 6, node_coords.lat); |
4171 | // sqlite3_bind_double(stmt_town, 7, node_coords.lon); |
4172 | //} |
4173 | |
4174 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
4175 | did_write_boundary_to_db = 1; |
4176 | |
4177 | break; |
4178 | } |
4179 | } |
4180 | } |
4181 | |
4182 | lat_lon_c = get_first_coord_of_boundary(item_bin_2, &memb); |
4183 | if (lat_lon_c) |
4184 | { |
4185 | sqlite3_bind_double(stmt_town, 6, lat_lon_c->lat); |
4186 | sqlite3_bind_double(stmt_town, 7, lat_lon_c->lon); |
4187 | fprintf_(stderr, "town to relation(*):coords %f %f\n", lat_lon_c->lat, lat_lon_c->lon); |
4188 | g_free(lat_lon_c); |
4189 | } |
4190 | |
4191 | |
4192 | sqlite3_bind_int64(stmt_town, 1, dummy_town_id); |
4193 | sqlite3_bind_int(stmt_town, 2, 999); |
4194 | sqlite3_bind_int(stmt_town, 4, (TOWN_ADMIN_LEVEL_CORR_BASE + admin_level) * TOWN_BY_BOUNDARY_SIZE_FACTOR); |
4195 | sqlite3_bind_text(stmt_town, 3, osm_tag_value(item_bin_2, "name"), -1, SQLITE_STATIC); |
4196 | sqlite3_bind_text(stmt_town, 5, NULL, -1, SQLITE_STATIC); |
4197 | |
4198 | if (did_write_boundary_to_db == 1) |
4199 | { |
4200 | sqlite3_bind_int64(stmt_town, 8, current_id); |
4201 | } |
4202 | else |
4203 | { |
4204 | // boundary not in DB |
4205 | // ----- what? i have no idea what to do here ----- |
4206 | } |
4207 | sqlite3_step(stmt_town); |
4208 | sqlite3_reset(stmt_town); |
4209 | |
4210 | found_town_rel = 1; |
4211 | |
4212 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4213 | //fprintf(stderr, "ret=%d\n", rr); |
4214 | |
4215 | dummy_town_id--; |
4216 | } |
4217 | |
4218 | // rest of the boundaries!!! |
4219 | if (found_town_rel == 0) |
4220 | { |
4221 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4222 | |
4223 | str = NULL; |
4224 | while ((str = item_bin_get_attr(item_bin_2, attr_osm_member, str))) |
4225 | { |
4226 | if (get_relation_member(str, &memb)) |
4227 | { |
4228 | if ((memb.type == 2) && (!strcmp(memb.role, "outer"))) |
4229 | { |
4230 | fprintf_(stderr, "town to relation(+): rel-name:%s admlevel:%d r:%lld t:%lld\n",osm_tag_value(item_bin_2, "name"), admin_level, current_id, 9797979797); |
4231 | |
4232 | add_boundary_to_db(current_id, admin_level, item_bin_2, &memb); |
4233 | break; |
4234 | } |
4235 | } |
4236 | } |
4237 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4238 | |
4239 | found_town_rel = 0; |
4240 | } |
4241 | |
4242 | |
4243 | #if 0 |
4244 | if (admin_level == 2) |
4245 | { |
4246 | FILE *f; |
4247 | fprintf(stderr,"Multipolygon for %s\n", iso_code); |
4248 | char *name=g_strdup_printf("country_%s.tmp",iso_code); |
4249 | f=fopen(name,"w"); |
4250 | item_bin_write(item_bin_2, f); |
4251 | fclose(f); |
4252 | } |
4253 | #endif |
4254 | item_bin_write(item_bin_2, osm->boundaries); |
4255 | } |
4256 | |
4257 | if (!strcmp(relation_type, "restriction") && (item_bin_2->type == type_street_turn_restriction_no || item_bin_2->type == type_street_turn_restriction_only)) |
4258 | { |
4259 | item_bin_write(item_bin_2, osm->turn_restrictions); |
4260 | } |
4261 | } |
4262 | |
4263 | |
4264 | // #define DEBUG_CORRECT_BOUNDARY_REF_POINT 1 |
4265 | |
4266 | void correct_boundary_ref_point(GList *bl) |
4267 | { |
4268 | long long rid; |
4269 | int retval; |
4270 | int rc = 0; |
4271 | int commit_after = 20000; |
4272 | int count = 0; |
4273 | int admin_l = 99; |
4274 | double lat, lon; |
4275 | struct coord c; |
4276 | GList *l = NULL; |
4277 | GList *l2 = NULL; |
4278 | GList *match = NULL; |
4279 | struct boundary *b = NULL; |
4280 | int admin_l_boundary; |
4281 | int max_admin_l; |
4282 | |
4283 | //fprintf(stderr, "BRP:001\n"); |
4284 | |
4285 | // loop thru all the boundaries |
4286 | do |
4287 | { |
4288 | |
4289 | //fprintf(stderr, "BRP:002\n"); |
4290 | |
4291 | rc = sqlite3_step(stmt_bd_002); |
4292 | |
4293 | //fprintf(stderr, "BRP:003\n"); |
4294 | |
4295 | switch (rc) |
4296 | { |
4297 | case SQLITE_DONE: |
4298 | break; |
4299 | case SQLITE_ROW: |
4300 | |
4301 | //fprintf(stderr, "BRP:004\n"); |
4302 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
4303 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
4304 | //fprintf(stderr, "BRP:005\n"); |
4305 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
4306 | //fprintf(stderr, "BRP:006\n"); |
4307 | lat = sqlite3_column_double(stmt_bd_002, 2); |
4308 | //fprintf(stderr, "BRP:007\n"); |
4309 | lon = sqlite3_column_double(stmt_bd_002, 3); |
4310 | //fprintf(stderr, "BRP:008\n"); |
4311 | c.x = transform_from_geo_lon(lon); |
4312 | //fprintf(stderr, "BRP:009\n"); |
4313 | c.y = transform_from_geo_lat(lat); |
4314 | //fprintf(stderr, "BRP:010\n"); |
4315 | |
4316 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4317 | fprintf(stderr, "correct_boundary_ref_point: relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
4318 | #endif |
4319 | |
4320 | // find this boundary in list |
4321 | l = bl; |
4322 | match = NULL; |
4323 | |
4324 | //fprintf(stderr, "BRP:011\n"); |
4325 | |
4326 | while (l) |
4327 | { |
4328 | // fprintf(stderr, "BRP:012 l=%p l->data=%p\n", l, l->data); |
4329 | |
4330 | b = l->data; |
4331 | |
4332 | // fprintf(stderr, "BRP:012a b=%p\n", b); |
4333 | |
4334 | if (b) |
4335 | { |
4336 | // fprintf(stderr, "BRP:012b\n"); |
4337 | if (b->ib) |
4338 | { |
4339 | // fprintf(stderr, "BRP:012c\n"); |
4340 | |
4341 | // fprintf(stderr, "BRP:013a %p\n", b); |
4342 | // fprintf(stderr, "BRP:013b %p\n", b->ib); |
4343 | // fprintf(stderr, "BRP:013c %lld\n", (long long)rid); |
4344 | |
4345 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4346 | fprintf(stderr, "correct_boundary_ref_point: %lld %lld\n", item_bin_get_relationid(b->ib), rid); |
4347 | #endif |
4348 | if (item_bin_get_relationid(b->ib) == rid) |
4349 | { |
4350 | // fprintf(stderr, "BRP:014\n"); |
4351 | match = l; |
4352 | break; |
4353 | } |
4354 | // fprintf(stderr, "BRP:015\n"); |
4355 | |
4356 | } |
4357 | } |
4358 | |
4359 | l = g_list_next(l); |
4360 | |
4361 | // fprintf(stderr, "BRP:016\n"); |
4362 | |
4363 | } |
4364 | |
4365 | //fprintf(stderr, "BRP:017\n"); |
4366 | |
4367 | if (match) |
4368 | { |
4369 | //fprintf(stderr, "BRP:018\n"); |
4370 | |
4371 | b = match->data; |
4372 | |
4373 | if (b) |
4374 | { |
4375 | |
4376 | //fprintf(stderr, "BRP:019\n"); |
4377 | |
4378 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4379 | fprintf(stderr, "correct_boundary_ref_point: relid:%lld(%d) parentid:%lld(%d)\n", rid, admin_l, item_bin_get_relationid(b->ib), max_admin_l); |
4380 | #endif |
4381 | // ------------------------------------------- |
4382 | /* |
4383 | GList *sl; |
4384 | sl = b->sorted_segments; |
4385 | if (sl) |
4386 | { |
4387 | struct geom_poly_segment *gs = sl->data; |
4388 | struct coord *c2 = gs->first; |
4389 | fprintf(stderr, "1a c=%d y=%d\n", c2->x, c2->y); |
4390 | } |
4391 | */ |
4392 | // ------------------------------------------- |
4393 | |
4394 | if (find_correct_point_in_boundary(match, &lat, &lon) == 1) |
4395 | { |
4396 | |
4397 | //fprintf(stderr, "BRP:020\n"); |
4398 | sqlite3_bind_double(stmt_bd_004, 1, lat); |
4399 | //fprintf(stderr, "BRP:021\n"); |
4400 | sqlite3_bind_double(stmt_bd_004, 2, lon); |
4401 | //fprintf(stderr, "BRP:022\n"); |
4402 | sqlite3_bind_int64(stmt_bd_004, 3, rid); |
4403 | //fprintf(stderr, "BRP:023\n"); |
4404 | sqlite3_step(stmt_bd_004); |
4405 | //fprintf(stderr, "BRP:024\n"); |
4406 | sqlite3_reset(stmt_bd_004); |
4407 | //fprintf(stderr, "BRP:025\n"); |
4408 | } |
4409 | |
4410 | //fprintf(stderr, "BRP:026\n"); |
4411 | |
4412 | } |
4413 | |
4414 | } |
4415 | |
4416 | //fprintf(stderr, "BRP:027\n"); |
4417 | |
4418 | if (count == 0) |
4419 | { |
4420 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4421 | } |
4422 | count++; |
4423 | |
4424 | //fprintf(stderr, "BRP:028\n"); |
4425 | |
4426 | if (count > commit_after) |
4427 | { |
4428 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4429 | count = 0; |
4430 | } |
4431 | |
4432 | //fprintf(stderr, "BRP:029\n"); |
4433 | |
4434 | break; |
4435 | default: |
4436 | fprintf(stderr, "SQL Error: %d\n", rc); |
4437 | break; |
4438 | } |
4439 | } |
4440 | while (rc == SQLITE_ROW); |
4441 | |
4442 | //fprintf(stderr, "BRP:091\n"); |
4443 | |
4444 | sqlite3_reset(stmt_bd_002); |
4445 | |
4446 | //fprintf(stderr, "BRP:092\n"); |
4447 | |
4448 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4449 | |
4450 | //fprintf(stderr, "BRP:093\n"); |
4451 | |
4452 | } |
4453 | |
4454 | |
4455 | int find_correct_point_in_boundary(GList *bl, double* lat, double* lon) |
4456 | { |
4457 | double lat2, lon2; |
4458 | struct coord c; |
4459 | struct boundary *b; |
4460 | GList *matches; |
4461 | double lat_d = 0.00006; |
4462 | double lon_d = 0.00006; |
4463 | |
4464 | lat2 = *lat; |
4465 | lon2 = *lon; |
4466 | |
4467 | c.x = transform_from_geo_lon(lon2 + lon_d); |
4468 | c.y = transform_from_geo_lat(lat2 + lat_d); |
4469 | |
4470 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4471 | fprintf(stderr, "2 c=%d y=%d\n", c.x, c.y); |
4472 | #endif |
4473 | |
4474 | matches = NULL; |
4475 | matches = boundary_find_matches_single(bl, &c); |
4476 | if (g_list_length(matches) > 0) |
4477 | { |
4478 | *lon = lon2 + lon_d; |
4479 | *lat = lat2 + lat_d; |
4480 | return 1; |
4481 | } |
4482 | |
4483 | c.x = transform_from_geo_lon(lon2 + lon_d); |
4484 | c.y = transform_from_geo_lat(lat2 - lat_d); |
4485 | |
4486 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4487 | fprintf(stderr, "3 c=%d y=%d\n", c.x, c.y); |
4488 | #endif |
4489 | |
4490 | matches = NULL; |
4491 | matches = boundary_find_matches_single(bl, &c); |
4492 | if (g_list_length(matches) > 0) |
4493 | { |
4494 | *lon = lon2 + lon_d; |
4495 | *lat = lat2 - lat_d; |
4496 | return 1; |
4497 | } |
4498 | |
4499 | c.x = transform_from_geo_lon(lon2 - lon_d); |
4500 | c.y = transform_from_geo_lat(lat2 + lat_d); |
4501 | |
4502 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4503 | fprintf(stderr, "4 c=%d y=%d\n", c.x, c.y); |
4504 | #endif |
4505 | |
4506 | matches = NULL; |
4507 | matches = boundary_find_matches_single(bl, &c); |
4508 | if (g_list_length(matches) > 0) |
4509 | { |
4510 | *lon = lon2 - lon_d; |
4511 | *lat = lat2 + lat_d; |
4512 | return 1; |
4513 | } |
4514 | |
4515 | c.x = transform_from_geo_lon(lon2 - lon_d); |
4516 | c.y = transform_from_geo_lat(lat2 - lat_d); |
4517 | |
4518 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4519 | fprintf(stderr, "5 c=%d y=%d\n", c.x, c.y); |
4520 | #endif |
4521 | |
4522 | matches = NULL; |
4523 | matches = boundary_find_matches_single(bl, &c); |
4524 | if (g_list_length(matches) > 0) |
4525 | { |
4526 | *lon = lon2 - lon_d; |
4527 | *lat = lat2 - lat_d; |
4528 | return 1; |
4529 | } |
4530 | |
4531 | |
4532 | c.x = transform_from_geo_lon(lon2 + lon_d); |
4533 | c.y = transform_from_geo_lat(lat2); |
4534 | |
4535 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4536 | fprintf(stderr, "6 c=%d y=%d\n", c.x, c.y); |
4537 | #endif |
4538 | |
4539 | matches = NULL; |
4540 | matches = boundary_find_matches_single(bl, &c); |
4541 | if (g_list_length(matches) > 0) |
4542 | { |
4543 | *lon = lon2 + lon_d; |
4544 | *lat = lat2; |
4545 | return 1; |
4546 | } |
4547 | |
4548 | c.x = transform_from_geo_lon(lon2 - lon_d); |
4549 | c.y = transform_from_geo_lat(lat2); |
4550 | |
4551 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4552 | fprintf(stderr, "7 c=%d y=%d\n", c.x, c.y); |
4553 | #endif |
4554 | |
4555 | matches = NULL; |
4556 | matches = boundary_find_matches_single(bl, &c); |
4557 | if (g_list_length(matches) > 0) |
4558 | { |
4559 | *lon = lon2 - lon_d; |
4560 | *lat = lat2; |
4561 | return 1; |
4562 | } |
4563 | |
4564 | c.x = transform_from_geo_lon(lon2); |
4565 | c.y = transform_from_geo_lat(lat2 + lat_d); |
4566 | |
4567 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4568 | fprintf(stderr, "8 c=%d y=%d\n", c.x, c.y); |
4569 | #endif |
4570 | |
4571 | matches = NULL; |
4572 | matches = boundary_find_matches_single(bl, &c); |
4573 | if (g_list_length(matches) > 0) |
4574 | { |
4575 | *lon = lon2; |
4576 | *lat = lat2 + lat_d; |
4577 | return 1; |
4578 | } |
4579 | |
4580 | |
4581 | c.x = transform_from_geo_lon(lon2); |
4582 | c.y = transform_from_geo_lat(lat2 - lat_d); |
4583 | |
4584 | #ifdef DEBUG_CORRECT_BOUNDARY_REF_POINT |
4585 | fprintf(stderr, "9 c=%d y=%d\n", c.x, c.y); |
4586 | #endif |
4587 | |
4588 | matches = NULL; |
4589 | matches = boundary_find_matches_single(bl, &c); |
4590 | if (g_list_length(matches) > 0) |
4591 | { |
4592 | *lon = lon2; |
4593 | *lat = lat2 - lat_d; |
4594 | return 1; |
4595 | } |
4596 | |
4597 | return 0; |
4598 | |
4599 | } |
4600 | |
4601 | void build_boundary_tree(GList *bl, GList *man_bl) |
4602 | { |
4603 | long long rid; |
4604 | int retval; |
4605 | int rc = 0; |
4606 | int commit_after = 20000; |
4607 | int count = 0; |
4608 | int admin_l = 99; |
4609 | double lat, lon; |
4610 | struct coord c; |
4611 | GList *l = NULL; |
4612 | GList *l2 = NULL; |
4613 | GList *match = NULL; |
4614 | struct boundary *b; |
4615 | int admin_l_boundary; |
4616 | int max_admin_l; |
4617 | long long b_count = 0; |
4618 | long long b_max_count = 0; |
4619 | |
4620 | |
4621 | sqlite3_stmt *stmt_mm_1; |
4622 | int retval8 = sqlite3_prepare_v2(sql_handle, "select count(*) from boundary where done = 0;", -1, &stmt_mm_1, NULL); |
4623 | fprintf_(stderr, "prep:%d\n", retval8); |
4624 | sqlite3_step(stmt_mm_1); |
4625 | b_max_count = sqlite3_column_int64(stmt_mm_1, 0); |
4626 | fprintf_(stderr, "b_max_count:%lld\n", b_max_count); |
4627 | sqlite3_reset(stmt_mm_1); |
4628 | sqlite3_finalize(stmt_mm_1); |
4629 | |
4630 | |
4631 | // loop thru all the boundaries |
4632 | do |
4633 | { |
4634 | rc = sqlite3_step(stmt_bd_002); |
4635 | switch (rc) |
4636 | { |
4637 | case SQLITE_DONE: |
4638 | break; |
4639 | case SQLITE_ROW: |
4640 | |
4641 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
4642 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
4643 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
4644 | lat = sqlite3_column_double(stmt_bd_002, 2); |
4645 | lon = sqlite3_column_double(stmt_bd_002, 3); |
4646 | c.x = transform_from_geo_lon(lon); |
4647 | c.y = transform_from_geo_lat(lat); |
4648 | |
4649 | b_count++; |
4650 | if ((b_count % 100) == 0) |
4651 | { |
4652 | fprintf_(stderr, "rel:%lld/%lld\n", b_count, b_max_count); |
4653 | // fprintf(stderr, "relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
4654 | } |
4655 | |
4656 | max_admin_l = 0; |
4657 | l2 = boundary_find_matches_level(bl, &c, 0, (admin_l - 1)); |
4658 | l = l2; |
4659 | match = NULL; |
4660 | while (l) |
4661 | { |
4662 | b = l->data; |
4663 | char *admin_l_boundary_str = osm_tag_value(b->ib, "admin_level"); |
4664 | if (!admin_l_boundary_str) |
4665 | { |
4666 | admin_l_boundary = 9999; |
4667 | } |
4668 | else |
4669 | { |
4670 | admin_l_boundary = atoi(admin_l_boundary_str); |
4671 | } |
4672 | |
4673 | if (admin_l_boundary < 2) |
4674 | { |
4675 | admin_l_boundary = 9999; |
4676 | } |
4677 | |
4678 | //fprintf(stderr, "b=%d\n", admin_l_boundary); |
4679 | if (admin_l_boundary > max_admin_l) |
4680 | { |
4681 | max_admin_l = admin_l_boundary; |
4682 | match = l; |
4683 | //fprintf(stderr, "b2=%d\n", max_admin_l); |
4684 | } |
4685 | l = g_list_next(l); |
4686 | } |
4687 | |
4688 | if (match) |
4689 | { |
4690 | b = match->data; |
4691 | //fprintf(stderr, "relid:%lld(%d) parentid:%lld(%d)\n", rid, admin_l, item_bin_get_relationid(b->ib), max_admin_l); |
4692 | |
4693 | sqlite3_bind_int64(stmt_bd_003, 1, item_bin_get_relationid(b->ib)); |
4694 | sqlite3_bind_int64(stmt_bd_003, 2, rid); |
4695 | sqlite3_step(stmt_bd_003); |
4696 | sqlite3_reset(stmt_bd_003); |
4697 | } |
4698 | |
4699 | |
4700 | if (count == 0) |
4701 | { |
4702 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4703 | } |
4704 | count++; |
4705 | |
4706 | if (count > commit_after) |
4707 | { |
4708 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4709 | count = 0; |
4710 | } |
4711 | |
4712 | break; |
4713 | default: |
4714 | fprintf(stderr, "SQL Error: %d\n", rc); |
4715 | break; |
4716 | } |
4717 | } |
4718 | while (rc == SQLITE_ROW); |
4719 | |
4720 | sqlite3_reset(stmt_bd_002); |
4721 | |
4722 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4723 | |
4724 | |
4725 | // ------- enter manual countries into boundary DB ---------- |
4726 | GList *bl2 = man_bl; |
4727 | struct boundary_manual *bb3; |
4728 | |
4729 | struct country_table3 |
4730 | { |
4731 | int countryid; |
4732 | char *names; |
4733 | char *admin_levels; |
4734 | FILE *file; |
4735 | int size; |
4736 | struct rect r; |
4737 | }; |
4738 | |
4739 | |
4740 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4741 | while (bl2) |
4742 | { |
4743 | bb3 = bl2->data; |
4744 | if (bb3) |
4745 | { |
4746 | struct country_table3* cc3 = bb3->country; |
4747 | sqlite3_bind_int64(stmt_bd_001, 1, bb3->town_id); // dummy id |
4748 | sqlite3_bind_int(stmt_bd_001, 2, 2); // admin level |
4749 | sqlite3_bind_text(stmt_bd_001, 5, cc3->names, -1, SQLITE_STATIC); // name |
4750 | sqlite3_step(stmt_bd_001); |
4751 | sqlite3_reset(stmt_bd_001); |
4752 | } |
4753 | bl2 = g_list_next(bl2); |
4754 | } |
4755 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4756 | count = 0; |
4757 | |
4758 | |
4759 | // ------- now assign all the left overs towns/boundaries to countries ---------- |
4760 | long long dummy_town_id2 = 0; |
4761 | count = 0; |
4762 | admin_l = 99; |
4763 | rc = 0; |
4764 | |
4765 | // loop thru all the boundaries |
4766 | do |
4767 | { |
4768 | rc = sqlite3_step(stmt_bd_002); |
4769 | switch (rc) |
4770 | { |
4771 | case SQLITE_DONE: |
4772 | break; |
4773 | case SQLITE_ROW: |
4774 | |
4775 | // select rel_id, admin_level, lat, lon, name from boundary where done = 0; |
4776 | rid = sqlite3_column_int64(stmt_bd_002, 0); |
4777 | admin_l = sqlite3_column_int(stmt_bd_002, 1); |
4778 | lat = sqlite3_column_double(stmt_bd_002, 2); |
4779 | lon = sqlite3_column_double(stmt_bd_002, 3); |
4780 | c.x = transform_from_geo_lon(lon); |
4781 | c.y = transform_from_geo_lat(lat); |
4782 | |
4783 | //fprintf(stderr, "relid:%lld(%d) x=%d y=%d\n", rid, admin_l, c.x, c.y); |
4784 | if (admin_l > 2) |
4785 | { |
4786 | |
4787 | // check if c is inside manual country border |
4788 | dummy_town_id2 = osm_process_street_by_manual_country_borders(man_bl, &c); |
4789 | |
4790 | if (dummy_town_id2 != -1) |
4791 | { |
4792 | sqlite3_bind_int64(stmt_bd_003, 1, dummy_town_id2); // parent rel_id |
4793 | sqlite3_bind_int64(stmt_bd_003, 2, rid); // rel_id |
4794 | sqlite3_step(stmt_bd_003); |
4795 | sqlite3_reset(stmt_bd_003); |
4796 | } |
4797 | |
4798 | |
4799 | if (count == 0) |
4800 | { |
4801 | sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
4802 | } |
4803 | count++; |
4804 | |
4805 | if (count > commit_after) |
4806 | { |
4807 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4808 | count = 0; |
4809 | } |
4810 | |
4811 | } |
4812 | break; |
4813 | default: |
4814 | fprintf(stderr, "SQL Error: %d\n", rc); |
4815 | break; |
4816 | } |
4817 | } |
4818 | while (rc == SQLITE_ROW); |
4819 | sqlite3_reset(stmt_bd_002); |
4820 | |
4821 | sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
4822 | |
4823 | } |
4824 | |
4825 | struct node_lat_lon* get_first_coord_of_boundary(struct item_bin *item_bin_3, struct relation_member *memb) |
4826 | { |
4827 | char *str = NULL; |
4828 | struct node_lat_lon* node_coords=g_new0(struct node_lat_lon, 1); |
4829 | |
4830 | while ((str = item_bin_get_attr(item_bin_3, attr_osm_member, str))) |
4831 | { |
4832 | if (get_relation_member(str, memb)) |
4833 | { |
4834 | if (memb->type == 2) |
4835 | { |
4836 | // way-id is "memb.id" |
4837 | // use the first nodes coords |
4838 | get_lat_lon_way_first_node(memb->id, node_coords); |
4839 | if (node_coords->valid == 1) |
4840 | { |
4841 | return node_coords; |
4842 | } |
4843 | break; |
4844 | } |
4845 | } |
4846 | } |
4847 | |
4848 | return NULL; |
4849 | } |
4850 | |
4851 | void add_boundary_to_db(long long current_id, int admin_level, struct item_bin *item_bin_3, struct relation_member *memb) |
4852 | { |
4853 | char *str = NULL; |
4854 | struct node_lat_lon node_coords; |
4855 | |
4856 | // fprintf(stderr, "add_boundary_to_db:bid:%lld admin_level:%d\n", current_id, admin_level); |
4857 | |
4858 | sqlite3_bind_int64(stmt_bd_001, 1, current_id); |
4859 | |
4860 | if (admin_level < 2) |
4861 | { |
4862 | sqlite3_bind_int(stmt_bd_001, 2, 9999); |
4863 | } |
4864 | else |
4865 | { |
4866 | sqlite3_bind_int(stmt_bd_001, 2, admin_level); |
4867 | } |
4868 | |
4869 | while ((str = item_bin_get_attr(item_bin_3, attr_osm_member, str))) |
4870 | { |
4871 | if (get_relation_member(str, memb)) |
4872 | { |
4873 | if (memb->type == 2) |
4874 | { |
4875 | // way-id is "memb.id" |
4876 | // use the first nodes coords |
4877 | get_lat_lon_way_first_node(memb->id, &node_coords); |
4878 | if (node_coords.valid == 1) |
4879 | { |
4880 | sqlite3_bind_double(stmt_bd_001, 3, node_coords.lat); |
4881 | sqlite3_bind_double(stmt_bd_001, 4, node_coords.lon); |
4882 | } |
4883 | break; |
4884 | } |
4885 | } |
4886 | } |
4887 | sqlite3_bind_text(stmt_bd_001, 5, osm_tag_value(item_bin_3, "name"), -1, SQLITE_STATIC); |
4888 | sqlite3_step(stmt_bd_001); |
4889 | sqlite3_reset(stmt_bd_001); |
4890 | } |
4891 | |
4892 | |
4893 | void osm_add_member(int type, osmid ref, char *role) |
4894 | { |
4895 | char member_buffer[BUFFER_SIZE * 3 + 3]; |
4896 | struct attr memberattr = { attr_osm_member }; |
4897 | |
4898 | sprintf(member_buffer,"%d:"LONGLONG_FMT":%s", type, (long long) ref, role); |
4899 | memberattr.u.str = member_buffer; |
4900 | item_bin_add_attr(item_bin_2, &memberattr); |
4901 | } |
4902 | |
4903 | static void relation_add_tag(char *k, char *v) |
4904 | { |
4905 | int add_tag = 1; |
4906 | #if 0 |
4907 | fprintf(stderr,"add tag %s %s\n",k,v); |
4908 | #endif |
4909 | if (!strcmp(k, "type")) |
4910 | { |
4911 | strcpy(relation_type, v); |
4912 | add_tag = 0; |
4913 | } |
4914 | else if (!strcmp(k, "restriction")) |
4915 | { |
4916 | if (!strncmp(v, "no_", 3)) |
4917 | { |
4918 | item_bin_2->type = type_street_turn_restriction_no; |
4919 | add_tag = 0; |
4920 | } |
4921 | else if (!strncmp(v, "only_", 5)) |
4922 | { |
4923 | item_bin_2->type = type_street_turn_restriction_only; |
4924 | add_tag = 0; |
4925 | } |
4926 | else |
4927 | { |
4928 | item_bin_2->type = type_none; |
4929 | //osm_warning("relation", current_id, 0, "Unknown restriction %s\n", v); |
4930 | } |
4931 | } |
4932 | else if (!strcmp(k, "admin_level")) |
4933 | { |
4934 | admin_level = atoi(v); |
4935 | } |
4936 | else if (!strcmp(k, "boundary")) |
4937 | { |
4938 | if (!strcmp(v, "administrative") || (experimental && !strcmp(v, "postal_code"))) |
4939 | { |
4940 | boundary = 1; |
4941 | } |
4942 | } |
4943 | else if (!strcmp(k, "ISO3166-1")) |
4944 | { |
4945 | strcpy(iso_code, v); |
4946 | } |
4947 | |
4948 | if (add_tag) |
4949 | { |
4950 | //fprintf(stderr,"*TAG*%s=%s\n", k, v); |
4951 | char tag[strlen(k) + strlen(v) + 2]; |
4952 | sprintf(tag, "%s=%s", k, v); |
4953 | item_bin_add_attr_string(item_bin_2, attr_osm_tag, tag); |
4954 | } |
4955 | } |
4956 | |
4957 | static int attr_longest_match(struct attr_mapping **mapping, int mapping_count, enum item_type *types, int types_count) |
4958 | { |
4959 | int i, j, longest = 0, ret = 0, sum, val; |
4960 | struct attr_mapping *curr; |
4961 | for (i = 0; i < mapping_count; i++) |
4962 | { |
4963 | sum = 0; |
4964 | curr = mapping[i]; |
4965 | for (j = 0; j < curr->attr_present_idx_count; j++) |
4966 | { |
4967 | val = attr_present[curr->attr_present_idx[j]]; |
4968 | if (val) |
4969 | sum += val; |
4970 | else |
4971 | { |
4972 | sum = -1; |
4973 | break; |
4974 | } |
4975 | } |
4976 | if (sum > longest) |
4977 | { |
4978 | longest = sum; |
4979 | ret = 0; |
4980 | } |
4981 | if (sum > 0 && sum == longest && ret < types_count) |
4982 | types[ret++] = curr->type; |
4983 | } |
4984 | return ret; |
4985 | } |
4986 | |
4987 | static void attr_longest_match_clear(void) |
4988 | { |
4989 | memset(attr_present, 0, sizeof(*attr_present) * attr_present_count); |
4990 | } |
4991 | |
4992 | char* remove_all_spaces_non_utf8(char *str) |
4993 | { |
4994 | char *write = str, *read = str; |
4995 | |
4996 | if (str == NULL) |
4997 | { |
4998 | return NULL; |
4999 | } |
5000 | |
5001 | do |
5002 | { |
5003 | if (!g_ascii_isspace(*read)) |
5004 | { |
5005 | *write++ = *read; |
5006 | } |
5007 | } while (*read++); |
5008 | |
5009 | return str; |
5010 | } |
5011 | |
5012 | |
5013 | char* get_index_for_string(const char *in) |
5014 | { |
5015 | // first letters for indexing faster later |
5016 | char *sub = g_strndup(in, 2); |
5017 | |
5018 | |
5019 | // check first letter |
5020 | if (strlen(sub) > 0) |
5021 | { |
5022 | if ((sub[0] < 97) || (sub[0]) > 122) |
5023 | { |
5024 | sub[0]='\0'; |
5025 | // fprintf(stderr, "(1)in=%s sub=%s\n", in, sub); |
5026 | return sub; |
5027 | } |
5028 | } |
5029 | |
5030 | // if second letter != a-z then delete it from index |
5031 | if (strlen(sub) > 1) |
5032 | { |
5033 | // 'a' 'z' |
5034 | if ((sub[1] < 97) || (sub[1]) > 122) |
5035 | { |
5036 | sub[1]='\0'; |
5037 | } |
5038 | } |
5039 | |
5040 | // fprintf(stderr, "(2)in=%s sub=%s\n", in, sub); |
5041 | return sub; |
5042 | } |
5043 | |
5044 | |
5045 | |
5046 | static int tab_atan[]= |
5047 | { 0,262,524,787,1051,1317,1584,1853,2126,2401,2679,2962,3249,3541,3839,4142,4452,4770,5095,5430,5774,6128,6494,6873,7265,7673,8098,8541,9004,9490,10000,10538}; |
5048 | |
5049 | static int |
5050 | atan2_int_lookup(int val) |
5051 | { |
5052 | int len=sizeof(tab_atan)/sizeof(int); |
5053 | int i=len/2; |
5054 | int p=i-1; |
5055 | |
5056 | for (;;) |
5057 | { |
5058 | i>>=1; |
5059 | if (val < tab_atan[p]) |
5060 | { |
5061 | p-=i; |
5062 | } |
5063 | else |
5064 | { |
5065 | if (val < tab_atan[p+1]) |
5066 | { |
5067 | return p+(p>>1); |
5068 | } |
5069 | else |
5070 | { |
5071 | p+=i; |
5072 | } |
5073 | } |
5074 | } |
5075 | } |
5076 | |
5077 | |
5078 | inline double my_atan2_double(double x, double y) |
5079 | { |
5080 | double result; |
5081 | |
5082 | asm ( |
5083 | "fpatan\n\t" |
5084 | : "=t" (result) // outputs; t = top of fpu stack |
5085 | : "0" (x), // inputs; 0 = same as result |
5086 | "u" (y) // u = 2nd floating point register |
5087 | ); |
5088 | |
5089 | return result; |
5090 | } |
5091 | |
5092 | |
5093 | static int |
5094 | atan2_int(int dx, int dy) |
5095 | { |
5096 | int mul=1,add=0,ret; |
5097 | |
5098 | if (! dx) |
5099 | { |
5100 | return dy < 0 ? 180 : 0; |
5101 | } |
5102 | |
5103 | if (! dy) |
5104 | { |
5105 | return dx < 0 ? -90 : 90; |
5106 | } |
5107 | |
5108 | if (dx < 0) |
5109 | { |
5110 | dx=-dx; |
5111 | mul=-1; |
5112 | } |
5113 | |
5114 | if (dy < 0) |
5115 | { |
5116 | dy=-dy; |
5117 | add=180*mul; |
5118 | mul*=-1; |
5119 | } |
5120 | |
5121 | while (dx > 20000 || dy > 20000) |
5122 | { |
5123 | dx/=10; |
5124 | dy/=10; |
5125 | } |
5126 | |
5127 | if (dx > dy) |
5128 | { |
5129 | ret=90-atan2_int_lookup(dy*10000/dx); |
5130 | } |
5131 | else |
5132 | { |
5133 | ret=atan2_int_lookup(dx*10000/dy); |
5134 | } |
5135 | |
5136 | return ret*mul+add; |
5137 | } |
5138 | |
5139 | |
5140 | |
5141 | static int maptool_get_angle_delta(struct coord *c1, struct coord *c2, int dir) |
5142 | { |
5143 | int dx = c2->x - c1->x; |
5144 | int dy = c2->y - c1->y; |
5145 | |
5146 | // fprintf(stderr, "angle: %d %d %d %d\n", c1->x, c1->y, c2->x, c2->y); |
5147 | |
5148 | #if 0 |
5149 | double angle; |
5150 | angle = my_atan2_double(dy, dx); |
5151 | angle *= 57.29577952019129709110; // ( 180/ M_PI ) = 57.29577952019129709110 |
5152 | //fprintf(stderr, "1 angle=%lf\n", angle); |
5153 | #endif |
5154 | |
5155 | #if 0 |
5156 | double angle; |
5157 | angle = atan2(dx, dy); |
5158 | angle *= 57.29577952019129709110; // ( 180/ M_PI ) = 57.29577952019129709110 |
5159 | fprintf(stderr, "2 angle=%lf\n", angle); |
5160 | #endif |
5161 | |
5162 | #if 1 |
5163 | int angle; |
5164 | angle=atan2_int(dx,dy); |
5165 | //fprintf(stderr, "3 angle=%d\n", (int)(angle)); |
5166 | #endif |
5167 | |
5168 | if (dir == -1) |
5169 | { |
5170 | angle = angle - 180; |
5171 | } |
5172 | |
5173 | if (angle < 0) |
5174 | { |
5175 | angle += 360; |
5176 | } |
5177 | |
5178 | return angle; |
5179 | } |
5180 | |
5181 | |
5182 | /** |
5183 | * @brief Calculates the delta between two angles |
5184 | * @param angle1 The first angle |
5185 | * @param angle2 The second angle |
5186 | * @return The difference between the angles: -179..-1=angle2 is left of angle1,0=same,1..179=angle2 is right of angle1,180=angle1 is opposite of angle2 |
5187 | */ |
5188 | static int maptool_delta_angle(int angle1, int angle2) |
5189 | { |
5190 | int delta = angle2 - angle1; |
5191 | |
5192 | if (delta <= -180) |
5193 | { |
5194 | delta += 360; |
5195 | } |
5196 | |
5197 | if (delta > 180) |
5198 | { |
5199 | delta -= 360; |
5200 | } |
5201 | |
5202 | return delta; |
5203 | } |
5204 | |
5205 | |
5206 | clock_t maptool_debug_measure_start(void) |
5207 | { |
5208 | clock_t start = clock(); |
5209 | return start; |
5210 | } |
5211 | |
5212 | clock_t maptool_debug_measure_end(clock_t start_time) |
5213 | { |
5214 | clock_t diff_time = clock() - start_time; |
5215 | return diff_time; |
5216 | } |
5217 | |
5218 | int maptool_debug_measure_end_tsecs(clock_t start_time) |
5219 | { |
5220 | clock_t diff_time = clock() - start_time; |
5221 | return (int) (((double) diff_time / (double) CLOCKS_PER_SEC) * 1000); |
5222 | } |
5223 | |
5224 | void maptool_debug_measure_result_str(clock_t diff, char *buffer) |
5225 | { |
5226 | sprintf(buffer, "elapsed: %fs\n", (diff / CLOCKS_PER_SEC)); |
5227 | } |
5228 | |
5229 | void maptool_debug_mrp(clock_t diff) |
5230 | { |
5231 | fprintf(stderr, "angle el:%fs\n", (double) ((double) diff / (double) CLOCKS_PER_SEC)); |
5232 | } |
5233 | |
5234 | |
5235 | |
5236 | static int maptool_get_node_x_y(long long way_id, int node_num_in_way, struct coord *c_ret) |
5237 | { |
5238 | int ret = 0; |
5239 | struct node_lat_lon node_coords2; |
5240 | |
5241 | // fprintf(stderr, "angle way id=%lld\n", way_id); |
5242 | |
5243 | long long way_node = get_waynode_num_have_seekpos(way_id, node_num_in_way, 0, (off_t)seekpos1); |
5244 | |
5245 | if (way_node > 0) |
5246 | { |
5247 | // fprintf(stderr, "angle way node id=%lld\n", way_node); |
5248 | |
5249 | get_lat_lon_for_node(way_node, &node_coords2); |
5250 | if (node_coords2.valid == 1) |
5251 | { |
5252 | //c_ret->x = transform_from_geo_lon(node_coords2.lon); |
5253 | c_ret->x = (int)(node_coords2.lon * 100000.0); |
5254 | |
5255 | //c_ret->y = transform_from_geo_lat(node_coords2.lat); |
5256 | c_ret->y = (int)(node_coords2.lat * 100000.0); |
5257 | |
5258 | // save coord of way_node |
5259 | // coord_buffer_3[node_num_in_way].x = c_ret->x; |
5260 | // coord_buffer_3[node_num_in_way].y = c_ret->y; |
5261 | |
5262 | // fprintf(stderr, "angle node_num=%d x=%d y=%d lon=%f lat=%f\n", node_num_in_way, c_ret->x, c_ret->y, node_coords2.lon, node_coords2.lat); |
5263 | ret = 1; |
5264 | } |
5265 | } |
5266 | |
5267 | return ret; |
5268 | } |
5269 | |
5270 | |
5271 | static void osm_write_cycle_way(FILE *ways_file, int i, int type, struct coord *coord_buffer_2, int start_node_num_in_way, int node_count, int part_num) |
5272 | { |
5273 | int *def_flags, add_flags; |
5274 | struct item_bin *item_bin; |
5275 | |
5276 | item_bin = init_item(type, 0); |
5277 | def_flags = item_get_default_flags(type); |
5278 | |
5279 | // struct coord *coord_buffer_4 = &coord_buffer_3[start_node_num_in_way]; |
5280 | struct coord *coord_buffer_4 = &coord_buffer[start_node_num_in_way]; |
5281 | item_bin_add_coord(item_bin, coord_buffer_4, node_count); |
5282 | |
5283 | // fprintf(stderr, "Xangle node_num=%d count=%d wayid=%lld\n", start_node_num_in_way, node_count, osmid_attr_value); |
5284 | //int ii; |
5285 | //for (ii=0;ii<node_count;ii++) |
5286 | //{ |
5287 | // fprintf(stderr, "Yangle node_num=%d x=%d y=%d\n", ii, coord_buffer_4[ii].x, coord_buffer_4[ii].y); |
5288 | //} |
5289 | |
5290 | if (def_flags) |
5291 | { |
5292 | flags_attr_value = (*def_flags | flags[0] | flags[1]) & ~flags[2]; |
5293 | // only add flags if they differ from the default flags!! |
5294 | if (flags_attr_value != *def_flags) |
5295 | { |
5296 | add_flags = 1; |
5297 | } |
5298 | } |
5299 | else // maybe should explicitly specify which "types" to consider? now its all "types" |
5300 | { |
5301 | def_flags = 0; |
5302 | flags_attr_value = (flags[0] | flags[1]) & ~flags[2]; |
5303 | |
5304 | // only add flags if we really have a value |
5305 | if (flags_attr_value != 0) |
5306 | { |
5307 | add_flags = 1; |
5308 | } |
5309 | } |
5310 | |
5311 | item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]); |
5312 | |
5313 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
5314 | |
5315 | if (add_flags) |
5316 | { |
5317 | item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); |
5318 | } |
5319 | |
5320 | // ------- add DEBUG ATTR -------- |
5321 | item_bin_add_attr_int(item_bin, attr_debugsplitway, start_node_num_in_way); |
5322 | // ------- add DEBUG ATTR -------- |
5323 | |
5324 | if (maxspeed_attr_value) |
5325 | { |
5326 | item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); |
5327 | } |
5328 | |
5329 | // custom color attribute |
5330 | if (attr_strings[attr_string_colour_]) |
5331 | { |
5332 | unsigned int cc = color_int_value_from_string(attr_strings[attr_string_colour_]); |
5333 | //fprintf(stderr, "col:ret=%d\n", cc); |
5334 | if (cc != 0) |
5335 | { |
5336 | cc = (cc >> 8); |
5337 | //fprintf(stderr, "col:in map=%d\n", (int)cc); |
5338 | item_bin_add_attr_int(item_bin, attr_colour2, (int)cc); |
5339 | } |
5340 | } |
5341 | |
5342 | item_bin_write(item_bin, ways_file); |
5343 | } |
5344 | |
5345 | long long cycle_w_processed_count = 0; |
5346 | |
5347 | void osm_end_way(struct maptool_osm *osm) |
5348 | { |
5349 | int i, count; |
5350 | int *def_flags, add_flags; |
5351 | enum item_type types[10]; |
5352 | struct item_bin *item_bin; |
5353 | int count_lines = 0, count_areas = 0; |
5354 | int dont_save_to_db = 1; |
5355 | int first = 1; |
5356 | int retval; |
5357 | char *name_folded = NULL; |
5358 | char *name_folded2 = NULL; |
5359 | struct node_lat_lon node_coords; |
5360 | osmid w_node; |
5361 | int write_this_item_to_binfile; |
5362 | off_t seek_posx = 0; |
5363 | |
5364 | in_way = 0; |
5365 | |
5366 | if (!osm->ways) |
5367 | { |
5368 | return; |
5369 | } |
5370 | |
5371 | ways_processed_count++; |
5372 | |
5373 | write_this_item_to_binfile = 1; |
5374 | |
5375 | count = attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types) / sizeof(enum item_type)); |
5376 | if (!count) |
5377 | { |
5378 | count = 1; |
5379 | types[0] = type_street_unkn; |
5380 | } |
5381 | |
5382 | if (count >= 10) |
5383 | { |
5384 | fprintf_(stderr, "way id %lld\n", osmid_attr_value); |
5385 | dbg_assert(count < 10); |
5386 | } |
5387 | |
5388 | if (attr_strings[attr_string_label] != NULL) |
5389 | { |
5390 | if (strlen(attr_strings[attr_string_label]) > 0) |
5391 | { |
5392 | dont_save_to_db = 0; |
5393 | |
5394 | // check if "alt name" is same as normal name |
5395 | if (attr_strings[attr_string_label_alt] != NULL) |
5396 | { |
5397 | if (!strcmp(attr_strings[attr_string_label], attr_strings[attr_string_label_alt])) |
5398 | { |
5399 | // strings are the same, clear "alt name" |
5400 | attr_strings[attr_string_label_alt] = NULL; |
5401 | } |
5402 | } |
5403 | } |
5404 | } |
5405 | |
5406 | // required for fread to work! |
5407 | fseeko(ways_ref_file, 0L, SEEK_CUR); |
5408 | |
5409 | |
5410 | // correct bicycle flags ------------------------------------------------------------------------ |
5411 | if ((flags[0] & NAVIT_AF_ONEWAY) || (flags[0] & NAVIT_AF_ONEWAYREV)) // it's a one way road |
5412 | { |
5413 | if (flags[0] & NAVIT_AF_ONEWAY_BICYCLE_NO) // bike against oneway |
5414 | { |
5415 | flags[0] = (flags[0] & ~NAVIT_AF_BICYCLE_LANE); // remove the lane flag |
5416 | flags[0] = (flags[0] & ~NAVIT_AF_BICYCLE_TRACK); // remove the track flag |
5417 | } |
5418 | flags[0] = (flags[0] & ~NAVIT_AF_ONEWAY_BICYCLE_YES); // its already oneway, so remove additional oneway-bike flag |
5419 | } |
5420 | else // no oneway |
5421 | { |
5422 | flags[0] = (flags[0] & ~NAVIT_AF_ONEWAY_BICYCLE_NO); // remove the bike against-oneway-road flag, if no oneway road |
5423 | } |
5424 | // correct bicycle flags ------------------------------------------------------------------------ |
5425 | |
5426 | |
5427 | |
5428 | |
5429 | |
5430 | // check if its a bicycle way and also a footway, remove footway then!! ------------------------- |
5431 | int is_cycleway = -1; |
5432 | int is_footway = -1; |
5433 | for (i = 0; i < count; i++) |
5434 | { |
5435 | // cycleway |
5436 | // footway |
5437 | if (types[i] == type_cycleway) |
5438 | { |
5439 | is_cycleway = i; |
5440 | } |
5441 | else if (types[i] == type_footway) |
5442 | { |
5443 | is_footway = i; |
5444 | } |
5445 | } |
5446 | |
5447 | if ((is_footway > -1) && (is_cycleway > -1)) |
5448 | { |
5449 | types[is_footway] = type_none; // remove the footway |
5450 | } |
5451 | // check if its a bicycle way and also a footway, remove footway then!! ------------------------- |
5452 | |
5453 | |
5454 | |
5455 | for (i = 0; i < count; i++) // loop thru all the attributes of this way (and add a way for every attribute known -> so ways get duplicated here!!) |
5456 | { |
5457 | add_flags = 0; |
5458 | write_this_item_to_binfile = 1; |
5459 | if (types[i] == type_none) |
5460 | { |
5461 | continue; |
5462 | } |
5463 | |
5464 | //if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) |
5465 | // continue; |
5466 | |
5467 | // DO NOT exclude unknown streets here, or city-to-countrypolygon matching won't work!! |
5468 | if (ignore_unkown && (types[i] == type_point_unkn)) |
5469 | { |
5470 | continue; |
5471 | } |
5472 | |
5473 | |
5474 | if (types[i] == type_cycleway) |
5475 | { |
5476 | |
5477 | // fprintf(stderr, "C=%lld W=%lld\n", cycle_w_processed_count, ways_processed_count); |
5478 | |
5479 | // check if we have a turn inside this way with angle greater than ROAD_ANGLE_MIN_FOR_TURN_BICYCLEMODE |
5480 | int i_coord; |
5481 | int i_coord_prev = 0; |
5482 | struct coord c1_; |
5483 | struct coord c2_; |
5484 | struct coord c3_; |
5485 | int angle_way_1; |
5486 | int angle_way_2; |
5487 | int angle_way_delta; |
5488 | osmid way_node; |
5489 | int is_valid_; |
5490 | int fff = 1; |
5491 | int split_part_num; |
5492 | struct coord *coord_buffer_2 = NULL; |
5493 | |
5494 | if (coord_count > 2) |
5495 | { |
5496 | if (osmid_attr_value > 0) |
5497 | { |
5498 | cycle_w_processed_count++; |
5499 | |
5500 | coord_buffer_2 = &coord_buffer[0]; // point to first real coordinate of way |
5501 | split_part_num = 1; |
5502 | |
5503 | for (i_coord = 1; i_coord < (coord_count - 1); i_coord++) |
5504 | { |
5505 | is_valid_ = 0; |
5506 | |
5507 | //fprintf(stderr, "angle i_coord=%d\n", i_coord); |
5508 | |
5509 | if (fff == 1) |
5510 | { |
5511 | is_valid_ = is_valid_ + (maptool_get_node_x_y(osmid_attr_value, (i_coord - 1), &c1_)); |
5512 | is_valid_ = is_valid_ + (maptool_get_node_x_y(osmid_attr_value, i_coord, &c2_)); |
5513 | fff = 0; |
5514 | } |
5515 | else |
5516 | { |
5517 | c1_.x = c2_.x; |
5518 | c1_.y = c2_.y; |
5519 | c2_.x = c3_.x; |
5520 | c2_.y = c3_.y; |
5521 | is_valid_++; |
5522 | is_valid_++; |
5523 | } |
5524 | |
5525 | if (is_valid_ == 2) |
5526 | { |
5527 | angle_way_1 = maptool_get_angle_delta(&c1_, &c2_, 1); |
5528 | //fprintf(stderr, "angle1=%d\n", angle_way_1); |
5529 | } |
5530 | |
5531 | is_valid_++; |
5532 | is_valid_ = is_valid_ + (maptool_get_node_x_y(osmid_attr_value, (i_coord + 1), &c3_)); |
5533 | |
5534 | if (is_valid_ == 4) |
5535 | { |
5536 | angle_way_2 = maptool_get_angle_delta(&c2_, &c3_, 1); |
5537 | //fprintf(stderr, "angle2=%d\n", angle_way_2); |
5538 | |
5539 | angle_way_delta = abs(maptool_delta_angle(angle_way_1, angle_way_2)); |
5540 | //fprintf(stderr, "angle_way_delta=%d\n", angle_way_delta); |
5541 | |
5542 | if (angle_way_delta >= ROAD_ANGLE_MIN_FOR_TURN_BICYCLEMODE) |
5543 | { |
5544 | // dont write this item to binfile in the normal way |
5545 | write_this_item_to_binfile = 0; |
5546 | |
5547 | //fprintf(stderr, "angle cut at node:%d prevnode:%d\n", i_coord, i_coord_prev); |
5548 | osm_write_cycle_way(osm->ways, i, types[i], coord_buffer_2, i_coord_prev, (i_coord - i_coord_prev + 1), split_part_num); |
5549 | i_coord_prev = i_coord; |
5550 | coord_buffer_2 = coord_buffer_2 + (i_coord - i_coord_prev); // move pointer to next starting coord of split-way |
5551 | split_part_num++; |
5552 | } |
5553 | } |
5554 | } |
5555 | |
5556 | if (write_this_item_to_binfile == 0) |
5557 | { |
5558 | //fprintf(stderr, "angle: write last part node:%d prevnode:%d\n", i_coord, i_coord_prev); |
5559 | // write last part of split-way |
5560 | osm_write_cycle_way(osm->ways, i, types[i], coord_buffer_2, i_coord_prev, (i_coord - i_coord_prev + 1), split_part_num); |
5561 | } |
5562 | } |
5563 | } |
5564 | } |
5565 | |
5566 | |
5567 | if (types[i] != type_street_unkn) |
5568 | { |
5569 | if (types[i] < type_area) |
5570 | { |
5571 | count_lines++; |
5572 | } |
5573 | else |
5574 | { |
5575 | count_areas++; |
5576 | } |
5577 | } |
5578 | item_bin = init_item(types[i], 0); |
5579 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
5580 | def_flags = item_get_default_flags(types[i]); |
5581 | |
5582 | // save nodes of way ----------------- |
5583 | // save nodes of way ----------------- |
5584 | |
5585 | if (coastline_only_map == 1) |
5586 | { |
5587 | first = 0; |
5588 | } |
5589 | |
5590 | if (first == 1) |
5591 | { |
5592 | first = 0; |
5593 | int i788 = 0; |
5594 | struct coord *c788 = (struct coord *) (item_bin + 1); // set pointer to coord struct of this item |
5595 | for (i788 = 0; i788 < item_bin->clen / 2; i788++) |
5596 | { |
5597 | if (dont_save_to_db == 0) |
5598 | { |
5599 | // save lat,lon of first node of this way |
5600 | if (i788 == 0) |
5601 | { |
5602 | #ifdef MAPTOOL_USE_SQL |
5603 | //fprintf(stderr, "insert -w\n"); |
5604 | //fprintf(stderr, "ways DEBUG: wid:%ld\n", osmid_attr_value); |
5605 | //fprintf(stderr, "ways DEBUG: nid:%lld\n", first_node_of_current_way); |
5606 | get_lat_lon_for_node(first_node_of_current_way, &node_coords); |
5607 | |
5608 | if (sql_counter == 0) |
5609 | { |
5610 | retval = sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
5611 | if ((retval > 0) && (retval < 100)) |
5612 | { |
5613 | fprintf_(stderr, "==================================\n"); |
5614 | fprintf_(stderr, "begin: ways code:%d\n", retval); |
5615 | retval = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
5616 | fprintf_(stderr, "begin:(commit) ways code:%d\n", retval); |
5617 | retval = sqlite3_exec(sql_handle, "BEGIN", 0, 0, 0); |
5618 | fprintf_(stderr, "begin:(begin) ways code:%d\n", retval); |
5619 | fprintf_(stderr, "==================================\n"); |
5620 | } |
5621 | else |
5622 | { |
5623 | //fprintf(stderr, "begin: ways\n"); |
5624 | } |
5625 | } |
5626 | |
5627 | |
5628 | // only save this way info to way table (used for index search) if its not a nonsearch way (like river, or some district outline) |
5629 | |
5630 | if (!item_not_for_search_index(types[i])) |
5631 | { |
5632 | |
5633 | sql_counter++; |
5634 | |
5635 | // save ORIG name to DB ------------------------------------- |
5636 | sqlite3_bind_int64(stmt_way, 1, osmid_attr_value); |
5637 | sqlite3_bind_text(stmt_way, 2, attr_strings[attr_string_label], -1, SQLITE_STATIC); |
5638 | |
5639 | // streetname folded for later sort/search |
5640 | char *sub = NULL; |
5641 | name_folded = linguistics_casefold(attr_strings[attr_string_label]); |
5642 | if (name_folded) |
5643 | { |
5644 | name_folded2 = linguistics_remove_all_specials(name_folded); |
5645 | if (name_folded2) |
5646 | { |
5647 | g_free(name_folded); |
5648 | name_folded = name_folded2; |
5649 | } |
5650 | |
5651 | name_folded2 = linguistics_expand_special(name_folded, 1); |
5652 | if (name_folded2) |
5653 | { |
5654 | sqlite3_bind_text(stmt_way, 6, name_folded2, -1, SQLITE_STATIC); |
5655 | sub = get_index_for_string(name_folded2); |
5656 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
5657 | } |
5658 | else |
5659 | { |
5660 | sqlite3_bind_text(stmt_way, 6, name_folded, -1, SQLITE_STATIC); |
5661 | sub = get_index_for_string(name_folded); |
5662 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
5663 | } |
5664 | } |
5665 | else |
5666 | { |
5667 | // use original string |
5668 | sqlite3_bind_text(stmt_way, 6, attr_strings[attr_string_label], -1, SQLITE_STATIC); |
5669 | sub = get_index_for_string(attr_strings[attr_string_label]); |
5670 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
5671 | } |
5672 | |
5673 | // town id |
5674 | sqlite3_bind_int(stmt_way, 3, -1); |
5675 | |
5676 | if (node_coords.valid == 1) |
5677 | { |
5678 | // lat |
5679 | sqlite3_bind_double(stmt_way, 4, node_coords.lat); |
5680 | // lon |
5681 | sqlite3_bind_double(stmt_way, 5, node_coords.lon); |
5682 | } |
5683 | |
5684 | // waytype |
5685 | if (types[i] != type_street_unkn) |
5686 | { |
5687 | sqlite3_bind_int(stmt_way, 8, 1); |
5688 | } |
5689 | else |
5690 | { |
5691 | // type -> POI |
5692 | sqlite3_bind_int(stmt_way, 8, 40); |
5693 | } |
5694 | |
5695 | // retval = |
5696 | sqlite3_step(stmt_way); |
5697 | //if ((retval > 0) && (retval < 100)) |
5698 | //{ |
5699 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
5700 | //} |
5701 | sqlite3_reset(stmt_way); |
5702 | |
5703 | if (name_folded) |
5704 | { |
5705 | g_free(name_folded); |
5706 | } |
5707 | |
5708 | if (name_folded2) |
5709 | { |
5710 | g_free(name_folded2); |
5711 | } |
5712 | |
5713 | if (sub) |
5714 | { |
5715 | g_free(sub); |
5716 | } |
5717 | // save ORIG name to DB ------------------------------------- |
5718 | |
5719 | // save alternate name to DB aswell ------------------------------------- |
5720 | if (attr_strings[attr_string_label_real_alt]) |
5721 | { |
5722 | sqlite3_bind_int64(stmt_way, 1, osmid_attr_value); |
5723 | sqlite3_bind_text(stmt_way, 2, attr_strings[attr_string_label_real_alt], -1, SQLITE_STATIC); |
5724 | |
5725 | |
5726 | // streetname folded for later sort/search |
5727 | char *sub = NULL; |
5728 | name_folded = linguistics_casefold(attr_strings[attr_string_label_real_alt]); |
5729 | if (name_folded) |
5730 | { |
5731 | name_folded2 = linguistics_remove_all_specials(name_folded); |
5732 | if (name_folded2) |
5733 | { |
5734 | g_free(name_folded); |
5735 | name_folded = name_folded2; |
5736 | } |
5737 | |
5738 | name_folded2 = linguistics_expand_special(name_folded, 1); |
5739 | if (name_folded2) |
5740 | { |
5741 | sqlite3_bind_text(stmt_way, 6, name_folded2, -1, SQLITE_STATIC); |
5742 | sub = get_index_for_string(name_folded2); |
5743 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
5744 | } |
5745 | else |
5746 | { |
5747 | sqlite3_bind_text(stmt_way, 6, name_folded, -1, SQLITE_STATIC); |
5748 | sub = get_index_for_string(name_folded); |
5749 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
5750 | } |
5751 | } |
5752 | else |
5753 | { |
5754 | // use original string |
5755 | sqlite3_bind_text(stmt_way, 6, attr_strings[attr_string_label_real_alt], -1, SQLITE_STATIC); |
5756 | sub = get_index_for_string(attr_strings[attr_string_label_real_alt]); |
5757 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
5758 | } |
5759 | |
5760 | // town id |
5761 | sqlite3_bind_int(stmt_way, 3, -1); |
5762 | |
5763 | if (node_coords.valid == 1) |
5764 | { |
5765 | // lat |
5766 | sqlite3_bind_double(stmt_way, 4, node_coords.lat); |
5767 | // lon |
5768 | sqlite3_bind_double(stmt_way, 5, node_coords.lon); |
5769 | } |
5770 | |
5771 | // waytype |
5772 | if (types[i] != type_street_unkn) |
5773 | { |
5774 | sqlite3_bind_int(stmt_way, 8, 3); |
5775 | } |
5776 | else |
5777 | { |
5778 | // type -> POI |
5779 | sqlite3_bind_int(stmt_way, 8, 40); |
5780 | } |
5781 | |
5782 | // retval = |
5783 | sqlite3_step(stmt_way); |
5784 | //if ((retval > 0) && (retval < 100)) |
5785 | //{ |
5786 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
5787 | //} |
5788 | sqlite3_reset(stmt_way); |
5789 | |
5790 | if (name_folded) |
5791 | { |
5792 | g_free(name_folded); |
5793 | } |
5794 | |
5795 | if (name_folded2) |
5796 | { |
5797 | g_free(name_folded2); |
5798 | } |
5799 | |
5800 | if (sub) |
5801 | { |
5802 | g_free(sub); |
5803 | } |
5804 | |
5805 | } |
5806 | // save alternate name to DB aswell ------------------------------------- |
5807 | |
5808 | |
5809 | // save english name to DB aswell ------------------------------------- |
5810 | if (attr_strings[attr_string_label_alt]) |
5811 | { |
5812 | sqlite3_bind_int64(stmt_way, 1, osmid_attr_value); |
5813 | sqlite3_bind_text(stmt_way, 2, attr_strings[attr_string_label_alt], -1, SQLITE_STATIC); |
5814 | |
5815 | |
5816 | // streetname folded for later sort/search |
5817 | char *sub = NULL; |
5818 | name_folded = linguistics_casefold(attr_strings[attr_string_label_alt]); |
5819 | if (name_folded) |
5820 | { |
5821 | name_folded2 = linguistics_remove_all_specials(name_folded); |
5822 | if (name_folded2) |
5823 | { |
5824 | g_free(name_folded); |
5825 | name_folded = name_folded2; |
5826 | } |
5827 | |
5828 | name_folded2 = linguistics_expand_special(name_folded, 1); |
5829 | if (name_folded2) |
5830 | { |
5831 | sqlite3_bind_text(stmt_way, 6, name_folded2, -1, SQLITE_STATIC); |
5832 | sub = get_index_for_string(name_folded2); |
5833 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
5834 | } |
5835 | else |
5836 | { |
5837 | sqlite3_bind_text(stmt_way, 6, name_folded, -1, SQLITE_STATIC); |
5838 | sub = get_index_for_string(name_folded); |
5839 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
5840 | } |
5841 | } |
5842 | else |
5843 | { |
5844 | // use original string |
5845 | sqlite3_bind_text(stmt_way, 6, attr_strings[attr_string_label_alt], -1, SQLITE_STATIC); |
5846 | sub = get_index_for_string(attr_strings[attr_string_label_alt]); |
5847 | sqlite3_bind_text(stmt_way, 7, sub, -1, SQLITE_STATIC); |
5848 | } |
5849 | |
5850 | // town id |
5851 | sqlite3_bind_int(stmt_way, 3, -1); |
5852 | |
5853 | if (node_coords.valid == 1) |
5854 | { |
5855 | // lat |
5856 | sqlite3_bind_double(stmt_way, 4, node_coords.lat); |
5857 | // lon |
5858 | sqlite3_bind_double(stmt_way, 5, node_coords.lon); |
5859 | } |
5860 | |
5861 | // waytype |
5862 | if (types[i] != type_street_unkn) |
5863 | { |
5864 | sqlite3_bind_int(stmt_way, 8, 2); |
5865 | } |
5866 | else |
5867 | { |
5868 | // type -> POI |
5869 | sqlite3_bind_int(stmt_way, 8, 40); |
5870 | } |
5871 | |
5872 | // retval = |
5873 | sqlite3_step(stmt_way); |
5874 | //if ((retval > 0) && (retval < 100)) |
5875 | //{ |
5876 | // fprintf(stderr, "ways step: code:%d wid:%lld\n", retval, osmid_attr_value); |
5877 | //} |
5878 | sqlite3_reset(stmt_way); |
5879 | |
5880 | if (name_folded) |
5881 | { |
5882 | g_free(name_folded); |
5883 | } |
5884 | |
5885 | if (name_folded2) |
5886 | { |
5887 | g_free(name_folded2); |
5888 | } |
5889 | |
5890 | if (sub) |
5891 | { |
5892 | g_free(sub); |
5893 | } |
5894 | |
5895 | } |
5896 | // save english name to DB aswell ------------------------------------- |
5897 | |
5898 | } |
5899 | |
5900 | |
5901 | if (sql_counter > MAX_ROWS_WO_COMMIT_3) |
5902 | { |
5903 | sql_counter = 0; |
5904 | retval = sqlite3_exec(sql_handle, "COMMIT", 0, 0, 0); |
5905 | if ((retval > 0) && (retval < 100)) |
5906 | { |
5907 | fprintf_(stderr, "ways: %lld code:%d\n", ways_processed_count, retval); |
5908 | } |
5909 | else |
5910 | { |
5911 | //fprintf(stderr, "ways: %lld\n", ways_processed_count); |
5912 | } |
5913 | } |
5914 | #endif |
5915 | // set ref file to start of waynodes of current way |
5916 | // fprintf(stderr, "w seek1 pos=%lld\n", seekpos1); |
5917 | seek_posx = ftello(ways_ref_file); |
5918 | if ((off_t)seek_posx != (off_t)seekpos1) |
5919 | { |
5920 | fseeko(ways_ref_file, (off_t)seekpos1, SEEK_SET); |
5921 | } |
5922 | } |
5923 | // save all the way nodes for streets |
5924 | int fret = (int)fread(&w_node, sizeof(osmid), 1, ways_ref_file); |
5925 | if (fret == 0) |
5926 | { |
5927 | fprintf(stderr, "**ERROR** at fread 001a: wayid:%lld count=%d\n", osmid_attr_value, (int)i788); |
5928 | } |
5929 | else if ((osmid)w_node > 4994968164L) |
5930 | { |
5931 | fprintf(stderr, "**ERROR** at fread 001b: wayid:%lld count=%d w_node=%lld\n", osmid_attr_value, (int)i788, (osmid)w_node); |
5932 | } |
5933 | // fprintf(stderr, "at fread: w_node:%lld\n", (osmid)w_node); |
5934 | // save first node of WAYS with name/label into db |
5935 | add_waynode_to_db((osmid)w_node, (int)i788); |
5936 | } |
5937 | else // rest of ways |
5938 | { |
5939 | // save all the waynodes to db |
5940 | if (i788 == 0) |
5941 | { |
5942 | // set ref file to start of waynodes of current way |
5943 | // fprintf(stderr, "w seek1.1 pos=%lld\n", seekpos1); |
5944 | seek_posx = ftello(ways_ref_file); |
5945 | if ((off_t)seek_posx != (off_t)seekpos1) |
5946 | { |
5947 | fseeko(ways_ref_file, (off_t)seekpos1, SEEK_SET); |
5948 | } |
5949 | } |
5950 | |
5951 | int fret = (int)fread(&w_node, sizeof(osmid), 1, ways_ref_file); |
5952 | if (fret == 0) |
5953 | { |
5954 | fprintf(stderr, "**ERROR** at fread 001.1a: wayid:%lld count=%d\n", osmid_attr_value, (int)i788); |
5955 | } |
5956 | else if ((osmid)w_node > 4994968164L) |
5957 | { |
5958 | fprintf(stderr, "**ERROR** at fread 001.1b: wayid:%lld count=%d w_node=%lld\n", osmid_attr_value, (int)i788, (osmid)w_node); |
5959 | } |
5960 | // save first node of ALL WAYS into db |
5961 | add_waynode_to_db((osmid)w_node, (int)i788); |
5962 | } |
5963 | } |
5964 | |
5965 | if (dont_save_to_db == 0) |
5966 | { |
5967 | // seek to end of file (this should not be needed, because we read values until EOF anyway) |
5968 | // fprintf(stderr, "w seek2\n"); |
5969 | fseeko(ways_ref_file, 0, SEEK_END); |
5970 | } |
5971 | } |
5972 | // save nodes of way ----------------- |
5973 | // save nodes of way ----------------- |
5974 | |
5975 | |
5976 | if (def_flags) |
5977 | { |
5978 | flags_attr_value = (*def_flags | flags[0] | flags[1]) & ~flags[2]; |
5979 | // only add flags if they differ from the default flags!! |
5980 | if (flags_attr_value != *def_flags) |
5981 | { |
5982 | add_flags = 1; |
5983 | } |
5984 | } |
5985 | else // maybe should explicitly specify which "types" to consider? now its all "types" |
5986 | { |
5987 | def_flags = 0; |
5988 | flags_attr_value = (flags[0] | flags[1]) & ~flags[2]; |
5989 | |
5990 | // only add flags if we really have a value |
5991 | if (flags_attr_value != 0) |
5992 | { |
5993 | add_flags = 1; |
5994 | } |
5995 | } |
5996 | item_bin_add_attr_string(item_bin, def_flags ? attr_street_name : attr_label, attr_strings[attr_string_label]); |
5997 | |
5998 | // housenumber from buildings -------------------- |
5999 | if (types[i] == type_poly_building) |
6000 | { |
6001 | // addr:street |
6002 | item_bin_add_attr_string(item_bin, attr_street_name_dummy, attr_strings[attr_string_street_name]); |
6003 | // fprintf(stderr, "addr:street :%s\n", attr_strings[attr_string_street_name]); |
6004 | // addr:housenumber |
6005 | item_bin_add_attr_string(item_bin, attr_house_number_dummy, attr_strings[attr_string_house_number]); |
6006 | // fprintf(stderr, "addr:housenumber:%s\n", attr_strings[attr_string_house_number]); |
6007 | } |
6008 | // housenumber from buildings -------------------- |
6009 | |
6010 | |
6011 | if (attr_strings[attr_string_label_alt]) |
6012 | { |
6013 | item_bin_add_attr_string(item_bin, attr_street_name_match, attr_strings[attr_string_label_alt]); |
6014 | if (debug_itembin(ib)) |
6015 | { |
6016 | fprintf(stderr, "street name : %s\n", attr_strings[attr_string_label]); |
6017 | fprintf(stderr, "street name sys: %s\n", attr_strings[attr_string_street_name_systematic]); |
6018 | fprintf(stderr, "street name alt: %s\n", attr_strings[attr_string_label_alt]); |
6019 | } |
6020 | } |
6021 | item_bin_add_attr_string(item_bin, attr_street_name_systematic, attr_strings[attr_string_street_name_systematic]); |
6022 | |
6023 | // -- NEW 001 -- |
6024 | item_bin_add_attr_string(item_bin, attr_street_name_systematic_nat, attr_strings[attr_string_street_name_systematic_nat]); |
6025 | item_bin_add_attr_string(item_bin, attr_street_lanes, attr_strings[attr_string_street_lanes]); |
6026 | item_bin_add_attr_string(item_bin, attr_street_lanes_forward, attr_strings[attr_string_street_lanes_forward]); |
6027 | item_bin_add_attr_string(item_bin, attr_street_turn_lanes, attr_strings[attr_string_street_turn_lanes]); |
6028 | item_bin_add_attr_string(item_bin, attr_street_destination, attr_strings[attr_string_street_destination]); |
6029 | item_bin_add_attr_string(item_bin, attr_street_destination_lanes, attr_strings[attr_string_street_destination_lanes]); |
6030 | // -- NEW 001 -- |
6031 | |
6032 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
6033 | |
6034 | if (debug_attr_buffer[0]) |
6035 | { |
6036 | item_bin_add_attr_string(item_bin, attr_debug, debug_attr_buffer); |
6037 | } |
6038 | |
6039 | if (add_flags) |
6040 | { |
6041 | item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); |
6042 | } |
6043 | |
6044 | if (maxspeed_attr_value) |
6045 | { |
6046 | item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); |
6047 | } |
6048 | |
6049 | // custom color attribute |
6050 | if (attr_strings[attr_string_colour_]) |
6051 | { |
6052 | unsigned int cc = color_int_value_from_string(attr_strings[attr_string_colour_]); |
6053 | //fprintf(stderr, "col:ret=%d\n", cc); |
6054 | if (cc != 0) |
6055 | { |
6056 | cc = (cc >> 8); |
6057 | //fprintf(stderr, "col:in map=%d\n", (int)cc); |
6058 | item_bin_add_attr_int(item_bin, attr_colour2, (int)cc); |
6059 | } |
6060 | } |
6061 | |
6062 | // if we duplicated this way here (because of multiple attributes), then set "duplicate_way" attr |
6063 | if (i > 0) |
6064 | { |
6065 | item_bin_add_attr_int(item_bin, attr_duplicate_way, 1); |
6066 | //fprintf(stderr, "attr_duplicate_way:1: dup=true wayid=%lld\n", item_bin_get_wayid(item_bin)); |
6067 | } |
6068 | |
6069 | if (write_this_item_to_binfile == 1) |
6070 | { |
6071 | item_bin_write(item_bin, osm->ways); |
6072 | } |
6073 | |
6074 | if (border_only_map_as_xml == 1) |
6075 | { |
6076 | item_bin_write_xml(item_bin, "borders.xml"); |
6077 | } |
6078 | } |
6079 | |
6080 | /* |
6081 | if(osm->line2poi) { |
6082 | count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type)); |
6083 | dbg_assert(count < 10); |
6084 | for (i = 0 ; i < count ; i++) { |
6085 | if (types[i] == type_none || types[i] == type_point_unkn) |
6086 | continue; |
6087 | item_bin=init_item(types[i], 0); |
6088 | item_bin_add_coord(item_bin, coord_buffer, coord_count); |
6089 | item_bin_add_attr_string(item_bin, attr_label, attr_strings[attr_string_label]); |
6090 | item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]); |
6091 | item_bin_add_attr_string(item_bin, attr_street_name, attr_strings[attr_string_street_name]); |
6092 | item_bin_add_attr_string(item_bin, attr_phone, attr_strings[attr_string_phone]); |
6093 | item_bin_add_attr_string(item_bin, attr_fax, attr_strings[attr_string_fax]); |
6094 | item_bin_add_attr_string(item_bin, attr_email, attr_strings[attr_string_email]); |
6095 | item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]); |
6096 | item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); |
6097 | item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); |
6098 | item_bin_write(i |