static void process_boundaries_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) { //fprintf(stderr,"process_boundaries_member:001\n"); struct boundary *b = relation_priv; enum geom_poly_segment_type role = (long) member_priv; int *dup; dup=item_bin_get_attr(member,attr_duplicate_way,NULL); // only add way to boundary if this way is not already added if(!dup || *dup == 0) { b->segments = g_list_prepend(b->segments, item_bin_to_poly_segment(member, role)); // fprintf(stderr, "process_boundaries_member: dupdup wayid=%lld %p\n", item_bin_get_wayid(member), dup); } else { // fprintf(stderr, "process_boundaries_member: dup=true wayid=%lld\n", item_bin_get_wayid(member)); } //fprintf(stderr,"process_boundaries_member:099\n"); }
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); }
static void process_boundaries_member(void *func_priv, void *relation_priv, struct item_bin *member, void *member_priv) { struct boundary *b=relation_priv; enum geom_poly_segment_type role=(long)member_priv; int *dup; dup=item_bin_get_attr(member,attr_duplicate,NULL); if(!dup || *dup==0) b->segments=g_list_prepend(b->segments,item_bin_to_poly_segment(member, role)); }
char * osm_tag_value(struct item_bin *ib, char *key) { char *tag=NULL; int len=strlen(key); while ((tag=item_bin_get_attr(ib, attr_osm_tag, tag))) { if (!strncmp(tag,key,len) && tag[len] == '=') return tag+len+1; } return NULL; }
long long * boundary_relid(struct boundary *b) { long long *id; if (!b) return 0; if (!b->ib) return 0; id = item_bin_get_attr(b->ib, attr_osm_relationid, NULL); if (id) return *id; return 0; }
static void test(GList *boundaries_list) { struct item_bin *ib; FILE *f=fopen("country_276.bin.unsorted","r"); printf("start\n"); while ((ib=read_item(f))) { struct coord *c=(struct coord *)(ib+1); char *name=item_bin_get_attr(ib, attr_town_name, NULL); printf("%s:",name); boundary_find_matches(boundaries_list, c); printf("\n"); } fclose(f); printf("end\n"); }
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); }
static GList * process_boundaries_setup(FILE *boundaries, struct relations *relations) { struct item_bin *ib; GList *boundaries_list = NULL; struct relations_func *relations_func; long long b_counter_1 = 0; // long long b_counter_2 = 0; //fprintf(stderr,"process_boundaries_setup:001\n"); relations_func = relations_func_new(process_boundaries_member, NULL); while ((ib = read_item(boundaries, 0))) { //fprintf(stderr,"********DUMP b ***********\n"); //dump_itembin(ib); //fprintf(stderr,"********DUMP b ***********\n"); char *member = NULL; struct boundary *boundary=g_new0(struct boundary, 1); char *admin_level = osm_tag_value(ib, "admin_level"); char *iso = osm_tag_value(ib, "ISO3166-1"); b_counter_1++; if ((b_counter_1 % 500) == 0) { fprintf(stderr,"boundaries:B:%lld\n", b_counter_1); } //fprintf(stderr,"process_boundaries_setup:002\n"); //fprintf(stderr,"== b:%s %s ==\n", iso, admin_level); /* disable spain for now since it creates a too large index */ if (admin_level && !strcmp(admin_level, "2") && (!iso || strcasecmp(iso, "es"))) { if (iso) { struct country_table *country = country_from_iso2(iso); if (!country) { osm_warning("relation", item_bin_get_relationid(ib), 0, "Country Boundary contains unknown ISO3166-1 value '%s'\n", iso); } else { boundary->iso2 = g_strdup(iso); osm_info("relation", item_bin_get_relationid(ib), 0, "Country Boundary for '%s'\n", iso); } boundary->country = country; } else { osm_warning("relation", item_bin_get_relationid(ib), 0, "Country Boundary doesn't contain an ISO3166-1 tag\n"); } } //b_counter_2 = 0; while ((member = item_bin_get_attr(ib, attr_osm_member, member))) { //fprintf(stderr,"process_boundaries_setup:005\n"); //fprintf(stderr,"********DUMP b ***********\n"); //dump_itembin(ib); //fprintf(stderr,"********DUMP b ***********\n"); //b_counter_2++; //fprintf(stderr,"boundaries:M:%lld\n", b_counter_2); long long wayid; int read = 0; if (sscanf(member, "2:%Ld:%n", &wayid, &read) >= 1) { char *rolestr = member + read; enum geom_poly_segment_type role; if (!strcmp(rolestr, "outer") || !strcmp(rolestr, "exclave")) role = geom_poly_segment_type_way_outer; else if (!strcmp(rolestr, "inner") || !strcmp(rolestr, "enclave")) role = geom_poly_segment_type_way_inner; else if (!strcmp(rolestr, "")) role = geom_poly_segment_type_way_unknown; else { osm_warning("relation", item_bin_get_relationid(ib), 0, "Unknown role %s in member ", rolestr); osm_warning("way", wayid, 1, "\n"); role = geom_poly_segment_type_none; } //fprintf(stderr,"process_boundaries_setup:006 %s %Ld\n", rolestr,wayid); relations_add_func(relations, relations_func, boundary, (gpointer) role, 2, wayid); } } boundary->ib = item_bin_dup(ib); boundaries_list = g_list_append(boundaries_list, boundary); } return boundaries_list; }
static GList * process_boundaries_setup(FILE *boundaries, struct relations *relations) { struct item_bin *ib; GList *boundaries_list=NULL; struct relations_func *relations_func; relations_func=relations_func_new(process_boundaries_member, NULL); while ((ib=read_item(boundaries))) { char *member=NULL; struct boundary *boundary=g_new0(struct boundary, 1); char *admin_level=osm_tag_value(ib, "admin_level"); char *iso=osm_tag_value(ib, "ISO3166-1"); int has_subrelations=0; int has_outer_ways=0; processed_relations++; if(!iso) iso=osm_tag_value(ib, "iso3166-1:alpha2"); if (admin_level && !strcmp(admin_level, "2")) { if(!iso) { char *int_name=osm_tag_value(ib,"int_name"); if(int_name && !strcmp(int_name,"France")) iso="FR"; } if (iso) { struct country_table *country=country_from_iso2(iso); if (!country) osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary contains unknown ISO3166-1 value '%s'\n",iso); else { boundary->iso2=g_strdup(iso); osm_info("relation",item_bin_get_relationid(ib),0,"Country Boundary for '%s'\n",iso); } boundary->country=country; } else osm_warning("relation",item_bin_get_relationid(ib),0,"Country Boundary doesn't contain an ISO3166-1 tag\n"); } while ((member=item_bin_get_attr(ib, attr_osm_member, member))) { long long osm_id; int read=0; enum relation_member_type member_type; int member_type_numeric; char *rolestr; if (sscanf(member,RELATION_MEMBER_PARSE_FORMAT,&member_type_numeric,&osm_id,&read) < 2) continue; member_type=(enum relation_member_type)member_type_numeric; rolestr=member+read; if(member_type==rel_member_node) { if(!strcmp(rolestr,"admin_centre") || !strcmp(rolestr,"admin_center")) boundary->admin_centre=osm_id; } if(member_type==rel_member_way) { enum geom_poly_segment_type role; if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave")) { has_outer_ways=1; role=geom_poly_segment_type_way_outer; } else if (!strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave")) role=geom_poly_segment_type_way_inner; else if (!strcmp(rolestr,"")) role=geom_poly_segment_type_way_unknown; else { osm_warning("relation",item_bin_get_relationid(ib),0,"Unknown role %s in member ",rolestr); osm_warning("way",osm_id,1,"\n"); role=geom_poly_segment_type_none; } relations_add_relation_member_entry(relations, relations_func, boundary, (gpointer)role, rel_member_way, osm_id); } if(member_type==rel_member_relation) { if (!strcmp(rolestr,"outer") || !strcmp(rolestr,"exclave") || !strcmp(rolestr,"inner") || !strcmp(rolestr,"enclave")) has_subrelations++; } } if(boundary->iso2 && has_subrelations) osm_warning("relation",item_bin_get_relationid(ib),0,"Country boundary '%s' has %d relations as boundary segments. These are not supported yet.\n", boundary->iso2, has_subrelations); if(boundary->iso2 && !has_outer_ways) { osm_warning("relation",item_bin_get_relationid(ib),0,"Skipping country boundary for '%s' because it has no outer ways.\n", boundary->iso2); g_free(boundary->iso2); boundary->iso2=NULL; } boundary->ib=item_bin_dup(ib); boundaries_list=g_list_append(boundaries_list, boundary); } return boundaries_list; }