1 #ifndef OSMIUM_GEOM_WKB_HPP
2 #define OSMIUM_GEOM_WKB_HPP
62 inline void str_push(std::string& str, T data) {
63 size_t size = str.size();
64 str.resize(size +
sizeof(T));
65 std::copy_n(reinterpret_cast<char*>(&data),
sizeof(T), &str[size]);
68 inline std::string convert_to_hex(
const std::string& str) {
69 static const char* lookup_hex =
"0123456789ABCDEF";
73 out += lookup_hex[(c >> 4) & 0xf];
74 out += lookup_hex[c & 0xf];
80 class WKBFactoryImpl {
83 static constexpr uint32_t srid = 4326;
92 enum wkbGeometryType : uint32_t {
97 wkbMultiLineString = 5,
99 wkbGeometryCollection = 7,
108 enum class wkb_byte_order_type : uint8_t {
114 uint32_t m_points {0};
118 size_t m_linestring_size_offset = 0;
119 size_t m_polygons = 0;
121 size_t m_multipolygon_size_offset = 0;
122 size_t m_polygon_size_offset = 0;
123 size_t m_ring_size_offset = 0;
125 size_t header(std::string& str, wkbGeometryType
type,
bool add_length)
const {
126 #if __BYTE_ORDER == __LITTLE_ENDIAN
127 str_push(str, wkb_byte_order_type::NDR);
129 str_push(str, wkb_byte_order_type::XDR);
132 str_push(str, type | wkbSRID);
137 size_t offset = str.size();
139 str_push(str, static_cast<uint32_t>(0));
144 void set_size(
const size_t offset,
const size_t size) {
145 *
reinterpret_cast<uint32_t*
>(&m_data[offset]) = static_cast_with_assert<uint32_t>(size);
150 typedef std::string point_type;
151 typedef std::string linestring_type;
152 typedef std::string polygon_type;
153 typedef std::string multipolygon_type;
154 typedef std::string ring_type;
165 header(data, wkbPoint,
false);
166 str_push(data, xy.
x);
167 str_push(data, xy.
y);
170 return convert_to_hex(data);
178 void linestring_start() {
180 m_linestring_size_offset = header(m_data, wkbLineString,
true);
184 str_push(m_data, xy.
x);
185 str_push(m_data, xy.
y);
188 linestring_type linestring_finish(
size_t num_points) {
189 set_size(m_linestring_size_offset, num_points);
191 std::swap(data, m_data);
194 return convert_to_hex(data);
202 void multipolygon_start() {
205 m_multipolygon_size_offset = header(m_data, wkbMultiPolygon,
true);
208 void multipolygon_polygon_start() {
211 m_polygon_size_offset = header(m_data, wkbPolygon,
true);
214 void multipolygon_polygon_finish() {
215 set_size(m_polygon_size_offset, m_rings);
218 void multipolygon_outer_ring_start() {
221 m_ring_size_offset = m_data.size();
222 str_push(m_data, static_cast<uint32_t>(0));
225 void multipolygon_outer_ring_finish() {
226 set_size(m_ring_size_offset, m_points);
229 void multipolygon_inner_ring_start() {
232 m_ring_size_offset = m_data.size();
233 str_push(m_data, static_cast<uint32_t>(0));
236 void multipolygon_inner_ring_finish() {
237 set_size(m_ring_size_offset, m_points);
241 str_push(m_data, xy.
x);
242 str_push(m_data, xy.
y);
246 multipolygon_type multipolygon_finish() {
247 set_size(m_multipolygon_size_offset, m_polygons);
249 std::swap(data, m_data);
252 return convert_to_hex(data);
262 template <
class TProjection = IdentityProjection>
269 #endif // OSMIUM_GEOM_WKB_HPP
double y
Definition: coordinates.hpp:50
Definition: factory.hpp:146
type
Definition: entity_bits.hpp:60
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
Definition: coordinates.hpp:47
wkb_type
Definition: wkb.hpp:49
out_type
Definition: wkb.hpp:54
double x
Definition: coordinates.hpp:49