9 #include <simo/geom/detail/geometry.hpp> 10 #include <simo/geom/detail/bounds.hpp> 17 template <
typename T,
typename AllocatorType = std::allocator<T>>
19 :
public std::vector<T, AllocatorType>,
23 using base_type = std::vector<T, AllocatorType>;
24 using point_type =
typename T::point_type;
25 using point_iterator =
typename std::vector<T>::iterator;
26 using point_const_iterator =
typename std::vector<T>::const_iterator;
27 using coord_type =
typename T::coord_type;
28 using coord_iterator =
typename std::vector<coord_type>::iterator;
29 using coord_const_iterator =
typename std::vector<coord_type>::const_iterator;
35 : base_type(first, last)
40 : base_type(first, last)
45 : base_type(init.begin(), init.end()) {}
47 template <
typename CoordIterator,
typename OffsetIterator>
48 basic_multilinestring(CoordIterator coord_first, CoordIterator coord_last, OffsetIterator offset_first, OffsetIterator offset_last)
50 if (std::distance(coord_first, coord_last) > 0)
52 auto n = this->
ndim();
53 this->reserve((coord_last - coord_first) / n);
55 for (
auto it = offset_first; it != offset_last; ++it)
58 this->emplace_back(coord_first + lo, coord_first + hi);
68 if (lhs.size() != rhs.size())
72 for (
size_t i = 0; i < lhs.size(); ++i)
84 return not operator==(lhs, rhs);
87 std::vector<std::tuple<double, double>> xy()
const 89 std::vector<std::tuple<double, double>> res;
90 res.reserve(this->size());
91 for (
const auto& p : *
this)
93 res.emplace_back(p.x, p.y);
103 geometry_type geom_type_() const noexcept
107 return geometry_type::MULTILINESTRINGZ;
111 return geometry_type::MULTILINESTRINGM;
115 return geometry_type::MULTILINESTRINGZM;
117 return geometry_type::MULTILINESTRING;
121 bool is_closed_() const noexcept
127 return *
this[0] == *
this[this->size() - 1];
131 void throw_for_invalid_()
const 133 for (
const auto& ls : *
this)
135 ls.throw_for_invalid();
143 for (
const auto& p : *
this)
157 auto j = nlohmann::json::parse(json);
158 auto geom_type = j.at(
"type").get<std::string>();
163 const auto& linestrings = j.at(
"coordinates");
165 res.reserve(linestrings.size());
166 std::vector<point_type> points;
171 const auto& coords =
linestring.get<std::vector<std::vector<double>>>();
172 points.reserve(coords.size());
173 std::for_each(std::begin(coords), std::end(coords),
174 [&points](
const std::vector<double>& coord) {
175 points.emplace_back(coord.begin(), coord.end());
177 res.emplace_back(points.begin(), points.end());
183 catch (
const nlohmann::json::exception& e)
194 std::string json_(std::int32_t precision = -1)
const 196 std::stringstream ss;
199 ss << std::setprecision(precision);
201 ss <<
"{\"type\":\"MultiLineString\",\"coordinates\":[";
203 for (
const auto& ls : *
this)
210 for (
size_t j = 0; j < ls.size(); ++j)
217 const auto& p = ls[j];
218 for (
size_t k = 0; k < p.size(); ++k)
242 auto result = reader.
read(wkt);
243 const auto& data = result.
data;
244 if (not utils::is_multilinestring(data.geom_type))
249 result.data.offsets.begin(), result.data.offsets.end());
253 std::string wkt_(std::int32_t precision = -1)
const 255 std::stringstream ss;
258 ss << std::setprecision(precision);
260 ss <<
"MULTILINESTRING";
271 for (
const auto& ls : *
this)
278 for (
size_t j = 0; j < ls.size(); ++j)
284 const auto& p = ls[j];
285 for (
size_t k = 0; k < p.size(); ++k)
306 template <
typename T>
314 template <
typename T>
322 template <
typename T>
330 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.
const char * what() const noexceptoverride
Returns the exception reason.
Represents an axis-aligned bounding box.
bool has_z() const noexcept
Whether the geometry has the z-coordinate.
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.