Add:Core:Added svn version in navit -v output
[navit-package] / navit / osm2navit.c
index 5624761..67e272d 100644 (file)
@@ -139,7 +139,25 @@ static char *attrmap={
        "n      railway=level_crossing          poi_level_crossing\n"
        "n      railway=station         poi_rail_station\n"
        "n      railway=tram_stop               poi_rail_tram_stop\n"
+       "n      amenity=park_bench              poi_bench\n"
+       "n      amenity=bench           poi_bench\n"
+       "n      amenity=biergarten              poi_biergarten\n"
+       "n      historic=boundary_stone         poi_boundary_stone\n"
+       "n      historic=castle         poi_castle\n"
+       "n      historic=ruins          poi_ruins\n"
+       "n      Annehmlichkeit=Hochsitz         poi_hunting_stand\n"
+       "n      amenity=hunting_stand           poi_hunting_stand\n"
+       "n      historic=memorial               poi_memorial\n"
+       "n      historic=monument               poi_monument\n"
+       "n      amenity=shelter         poi_shelter\n"
+       "n      amenity=fountain                poi_fountain\n"
+       "n      amenity=drinking_water          poi_potable_water\n"
+       "n      amenity=toilets         poi_toilets\n"
+       "n      tourism=viewpoint               poi_viewpoint\n"
        "w      *=*                     street_unkn\n"
+       "w      contour_ext=elevation_major     height_line_1\n"
+       "w      contour_ext=elevation_medium    height_line_2\n"
+       "w      contour_ext=elevation_minor     height_line_3\n"
        "w      amenity=place_of_worship        poly_building\n"
        "w      building=*      poly_building\n"
        "w      aeroway=aerodrome       poly_airport\n"
@@ -154,7 +172,8 @@ static char *attrmap={
        "w      highway=path,bicycle=designated cycleway\n"
        "w      highway=footway         footway\n"
        "w      piste:type=nordic       piste_nordic\n"
-       "w      route=ski               piste_nordic\n"
+       "w      highway=footway,piste:type=nordic       footway_and_piste_nordic\n"
+       "w      route=ski       piste_nordic\n"
        "w      piste:type=downhill,piste:difficulty=novice     piste_downhill_novice\n"
        "w      piste:type=downhill,piste:difficulty=easy       piste_downhill_easy\n"
        "w      piste:type=downhill,piste:difficulty=intermediate       piste_downhill_intermediate\n"
@@ -162,8 +181,14 @@ static char *attrmap={
        "w      piste:type=downhill,piste:difficulty=expert     piste_downhill_expert\n"
        "w      piste:type=downhill,piste:difficulty=freeride   piste_downhill_freeride\n"
        "w      highway=path,foot=designated    footway\n"
-       "w      highway=steps           steps\n"
-       "w      highway=path            path\n"
+       "w      highway=steps   steps\n"
+       "w      highway=path    path\n"
+       "w      highway=path,sac_scale=hiking   hiking\n"
+       "w      highway=path,sac_scale=mountain_hiking  hiking_mountain\n"
+       "w      highway=path,sac_scale=demanding_mountain_hiking        hiking_mountain_demanding\n"
+       "w      highway=path,sac_scale=alpine_hiking    hiking_alpine\n"
+       "w      highway=path,sac_scale=demanding_alpine_hiking  hiking_alpine_demanding\n"
+       "w      highway=path,sac_scale=difficult_alpine_hiking  hiking_alpine_difficult\n"
        "w      highway=unsurfaced      track_gravelled\n"
        "w      highway=track           track_gravelled\n"
        "w      highway=track,tracktype=grade1          track_paved\n"
@@ -176,7 +201,8 @@ static char *attrmap={
        "w      highway=track,surface=ground            track_ground\n"
        "w      highway=track,tracktype=grade5          track_grass\n"
        "w      highway=track,surface=grass             track_grass\n"
-       "w      highway=parking_lane    street_service\n"
+       "w      highway=parking_lane    street_parking_lane\n"
+       "w      highway=service,service=parking_aisle   street_parking_lane\n"
        "w      highway=service         street_service\n"
        "w      highway=service,area=1  poly_service\n"
        "w      highway=construction            street_construction\n"
@@ -329,12 +355,20 @@ struct country_table {
        int count;
        struct rect r;
 } country_table[] = {
-       { 40,"Austria,Österreich,AUT"},
+       { 40,"Austria,�sterreich,AUT"},
        {124,"Canada"},
+       {208,"Denmark,Danmark,DK"},
+       {246,"Finland,Suomi"},
+       {250,"France,R�publique fran�aise,FR"},
        {276,"Germany,Deutschland,Bundesrepublik Deutschland"},
+       {380,"Italy,Italia"},
        {528,"Nederland,The Netherlands,Niederlande,NL"},
-       {756,"Schweiz"},
-       {840,"USA"}
+       {578,"Norway,Norge,Noreg,NO"},
+       {724,"Spain,Espana,Espana,Reino de Espana"},
+       {752,"Sweden,Sverige,Konungariket Sverige,SE"},
+       {756,"Schweiz"}, 
+       {826,"United Kingdom,UK"},
+       {840,"USA"} 
 };
 
 static GHashTable *country_table_hash;
@@ -930,6 +964,46 @@ parse_relation(char *p)
 }
 
 static void
+item_buffer_set_type(char *buffer, enum item_type type)
+{
+       struct item_bin *ib=(struct item_bin *) buffer;
+       ib->clen=0;
+       ib->len=2;
+       ib->type=type;
+}
+
+static void
+item_buffer_add_coord(char *buffer, struct coord *c, int count)
+{
+       struct item_bin *ib=(struct item_bin *) buffer;
+       struct coord *c2=(struct coord *)(ib+1);
+       c2+=ib->clen/2;
+       memcpy(c2, c, count*sizeof(struct coord));
+       ib->clen+=count*2;
+       ib->len+=count*2;
+}
+
+static void
+item_buffer_add_attr(char *buffer, struct attr *attr)
+{
+       struct item_bin *ib=(struct item_bin *) buffer;
+       struct attr_bin *ab=(struct attr_bin *)((int *)ib+ib->len+1);
+       if (attr->type >= attr_type_string_begin && attr->type <= attr_type_string_end) {
+               ab->type=attr->type;
+               strcpy((char *)(ab+1),attr->u.str);
+               pad_text_attr(ab, (char *)(ab+1));
+               ib->len+=ab->len+1;
+       }
+}
+
+static void
+item_buffer_write(char *buffer, FILE *out)
+{
+       struct item_bin *ib=(struct item_bin *) buffer;
+       fwrite(buffer, (ib->len+1)*4, 1, out);
+}
+
+static void
 write_attr(FILE *out, struct attr_bin *attr, void *buffer)
 {
        if (attr->len) {
@@ -1435,7 +1509,34 @@ phase1_db(char *dbstr, FILE *out_ways, FILE *out_nodes)
 }
 #endif
 
-static char buffer[150000];
+static char buffer[200000];
+
+static 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 item_bin ib;
+       struct attr attr;
+       FILE *file;
+
+       while ((item = map_rect_get_item(mr))) {
+               count=item_coord_get(item, ca, item->type < type_line ? 1: max);
+               item_buffer_set_type(buffer, item->type);
+               item_buffer_add_coord(buffer, ca, count);
+               while (item_attr_get(item, attr_any, &attr)) {
+                       item_buffer_add_attr(buffer, &attr);
+               }
+                if (item->type >= type_line) 
+                       item_buffer_write(buffer, out_ways);
+               else
+                       item_buffer_write(buffer, out_nodes);
+       }
+       map_rect_destroy(mr);
+}
+
 
 int bytes_read=0;
 
@@ -1448,7 +1549,7 @@ read_item(FILE *in)
        if (r != 1)
                return NULL;
        bytes_read+=r;
-       assert((ib->len+1) < sizeof(buffer));
+       assert((ib->len+1)*4 < sizeof(buffer));
        s=(ib->len+1)*4-sizeof(*ib);
        r=fread(ib+1, s, 1, in);
        if (r != 1)
@@ -1720,7 +1821,6 @@ write_item(char *tile, struct item_bin *ib)
        }
 }
 
-
 static void
 write_item_part(FILE *out, struct item_bin *orig, int first, int last)
 {
@@ -2339,6 +2439,7 @@ write_zipmember(FILE *out, FILE *dir_out, char *name, int filelen, char *data, i
 
        crc=crc32(0, NULL, 0);
        crc=crc32(crc, (unsigned char *)data, data_size);
+#ifdef HAVE_ZLIB
        if (compression_level) {
                error=compress2_int((Byte *)compbuffer, &destlen, (Bytef *)data, data_size, compression_level);
                if (error == Z_OK) {
@@ -2350,6 +2451,7 @@ write_zipmember(FILE *out, FILE *dir_out, char *name, int filelen, char *data, i
                        fprintf(stderr,"compress2 returned %d\n", error);
                }
        }
+#endif
        lfh.zipcrc=crc;
        lfh.zipsize=comp_size;
        lfh.zipuncmp=data_size;
@@ -2500,6 +2602,7 @@ phase4(FILE *ways_in, FILE *nodes_in, FILE *out, FILE *dir_out, int compression_
 static void
 usage(FILE *f)
 {
+       /* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
        fprintf(f,"\n");
        fprintf(f,"osm2navit - parse osm textfile and converts to NavIt binfile format\n\n");
        fprintf(f,"Usage :\n");
@@ -2539,13 +2642,18 @@ int main(int argc, char **argv)
        int i,c,start=1,end=4,dump_coordinates=0;
        int keep_tmpfiles=0;
        int process_nodes=1, process_ways=1;
+#ifdef HAVE_ZLIB
        int compression_level=9;
+#else
+       int compression_level=0;
+#endif
        int output=0;
        int input=0;
        char *result,*dbstr=NULL;
        FILE* input_file = stdin;
        struct plugins *plugins=NULL;
        struct attr **attrs;
+       struct map *map_handle=NULL;
 
        while (1) {
 #if 0
@@ -2562,6 +2670,7 @@ int main(int argc, char **argv)
 #endif
                        {"dedupe-ways", 0, 0, 'w'},
                        {"dump", 0, 0, 'D'},
+                       {"dump-coordinates", 0, 0, 'c'},
                        {"end", 1, 0, 'e'},
                        {"help", 0, 0, 'h'},
                        {"keep-tmpfiles", 0, 0, 'k'},
@@ -2578,7 +2687,7 @@ int main(int argc, char **argv)
 #ifdef HAVE_POSTGRESQL
                                              "d:"
 #endif
-                                             "e:hi:knm:ps:w", long_options, &option_index);
+                                             "e:hi:knm:p:s:w", long_options, &option_index);
                if (c == -1)
                        break;
                switch (c) {
@@ -2616,7 +2725,7 @@ int main(int argc, char **argv)
                                &(struct attr){attr_type,{"textfile"}},
                                &(struct attr){attr_data,{"bookmark.txt"}},
                                NULL};
-                       map_new(attrs);
+                       map_handle=map_new(attrs);
                        fprintf(stderr,"optarg=%s\n", optarg);
                        break;  
                case 'n':
@@ -2633,6 +2742,7 @@ int main(int argc, char **argv)
                case 'p':
                        if (! plugins)
                                plugins=plugins_new();
+                       fprintf(stderr,"optarg=%s\n",optarg);
                        attrs=(struct attr*[]){&(struct attr){attr_path,{optarg}},NULL};
                        plugins_add_path(plugins, attrs);       
                        break;
@@ -2650,9 +2760,11 @@ int main(int argc, char **argv)
                            exit( -1 );
                        }
                        break;
+#ifdef HAVE_ZLIB
                case 'z':
                        compression_level=atoi(optarg);
                        break;
+#endif
                case '?':
                        usage(stderr);
                        break;
@@ -2685,6 +2797,11 @@ int main(int argc, char **argv)
                        phase1_db(dbstr,ways,nodes);
                else
 #endif
+               if (map_handle) {
+                       phase1_map(map_handle,ways,nodes);
+                       map_destroy(map_handle);
+               }
+               else
                        phase1(input_file,ways,nodes);
                if (ways)
                        fclose(ways);