Пример #1
0
static void
ocean_tile(GHashTable *hash, char *tile, char c, struct item_bin_sink *out)
{
	int len=strlen(tile);
	char tile2[len+1];
	struct rect bbox;
	struct item_bin *ib=(struct item_bin *)buffer;
	struct coord co;

	strcpy(tile2, tile);
	tile2[len-1]=c;
	//fprintf(stderr,"Testing %s\n",tile2);
	if (g_hash_table_lookup_extended(hash, tile2, NULL, NULL))
		return;
	//fprintf(stderr,"%s ok\n",tile2);
	tile_bbox(tile2, &bbox, 0);
	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(hash, g_strdup(tile2), (void *)15);
#if 0
	item_bin_init(ib, type_border_country);
	item_bin_bbox(ib, &bbox);
	item_bin_add_attr_string(ib, attr_debug, tile2);
	item_bin_write_to_sink(ib, out, NULL);
#endif
	co.x=(bbox.l.x+bbox.h.x)/2;
	co.y=(bbox.l.y+bbox.h.y)/2;
	//item_bin_write_debug_point_to_sink(out, &co, "%s 15",tile2);
	
}
Пример #2
0
static void
ocean_tile2(struct rect *r, int dx, int dy, int wf, int hf, struct item_bin_sink *out)
{
	struct item_bin *ib=(struct item_bin *)buffer;
	int w=r->h.x-r->l.x;
	int h=r->h.y-r->l.y;
	char tile2[32];
	struct rect bbox;
	struct coord co;
	bbox.l.x=r->l.x+dx*w;
	bbox.l.y=r->l.y+dy*h;
	bbox.h.x=bbox.l.x+w*wf;
	bbox.h.y=bbox.l.y+h*hf;
	//fprintf(stderr,"0x%x,0x%x-0x%x,0x%x -> 0x%x,0x%x-0x%x,0x%x\n",r->l.x,r->l.y,r->h.x,r->h.y,bbox.l.x,bbox.l.y,bbox.h.x,bbox.h.y);
	item_bin_init(ib,type_poly_water_tiled);
	item_bin_bbox(ib, &bbox);
	item_bin_write_to_sink(ib, out, NULL);
#if 0
	item_bin_init(ib, type_border_country);
	item_bin_bbox(ib, &bbox);
	item_bin_add_attr_string(ib, attr_debug, tile2);
	item_bin_write_to_sink(ib, out, NULL);
#endif
	tile(&bbox, NULL, tile2, 32, 0, NULL);
	co.x=(bbox.l.x+bbox.h.x)/2;
	co.y=(bbox.l.y+bbox.h.y)/2;
	//item_bin_write_debug_point_to_sink(out, &co, "%s 15",tile2);
}
Пример #3
0
void
item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, int maxdepth, FILE *out)
{
	char *word=item_bin_get_attr(ib, type, NULL);
	int i,words=0,len;
	char tilename[32]="";

	if (!word)
		return;

	if(maxdepth && ib->clen>0) {
		struct rect r;
		struct coord *c=(struct coord *)(ib+1);
		r.l=c[0];
		r.h=c[0];
		for (i = 1 ; i < ib->clen/2 ; i++)
			bbox_extend(&c[i], &r);
		tile(&r,NULL,tilename,maxdepth,overlap,NULL);
	}

	/* insert attr_tile_name attribute before the attribute used as alphabetical key (of type type) */
	if(maxdepth) {
		item_bin_add_attr_string(ib, attr_tile_name, tilename);
		item_bin_add_attr_string(ib, type, word);
		item_bin_remove_attr(ib,word);
		word=item_bin_get_attr(ib, type, NULL);
	}
	len=ib->len;
	do  {
		if (linguistics_search(word)) {
			for (i = 0 ; i < 3 ; i++) {
				char *str=linguistics_expand_special(word, i);
				if (str) {
					ib->len=len;
					if (i || words)
						item_bin_add_attr_string(ib, match, str);
					item_bin_write(ib, out);
					g_free(str);
				}
			}
			words++;
		}
		word=linguistics_next_word(word);
	} while (word);
}
Пример #4
0
void
item_bin_write_match(struct item_bin *ib, enum attr_type type, enum attr_type match, FILE *out)
{
	char *word=item_bin_get_attr(ib, type, NULL);
	int i,words=0,len=ib->len;
	if (!word)
		return;
	do  {
		if (linguistics_search(word)) {
			for (i = 0 ; i < 3 ; i++) {
				char *str=linguistics_expand_special(word, i);
				if (str) {
					ib->len=len;
					if (i || words)
						item_bin_add_attr_string(ib, match, str);
					item_bin_write(ib, out);
					g_free(str);
				}
			}
			words++;
		}
		word=linguistics_next_word(word);
	} while (word);
}
Пример #5
0
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
}