@@ -165,6 +165,35 @@ void output_pgsql_t::way_add(osmium::Way *way)
165165 }
166166}
167167
168+ // The roles of all available member ways of a relation are available in the
169+ // Lua "filter_tags_relation_member" callback function. This function extracts
170+ // the roles from all ways in the buffer and returns the list.
171+ static rolelist_t get_rolelist (osmium::Relation const &rel,
172+ osmium::memory::Buffer const &buffer)
173+ {
174+ rolelist_t roles;
175+
176+ auto it = buffer.select <osmium::Way>().cbegin ();
177+ auto const end = buffer.select <osmium::Way>().cend ();
178+
179+ if (it == end) {
180+ return roles;
181+ }
182+
183+ for (auto const &member : rel.members ()) {
184+ if (member.type () == osmium::item_type::way &&
185+ member.ref () == it->id ()) {
186+ roles.emplace_back (member.role ());
187+ ++it;
188+ if (it == end) {
189+ break ;
190+ }
191+ }
192+ }
193+
194+ return roles;
195+ }
196+
168197/* This is the workhorse of pgsql_add_relation, split out because it is used as the callback for iterate relations */
169198void output_pgsql_t::pgsql_process_relation (osmium::Relation const &rel)
170199{
@@ -174,8 +203,7 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
174203 }
175204
176205 buffer.clear ();
177- rolelist_t xrole;
178- auto num_ways = m_mid->rel_way_members_get (rel, &xrole, &buffer);
206+ auto const num_ways = m_mid->rel_way_members_get (rel, &buffer);
179207
180208 if (num_ways == 0 ) {
181209 return ;
@@ -186,6 +214,11 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
186214 bool make_boundary = false ;
187215 taglist_t outtags;
188216
217+ rolelist_t xrole;
218+ if (!m_options.tag_transform_script .empty ()) {
219+ xrole = get_rolelist (rel, buffer);
220+ }
221+
189222 // If it's a route relation make_boundary and make_polygon will be false
190223 // otherwise one or the other will be true.
191224 if (m_tagtransform->filter_rel_member_tags (prefiltered_tags, buffer, xrole,
0 commit comments