Skip to content

Commit

Permalink
Fix:maptool:Duplicte multipolygons if required (#1019)
Browse files Browse the repository at this point in the history
In order to support (multi)polygons that are tagged with more than one
set of tags resulting it to require two navit items to be represented on
map, affected elements are duplicated and added with every item type
decoded. This is already done for ways and points. This fix makes
maptool do this for multipolygons as well.

+ fixes some valgrind findings
  • Loading branch information
metalstrolch committed Jun 18, 2020
1 parent ac97b39 commit 4dfe938
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
1 change: 1 addition & 0 deletions navit/maptool/maptool.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ static void maptool_assemble_map(struct maptool_params *p, char *suffix, char **
zip_write_index(zip_info);
zip_write_directory(zip_info);
zip_close(zip_info);
zip_destroy(zip_info);
if (!p->keep_tmpfiles) {
remove_countryfiles();
tempfile_unlink("index","");
Expand Down
55 changes: 38 additions & 17 deletions navit/maptool/osm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1639,40 +1639,63 @@ country_from_iso2(char *iso) {
return country_from_countryid(country_id_from_iso2(iso));
}

static inline void osm_end_relation_multipolygon (struct maptool_osm * osm, enum item_type* type) {
static inline void osm_end_relation_multipolygon (struct maptool_osm * osm) {
if((!g_strcmp0(relation_type, "multipolygon")) && (!boundary)) {
if(attr_longest_match(attr_mapping_way, attr_mapping_way_count, type, 1)) {
tmp_item_bin->type = *type;
int count;
enum item_type types[10];
/* This is a multipolygon relation which is no boundary. Lets check what it is */
count = attr_longest_match(attr_mapping_way, attr_mapping_way_count, types, sizeof(types) / (sizeof(enum item_type)));
if(count > 0) {
int a;
/* got some type(s). Duplicate the multipolygon if more than one type. That's the only
* way right now to deal with things tagged multiple things without loosing something.
*/
if (count >= 10) {
fprintf(stderr,"relation id "OSMID_FMT"\n",osmid_attr_value);
dbg_assert(count < 10);
count = 10;
}
//fprintf(stderr, "relation id "OSMID_FMT": got %d types\n", osmid_attr_value, count);
item_bin_add_attr_string(tmp_item_bin, attr_label, attr_strings[attr_string_label]);
for(a=0; a < count ; a++) {
/* no need to clone the item in memory. We just write it out multiple times */
if(a==1) {
/*add duplicate tag if 2nd type. The tag stays for all subsequent writes */
item_bin_add_attr_int(tmp_item_bin, attr_duplicate, 1);
}
tmp_item_bin->type = types[a];
item_bin_write(tmp_item_bin, osm->multipolygons);
}
} else {
*type=type_none;
/* Don't know what this is. Keep it, as it could have been preprocessed by e.g. turn restriction
* code before
*/
/* do not touch tmp_item_bin->type in this case, as it may be already set! For example
* indicating the turn restrictions */
//tmp_item_bin->type=*type;
//tmp_item_bin->type=type_none;
item_bin_add_attr_string(tmp_item_bin, attr_label, attr_strings[attr_string_label]);
item_bin_write(tmp_item_bin, osm->multipolygons);
}
item_bin_add_attr_string(tmp_item_bin, attr_label, attr_strings[attr_string_label]);
item_bin_write(tmp_item_bin, osm->multipolygons);
} else {
if(attr_longest_match(attr_mapping_rel2poly_place, attr_mapping_rel2poly_place_count, type, 1)) {
tmp_item_bin->type=*type;
enum item_type type;
if(attr_longest_match(attr_mapping_rel2poly_place, attr_mapping_rel2poly_place_count, &type, 1)) {
tmp_item_bin->type=type;
} else {
*type=type_none;
/* do not touch tmp_item_bin->type in this case, as it may be already set! For example
* indicating the turn restrictions */
//tmp_item_bin->type=*type;
//tmp_item_bin->type=type_none;
}
if ((!g_strcmp0(relation_type, "multipolygon") || !g_strcmp0(relation_type, "boundary"))
&& (boundary || *type!=type_none)) {
&& (boundary || type!=type_none)) {
item_bin_write(tmp_item_bin, osm->boundaries);
}
}
}

void osm_end_relation(struct maptool_osm *osm) {
enum item_type type;

in_relation=0;
/* sets tmp_item_bin type and other fields */
osm_end_relation_multipolygon (osm, &type);
osm_end_relation_multipolygon (osm);

if (!g_strcmp0(relation_type, "restriction") && (tmp_item_bin->type == type_street_turn_restriction_no
|| tmp_item_bin->type == type_street_turn_restriction_only))
Expand Down Expand Up @@ -3209,7 +3232,6 @@ static GList ** process_multipolygons_setup(FILE *in, int thread_count, struct r
GList **multipolygons=NULL;
/* allocate and reference async queue */
GAsyncQueue * ib_queue=g_async_queue_new ();
g_async_queue_ref(ib_queue);
/* allocate per thread storage */
sthread=g_malloc0(sizeof(struct process_multipolygon_setup_thread) * thread_count);

Expand Down Expand Up @@ -3565,7 +3587,6 @@ static GList ** process_turn_restrictions_setup(FILE *in, int thread_count, stru
GList **turn_restrictions=NULL;
/* allocate and reference async queue */
GAsyncQueue * ib_queue=g_async_queue_new ();
g_async_queue_ref(ib_queue);
/* allocate per thread storage */
sthread=g_malloc0(sizeof(struct process_turn_restrictions_setup_thread) * thread_count);

Expand Down

0 comments on commit 4dfe938

Please sign in to comment.