| Home | Libraries | People | FAQ | More

##### densify (with strategy)

Densify a geometry using a specified strategy.

###### Synopsis

    template<typename Geometry, typename Distance, typename Strategy>
    void densify(Geometry const & geometry, Geometry & out, Distance const & max_distance,
                 Strategy const & strategy)

###### Parameters

Type | Concept | Name | Description
--- | --- | --- | ---
Geometry const & | Any type fulfilling a Geometry Concept | geometry | Input geometry, to be densified
Geometry & | Any type fulfilling a Geometry Concept | out | Output geometry, densified version of the input geometry
Distance const & | A numerical distance measure | max_distance | Distance threshold (in units depending on strategy)
Strategy const & | A type fulfilling a DensifyStrategy concept | strategy | Densify strategy to be used for densification

###### Header

Either

`#include <boost/geometry.hpp>`

Or

`#include <boost/geometry/algorithms/densify.hpp>`

###### Conformance

The function densify is not defined by OGC.

| Note
PostGIS contains an algorithm ST_Segmentize with the same functionality. See the PostGIS documentation.

###### Behavior

The algorithm divides segments of a geometry if they are longer than passed distance into smaller segments.

| Note
The units of the distance depends on strategy. In order to change the default behavior a user has to create a strategy and pass it explicitly into the algorithm.

###### Available Strategies

- Cartesian
- Spherical
- Geographic

###### Example

Shows how to densify a linestring in geographic coordinate system

    #include <iostream>

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

    int main()
    {
        namespace bg = boost::geometry;
        typedef bg::model::point<double, 2, bg::cs::geographic<bg::degree> > point_type;
        typedef bg::model::linestring<point_type> linestring_type;

        linestring_type ls;
        bg::read_wkt("LINESTRING(0 0,1 1)", ls);

        linestring_type res;

        bg::srs::spheroid<double> spheroid(6378137.0, 6356752.3142451793);
        bg::strategy::densify::geographic<> strategy(spheroid);

        boost::geometry::densify(ls, res, 50000.0, strategy);

        std::cout << "densified: " << boost::geometry::wkt(res) << std::endl;

        return 0;
    }

Output:

    densified: LINESTRING(0 0,0.249972 0.250011,0.499954 0.500017,0.749954 0.750013,1 1)

###### See also

- line_interpolate