GeographicLib: GeographicLib::PolygonAreaT< GeodType > Class Template Reference (original) (raw)

template
class GeographicLib::PolygonAreaT< GeodType >

Polygon areas.

This computes the area of a polygon whose edges are geodesics using the method given in Section 6 of

Arbitrarily complex polygons are allowed. In the case self-intersecting of polygons the area is accumulated "algebraically", e.g., the areas of the 2 loops in a figure-8 polygon will partially cancel.

This class lets you add vertices and edges one at a time to the polygon. The sequence must start with a vertex and thereafter vertices and edges can be added in any order. Any vertex after the first creates a new edge which is the shortest geodesic from the previous vertex. In some cases there may be two or many such shortest geodesics and the area is then not uniquely defined. In this case, either add an intermediate vertex or add the edge as an edge (by defining its direction and length).

The area and perimeter are accumulated at two times the standard floating point precision to guard against the loss of accuracy with many-sided polygons. At any point you can ask for the perimeter and area so far. There's an option to treat the points as defining a polyline instead of a polygon; in that case, only the perimeter is computed.

This is a templated class to allow it to be used with Geodesic, GeodesicExact, and Rhumb. GeographicLib::PolygonArea, GeographicLib::PolygonAreaExact, and GeographicLib::PolygonAreaRhumb are typedefs for these cases.

For GeographicLib::PolygonArea (edges defined by Geodesic), an upper bound on the error is about 0.1 m2 per vertex. However this is a wildly pessimistic estimate in most cases. A more realistic estimate of the error is given by a test involving 107 approximately regular polygons on the WGS84 ellipsoid. The centers and the orientations of the polygons were uniformly distributed, the number of vertices was log-uniformly distributed in [3, 300], and the center to vertex distance log-uniformly distributed in [0.1 m, 9000 km].

Using double precision (the standard precision for GeographicLib), the maximum error in the perimeter was 200 nm, and the maximum error in the area was

0.0013 m^2 for perimeter < 10 km
0.0070 m^2 for perimeter < 100 km
0.070 m^2 for perimeter < 1000 km
0.11 m^2 for all perimeters

The errors are given in terms of the perimeter, because it is expected that the errors depend mainly on the number of edges and the edge lengths.

Using long doubles (GEOGRPAHICLIB_PRECISION = 3), the maximum error in the perimeter was 200 pm, and the maximum error in the area was

0.7 mm^2 for perim < 10 km
3.2 mm^2 for perimeter < 100 km
21 mm^2 for perimeter < 1000 km
45 mm^2 for all perimeters

Template Parameters

GeodType the geodesic class to use.

Example of use:

#include

#include

using namespace std;

try {

Geodesic geod(Constants::WGS84_a(), Constants::WGS84_f());

poly.AddPoint( 52, 0);

poly.AddPoint( 41,-74);

poly.AddPoint(-23,-43);

poly.AddPoint(-26, 28);

double perimeter, area;

unsigned n = poly.Compute(false, true, perimeter, area);

cout << n << " " << perimeter << " " << area << "\n";

poly1.AddPoint(0,0);

poly1.AddEdge(90,1000);

poly1.AddEdge(0,1000);

poly1.AddEdge(-90,1000);

n = poly1.Compute(false, true, perimeter, area);

cout << n << " " << perimeter << " " << area << "\n";

}

catch (const exception& e) {

cerr << "Caught exception: " << e.what() << "\n";

return 1;

}

}

int main(int argc, const char *const argv[])

Header for GeographicLib::Constants class.

Header for GeographicLib::Geodesic class.

Header for GeographicLib::PolygonAreaT class.

Namespace for GeographicLib.

Planimeter is a command-line utility providing access to the functionality of PolygonAreaT.

Definition at line 97 of file PolygonArea.hpp.