Skip to content

Commit 9edbd8b

Browse files
committed
Add stand-alone function for creating EWKB point geometry
1 parent 1f5b4a9 commit 9edbd8b

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/wkb.hpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ inline std::size_t write_header_with_length(std::string *str,
8181
return offset;
8282
}
8383

84+
/// Create EWKB Point geometry.
85+
inline std::string create_point(double x, double y, uint32_t srid = 4326)
86+
{
87+
std::string data;
88+
data.reserve(25); // Point geometries are always 25 bytes
89+
90+
write_header(&data, wkb_point, srid);
91+
str_push(&data, x);
92+
str_push(&data, y);
93+
94+
return data;
95+
}
96+
8497
/**
8598
* Writer for EWKB data suitable for postgres.
8699
*
@@ -124,12 +137,7 @@ class writer_t
124137

125138
std::string make_point(osmium::geom::Coordinates const &xy) const
126139
{
127-
std::string data;
128-
write_header(&data, wkb_point, m_srid);
129-
str_push(&data, xy.x);
130-
str_push(&data, xy.y);
131-
132-
return data;
140+
return create_point(xy.x, xy.y, m_srid);
133141
}
134142

135143
/* LineString */

0 commit comments

Comments
 (0)