Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.
PrevUpHomeNext

unique

Calculates the minimal set of a geometry.

Description

The free function unique calculates the minimal set (where duplicate consecutive points are removed) of a geometry.

Synopsis

template<typename Geometry>
void unique(Geometry & geometry)

Parameters

Type

Concept

Name

Description

Geometry &

Any type fulfilling a Geometry Concept

geometry

A model of the specified concept which will be made unique

Header

Either

#include <boost/geometry/geometry.hpp>

Or

#include <boost/geometry/algorithms/unique.hpp>

Behavior

Case

Behavior

Point

Nothing happens, geometry is unchanged

Segment

Nothing happens, geometry is unchanged

Rectangle

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)

[Tip] Tip

Conforms to std::unique functionality. It is not defined within OGC or ISO

Complexity

Linear

Example

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))

PrevUpHomeNext