| Home | Libraries | People | FAQ | More

##### area (with strategy)

Calculates the area of a geometry using the specified strategy.

###### Description

The free function area calculates the area of a geometry using the specified strategy. Reasons to specify a strategy include: use another coordinate system for calculations; construct the strategy beforehand (e.g. with the radius of the Earth); select a strategy when there are more than one available for a calculation.

###### Synopsis

    template<typename Geometry, typename Strategy>
    Strategy::return_type area(Geometry const & geometry, Strategy const & strategy)

###### Parameters

Type | Concept | Name | Description
--- | --- | --- | ---
Geometry const & | Any type fulfilling a Geometry Concept | geometry | A model of the specified concept
Strategy const & | Any type fulfilling a Area Strategy Concept | strategy | The strategy which will be used for area calculations

###### Returns

The calculated area

###### Header

Either

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

Or

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

###### Behavior

Case | Behavior
--- | ---
pointlike (e.g. point) | Returns 0
linear (e.g. linestring) | Returns 0
areal (e.g. polygon) | Returns the area
Cartesian | Returns the area in the same units as the input coordinates
Spherical | Returns the area on a unit sphere (or another sphere, if specified as such in the constructor of the strategy)
Reversed polygon (coordinates not according their orientiation) | Returns the negative area

###### Supported geometries

Geometry | Status
--- | ---
Point |
Segment |
Box |
Linestring |
Ring |
Polygon |
MultiPoint |
MultiLinestring |
MultiPolygon |

###### Complexity

Linear

###### 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;

    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;
    }

| Convenient namespace alias

Output:

    Area: 16
    Area: 0.339837

###### Available Strategies

- Surveyor (cartesian)
- Huiller (spherical)