Skip to content

Commit 4872930

Browse files
authored
Merge pull request #1462 from joto/remove-multi-cleanup
Cleanup some code after removal of multi output
2 parents feb2e0d + c3647a2 commit 4872930

File tree

6 files changed

+96
-108
lines changed

6 files changed

+96
-108
lines changed

src/output-pgsql.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ void output_pgsql_t::pending_way(osmid_t id)
8484
pgsql_delete_way_from_output(id);
8585

8686
taglist_t outtags;
87-
int polygon = 0;
88-
int roads = 0;
87+
bool polygon = false;
88+
bool roads = false;
8989
auto &way = buffer.get<osmium::Way>(0);
9090
if (!m_tagtransform->filter_tags(way, &polygon, &roads, outtags)) {
9191
auto nnodes = m_mid->nodes_get_list(&(way.nodes()));
@@ -149,8 +149,8 @@ void output_pgsql_t::node_add(osmium::Node const &node)
149149

150150
void output_pgsql_t::way_add(osmium::Way *way)
151151
{
152-
int polygon = 0;
153-
int roads = 0;
152+
bool polygon = false;
153+
bool roads = false;
154154
taglist_t outtags;
155155

156156
/* Check whether the way is: (1) Exportable, (2) Maybe a polygon */
@@ -181,9 +181,9 @@ void output_pgsql_t::pgsql_process_relation(osmium::Relation const &rel)
181181
return;
182182
}
183183

184-
int roads = 0;
185-
int make_polygon = 0;
186-
int make_boundary = 0;
184+
bool roads = false;
185+
bool make_polygon = false;
186+
bool make_boundary = false;
187187
taglist_t outtags;
188188

189189
// If it's a route relation make_boundary and make_polygon will be false

src/tagtransform-c.cpp

Lines changed: 72 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ static const struct
2323
{
2424
int offset;
2525
char const *highway;
26-
int roads;
27-
} layers[] = {{1, "proposed", 0}, {2, "construction", 0},
28-
{10, "steps", 0}, {10, "cycleway", 0},
29-
{10, "bridleway", 0}, {10, "footway", 0},
30-
{10, "path", 0}, {11, "track", 0},
31-
{15, "service", 0},
32-
33-
{24, "tertiary_link", 0}, {25, "secondary_link", 1},
34-
{27, "primary_link", 1}, {28, "trunk_link", 1},
35-
{29, "motorway_link", 1},
36-
37-
{30, "raceway", 0}, {31, "pedestrian", 0},
38-
{32, "living_street", 0}, {33, "road", 0},
39-
{33, "unclassified", 0}, {33, "residential", 0},
40-
{34, "tertiary", 0}, {36, "secondary", 1},
41-
{37, "primary", 1}, {38, "trunk", 1},
42-
{39, "motorway", 1}};
43-
44-
void add_z_order(taglist_t &tags, int *roads)
26+
bool roads;
27+
} layers[] = {{1, "proposed", false}, {2, "construction", false},
28+
{10, "steps", false}, {10, "cycleway", false},
29+
{10, "bridleway", false}, {10, "footway", false},
30+
{10, "path", false}, {11, "track", false},
31+
{15, "service", false},
32+
33+
{24, "tertiary_link", false}, {25, "secondary_link", true},
34+
{27, "primary_link", true}, {28, "trunk_link", true},
35+
{29, "motorway_link", true},
36+
37+
{30, "raceway", false}, {31, "pedestrian", false},
38+
{32, "living_street", false}, {33, "road", false},
39+
{33, "unclassified", false}, {33, "residential", false},
40+
{34, "tertiary", false}, {36, "secondary", true},
41+
{37, "primary", true}, {38, "trunk", true},
42+
{39, "motorway", true}};
43+
44+
void add_z_order(taglist_t &tags, bool *roads)
4545
{
4646
std::string const *const layer = tags.get("layer");
4747
std::string const *const highway = tags.get("highway");
@@ -54,7 +54,7 @@ void add_z_order(taglist_t &tags, int *roads)
5454

5555
int l = layer ? (int)strtol(layer->c_str(), nullptr, 10) : 0;
5656
z_order = 100 * l;
57-
*roads = 0;
57+
*roads = false;
5858

5959
if (highway) {
6060
for (const auto &layer : layers) {
@@ -68,11 +68,11 @@ void add_z_order(taglist_t &tags, int *roads)
6868

6969
if (railway && !railway->empty()) {
7070
z_order += 35;
71-
*roads = 1;
71+
*roads = true;
7272
}
7373
/* Administrative boundaries are rendered at low zooms so we prefer to use the roads table */
7474
if (boundary && *boundary == "administrative") {
75-
*roads = 1;
75+
*roads = true;
7676
}
7777

7878
if (bridge) {
@@ -101,8 +101,7 @@ std::unique_ptr<tagtransform_t> c_tagtransform_t::clone() const
101101
}
102102

103103
bool c_tagtransform_t::check_key(std::vector<taginfo> const &infos,
104-
char const *k, bool *filter, int *flags,
105-
bool strict)
104+
char const *k, bool *filter, int *flags)
106105
{
107106
//go through the actual tags found on the item and keep the ones in the export list
108107
for (auto const &info : infos) {
@@ -119,38 +118,35 @@ bool c_tagtransform_t::check_key(std::vector<taginfo> const &infos,
119118
}
120119

121120
// if we didn't find any tags that we wanted to export
122-
// and we aren't strictly adhering to the list
123-
if (!strict) {
124-
if (m_options->hstore_mode != hstore_column::none) {
125-
/* ... but if hstore_match_only is set then don't take this
121+
if (m_options->hstore_mode != hstore_column::none) {
122+
/* ... but if hstore_match_only is set then don't take this
126123
as a reason for keeping the object */
127-
if (!m_options->hstore_match_only) {
128-
*filter = false;
129-
}
130-
/* with hstore, copy all tags... */
131-
return true;
124+
if (!m_options->hstore_match_only) {
125+
*filter = false;
132126
}
127+
/* with hstore, copy all tags... */
128+
return true;
129+
}
133130

134-
if (!m_options->hstore_columns.empty()) {
135-
/* does this column match any of the hstore column prefixes? */
136-
for (auto const &column : m_options->hstore_columns) {
137-
if (boost::starts_with(k, column)) {
138-
/* ... but if hstore_match_only is set then don't take this
131+
if (!m_options->hstore_columns.empty()) {
132+
/* does this column match any of the hstore column prefixes? */
133+
for (auto const &column : m_options->hstore_columns) {
134+
if (boost::starts_with(k, column)) {
135+
/* ... but if hstore_match_only is set then don't take this
139136
as a reason for keeping the object */
140-
if (!m_options->hstore_match_only) {
141-
*filter = false;
142-
}
143-
return true;
137+
if (!m_options->hstore_match_only) {
138+
*filter = false;
144139
}
140+
return true;
145141
}
146142
}
147143
}
148144

149145
return false;
150146
}
151147

152-
bool c_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
153-
int *roads, taglist_t &out_tags, bool strict)
148+
bool c_tagtransform_t::filter_tags(osmium::OSMObject const &o, bool *polygon,
149+
bool *roads, taglist_t &out_tags)
154150
{
155151
//assume we dont like this set of tags
156152
bool filter = true;
@@ -170,27 +166,25 @@ bool c_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
170166
for (auto const &item : o.tags()) {
171167
char const *const k = item.key();
172168
char const *const v = item.value();
173-
//if we want to do more than the export list says
174-
if (!strict) {
175-
if (o.type() == osmium::item_type::relation &&
176-
std::strcmp("type", k) == 0) {
177-
out_tags.add_tag(k, v);
169+
170+
if (o.type() == osmium::item_type::relation &&
171+
std::strcmp("type", k) == 0) {
172+
out_tags.add_tag(k, v);
173+
continue;
174+
}
175+
/* Allow named islands to appear as polygons */
176+
if (std::strcmp("natural", k) == 0 &&
177+
std::strcmp("coastline", v) == 0) {
178+
add_area_tag = 1;
179+
180+
/* Discard natural=coastline tags (we render these from a shapefile instead) */
181+
if (!m_options->keep_coastlines) {
178182
continue;
179183
}
180-
/* Allow named islands to appear as polygons */
181-
if (std::strcmp("natural", k) == 0 &&
182-
std::strcmp("coastline", v) == 0) {
183-
add_area_tag = 1;
184-
185-
/* Discard natural=coastline tags (we render these from a shapefile instead) */
186-
if (!m_options->keep_coastlines) {
187-
continue;
188-
}
189-
}
190184
}
191185

192186
//go through the actual tags found on the item and keep the ones in the export list
193-
if (check_key(infos, k, &filter, &flags, strict)) {
187+
if (check_key(infos, k, &filter, &flags)) {
194188
out_tags.add_tag(k, v);
195189
}
196190
}
@@ -202,7 +196,7 @@ bool c_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
202196
if (add_area_tag) {
203197
/* If we need to force this as a polygon, append an area tag */
204198
out_tags.add_tag_if_not_exists("area", "yes");
205-
*polygon = 1;
199+
*polygon = true;
206200
} else {
207201
auto const *area = o.tags()["area"];
208202
if (area) {
@@ -222,27 +216,25 @@ bool c_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
222216

223217
bool c_tagtransform_t::filter_rel_member_tags(
224218
taglist_t const &rel_tags, osmium::memory::Buffer const &,
225-
rolelist_t const &, int *make_boundary, int *make_polygon, int *roads,
226-
taglist_t &out_tags, bool allow_typeless)
219+
rolelist_t const &, bool *make_boundary, bool *make_polygon, bool *roads,
220+
taglist_t &out_tags)
227221
{
228-
//if it has a relation figure out what kind it is
229222
std::string const *type = rel_tags.get("type");
223+
if (!type) {
224+
return true;
225+
}
226+
230227
bool is_route = false;
231228
bool is_boundary = false;
232229
bool is_multipolygon = false;
233-
if (type) {
234-
//what kind of relation is it
235-
if (*type == "route") {
236-
is_route = true;
237-
} else if (*type == "boundary") {
238-
is_boundary = true;
239-
} else if (*type == "multipolygon") {
240-
is_multipolygon = true;
241-
} else if (!allow_typeless) {
242-
return true;
243-
}
244-
} //you didnt have a type and it was required
245-
else if (!allow_typeless) {
230+
231+
if (*type == "route") {
232+
is_route = true;
233+
} else if (*type == "boundary") {
234+
is_boundary = true;
235+
} else if (*type == "multipolygon") {
236+
is_multipolygon = true;
237+
} else {
246238
return true;
247239
}
248240

@@ -331,12 +323,12 @@ bool c_tagtransform_t::filter_rel_member_tags(
331323
- Linear features will end up in the line and roads tables (useful for admin boundaries)
332324
- Polygon features also go into the polygon table (useful for national_forests)
333325
The edges of the polygon also get treated as linear fetaures allowing these to be rendered seperately. */
334-
*make_boundary = 1;
326+
*make_boundary = true;
335327
} else if (is_multipolygon && out_tags.contains("boundary")) {
336328
/* Treat type=multipolygon exactly like type=boundary if it has a boundary tag. */
337-
*make_boundary = 1;
329+
*make_boundary = true;
338330
} else if (is_multipolygon) {
339-
*make_polygon = 1;
331+
*make_polygon = true;
340332
}
341333

342334
add_z_order(out_tags, roads);

src/tagtransform-c.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ class c_tagtransform_t : public tagtransform_t
2020

2121
std::unique_ptr<tagtransform_t> clone() const override;
2222

23-
bool filter_tags(osmium::OSMObject const &o, int *polygon, int *roads,
24-
taglist_t &out_tags, bool strict = false) override;
23+
bool filter_tags(osmium::OSMObject const &o, bool *polygon, bool *roads,
24+
taglist_t &out_tags) override;
2525

2626
bool filter_rel_member_tags(taglist_t const &rel_tags,
2727
osmium::memory::Buffer const &members,
2828
rolelist_t const &member_roles,
29-
int *make_boundary, int *make_polygon,
30-
int *roads, taglist_t &out_tags,
31-
bool allow_typeless = false) override;
29+
bool *make_boundary, bool *make_polygon,
30+
bool *roads, taglist_t &out_tags) override;
3231

3332
private:
3433
bool check_key(std::vector<taginfo> const &infos, char const *k,
35-
bool *filter, int *flags, bool strict);
34+
bool *filter, int *flags);
3635

3736
options_t const *m_options;
3837
export_list m_export_list;

src/tagtransform-lua.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ void lua_tagtransform_t::check_lua_function_exists(std::string const &func_name)
6363
lua_pop(L, 1);
6464
}
6565

66-
bool lua_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
67-
int *roads, taglist_t &out_tags, bool)
66+
bool lua_tagtransform_t::filter_tags(osmium::OSMObject const &o, bool *polygon,
67+
bool *roads, taglist_t &out_tags)
6868
{
6969
switch (o.type()) {
7070
case osmium::item_type::node:
@@ -150,8 +150,8 @@ bool lua_tagtransform_t::filter_tags(osmium::OSMObject const &o, int *polygon,
150150

151151
bool lua_tagtransform_t::filter_rel_member_tags(
152152
taglist_t const &rel_tags, osmium::memory::Buffer const &members,
153-
rolelist_t const &member_roles, int *make_boundary, int *make_polygon,
154-
int *roads, taglist_t &out_tags, bool)
153+
rolelist_t const &member_roles, bool *make_boundary, bool *make_polygon,
154+
bool *roads, taglist_t &out_tags)
155155
{
156156
size_t const num_members = member_roles.size();
157157
lua_getglobal(L, m_rel_mem_func.c_str());

src/tagtransform-lua.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ class lua_tagtransform_t : public tagtransform_t
2929

3030
std::unique_ptr<tagtransform_t> clone() const override;
3131

32-
bool filter_tags(osmium::OSMObject const &o, int *polygon, int *roads,
33-
taglist_t &out_tags, bool strict = false) override;
32+
bool filter_tags(osmium::OSMObject const &o, bool *polygon, bool *roads,
33+
taglist_t &out_tags) override;
3434

3535
bool filter_rel_member_tags(taglist_t const &rel_tags,
3636
osmium::memory::Buffer const &members,
3737
rolelist_t const &member_roles,
38-
int *make_boundary, int *make_polygon,
39-
int *roads, taglist_t &out_tags,
40-
bool allow_typeless = false) override;
38+
bool *make_boundary, bool *make_polygon,
39+
bool *roads, taglist_t &out_tags) override;
4140

4241
private:
4342
void open_style();

src/tagtransform.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ class tagtransform_t
2929

3030
virtual std::unique_ptr<tagtransform_t> clone() const = 0;
3131

32-
virtual bool filter_tags(osmium::OSMObject const &o, int *polygon,
33-
int *roads, taglist_t &out_tags,
34-
bool strict = false) = 0;
32+
virtual bool filter_tags(osmium::OSMObject const &o, bool *polygon,
33+
bool *roads, taglist_t &out_tags) = 0;
3534

3635
virtual bool filter_rel_member_tags(taglist_t const &rel_tags,
3736
osmium::memory::Buffer const &members,
3837
rolelist_t const &member_roles,
39-
int *make_boundary, int *make_polygon,
40-
int *roads, taglist_t &out_tags,
41-
bool allow_typeless = false) = 0;
38+
bool *make_boundary, bool *make_polygon,
39+
bool *roads, taglist_t &out_tags) = 0;
4240
};
4341

4442
#endif // OSM2PGSQL_TAGTRANSFORM_HPP

0 commit comments

Comments
 (0)