File: node_location_handler.cc

package info (click to toggle)
pyosmium 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,584 kB
  • sloc: python: 4,400; cpp: 2,504; makefile: 20
file content (75 lines) | stat: -rw-r--r-- 1,943 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* SPDX-License-Identifier: BSD-2-Clause
 *
 * This file is part of pyosmium. (https://osmcode.org/pyosmium/)
 *
 * Copyright (C) 2024 Sarah Hoffmann <lonvia@denofr.de> and others.
 * For a full list of authors see the git log.
 */
#include <pybind11/pybind11.h>

#include <osmium/index/map/all.hpp>
#include <osmium/handler/node_locations_for_ways.hpp>

#include "base_handler.h"

namespace {

using LocationTable =
        osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>;
using NodeLocationHandler =
        osmium::handler::NodeLocationsForWays<LocationTable>;

class NodeLocationsForWays : public pyosmium::BaseHandler
{
public:
    NodeLocationsForWays(LocationTable &idx)
    : handler(idx)
    {
        m_enabled_for = osmium::osm_entity_bits::node
                        | osmium::osm_entity_bits::way;
    }

    bool node(pyosmium::PyOSMNode &o) override
    {
        handler.node(*(o.get()));
        return false;
    }

    bool way(pyosmium::PyOSMWay &o) override
    {
        if (apply_nodes_to_ways) {
            handler.way(*(o.get()));
        }
        return false;
    }

    bool get_apply_nodes_to_ways() const { return apply_nodes_to_ways; }

    void set_apply_nodes_to_ways(bool val) { apply_nodes_to_ways = val; }

    void ignore_errors() { handler.ignore_errors(); }

private:
    NodeLocationHandler handler;
    bool apply_nodes_to_ways = true;
};

} // namespace

namespace py = pybind11;

namespace pyosmium {

void init_node_location_handler(py::module &m)
{
    py::class_<NodeLocationsForWays, BaseHandler>(m, "NodeLocationsForWays")
        .def(py::init<LocationTable&>(), py::keep_alive<1, 2>())
        .def("ignore_errors", &NodeLocationsForWays::ignore_errors)
        .def_property("apply_nodes_to_ways",
                     &NodeLocationsForWays::get_apply_nodes_to_ways,
                     &NodeLocationsForWays::set_apply_nodes_to_ways)
    ;

}

} // namespace