static unsigned int tagtransform_c_filter_rel_member_tags( struct keyval *rel_tags, int member_count, struct keyval *member_tags, const char **member_role, int * member_superseeded, int * make_boundary, int * make_polygon, int * roads) { char *type; struct keyval tags, *p, *q, *qq, poly_tags; int i, j; int first_outerway, contains_tag; /* Get the type, if there's no type we don't care */ type = getItem(rel_tags, "type"); if (!type) return 1; initList(&tags); initList(&poly_tags); /* Clone tags from relation */ p = rel_tags->next; while (p != rel_tags) { /* For routes, we convert name to route_name */ if ((strcmp(type, "route") == 0) && (strcmp(p->key, "name") == 0)) addItem(&tags, "route_name", p->value, 1); else if (strcmp(p->key, "type")) /* drop type= */ addItem(&tags, p->key, p->value, 1); p = p->next; } if (strcmp(type, "route") == 0) { const char *state = getItem(rel_tags, "state"); const char *netw = getItem(rel_tags, "network"); int networknr = -1; if (state == NULL ) { state = ""; } if (netw != NULL ) { if (strcmp(netw, "lcn") == 0) { networknr = 10; if (strcmp(state, "alternate") == 0) { addItem(&tags, "lcn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "lcn", "connection", 1); } else { addItem(&tags, "lcn", "yes", 1); } } else if (strcmp(netw, "rcn") == 0) { networknr = 11; if (strcmp(state, "alternate") == 0) { addItem(&tags, "rcn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "rcn", "connection", 1); } else { addItem(&tags, "rcn", "yes", 1); } } else if (strcmp(netw, "ncn") == 0) { networknr = 12; if (strcmp(state, "alternate") == 0) { addItem(&tags, "ncn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "ncn", "connection", 1); } else { addItem(&tags, "ncn", "yes", 1); } } else if (strcmp(netw, "lwn") == 0) { networknr = 20; if (strcmp(state, "alternate") == 0) { addItem(&tags, "lwn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "lwn", "connection", 1); } else { addItem(&tags, "lwn", "yes", 1); } } else if (strcmp(netw, "rwn") == 0) { networknr = 21; if (strcmp(state, "alternate") == 0) { addItem(&tags, "rwn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "rwn", "connection", 1); } else { addItem(&tags, "rwn", "yes", 1); } } else if (strcmp(netw, "nwn") == 0) { networknr = 22; if (strcmp(state, "alternate") == 0) { addItem(&tags, "nwn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "nwn", "connection", 1); } else { addItem(&tags, "nwn", "yes", 1); } } } if (getItem(rel_tags, "preferred_color") != NULL ) { const char *a = getItem(rel_tags, "preferred_color"); if (strcmp(a, "0") == 0 || strcmp(a, "1") == 0 || strcmp(a, "2") == 0 || strcmp(a, "3") == 0 || strcmp(a, "4") == 0) { addItem(&tags, "route_pref_color", a, 1); } else { addItem(&tags, "route_pref_color", "0", 1); } } else { addItem(&tags, "route_pref_color", "0", 1); } if (getItem(rel_tags, "ref") != NULL ) { if (networknr == 10) { addItem(&tags, "lcn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 11) { addItem(&tags, "rcn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 12) { addItem(&tags, "ncn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 20) { addItem(&tags, "lwn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 21) { addItem(&tags, "rwn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 22) { addItem(&tags, "nwn_ref", getItem(rel_tags, "ref"), 1); } } } else if (strcmp(type, "boundary") == 0) { /* Boundaries will get converted into multiple geometries: - Linear features will end up in the line and roads tables (useful for admin boundaries) - Polygon features also go into the polygon table (useful for national_forests) The edges of the polygon also get treated as linear fetaures allowing these to be rendered seperately. */ *make_boundary = 1; } else if (strcmp(type, "multipolygon") == 0 && getItem(&tags, "boundary")) { /* Treat type=multipolygon exactly like type=boundary if it has a boundary tag. */ *make_boundary = 1; } else if (strcmp(type, "multipolygon") == 0) { *make_polygon = 1; /* Collect a list of polygon-like tags, these are used later to identify if an inner rings looks like it should be rendered separately */ p = tags.next; while (p != &tags) { if (!strcmp(p->key, "area")) { addItem(&poly_tags, p->key, p->value, 1); } else { for (i = 0; i < exportListCount[OSMTYPE_WAY]; i++) { if (strcmp(exportList[OSMTYPE_WAY][i].name, p->key) == 0) { if (exportList[OSMTYPE_WAY][i].flags & FLAG_POLYGON) { addItem(&poly_tags, p->key, p->value, 1); } break; } } } p = p->next; } /* Copy the tags from the outer way(s) if the relation is untagged (with * respect to tags that influence its polygon nature. Tags like name or fixme should be fine*/ if (!listHasData(&poly_tags)) { first_outerway = 1; for (i = 0; i < member_count; i++) { if (member_role[i] && !strcmp(member_role[i], "inner")) continue; /* insert all tags of the first outerway to the potential list of copied tags. */ if (first_outerway) { p = member_tags[i].next; while (p != &(member_tags[i])) { addItem(&poly_tags, p->key, p->value, 1); p = p->next; } } else { /* Check if all of the tags in the list of potential tags are present on this way, otherwise remove from the list of potential tags. Tags need to be present on all outer ways to be copied over to the relation */ q = poly_tags.next; while (q != &poly_tags) { p = getTag(&(member_tags[i]), q->key); if ((p != NULL) && (strcmp(q->value, p->value) == 0)) { q = q->next; } else { /* This tag is not present on all member outer ways, so don't copy it over to relation */ qq = q->next; removeTag(q); q = qq; } } } first_outerway = 0; } /* Copy the list identified outer way tags over to the relation */ q = poly_tags.next; while (q != &poly_tags) { addItem(&tags, q->key, q->value, 1); q = q->next; } /* We need to re-check and only keep polygon tags in the list of polytags */ q = poly_tags.next; while (q != &poly_tags) { contains_tag = 0; for (j = 0; j < exportListCount[OSMTYPE_WAY]; j++) { if (strcmp(exportList[OSMTYPE_WAY][j].name, q->key) == 0) { if (exportList[OSMTYPE_WAY][j].flags & FLAG_POLYGON) { contains_tag = 1; break; } } } if (contains_tag == 0) { qq = q->next; removeTag(q); q = qq; } else { q = q->next; } } } resetList(&poly_tags); } else { /* Unknown type, just exit */ resetList(&tags); resetList(&poly_tags); return 1; } if (!listHasData(&tags)) { resetList(&tags); resetList(&poly_tags); return 1; } /* If we are creating a multipolygon then we mark each member so that we can skip them during iterate_ways but only if the polygon-tags look the same as the outer ring */ if (make_polygon) { for (i = 0; i < member_count; i++) { int match = 1; struct keyval *p = member_tags[i].next; while (p != &(member_tags[i])) { const char *v = getItem(&tags, p->key); if (!v || strcmp(v, p->value)) { /* z_order and osm_ are automatically generated tags, so ignore them */ if ((strcmp(p->key, "z_order") != 0) && (strcmp(p->key, "osm_user") != 0) && (strcmp(p->key, "osm_version") != 0) && (strcmp(p->key, "osm_uid") != 0) && (strcmp(p->key, "osm_changeset")) && (strcmp(p->key, "osm_timestamp") != 0)) { match = 0; break; } } p = p->next; } if (match) { member_superseeded[i] = 1; } else { member_superseeded[i] = 0; } } } resetList(rel_tags); cloneList(rel_tags, &tags); resetList(&tags); add_z_order(rel_tags, roads); return 0; }
static unsigned int tagtransform_c_filter_rel_member_tags( struct keyval *rel_tags, int member_count, struct keyval *member_tags, const char **member_role, int * member_superseeded, int * make_boundary, int * make_polygon, int * roads) { char *type; struct keyval tags, *p, poly_tags; int i; /* Get the type, if there's no type we don't care */ type = getItem(rel_tags, "type"); if (!type) return 1; initList(&tags); initList(&poly_tags); /* Clone tags from relation */ p = rel_tags->next; while (p != rel_tags) { /* For routes, we convert name to route_name */ if ((strcmp(type, "route") == 0) && (strcmp(p->key, "name") == 0)) addItem(&tags, "route_name", p->value, 1); else if (strcmp(p->key, "type")) /* drop type= */ addItem(&tags, p->key, p->value, 1); p = p->next; } if (strcmp(type, "route") == 0) { const char *state = getItem(rel_tags, "state"); const char *netw = getItem(rel_tags, "network"); int networknr = -1; if (state == NULL ) { state = ""; } if (netw != NULL ) { if (strcmp(netw, "lcn") == 0) { networknr = 10; if (strcmp(state, "alternate") == 0) { addItem(&tags, "lcn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "lcn", "connection", 1); } else { addItem(&tags, "lcn", "yes", 1); } } else if (strcmp(netw, "rcn") == 0) { networknr = 11; if (strcmp(state, "alternate") == 0) { addItem(&tags, "rcn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "rcn", "connection", 1); } else { addItem(&tags, "rcn", "yes", 1); } } else if (strcmp(netw, "ncn") == 0) { networknr = 12; if (strcmp(state, "alternate") == 0) { addItem(&tags, "ncn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "ncn", "connection", 1); } else { addItem(&tags, "ncn", "yes", 1); } } else if (strcmp(netw, "lwn") == 0) { networknr = 20; if (strcmp(state, "alternate") == 0) { addItem(&tags, "lwn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "lwn", "connection", 1); } else { addItem(&tags, "lwn", "yes", 1); } } else if (strcmp(netw, "rwn") == 0) { networknr = 21; if (strcmp(state, "alternate") == 0) { addItem(&tags, "rwn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "rwn", "connection", 1); } else { addItem(&tags, "rwn", "yes", 1); } } else if (strcmp(netw, "nwn") == 0) { networknr = 22; if (strcmp(state, "alternate") == 0) { addItem(&tags, "nwn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "nwn", "connection", 1); } else { addItem(&tags, "nwn", "yes", 1); } } } if (getItem(rel_tags, "preferred_color") != NULL ) { const char *a = getItem(rel_tags, "preferred_color"); if (strcmp(a, "0") == 0 || strcmp(a, "1") == 0 || strcmp(a, "2") == 0 || strcmp(a, "3") == 0 || strcmp(a, "4") == 0) { addItem(&tags, "route_pref_color", a, 1); } else { addItem(&tags, "route_pref_color", "0", 1); } } else { addItem(&tags, "route_pref_color", "0", 1); } if (getItem(rel_tags, "ref") != NULL ) { if (networknr == 10) { addItem(&tags, "lcn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 11) { addItem(&tags, "rcn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 12) { addItem(&tags, "ncn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 20) { addItem(&tags, "lwn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 21) { addItem(&tags, "rwn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 22) { addItem(&tags, "nwn_ref", getItem(rel_tags, "ref"), 1); } } } else if (strcmp(type, "boundary") == 0) { /* Boundaries will get converted into multiple geometries: - Linear features will end up in the line and roads tables (useful for admin boundaries) - Polygon features also go into the polygon table (useful for national_forests) The edges of the polygon also get treated as linear fetaures allowing these to be rendered seperately. */ *make_boundary = 1; } else if (strcmp(type, "multipolygon") == 0 && getItem(&tags, "boundary")) { /* Treat type=multipolygon exactly like type=boundary if it has a boundary tag. */ *make_boundary = 1; } else if (strcmp(type, "multipolygon") == 0) { *make_polygon = 1; /* Copy the tags from the outer way(s) if the relation is untagged */ /* or if there is just a name tag, people seem to like naming relations */ if (!listHasData(&tags) || ((countList(&tags) == 1) && getItem(&tags, "name"))) { for (i = 0; i < member_count; i++) { if (member_role[i] && !strcmp(member_role[i], "inner")) continue; p = member_tags[i].next; while (p != &(member_tags[i])) { addItem(&tags, p->key, p->value, 1); p = p->next; } } } /* Collect a list of polygon-like tags, these are used later to identify if an inner rings looks like it should be rendered separately */ p = tags.next; while (p != &tags) { if (!strcmp(p->key, "area")) { addItem(&poly_tags, p->key, p->value, 1); } else { for (i = 0; i < exportListCount[OSMTYPE_WAY]; i++) { if (strcmp(exportList[OSMTYPE_WAY][i].name, p->key) == 0) { if (exportList[OSMTYPE_WAY][i].flags & FLAG_POLYGON) { addItem(&poly_tags, p->key, p->value, 1); } break; } } } p = p->next; } } else { /* Unknown type, just exit */ resetList(&tags); resetList(&poly_tags); return 1; } /* If we are creating a multipolygon then we mark each member so that we can skip them during iterate_ways but only if the polygon-tags look the same as the outer ring */ if (make_polygon) { for (i = 0; i < member_count; i++) { int match = 0; struct keyval *p = poly_tags.next; while (p != &poly_tags) { const char *v = getItem(&(member_tags[i]), p->key); if (!v || strcmp(v, p->value)) { match = 0; break; } match = 1; p = p->next; } if (match) { member_superseeded[i] = 1; } else { member_superseeded[i] = 0; } } } resetList(rel_tags); cloneList(rel_tags, &tags); resetList(&tags); add_z_order(rel_tags, roads); return 0; }
/* Go through the given tags and determine the union of flags. Also remove * any tags from the list that we don't know about */ static unsigned int tagtransform_c_filter_basic_tags(enum OsmType type, struct keyval *tags, int *polygon, int * roads) { int i, filter = 1; int flags = 0; int add_area_tag = 0; enum OsmType export_type; const char *area; struct keyval *item; struct keyval temp; initList(&temp); if (type == OSMTYPE_RELATION) {export_type = OSMTYPE_WAY;} else {export_type = type;} /* We used to only go far enough to determine if it's a polygon or not, but now we go through and filter stuff we don't need */ while ((item = popItem(tags)) != NULL ) { if (type == OSMTYPE_RELATION && !strcmp("type", item->key)) { pushItem(&temp, item); item = NULL; filter = 0; continue; } /* Allow named islands to appear as polygons */ if (!strcmp("natural", item->key) && !strcmp("coastline", item->value)) { add_area_tag = 1; } /* Discard natural=coastline tags (we render these from a shapefile instead) */ if (!options->keep_coastlines && !strcmp("natural", item->key) && !strcmp("coastline", item->value)) { freeItem(item); item = NULL; continue; } for (i = 0; i < exportListCount[export_type]; i++) { if (wildMatch(exportList[export_type][i].name, item->key)) { if (exportList[export_type][i].flags & FLAG_DELETE) { freeItem(item); item = NULL; break; } filter = 0; flags |= exportList[export_type][i].flags; pushItem(&temp, item); item = NULL; break; } } /** if tag not found in list of exports: */ if (i == exportListCount[export_type]) { if (options->enable_hstore) { /* with hstore, copy all tags... */ pushItem(&temp, item); /* ... but if hstore_match_only is set then don't take this as a reason for keeping the object */ if (!options->hstore_match_only && strcmp("osm_uid", item->key) && strcmp("osm_user", item->key) && strcmp("osm_timestamp", item->key) && strcmp("osm_version", item->key) && strcmp("osm_changeset", item->key)) filter = 0; } else if (options->n_hstore_columns) { /* does this column match any of the hstore column prefixes? */ int j; for (j = 0; j < options->n_hstore_columns; j++) { char *pos = strstr(item->key, options->hstore_columns[j]); if (pos == item->key) { pushItem(&temp, item); /* ... but if hstore_match_only is set then don't take this as a reason for keeping the object */ if (!options->hstore_match_only && strcmp("osm_uid", item->key) && strcmp("osm_user", item->key) && strcmp("osm_timestamp", item->key) && strcmp("osm_version", item->key) && strcmp("osm_changeset", item->key)) filter = 0; break; } } /* if not, skip the tag */ if (j == options->n_hstore_columns) { freeItem(item); } } else { freeItem(item); } item = NULL; } } /* Move from temp list back to original list */ while ((item = popItem(&temp)) != NULL ) pushItem(tags, item); *polygon = flags & FLAG_POLYGON; /* Special case allowing area= to override anything else */ if ((area = getItem(tags, "area"))) { if (!strcmp(area, "yes") || !strcmp(area, "true") || !strcmp(area, "1")) *polygon = 1; else if (!strcmp(area, "no") || !strcmp(area, "false") || !strcmp(area, "0")) *polygon = 0; } else { /* If we need to force this as a polygon, append an area tag */ if (add_area_tag) { addItem(tags, "area", "yes", 0); *polygon = 1; } } if (!filter && (type == OSMTYPE_WAY)) { add_z_order(tags,roads); } return filter; }
/* Go through the given tags and determine the union of flags. Also remove * any tags from the list that we don't know about */ unsigned int tagtransform::c_filter_basic_tags(OsmType type, const taglist_t &tags, int *polygon, int *roads, const export_list &exlist, taglist_t &out_tags, bool strict) { //assume we dont like this set of tags int filter = 1; int flags = 0; int add_area_tag = 0; OsmType export_type; if (type == OSMTYPE_RELATION) { export_type = OSMTYPE_WAY; } else { export_type = type; } const std::vector<taginfo> &infos = exlist.get(export_type); /* We used to only go far enough to determine if it's a polygon or not, but now we go through and filter stuff we don't need pop each tag off and keep it in the temp list if we like it */ for (taglist_t::const_iterator item = tags.begin(); item != tags.end(); ++item) { //if we want to do more than the export list says if(!strict) { if (type == OSMTYPE_RELATION && "type" == item->key) { out_tags.push_back(*item); filter = 0; continue; } /* Allow named islands to appear as polygons */ if ("natural" == item->key && "coastline" == item->value) { add_area_tag = 1; /* Discard natural=coastline tags (we render these from a shapefile instead) */ if (!options->keep_coastlines) { continue; } } } //go through the actual tags found on the item and keep the ones in the export list size_t i = 0; for (; i < infos.size(); i++) { const taginfo &info = infos[i]; if (wildMatch(info.name.c_str(), item->key.c_str())) { if (info.flags & FLAG_DELETE) { break; } filter = 0; flags |= info.flags; out_tags.push_back(*item); break; } } // if we didn't find any tags that we wanted to export // and we aren't strictly adhering to the list if (i == infos.size() && !strict) { if (options->hstore_mode != HSTORE_NONE) { /* with hstore, copy all tags... */ out_tags.push_back(*item); /* ... but if hstore_match_only is set then don't take this as a reason for keeping the object */ if (!options->hstore_match_only && "osm_uid" != item->key && "osm_user" != item->key && "osm_timestamp" != item->key && "osm_version" != item->key && "osm_changeset" != item->key) filter = 0; } else if (options->hstore_columns.size() > 0) { /* does this column match any of the hstore column prefixes? */ size_t j = 0; for(; j < options->hstore_columns.size(); ++j) { size_t pos = item->key.find(options->hstore_columns[j]); if (pos == 0) { out_tags.push_back(*item); /* ... but if hstore_match_only is set then don't take this as a reason for keeping the object */ if (!options->hstore_match_only && "osm_uid" != item->key && "osm_user" != item->key && "osm_timestamp" != item->key && "osm_version" != item->key && "osm_changeset" != item->key) filter = 0; break; } } } } } if (polygon) { if (add_area_tag) { /* If we need to force this as a polygon, append an area tag */ out_tags.push_dedupe(tag("area", "yes")); *polygon = 1; } else { *polygon = tags.get_bool("area", flags & FLAG_POLYGON); } } if (roads && !filter && (type == OSMTYPE_WAY)) { add_z_order(out_tags, roads); } return filter; }