static void tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_data *data) { int poly_start_valid,tile_start_valid,exclude,search=0; struct rect bbox; struct coord cn[2],end,poly_start,tile_start; struct geom_poly_segment *first; struct item_bin *ib=(struct item_bin *)buffer; struct item_bin_sink *out=data->sink->priv_data[1]; int dbgl=1; int edges=0,flags; GList *sorted_segments,*curr; #if 0 if (strncmp(tile,"bcdbdcabddddba",7)) return; #endif #if 0 if (strncmp(tile,"bcdbdcaaaaddba",14)) return; #endif #if 0 fprintf(stderr,"tile %s of size %d\n", tile, *tile_data); #endif tile_bbox(tile, &bbox, 0); sorted_segments=geom_poly_segments_sort(tile_data_to_segments(tile_data), geom_poly_segment_type_way_right_side); #if 0 { GList *sort_segments=sorted_segments; int count=0; while (sort_segments) { struct geom_poly_segment *seg=sort_segments->data; struct item_bin *ib=(struct item_bin *)buffer; char *text=g_strdup_printf("segment %d type %d %p %s area "LONGLONG_FMT,count++,seg->type,sort_segments,coord_is_equal(*seg->first, *seg->last) ? "closed":"open",geom_poly_area(seg->first,seg->last-seg->first+1)); item_bin_init(ib, type_rg_segment); item_bin_add_coord(ib, seg->first, seg->last-seg->first+1); item_bin_add_attr_string(ib, attr_debug, text); // fprintf(stderr,"%s\n",text); g_free(text); // item_bin_dump(ib, stderr); item_bin_write_to_sink(ib, out, NULL); sort_segments=g_list_next(sort_segments); } } #endif flags=0; curr=sorted_segments; while (curr) { struct geom_poly_segment *seg=curr->data; switch (seg->type) { case geom_poly_segment_type_way_inner: flags|=1; break; case geom_poly_segment_type_way_outer: flags|=2; break; default: flags|=4; break; } curr=g_list_next(curr); } if (flags == 1) { item_bin_init(ib, type_poly_water_tiled); item_bin_bbox(ib, &bbox); item_bin_write_to_sink(ib, out, NULL); g_hash_table_insert(data->tile_edges, g_strdup(tile), (void *)15); return; } #if 1 end=bbox.l; tile_start_valid=0; poly_start_valid=0; exclude=0; poly_start.x=0; poly_start.y=0; tile_start.x=0; tile_start.y=0; for (;;) { search++; // item_bin_write_debug_point_to_sink(out, &end, "Search %d",search); dbg(dbgl,"searching next polygon from 0x%x 0x%x\n",end.x,end.y); first=find_next(&bbox, sorted_segments, &end, exclude, cn); exclude=1; if (!first) break; if (!tile_start_valid) { tile_start=cn[0]; tile_start_valid=1; } else { if (cn[0].x == tile_start.x && cn[0].y == tile_start.y) { dbg(dbgl,"end of tile reached\n"); break; } } if (first->type == geom_poly_segment_type_none) { end=cn[0]; continue; } poly_start_valid=0; dbg(dbgl,"start of polygon 0x%x 0x%x\n",cn[0].x,cn[0].y); for (;;) { if (!poly_start_valid) { poly_start=cn[0]; poly_start_valid=1; item_bin_init(ib,type_poly_water_tiled); } else { close_polygon(ib, &end, &cn[0], 1, &bbox, &edges); if (cn[0].x == poly_start.x && cn[0].y == poly_start.y) { dbg(dbgl,"poly end reached\n"); item_bin_write_to_sink(ib, out, NULL); end=cn[0]; break; } } if (first->type == geom_poly_segment_type_none) break; item_bin_add_coord(ib, first->first, first->last-first->first+1); first->type=geom_poly_segment_type_none; end=cn[1]; if (distance_from_ll(&end, &bbox) == -1) { dbg(dbgl,"incomplete\n"); break; } first=find_next(&bbox, sorted_segments, &end, 1, cn); dbg(dbgl,"next segment of polygon 0x%x 0x%x\n",cn[0].x,cn[0].y); } if (search > 55) break; } #endif #if 0 { int *end=tile_data+tile_data[0]; int *curr=tile_data+1; while (curr < end) { struct item_bin *ib=(struct item_bin *)curr; // item_bin_dump(ib); ib->type=type_rg_segment; item_bin_write_to_sink(ib, out, NULL); curr+=ib->len+1; #if 0 { struct coord *c[2]; int i; char *s; c[0]=(struct coord *)(ib+1); c[1]=c[0]+ib->clen/2-1; for (i = 0 ; i < 2 ; i++) { s=coord_to_str(c[i]); item_bin_write_debug_point_to_sink(out, c[i], "%s",s); g_free(s); } } #endif } } #endif g_hash_table_insert(data->tile_edges, g_strdup(tile), (void *)edges); #if 0 item_bin_init(ib, type_border_country); item_bin_bbox(ib, &bbox); item_bin_add_attr_string(ib, attr_debug, tile); item_bin_write_to_sink(ib, out, NULL); #endif #if 0 c.x=(bbox.l.x+bbox.h.x)/2; c.y=(bbox.l.y+bbox.h.y)/2; item_bin_write_debug_point_to_sink(out, &c, "%s %d",tile,edges); #endif }
static GList * process_boundaries_finish(GList *boundaries_list) { //fprintf(stderr,"process_boundaries_finish:001\n"); GList *l, *sl, *l2, *ln; GList *ret = NULL; l = boundaries_list; char *f1_name = NULL; char *f2_name = NULL; long long b_counter_1 = 0; long long nodes_counter_ = 0; long long ways_counter_ = 0; while (l) { struct boundary *boundary = l->data; int first = 1; FILE *f = NULL, *fu = NULL; b_counter_1++; if ((b_counter_1 % 500) == 0) { fprintf(stderr,"boundaries_f1:B:%lld\n", b_counter_1); } //fprintf(stderr,"process_boundaries_finish:002\n"); // only lowercase country code if (boundary->iso2) { int i99; for (i99 = 0; boundary->iso2[i99]; i99++) { boundary->iso2[i99] = tolower(boundary->iso2[i99]); } } // only lowercase country code if (boundary->country) { //fprintf(stderr,"process_boundaries_finish:003\n"); char *name = g_strdup_printf("country_%s_poly", boundary->iso2); f1_name = g_strdup_printf("country_%s_poly", boundary->iso2); f = tempfile("", name, 1); g_free(name); } // calc bounding box first = 1; nodes_counter_ = 0; ways_counter_ = 0; sl = boundary->segments; while (sl) { struct geom_poly_segment *gs = sl->data; struct coord *c = gs->first; while (c <= gs->last) { if (first) { boundary->r.l = *c; boundary->r.h = *c; first = 0; } else { bbox_extend(c, &boundary->r); } c++; nodes_counter_++; } sl = g_list_next(sl); ways_counter_++; } //fprintf(stderr, "relid:%lld\n", item_bin_get_relationid(boundary->ib)); //fprintf(stderr, "ways:%lld nodes:%lld\n", ways_counter_, nodes_counter_); boundary->sorted_segments = geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side); sl = boundary->sorted_segments; first = 1; while (sl) { //fprintf(stderr,"process_boundaries_finish:004.1\n"); struct geom_poly_segment *gs = sl->data; struct coord *c = gs->first; /* while (c <= gs->last) { if (first) { boundary->r.l = *c; boundary->r.h = *c; first = 0; } else { bbox_extend(c, &boundary->r); } c++; //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); } */ if (f) { struct item_bin *ib = item_bin_2; item_bin_init(ib, type_selected_line); item_bin_add_coord(ib, gs->first, gs->last - gs->first + 1); item_bin_write(ib, f); } if (boundary->country) { if (!coord_is_equal(*gs->first, *gs->last)) { if (!fu) { char *name = g_strdup_printf("country_%s_broken", boundary->iso2); f2_name = g_strdup_printf("country_%s_broken", boundary->iso2); fprintf(stderr, "*BROKEN* country_%s_broken\n", boundary->iso2); fu = tempfile("", name, 1); g_free(name); } struct item_bin *ib = item_bin_2; item_bin_init(ib, type_selected_point); item_bin_add_coord(ib, gs->first, 1); item_bin_write(ib, fu); item_bin_init(ib, type_selected_point); item_bin_add_coord(ib, gs->last, 1); item_bin_write(ib, fu); } } sl = g_list_next(sl); if (f2_name) { tempfile_unlink("", f2_name); g_free(f2_name); f2_name = NULL; } } ret = process_boundaries_insert(ret, boundary); l = g_list_next(l); if (f) { fclose(f); } if (fu) { if (boundary->country) { //osm_warning("relation", item_bin_get_relationid(boundary->ib), 0, "Broken country polygon '%s'\n", boundary->iso2); fprintf(stderr, "*BROKEN* country polygon '%s' relid=%lld\n", boundary->iso2, item_bin_get_relationid(boundary->ib)); } fclose(fu); } if (f1_name) { tempfile_unlink("", f1_name); g_free(f1_name); f1_name = NULL; } } #if 0 printf("hierarchy\n"); #endif // boundaries_list = g_list_sort(boundaries_list, boundary_bbox_compare); // disable sorting, does not seem to do any good // children stuff totally broken!!! #if 0 b_counter_1 = 0; l = boundaries_list; while (l) { b_counter_1++; if ((b_counter_1 % 500) == 0) { fprintf(stderr,"boundaries_f2:B:%lld\n", b_counter_1); } struct boundary *boundary = l->data; ln = l2 = g_list_next(l); while (l2) { struct boundary *boundary2 = l2->data; if (bbox_contains_bbox(&boundary2->r, &boundary->r)) { boundaries_list = g_list_remove(boundaries_list, boundary); boundary2->children = g_list_append(boundary2->children, boundary); break; } l2 = g_list_next(l2); } l = ln; } #endif // children stuff totally broken!!! // -- DEBUG -- // -- DEBUG -- // -- DEBUG -- // dump_hierarchy(boundaries_list,""); // --> prints huge amounts of data!! be careful // -- DEBUG -- // -- DEBUG -- // -- DEBUG -- return boundaries_list; }
static GList * process_boundaries_finish(GList *boundaries_list) { GList *l,*sl; GList *ret=NULL; l=boundaries_list; while (l) { struct boundary *boundary=l->data; int first=1; FILE *f=NULL,*fu=NULL; if (boundary->country) { char *name=g_strdup_printf("country_%s_poly",boundary->iso2); f=tempfile("",name,1); g_free(name); } boundary->sorted_segments=geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side); sl=boundary->sorted_segments; while (sl) { struct geom_poly_segment *gs=sl->data; struct coord *c=gs->first; while (c <= gs->last) { if (first) { boundary->r.l=*c; boundary->r.h=*c; first=0; } else bbox_extend(c, &boundary->r); c++; } if (f) { struct item_bin *ib=tmp_item_bin; item_bin_init(ib, type_selected_line); item_bin_add_coord(ib, gs->first, gs->last-gs->first+1); item_bin_write(ib, f); } if (boundary->country) { if (!coord_is_equal(*gs->first,*gs->last)) { struct item_bin *ib; if (!fu) { char *name=g_strdup_printf("country_%s_broken",boundary->iso2); fu=tempfile("",name,1); g_free(name); } ib=tmp_item_bin; item_bin_init(ib, type_selected_point); item_bin_add_coord(ib, gs->first, 1); item_bin_write(ib, fu); item_bin_init(ib, type_selected_point); item_bin_add_coord(ib, gs->last, 1); item_bin_write(ib, fu); } } sl=g_list_next(sl); } ret=process_boundaries_insert(ret, boundary); l=g_list_next(l); if (f) fclose(f); if (fu) { if (boundary->country) osm_warning("relation",item_bin_get_relationid(boundary->ib),0,"Broken country polygon '%s'\n",boundary->iso2); fclose(fu); } } #if 0 printf("hierarchy\n"); #endif #if 0 boundaries_list=g_list_sort(boundaries_list, boundary_bbox_compare); l=boundaries_list; while (l) { struct boundary *boundary=l->data; GList *l2,*ln; ln=l2=g_list_next(l); while (l2) { struct boundary *boundary2=l2->data; if (bbox_contains_bbox(&boundary2->r, &boundary->r)) { boundaries_list=g_list_remove(boundaries_list, boundary); boundary2->children=g_list_append(boundary2->children, boundary); #if 0 printf("found\n"); #endif break; } l2=g_list_next(l2); } l=ln; } dump_hierarchy(boundaries_list,""); #if 0 printf("hierarchy done\n"); printf("test\n"); test(boundaries_list); #endif #endif return ret; }