forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflex-table-column.hpp
More file actions
171 lines (131 loc) · 4.03 KB
/
flex-table-column.hpp
File metadata and controls
171 lines (131 loc) · 4.03 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#ifndef OSM2PGSQL_FLEX_TABLE_COLUMN_HPP
#define OSM2PGSQL_FLEX_TABLE_COLUMN_HPP
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2026 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include "expire-config.hpp"
#include "expire-tiles.hpp"
#include "geom.hpp"
#include "projection.hpp"
#include <cassert>
#include <cstdint>
#include <string>
#include <vector>
enum class table_column_type : uint8_t
{
text,
boolean,
int2,
int4,
int8,
real,
hstore,
json,
jsonb,
direction,
geometry,
point,
linestring,
polygon,
multipoint,
multilinestring,
multipolygon,
geometrycollection,
id_type,
id_num
};
/**
* A column in a flex_table_t.
*/
class flex_table_column_t
{
public:
flex_table_column_t(std::string name, std::string const &type,
std::string sql_type);
std::string const &name() const noexcept { return m_name; }
table_column_type type() const noexcept { return m_type; }
bool is_point_column() const noexcept
{
return (m_type == table_column_type::point) ||
(m_type == table_column_type::multipoint);
}
bool is_linestring_column() const noexcept
{
return (m_type == table_column_type::linestring) ||
(m_type == table_column_type::multilinestring);
}
bool is_polygon_column() const noexcept
{
return (m_type == table_column_type::geometry) ||
(m_type == table_column_type::polygon) ||
(m_type == table_column_type::multipolygon);
}
bool is_geometry_column() const noexcept
{
return (m_type >= table_column_type::geometry) &&
(m_type <= table_column_type::geometrycollection);
}
/**
* Do we need an ST_IsValid() check in the database for this geometry
* column? If the SRID is 4326 the geometry validity is already assured
* by libosmium, so we don't need it. And Point geometries are always
* valid.
* No checks are needed for create_only columns, because they don't
* contain anything.
*/
bool needs_isvalid() const noexcept
{
assert(is_geometry_column());
return !m_create_only && m_srid != PROJ_LATLONG &&
m_type != table_column_type::point;
}
std::string const &type_name() const noexcept { return m_type_name; }
bool not_null() const noexcept { return m_not_null; }
bool create_only() const noexcept { return m_create_only; }
void set_not_null(bool value = true) noexcept { m_not_null = value; }
void set_create_only(bool value = true) noexcept { m_create_only = value; }
void set_projection(char const *projection);
std::string sql_type_name() const;
std::string sql_modifiers() const;
std::string sql_create() const;
int srid() const noexcept { return m_srid; }
void add_expire(expire_config_t const &config);
bool has_expire() const noexcept { return !m_expires.empty(); }
std::vector<expire_config_t> const &expire_configs() const noexcept
{
return m_expires;
}
void do_expire(geom::geometry_t const &geom,
std::vector<expire_tiles_t> *expire) const;
private:
std::vector<expire_config_t> m_expires;
/// The name of the database table column.
std::string m_name;
/**
* The type name of the column.
*/
std::string m_type_name;
/**
* The SQL type of the database table column. If this is not set, use
* one generated from the m_type.
*/
std::string m_sql_type;
/**
* The type of column.
*/
table_column_type m_type;
/**
* For geometry columns only: The projection SRID. Default is web mercator.
*/
int m_srid = PROJ_SPHERE_MERC;
/// NOT NULL constraint
bool m_not_null = false;
/// Column will be created but not filled by osm2pgsql.
bool m_create_only = false;
};
#endif // OSM2PGSQL_FLEX_TABLE_COLUMN_HPP