File: index.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 (65 lines) | stat: -rw-r--r-- 2,021 bytes parent folder | download | duplicates (4)
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
/* SPDX-License-Identifier: BSD-2-Clause
 *
 * This file is part of pyosmium. (https://osmcode.org/pyosmium/)
 *
 * Copyright (C) 2025 Sarah Hoffmann <lonvia@denofr.de> and others.
 * For a full list of authors see the git log.
 */
#include <pybind11/pybind11.h>

#include <osmium/osm.hpp>
#include <osmium/index/map/all.hpp>
#include <osmium/index/node_locations_map.hpp>
#include <osmium/index/id_set.hpp>

namespace py = pybind11;

#ifdef Py_GIL_DISABLED
PYBIND11_MODULE(index, m, py::mod_gil_not_used())
#else
PYBIND11_MODULE(index, m)
#endif
{
    using LocationTable =
        osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>;
    using IndexFactory =
        osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>;

    py::class_<LocationTable>(m, "LocationTable")
        .def("set", &LocationTable::set, py::arg("id"), py::arg("loc"))
        .def("get", &LocationTable::get, py::arg("id"))
        .def("used_memory", &LocationTable::used_memory)
        .def("clear", &LocationTable::clear)
        .def ("__setitem__", &LocationTable::set)
        .def ("__getitem__", &LocationTable::get)
    ;

    m.def("create_map", [](const std::string& config_string) {
            const auto& map_factory = IndexFactory::instance();
            return map_factory.create_map(config_string);
        },
        py::arg("map_type"));

    m.def("map_types", []() {
        const auto& map_factory = IndexFactory::instance();

        auto l = py::list();
        for (auto const &e : map_factory.map_types())
            l.append(e);

        return l;
        });

    using IdSet = osmium::index::IdSetDense<osmium::unsigned_object_id_type>;

    py::class_<IdSet>(m, "IdSet")
        .def(py::init<>())
        .def("set", &IdSet::set)
        .def("unset", &IdSet::unset)
        .def("get", &IdSet::get)
        .def("empty", &IdSet::empty)
        .def("clear", &IdSet::clear)
        .def("__len__", &IdSet::size)
        .def("__contains__", &IdSet::get)
    ;
}