unlink("coords.tmp");
if (p->process_ways)
p->osm.ways=tempfile(suffix,"ways",1);
- if (p->process_nodes)
+ if (p->process_nodes) {
p->osm.nodes=tempfile(suffix,"nodes",1);
+ p->osm.towns=tempfile(suffix,"towns",1);
+ }
if (p->process_ways && p->process_nodes) {
p->osm.turn_restrictions=tempfile(suffix,"turn_restrictions",1);
if(doway2poi) {
fclose(p->osm.poly2poi);
if (p->osm.line2poi)
fclose(p->osm.line2poi);
+ if (p->osm.towns)
+ fclose(p->osm.towns);
}
int debug_ref=0;
}
phase++;
if (p.start <= phase && p.end >= phase) {
+ FILE *towns=tempfile(suffix,"towns",0);
+ fprintf(stderr,"PROGRESS: Phase %d: assinging towns to countries\n",phase);
+ osm_process_towns(towns);
+ fclose(towns);
+ if(!p.keep_tmpfiles)
+ tempfile_unlink(suffix,"towns");
+ }
+ phase++;
+ if (p.start <= phase && p.end >= phase) {
fprintf(stderr,"PROGRESS: Phase %d: sorting countries\n",phase);
sort_countries(p.keep_tmpfiles);
p.countries_loaded=1;
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);
void item_bin_add_attr_range(struct item_bin *ib, enum attr_type type, short min, short max);
+void item_bin_remove_attr(struct item_bin *ib, void *ptr);
void item_bin_write(struct item_bin *ib, FILE *out);
struct item_bin *item_bin_dup(struct item_bin *ib);
void item_bin_write_range(struct item_bin *ib, FILE *out, int min, int max);
FILE *ways;
FILE *line2poi;
FILE *poly2poi;
+ FILE *towns;
};
void osm_add_tag(char *k, char *v);
void process_way2poi(FILE *in, FILE *out, int type);
int map_find_intersections(FILE *in, FILE *out, FILE *out_index, FILE *out_graph, FILE *out_coastline, int final);
void write_countrydir(struct zip_info *zip_info);
+void osm_process_towns(FILE *in);
void load_countries(void);
void remove_countryfiles(void);
void osm_init(FILE*);
void
osm_end_node(struct maptool_osm *osm)
{
- int conflict,count,i;
+ int count,i;
char *postal;
enum item_type types[10];
- struct country_table *result=NULL, *lookup;
struct item_bin *item_bin;
in_node=0;
}
dbg_assert(count < 10);
for (i = 0 ; i < count ; i++) {
- conflict=0;
if (types[i] == type_none)
continue;
if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn))
item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal);
}
item_bin_write(item_bin,osm->nodes);
- if (item_is_town(*item_bin) && attr_strings[attr_string_label]) {
- char *tok,*buf=is_in_buffer;
- if (!buf[0] && unknown_country)
- strcpy(is_in_buffer, "Unknown");
- while ((tok=strtok(buf, ",;"))) {
- while (*tok==' ')
- tok++;
- lookup=g_hash_table_lookup(country_table_hash,tok);
- if (lookup) {
- if (result && result->countryid != lookup->countryid) {
- osm_warning("node",nodeid,0,"conflict for %s %s country %d vs %d\n", attr_strings[attr_string_label], debug_attr_buffer, lookup->countryid, result->countryid);
- conflict=1;
- }
- result=lookup;
+ if (item_is_town(*item_bin) && attr_strings[attr_string_label] && osm->towns) {
+ item_bin=init_item(item_bin->type);
+ item_bin_add_coord(item_bin, &ni->c, 1);
+ item_bin_add_attr_string(item_bin, attr_osm_is_in, is_in_buffer);
+ item_bin_add_attr_string(item_bin, attr_town_postal, postal);
+ item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
+ item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]);
+ item_bin_write(item_bin, osm->towns);
+ }
+ }
+ processed_nodes_out++;
+ attr_longest_match_clear();
+}
+
+void
+osm_process_towns(FILE *in)
+{
+ struct item_bin *ib;
+
+ while ((ib=read_item(in))) {
+ struct country_table *result=NULL, *lookup;
+ char *tok,*is_in=item_bin_get_attr(ib, attr_osm_is_in, NULL), *buf=g_strdup(is_in);
+ int conflict;
+ if (!buf && unknown_country)
+ buf=g_strdup("Unknown");
+ while ((tok=strtok(buf, ",;"))) {
+ while (*tok==' ')
+ tok++;
+ lookup=g_hash_table_lookup(country_table_hash,tok);
+ if (lookup) {
+ if (result && result->countryid != lookup->countryid) {
+ osm_warning("node",nodeid,0,"conflict for %s %s country %d vs %d\n", attr_strings[attr_string_label], debug_attr_buffer, lookup->countryid, result->countryid);
+ conflict=1;
}
- buf=NULL;
+ result=lookup;
}
- if (result) {
- if (!result->file) {
- char *name=g_strdup_printf("country_%d.bin.unsorted", result->countryid);
- result->file=fopen(name,"wb");
- g_free(name);
- }
- if (result->file) {
- item_bin=init_item(item_bin->type);
- item_bin_add_coord(item_bin, &ni->c, 1);
- item_bin_add_attr_string(item_bin, attr_town_postal, postal);
- item_bin_add_attr_string(item_bin, attr_county_name, attr_strings[attr_string_county_name]);
- item_bin_add_attr_string(item_bin, attr_town_name, attr_strings[attr_string_label]);
- item_bin_write_match(item_bin, attr_town_name, attr_town_name_match, result->file);
- }
-
+ buf=NULL;
+ }
+ if (result) {
+ if (!result->file) {
+ char *name=g_strdup_printf("country_%d.bin.unsorted", result->countryid);
+ result->file=fopen(name,"wb");
+ g_free(name);
+ }
+ if (result->file) {
+ if (is_in)
+ item_bin_remove_attr(ib, is_in);
+ item_bin_write_match(ib, attr_town_name, attr_town_name_match, result->file);
}
}
+ g_free(buf);
}
- processed_nodes_out++;
- attr_longest_match_clear();
}
void