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

This is the documentation for a snapshot of the develop branch, built from commit 7a526fa2b7.
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.hpp>

Or

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

Conformance

The function unique is not defined by OGC.

The function unique conforms to the std::unique function of the C++ std-library.

Behavior

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)

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