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

Diff of /navit/navit/maptool/boundaries.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 36 Revision 37
1/**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
1/** 20/**
2 * Navit, a modular navigation system. 21 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2011 Navit Team 22 * Copyright (C) 2005-2011 Navit Team
4 * 23 *
5 * This program is free software; you can redistribute it and/or 24 * This program is free software; you can redistribute it and/or
19#include <stdio.h> 38#include <stdio.h>
20#include <string.h> 39#include <string.h>
21#include <ctype.h> 40#include <ctype.h>
22#include "maptool.h" 41#include "maptool.h"
23 42
24
25char * 43char *
26osm_tag_value(struct item_bin *ib, char *key) 44osm_tag_value(struct item_bin *ib, char *key)
27{ 45{
28 char *tag=NULL; 46 char *tag = NULL;
29 int len=strlen(key); 47 int len = strlen(key);
30 while ((tag=item_bin_get_attr(ib, attr_osm_tag, tag))) { 48 while ((tag = item_bin_get_attr(ib, attr_osm_tag, tag)))
49 {
31 if (!strncmp(tag,key,len) && tag[len] == '=') 50 if (!strncmp(tag, key, len) && tag[len] == '=')
32 return tag+len+1; 51 return tag + len + 1;
33 } 52 }
34 return NULL; 53 return NULL;
35} 54}
36 55
37static char * 56static char *
46 long long *id; 65 long long *id;
47 if (!b) 66 if (!b)
48 return 0; 67 return 0;
49 if (!b->ib) 68 if (!b->ib)
50 return 0; 69 return 0;
51 id=item_bin_get_attr(b->ib, attr_osm_relationid, NULL); 70 id = item_bin_get_attr(b->ib, attr_osm_relationid, NULL);
52 if (id) 71 if (id)
53 return *id; 72 return *id;
54 return 0; 73 return 0;
55} 74}
56 75
57static void
58process_boundaries_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) 76static void process_boundaries_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv)
59{ 77{
78 //fprintf(stderr,"process_boundaries_member:001\n");
79
60 struct boundary *b=relation_priv; 80 struct boundary *b = relation_priv;
61 enum geom_poly_segment_type role=(long)member_priv; 81 enum geom_poly_segment_type role = (long) member_priv;
82
83
84
85 int *dup;
86 dup=item_bin_get_attr(member,attr_duplicate_way,NULL);
87
88 // only add way to boundary if this way is not already added
89 if(!dup || *dup == 0)
90 {
62 b->segments=g_list_prepend(b->segments,item_bin_to_poly_segment(member, role)); 91 b->segments = g_list_prepend(b->segments, item_bin_to_poly_segment(member, role));
92 // fprintf(stderr, "process_boundaries_member: dupdup wayid=%lld %p\n", item_bin_get_wayid(member), dup);
93 }
94 else
95 {
96 // fprintf(stderr, "process_boundaries_member: dup=true wayid=%lld\n", item_bin_get_wayid(member));
97 }
98
99 //fprintf(stderr,"process_boundaries_member:099\n");
63} 100}
64 101
65static GList * 102static GList *
66process_boundaries_setup(FILE *boundaries, struct relations *relations) 103process_boundaries_setup(FILE *boundaries, struct relations *relations)
67{ 104{
68 struct item_bin *ib; 105 struct item_bin *ib;
69 GList *boundaries_list=NULL; 106 GList *boundaries_list = NULL;
70 struct relations_func *relations_func; 107 struct relations_func *relations_func;
108 long long b_counter_1 = 0;
109 // long long b_counter_2 = 0;
71 110
111 //fprintf(stderr,"process_boundaries_setup:001\n");
112
72 relations_func=relations_func_new(process_boundaries_member, NULL); 113 relations_func = relations_func_new(process_boundaries_member, NULL);
73 while ((ib=read_item(boundaries))) { 114 while ((ib = read_item(boundaries, 0)))
115 {
116
117 //fprintf(stderr,"********DUMP b ***********\n");
118 //dump_itembin(ib);
119 //fprintf(stderr,"********DUMP b ***********\n");
120
121
74 char *member=NULL; 122 char *member = NULL;
75 struct boundary *boundary=g_new0(struct boundary, 1); 123 struct boundary *boundary=g_new0(struct boundary, 1);
76 char *admin_level=osm_tag_value(ib, "admin_level"); 124 char *admin_level = osm_tag_value(ib, "admin_level");
77 char *iso=osm_tag_value(ib, "ISO3166-1"); 125 char *iso = osm_tag_value(ib, "ISO3166-1");
126
127 b_counter_1++;
128 if ((b_counter_1 % 500) == 0)
129 {
130 fprintf(stderr,"boundaries:B:%lld\n", b_counter_1);
131 }
132
133 //fprintf(stderr,"process_boundaries_setup:002\n");
134 //fprintf(stderr,"== b:%s %s ==\n", iso, admin_level);
135
78 /* disable spain for now since it creates a too large index */ 136 /* disable spain for now since it creates a too large index */
79 if (admin_level && !strcmp(admin_level, "2") && (!iso || strcasecmp(iso,"es"))) { 137 if (admin_level && !strcmp(admin_level, "2") && (!iso || strcasecmp(iso, "es")))
138 {
80 if (iso) { 139 if (iso)
140 {
81 struct country_table *country=country_from_iso2(iso); 141 struct country_table *country = country_from_iso2(iso);
82 if (!country) 142 if (!country)
143 {
83 osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary contains unknown ISO3166-1 value '%s'\n",iso); 144 osm_warning("relation", item_bin_get_relationid(ib), 0, "Country Boundary contains unknown ISO3166-1 value '%s'\n", iso);
145 }
84 else { 146 else
147 {
85 boundary->iso2=g_strdup(iso); 148 boundary->iso2 = g_strdup(iso);
86 osm_info("relation",item_bin_get_relationid(ib),0,"Country Boundary for '%s'\n",iso); 149 osm_info("relation", item_bin_get_relationid(ib), 0, "Country Boundary for '%s'\n", iso);
87 } 150 }
88 boundary->country=country; 151 boundary->country = country;
152 }
89 } else 153 else
154 {
90 osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary doesn't contain an ISO3166-1 tag\n"); 155 osm_warning("relation", item_bin_get_relationid(ib), 0, "Country Boundary doesn't contain an ISO3166-1 tag\n");
91 } 156 }
157 }
158
159 //b_counter_2 = 0;
92 while ((member=item_bin_get_attr(ib, attr_osm_member, member))) { 160 while ((member = item_bin_get_attr(ib, attr_osm_member, member)))
161 {
162 //fprintf(stderr,"process_boundaries_setup:005\n");
163 //fprintf(stderr,"********DUMP b ***********\n");
164 //dump_itembin(ib);
165 //fprintf(stderr,"********DUMP b ***********\n");
166
167 //b_counter_2++;
168 //fprintf(stderr,"boundaries:M:%lld\n", b_counter_2);
169
93 long long wayid; 170 long long wayid;
94 int read=0; 171 int read = 0;
95 if (sscanf(member,"2:%Ld:%n",&wayid,&read) >= 1) { 172 if (sscanf(member, "2:%Ld:%n", &wayid, &read) >= 1)
173 {
96 char *rolestr=member+read; 174 char *rolestr = member + read;
97 enum geom_poly_segment_type role; 175 enum geom_poly_segment_type role;
98 if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave")) 176 if (!strcmp(rolestr, "outer") || !strcmp(rolestr, "exclave"))
99 role=geom_poly_segment_type_way_outer; 177 role = geom_poly_segment_type_way_outer;
100 else if (!strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave")) 178 else if (!strcmp(rolestr, "inner") || !strcmp(rolestr, "enclave"))
101 role=geom_poly_segment_type_way_inner; 179 role = geom_poly_segment_type_way_inner;
102 else if (!strcmp(rolestr,"")) 180 else if (!strcmp(rolestr, ""))
103 role=geom_poly_segment_type_way_unknown; 181 role = geom_poly_segment_type_way_unknown;
104 else { 182 else
183 {
105 osm_warning("relation",item_bin_get_relationid(ib),0,"Unknown role %s in member ",rolestr); 184 osm_warning("relation", item_bin_get_relationid(ib), 0, "Unknown role %s in member ", rolestr);
106 osm_warning("way",wayid,1,"\n"); 185 osm_warning("way", wayid, 1, "\n");
107 role=geom_poly_segment_type_none; 186 role = geom_poly_segment_type_none;
108 } 187 }
188
189 //fprintf(stderr,"process_boundaries_setup:006 %s %Ld\n", rolestr,wayid);
190
109 relations_add_func(relations, relations_func, boundary, (gpointer)role, 2, wayid); 191 relations_add_func(relations, relations_func, boundary, (gpointer) role, 2, wayid);
110 }
111 } 192 }
193 }
194
112 boundary->ib=item_bin_dup(ib); 195 boundary->ib = item_bin_dup(ib);
113 boundaries_list=g_list_append(boundaries_list, boundary); 196 boundaries_list = g_list_append(boundaries_list, boundary);
114 } 197 }
198
115 return boundaries_list; 199 return boundaries_list;
116} 200}
117 201
118GList * 202GList *
119boundary_find_matches(GList *l, struct coord *c) 203boundary_find_matches(GList *l, struct coord *c)
120{ 204{
121 GList *ret=NULL; 205 GList *ret = NULL;
206 //fprintf(stderr,"boundary_find_matches:001\n");
122 while (l) { 207 while (l)
208 {
209 //fprintf(stderr,"boundary_find_matches:002\n");
210
123 struct boundary *boundary=l->data; 211 struct boundary *boundary = l->data;
124 if (bbox_contains_coord(&boundary->r, c)) { 212 if (bbox_contains_coord(&boundary->r, c))
213 {
214 //fprintf(stderr,"boundary_find_matches:003 id=%lld name=%s\n", item_bin_get_relationid(boundary->ib), osm_tag_name(boundary->ib));
125 if (geom_poly_segments_point_inside(boundary->sorted_segments,c) > 0) 215 if (geom_poly_segments_point_inside(boundary->sorted_segments, c) > 0)
216 {
217 //fprintf(stderr,"boundary_find_matches:004\n");
126 ret=g_list_prepend(ret, boundary); 218 ret = g_list_prepend(ret, boundary);
219 }
220 // children stuff disabled!!
127 ret=g_list_concat(ret,boundary_find_matches(boundary->children, c)); 221 // ret = g_list_concat(ret, boundary_find_matches(boundary->children, c));
222 // children stuff disabled!!
128 } 223 }
129 l=g_list_next(l); 224 l = g_list_next(l);
130 } 225 }
226
227 //fprintf(stderr,"boundary_find_matches:099\n");
228
131 return ret; 229 return ret;
132} 230}
133 231
134static void 232GList *
135test(GList *boundaries_list) 233boundary_find_matches_level(GList *l, struct coord *c, int min_admin_level, int max_admin_level)
136{ 234{
137 struct item_bin *ib; 235 GList *ret = NULL;
138 FILE *f=fopen("country_276.bin.unsorted","r"); 236 char *al;
139 printf("start\n"); 237 int admin_level;
140 while ((ib=read_item(f))) { 238 struct boundary *boundary = NULL;
141 struct coord *c=(struct coord *)(ib+1); 239
142 char *name=item_bin_get_attr(ib, attr_town_name, NULL); 240 while (l)
143 printf("%s:",name); 241 {
144 boundary_find_matches(boundaries_list, c); 242 boundary = l->data;
145 printf("\n"); 243 al = osm_tag_value(boundary->ib, "admin_level");
244 if (!al)
245 {
246 admin_level = 9999;
146 } 247 }
147 fclose(f); 248 else
148 printf("end\n"); 249 {
149} 250 admin_level = atoi(al);
251 }
150 252
151static void 253 if (admin_level < 2)
254 {
255 admin_level = 9999;
256 }
257
258 //fprintf(stderr, "matches 001:this:%d min:%d max:%d\n", admin_level, min_admin_level, max_admin_level);
259
260 if ((admin_level >= min_admin_level) && (admin_level <= max_admin_level))
261 {
262 //fprintf(stderr, "matches 002:level\n");
263 if (bbox_contains_coord(&boundary->r, c))
264 {
265 //fprintf(stderr, "matches 003:bbox\n");
266 if (geom_poly_segments_point_inside(boundary->sorted_segments, c) > 0)
267 {
268 //fprintf(stderr, "matches 004:**found**\n");
269 ret = g_list_prepend(ret, boundary);
270 }
271 }
272 }
273 l = g_list_next(l);
274 }
275
276 return ret;
277}
278
279
280GList *
281boundary_find_matches_single(GList *l, struct coord *c)
282{
283 GList *ret = NULL;
284
285 if (l)
286 {
287 //fprintf(stderr, "bbox:001\n");
288 struct boundary *boundary = l->data;
289 //fprintf(stderr, "bbox:%d %d %d %d\n", boundary->r.l.x, boundary->r.l.y, boundary->r.h.x, boundary->r.h.y);
290 //fprintf(stderr, "c:%d %d\n", c->x, c->y);
291 if (bbox_contains_coord(&boundary->r, c))
292 {
293 //fprintf(stderr, "inside bbox\n");
294 if (geom_poly_segments_point_inside(boundary->sorted_segments, c) > 0)
295 {
296 //fprintf(stderr, "bbox:002\n");
297 ret = g_list_prepend(ret, boundary);
298 }
299 }
300 }
301
302 return ret;
303}
304
305
152dump_hierarchy(GList *l, char *prefix) 306static void dump_hierarchy(GList *l, char *prefix)
153{ 307{
154 char *newprefix=g_alloca(sizeof(char)*(strlen(prefix)+2)); 308 char *newprefix = g_alloca(sizeof(char) * (strlen(prefix) + 2));
155 strcpy(newprefix, prefix); 309 strcpy(newprefix, prefix);
156 strcat(newprefix," "); 310 strcat(newprefix, " ");
157 while (l) { 311 while (l)
312 {
158 struct boundary *boundary=l->data; 313 struct boundary *boundary = l->data;
159 fprintf(stderr,"%s:%s (0x%x,0x%x)-(0x%x,0x%x)\n",prefix,osm_tag_name(boundary->ib),boundary->r.l.x,boundary->r.l.y,boundary->r.h.x,boundary->r.h.y); 314 fprintf(stderr, "%s:childs:%d:%lld:%s\n", prefix, g_list_length(boundary->children), item_bin_get_relationid(boundary->ib), osm_tag_name(boundary->ib));
160 dump_hierarchy(boundary->children, newprefix); 315 dump_hierarchy(boundary->children, newprefix);
161 l=g_list_next(l); 316 l = g_list_next(l);
162 } 317 }
163} 318}
164 319
165static gint
166boundary_bbox_compare(gconstpointer a, gconstpointer b) 320static gint boundary_bbox_compare(gconstpointer a, gconstpointer b)
167{ 321{
168 const struct boundary *boundarya=a; 322 const struct boundary *boundarya = a;
169 const struct boundary *boundaryb=b; 323 const struct boundary *boundaryb = b;
170 long long areaa=bbox_area(&boundarya->r); 324 long long areaa = bbox_area(&boundarya->r);
171 long long areab=bbox_area(&boundaryb->r); 325 long long areab = bbox_area(&boundaryb->r);
172 if (areaa > areab) 326 if (areaa > areab)
173 return 1; 327 return 1;
174 if (areaa < areab) 328 if (areaa < areab)
175 return -1; 329 return -1;
176 return 0; 330 return 0;
177} 331}
178 332
179static GList * 333static GList *
180process_boundaries_insert(GList *list, struct boundary *boundary) 334process_boundaries_insert(GList *list, struct boundary *boundary)
181{ 335{
336 // children stuff is totally broken, so it is disabled now!!
337 /*
182 GList *l=list; 338 GList *l = list;
183 while (l) { 339 while (l)
340 {
184 struct boundary *b=l->data; 341 struct boundary *b = l->data;
185 if (bbox_contains_bbox(&boundary->r, &b->r)) { 342 if (bbox_contains_bbox(&boundary->r, &b->r))
343 {
186 list=g_list_remove(list, b); 344 list = g_list_remove(list, b);
187 boundary->children=g_list_prepend(boundary->children, b); 345 boundary->children = g_list_prepend(boundary->children, b);
188 l=list; 346 l = list;
347 }
189 } else if (bbox_contains_bbox(&b->r, &boundary->r)) { 348 else if (bbox_contains_bbox(&b->r, &boundary->r))
349 {
190 b->children=process_boundaries_insert(b->children, boundary); 350 b->children = process_boundaries_insert(b->children, boundary);
191 return list; 351 return list;
352 }
192 } else 353 else
354 {
193 l=g_list_next(l); 355 l = g_list_next(l);
194 } 356 }
357 }
358 */
359 // children stuff is totally broken, so it is disabled now!!
360
195 return g_list_prepend(list, boundary); 361 return g_list_prepend(list, boundary);
196} 362}
197
198 363
199static GList * 364static GList *
200process_boundaries_finish(GList *boundaries_list) 365process_boundaries_finish(GList *boundaries_list)
201{ 366{
367 //fprintf(stderr,"process_boundaries_finish:001\n");
368
202 GList *l,*sl,*l2,*ln; 369 GList *l, *sl, *l2, *ln;
203 GList *ret=NULL; 370 GList *ret = NULL;
204 l=boundaries_list; 371 l = boundaries_list;
205 char *f1_name=NULL; 372 char *f1_name = NULL;
206 char *f2_name=NULL; 373 char *f2_name = NULL;
374 long long b_counter_1 = 0;
375 long long nodes_counter_ = 0;
376 long long ways_counter_ = 0;
377
207 while (l) 378 while (l)
208 { 379 {
209 struct boundary *boundary=l->data; 380 struct boundary *boundary = l->data;
210 int first=1; 381 int first = 1;
211 FILE *f=NULL,*fu=NULL; 382 FILE *f = NULL, *fu = NULL;
383
384 b_counter_1++;
385 if ((b_counter_1 % 500) == 0)
386 {
387 fprintf(stderr,"boundaries_f1:B:%lld\n", b_counter_1);
388 }
389
390 //fprintf(stderr,"process_boundaries_finish:002\n");
212 391
213 // only lowercase country code 392 // only lowercase country code
214 if (boundary->iso2) 393 if (boundary->iso2)
215 { 394 {
216 int i99; 395 int i99;
219 boundary->iso2[i99] = tolower(boundary->iso2[i99]); 398 boundary->iso2[i99] = tolower(boundary->iso2[i99]);
220 } 399 }
221 } 400 }
222 // only lowercase country code 401 // only lowercase country code
223 402
224 if (boundary->country) { 403 if (boundary->country)
404 {
405 //fprintf(stderr,"process_boundaries_finish:003\n");
406
225 char *name=g_strdup_printf("country_%s_poly",boundary->iso2); 407 char *name = g_strdup_printf("country_%s_poly", boundary->iso2);
226 f1_name=g_strdup_printf("country_%s_poly",boundary->iso2); 408 f1_name = g_strdup_printf("country_%s_poly", boundary->iso2);
227 f=tempfile("",name,1); 409 f = tempfile("", name, 1);
228 g_free(name); 410 g_free(name);
229 } 411 }
230 boundary->sorted_segments=geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side); 412
413
414
415 // calc bounding box
416 first = 1;
417 nodes_counter_ = 0;
418 ways_counter_ = 0;
231 sl=boundary->sorted_segments; 419 sl = boundary->segments;
232 while (sl) 420 while (sl)
233 { 421 {
234 struct geom_poly_segment *gs=sl->data; 422 struct geom_poly_segment *gs = sl->data;
235 struct coord *c=gs->first; 423 struct coord *c = gs->first;
236 while (c <= gs->last) { 424 while (c <= gs->last)
425 {
237 if (first) { 426 if (first)
427 {
238 boundary->r.l=*c; 428 boundary->r.l = *c;
239 boundary->r.h=*c; 429 boundary->r.h = *c;
240 first=0; 430 first = 0;
431 }
241 } else 432 else
433 {
242 bbox_extend(c, &boundary->r); 434 bbox_extend(c, &boundary->r);
435 }
243 c++; 436 c++;
437 nodes_counter_++;
438 }
439 sl = g_list_next(sl);
440 ways_counter_++;
441 }
442
443 //fprintf(stderr, "relid:%lld\n", item_bin_get_relationid(boundary->ib));
444 //fprintf(stderr, "ways:%lld nodes:%lld\n", ways_counter_, nodes_counter_);
445
446 boundary->sorted_segments = geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side);
447 sl = boundary->sorted_segments;
448
449 first = 1;
450 while (sl)
451 {
452 //fprintf(stderr,"process_boundaries_finish:004.1\n");
453
454 struct geom_poly_segment *gs = sl->data;
455 struct coord *c = gs->first;
456
457 /*
458 while (c <= gs->last)
459 {
460 if (first)
461 {
462 boundary->r.l = *c;
463 boundary->r.h = *c;
464 first = 0;
244 } 465 }
466 else
467 {
468 bbox_extend(c, &boundary->r);
469 }
470 c++;
471
472 //fprintf(stderr,"process_boundaries_finish:004.2 lx=%d ly=%d hx=%d hy=%d\n",boundary->r.l.x,boundary->r.l.y,boundary->r.h.x,boundary->r.h.y);
473
474 }
475 */
476
245 if (f) { 477 if (f)
478 {
246 struct item_bin *ib=item_bin; 479 struct item_bin *ib = item_bin_2;
247 item_bin_init(ib, type_selected_line); 480 item_bin_init(ib, type_selected_line);
248 item_bin_add_coord(ib, gs->first, gs->last-gs->first+1); 481 item_bin_add_coord(ib, gs->first, gs->last - gs->first + 1);
249 item_bin_write(ib, f); 482 item_bin_write(ib, f);
250 } 483 }
484
251 if (boundary->country) { 485 if (boundary->country)
486 {
252 if (!coord_is_equal(*gs->first,*gs->last)) { 487 if (!coord_is_equal(*gs->first, *gs->last))
488 {
253 if (!fu) { 489 if (!fu)
490 {
254 char *name=g_strdup_printf("country_%s_broken",boundary->iso2); 491 char *name = g_strdup_printf("country_%s_broken", boundary->iso2);
255 f2_name=g_strdup_printf("country_%s_broken",boundary->iso2); 492 f2_name = g_strdup_printf("country_%s_broken", boundary->iso2);
493 fprintf(stderr, "*BROKEN* country_%s_broken\n", boundary->iso2);
256 fu=tempfile("",name,1); 494 fu = tempfile("", name, 1);
257 g_free(name); 495 g_free(name);
258 } 496 }
259 struct item_bin *ib=item_bin; 497 struct item_bin *ib = item_bin_2;
260 item_bin_init(ib, type_selected_point); 498 item_bin_init(ib, type_selected_point);
261 item_bin_add_coord(ib, gs->first, 1); 499 item_bin_add_coord(ib, gs->first, 1);
262 item_bin_write(ib, fu); 500 item_bin_write(ib, fu);
263 501
264 item_bin_init(ib, type_selected_point); 502 item_bin_init(ib, type_selected_point);
265 item_bin_add_coord(ib, gs->last, 1); 503 item_bin_add_coord(ib, gs->last, 1);
266 item_bin_write(ib, fu); 504 item_bin_write(ib, fu);
267 } 505 }
268 } 506 }
269 sl=g_list_next(sl); 507 sl = g_list_next(sl);
270 508
271 if (f2_name) 509 if (f2_name)
272 { 510 {
273 tempfile_unlink("",f2_name); 511 tempfile_unlink("", f2_name);
274 g_free(f2_name); 512 g_free(f2_name);
275 f2_name=NULL; 513 f2_name = NULL;
514 }
276 } 515 }
277 } 516
278 ret=process_boundaries_insert(ret, boundary); 517 ret = process_boundaries_insert(ret, boundary);
279 l=g_list_next(l); 518 l = g_list_next(l);
519
280 if (f) 520 if (f)
521 {
281 fclose(f); 522 fclose(f);
523 }
524
282 if (fu) { 525 if (fu)
526 {
283 if (boundary->country) 527 if (boundary->country)
528 {
284 osm_warning("relation",item_bin_get_relationid(boundary->ib),0,"Broken country polygon '%s'\n",boundary->iso2); 529 //osm_warning("relation", item_bin_get_relationid(boundary->ib), 0, "Broken country polygon '%s'\n", boundary->iso2);
530 fprintf(stderr, "*BROKEN* country polygon '%s' relid=%lld\n", boundary->iso2, item_bin_get_relationid(boundary->ib));
531 }
285 fclose(fu); 532 fclose(fu);
286 } 533 }
287 534
288 if (f1_name) 535 if (f1_name)
289 { 536 {
290 tempfile_unlink("",f1_name); 537 tempfile_unlink("", f1_name);
291 g_free(f1_name); 538 g_free(f1_name);
292 f1_name=NULL; 539 f1_name = NULL;
293 } 540 }
294 } 541 }
295#if 0 542#if 0
296 printf("hierarchy\n"); 543 printf("hierarchy\n");
297#endif 544#endif
298 boundaries_list=g_list_sort(boundaries_list, boundary_bbox_compare); 545
299 l=boundaries_list; 546 // boundaries_list = g_list_sort(boundaries_list, boundary_bbox_compare); // disable sorting, does not seem to do any good
300 while (l) { 547
301 struct boundary *boundary=l->data; 548// children stuff totally broken!!!
302 ln=l2=g_list_next(l);
303 while (l2) {
304 struct boundary *boundary2=l2->data;
305 if (bbox_contains_bbox(&boundary2->r, &boundary->r)) {
306 boundaries_list=g_list_remove(boundaries_list, boundary);
307 boundary2->children=g_list_append(boundary2->children, boundary);
308#if 0 549#if 0
309 printf("found\n"); 550 b_counter_1 = 0;
551 l = boundaries_list;
552 while (l)
553 {
554 b_counter_1++;
555 if ((b_counter_1 % 500) == 0)
556 {
557 fprintf(stderr,"boundaries_f2:B:%lld\n", b_counter_1);
558 }
559
560 struct boundary *boundary = l->data;
561 ln = l2 = g_list_next(l);
562 while (l2)
563 {
564 struct boundary *boundary2 = l2->data;
565 if (bbox_contains_bbox(&boundary2->r, &boundary->r))
566 {
567 boundaries_list = g_list_remove(boundaries_list, boundary);
568 boundary2->children = g_list_append(boundary2->children, boundary);
569 break;
570 }
571 l2 = g_list_next(l2);
572 }
573 l = ln;
574 }
310#endif 575#endif
311 break; 576// children stuff totally broken!!!
312 } 577
313 l2=g_list_next(l2); 578 // -- DEBUG --
314 } 579 // -- DEBUG --
315 l=ln; 580 // -- DEBUG --
316 }
317 // dump_hierarchy(boundaries_list,""); --> make much data!! be careful 581 // dump_hierarchy(boundaries_list,""); // --> prints huge amounts of data!! be careful
318#if 0 582 // -- DEBUG --
319 printf("hierarchy done\n"); 583 // -- DEBUG --
320 printf("test\n"); 584 // -- DEBUG --
321 test(boundaries_list); 585
322#endif
323 return boundaries_list; 586 return boundaries_list;
324} 587}
325 588
326GList * 589GList *
327process_boundaries(FILE *boundaries, FILE *ways) 590process_boundaries(FILE *boundaries, FILE *coords, FILE *ways)
328{ 591{
329 GList *boundaries_list; 592 GList *boundaries_list;
330 struct relations *relations=relations_new(); 593 struct relations *relations = relations_new();
331 594
595 //fprintf(stderr,"process_boundaries:001\n");
332 boundaries_list=process_boundaries_setup(boundaries, relations); 596 boundaries_list = process_boundaries_setup(boundaries, relations);
597 //fprintf(stderr,"process_boundaries:001.rp1\n");
333 relations_process(relations, NULL, ways, NULL); 598 relations_process(relations, NULL, ways, NULL);
599 //fprintf(stderr,"process_boundaries:001.rp2\n");
334 return process_boundaries_finish(boundaries_list); 600 return process_boundaries_finish(boundaries_list);
335} 601}
336 602
337

Legend:
Removed from v.36  
changed lines
  Added in v.37

   
Visit the ZANavi Wiki