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 c6ae40a822.
PrevUpHomeNext
line_interpolate

Returns one or more points interpolated along a LineString.

Synopsis

template<typename Geometry, typename Distance, typename Pointlike>
void line_interpolate(Geometry const & geometry, Distance const & max_distance, Pointlike & pointlike)

Parameters

Type

Concept

Name

Description

Geometry const &

Any type fulfilling a LineString concept

geometry

Input geometry

Distance const &

A numerical distance measure

max_distance

Distance threshold (in units depending on coordinate system) representing the spacing between the points

Pointlike &

Any type fulfilling Point or Multipoint concept

pointlike

Output: either a Point (exactly one point will be constructed) or a MultiPoint (depending on the max_distance one or more points will be constructed)

Header

Either

#include <boost/geometry.hpp>

Or

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

Conformance

The function line_interpolate_point is not defined by OGC.

[Note] Note

PostGIS contains an algorithm ST_LineInterpolatePoints with similar functionality. See the PostGIS documentation.

Behavior

The algorithm iterates among segments of the linestring and computes interpolation points if needed.

Example

Shows how to interpolate points on a linestring

#include <iostream>

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

using namespace boost::geometry;

int main()
{
    using point_type = boost::geometry::model::d2::point_xy<double>;
    using segment_type = model::segment<point_type>;
    using linestring_type = model::linestring<point_type>;
    using multipoint_type = model::multi_point<point_type>;

    segment_type const s { {0, 0}, {1, 1} };
    linestring_type const l { {0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2} };
    point_type p;
    multipoint_type mp;

    std::cout << "point interpolation" << std::endl;

    line_interpolate(s, std::sqrt(2)/4, p);
    std::cout << "on segment : " << wkt(p) << std::endl;

    line_interpolate(l, 1.4, p);
    std::cout << "on linestring : " << wkt(p) << std::endl << std::endl;

    std::cout << "multipoint interpolation" << std::endl;

    line_interpolate(s, std::sqrt(2)/4, mp);
    std::cout << "on segment : " << wkt(mp) << std::endl;

    mp=multipoint_type();
    line_interpolate(l, 1.4, mp);
    std::cout << "on linestring : " << wkt(mp) << std::endl;

    return 0;
}

Output:

point interpolation
on segment : POINT(0.25 0.25)
on linestring : POINT(1 0.4)

multipoint interpolation
on segment : MULTIPOINT((0.25 0.25),(0.5 0.5),(0.75 0.75),(1 1))
on linestring : MULTIPOINT((1 0.4),(0.2 1))
See also

PrevUpHomeNext