...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Calculates the perimeter of a geometry.
The function perimeter returns the perimeter of a geometry, using the default distance-calculation-strategy
template<typename Geometry> default_length_result<Geometry>::type perimeter(Geometry const & geometry)
Type |
Concept |
Name |
Description |
---|---|---|---|
Geometry const & |
Any type fulfilling a Geometry Concept |
geometry |
A model of the specified concept |
The calculated perimeter
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/algorithms/perimeter.hpp>
The function perimeter is not defined by OGC.
Note | |
---|---|
PostGIS contains an algorithm with the same name and the same functionality. See the PostGIS documentation. |
Case |
Behavior |
---|---|
pointlike (e.g. point) |
Returns zero |
linear (e.g. linestring) |
Returns zero |
areal (e.g. polygon) |
Returns the perimeter |
Linear
Calculate the perimeter of a polygon
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> namespace bg = boost::geometry; int main() { // Calculate the perimeter of a cartesian polygon bg::model::polygon<bg::model::d2::point_xy<double> > poly; bg::read_wkt("POLYGON((0 0,3 4,5 -5,-2 -4, 0 0))", poly); double perimeter = bg::perimeter(poly); std::cout << "Perimeter: " << perimeter << std::endl; return 0; }
Output:
Perimeter: 25.7627