Fix:maptool:Some cleanups
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 3 Dec 2009 10:22:51 +0000 (10:22 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Thu, 3 Dec 2009 10:22:51 +0000 (10:22 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2822 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/maptool/itembin.c
navit/navit/maptool/maptool.c
navit/navit/maptool/maptool.h
navit/navit/maptool/osm.c

index 9b42b91..47a0893 100644 (file)
@@ -267,3 +267,81 @@ dump_itembin(struct item_bin *ib)
        item_bin_dump(ib, stdout);
 }
 
+struct population_table {
+       enum item_type type;
+       int population;
+};
+
+static struct population_table town_population[] = {
+       {type_town_label_0e0,0},
+       {type_town_label_1e0,1},
+       {type_town_label_2e0,2},
+       {type_town_label_5e0,5},
+       {type_town_label_1e1,10},
+       {type_town_label_2e1,20},
+       {type_town_label_5e1,50},
+       {type_town_label_1e2,100},
+       {type_town_label_2e2,200},
+       {type_town_label_5e2,500},
+       {type_town_label_1e3,1000},
+       {type_town_label_2e3,2000},
+       {type_town_label_5e3,5000},
+       {type_town_label_1e4,10000},
+       {type_town_label_2e4,20000},
+       {type_town_label_5e4,50000},
+       {type_town_label_1e5,100000},
+       {type_town_label_2e5,200000},
+       {type_town_label_5e5,500000},
+       {type_town_label_1e6,1000000},
+       {type_town_label_2e6,2000000},
+       {type_town_label_5e6,5000000},
+       {type_town_label_1e7,1000000},
+};
+
+static struct population_table district_population[] = {
+       {type_district_label_0e0,0},
+       {type_district_label_1e0,1},
+       {type_district_label_2e0,2},
+       {type_district_label_5e0,5},
+       {type_district_label_1e1,10},
+       {type_district_label_2e1,20},
+       {type_district_label_5e1,50},
+       {type_district_label_1e2,100},
+       {type_district_label_2e2,200},
+       {type_district_label_5e2,500},
+       {type_district_label_1e3,1000},
+       {type_district_label_2e3,2000},
+       {type_district_label_5e3,5000},
+       {type_district_label_1e4,10000},
+       {type_district_label_2e4,20000},
+       {type_district_label_5e4,50000},
+       {type_district_label_1e5,100000},
+       {type_district_label_2e5,200000},
+       {type_district_label_5e5,500000},
+       {type_district_label_1e6,1000000},
+       {type_district_label_2e6,2000000},
+       {type_district_label_5e6,5000000},
+       {type_district_label_1e7,1000000},
+};
+
+void
+item_bin_set_type_by_population(struct item_bin *ib, int population)
+{
+       struct population_table *table;
+       int i,count;
+
+       if (population < 0)
+               population=0;
+       if (item_is_district(*item_bin)) {
+               table=district_population;
+               count=sizeof(district_population)/sizeof(district_population[0]);
+       } else {
+               table=town_population;
+               count=sizeof(town_population)/sizeof(town_population[0]);
+       }
+       for (i = 0 ; i < count ; i++) {
+               if (population < table[i].population)
+                       break;
+       }
+       item_bin_set_type(ib, table[i-1].type);
+}
index a5fb4a5..6bb1962 100644 (file)
@@ -404,32 +404,36 @@ int main(int argc, char **argv)
        }
 #if 1
        coastline=tempfile(suffix,"coastline",0);
-       ways_split=tempfile(suffix,"ways_split",2);
-       fprintf(stderr,"coastline=%p\n",coastline);
-       process_coastlines(coastline, ways_split);
-       fclose(ways_split);
-       fclose(coastline);
+       if (coastline) {
+               ways_split=tempfile(suffix,"ways_split",2);
+               fprintf(stderr,"coastline=%p\n",coastline);
+               process_coastlines(coastline, ways_split);
+               fclose(ways_split);
+               fclose(coastline);
+       }
 #endif
        if (start <= 3) {
                fprintf(stderr,"PROGRESS: Phase 3: sorting countries, generating turn restrictions\n");
                sort_countries(keep_tmpfiles);
                if (process_relations) {
                        turn_restrictions=tempfile(suffix,"turn_restrictions",0);
-                       relations=tempfile(suffix,"relations",1);
-                       coords=fopen("coords.tmp","rb");
-                       ways_split=tempfile(suffix,"ways_split",0);
-                       ways_split_index=tempfile(suffix,"ways_split_index",0);
-                       process_turn_restrictions(turn_restrictions,coords,ways_split,ways_split_index,relations);
-#if 0
-                       process_countries(ways_split,ways_split_index);
-#endif
-                       fclose(ways_split_index);
-                       fclose(ways_split);
-                       fclose(coords);
-                       fclose(relations);
-                       fclose(turn_restrictions);
-                       if(!keep_tmpfiles)
-                               tempfile_unlink(suffix,"turn_restrictions");
+                       if (turn_restrictions) {
+                               relations=tempfile(suffix,"relations",1);
+                               coords=fopen("coords.tmp","rb");
+                               ways_split=tempfile(suffix,"ways_split",0);
+                               ways_split_index=tempfile(suffix,"ways_split_index",0);
+                               process_turn_restrictions(turn_restrictions,coords,ways_split,ways_split_index,relations);
+       #if 0
+                               process_countries(ways_split,ways_split_index);
+       #endif
+                               fclose(ways_split_index);
+                               fclose(ways_split);
+                               fclose(coords);
+                               fclose(relations);
+                               fclose(turn_restrictions);
+                               if(!keep_tmpfiles)
+                                       tempfile_unlink(suffix,"turn_restrictions");
+                       }
                }
                if(!keep_tmpfiles)
                        tempfile_unlink(suffix,"ways_split_index");
index 3a9165a..42aae3f 100644 (file)
@@ -152,6 +152,8 @@ void item_bin_write(struct item_bin *ib, FILE *out);
 void item_bin_write_clipped(struct item_bin *ib, struct tile_parameter *param, struct item_bin_sink *out);
 void item_bin_dump(struct item_bin *ib, FILE *out);
 void dump_itembin(struct item_bin *ib);
+void item_bin_set_type_by_population(struct item_bin *ib, int population);
+
 
 /* maptool.c */
 
index bf6d522..b81dc7d 100644 (file)
@@ -1379,63 +1379,6 @@ end_way(FILE *out)
        }
 }
 
-struct population_table {
-       enum item_type type;
-       int population;
-};
-
-static struct population_table town_population[] = {
-       {type_town_label_0e0,0},
-       {type_town_label_1e0,1},
-       {type_town_label_2e0,2},
-       {type_town_label_5e0,5},
-       {type_town_label_1e1,10},
-       {type_town_label_2e1,20},
-       {type_town_label_5e1,50},
-       {type_town_label_1e2,100},
-       {type_town_label_2e2,200},
-       {type_town_label_5e2,500},
-       {type_town_label_1e3,1000},
-       {type_town_label_2e3,2000},
-       {type_town_label_5e3,5000},
-       {type_town_label_1e4,10000},
-       {type_town_label_2e4,20000},
-       {type_town_label_5e4,50000},
-       {type_town_label_1e5,100000},
-       {type_town_label_2e5,200000},
-       {type_town_label_5e5,500000},
-       {type_town_label_1e6,1000000},
-       {type_town_label_2e6,2000000},
-       {type_town_label_5e6,5000000},
-       {type_town_label_1e7,1000000},
-};
-
-static struct population_table district_population[] = {
-       {type_district_label_0e0,0},
-       {type_district_label_1e0,1},
-       {type_district_label_2e0,2},
-       {type_district_label_5e0,5},
-       {type_district_label_1e1,10},
-       {type_district_label_2e1,20},
-       {type_district_label_5e1,50},
-       {type_district_label_1e2,100},
-       {type_district_label_2e2,200},
-       {type_district_label_5e2,500},
-       {type_district_label_1e3,1000},
-       {type_district_label_2e3,2000},
-       {type_district_label_5e3,5000},
-       {type_district_label_1e4,10000},
-       {type_district_label_2e4,20000},
-       {type_district_label_5e4,50000},
-       {type_district_label_1e5,100000},
-       {type_district_label_2e5,200000},
-       {type_district_label_5e5,500000},
-       {type_district_label_1e6,1000000},
-       {type_district_label_2e6,2000000},
-       {type_district_label_5e6,5000000},
-       {type_district_label_1e7,1000000},
-};
-
 static void
 end_node(FILE *out)
 {
@@ -1456,24 +1399,8 @@ end_node(FILE *out)
                if (types[i] == type_none)
                        continue;
                item_bin_init(item_bin, types[i]);
-               if (item_is_town(*item_bin) && attr_strings[attr_string_population]) {
-                       int i,count,population=atoi(attr_strings[attr_string_population]);
-                       struct population_table *table;
-                       if (population < 0)
-                               population=0;
-                       if (item_is_district(*item_bin)) {
-                               table=district_population;
-                               count=sizeof(district_population)/sizeof(district_population[0]);
-                       } else {
-                               table=town_population;
-                               count=sizeof(town_population)/sizeof(town_population[0]);
-                       }
-                       for (i = 0 ; i < count ; i++) {
-                               if (population < table[i].population)
-                                       break;
-                       }
-                       item_bin_set_type(item_bin, table[i-1].type);
-               }
+               if (item_is_town(*item_bin) && attr_strings[attr_string_population]) 
+                       item_bin_set_type_by_population(item_bin, atoi(attr_strings[attr_string_population]));
                item_bin_add_coord(item_bin, &ni->c, 1);
                item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_name : attr_label, attr_strings[attr_string_label]);
                item_bin_add_attr_string(item_bin, attr_house_number, attr_strings[attr_string_house_number]);