From bd31f85a2533bbb865a3daea7f6f18121f607d2f Mon Sep 17 00:00:00 2001 From: martin-s Date: Sun, 4 Sep 2011 19:13:05 +0000 Subject: [PATCH] Fix:maptool:Better diagnostics for coastline problems git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4755 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/maptool/coastline.c | 39 +++++++++++++++++++++++---------------- navit/navit/maptool/geom.c | 9 ++++++++- navit/navit/maptool/itembin.c | 27 +++++++++++++++++++++++++++ navit/navit/maptool/maptool.h | 3 +++ 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/navit/navit/maptool/coastline.c b/navit/navit/maptool/coastline.c index 836625a..042fb2b 100644 --- a/navit/navit/maptool/coastline.c +++ b/navit/navit/maptool/coastline.c @@ -21,7 +21,7 @@ struct coastline_tile { - osmid id; + osmid wayid; int edges; }; @@ -176,10 +176,12 @@ tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_da struct geom_poly_segment *first; struct item_bin *ib=NULL; struct item_bin_sink *out=data->sink->priv_data[1]; - struct coastline_tile *ct; int dbgl=1; int edges=0,flags; GList *sorted_segments,*curr; + struct item_bin *ibt=(struct item_bin *)(tile_data+1); + struct coastline_tile *ct=g_new0(struct coastline_tile, 1); + ct->wayid=item_bin_get_wayid(ibt); #if 0 if (strncmp(tile,"bcdbdcabddddba",7)) return; @@ -230,11 +232,11 @@ tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_da curr=g_list_next(curr); } if (flags == 1) { - struct coastline_tile *ct=g_new0(struct coastline_tile, 1); + ct->edges=15; ib=init_item(type_poly_water_tiled); item_bin_bbox(ib, &bbox); + item_bin_add_attr_longlong(ib, attr_osm_wayid, ct->wayid); item_bin_write_to_sink(ib, out, NULL); - ct->edges=15; g_hash_table_insert(data->tile_edges, g_strdup(tile), ct); return; } @@ -279,6 +281,7 @@ tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_da 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_add_attr_longlong(ib, attr_osm_wayid, ct->wayid); item_bin_write_to_sink(ib, out, NULL); end=cn[0]; break; @@ -329,7 +332,6 @@ tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_da } } #endif - ct=g_new0(struct coastline_tile, 1); ct->edges=edges; g_hash_table_insert(data->tile_edges, g_strdup(tile), ct); #if 0 @@ -346,7 +348,7 @@ tile_collector_process_tile(char *tile, int *tile_data, struct coastline_tile_da } static void -ocean_tile(GHashTable *hash, char *tile, char c, struct item_bin_sink *out) +ocean_tile(GHashTable *hash, char *tile, char c, osmid wayid, struct item_bin_sink *out) { int len=strlen(tile); char *tile2=g_alloca(sizeof(char)*(len+1)); @@ -365,9 +367,11 @@ ocean_tile(GHashTable *hash, char *tile, char c, struct item_bin_sink *out) tile_bbox(tile2, &bbox, 0); ib=init_item(type_poly_water_tiled); item_bin_bbox(ib, &bbox); + item_bin_add_attr_longlong(ib, attr_osm_wayid, wayid); item_bin_write_to_sink(ib, out, NULL); ct=g_new0(struct coastline_tile, 1); ct->edges=15; + ct->wayid=wayid; g_hash_table_insert(hash, g_strdup(tile2), ct); #if 0 item_bin_init(ib, type_border_country); @@ -402,21 +406,21 @@ tile_collector_add_siblings(char *tile, struct coastline_tile *ct, struct coastl if (debug) fprintf(stderr,"%s (%c) has %d edges active\n",tile,t,edges); if (t == 'a' && (edges & 1)) - ocean_tile(data->tile_edges, tile, 'b', out); + ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out); if (t == 'a' && (edges & 8)) - ocean_tile(data->tile_edges, tile, 'c', out); + ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out); if (t == 'b' && (edges & 4)) - ocean_tile(data->tile_edges, tile, 'a', out); + ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out); if (t == 'b' && (edges & 8)) - ocean_tile(data->tile_edges, tile, 'd', out); + ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out); if (t == 'c' && (edges & 1)) - ocean_tile(data->tile_edges, tile, 'd', out); + ocean_tile(data->tile_edges, tile, 'd', ct->wayid, out); if (t == 'c' && (edges & 2)) - ocean_tile(data->tile_edges, tile, 'a', out); + ocean_tile(data->tile_edges, tile, 'a', ct->wayid, out); if (t == 'd' && (edges & 4)) - ocean_tile(data->tile_edges, tile, 'c', out); + ocean_tile(data->tile_edges, tile, 'c', ct->wayid, out); if (t == 'd' && (edges & 2)) - ocean_tile(data->tile_edges, tile, 'b', out); + ocean_tile(data->tile_edges, tile, 'b', ct->wayid, out); } static int @@ -507,8 +511,11 @@ tile_collector_add_siblings2(char *tile, struct coastline_tile *ct, struct coast fprintf(stderr,"result '%s' %d old %d\n",tile2,pedges,co?co->edges:0); cn=g_new0(struct coastline_tile, 1); cn->edges=pedges; - if (co) + if (co) { cn->edges|=co->edges; + cn->wayid=co->wayid; + } else + cn->wayid=ct->wayid; g_hash_table_insert(data->tile_edges, g_strdup(tile2), cn); } @@ -584,10 +591,10 @@ coastline_processor_new(struct item_bin_sink *out) struct item_bin_sink_func *tile_collector=tile_collector_new(out); struct tile_parameter *param=g_new0(struct tile_parameter, 1); - fprintf(stderr,"new:out=%p\n",out); param->min=14; param->max=14; param->overlap=0; + param->attr_to_copy=attr_osm_wayid; item_bin_sink_add_func(tiles, tile_collector); coastline_processor->priv_data[0]=param; diff --git a/navit/navit/maptool/geom.c b/navit/navit/maptool/geom.c index 225b96a..991e980 100644 --- a/navit/navit/maptool/geom.c +++ b/navit/navit/maptool/geom.c @@ -509,6 +509,8 @@ clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, str item_bin_add_coord(ib_new, &p2, 1); } if (i == count-1 || (code & 4)) { + if (param->attr_to_copy) + item_bin_copy_attr(ib_new, ib, param->attr_to_copy); if (ib_new->clen) item_bin_write_clipped(ib_new, param, out); item_bin_init(ib_new, ib->type); @@ -518,6 +520,8 @@ clip_line(struct item_bin *ib, struct rect *r, struct tile_parameter *param, str item_bin_init(ib_new, ib->type); item_bin_add_coord(ib_new, &p1, 1); item_bin_add_coord(ib_new, &p2, 1); + if (param->attr_to_copy) + item_bin_copy_attr(ib_new, ib, param->attr_to_copy); item_bin_write_clipped(ib_new, param, out); } #endif @@ -610,6 +614,9 @@ clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, ib_out=ib2; } } - if (ib_in->clen) + if (ib_in->clen) { + if (param->attr_to_copy) + item_bin_copy_attr(ib_in, ib, param->attr_to_copy); item_bin_write_clipped(ib_in, param, out); + } } diff --git a/navit/navit/maptool/itembin.c b/navit/navit/maptool/itembin.c index 35f9070..f2dce72 100644 --- a/navit/navit/maptool/itembin.c +++ b/navit/navit/maptool/itembin.c @@ -100,6 +100,17 @@ item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir) } void +item_bin_copy_attr(struct item_bin *ib, struct item_bin *from, enum attr_type attr) +{ + struct attr_bin *ab=item_bin_get_attr_bin(from, attr, NULL); + if (ab) + item_bin_add_attr_data(ib, ab->type, (void *)(ab+1), (ab->len-1)*4); +#include + assert(attr == attr_osm_wayid); + assert(item_bin_get_wayid(ib) == item_bin_get_wayid(from)); +} + +void item_bin_add_coord_rect(struct item_bin *ib, struct rect *r) { item_bin_add_coord(ib, &r->l, 1); @@ -196,6 +207,22 @@ item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last) } struct attr_bin * +item_bin_get_attr_bin(struct item_bin *ib, enum attr_type type, void *last) +{ + unsigned char *s=(unsigned char *)ib; + unsigned char *e=s+(ib->len+1)*4; + s+=sizeof(struct item_bin)+ib->clen*4; + while (s < e) { + struct attr_bin *ab=(struct attr_bin *)s; + s+=(ab->len+1)*4; + if (ab->type == type && (void *)(ab+1) > last) { + return ab; + } + } + return NULL; +} + +struct attr_bin * item_bin_get_attr_bin_last(struct item_bin *ib) { struct attr_bin *ab=NULL; diff --git a/navit/navit/maptool/maptool.h b/navit/navit/maptool/maptool.h index 1ffc1f1..2738950 100644 --- a/navit/navit/maptool/maptool.h +++ b/navit/navit/maptool/maptool.h @@ -54,6 +54,7 @@ struct tile_parameter { int min; int max; int overlap; + enum attr_type attr_to_copy; }; struct tile_info { @@ -198,6 +199,7 @@ void item_bin_add_coord(struct item_bin *ib, struct coord *c, int count); void item_bin_add_coord_reverse(struct item_bin *ib, struct coord *c, int count); void item_bin_bbox(struct item_bin *ib, struct rect *r); void item_bin_copy_coord(struct item_bin *ib, struct item_bin *from, int dir); +void item_bin_copy_attr(struct item_bin *ib, struct item_bin *from, enum attr_type attr); void item_bin_add_coord_rect(struct item_bin *ib, struct rect *r); int attr_bin_write_data(struct attr_bin *ab, enum attr_type type, void *data, int size); int attr_bin_write_attr(struct attr_bin *ab, struct attr *attr); @@ -205,6 +207,7 @@ void item_bin_add_attr_data(struct item_bin *ib, enum attr_type type, void *data void item_bin_add_attr(struct item_bin *ib, struct attr *attr); void item_bin_add_attr_int(struct item_bin *ib, enum attr_type type, int val); void *item_bin_get_attr(struct item_bin *ib, enum attr_type type, void *last); +struct attr_bin * item_bin_get_attr_bin(struct item_bin *ib, enum attr_type type, void *last); struct attr_bin * item_bin_get_attr_bin_last(struct item_bin *ib); void item_bin_add_attr_longlong(struct item_bin *ib, enum attr_type type, long long val); void item_bin_add_attr_string(struct item_bin *ib, enum attr_type type, char *str); -- 2.7.4