From: <mar...@us...> - 2011-07-09 12:18:03
|
Revision: 4605 http://navit.svn.sourceforge.net/navit/?rev=4605&view=rev Author: martin-s Date: 2011-07-09 12:17:56 +0000 (Sat, 09 Jul 2011) Log Message: ----------- Add:maptool:Some cleanup Modified Paths: -------------- trunk/navit/navit/maptool/maptool.c trunk/navit/navit/maptool/maptool.h trunk/navit/navit/maptool/osm.c trunk/navit/navit/maptool/osm_o5m.c trunk/navit/navit/maptool/osm_protobuf.c trunk/navit/navit/maptool/osm_xml.c Modified: trunk/navit/navit/maptool/maptool.c =================================================================== --- trunk/navit/navit/maptool/maptool.c 2011-07-09 08:40:05 UTC (rev 4604) +++ trunk/navit/navit/maptool/maptool.c 2011-07-09 12:17:56 UTC (rev 4605) @@ -182,6 +182,7 @@ struct attr *attrs[10]; GList *map_handles=NULL; struct map *handle; + struct maptool_osm osm; #if 0 char *suffixes[]={"m0l0", "m0l1","m0l2","m0l3","m0l4","m0l5","m0l6"}; char *suffixes[]={"m","r"}; @@ -403,9 +404,14 @@ boundaries=tempfile(suffix,"boundaries",1); phase=1; fprintf(stderr,"PROGRESS: Phase 1: collecting data\n"); + osm.ways=ways; + osm.way2poi=way2poi; + osm.nodes=nodes; + osm.turn_restrictions=turn_restrictions; + osm.boundaries=boundaries; #ifdef HAVE_POSTGRESQL if (dbstr) - map_collect_data_osm_db(dbstr,ways,way2poi,nodes,turn_restrictions,boundaries); + map_collect_data_osm_db(dbstr,&osm); else #endif if (map_handles) { @@ -418,11 +424,11 @@ } } else if (protobuf) - map_collect_data_osm_protobuf(input_file,ways,way2poi,nodes,turn_restrictions,boundaries); + map_collect_data_osm_protobuf(input_file,&osm); else if (o5m) - map_collect_data_osm_o5m(input_file,ways,way2poi,nodes,turn_restrictions,boundaries); + map_collect_data_osm_o5m(input_file,&osm); else - map_collect_data_osm(input_file,ways,way2poi,nodes,turn_restrictions,boundaries); + map_collect_data_osm(input_file,&osm); flush_nodes(1); if (slices) { int first=1; Modified: trunk/navit/navit/maptool/maptool.h =================================================================== --- trunk/navit/navit/maptool/maptool.h 2011-07-09 08:40:05 UTC (rev 4604) +++ trunk/navit/navit/maptool/maptool.h 2011-07-09 12:17:56 UTC (rev 4605) @@ -231,15 +231,22 @@ /* osm.c */ typedef long int osmid; +struct maptool_osm { + FILE *boundaries; + FILE *turn_restrictions; + FILE *nodes; + FILE *ways; + FILE *way2poi; +}; void osm_add_tag(char *k, char *v); void osm_add_node(osmid id, double lat, double lon); void osm_add_way(osmid id); void osm_add_relation(osmid id); -void osm_end_relation(FILE *turn_restrictions, FILE *boundaries); +void osm_end_relation(struct maptool_osm *osm); void osm_add_member(int type, osmid ref, char *role); -void osm_end_way(FILE *out, FILE *outwaypoi); -void osm_end_node(FILE *out); +void osm_end_way(struct maptool_osm *osm); +void osm_end_node(struct maptool_osm *osm); void osm_add_nd(osmid ref); long long item_bin_get_id(struct item_bin *ib); void flush_nodes(int final); @@ -254,19 +261,19 @@ void osm_init(FILE*); /* osm_o5m.c */ -int map_collect_data_osm_o5m(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); +int map_collect_data_osm_o5m(FILE *in, struct maptool_osm *osm); /* osm_psql.c */ -int map_collect_data_osm_db(char *dbstr, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); +int map_collect_data_osm_db(char *dbstr, struct maptool_osm *osm); /* osm_protobuf.c */ -int map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); +int map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm); int osm_protobufdb_load(FILE *in, char *dir); /* osm_xml.c */ int osm_xml_get_attribute(char *xml, char *attribute, char *buffer, int buffer_size); void osm_xml_decode_entities(char *buffer); -int map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries); +int map_collect_data_osm(FILE *in, struct maptool_osm *osm); /* sourcesink.c */ Modified: trunk/navit/navit/maptool/osm.c =================================================================== --- trunk/navit/navit/maptool/osm.c 2011-07-09 08:40:05 UTC (rev 4604) +++ trunk/navit/navit/maptool/osm.c 2011-07-09 12:17:56 UTC (rev 4605) @@ -1427,7 +1427,7 @@ } void -osm_end_relation(FILE *turn_restrictions, FILE *boundaries) +osm_end_relation(struct maptool_osm *osm) { in_relation=0; if ((!strcmp(relation_type, "multipolygon") || !strcmp(relation_type, "boundary")) && boundary) { @@ -1441,11 +1441,11 @@ fclose(f); } #endif - item_bin_write(item_bin, boundaries); + item_bin_write(item_bin, osm->boundaries); } if (!strcmp(relation_type, "restriction") && (item_bin->type == type_street_turn_restriction_no || item_bin->type == type_street_turn_restriction_only)) - item_bin_write(item_bin, turn_restrictions); + item_bin_write(item_bin, osm->turn_restrictions); } void @@ -1534,7 +1534,7 @@ } void -osm_end_way(FILE *out, FILE *outwaypoi) +osm_end_way(struct maptool_osm *osm) { int i,count; int *def_flags,add_flags; @@ -1543,7 +1543,7 @@ in_way=0; - if (! out) + if (! osm->ways) return; if (dedupe_ways_hash) { @@ -1567,7 +1567,7 @@ continue; if (ignore_unkown && (types[i] == type_street_unkn || types[i] == type_point_unkn)) continue; - if(!outwaypoi && types[i]<type_line) + if(!osm->way2poi && types[i]<type_line) continue; item_bin=init_item(types[i]); item_bin_add_coord(item_bin, coord_buffer, coord_count); @@ -1587,9 +1587,9 @@ item_bin_add_attr_int(item_bin, attr_flags, flags_attr_value); if (maxspeed_attr_value) item_bin_add_attr_int(item_bin, attr_maxspeed, maxspeed_attr_value); - item_bin_write(item_bin,out); + item_bin_write(item_bin,osm->ways); } - if(outwaypoi) { + if(osm->way2poi) { count=attr_longest_match(attr_mapping_way2poi, attr_mapping_way2poi_count, types, sizeof(types)/sizeof(enum item_type)); dbg_assert(count < 10); for (i = 0 ; i < count ; i++) { @@ -1607,14 +1607,14 @@ item_bin_add_attr_string(item_bin, attr_url, attr_strings[attr_string_url]); item_bin_add_attr_longlong(item_bin, attr_osm_wayid, osmid_attr_value); - item_bin_write(item_bin,outwaypoi); + item_bin_write(item_bin,osm->way2poi); } } attr_longest_match_clear(); } void -osm_end_node(FILE *out) +osm_end_node(struct maptool_osm *osm) { int conflict,count,i; char *postal; @@ -1623,7 +1623,7 @@ struct item_bin *item_bin; in_node=0; - if (!out || ! node_is_tagged || ! nodeid) + if (!osm->nodes || ! node_is_tagged || ! nodeid) return; count=attr_longest_match(attr_mapping_node, attr_mapping_node_count, types, sizeof(types)/sizeof(enum item_type)); if (!count) { @@ -1658,7 +1658,7 @@ *sep='\0'; item_bin_add_attr_string(item_bin, item_is_town(*item_bin) ? attr_town_postal : attr_postal, postal); } - item_bin_write(item_bin,out); + 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) Modified: trunk/navit/navit/maptool/osm_o5m.c =================================================================== --- trunk/navit/navit/maptool/osm_o5m.c 2011-07-09 08:40:05 UTC (rev 4604) +++ trunk/navit/navit/maptool/osm_o5m.c 2011-07-09 12:17:56 UTC (rev 4605) @@ -170,7 +170,7 @@ } int -map_collect_data_osm_o5m(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) +map_collect_data_osm_o5m(FILE *in, struct maptool_osm *osm) { struct o5m o; unsigned char c, *end, *rend; @@ -301,13 +301,13 @@ } switch (c) { case 0x10: - osm_end_node(out_nodes); + osm_end_node(osm); break; case 0x11: - osm_end_way(out_ways, out_way2poi); + osm_end_way(osm); break; case 0x12: - osm_end_relation(out_turn_restrictions, out_boundaries); + osm_end_relation(osm); break; } break; Modified: trunk/navit/navit/maptool/osm_protobuf.c =================================================================== --- trunk/navit/navit/maptool/osm_protobuf.c 2011-07-09 08:40:05 UTC (rev 4604) +++ trunk/navit/navit/maptool/osm_protobuf.c 2011-07-09 12:17:56 UTC (rev 4605) @@ -185,7 +185,7 @@ static void -process_dense(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__DenseNodes *dense, FILE *out_nodes) +process_dense(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__DenseNodes *dense, struct maptool_osm *osm) { int i,j=0,has_tags; long long id=0,lat=0,lon=0,changeset=0,timestamp=0; @@ -225,7 +225,7 @@ #else } #endif - osm_end_node(out_nodes); + osm_end_node(osm); j++; } } @@ -241,7 +241,7 @@ #endif static void -process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, FILE *out_ways, FILE *out_way2poi) +process_way(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Way *way, struct maptool_osm *osm) { int i; long long ref=0; @@ -266,11 +266,11 @@ #if 0 printf("\t</way>\n"); #endif - osm_end_way(out_ways, out_way2poi); + osm_end_way(osm); } static void -process_relation(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Relation *relation, FILE *out_turn_restrictions, FILE *out_boundaries) +process_relation(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__Relation *relation, struct maptool_osm *osm) { int i; long long ref=0; @@ -313,23 +313,23 @@ #if 0 printf("\t</relation>\n"); #else - osm_end_relation(out_turn_restrictions, out_boundaries); + osm_end_relation(osm); #endif } static void -process_osmdata(OSMPBF__Blob *blob, unsigned char *data, FILE *out_nodes, FILE *out_ways, FILE *out_way2poi, FILE *out_turn_restrictions, FILE *out_boundaries) +process_osmdata(OSMPBF__Blob *blob, unsigned char *data, struct maptool_osm *osm) { int i,j; OSMPBF__PrimitiveBlock *primitive_block; primitive_block=osmpbf__primitive_block__unpack(&protobuf_c_system_allocator, blob->raw_size, data); for (i = 0 ; i < primitive_block->n_primitivegroup ; i++) { OSMPBF__PrimitiveGroup *primitive_group=primitive_block->primitivegroup[i]; - process_dense(primitive_block, primitive_group->dense, out_nodes); + process_dense(primitive_block, primitive_group->dense, osm); for (j = 0 ; j < primitive_group->n_ways ; j++) - process_way(primitive_block, primitive_group->ways[j], out_ways, out_way2poi); + process_way(primitive_block, primitive_group->ways[j], osm); for (j = 0 ; j < primitive_group->n_relations ; j++) - process_relation(primitive_block, primitive_group->relations[j], out_turn_restrictions, out_boundaries); + process_relation(primitive_block, primitive_group->relations[j], osm); #if 0 printf("Group %p %d %d %d %d\n",primitive_group->dense,primitive_group->n_nodes,primitive_group->n_ways,primitive_group->n_relations,primitive_group->n_changesets); #endif @@ -339,7 +339,7 @@ int -map_collect_data_osm_protobuf(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) +map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm) { OSMPBF__BlobHeader *header; OSMPBF__Blob *blob; @@ -354,7 +354,7 @@ if (!strcmp(header->type,"OSMHeader")) { process_osmheader(blob, data); } else if (!strcmp(header->type,"OSMData")) { - process_osmdata(blob, data, out_nodes, out_ways, out_way2poi, out_turn_restrictions, out_boundaries); + process_osmdata(blob, data, osm); } else { printf("unknown\n"); return 0; Modified: trunk/navit/navit/maptool/osm_xml.c =================================================================== --- trunk/navit/navit/maptool/osm_xml.c 2011-07-09 08:40:05 UTC (rev 4604) +++ trunk/navit/navit/maptool/osm_xml.c 2011-07-09 12:17:56 UTC (rev 4605) @@ -178,7 +178,7 @@ } int -map_collect_data_osm(FILE *in, FILE *out_ways, FILE *out_way2poi, FILE *out_nodes, FILE *out_turn_restrictions, FILE *out_boundaries) +map_collect_data_osm(FILE *in, struct maptool_osm *osm) { int size=BUFFER_SIZE; char buffer[size]; @@ -215,11 +215,11 @@ if (!parse_member(p)) fprintf(stderr,"WARNING: failed to parse %s\n", buffer); } else if (!strncmp(p, "</node>",7)) { - osm_end_node(out_nodes); + osm_end_node(osm); } else if (!strncmp(p, "</way>",6)) { - osm_end_way(out_ways, out_way2poi); + osm_end_way(osm); } else if (!strncmp(p, "</relation>",11)) { - osm_end_relation(out_turn_restrictions, out_boundaries); + osm_end_relation(osm); } else if (!strncmp(p, "</osm>",6)) { } else { fprintf(stderr,"WARNING: unknown tag in %s\n", buffer); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |