Skip to content

Commit 706f3a0

Browse files
authored
Merge pull request #862 from lonvia/drop-old-style-mps
Remove support for old-style MPs
2 parents ea38035 + 5768610 commit 706f3a0

14 files changed

+103
-335
lines changed

geometry-processor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ size_t relation_helper::set(osmium::Relation const &rel, middle_t const *mid)
9090
// get the nodes and roles of the ways
9191
auto num_ways = mid->rel_way_members_get(rel, &roles, data);
9292

93-
// mark the ends of each so whoever uses them will know where they end..
94-
superseded.resize(num_ways);
95-
9693
return num_ways;
9794
}
9895

geometry-processor.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class relation_helper
9090
void add_way_locations(middle_t const *mid);
9191

9292
rolelist_t roles;
93-
std::vector<int> superseded;
9493
osmium::memory::Buffer data;
9594
};
9695

output-multi.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,19 @@ int output_multi_t::process_relation(osmium::Relation const &rel,
368368
if (m_relation_helper.set(rel, (middle_t *)m_mid) < 1)
369369
return 0;
370370

371-
//NOTE: make_polygon is preset here this is to force the tag matching/superseded stuff
371+
//NOTE: make_polygon is preset here this is to force the tag matching
372372
//normally this wouldnt work but we tell the tag transform to allow typeless relations
373373
//this is needed because the type can get stripped off by the rel_tag filter above
374374
//if the export list did not include the type tag.
375-
//TODO: find a less hacky way to do the matching/superseded and tag copying stuff without
375+
//TODO: find a less hacky way to do the matching and tag copying stuff without
376376
//all this trickery
377377
int roads;
378378
int make_boundary, make_polygon;
379379
taglist_t outtags;
380380
filter = m_tagtransform->filter_rel_member_tags(
381381
rel_outtags, m_relation_helper.data, m_relation_helper.roles,
382-
&m_relation_helper.superseded.front(), &make_boundary,
383-
&make_polygon, &roads, *m_export_list.get(), outtags, true);
382+
&make_boundary, &make_polygon, &roads, *m_export_list.get(),
383+
outtags, true);
384384
if (!filter)
385385
{
386386
m_relation_helper.add_way_locations((middle_t *)m_mid);
@@ -389,23 +389,6 @@ int output_multi_t::process_relation(osmium::Relation const &rel,
389389
for (const auto geom : geoms) {
390390
copy_to_table(-rel.id(), geom, outtags);
391391
}
392-
393-
//TODO: should this loop be inside the if above just in case?
394-
//take a look at each member to see if its superseded (tags on it matched the tags on the relation)
395-
size_t i = 0;
396-
for (auto const &w : m_relation_helper.data.select<osmium::Way>()) {
397-
//tags matched so we are keeping this one with this relation
398-
if (m_relation_helper.superseded[i]) {
399-
//just in case it wasnt previously with this relation we get rid of them
400-
way_delete(w.id());
401-
//the other option is that we marked them pending in the way processing so here we mark them
402-
//done so when we go back over the pendings we can just skip it because its in the done list
403-
//TODO: dont do this when working with pending relations to avoid thread races
404-
if(!pending)
405-
ways_done_tracker->mark(w.id());
406-
}
407-
++i;
408-
}
409392
}
410393
}
411394
return 0;

output-pgsql.cpp

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,7 @@ int output_pgsql_t::way_add(osmium::Way *way)
276276
auto filter = m_tagtransform->filter_tags(*way, &polygon, &roads,
277277
*m_export_list.get(), outtags);
278278

279-
/* If this isn't a polygon then it can not be part of a multipolygon
280-
Hence only polygons are "pending" */
281-
if (!filter && polygon) { ways_pending_tracker.mark(way->id()); }
282-
283-
if( !polygon && !filter )
284-
{
279+
if (!filter) {
285280
/* Get actual node data and generate output */
286281
auto nnodes = m_mid->nodes_get_list(&(way->nodes()));
287282
if (nnodes > 1) {
@@ -320,15 +315,13 @@ int output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel,
320315
int roads = 0;
321316
int make_polygon = 0;
322317
int make_boundary = 0;
323-
std::vector<int> members_superseded(num_ways, 0);
324318
taglist_t outtags;
325319

326320
// If it's a route relation make_boundary and make_polygon will be false
327321
// otherwise one or the other will be true.
328322
if (m_tagtransform->filter_rel_member_tags(
329-
prefiltered_tags, buffer, xrole, &(members_superseded[0]),
330-
&make_boundary, &make_polygon, &roads, *m_export_list.get(),
331-
outtags)) {
323+
prefiltered_tags, buffer, xrole, &make_boundary, &make_polygon,
324+
&roads, *m_export_list.get(), outtags)) {
332325
return 0;
333326
}
334327

@@ -369,24 +362,6 @@ int output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel,
369362
}
370363
m_tables[t_poly]->write_row(-rel.id(), outtags, wkb);
371364
}
372-
373-
/* Tagtransform will have marked those member ways of the relation that
374-
* have fully been dealt with as part of the multi-polygon entry.
375-
* Set them in the database as done and delete their entry to not
376-
* have duplicates */
377-
if (make_polygon) {
378-
size_t j = 0;
379-
for (auto &w : buffer.select<osmium::Way>()) {
380-
if (members_superseded[j]) {
381-
pgsql_delete_way_from_output(w.id());
382-
// When working with pending relations this is not needed.
383-
if (!pending) {
384-
ways_done_tracker->mark(w.id());
385-
}
386-
}
387-
++j;
388-
}
389-
}
390365
}
391366

392367
return 0;

style.lua

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,6 @@ function filter_tags_relation_member (keyvalues, keyvaluemembers, roles, memberc
236236
linestring = 0 -- Will object be treated as linestring?
237237
polygon = 0 -- Will object be treated as polygon?
238238
roads = 0 -- Will object be added to planet_osm_roads?
239-
membersuperseded = {}
240-
for i = 1, membercount do
241-
membersuperseded[i] = 0 -- Will member be ignored when handling areas?
242-
end
243239

244240
type = keyvalues["type"]
245241

@@ -257,59 +253,10 @@ function filter_tags_relation_member (keyvalues, keyvaluemembers, roles, memberc
257253
elseif (type == "multipolygon") then
258254
-- Treat as polygon
259255
polygon = 1
260-
polytagcount = 0;
261-
-- Count the number of polygon tags of the object
262-
for i,k in ipairs(polygon_keys) do
263-
if keyvalues[k] then
264-
polytagcount = 1
265-
break
266-
end
267-
end
268-
-- If there are no polygon tags, add tags from all outer elements to the multipolygon itself
269-
if (polytagcount == 0) then
270-
for i = 1,membercount do
271-
if (roles[i] == "outer") then
272-
for k,v in pairs(keyvaluemembers[i]) do
273-
keyvalues[k] = v
274-
end
275-
end
276-
end
277-
278-
f, keyvalues = filter_tags_generic(keyvalues, 1)
279-
-- check again if there are still polygon tags left
280-
polytagcount = 0
281-
for i,k in ipairs(polygon_keys) do
282-
if keyvalues[k] then
283-
polytagcount = 1
284-
break
285-
end
286-
end
287-
if polytagcount == 0 then
288-
filter = 1
289-
end
290-
end
291-
-- For any member of the multipolygon, set membersuperseded to 1 (i.e. don't deal with it as area as well),
292-
-- except when the member has a key/value combination such that
293-
-- 1) the key occurs in generic_keys
294-
-- 2) the key/value combination is not also a key/value combination of the multipolygon itself
295-
for i = 1,membercount do
296-
superseded = 1
297-
for k,v in pairs(keyvaluemembers[i]) do
298-
if ((keyvalues[k] == nil) or (keyvalues[k] ~= v)) then
299-
for j,k2 in ipairs(generic_keys) do
300-
if (k == k2) then
301-
superseded = 0;
302-
break
303-
end
304-
end
305-
end
306-
end
307-
membersuperseded[i] = superseded
308-
end
309256
end
310257

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

314-
return filter, keyvalues, membersuperseded, linestring, polygon, roads
261+
return filter, keyvalues, {}, linestring, polygon, roads
315262
end

tagtransform-c.cpp

Lines changed: 8 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ bool c_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
160160
if (o.type() == osmium::item_type::relation &&
161161
strcmp("type", k) == 0) {
162162
out_tags.emplace_back(k, v);
163-
filter = false;
164163
continue;
165164
}
166165
/* Allow named islands to appear as polygons */
@@ -206,11 +205,10 @@ bool c_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
206205

207206
bool c_tagtransform_t::filter_rel_member_tags(
208207
taglist_t const &rel_tags, osmium::memory::Buffer const &members,
209-
rolelist_t const &member_roles, int *member_superseded, int *make_boundary,
210-
int *make_polygon, int *roads, export_list const &exlist,
211-
taglist_t &out_tags, bool allow_typeless)
208+
rolelist_t const &member_roles, int *make_boundary, int *make_polygon,
209+
int *roads, export_list const &exlist, taglist_t &out_tags,
210+
bool allow_typeless)
212211
{
213-
auto const &infos = exlist.get(osmium::item_type::way);
214212
//if it has a relation figure out what kind it is
215213
const std::string *type = rel_tags.get("type");
216214
bool is_route = false, is_boundary = false, is_multipolygon = false;
@@ -239,6 +237,10 @@ bool c_tagtransform_t::filter_rel_member_tags(
239237
out_tags.push_dedupe(rel_tag);
240238
}
241239

240+
if (out_tags.empty()) {
241+
return true;
242+
}
243+
242244
if (is_route) {
243245
const std::string *netw = rel_tags.get("network");
244246
int networknr = -1;
@@ -313,109 +315,9 @@ bool c_tagtransform_t::filter_rel_member_tags(
313315
*make_boundary = 1;
314316
} else if (is_multipolygon) {
315317
*make_polygon = 1;
316-
317-
// Check if the relation has any polygon-like tags. In that case
318-
// we have a new-style polygon.
319-
bool newstyle_mp = false;
320-
for (const auto &tag : out_tags) {
321-
if (tag.key == "area") {
322-
newstyle_mp = true;
323-
} else {
324-
for (const auto &info : infos) {
325-
if (info.name == tag.key) {
326-
newstyle_mp = info.flags & FLAG_POLYGON;
327-
break;
328-
}
329-
}
330-
}
331-
if (newstyle_mp) {
332-
break;
333-
}
334-
}
335-
336-
// Old-style MP: copy the tags from the outer way(s). Only use tags
337-
// that appear in all outer rings.
338-
if (!newstyle_mp) {
339-
taglist_t poly_tags;
340-
bool first_outerway = true;
341-
size_t i = 0;
342-
for (auto const &w : members.select<osmium::Way>()) {
343-
if (member_roles[i] && strcmp(member_roles[i], "inner") == 0)
344-
continue;
345-
346-
/* insert all tags of the first outerway to the potential list of copied tags. */
347-
if (first_outerway) {
348-
for (auto const &tag : w.tags()) {
349-
poly_tags.emplace_back(tag.key(), tag.value());
350-
}
351-
first_outerway = false;
352-
} else {
353-
/* Check if all of the tags in the list of potential tags are present on this way,
354-
otherwise remove from the list of potential tags. Tags need to be present on
355-
all outer ways to be copied over to the relation */
356-
auto it = poly_tags.begin();
357-
while (it != poly_tags.end()) {
358-
if (!w.tags().has_key(it->key.c_str()))
359-
/* This tag is not present on all member outer ways, so don't copy it over to relation */
360-
it = poly_tags.erase(it);
361-
else
362-
++it;
363-
}
364-
}
365-
++i;
366-
}
367-
// Copy the list identified outer way tags over to the relation
368-
// filtering for wanted tags on the way.
369-
bool filter;
370-
int flags = 0;
371-
for (const auto &poly_tag : poly_tags) {
372-
if (check_key(infos, poly_tag.key.c_str(), &filter, &flags,
373-
false)) {
374-
out_tags.push_dedupe(poly_tag);
375-
}
376-
}
377-
378-
if (!(flags & FLAG_POLYGON)) {
379-
out_tags.clear();
380-
return true;
381-
}
382-
}
383-
}
384-
385-
if (out_tags.empty()) {
386-
return true;
387-
}
388-
389-
/* If we are creating a multipolygon then we
390-
mark each member so that we can skip them during iterate_ways
391-
but only if the polygon-tags look the same as the outer ring */
392-
if (make_polygon) {
393-
size_t i = 0;
394-
for (auto const &w : members.select<osmium::Way>()) {
395-
member_superseded[i] = 1;
396-
for (const auto &member_tag : w.tags()) {
397-
auto const *v = out_tags.get(member_tag.key());
398-
bool filt;
399-
int flag;
400-
if ((!v && check_key(infos, member_tag.key(), &filt, &flag, false))
401-
|| (v && *v != member_tag.value())) {
402-
/* z_order and osm_ are automatically generated tags, so ignore them */
403-
if (strcmp(member_tag.key(), "z_order") &&
404-
strcmp(member_tag.key(), "osm_user") &&
405-
strcmp(member_tag.key(), "osm_version") &&
406-
strcmp(member_tag.key(), "osm_uid") &&
407-
strcmp(member_tag.key(), "osm_changeset") &&
408-
strcmp(member_tag.key(), "osm_timestamp")) {
409-
member_superseded[i] = 0;
410-
break;
411-
}
412-
}
413-
}
414-
++i;
415-
}
416318
}
417319

418320
add_z_order(out_tags, roads);
419321

420-
return 0;
322+
return false;
421323
}

tagtransform-c.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class c_tagtransform_t : public tagtransform_t
1616
bool filter_rel_member_tags(taglist_t const &rel_tags,
1717
osmium::memory::Buffer const &members,
1818
rolelist_t const &member_roles,
19-
int *member_superseded, int *make_boundary,
20-
int *make_polygon, int *roads,
21-
export_list const &exlist, taglist_t &out_tags,
19+
int *make_boundary, int *make_polygon,
20+
int *roads, export_list const &exlist,
21+
taglist_t &out_tags,
2222
bool allow_typeless = false) override;
2323

2424
private:

tagtransform-lua.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ bool lua_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
140140

141141
bool lua_tagtransform_t::filter_rel_member_tags(
142142
taglist_t const &rel_tags, osmium::memory::Buffer const &members,
143-
rolelist_t const &member_roles, int *member_superseded, int *make_boundary,
144-
int *make_polygon, int *roads, export_list const &, taglist_t &out_tags,
145-
bool)
143+
rolelist_t const &member_roles, int *make_boundary, int *make_polygon,
144+
int *roads, export_list const &, taglist_t &out_tags, bool)
146145
{
147146
size_t num_members = member_roles.size();
148147
lua_getglobal(L, m_rel_mem_func.c_str());
@@ -195,16 +194,8 @@ bool lua_tagtransform_t::filter_rel_member_tags(
195194
*make_boundary = (int)lua_tointeger(L, -1);
196195
lua_pop(L, 1);
197196

198-
lua_pushnil(L);
199-
for (size_t i = 0; i < num_members; ++i) {
200-
if (lua_next(L, -2)) {
201-
member_superseded[i] = (int)lua_tointeger(L, -1);
202-
lua_pop(L, 1);
203-
} else {
204-
throw std::runtime_error("Failed to read member_superseded from lua function");
205-
}
206-
}
207-
lua_pop(L, 2);
197+
// obsolete member superseded is ignored.
198+
lua_pop(L, 1);
208199

209200
lua_pushnil(L);
210201
while (lua_next(L, -2) != 0) {

tagtransform-lua.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class lua_tagtransform_t : public tagtransform_t
2222
bool filter_rel_member_tags(taglist_t const &rel_tags,
2323
osmium::memory::Buffer const &members,
2424
rolelist_t const &member_roles,
25-
int *member_superseded, int *make_boundary,
26-
int *make_polygon, int *roads,
27-
export_list const &exlist, taglist_t &out_tags,
25+
int *make_boundary, int *make_polygon,
26+
int *roads, export_list const &exlist,
27+
taglist_t &out_tags,
2828
bool allow_typeless = false) override;
2929

3030
private:

0 commit comments

Comments
 (0)