GeographicLib
1.21
|
Polygon Areas. More...
#include <GeographicLib/PolygonArea.hpp>
Public Member Functions | |
PolygonArea (const Geodesic &earth, bool polyline=false) throw () | |
void | Clear () throw () |
void | AddPoint (real lat, real lon) throw () |
unsigned | Compute (bool reverse, bool sign, real &perimeter, real &area) const throw () |
unsigned | TestCompute (real lat, real lon, bool reverse, bool sign, real &perimeter, real &area) const throw () |
Inspector functions | |
Math::real | MajorRadius () const throw () |
Math::real | Flattening () const throw () |
Polygon Areas.
This computes the area of a geodesic polygon using the method given Section 15 of
See also Section 6 of
This class lets you add vertices one at a time to the polygon. The area and perimeter are accumulated in 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.
Example of use:
// Example of using the GeographicLib::PolygonArea class // $Id: 103c4d2f060347fd499adc2e8487102c8b93d58f $ #include <iostream> #include <exception> #include <GeographicLib/PolygonArea.hpp> #include <GeographicLib/Geodesic.hpp> #include <GeographicLib/Constants.hpp> using namespace std; using namespace GeographicLib; int main() { try { Geodesic geod(Constants::WGS84_a(), Constants::WGS84_f()); // Alternatively: const Geodesic& geod = Geodesic::WGS84; PolygonArea poly(geod); poly.AddPoint( 52, 0); // London poly.AddPoint( 41,-74); // New York poly.AddPoint(-23,-43); // Rio de Janeiro poly.AddPoint(-26, 28); // Johannesburg double perimeter, area; unsigned n = poly.Compute(false, true, perimeter, area); cout << n << " " << perimeter << " " << area << "\n"; } catch (const exception& e) { cerr << "Caught exception: " << e.what() << "\n"; return 1; } return 0; }
Planimeter is a command-line utility providing access to the functionality of PolygonArea.
GeographicLib::PolygonArea::PolygonArea | ( | const Geodesic & | earth, |
bool | polyline = false |
||
) | throw () [inline] |
Constructor for PolygonArea.
[in] | earth | the Geodesic object to use for geodesic calculations. By default this uses the WGS84 ellipsoid. |
[in] | polyline | if true that treat the points as defining a polyline instead of a polygon (default = false). |
Definition at line 98 of file PolygonArea.hpp.
void GeographicLib::PolygonArea::Clear | ( | ) | throw () [inline] |
Clear PolygonArea, allowing a new polygon to be started.
Definition at line 110 of file PolygonArea.hpp.
Referenced by main().
void GeographicLib::PolygonArea::AddPoint | ( | real | lat, |
real | lon | ||
) | throw () |
Add a point to the polygon or polyline.
[in] | lat | the latitude of the point (degrees). |
[in] | lon | the latitude of the point (degrees). |
lat should be in the range [-90, 90] and lon should be in the range [-180, 360].
Definition at line 23 of file PolygonArea.cpp.
Referenced by main().
unsigned GeographicLib::PolygonArea::Compute | ( | bool | reverse, |
bool | sign, | ||
real & | perimeter, | ||
real & | area | ||
) | const throw () |
Return the results so far.
[in] | reverse | if true then clockwise (instead of counter-clockwise) traversal counts as a positive area. |
[in] | sign | if true then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth. |
[out] | perimeter | the perimeter of the polygon or length of the polyline (meters). |
[out] | area | the area of the polygon (meters^2); only set if polyline is false in the constructor. |
Definition at line 41 of file PolygonArea.cpp.
Referenced by main().
unsigned GeographicLib::PolygonArea::TestCompute | ( | real | lat, |
real | lon, | ||
bool | reverse, | ||
bool | sign, | ||
real & | perimeter, | ||
real & | area | ||
) | const throw () |
Return the results assuming a tentative final test point is added; however, the data for the test point is not saved. This lets you report a running result for the perimeter and area as the user moves the mouse cursor. Ordinary floating point arithmetic is used to accumulate the data for the test point; thus the area and perimeter returned are less accurate than if AddPoint and Compute are used.
[in] | lat | the latitude of the test point (degrees). |
[in] | lon | the longitude of the test point (degrees). |
[in] | reverse | if true then clockwise (instead of counter-clockwise) traversal counts as a positive area. |
[in] | sign | if true then return a signed result for the area if the polygon is traversed in the "wrong" direction instead of returning the area for the rest of the earth. |
[out] | perimeter | the approximate perimeter of the polygon or length of the polyline (meters). |
[out] | area | the approximate area of the polygon (meters^2); only set if polyline is false in the constructor. |
lat should be in the range [-90, 90] and lon should be in the range [-180, 360].
Definition at line 82 of file PolygonArea.cpp.
Math::real GeographicLib::PolygonArea::MajorRadius | ( | ) | const throw () [inline] |
Definition at line 181 of file PolygonArea.hpp.
Math::real GeographicLib::PolygonArea::Flattening | ( | ) | const throw () [inline] |
Definition at line 187 of file PolygonArea.hpp.