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
simplify

Simplify a geometry.

Synopsis

template<typename Geometry, typename Distance>
void simplify(Geometry const & geometry, Geometry & out, Distance const & max_distance)

Parameters

Type

Concept

Name

Description

Geometry const &

Any type fulfilling a Geometry Concept

geometry

input geometry, to be simplified

Geometry &

Any type fulfilling a Geometry Concept

out

output geometry, simplified version of the input geometry

Distance const &

numerical type (int, double, ttmath, ...)

max_distance

distance (in units of input coordinates) of a vertex to other segments to be removed

Header

Either

#include <boost/geometry/geometry.hpp>

Or

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

Conformance

The function simplify is not defined by OGC.

[Note] Note

PostGIS contains an algorithm with the same name and the same functionality. See the PostGIS documentation.

[Note] Note

SQL Server contains an algorithm Reduce() with the same functionality. See the MSDN documentation.

Behavior

Simplification is done using Douglas-Peucker (if the default strategy is used).

[Note] Note

Geometries might become invalid by using simplify. The simplification process might create self-intersections.

Examples

Example showing how to simplify a linestring

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

1
#include <boost/assign.hpp>

using namespace boost::assign;


int main()
{
    typedef boost::geometry::model::d2::point_xy<double> xy;

    boost::geometry::model::linestring<xy> line;
    line += xy(1.1, 1.1), xy(2.5, 2.1), xy(3.1, 3.1), xy(4.9, 1.1), xy(3.1, 1.9); 2

    // Simplify it, using distance of 0.5 units
    boost::geometry::model::linestring<xy> simplified;
    boost::geometry::simplify(line, simplified, 0.5);
    std::cout
        << "  original: " << boost::geometry::dsv(line) << std::endl
        << "simplified: " << boost::geometry::dsv(simplified) << std::endl;


    return 0;
}

1

For this example we use Boost.Assign to add points

2

With Boost.Assign

Output:

original: ((1.1, 1.1), (2.5, 2.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
simplified: ((1.1, 1.1), (3.1, 3.1), (4.9, 1.1), (3.1, 1.9))
Image(s)

svg_simplify_country


PrevUpHomeNext