Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for old-style MPs #862

Merged
merged 4 commits into from
Dec 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions geometry-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ size_t relation_helper::set(osmium::Relation const &rel, middle_t const *mid)
// get the nodes and roles of the ways
auto num_ways = mid->rel_way_members_get(rel, &roles, data);

// mark the ends of each so whoever uses them will know where they end..
superseded.resize(num_ways);

return num_ways;
}

Expand Down
1 change: 0 additions & 1 deletion geometry-processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class relation_helper
void add_way_locations(middle_t const *mid);

rolelist_t roles;
std::vector<int> superseded;
osmium::memory::Buffer data;
};

Expand Down
25 changes: 4 additions & 21 deletions output-multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,19 +368,19 @@ int output_multi_t::process_relation(osmium::Relation const &rel,
if (m_relation_helper.set(rel, (middle_t *)m_mid) < 1)
return 0;

//NOTE: make_polygon is preset here this is to force the tag matching/superseded stuff
//NOTE: make_polygon is preset here this is to force the tag matching
//normally this wouldnt work but we tell the tag transform to allow typeless relations
//this is needed because the type can get stripped off by the rel_tag filter above
//if the export list did not include the type tag.
//TODO: find a less hacky way to do the matching/superseded and tag copying stuff without
//TODO: find a less hacky way to do the matching and tag copying stuff without
//all this trickery
int roads;
int make_boundary, make_polygon;
taglist_t outtags;
filter = m_tagtransform->filter_rel_member_tags(
rel_outtags, m_relation_helper.data, m_relation_helper.roles,
&m_relation_helper.superseded.front(), &make_boundary,
&make_polygon, &roads, *m_export_list.get(), outtags, true);
&make_boundary, &make_polygon, &roads, *m_export_list.get(),
outtags, true);
if (!filter)
{
m_relation_helper.add_way_locations((middle_t *)m_mid);
Expand All @@ -389,23 +389,6 @@ int output_multi_t::process_relation(osmium::Relation const &rel,
for (const auto geom : geoms) {
copy_to_table(-rel.id(), geom, outtags);
}

//TODO: should this loop be inside the if above just in case?
//take a look at each member to see if its superseded (tags on it matched the tags on the relation)
size_t i = 0;
for (auto const &w : m_relation_helper.data.select<osmium::Way>()) {
//tags matched so we are keeping this one with this relation
if (m_relation_helper.superseded[i]) {
//just in case it wasnt previously with this relation we get rid of them
way_delete(w.id());
//the other option is that we marked them pending in the way processing so here we mark them
//done so when we go back over the pendings we can just skip it because its in the done list
//TODO: dont do this when working with pending relations to avoid thread races
if(!pending)
ways_done_tracker->mark(w.id());
}
++i;
}
}
}
return 0;
Expand Down
31 changes: 3 additions & 28 deletions output-pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,7 @@ int output_pgsql_t::way_add(osmium::Way *way)
auto filter = m_tagtransform->filter_tags(*way, &polygon, &roads,
*m_export_list.get(), outtags);

/* If this isn't a polygon then it can not be part of a multipolygon
Hence only polygons are "pending" */
if (!filter && polygon) { ways_pending_tracker.mark(way->id()); }

if( !polygon && !filter )
{
if (!filter) {
/* Get actual node data and generate output */
auto nnodes = m_mid->nodes_get_list(&(way->nodes()));
if (nnodes > 1) {
Expand Down Expand Up @@ -320,15 +315,13 @@ int output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel,
int roads = 0;
int make_polygon = 0;
int make_boundary = 0;
std::vector<int> members_superseded(num_ways, 0);
taglist_t outtags;

// If it's a route relation make_boundary and make_polygon will be false
// otherwise one or the other will be true.
if (m_tagtransform->filter_rel_member_tags(
prefiltered_tags, buffer, xrole, &(members_superseded[0]),
&make_boundary, &make_polygon, &roads, *m_export_list.get(),
outtags)) {
prefiltered_tags, buffer, xrole, &make_boundary, &make_polygon,
&roads, *m_export_list.get(), outtags)) {
return 0;
}

Expand Down Expand Up @@ -369,24 +362,6 @@ int output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel,
}
m_tables[t_poly]->write_row(-rel.id(), outtags, wkb);
}

/* Tagtransform will have marked those member ways of the relation that
* have fully been dealt with as part of the multi-polygon entry.
* Set them in the database as done and delete their entry to not
* have duplicates */
if (make_polygon) {
size_t j = 0;
for (auto &w : buffer.select<osmium::Way>()) {
if (members_superseded[j]) {
pgsql_delete_way_from_output(w.id());
// When working with pending relations this is not needed.
if (!pending) {
ways_done_tracker->mark(w.id());
}
}
++j;
}
}
}

return 0;
Expand Down
55 changes: 1 addition & 54 deletions style.lua
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ function filter_tags_relation_member (keyvalues, keyvaluemembers, roles, memberc
linestring = 0 -- Will object be treated as linestring?
polygon = 0 -- Will object be treated as polygon?
roads = 0 -- Will object be added to planet_osm_roads?
membersuperseded = {}
for i = 1, membercount do
membersuperseded[i] = 0 -- Will member be ignored when handling areas?
end

type = keyvalues["type"]

Expand All @@ -257,59 +253,10 @@ function filter_tags_relation_member (keyvalues, keyvaluemembers, roles, memberc
elseif (type == "multipolygon") then
-- Treat as polygon
polygon = 1
polytagcount = 0;
-- Count the number of polygon tags of the object
for i,k in ipairs(polygon_keys) do
if keyvalues[k] then
polytagcount = 1
break
end
end
-- If there are no polygon tags, add tags from all outer elements to the multipolygon itself
if (polytagcount == 0) then
for i = 1,membercount do
if (roles[i] == "outer") then
for k,v in pairs(keyvaluemembers[i]) do
keyvalues[k] = v
end
end
end

f, keyvalues = filter_tags_generic(keyvalues, 1)
-- check again if there are still polygon tags left
polytagcount = 0
for i,k in ipairs(polygon_keys) do
if keyvalues[k] then
polytagcount = 1
break
end
end
if polytagcount == 0 then
filter = 1
end
end
-- For any member of the multipolygon, set membersuperseded to 1 (i.e. don't deal with it as area as well),
-- except when the member has a key/value combination such that
-- 1) the key occurs in generic_keys
-- 2) the key/value combination is not also a key/value combination of the multipolygon itself
for i = 1,membercount do
superseded = 1
for k,v in pairs(keyvaluemembers[i]) do
if ((keyvalues[k] == nil) or (keyvalues[k] ~= v)) then
for j,k2 in ipairs(generic_keys) do
if (k == k2) then
superseded = 0;
break
end
end
end
end
membersuperseded[i] = superseded
end
end

-- Add z_order key/value combination and determine if the object should also be added to planet_osm_roads
keyvalues, roads = add_z_order(keyvalues)

return filter, keyvalues, membersuperseded, linestring, polygon, roads
return filter, keyvalues, {}, linestring, polygon, roads
end
114 changes: 8 additions & 106 deletions tagtransform-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ bool c_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
if (o.type() == osmium::item_type::relation &&
strcmp("type", k) == 0) {
out_tags.emplace_back(k, v);
filter = false;
continue;
}
/* Allow named islands to appear as polygons */
Expand Down Expand Up @@ -206,11 +205,10 @@ bool c_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,

bool c_tagtransform_t::filter_rel_member_tags(
taglist_t const &rel_tags, osmium::memory::Buffer const &members,
rolelist_t const &member_roles, int *member_superseded, int *make_boundary,
int *make_polygon, int *roads, export_list const &exlist,
taglist_t &out_tags, bool allow_typeless)
rolelist_t const &member_roles, int *make_boundary, int *make_polygon,
int *roads, export_list const &exlist, taglist_t &out_tags,
bool allow_typeless)
{
auto const &infos = exlist.get(osmium::item_type::way);
//if it has a relation figure out what kind it is
const std::string *type = rel_tags.get("type");
bool is_route = false, is_boundary = false, is_multipolygon = false;
Expand Down Expand Up @@ -239,6 +237,10 @@ bool c_tagtransform_t::filter_rel_member_tags(
out_tags.push_dedupe(rel_tag);
}

if (out_tags.empty()) {
return true;
}

if (is_route) {
const std::string *netw = rel_tags.get("network");
int networknr = -1;
Expand Down Expand Up @@ -313,109 +315,9 @@ bool c_tagtransform_t::filter_rel_member_tags(
*make_boundary = 1;
} else if (is_multipolygon) {
*make_polygon = 1;

// Check if the relation has any polygon-like tags. In that case
// we have a new-style polygon.
bool newstyle_mp = false;
for (const auto &tag : out_tags) {
if (tag.key == "area") {
newstyle_mp = true;
} else {
for (const auto &info : infos) {
if (info.name == tag.key) {
newstyle_mp = info.flags & FLAG_POLYGON;
break;
}
}
}
if (newstyle_mp) {
break;
}
}

// Old-style MP: copy the tags from the outer way(s). Only use tags
// that appear in all outer rings.
if (!newstyle_mp) {
taglist_t poly_tags;
bool first_outerway = true;
size_t i = 0;
for (auto const &w : members.select<osmium::Way>()) {
if (member_roles[i] && strcmp(member_roles[i], "inner") == 0)
continue;

/* insert all tags of the first outerway to the potential list of copied tags. */
if (first_outerway) {
for (auto const &tag : w.tags()) {
poly_tags.emplace_back(tag.key(), tag.value());
}
first_outerway = false;
} 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 */
auto it = poly_tags.begin();
while (it != poly_tags.end()) {
if (!w.tags().has_key(it->key.c_str()))
/* This tag is not present on all member outer ways, so don't copy it over to relation */
it = poly_tags.erase(it);
else
++it;
}
}
++i;
}
// Copy the list identified outer way tags over to the relation
// filtering for wanted tags on the way.
bool filter;
int flags = 0;
for (const auto &poly_tag : poly_tags) {
if (check_key(infos, poly_tag.key.c_str(), &filter, &flags,
false)) {
out_tags.push_dedupe(poly_tag);
}
}

if (!(flags & FLAG_POLYGON)) {
out_tags.clear();
return true;
}
}
}

if (out_tags.empty()) {
return true;
}

/* 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) {
size_t i = 0;
for (auto const &w : members.select<osmium::Way>()) {
member_superseded[i] = 1;
for (const auto &member_tag : w.tags()) {
auto const *v = out_tags.get(member_tag.key());
bool filt;
int flag;
if ((!v && check_key(infos, member_tag.key(), &filt, &flag, false))
|| (v && *v != member_tag.value())) {
/* z_order and osm_ are automatically generated tags, so ignore them */
if (strcmp(member_tag.key(), "z_order") &&
strcmp(member_tag.key(), "osm_user") &&
strcmp(member_tag.key(), "osm_version") &&
strcmp(member_tag.key(), "osm_uid") &&
strcmp(member_tag.key(), "osm_changeset") &&
strcmp(member_tag.key(), "osm_timestamp")) {
member_superseded[i] = 0;
break;
}
}
}
++i;
}
}

add_z_order(out_tags, roads);

return 0;
return false;
}
6 changes: 3 additions & 3 deletions tagtransform-c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class c_tagtransform_t : public tagtransform_t
bool filter_rel_member_tags(taglist_t const &rel_tags,
osmium::memory::Buffer const &members,
rolelist_t const &member_roles,
int *member_superseded, int *make_boundary,
int *make_polygon, int *roads,
export_list const &exlist, taglist_t &out_tags,
int *make_boundary, int *make_polygon,
int *roads, export_list const &exlist,
taglist_t &out_tags,
bool allow_typeless = false) override;

private:
Expand Down
17 changes: 4 additions & 13 deletions tagtransform-lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ bool lua_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,

bool lua_tagtransform_t::filter_rel_member_tags(
taglist_t const &rel_tags, osmium::memory::Buffer const &members,
rolelist_t const &member_roles, int *member_superseded, int *make_boundary,
int *make_polygon, int *roads, export_list const &, taglist_t &out_tags,
bool)
rolelist_t const &member_roles, int *make_boundary, int *make_polygon,
int *roads, export_list const &, taglist_t &out_tags, bool)
{
size_t num_members = member_roles.size();
lua_getglobal(L, m_rel_mem_func.c_str());
Expand Down Expand Up @@ -195,16 +194,8 @@ bool lua_tagtransform_t::filter_rel_member_tags(
*make_boundary = (int)lua_tointeger(L, -1);
lua_pop(L, 1);

lua_pushnil(L);
for (size_t i = 0; i < num_members; ++i) {
if (lua_next(L, -2)) {
member_superseded[i] = (int)lua_tointeger(L, -1);
lua_pop(L, 1);
} else {
throw std::runtime_error("Failed to read member_superseded from lua function");
}
}
lua_pop(L, 2);
// obsolete member superseded is ignored.
lua_pop(L, 1);

lua_pushnil(L);
while (lua_next(L, -2) != 0) {
Expand Down
6 changes: 3 additions & 3 deletions tagtransform-lua.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class lua_tagtransform_t : public tagtransform_t
bool filter_rel_member_tags(taglist_t const &rel_tags,
osmium::memory::Buffer const &members,
rolelist_t const &member_roles,
int *member_superseded, int *make_boundary,
int *make_polygon, int *roads,
export_list const &exlist, taglist_t &out_tags,
int *make_boundary, int *make_polygon,
int *roads, export_list const &exlist,
taglist_t &out_tags,
bool allow_typeless = false) override;

private:
Expand Down
Loading