...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
template<typename Geometry, typename Distance> void densify(Geometry const & geometry, Geometry & out, Distance const & max_distance)
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 coordinate system) |
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/algorithms/densify.hpp>
The function densify is not defined by OGC.
Note | |
---|---|
PostGIS contains an algorithm ST_Segmentize with the same functionality. See the PostGIS documentation. |
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. |
Shows how to densify a polygon
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> int main() { typedef boost::geometry::model::d2::point_xy<double> point_type; typedef boost::geometry::model::polygon<point_type> polygon_type; polygon_type poly; boost::geometry::read_wkt( "POLYGON((0 0,0 10,10 10,10 0,0 0),(1 1,4 1,4 4,1 4,1 1))", poly); polygon_type res; boost::geometry::densify(poly, res, 6.0); std::cout << "densified: " << boost::geometry::wkt(res) << std::endl; return 0; }
Output:
densified: POLYGON((0 0,0 5,0 10,5 10,10 10,10 5,10 0,5 0,0 0),(1 1,4 1,4 4,1 4,1 1))