8 #include <simo/geom/detail/geometry.hpp> 9 #include <simo/geom/detail/bounds.hpp> 16 template <
typename T,
typename AllocatorType = std::allocator<T>>
20 using base_type = std::vector<T, AllocatorType>;
22 using point_type =
typename T::point_type;
23 using point_iterator =
typename std::vector<T>::iterator;
24 using point_const_iterator =
typename std::vector<T>::const_iterator;
26 using coord_type =
typename T::coord_type;
27 using coord_iterator =
typename std::vector<coord_type>::iterator;
28 using coord_const_iterator =
typename std::vector<coord_type>::const_iterator;
34 : base_type(init.begin(), init.end()) {}
39 size_t n = this->
ndim();
40 this->reserve(std::distance(first, last));
41 for (
auto it = first; it != last; it += n)
43 this->emplace_back(it, it + n);
50 size_t n = this->
ndim();
51 this->reserve(std::distance(first, last));
52 for (
auto it = first; it != last; it += n)
54 this->emplace_back(it, it + n);
59 : base_type(first, last)
64 : base_type(first, last)
79 if (lhs.size() != rhs.size())
83 for (
size_t i = 0; i < lhs.size(); ++i)
105 std::vector<std::tuple<double, double>> xy()
const 107 std::vector<std::tuple<double, double>> res;
108 res.reserve(this->size());
109 for (
const auto& p : *
this)
111 res.emplace_back(p.x, p.y);
118 static basic_multipoint<T> from_polyline(
const std::string& polyline, std::int32_t precision = 5)
122 auto coords = polyline::decode(polyline, precision);
123 return {coords.begin(), coords.end()};
126 std::string polyline(std::int32_t precision = 5)
const 131 res.reserve(this->size() * 6);
134 for (
const auto& p : *
this)
136 res += polyline::encode(p.lat - prev_lat, precision);
137 res += polyline::encode(p.lng - prev_lng, precision);
149 geometry_type geom_type_() const noexcept
153 return geometry_type::MULTIPOINTZ;
157 return geometry_type::MULTIPOINTM;
161 return geometry_type::MULTIPOINTZM;
163 return geometry_type::MULTIPOINT;
167 bool is_closed_() const noexcept
173 return *
this[0] == *
this[this->size() - 1];
177 void throw_for_invalid_()
const 186 for (
const auto& p : *
this)
200 auto j = nlohmann::json::parse(json);
201 auto geom_type = j.at(
"type").get<std::string>();
206 const auto& coords = j.at(
"coordinates").get<std::vector<std::vector<double>>>();
207 std::vector<point_type> res;
208 res.reserve(coords.size());
209 std::for_each(std::begin(coords), std::end(coords), [&](
const std::vector<double>& coord) {
210 res.emplace_back(coord.begin(), coord.end());
214 catch (
const nlohmann::json::exception& e)
225 std::string json_(std::int32_t precision = -1)
const 227 std::stringstream ss;
230 ss << std::setprecision(precision);
232 ss <<
"{\"type\":\"MultiPoint\",\"coordinates\":[";
234 for (
const auto& p : *
this)
241 for (
size_t j = 0; j < p.size(); ++j)
262 auto result = reader.
read(wkt);
263 const auto& data = result.
data;
264 if (not utils::is_multipoint(data.geom_type))
272 std::string wkt_(std::int32_t precision = -1)
const 274 std::stringstream ss;
277 ss << std::setprecision(precision);
290 for (
const auto& p : *
this)
297 for (
size_t j = 0; j < p.size(); ++j)
317 template <
typename T>
325 template <
typename T>
333 template <
typename T>
341 template <
typename T>
geometry_type geom_type() const noexcept
Returns the geometry type.
Base class for all geometries.
wkt_data data
the parser result data
wkt_result read(const std::string &wkt)
parse the given wkt string
Exception thrown when a geometry error is found.
basic_multipoint(coord_const_iterator first, coord_const_iterator last)
friend bool operator!=(const basic_multipoint< T > &lhs, const basic_multipoint< T > &rhs)
const char * what() const noexceptoverride
Returns the exception reason.
Represents an axis-aligned bounding box.
friend bool operator==(const basic_multipoint< T > &lhs, const basic_multipoint< T > &rhs)
bool has_z() const noexcept
Whether the geometry has the z-coordinate.
basic_multipoint(coord_iterator first, coord_iterator last)
bounds_t & extend(double x, double y)
Extends the bounds to contain the given point.
Exception thrown when an error has been found while parsing.
std::string json(std::int32_t precision=-1) const
Dumps the geojson representation of the geometry.
bool has_m() const noexcept
Whether the geometry has the m-coordinate (measurement coordinate)
std::string wkt(std::int32_t precision=-1) const
Dumps the wkt representation of the geometry.
size_t ndim() const noexcept
Returns the number of dimensions of the geometry.