File: id_filter.cc

package info (click to toggle)
pyosmium 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,584 kB
  • sloc: python: 4,400; cpp: 2,504; makefile: 20
file content (55 lines) | stat: -rw-r--r-- 1,149 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
/* 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/id_set.hpp>

#include "base_filter.h"

namespace py = pybind11;

namespace {

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

class IdFilter : public pyosmium::BaseFilter
{
public:
    IdFilter(py::iterable const &ids)
    {
        for (auto &i: py::iter(ids)) {
            m_ids.set(i.cast<osmium::unsigned_object_id_type>());
        }
    }

    bool filter(osmium::OSMObject const *o) override
    {
        return !m_ids.get(o->id());
    }

    bool filter_changeset(pyosmium::PyOSMChangeset &o) override
    {
        return !m_ids.get(o.get()->id());
    }

private:
    IdSet m_ids;
};

} // namespace

namespace pyosmium {

void init_id_filter(pybind11::module &m)
{
    py::class_<IdFilter, pyosmium::BaseFilter, pyosmium::BaseHandler>(m, "IdFilter")
        .def(py::init<py::iterable const &>())
    ;
}

} // namespace