/[zanavi_public1]/navit/navit/maptool/osm.c
ZANavi

Contents of /navit/navit/maptool/osm.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 57 - (hide annotations) (download)
Sun Mar 19 16:46:08 2017 UTC (3 years, 10 months ago) by zoff99
File MIME type: text/plain
File size: 245141 byte(s)
updates
1 zoff99 8 /**
2 zoff99 37 * ZANavi, Zoff Android Navigation system.
3 zoff99 57 * Copyright (C) 2011-2013 Zoff <zoff@zoff.cc>
4 zoff99 37 *
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 zoff99 8 * 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 zoff99 37
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 zoff99 8 #include <unistd.h>
112 zoff99 37 #include <time.h>
113     #include <stdio.h>
114 zoff99 8 #include <string.h>
115     #include <stdlib.h>
116     #include <math.h>
117     #include "debug.h"
118     #include "linguistics.h"
119 zoff99 36 #include "country.h"
120 zoff99 8 #include "file.h"
121    
122 zoff99 37 /* 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 zoff99 36 #define _FILE_OFFSET_BITS 64
145     #define _LARGEFILE_SOURCE
146     #define _LARGEFILE64_SOURCE
147    
148 zoff99 57
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 zoff99 36 extern int doway2poi;
161    
162 zoff99 8 static int in_way, in_node, in_relation;
163 zoff99 37 static osmid nodeid, wayid;
164     osmid current_id;
165 zoff99 8
166 zoff99 37 static GHashTable *attr_hash, *country_table_hash;
167 zoff99 8
168 zoff99 37 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 zoff99 8 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 zoff99 37 osmid osmid_attr_value;
186 zoff99 8
187     char is_in_buffer[BUFFER_SIZE];
188    
189 zoff99 37 char attr_strings_buffer[BUFFER_SIZE * 16];
190 zoff99 8 int attr_strings_buffer_len;
191 zoff99 37 int alt_name_found = 0;
192 zoff99 57 int real_alt_name_found = 0;
193 zoff99 8
194     struct coord coord_buffer[65536];
195 zoff99 57 struct coord coord_buffer_3[65536];
196 zoff99 8
197 zoff99 37 struct attr_mapping
198     {
199 zoff99 8 enum item_type type;
200     int attr_present_idx_count;
201     int attr_present_idx[0];
202     };
203    
204 zoff99 37 static void nodes_ref_item_bin(struct item_bin *ib, int local_thread_num, osmid this_way_id);
205 zoff99 36
206 zoff99 8 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 zoff99 36 static struct attr_mapping **attr_mapping_way2poi;
211     static int attr_mapping_way2poi_count;
212 zoff99 8
213     static char *attr_present;
214     static int attr_present_count;
215    
216 zoff99 37 static long long seekpos1;
217 zoff99 34
218 zoff99 37 enum attr_strings
219     {
220 zoff99 57 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 zoff99 8 };
235    
236     char *attr_strings[attr_string_last];
237    
238 zoff99 37 char *osm_types[] = { "unknown", "node", "way", "relation" };
239 zoff99 8
240 zoff99 57 double save_node_lat;
241     double save_node_lon;
242 zoff99 8
243 zoff99 37 // #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 zoff99 36 // first char - item type
333     // =w - ways
334     // =? - used both for nodes and ways
335     // otherwise - nodes
336 zoff99 8
337 zoff99 36
338     // for coastline-only map
339 zoff99 37 static char *attrmap_cl = { "n *=* point_unkn\n"
340 zoff99 36 "w *=* street_unkn\n"
341 zoff99 37 "w natural=coastline water_line\n" };
342 zoff99 36
343     // for border-only map
344 zoff99 37 static char *attrmap_bo = { "n *=* point_unkn\n"
345 zoff99 36 "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 zoff99 37 "w boundary=administrative,maritime=yes,admin_level=2 border_country\n"
351 zoff99 36 "w boundary=administrative,maritime=yes,admin_level=4 border_country\n"
352 zoff99 37 "w boundary=administrative,border_type=state,admin_level=4 border_country\n" };
353 zoff99 36
354     // ==========================
355     // for USA
356     // ==========================
357     // admin_level = 4
358     // border_type = state
359     // boundary = administrative
360     // ==========================
361    
362    
363     // for normal map
364 zoff99 37 static char *attrmap_normal = { "n *=* point_unkn\n"
365 zoff99 36 //// "n Annehmlichkeit=Hochsitz poi_hunting_stand\n"
366 zoff99 8 "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 zoff99 37 "n amenity=atm poi_atm\n"
372 zoff99 8 "n amenity=bank poi_bank\n"
373     "n amenity=bar poi_bar\n"
374 zoff99 36 //"n amenity=bench poi_bench\n"
375 zoff99 8 "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 zoff99 36 //"n amenity=drinking_water poi_potable_water\n"
383 zoff99 8 "n amenity=fast_food poi_fastfood\n"
384     "n amenity=fire_station poi_firebrigade\n"
385 zoff99 36 //"n amenity=fountain poi_fountain\n"
386 zoff99 8 "n amenity=fuel poi_fuel\n"
387     "n amenity=grave_yard poi_cemetery\n"
388     "n amenity=hospital poi_hospital\n"
389 zoff99 36 //"n amenity=hunting_stand poi_hunting_stand\n"
390 zoff99 8 "n amenity=kindergarten poi_kindergarten\n"
391     "n amenity=library poi_library\n"
392     "n amenity=nightclub poi_nightclub\n"
393 zoff99 36 //"n amenity=park_bench poi_bench\n"
394 zoff99 8 "n amenity=parking poi_car_parking\n"
395 zoff99 57 "n amenity=bicycle_parking poi_bicycle_parking\n"
396     "n amenity=bicycle_rental poi_bicycle_rental\n"
397 zoff99 8 "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 zoff99 36 //"n amenity=post_box poi_post_box\n"
402 zoff99 8 "n amenity=post_office poi_post_office\n"
403     "n amenity=prison poi_prison\n"
404 zoff99 37 //"n amenity=pub poi_pub\n"
405 zoff99 8 "n amenity=public_building poi_public_office\n"
406 zoff99 36 //"n amenity=recycling poi_recycling\n"
407 zoff99 8 "n amenity=restaurant,cuisine=fine_dining poi_dining\n"
408     "n amenity=restaurant poi_restaurant\n"
409     "n amenity=school poi_school\n"
410 zoff99 36 //"n amenity=shelter poi_shelter\n"
411 zoff99 8 "n amenity=taxi poi_taxi\n"
412 zoff99 36 //"n amenity=tec_common tec_common\n"
413     //"n amenity=telephone poi_telephone\n"
414 zoff99 8 "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 zoff99 36 //"n amenity=vending_machine poi_vending_machine\n"
419 zoff99 8 "n barrier=bollard barrier_bollard\n"
420     "n barrier=cycle_barrier barrier_cycle\n"
421     "n barrier=lift_gate barrier_lift_gate\n"
422 zoff99 37 "n car=car_rental poi_car_rent\n"
423 zoff99 8 "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 zoff99 57 "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 zoff99 8 "n highway=traffic_signals traffic_signals\n"
433     "n highway=turning_circle turning_circle\n"
434 zoff99 36 //"n historic=boundary_stone poi_boundary_stone\n"
435 zoff99 8 "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 zoff99 37 //// "n historic=* poi_ruins\n"
440 zoff99 8 "n landuse=cemetery poi_cemetery\n"
441 zoff99 36 //"n leisure=fishing poi_fish\n"
442 zoff99 8 "n leisure=golf_course poi_golf\n"
443     "n leisure=marina poi_marine\n"
444 zoff99 36 //"n leisure=playground poi_playground\n"
445     //"n leisure=slipway poi_boat_ramp\n"
446 zoff99 37 "n leisure=sports_centre poi_sport\n"
447 zoff99 8 "n leisure=stadium poi_stadium\n"
448 zoff99 36 //"n man_made=tower poi_tower\n"
449 zoff99 8 "n military=airfield poi_military\n"
450 zoff99 37 "n military=barracks poi_military\n"
451     "n military=bunker poi_military\n"
452 zoff99 8 "n military=danger_area poi_danger_area\n"
453     "n military=range poi_military\n"
454     "n natural=bay poi_bay\n"
455 zoff99 37 "n natural=peak,ele=* poi_peak\n" // show only major peaks with elevation
456 zoff99 36 //"n natural=tree poi_tree\n"
457 zoff99 8 "n place=city town_label_2e5\n"
458 zoff99 57 "n place=town town_label_2e4\n"
459     "n place=village town_label_2e3\n"
460 zoff99 8 "n place=hamlet town_label_2e2\n"
461     "n place=locality town_label_2e0\n"
462     "n place=suburb district_label\n"
463 zoff99 57 "n place=quarter district_label_1e2\n"
464     "n place=neighbourhood district_label_1e1\n"
465 zoff99 36 //"n power=tower power_tower\n"
466     //"n power=sub_station power_substation\n"
467 zoff99 8 "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 zoff99 37 "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 zoff99 8 "n shop=car poi_car_dealer_parts\n"
477     "n shop=car_repair poi_repair_service\n"
478 zoff99 36 //"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 zoff99 37 "n shop=hairdresser poi_hairdresser\n"
487 zoff99 36 //"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 zoff99 37 "n shop=shoes poi_shop_shoes\n"
492 zoff99 8 "n shop=supermarket poi_shopping\n"
493 zoff99 36 //"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 zoff99 37 "n sport=golf poi_golf\n"
498 zoff99 36 //"n sport=motor_sports poi_motor_sport\n"
499     //"n sport=skiing poi_skiing\n"
500 zoff99 37 "n sport=soccer poi_soccer\n"
501 zoff99 8 "n sport=stadium poi_stadium\n"
502     "n sport=swimming poi_swimming\n"
503 zoff99 37 "n sport=tennis poi_tennis\n"
504 zoff99 8 "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 zoff99 36 //"n tourism=picnic_site poi_picnic\n"
514 zoff99 8 "n tourism=theme_park poi_resort\n"
515 zoff99 37 "n tourism=viewpoint poi_viewpoint\n"
516 zoff99 8 "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 zoff99 36 //"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 zoff99 8 "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 zoff99 36 //"w amenity=grave_yard poly_cemetery\n"
534 zoff99 8 "w amenity=parking poly_car_parking\n"
535     "w amenity=place_of_worship poly_building\n"
536     "w amenity=university poly_university\n"
537 zoff99 36 // "w boundary=administrative,admin_level=2 border_country\n" --> in border map
538     //"w boundary=civil border_civil\n"
539 zoff99 8 "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 zoff99 36 //"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 zoff99 8 "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 zoff99 57 "w highway=motorway_link ramp_highway_land\n"
574     "w highway=trunk street_n_lanes\n"
575 zoff99 8 "w highway=trunk,name=*,rural=1 street_4_land\n"
576 zoff99 57 "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 zoff99 8 "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 zoff99 57 "w highway=primary_link ramp_street_4_city\n"
584 zoff99 8 "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 zoff99 57 "w highway=secondary_link ramp_street_3_city\n"
590 zoff99 8 "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 zoff99 57 "w highway=tertiary_link ramp_street_2_city\n"
596 zoff99 8 "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 zoff99 36 //"w landuse=allotments poly_allotments\n"
627     //"w landuse=basin poly_basin\n"
628     //"w landuse=brownfield poly_brownfield\n"
629 zoff99 8 "w landuse=cemetery poly_cemetery\n"
630 zoff99 36 //"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 zoff99 8 "w landuse=forest poly_wood\n"
636     "w landuse=greenfield poly_greenfield\n"
637 zoff99 36 //"w landuse=industrial poly_industry\n"
638     //"w landuse=landfill poly_landfill\n"
639 zoff99 8 "w landuse=military poly_military\n"
640     "w landuse=plaza poly_plaza\n"
641 zoff99 36 //"w landuse=quarry poly_quarry\n"
642 zoff99 8 "w landuse=railway poly_railway\n"
643 zoff99 36 //"w landuse=recreation_ground poly_recreation_ground\n"
644 zoff99 8 "w landuse=reservoir poly_reservoir\n"
645 zoff99 36 //"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 zoff99 8 "w leisure=park poly_park\n"
657 zoff99 36 //"w leisure=pitch poly_sports_pitch\n"
658 zoff99 8 "w leisure=playground poly_playground\n"
659 zoff99 36 //"w leisure=sports_centre poly_sport\n"
660 zoff99 8 "w leisure=stadium poly_sports_stadium\n"
661 zoff99 36 //"w leisure=track poly_sports_track\n"
662 zoff99 8 "w leisure=water_park poly_water_park\n"
663     "w military=airfield poly_airfield\n"
664 zoff99 37 "w military=barracks poly_barracks\n"
665 zoff99 8 "w military=danger_area poly_danger_area\n"
666     "w military=naval_base poly_naval_base\n"
667 zoff99 37 "w military=range poly_range\n"
668 zoff99 8 "w natural=beach poly_beach\n"
669 zoff99 36 // "w natural=coastline water_line\n" --> in coastline map
670 zoff99 8 "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 zoff99 36 //"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 zoff99 8 "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 zoff99 36 //"w power=line powerline\n"
694     //"w railway=abandoned rail_abandoned\n"
695     //"w railway=disused rail_disused\n"
696 zoff99 37 "w railway=light_rail rail_light\n"
697     "w railway=monorail rail_mono\n"
698     "w railway=narrow_gauge rail_narrow_gauge\n"
699 zoff99 36 //"w railway=preserved rail_preserved\n"
700 zoff99 8 "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 zoff99 36 //"w route=ski piste_nordic\n"
705     //"w sport=* poly_sport\n"
706 zoff99 8 "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 zoff99 37 "w barrier=city_wall city_wall\n" };
724 zoff99 8
725 zoff99 37 static void build_attrmap_line(char *line)
726 zoff99 8 {
727 zoff99 37 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 zoff99 8 while (*p == '\t')
735 zoff99 37 *p++ = '\0';
736     kvl = p;
737     p = strchr(kvl, '\t');
738 zoff99 8 }
739 zoff99 37 if (p)
740     {
741 zoff99 8 while (*p == '\t')
742 zoff99 37 *p++ = '\0';
743     i = p;
744 zoff99 8 }
745 zoff99 37 if (t[0] == 'w')
746     {
747     if (!i)
748     i = "street_unkn";
749 zoff99 8 }
750 zoff99 37 else
751     {
752     if (!i)
753     i = "point_unkn";
754 zoff99 36 }
755 zoff99 37
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 zoff99 8 }
771 zoff99 37 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 zoff99 8 }
775 zoff99 37 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 zoff99 36 }
780 zoff99 37 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 zoff99 36 }
785 zoff99 37 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 zoff99 36 }
790    
791 zoff99 8 }
792    
793 zoff99 37 static void build_attrmap(FILE* rule_file)
794 zoff99 8 {
795 zoff99 37 attr_hash = g_hash_table_new(g_str_hash, g_str_equal);
796     attr_present_count = 1;
797 zoff99 8
798 zoff99 37 // 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 zoff99 36
828 zoff99 37 while (map)
829     {
830     p = strchr(map, '\n');
831     if (p)
832     *p++ = '\0';
833 zoff99 57
834 zoff99 37 if (strlen(map))
835     build_attrmap_line(map);
836 zoff99 57
837 zoff99 37 map = p;
838     }
839     }
840 zoff99 8
841 zoff99 37 attr_present = g_malloc0(sizeof(*attr_present) * attr_present_count);
842 zoff99 8 }
843    
844 zoff99 37 static void build_countrytable(void)
845 zoff99 8 {
846     int i;
847 zoff99 37 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 zoff99 8 }
858     }
859     }
860 zoff99 36
861 zoff99 57 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 zoff99 37 void osm_warning(char *type, long long id, int cont, char *fmt, ...)
896 zoff99 8 {
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 zoff99 37 if (verbose_mode) fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Warning:",type,id,str);
903 zoff99 8 }
904    
905 zoff99 37 void osm_info(char *type, long long id, int cont, char *fmt, ...)
906 zoff99 36 {
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 zoff99 37 if (verbose_mode) fprintf(stderr,"%shttp://www.openstreetmap.org/browse/%s/"LONGLONG_FMT" %s",cont ? "":"OSM Info:",type,id,str);
913 zoff99 36 }
914    
915 zoff99 37 static void attr_strings_clear(void)
916 zoff99 8 {
917 zoff99 37 alt_name_found = 0;
918 zoff99 57 real_alt_name_found = 0;
919 zoff99 37 attr_strings_buffer_len = 0;
920 zoff99 8 memset(attr_strings, 0, sizeof(attr_strings));
921     }
922    
923 zoff99 37 static void attr_strings_save(enum attr_strings id, char *str)
924 zoff99 8 {
925 zoff99 37 attr_strings[id] = attr_strings_buffer + attr_strings_buffer_len;
926 zoff99 8 strcpy(attr_strings[id], str);
927 zoff99 37 attr_strings_buffer_len += strlen(str) + 1;
928 zoff99 8 }
929    
930 zoff99 37 long long item_bin_get_nodeid(struct item_bin *ib)
931 zoff99 8 {
932 zoff99 37 long long *ret = item_bin_get_attr(ib, attr_osm_nodeid, NULL);
933 zoff99 8 if (ret)
934 zoff99 37 {
935 zoff99 8 return *ret;
936 zoff99 37 }
937 zoff99 8 return 0;
938     }
939    
940 zoff99 37 long long item_bin_get_wayid(struct item_bin *ib)
941 zoff99 8 {
942 zoff99 37 long long *ret = item_bin_get_attr(ib, attr_osm_wayid, NULL);
943 zoff99 8 if (ret)
944 zoff99 37 {
945 zoff99 8 return *ret;
946 zoff99 37 }
947 zoff99 8 return 0;
948     }
949    
950 zoff99 37 long long item_bin_get_relationid(struct item_bin *ib)
951 zoff99 8 {
952 zoff99 37 long long *ret = item_bin_get_attr(ib, attr_osm_relationid, NULL);
953 zoff99 8 if (ret)
954 zoff99 37 {
955 zoff99 8 return *ret;
956 zoff99 37 }
957 zoff99 8 return 0;
958     }
959    
960 zoff99 37 long long item_bin_get_id(struct item_bin *ib)
961 zoff99 8 {
962     long long ret;
963     if (ib->type < 0x80000000)
964 zoff99 37 {
965 zoff99 8 return item_bin_get_nodeid(ib);
966 zoff99 37 }
967     ret = item_bin_get_wayid(ib);
968 zoff99 8 if (!ret)
969 zoff99 37 {
970     ret = item_bin_get_relationid(ib);
971     }
972 zoff99 8 return ret;
973     }
974    
975     static int node_is_tagged;
976     static void relation_add_tag(char *k, char *v);
977 zoff99 57 osmid get_waynode_num_have_seekpos(osmid way_id, int coord_num, int local_thread_num, off_t seek_pos);
978 zoff99 8
979 zoff99 57
980 zoff99 37 static int access_value(char *v)
981 zoff99 8 {
982 zoff99 37 if (!strcmp(v, "1"))
983 zoff99 8 return 1;
984 zoff99 37 if (!strcmp(v, "yes"))
985 zoff99 8 return 1;
986 zoff99 37 if (!strcmp(v, "designated"))
987 zoff99 8 return 1;
988 zoff99 37 if (!strcmp(v, "official"))
989 zoff99 8 return 1;
990 zoff99 37 if (!strcmp(v, "permissive"))
991 zoff99 8 return 1;
992 zoff99 37 if (!strcmp(v, "0"))
993 zoff99 8 return 2;
994 zoff99 37 if (!strcmp(v, "no"))
995 zoff99 8 return 2;
996 zoff99 37 if (!strcmp(v, "agricultural"))
997 zoff99 8 return 2;
998 zoff99 37 if (!strcmp(v, "forestry"))
999 zoff99 8 return 2;
1000 zoff99 37 if (!strcmp(v, "private"))
1001 zoff99 8 return 2;
1002 zoff99 37 if (!strcmp(v, "delivery"))
1003 zoff99 8 return 2;
1004 zoff99 37 if (!strcmp(v, "destination"))
1005 zoff99 8 return 2;
1006     return 3;
1007     }
1008    
1009 zoff99 37 void osm_add_tag(char *k, char *v)
1010 zoff99 8 {
1011 zoff99 37 int idx, level = 2;
1012     char buffer[BUFFER_SIZE * 2 + 2];
1013    
1014     if (in_relation)
1015     {
1016     relation_add_tag(k, v);
1017 zoff99 8 return;
1018     }
1019 zoff99 37
1020     if (!strcmp(k, "ele"))
1021     level = 9;
1022 zoff99 57
1023 zoff99 37 if (!strcmp(k, "time"))
1024     level = 9;
1025 zoff99 57
1026 zoff99 37 if (!strcmp(k, "created_by"))
1027     level = 9;
1028 zoff99 57
1029 zoff99 37 if (!strncmp(k, "tiger:", 6) || !strcmp(k, "AND_nodes"))
1030     level = 9;
1031 zoff99 57
1032 zoff99 37 if (!strcmp(k, "converted_by") || !strcmp(k, "source"))
1033     level = 8;
1034 zoff99 57
1035 zoff99 37 if (!strncmp(k, "osmarender:", 11) || !strncmp(k, "svg:", 4))
1036     level = 8;
1037 zoff99 57
1038 zoff99 37 if (!strcmp(k, "layer"))
1039     level = 7;
1040 zoff99 57
1041 zoff99 37 if (!strcasecmp(v, "true") || !strcasecmp(v, "yes"))
1042     v = "1";
1043 zoff99 57
1044 zoff99 37 if (!strcasecmp(v, "false") || !strcasecmp(v, "no"))
1045     v = "0";
1046 zoff99 57
1047    
1048    
1049    
1050    
1051 zoff99 37 if (!strcmp(k, "oneway"))
1052     {
1053     if (!strcmp(v, "1"))
1054     {
1055     flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT_VALID;
1056 zoff99 8 }
1057 zoff99 57
1058 zoff99 37 if (!strcmp(v, "-1"))
1059     {
1060     flags[0] |= NAVIT_AF_ONEWAYREV | NAVIT_AF_ROUNDABOUT_VALID;
1061 zoff99 8 }
1062 zoff99 57
1063 zoff99 8 if (!in_way)
1064 zoff99 57 {
1065 zoff99 37 level = 6;
1066 zoff99 57 }
1067 zoff99 8 else
1068 zoff99 57 {
1069 zoff99 37 level = 5;
1070 zoff99 57 }
1071 zoff99 8 }
1072 zoff99 57
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 zoff99 37 if (!strcmp(k, "junction"))
1254     {
1255     if (!strcmp(v, "roundabout"))
1256     flags[0] |= NAVIT_AF_ONEWAY | NAVIT_AF_ROUNDABOUT | NAVIT_AF_ROUNDABOUT_VALID;
1257 zoff99 8 }
1258 zoff99 57
1259 zoff99 37 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 zoff99 8 maxspeed_attr_value = atoi(v);
1268     }
1269 zoff99 57
1270 zoff99 8 if (maxspeed_attr_value)
1271 zoff99 57
1272 zoff99 37 flags[0] |= NAVIT_AF_SPEED_LIMIT;
1273     level = 5;
1274 zoff99 8 }
1275 zoff99 37 if (!strcmp(k, "toll"))
1276     {
1277     if (!strcmp(v, "1"))
1278     {
1279     flags[0] |= NAVIT_AF_TOLL;
1280 zoff99 36 }
1281     }
1282 zoff99 37 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 zoff99 8 }
1287 zoff99 37 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 zoff99 8 }
1292 zoff99 37 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 zoff99 8 }
1297 zoff99 37 if (!strcmp(k, "bicycle"))
1298     {
1299     flags[access_value(v)] |= NAVIT_AF_BIKE;
1300     level = 5;
1301 zoff99 8 }
1302 zoff99 37 if (!strcmp(k, "foot"))
1303     {
1304     flags[access_value(v)] |= NAVIT_AF_PEDESTRIAN;
1305     level = 5;
1306 zoff99 8 }
1307 zoff99 37 if (!strcmp(k, "horse"))
1308     {
1309     flags[access_value(v)] |= NAVIT_AF_HORSE;
1310     level = 5;
1311 zoff99 8 }
1312 zoff99 37 if (!strcmp(k, "moped"))
1313     {
1314     flags[access_value(v)] |= NAVIT_AF_MOPED;
1315     level = 5;
1316 zoff99 8 }
1317 zoff99 37 if (!strcmp(k, "motorcycle"))
1318     {
1319     flags[access_value(v)] |= NAVIT_AF_MOTORCYCLE;
1320     level = 5;
1321 zoff99 8 }
1322 zoff99 37 if (!strcmp(k, "motorcar"))
1323     {
1324     flags[access_value(v)] |= NAVIT_AF_CAR;
1325     level = 5;
1326 zoff99 8 }
1327 zoff99 37 if (!strcmp(k, "hov"))
1328     {
1329     flags[access_value(v)] |= NAVIT_AF_HIGH_OCCUPANCY_CAR;
1330     level = 5;
1331 zoff99 8 }
1332 zoff99 37 if (!strcmp(k, "bus"))
1333     {
1334     flags[access_value(v)] |= NAVIT_AF_PUBLIC_BUS;
1335     level = 5;
1336 zoff99 8 }
1337 zoff99 37 if (!strcmp(k, "taxi"))
1338     {
1339     flags[access_value(v)] |= NAVIT_AF_TAXI;
1340     level = 5;
1341 zoff99 8 }
1342 zoff99 37 if (!strcmp(k, "goods"))
1343     {
1344     flags[access_value(v)] |= NAVIT_AF_DELIVERY_TRUCK;
1345     level = 5;
1346 zoff99 8 }
1347 zoff99 37 if (!strcmp(k, "hgv"))
1348     {
1349     flags[access_value(v)] |= NAVIT_AF_TRANSPORT_TRUCK;
1350     level = 5;
1351 zoff99 8 }
1352 zoff99 37 if (!strcmp(k, "emergency"))
1353     {
1354     flags[access_value(v)] |= NAVIT_AF_EMERGENCY_VEHICLES;
1355     level = 5;
1356 zoff99 8 }
1357 zoff99 37 if (!strcmp(k, "hazmat"))
1358     {
1359     flags[access_value(v)] |= NAVIT_AF_DANGEROUS_GOODS;
1360     level = 5;
1361 zoff99 8 }
1362 zoff99 37 if (!strcmp(k, "tunnel") && !strcmp(v, "1"))
1363     {
1364     flags[0] |= NAVIT_AF_UNDERGROUND;
1365 zoff99 36 }
1366 zoff99 37 if (!strcmp(k, "bridge") && !strcmp(v, "1"))
1367     {
1368     flags[0] |= NAVIT_AF_BRIDGE;
1369     }
1370 zoff99 57
1371 zoff99 37 if (!strcmp(k, "note"))
1372 zoff99 57 {
1373 zoff99 37 level = 5;
1374 zoff99 57 }
1375    
1376 zoff99 37 if (!strcmp(k, "name"))
1377     {
1378 zoff99 8 attr_strings_save(attr_string_label, v);
1379 zoff99 37 level = 5;
1380 zoff99 8 }
1381 zoff99 37
1382 zoff99 57 if (!strcmp(k, "capacity"))
1383 zoff99 37 {
1384 zoff99 57 attr_strings_save(attr_string_capacity, v);
1385 zoff99 37 level = 5;
1386     }
1387 zoff99 57
1388     if (!strcmp(k, "alt_name"))
1389 zoff99 37 {
1390 zoff99 57 // 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 zoff99 37 attr_strings_save(attr_string_label_alt, v);
1400 zoff99 57 alt_name_found = 1; // lowest priority
1401 zoff99 37 level = 5;
1402     }
1403 zoff99 57 if (!strcmp(k, "name:en"))
1404 zoff99 37 {
1405     attr_strings_save(attr_string_label_alt, v);
1406 zoff99 57 alt_name_found = 2; // highest priority
1407 zoff99 37 level = 5;
1408     }
1409     if (!strcmp(k, "addr:email"))
1410     {
1411 zoff99 8 attr_strings_save(attr_string_email, v);
1412 zoff99 37 level = 5;
1413 zoff99 8 }
1414 zoff99 37 if (!strcmp(k, "addr:housenumber"))
1415     {
1416 zoff99 8 attr_strings_save(attr_string_house_number, v);
1417 zoff99 37 level = 5;
1418 zoff99 8 }
1419 zoff99 37 if (!strcmp(k, "addr:street"))
1420     {
1421 zoff99 8 attr_strings_save(attr_string_street_name, v);
1422 zoff99 37 level = 5;
1423 zoff99 8 }
1424 zoff99 37 if (!strcmp(k, "colour"))
1425     {
1426     attr_strings_save(attr_string_colour_, v);
1427     level = 5;
1428     }
1429     if (!strcmp(k, "phone"))
1430     {
1431 zoff99 8 attr_strings_save(attr_string_phone, v);
1432 zoff99 37 level = 5;
1433 zoff99 8 }
1434 zoff99 37 if (!strcmp(k, "fax"))
1435     {
1436 zoff99 8 attr_strings_save(attr_string_fax, v);
1437 zoff99 37 level = 5;
1438 zoff99 8 }
1439 zoff99 37 if (!strcmp(k, "postal_code"))
1440     {
1441 zoff99 8 attr_strings_save(attr_string_postal, v);
1442 zoff99 37 level = 5;
1443 zoff99 8 }
1444 zoff99 37 if (!strcmp(k, "openGeoDB:postal_codes") && !attr_strings[attr_string_postal])
1445     {
1446 zoff99 8 attr_strings_save(attr_string_postal, v);
1447 zoff99 37 level = 5;
1448 zoff99 8 }
1449 zoff99 37 if (!strcmp(k, "population"))
1450     {
1451 zoff99 8 attr_strings_save(attr_string_population, v);
1452 zoff99 37 level = 5;
1453 zoff99 8 }
1454 zoff99 37 if (!strcmp(k, "openGeoDB:population") && !attr_strings[attr_string_population])
1455     {
1456 zoff99 8 attr_strings_save(attr_string_population, v);
1457 zoff99 37 level = 5;
1458 zoff99 8 }
1459 zoff99 37 if (!strcmp(k, "ref"))
1460     {
1461 zoff99 8 if (in_way)
1462 zoff99 57 {
1463 zoff99 8 attr_strings_save(attr_string_street_name_systematic, v);
1464 zoff99 57 }
1465     else
1466     {
1467     attr_strings_save(attr_string_ref, v);
1468     }
1469 zoff99 37 level = 5;
1470 zoff99 8 }
1471 zoff99 57 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 zoff99 37 if (!strcmp(k, "openGeoDB:is_in"))
1514     {
1515 zoff99 8 if (!is_in_buffer[0])
1516 zoff99 57 {
1517 zoff99 8 strcpy(is_in_buffer, v);
1518 zoff99 57 }
1519 zoff99 37 level = 5;
1520 zoff99 8 }
1521 zoff99 37 if (!strcmp(k, "is_in"))
1522     {
1523     if (!is_in_buffer[0])
1524 zoff99 57 {
1525 zoff99 37 strcpy(is_in_buffer, v);
1526 zoff99 57 }
1527 zoff99 37 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 zoff99 8 strcpy(is_in_buffer, v);
1536 zoff99 37 level = 5;
1537 zoff99 8 }
1538 zoff99 37 if (!strcmp(k, "place_county"))
1539     {
1540 zoff99 8 /**
1541 zoff99 37 * 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 zoff99 8 strcpy(is_in_buffer, "Ireland");
1548     attr_strings_save(attr_string_county_name, v);
1549 zoff99 37 level = 5;
1550 zoff99 8 }
1551 zoff99 37 if (!strcmp(k, "gnis:ST_alpha"))
1552     {
1553 zoff99 8 /* assume a gnis tag means it is part of the USA:
1554 zoff99 37 http://en.wikipedia.org/wiki/Geographic_Names_Information_System
1555     many US towns do not have is_in tags
1556     */
1557 zoff99 8 strcpy(is_in_buffer, "USA");
1558 zoff99 37 level = 5;
1559 zoff99 8 }
1560 zoff99 57
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 zoff99 37 if (!strcmp(k, "lanes"))
1583     {
1584 zoff99 57 if (in_way)
1585     {
1586     attr_strings_save(attr_string_street_lanes, v);
1587     //fprintf(stderr, "XYZ123!?:lanes=%s\n", v);
1588     }
1589 zoff99 37 level = 5;
1590 zoff99 8 }
1591 zoff99 57
1592    
1593 zoff99 37 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 zoff99 8 {
1598 zoff99 37 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 zoff99 8 }
1602     }
1603 zoff99 37
1604 zoff99 8 if (level < 6)
1605 zoff99 37 {
1606     node_is_tagged = 1;
1607     }
1608 zoff99 8
1609 zoff99 37 strcpy(buffer, "*=*");
1610     if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer)))
1611 zoff99 57 {
1612 zoff99 37 attr_present[idx] = 1;
1613 zoff99 57 }
1614 zoff99 8
1615 zoff99 37 sprintf(buffer, "%s=*", k);
1616     if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer)))
1617 zoff99 57 {
1618 zoff99 37 attr_present[idx] = 2;
1619 zoff99 57 }
1620 zoff99 8
1621 zoff99 37 sprintf(buffer, "*=%s", v);
1622     if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer)))
1623 zoff99 57 {
1624 zoff99 37 attr_present[idx] = 2;
1625 zoff99 57 }
1626 zoff99 8
1627 zoff99 37 sprintf(buffer, "%s=%s", k, v);
1628     if ((idx = (int) (long) g_hash_table_lookup(attr_hash, buffer)))
1629 zoff99 57 {
1630 zoff99 37 attr_present[idx] = 4;
1631 zoff99 57 }
1632 zoff99 8 }
1633    
1634     int coord_count;
1635    
1636 zoff99 37 static void extend_buffer(struct buffer *b)
1637 zoff99 8 {
1638 zoff99 37 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 zoff99 8 exit(1);
1645     }
1646 zoff99 34
1647 zoff99 37 if (verbose_mode) fprintf(stderr, "extend_buffer: "LONGLONG_FMT" bytes\n", (size_t) b->malloced);
1648 zoff99 8 }
1649    
1650 zoff99 37 osmid nodeid_last;
1651     GHashTable *way_hash, *waytag_hash;
1652     cfuhash_table_t *way_hash_cfu = NULL;
1653 zoff99 8
1654 zoff99 57 typedef struct dummy_cfuhash_entry
1655     {
1656 zoff99 37 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 zoff99 8 {
1663 zoff99 37 if (verbose_mode)
1664 zoff99 57 {
1665 zoff99 37 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 zoff99 57 }
1669 zoff99 37
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 zoff99 57 #if 0
1675 zoff99 37 fprintf(stderr, "[THREAD] #%d fill hash node: count=%d size=%d\n", local_thread_num, count2, sizeof(dummy_cfuhash_entry));
1676 zoff99 57 #endif
1677 zoff99 37
1678 zoff99 57 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 zoff99 37 for (i = 0; i < count2; i++)
1687     {
1688     /*
1689     if (i % 5000)
1690     {
1691     }
1692     */
1693 zoff99 57
1694     // fprintf_(stderr, "thread #%d fill #%d/%d\n", local_thread_num, i, count2);
1695    
1696 zoff99 37 // 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 zoff99 57 #if 0
1700 zoff99 37 //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 zoff99 57 #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 zoff99 37 }
1708    
1709 zoff99 57 // fprintf_(stderr, "thread #%d node_buffer_to_hash ready\n", local_thread_num);
1710    
1711 zoff99 37 if (verbose_mode)
1712     {
1713     fprintf(stderr, "node_buffer_to_hash ready\n");
1714     }
1715 zoff99 8 }
1716    
1717 zoff99 37 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 zoff99 8 static struct node_item *ni;
1729    
1730 zoff99 37 void init_node_hash(int threads, int clear)
1731 zoff99 8 {
1732 zoff99 37 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 zoff99 57 #if 0
1744 zoff99 37 node_hash_cfu[i] = cfuhash_new_with_initial_size(CFUHASH_BUCKETS_NODES);
1745     cfuhash_set_flag(node_hash_cfu[i], CFUHASH_FROZEN);
1746 zoff99 57 #endif
1747     node_hash_cfu[i] = quick_hash_init(CFUHASH_BUCKETS_NODES);
1748 zoff99 8 }
1749     }
1750    
1751 zoff99 37 void fill_hash_node(int local_thread_num)
1752 zoff99 8 {
1753 zoff99 37 //fprintf(stderr, "001t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]);
1754    
1755     if (verbose_mode)
1756 zoff99 57 {
1757 zoff99 37 fprintf(stderr, "fill_hash_node - START\n");
1758 zoff99 57 }
1759 zoff99 37 //if (node_hash[local_thread_num])
1760     if (node_hash_cfu[local_thread_num])
1761     {
1762 zoff99 57 #if 0
1763 zoff99 37 //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 zoff99 57 #endif
1769     quick_hash_destroy(node_hash_cfu[local_thread_num]);
1770     node_hash_cfu[local_thread_num] = NULL;
1771 zoff99 8 }
1772    
1773 zoff99 57 #if 0
1774 zoff99 37 // 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 zoff99 57 #endif
1778     node_hash_cfu[local_thread_num] = quick_hash_init(CFUHASH_BUCKETS_NODES);
1779    
1780 zoff99 37
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 zoff99 57
1784     quick_hash_print_stats(node_hash_cfu[local_thread_num]);
1785    
1786 zoff99 37 //fprintf(stderr, "003t:%d base:%lu\n", local_thread_num, node_buffer[local_thread_num]);
1787     if (verbose_mode)
1788 zoff99 57 {
1789 zoff99 37 fprintf(stderr, "fill_hash_node - END\n");
1790 zoff99 57 }
1791 zoff99 8 }
1792    
1793 zoff99 37 void flush_nodes(int final, int local_thread_num)
1794 zoff99 36 {
1795 zoff99 37 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 zoff99 36 }
1802 zoff99 37
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 zoff99 57 #if 0
1814 zoff99 37 //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 zoff99 57 #endif
1820     quick_hash_destroy(node_hash_cfu[local_thread_num]);
1821     node_hash_cfu[local_thread_num] = NULL;
1822 zoff99 37 }
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 zoff99 36 }
1831    
1832 zoff99 57
1833    
1834     inline double transform_to_geo_lat(int y)
1835 zoff99 8 {
1836 zoff99 57 /* ZZ GEO TRANS ZZ */
1837     return TO_GEO_LAT_(y);
1838 zoff99 37 }
1839    
1840 zoff99 57 inline double transform_to_geo_lon(int x)
1841 zoff99 37 {
1842 zoff99 57 /* ZZ GEO TRANS ZZ */
1843     return TO_GEO_LON_(x);
1844 zoff99 37 }
1845    
1846 zoff99 57 inline int transform_from_geo_lat(double lat)
1847 zoff99 37 {
1848 zoff99 57 /* ZZ GEO TRANS ZZ */
1849     return FROM_GEO_LAT_(lat);
1850 zoff99 37 }
1851    
1852 zoff99 57 inline int transform_from_geo_lon(double lon)
1853 zoff99 37 {
1854 zoff99 57 /* ZZ GEO TRANS ZZ */
1855     return FROM_GEO_LON_(lon);
1856 zoff99 37 }
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 zoff99 8 }
1865 zoff99 37 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 zoff99 8 }
1879 zoff99 37 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 zoff99 57 // fprintf(stderr, "NNDD:000:%f %f\n", lat, lon);
1887 zoff99 37
1888 zoff99 57 /* 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 zoff99 37
1893 zoff99 57 // 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 zoff99 37 #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 zoff99 8 #endif
1938 zoff99 37 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 zoff99 8 }
1945 zoff99 37 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 zoff99 8 }
1954 zoff99 37 #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 zoff99 8 }
2016    
2017 zoff99 37 void clear_node_item_buffer(void)
2018 zoff99 8 {
2019 zoff99 37 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 zoff99 8 }
2025     }
2026    
2027 zoff99 37 static struct node_item *
2028     node_item_get_fast(osmid id, int local_thread_num)
2029 zoff99 8 {
2030 zoff99 57 #if 1
2031 zoff99 37 int i;
2032 zoff99 57 //void *p_tmp;
2033     //int rr;
2034     //size_t data_size2 = sizeof(int);
2035 zoff99 37 struct node_item *ni = (struct node_item *) (node_buffer[local_thread_num].base);
2036 zoff99 57 #endif
2037 zoff99 37
2038     //if (node_hash[local_thread_num])
2039     if (node_hash_cfu[local_thread_num])
2040     {
2041 zoff99 57 #if 0
2042 zoff99 37 //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 zoff99 57 #endif
2051 zoff99 37
2052 zoff99 57 //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 zoff99 37 //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 zoff99 8 }
2071 zoff99 37 return NULL;
2072     }
2073 zoff99 8
2074 zoff99 37 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 zoff99 34 return 0;
2081 zoff99 8 }
2082 zoff99 37 return 1;
2083 zoff99 8 }
2084    
2085 zoff99 37 static osmid first_node_of_current_way;
2086    
2087     void osm_add_way(osmid id)
2088 zoff99 8 {
2089 zoff99 37 static osmid wayid_last;
2090 zoff99 8
2091 zoff99 37 in_way = 1;
2092     wayid = id;
2093     coord_count = 0;
2094 zoff99 34 attr_strings_clear();
2095 zoff99 37 item.type = type_street_unkn;
2096     debug_attr_buffer[0] = '\0';
2097     maxspeed_attr_value = 0;
2098 zoff99 34 flags_attr_value = 0;
2099     memset(flags, 0, sizeof(flags));
2100 zoff99 37 debug_attr_buffer[0] = '\0';
2101     osmid_attr_value = id;
2102 zoff99 57
2103 zoff99 37 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 zoff99 57 cfuhash_set_flag(way_hash_cfu, CFUHASH_FROZEN);
2112 zoff99 37
2113 zoff99 8 }
2114 zoff99 37 wayid_last = wayid;
2115 zoff99 8 }
2116    
2117 zoff99 34 char relation_type[BUFFER_SIZE];
2118     char iso_code[BUFFER_SIZE];
2119     int admin_level;
2120     int boundary;
2121 zoff99 8
2122 zoff99 37 void osm_add_relation(osmid id)
2123 zoff99 8 {
2124 zoff99 37 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 zoff99 57
2132     // zero out buffer -----------------------
2133     // bzero(item_bin_2, MAX_ITEMBIN_BYTES_);
2134     // zero out buffer -----------------------
2135    
2136 zoff99 37 item_bin_init(item_bin_2, type_none);
2137     item_bin_add_attr_longlong(item_bin_2, attr_osm_relationid, current_id);
2138 zoff99 8 }
2139    
2140 zoff99 37 static int country_id_from_iso2(char *iso)
2141 zoff99 36 {
2142 zoff99 37 int ret = 0;
2143 zoff99 36 if (iso)
2144     {
2145 zoff99 57 // make uppercase
2146 zoff99 36 int i99;
2147     for (i99 = 0; iso[i99]; i99++)
2148     {
2149 zoff99 57 iso[i99] = toupper(iso[i99]);
2150 zoff99 36 }
2151     struct country_search *search;
2152 zoff99 37 struct attr country_iso2, country_id;
2153 zoff99 36 struct item *item;
2154 zoff99 37 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 zoff99 36 {
2159 zoff99 37 ret = country_id.u.num;
2160 zoff99 36 if (debug_itembin(3))
2161     {
2162 zoff99 37 fprintf(stderr, "country id(1)=%d\n", ret);
2163 zoff99 36 }
2164     }
2165     else
2166     {
2167     if (debug_itembin(3))
2168     {
2169 zoff99 37 fprintf(stderr, "country id(2)=%d\n", ret);
2170 zoff99 36 }
2171     }
2172     country_search_destroy(search);
2173     }
2174     return ret;
2175     }
2176    
2177 zoff99 57 struct country_table *country_from_countryid(int id)
2178 zoff99 36 {
2179     int i;
2180 zoff99 37 for (i = 0; i < sizeof(country_table) / sizeof(struct country_table); i++)
2181 zoff99 36 {
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 zoff99 37 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 zoff99 36
2215 zoff99 37 #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 zoff99 8 {
2219 zoff99 37 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 zoff99 57 // sqlite3_finalize(st);
2387 zoff99 37
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 zoff99 57 struct node_lat_lon* lat_lon_c;
2632    
2633 zoff99 37 // triangulate vars
2634 zoff99 8 #if 0
2635 zoff99 37 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 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3063     fprintf_(stderr, "some problem with this multipolygon\n");
3064 zoff99 37 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 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3164     fprintf_(stderr, "Got Exception 1!\n");
3165 zoff99 37 exception = 1;
3166     }
3167     CATCH( MAPTOOL_00002_EXCEPTION )
3168     {
3169 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3170     fprintf_(stderr, "Got segv Exception 1!\n");
3171 zoff99 37 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 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3223     fprintf_(stderr, "problem with hole!\n");
3224 zoff99 37 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 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3411     fprintf_(stderr, "Got Exception A!\n");
3412 zoff99 37 exception = 1;
3413     }
3414     CATCH( MAPTOOL_00002_EXCEPTION )
3415     {
3416 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3417     fprintf_(stderr, "Got segv Exception A!\n");
3418 zoff99 37 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 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3493     fprintf_(stderr, "Got Exception 8!\n");
3494 zoff99 37 exception = 1;
3495     }
3496     CATCH( MAPTOOL_00002_EXCEPTION )
3497     {
3498 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3499     fprintf_(stderr, "Got segv Exception 8!\n");
3500 zoff99 37 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 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3558     fprintf_(stderr, "Got Exception 2! (in triangulate)\n");
3559 zoff99 37 exception = 1;
3560     }
3561     CATCH( MAPTOOL_00002_EXCEPTION )
3562     {
3563 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3564     fprintf_(stderr, "Got segv Exception 2! (in triangulate)\n");
3565 zoff99 37 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 zoff99 57 // first add coords
3663 zoff99 37 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 zoff99 57 // now add dummy osm wayid
3673     item_bin_add_attr_longlong(item_bin_tri, attr_osm_wayid, current_id);
3674 zoff99 37
3675 zoff99 57 // DEBUG -- DEBUG -- DEBUG --
3676     // DEBUG -- DEBUG -- DEBUG --
3677     // dump_itembin(item_bin_tri);
3678     // DEBUG -- DEBUG -- DEBUG --
3679     // DEBUG -- DEBUG -- DEBUG --
3680 zoff99 37 item_bin_write(item_bin_tri, osm->ways_with_coords);
3681 zoff99 57
3682 zoff99 37 // 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 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3714     fprintf_(stderr, "Got Exception 3!\n");
3715 zoff99 37 exception = 1;
3716     }
3717     CATCH( MAPTOOL_00002_EXCEPTION )
3718     {
3719 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3720     fprintf_(stderr, "Got segv Exception 3!\n");
3721 zoff99 37 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 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3741     fprintf_(stderr, "Got Exception 4!\n");
3742 zoff99 37 exception = 1;
3743     }
3744     CATCH( MAPTOOL_00002_EXCEPTION )
3745     {
3746 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3747     fprintf_(stderr, "Got segv Exception 4!\n");
3748 zoff99 37 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 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3766     fprintf_(stderr, "Got Exception 5!\n");
3767 zoff99 37 exception = 1;
3768     }
3769     CATCH( MAPTOOL_00002_EXCEPTION )
3770     {
3771 zoff99 57 fprintf_(stderr, "relation id=%lld\n", current_id);
3772     fprintf_(stderr, "Got segv Exception 5!\n");
3773 zoff99 37 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 &