...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Calculates the minimal set of a geometry.
The free function unique calculates the minimal set (where duplicate consecutive points are removed) of a geometry.
template<typename Geometry> void unique(Geometry & geometry)
Type |
Concept |
Name |
Description |
---|---|---|---|
Geometry & |
Any type fulfilling a Geometry Concept |
geometry |
A model of the specified concept which will be made unique |
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/algorithms/unique.hpp>
The function unique is not defined by OGC.
The function unique conforms to the std::unique function of the C++ std-library.
Case |
Behavior |
---|---|
Point |
Nothing happens, geometry is unchanged |
Segment |
Nothing happens, geometry is unchanged |
Box |
Nothing happens, geometry is unchanged |
Linestring |
Removes all consecutive duplicate points |
Ring |
Removes all consecutive duplicate points |
Polygon |
Removes all consecutive duplicate points in all rings |
Multi Point |
Nothing happens, geometry is unchanged. Even if two equal points happen to be stored consecutively, they are kept |
Multi Linestring |
Removes all consecutive duplicate points in all contained linestrings |
Multi Polygon |
Removes all consecutive duplicate points in all contained polygons (all rings) |
Linear
Shows how to make a so-called minimal set of a polygon by removing duplicate points
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/polygon.hpp> #include <boost/geometry/geometries/adapted/boost_tuple.hpp> BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) int main() { boost::geometry::model::polygon<boost::tuple<double, double>> poly; boost::geometry::read_wkt("POLYGON((0 0,0 0,0 5,5 5,5 5,5 5,5 0,5 0,0 0,0 0,0 0,0 0))", poly); boost::geometry::unique(poly); std::cout << boost::geometry::wkt(poly) << std::endl; return 0; }
Output:
POLYGON((0 0,0 5,5 5,5 0,0 0))