コード例 #1
0
ファイル: misc.c プロジェクト: justinzane/navit
void
phase1_map(struct map *map, FILE *out_ways, FILE *out_nodes)
{
	struct map_rect *mr=map_rect_new(map, NULL);
	struct item *item;
	int count,max=16384;
	struct coord ca[max];
	struct attr attr;

	while ((item = map_rect_get_item(mr))) {
		count=item_coord_get(item, ca, item->type < type_line ? 1: max);
		item_bin_init(item_bin, item->type);
		item_bin_add_coord(item_bin, ca, count);
		while (item_attr_get(item, attr_any, &attr)) {
			if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) {
				attr.u.str=map_convert_string(map, attr.u.str);
				item_bin_add_attr(item_bin, &attr);
				map_convert_free(attr.u.str);
			} else 
				item_bin_add_attr(item_bin, &attr);
		}
		if (item->type >= type_line) 
			item_bin_write(item_bin, out_ways);
		else
			item_bin_write(item_bin, out_nodes);
	}
	map_rect_destroy(mr);
}
コード例 #2
0
ファイル: misc.c プロジェクト: Jalakas/navit
void
phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes)
{
	struct map_rect *mr;
	struct item *item;
	int count;
	struct coord ca[phase1_coord_max];
	struct attr attr;
	struct item_bin *item_bin;

	while (maps) {
		mr=map_rect_new(maps->data, NULL);
		while ((item = map_rect_get_item(mr))) {
			count=item_coord_get(item, ca, item->type < type_line ? 1: phase1_coord_max);
			item_bin=init_item(item->type);
			item_bin_add_coord(item_bin, ca, count);
			while (item_attr_get(item, attr_any, &attr)) {
				if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) {
					attr.u.str=map_convert_string(maps->data, attr.u.str);
					if (attr.u.str) {
						item_bin_add_attr(item_bin, &attr);
						map_convert_free(attr.u.str);
					}
				} else 
					item_bin_add_attr(item_bin, &attr);
			}
			if (item->type >= type_line) 
				item_bin_write(item_bin, out_ways);
			else
				item_bin_write(item_bin, out_nodes);
		}
		map_rect_destroy(mr);
		maps=g_list_next(maps);
	}
}
コード例 #3
0
ファイル: sourcesink.c プロジェクト: Jalakas/navit
int
file_writer_process(struct item_bin_sink_func *func, struct item_bin *ib, struct tile_data *tile_data)
{
	FILE *out=func->priv_data[0];
	item_bin_write(ib, out);
	return 0;
}
コード例 #4
0
ファイル: itembin.c プロジェクト: Jalakas/navit
void
item_bin_write_range(struct item_bin *ib, FILE *out, int min, int max)
{
	struct range r;

	r.min=min;
	r.max=max;
	fwrite(&r, sizeof(r), 1, out);
	item_bin_write(ib, out);
}
コード例 #5
0
ファイル: tile.c プロジェクト: noradtux/navit-webos
void
index_init(struct zip_info *info, int version)
{
    struct item_bin *item_bin;
    int i;
    map_information_attrs[0].type=attr_version;
    map_information_attrs[0].u.num=version;
    item_bin=init_item(type_map_information);
    for (i = 0 ; i < 32 ; i++) {
        if (!map_information_attrs[i].type)
            break;
        item_bin_add_attr(item_bin, &map_information_attrs[i]);
    }
    item_bin_write(item_bin, zip_get_index(info));
}
コード例 #6
0
ファイル: itembin.c プロジェクト: Jalakas/navit
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);
}
コード例 #7
0
ファイル: itembin.c プロジェクト: albertz/navit
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);
}
コード例 #8
0
ファイル: ch.c プロジェクト: PDXostc/navit
static void
ch_process_node(FILE *out, int node, int resolve)
{
	int first_edge_id=nodes[node].first_edge;
	int last_edge_id=nodes[node+1].first_edge;
	int edge_id;
	struct ch_edge ch_edge;
	struct item_bin *item_bin;
	struct edge_hash_item fwd,rev;
	int oldnode;
	memset(&ch_edge, 0, sizeof(ch_edge));
	item_bin=init_item(type_ch_node);
	oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER(node)));
#if 0
	dbg(lvl_debug,"0x%x,0x%x\n",node_index[oldnode].x,node_index[oldnode].y);
#endif
	item_bin_add_coord(item_bin, &node_index[oldnode], 1);
	fwd.first=oldnode;
	rev.last=oldnode;
	for (edge_id = first_edge_id ; edge_id < last_edge_id ; edge_id++) {
		if (resolve)  {
			struct edge *edge=&edges[edge_id];
			int oldnode=GPOINTER_TO_INT(g_hash_table_lookup(newnode_hash, GINT_TO_POINTER((int)edge->target)));
			struct item_id *id;
			ch_edge.weight=edge->weight;
			fwd.last=oldnode;
			rev.first=oldnode;
			ch_edge.flags=edge->flags & 3;
			if (edge->scmiddle == 67108863) {
				id=g_hash_table_lookup(edge_hash, &fwd);
				if (!id) {
					ch_edge.flags|=8;
					id=g_hash_table_lookup(edge_hash, &rev);
				}
				if (id == NULL) {
					fprintf(stderr,"Shortcut %d Weight %d\n",edge->scmiddle,edge->weight);
					fprintf(stderr,"Neither %d-%d nor %d-%d exists\n",fwd.first,fwd.last,rev.first,rev.last);
					exit(1);
				} else {
					ch_edge.middle=*id;
#if 0
					dbg(lvl_debug,"middle street id for is "ITEM_ID_FMT"\n",ITEM_ID_ARGS(*id));
#endif
				}
			} else {
				ch_edge.flags|=4;
				id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->scmiddle));
				dbg_assert(id != NULL);
				ch_edge.middle=*id;
#if 0
				dbg(lvl_debug,"middle node id for is "ITEM_ID_FMT"\n",ITEM_ID_ARGS(*id));
#endif
			}
			id=g_hash_table_lookup(sgr_nodes_hash, GINT_TO_POINTER((int)edge->target));
#if 0
			dbg(lvl_debug,"id for %d is "ITEM_ID_FMT"\n",edge->target,ITEM_ID_ARGS(*id));
#endif
			if (id == NULL) {
				fprintf(stderr,"Failed to look up target %d\n",edge->target);
			} else {
				ch_edge.target=*id;
			}
		}
		item_bin_add_attr_data(item_bin,attr_ch_edge,&ch_edge,sizeof(ch_edge));
	}
	item_bin_write(item_bin, out);
}
コード例 #9
0
ファイル: tile.c プロジェクト: noradtux/navit-webos
void
write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out)
{
    int idx,len,maxlen;
    GList *next,*tiles_list;
    char **data;
    struct tile_head *th,**last=NULL;

    tiles_list=get_tiles_list();
    info->tiles_list=&tiles_list;
    if (! info->write)
        create_tile_hash_list(tiles_list);
    next=g_list_first(tiles_list);
    last=&tile_head_root;
    maxlen=info->maxlen;
    if (! maxlen) {
        while (next) {
            if (strlen(next->data) > maxlen)
                maxlen=strlen(next->data);
            next=g_list_next(next);
        }
    }
    len=maxlen;
    while (len >= 0) {
#if 0
        fprintf(stderr,"PROGRESS: collecting tiles with len=%d\n", len);
#endif
        next=g_list_first(tiles_list);
        while (next) {
            if (strlen(next->data) == len) {
                th=g_hash_table_lookup(tile_hash, next->data);
                if (!info->write) {
                    *last=th;
                    last=&th->next;
                    th->next=NULL;
                    th->zipnum=zip_get_zipnum(zip_info);
                    fprintf(out,"%s:%d",strlen((char *)next->data)?(char *)next->data:"index",th->total_size);

                    for ( idx = 0; idx< th->num_subtiles; idx++ ) {
                        data= th_get_subtile( th, idx );
                        fprintf(out,":%s", *data);
                    }

                    fprintf(out,"\n");
                }
                if (th->name[strlen(info->suffix)])
                    index_submap_add(info, th);
                zip_add_member(zip_info);
                processed_tiles++;
            }
            next=g_list_next(next);
        }
        len--;
    }
    if (info->suffix[0] && info->write) {
        struct item_bin *item_bin=init_item(type_submap);
        item_bin_add_coord_rect(item_bin, &world_bbox);
        item_bin_add_attr_range(item_bin, attr_order, 0, 255);
        item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_get_zipnum(zip_info)-1);
        item_bin_write(item_bin, zip_get_index(zip_info));
    }
}
コード例 #10
0
ファイル: boundaries.c プロジェクト: nutellarlz/Navination
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;
}
コード例 #11
0
ファイル: boundaries.c プロジェクト: greg42/navit
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;
}