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

strategy::area::huiller

Area calculation by spherical excess / Huiller's formula.

Synopsis

template<typename PointOfSegment, typename CalculationType>
class strategy::area::huiller
{
  // ...
};

Template parameter(s)

Parameter

Default

Description

typename PointOfSegment

point type of segments of rings/polygons

typename CalculationType

void

numeric type for calculation (e.g. high precision); if void then it is extracted automatically from the coordinate type and (if necessary) promoted to floating point

Constructor(s)

Function

Description

Parameters

huiller(calculation_type radius = 1.0)

calculation_type: radius:

Member Function(s)

Function

Description

Parameters

Returns

void apply(PointOfSegment const & p1, PointOfSegment const & p2, excess_sum & state)

PointOfSegment const &: p1:

PointOfSegment const &: p2:

excess_sum &: state:

return_type result(excess_sum const & state)

excess_sum const &: state:

Header

#include <boost/geometry/strategies/spherical/area_huiller.hpp>

Example

Calculate the area of a polygon

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>

namespace bg = boost::geometry; 1

int main()
{
    // Calculate the area of a cartesian polygon
    bg::model::polygon<bg::model::d2::point_xy<double> > poly;
    bg::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", poly);
    double area = bg::area(poly);
    std::cout << "Area: " << area << std::endl;

    // Calculate the area of a spherical polygon (for latitude: 0 at equator)
    bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
    bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly);
    area = bg::area(sph_poly);
    std::cout << "Area: " << area << std::endl;

    return 0;
}

1

Convenient namespace alias

Output:

Area: 16
Area: 0.339837
See also

area (with strategy)


PrevUpHomeNext