Skip to content

Commit e1b75a5

Browse files
committed
convert remaining outputs to libosmium
1 parent 728a4ff commit e1b75a5

19 files changed

+310
-319
lines changed

contrib/libosmium/osmium/geom/wkb.hpp

+25
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,31 @@ namespace osmium {
199199
}
200200
}
201201

202+
/* MultiLineString */
203+
204+
void multilinestring_start() {
205+
m_data.clear();
206+
m_multipolygon_size_offset = header(m_data, wkbMultiLineString, true);
207+
}
208+
209+
void add_part(std::string const &part) {
210+
m_data.append(part);
211+
}
212+
213+
linestring_type multilinestring_finish(size_t num_lines) {
214+
set_size(m_multipolygon_size_offset, num_lines);
215+
std::string data;
216+
217+
using std::swap;
218+
swap(data, m_data);
219+
220+
if (m_out_type == out_type::hex) {
221+
return convert_to_hex(data);
222+
} else {
223+
return data;
224+
}
225+
}
226+
202227
/* Polygon */
203228
polygon_type polygon_finish() {
204229
set_size(m_polygon_size_offset, m_rings);

expire-tiles.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ int expire_tiles::from_db(table_t* table, osmid_t osm_id) {
508508
//dirty the stuff
509509
const char* wkb = nullptr;
510510
while((wkb = wkbs.get_next()))
511+
// XXX need to convert from hex to binary
511512
from_wkb(wkb, osm_id);
512513

513514
//return how many rows were affected

geometry-processor.cpp

+30-58
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
std::shared_ptr<geometry_processor> geometry_processor::create(const std::string &type,
1515
const options_t *options) {
1616
std::shared_ptr<geometry_processor> ptr;
17-
int srid = options->projection->target_srs();
1817

1918
if (type == "point") {
20-
ptr = std::make_shared<processor_point>(srid);
19+
ptr = std::make_shared<processor_point>(options->projection);
2120
}
2221
else if (type == "line") {
23-
ptr = std::make_shared<processor_line>(srid);
22+
ptr = std::make_shared<processor_line>(options->projection);
2423
}
2524
else if (type == "polygon") {
26-
ptr = std::make_shared<processor_polygon>(srid, options->enable_multi);
25+
ptr = std::make_shared<processor_polygon>(options->projection,
26+
options->enable_multi);
2727
}
2828
else {
2929
throw std::runtime_error((boost::format("Unable to construct geometry processor "
@@ -38,8 +38,7 @@ geometry_processor::geometry_processor(int srid, const std::string &type, unsign
3838
: m_srid(srid), m_type(type), m_interests(interests) {
3939
}
4040

41-
geometry_processor::~geometry_processor() {
42-
}
41+
geometry_processor::~geometry_processor() = default;
4342

4443
int geometry_processor::srid() const {
4544
return m_srid;
@@ -57,40 +56,29 @@ bool geometry_processor::interests(unsigned int interested) const {
5756
return (interested & m_interests) == interested;
5857
}
5958

60-
geometry_builder::pg_geom_t geometry_processor::process_node(double, double) {
61-
return geometry_builder::pg_geom_t();
62-
}
63-
64-
geometry_builder::pg_geom_t geometry_processor::process_way(const nodelist_t &) {
65-
return geometry_builder::pg_geom_t();
66-
}
67-
68-
geometry_builder::pg_geoms_t geometry_processor::process_relation(const multinodelist_t &) {
69-
return geometry_builder::pg_geoms_t();
59+
geometry_processor::wkb_t
60+
geometry_processor::process_node(osmium::Location const &)
61+
{
62+
return wkb_t();
7063
}
7164

72-
way_helper::way_helper()
65+
geometry_processor::wkb_t geometry_processor::process_way(osmium::Way const &)
7366
{
67+
return wkb_t();
7468
}
75-
way_helper::~way_helper()
69+
70+
geometry_processor::wkbs_t
71+
geometry_processor::process_relation(osmium::Relation const &,
72+
osmium::memory::Buffer const &)
7673
{
74+
return wkbs_t();
7775
}
78-
size_t way_helper::set(osmium::WayNodeList const &node_ids,
79-
middle_query_t const *mid, reprojection const *proj)
80-
{
81-
node_cache.clear();
82-
mid->nodes_get_list(node_cache, node_ids, proj);
8376

84-
// equivalent to returning node_count for complete ways, different for partial
85-
// extracts
86-
return node_cache.size();
87-
}
8877

8978
relation_helper::relation_helper()
9079
: data(1024, osmium::memory::Buffer::auto_grow::yes)
9180
{}
9281

93-
relation_helper::~relation_helper() = default;
9482

9583
size_t relation_helper::set(osmium::RelationMemberList const &member_list, middle_t const *mid)
9684
{
@@ -100,13 +88,10 @@ size_t relation_helper::set(osmium::RelationMemberList const &member_list, middl
10088
roles.clear();
10189

10290
//grab the way members' ids
103-
size_t num_input = member_list.size();
104-
input_way_ids.reserve(num_input);
105-
roles.reserve(num_input);
106-
for (auto const &member : member_list) {
107-
if (member.type() == osmium::item_type::way) {
108-
input_way_ids.push_back(member.ref());
109-
roles.push_back(member.role());
91+
for (auto const &m : member_list) {
92+
/* Need to handle more than just ways... */
93+
if (m.type() == osmium::item_type::way) {
94+
input_way_ids.push_back(m.ref());
11095
}
11196
}
11297

@@ -118,21 +103,14 @@ size_t relation_helper::set(osmium::RelationMemberList const &member_list, middl
118103
auto num_ways = mid->ways_get_list(input_way_ids, data);
119104

120105
//grab the roles of each way
121-
if (num_ways < input_way_ids.size()) {
122-
size_t memberpos = 0;
123-
size_t waypos = 0;
124-
for (auto const &w : data.select<osmium::Way>()) {
125-
while (memberpos < input_way_ids.size()) {
126-
if (input_way_ids[memberpos] == w.id()) {
127-
roles[waypos] = roles[memberpos];
128-
++memberpos;
129-
break;
130-
}
131-
++memberpos;
106+
for (auto const &w : data.select<osmium::Way>()) {
107+
for (auto const &member : member_list) {
108+
if (member.ref() == w.id() &&
109+
member.type() == osmium::item_type::way) {
110+
roles.emplace_back(member.role());
111+
break;
132112
}
133-
++waypos;
134113
}
135-
roles.resize(num_ways);
136114
}
137115

138116
//mark the ends of each so whoever uses them will know where they end..
@@ -147,21 +125,15 @@ multitaglist_t relation_helper::get_filtered_tags(tagtransform *transform, expor
147125

148126
size_t i = 0;
149127
for (auto const &w : data.select<osmium::Way>()) {
150-
transform->filter_tags(w, nullptr, nullptr, el, filtered[i++]);
128+
transform->filter_tags(w, nullptr, nullptr, el, filtered[++i]);
151129
}
152130

153131
return filtered;
154132
}
155133

156-
multinodelist_t relation_helper::get_nodes(middle_t const *mid,
157-
reprojection const *proj) const
134+
void relation_helper::add_way_locations(middle_t const *mid)
158135
{
159-
multinodelist_t nodes(roles.size());
160-
161-
size_t i = 0;
162-
for (auto const &w : data.select<osmium::Way>()) {
163-
mid->nodes_get_list(nodes[i++], w.nodes(), proj);
136+
for (auto &w : data.select<osmium::Way>()) {
137+
mid->nodes_get_list(&(w.nodes()));
164138
}
165-
166-
return nodes;
167139
}

geometry-processor.hpp

+11-22
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <osmium/memory/buffer.hpp>
1010

11-
#include "geometry-builder.hpp"
11+
#include "osmium-builder.hpp"
1212
#include "osmtypes.hpp"
1313
#include "tagtransform.hpp"
1414

@@ -18,6 +18,8 @@ struct options_t;
1818
class reprojection;
1919

2020
struct geometry_processor {
21+
using wkb_t = geom::osmium_builder_t::wkb_t;
22+
using wkbs_t = geom::osmium_builder_t::wkbs_t;
2123
// factory method for creating various types of geometry processors either by name or by geometry column type
2224
static std::shared_ptr<geometry_processor> create(const std::string &type,
2325
const options_t *options);
@@ -45,17 +47,18 @@ struct geometry_processor {
4547

4648
// process a node, optionally returning a WKB string describing
4749
// geometry to be inserted into the table.
48-
virtual geometry_builder::pg_geom_t process_node(double lat, double lon);
50+
virtual wkb_t process_node(osmium::Location const &loc);
4951

5052
// process a way
5153
// position data and optionally returning WKB-encoded geometry
5254
// for insertion into the table.
53-
virtual geometry_builder::pg_geom_t process_way(const nodelist_t &nodes);
55+
virtual wkb_t process_way(osmium::Way const &way);
5456

5557
// process a way, taking a middle query object to get way and
5658
// node position data. optionally returns an array of WKB-encoded geometry
5759
// for insertion into the table.
58-
virtual geometry_builder::pg_geoms_t process_relation(const multinodelist_t &nodes);
60+
virtual wkbs_t process_relation(osmium::Relation const &rel,
61+
osmium::memory::Buffer const &ways);
5962

6063
// returns the SRID of the output geometry.
6164
int srid() const;
@@ -75,29 +78,15 @@ struct geometry_processor {
7578
};
7679

7780

78-
//various bits for continuous processing of ways
79-
struct way_helper
80-
{
81-
way_helper();
82-
~way_helper();
83-
size_t set(osmium::WayNodeList const &node_ids, middle_query_t const *mid,
84-
reprojection const *proj);
85-
86-
nodelist_t node_cache;
87-
};
88-
8981
//various bits for continuous processing of members of relations
90-
struct relation_helper
82+
class relation_helper
9183
{
84+
public:
9285
relation_helper();
93-
~relation_helper();
86+
9487
size_t set(osmium::RelationMemberList const &member_list, middle_t const *mid);
9588
multitaglist_t get_filtered_tags(tagtransform *transform, export_list const &el) const;
96-
multinodelist_t get_nodes(middle_t const *mid,
97-
reprojection const *proj) const;
98-
99-
osmium::memory::ItemIteratorRange<const osmium::Way> way_iterator() const
100-
{ return data.select<osmium::Way>(); }
89+
void add_way_locations(middle_t const *mid);
10190

10291
rolelist_t roles;
10392
std::vector<int> superseded;

0 commit comments

Comments
 (0)