1414
1515#include " db-copy.hpp"
1616#include " format.hpp"
17- #include " input-handler.hpp"
1817#include " logging.hpp"
1918#include " middle.hpp"
2019#include " options.hpp"
@@ -188,8 +187,9 @@ osmdata_t::osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
188187 options_t const &options)
189188: m_dependency_manager(std::move(dependency_manager)), m_mid(std::move(mid)),
190189 m_outs (std::move(outs)), m_conninfo(options.database_options.conninfo()),
191- m_num_procs(options.num_procs), m_append(options.append),
192- m_droptemp(options.droptemp), m_parallel_indexing(options.parallel_indexing),
190+ m_bbox(options.bbox), m_num_procs(options.num_procs),
191+ m_append(options.append), m_droptemp(options.droptemp),
192+ m_parallel_indexing(options.parallel_indexing),
193193 m_with_extra_attrs(options.extra_attributes),
194194 m_with_forward_dependencies(options.with_forward_dependencies)
195195{
@@ -211,6 +211,84 @@ slim_middle_t &osmdata_t::slim_middle() const noexcept
211211 return *slim;
212212}
213213
214+ void osmdata_t::node (osmium::Node const &node)
215+ {
216+ if (node.deleted ()) {
217+ if (!m_append) {
218+ throw std::runtime_error{" Input file contains deleted objects but "
219+ " you are not in append mode." };
220+ }
221+ node_delete (node.id ());
222+ } else {
223+ // if the node is not valid, then node.location.lat/lon() can throw.
224+ // we probably ought to treat invalid locations as if they were
225+ // deleted and ignore them.
226+ if (!node.location ().valid ()) {
227+ log_warn (" Ignored invalid location on node {} (version {})" ,
228+ node.id (), node.version ());
229+ return ;
230+ }
231+
232+ if (!m_bbox.valid () || m_bbox.contains (node.location ())) {
233+ if (m_append) {
234+ node_modify (node);
235+ } else {
236+ node_add (node);
237+ }
238+ }
239+ }
240+ m_progress.add_node (node.id ());
241+ }
242+
243+ void osmdata_t::way (osmium::Way &way)
244+ {
245+ if (m_type != osmium::item_type::way) {
246+ m_type = osmium::item_type::way;
247+ flush ();
248+ }
249+
250+ if (way.deleted ()) {
251+ if (!m_append) {
252+ throw std::runtime_error{" Input file contains deleted objects but "
253+ " you are not in append mode." };
254+ }
255+ way_delete (way.id ());
256+ } else {
257+ if (m_append) {
258+ way_modify (&way);
259+ } else {
260+ way_add (&way);
261+ }
262+ }
263+ m_progress.add_way (way.id ());
264+ }
265+
266+ void osmdata_t::relation (osmium::Relation const &rel)
267+ {
268+ if (m_type != osmium::item_type::relation) {
269+ m_type = osmium::item_type::relation;
270+ flush ();
271+ }
272+
273+ if (rel.deleted ()) {
274+ if (!m_append) {
275+ throw std::runtime_error{" Input file contains deleted objects but "
276+ " you are not in append mode." };
277+ }
278+ relation_delete (rel.id ());
279+ } else {
280+ if (rel.members ().size () > 32767 ) {
281+ return ;
282+ }
283+ if (m_append) {
284+ relation_modify (rel);
285+ } else {
286+ relation_add (rel);
287+ }
288+ }
289+ m_progress.add_rel (rel.id ());
290+ }
291+
214292void osmdata_t::node_add (osmium::Node const &node) const
215293{
216294 m_mid->node_set (node);
@@ -520,32 +598,29 @@ class multithreaded_processor
520598
521599} // anonymous namespace
522600
523- progress_display_t osmdata_t::process_file (osmium::io::File const &file,
524- osmium::Box const &bbox) const
601+ progress_display_t osmdata_t::process_file (osmium::io::File const &file)
525602{
526- input_handler_t handler{bbox, m_append, this };
527603 osmium::io::Reader reader{file};
528604 type_id_version last{osmium::item_type::node, 0 , 0 };
529605
530606 while (osmium::memory::Buffer buffer = reader.read ()) {
531607 for (auto &object : buffer.select <osmium::OSMObject>()) {
532608 last = check_input (last, object);
533- osmium::apply_item (object, handler );
609+ osmium::apply_item (object, * this );
534610 }
535611 }
536- osmium::apply_flush (handler );
612+ flush ( );
537613
538614 reader.close ();
539615
540- return handler. progress () ;
616+ return m_progress ;
541617}
542618
543619progress_display_t
544- osmdata_t ::process_files(std::vector<osmium::io::File> const &files,
545- osmium::Box const &bbox) const
620+ osmdata_t ::process_files(std::vector<osmium::io::File> const &files)
546621{
547622 if (files.size () == 1 ) {
548- return process_file (files.front (), bbox );
623+ return process_file (files.front ());
549624 }
550625
551626 std::vector<data_source_t > data_sources;
@@ -561,13 +636,11 @@ osmdata_t::process_files(std::vector<osmium::io::File> const &files,
561636 }
562637 }
563638
564- input_handler_t handler{bbox, m_append, this };
565-
566639 while (!queue.empty ()) {
567640 auto element = queue.top ();
568641 queue.pop ();
569642 if (queue.empty () || element != queue.top ()) {
570- osmium::apply_item (element.object (), handler );
643+ osmium::apply_item (element.object (), * this );
571644 }
572645
573646 auto *source = element.data_source ();
@@ -576,13 +649,13 @@ osmdata_t::process_files(std::vector<osmium::io::File> const &files,
576649 }
577650 }
578651
579- osmium::apply_flush (handler );
652+ flush ( );
580653
581654 for (auto &data_source : data_sources) {
582655 data_source.close ();
583656 }
584657
585- return handler. progress () ;
658+ return m_progress ;
586659}
587660
588661void osmdata_t::process_dependents () const
0 commit comments