File: geometry-processor.cpp

package info (click to toggle)
osm2pgsql 0.96.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,304 kB
  • sloc: cpp: 11,462; python: 543; sh: 98; makefile: 17
file content (104 lines) | stat: -rw-r--r-- 2,851 bytes parent folder | download
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "geometry-processor.hpp"
#include "processor-line.hpp"
#include "processor-point.hpp"
#include "processor-polygon.hpp"
#include "middle.hpp"
#include "options.hpp"
#include "reprojection.hpp"

#include <boost/format.hpp>
#include <boost/optional.hpp>
#include <stdexcept>
#include <memory>

std::shared_ptr<geometry_processor> geometry_processor::create(const std::string &type,
                                                                 const options_t *options) {
    std::shared_ptr<geometry_processor> ptr;

    if (type == "point") {
        ptr = std::make_shared<processor_point>(options->projection);
    }
    else if (type == "line") {
        ptr = std::make_shared<processor_line>(options->projection);
    }
    else if (type == "polygon") {
        ptr = std::make_shared<processor_polygon>(options->projection);
    }
    else {
        throw std::runtime_error((boost::format("Unable to construct geometry processor "
                                                "because type `%1%' is not known.")
                                  % type).str());
    }

    return ptr;
}

geometry_processor::geometry_processor(int srid, const std::string &type, unsigned int interests)
    : m_srid(srid), m_type(type), m_interests(interests) {
}

geometry_processor::~geometry_processor() = default;

int geometry_processor::srid() const {
    return m_srid;
}

const std::string &geometry_processor::column_type() const {
    return m_type;
}

unsigned int geometry_processor::interests() const {
    return m_interests;
}

bool geometry_processor::interests(unsigned int interested) const {
    return (interested & m_interests) == interested;
}

geometry_processor::wkb_t
geometry_processor::process_node(osmium::Location const &,
                                 geom::osmium_builder_t *)
{
    return wkb_t();
}

geometry_processor::wkb_t
geometry_processor::process_way(osmium::Way const &, geom::osmium_builder_t *)
{
    return wkb_t();
}

geometry_processor::wkbs_t
geometry_processor::process_relation(osmium::Relation const &,
                                     osmium::memory::Buffer const &,
                                     geom::osmium_builder_t *)
{
    return wkbs_t();
}


relation_helper::relation_helper()
: data(1024, osmium::memory::Buffer::auto_grow::yes)
{}

size_t relation_helper::set(osmium::Relation const &rel, middle_t const *mid)
{
    // cleanup
    data.clear();
    roles.clear();

    // get the nodes and roles of the ways
    auto num_ways = mid->rel_way_members_get(rel, &roles, data);

    // mark the ends of each so whoever uses them will know where they end..
    superseded.resize(num_ways);

    return num_ways;
}

void relation_helper::add_way_locations(middle_t const *mid)
{
    for (auto &w : data.select<osmium::Way>()) {
        mid->nodes_get_list(&(w.nodes()));
    }
}