geodesic

package module
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 1 Imported by: 7

README

geodesic

GoDoc

geodesic is a Go package providing operations for performing accurate measurements of Earth. Includes a Go port of the geodesic routines from GeographicLib along with general-purpose spherical algorithms.

Features

  • Precise distance calculations (5-15 nanometer)
  • Calculate the area and perimeter of a polygon
  • Get the length of a polyline
  • Direct and Inverse solutions
  • Optional spherical formulas for efficency, such as Haversine.

Installing

To start using geodesic, install Go and run go get:

$ go get -u github.com/tidwall/geodesic

This will retrieve the library.

Using

All operations are performed on an Ellipsoid object.

To create a custom ellipsoid:

  • geodesic.NewEllipsoid: For highly accurate geodesic routines.
  • geodesic.NewSpherical: For faster spherical routines such as Haversine.
// The first argument is the radius and the second is the flattening.
myEllipsoid := geodesic.NewEllipsoid(6378137.0, 1.0/298.257223563)

Or, you can simply use the built-in geodesic.WGS84 non-spherical ellipsoid, which conforms to the WGS84 standard.

// The argument is the radius.
mySphere := geodesic.NewSpherical(6378137.0)

Or, you can use the geodesic.Globe spherical ellipsoid, which represents Earth as a terrestrial globe.

Examples

Calculate distance between two points.

var dist float64
geodesic.WGS84.Inverse(33.4911, -112.4223, 32.1189, -113.1123, &dist, nil, nil)
fmt.Printf("%f meters\n", dist)
// output: 
// 165330.214571 meters

Calculate initial azimuth from point A to point B.

var azi float64
geodesic.WGS84.Inverse(33.4911, -112.4223, 32.1189, -113.1123, nil, &azi, nil)
fmt.Printf("%f degrees\n", azi)
// output:
// -156.803310 degrees

Calculate final azimuth from point A to point B.

var azi float64
geodesic.WGS84.Inverse(33.4911, -112.4223, 32.1189, -113.1123, nil, nil, &azi)
fmt.Printf("%f degrees\n", azi)
// output:
// -157.177169 degrees

Calculate distance and azimuths at the same time.

var dist, azi1, azi2 float64
geodesic.WGS84.Inverse(33.4911, -112.4223, 32.1189, -113.1123, &dist, &azi1, &azi2)
fmt.Printf("%f meters, %f degrees, %f degrees\n", dist,azi1,azi2)
// output:
// 165330.214571 meters, -156.803310 degrees, -157.177169 degrees

Calculate destination using an initial point, azimuth, and distance.

var lat, lon float64
geodesic.WGS84.Direct(33.4911, -112.4223, -156.803310, 165330.214571, &lat, &lon, nil)
fmt.Printf("%f, %f\n", lat, lon)
// output: 
// 32.118900, -113.112300

Calculate the area and perimeter of a polygon.

// Arizona
poly := WGS84.PolygonInit(false)
poly.AddPoint(36.99377, -109.050292)
poly.AddPoint(36.96744, -114.049072)
poly.AddPoint(36.26199, -114.016113)
poly.AddPoint(36.08462, -114.279785)
poly.AddPoint(36.11125, -114.730224)
poly.AddPoint(34.86790, -114.631347)
poly.AddPoint(34.47939, -114.367675)
poly.AddPoint(34.29806, -114.104003)
poly.AddPoint(33.89777, -114.532470)
poly.AddPoint(33.58716, -114.543457)
poly.AddPoint(33.35806, -114.708251)
poly.AddPoint(33.09154, -114.708251)
poly.AddPoint(32.87036, -114.444580)
poly.AddPoint(32.74108, -114.719238)
poly.AddPoint(32.50049, -114.818115)
poly.AddPoint(31.33487, -111.093749)
poly.AddPoint(31.35363, -109.050292)
poly.AddPoint(36.99377, -109.050292)
var area, perimeter float64
poly.Compute(false, false, &area, &perimeter)
fmt.Printf("%f area (km²), %f perimeter (meters)\n", area/1000000, perimeter)
// output:
// 294838.722804 area (km²), 2254910.021767 perimeter (meters)

For full api documentation see https://pkg.go.dev/github.com/tidwall/geodesic#pkg-index.

Documentation

Overview

Package geodesic and an API for the geodesic routines in Go

This an implementation in Go of the geodesic algorithms described in:

C. F. F. Karney, Algorithms for geodesics,
J. Geodesy 87, 43--55 (2013);
DOI: 10.1007/s00190-012-0578-z;
addenda: https://geographiclib.sourceforge.io/geod-addenda.html;
link: https://doi.org/10.1007/s00190-012-0578-z;

Copyright (c) Charles Karney (2012-2021) <charles@karney.com> and licensed under the MIT/X11 License. For more information, see https://geographiclib.sourceforge.io/

Also contains spherical algorithms derived from the Geodesy project.

Geodesy representation conversion functions   (c) Chris Veness 2002-2019
                                                             MIT Licence
www.movable-type.co.uk/scripts/latlong.html
www.movable-type.co.uk/scripts/js/geodesy/geodesy-library.html#dms

Ported to Go by Joshua Baker <joshbaker77@gmail.com> and licensed under the MIT License.

Index

Constants

This section is empty.

Variables

View Source
var Globe = NewSpherical(6378137)

Globe is a pre-initialized spherical representing Earth as a terrestrial globe.

View Source
var WGS84 = NewEllipsoid(6378137, float64(1.)/298.257223563)

WGS84 conforming ellispoid https://en.wikipedia.org/wiki/World_Geodetic_System

Functions

This section is empty.

Types

type Ellipsoid

type Ellipsoid struct {
	// contains filtered or unexported fields
}

Ellipsoid is an object for performing geodesic operations.

func NewEllipsoid

func NewEllipsoid(radius, flattening float64) *Ellipsoid

NewEllipsoid initializes a new geodesic ellipsoid object.

Param radius is the equatorial radius (meters). Param flattening is the flattening factor of the ellipsoid.

The WGS84 pacakge-level variable is a pre-initialized ellipsoid representing Earth.

func NewSpherical

func NewSpherical(radius float64) *Ellipsoid

NewSpherical initializes a new geodesic ellipsoid object that uses simplified operations on a sphere.

The Inverse and Direct operations will often be more computationally efficient than NewEllipsoid because it uses simplier great-circle calculations such as the Haversine formula.

Param radius is the equatorial radius (meters).

The Globe package-level variable is a pre-initialized spherical representing Earth as a terrestrial globe.

func (*Ellipsoid) Direct

func (e *Ellipsoid) Direct(
	lat1, lon1, azi1, s12 float64,
	lat2, lon2, azi2 *float64,
)

Direct solves the direct geodesic problem.

Param g is a pointer to the geod_geodesic object specifying the ellipsoid. Param lat1 is the latitude of point 1 (degrees). Param lon1 is the longitude of point 1 (degrees). Param azi1 is the azimuth at point 1 (degrees). Param s12 is the distance from point 1 to point 2 (meters). negative is ok. Out param plat2 is a pointer to the latitude of point 2 (degrees). Out param plon2 is a pointer to the longitude of point 2 (degrees). Out param pazi2 is a pointer to the (forward) azimuth at point 2 (degrees).

lat1 should be in the range [-90,+90]. The values of lon2 and azi2 returned are in the range [-180,+180]. Any of the "return" arguments, plat2, etc., may be replaced with nil, if you do not need some quantities computed.

func (*Ellipsoid) DirectLine added in v0.3.2

func (e *Ellipsoid) DirectLine(lat1, lon1, azi1, s12 float64, caps Mask) Line

DirectLine initializes a geodesic Line object in terms of the direct geodesic problem.

Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param azi1 azimuth at point 1 (degrees). Param s12 distance from point 1 to point 2 (meters); it can be negative. Param caps bitor'ed combination of Mask values specifying the capabilities the geodesic Line object should possess, i.e., which quantities can be returned in calls to Line.Position() and Line.GenPosition()

This function sets point 3 of the geodesic Line to correspond to point 2 of the direct geodesic problem. See LineInit() for more information.

func (*Ellipsoid) Flattening

func (e *Ellipsoid) Flattening() float64

Flattening of the Ellipsoid

func (*Ellipsoid) GenDirect added in v0.3.2

func (e *Ellipsoid) GenDirect(
	lat1, lon1, azi1 float64,
	flags Flags, s12_a12 float64,
	lat2, lon2, azi2 *float64,
	s12, m12 *float64,
	M12, M21 *float64,
	S12 *float64,
) float64

GenDirect solves the general direct geodesic problem.

Param lat1 is the latitude of point 1 (degrees). Param lon1 is thelongitude of point 1 (degrees). Param azi1 is theazimuth at point 1 (degrees). Param flags is the bitor'ed combination of Flags; flags & ArgMode determines the meaning of s12_a12 and flags & LongUnroll "unrolls" lon2. Param s12_a12 if flags & ArcMode is 0, this is the distance from point 1 to point 2 (meters); otherwise it is the arc length from point 1 to point 2 (degrees); it can be negative. Out param lat2 is a pointer to the latitude of point 2 (degrees). Out param lon2 is a pointer to the longitude of point 2 (degrees). Out param azi2 is a pointer to the (forward) azimuth at point 2 (degrees). Out param s12 is a pointer to the distance from point 1 to point 2 (meters). Out param m12 is a pointer to the reduced length of geodesic (meters). Out param M12 is a pointer to the geodesic scale of point 2 relative to point 1 (dimensionless). Out param M21 is a pointer to the geodesic scale of point 1 relative to point 2 (dimensionless). Out param S12 is a pointer to the area under the geodesic (meters-squared). Returns a12 arc length from point 1 to point 2 (degrees).

lat1 should be in the range [-90,+90]. The function value a12 equals s12_a12 if flags & ArcMode. Any of the "return" arguments, plat2, etc., may be replaced by nil, if you do not need some quantities computed.

With flags & LongUnroll bit set, the longitude is "unrolled" so that the quantity lon2 - lon1 indicates how many times and in what sense the geodesic encircles the ellipsoid.

func (*Ellipsoid) GenDirectLine added in v0.3.2

func (e *Ellipsoid) GenDirectLine(
	lat1, lon1, azi1 float64,
	flags Flags, s12_a12 float64,
	caps Mask,
) Line

GenDirectLine initializes a geodesic Line object in terms of the direct geodesic problem specified in terms of either distance or arc length.

Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param azi1 azimuth at point 1 (degrees). Param flags either NoFlags or ArcMode to determining the meaning of the s12_a12. Param s12_a12 if flags = NoFlags, this is the distance from point 1 to point 2 (meters); if flags = ArcMode, it is the arc length from point 1 to point 2 (degrees); it can be negative. Param caps bitor'ed combination of Mask values specifying the capabilities the geodesic Line object should possess, i.e., which quantities can be returned in calls to Line.Position() and Line.GenPosition().

This function sets point 3 of the geodesic Line to correspond to point 2 of the direct geodesic problem. See LineInit() for more information.

func (*Ellipsoid) GenInverse added in v0.3.2

func (e *Ellipsoid) GenInverse(
	lat1 float64, lon1 float64, lat2 float64, lon2 float64,
	s12 *float64, azi1 *float64, azi2 *float64,
	m12 *float64, M12 *float64, M21 *float64, S12 *float64,
) float64

The general inverse geodesic calculation.

Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param lat2 latitude of point 2 (degrees). Param lon2 longitude of point 2 (degrees). Out param s12 pointer to the distance from point 1 to point 2 (meters). Out param azi1 pointer to the azimuth at point 1 (degrees). Out param azi2 pointer to the (forward) azimuth at point 2 (degrees). Out param m12 pointer to the reduced length of geodesic (meters). Out param M12 pointer to the geodesic scale of point 2 relative to point 1 (dimensionless). Out param M21 pointer to the geodesic scale of point 1 relative to point 2 (dimensionless). Out param S12 pointer to the area under the geodesic (meters-squared). Returns a12 arc length from point 1 to point 2 (degrees).

lat1 and lat2 should be in the range [-90, +90]. Any of the "return" arguments s12, etc., may be replaced by nil, if you do not need some quantities computed.

func (*Ellipsoid) Inverse

func (e *Ellipsoid) Inverse(
	lat1, lon1, lat2, lon2 float64,
	s12, azi1, azi2 *float64,
)

Inverse solve the inverse geodesic problem.

Param lat1 is latitude of point 1 (degrees). Param lon1 is longitude of point 1 (degrees). Param lat2 is latitude of point 2 (degrees). Param lon2 is longitude of point 2 (degrees). Out param ps12 is a pointer to the distance from point 1 to point 2 (meters). Out param pazi1 is a pointer to the azimuth at point 1 (degrees). Out param pazi2 is a pointer to the (forward) azimuth at point 2 (degrees).

lat1 and lat2 should be in the range [-90,+90]. The values of azi1 and azi2 returned are in the range [-180,+180]. Any of the "return" arguments, ps12, etc., may be replaced with nil, if you do not need some quantities computed.

The solution to the inverse problem is found using Newton's method. If this fails to converge (this is very unlikely in geodetic applications but does occur for very eccentric ellipsoids), then the bisection method is used to refine the solution.

func (*Ellipsoid) InverseLine added in v0.3.2

func (e *Ellipsoid) InverseLine(lat1, lon1, lat2, lon2 float64, caps Mask) Line

InverseLine initializes a geodesic Line object in terms of the inverse geodesic problem.

Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param lat2 latitude of point 2 (degrees). Param lon2 longitude of point 2 (degrees). Param caps bitor'ed combination of Mask values specifying the capabilities the Line object should possess, i.e., which quantities can be returned in calls to Line.Position() and Line.GenPosition().

This function sets point 3 of the Line to correspond to point 2 of the inverse geodesic problem. See LineInit() for more information.

func (*Ellipsoid) LineInit added in v0.3.2

func (e *Ellipsoid) LineInit(lat1, lon1, azi1 float64, caps Mask) Line

LineInit initializes a geodesic Line object.

Param lat1 latitude of point 1 (degrees). Param lon1 longitude of point 1 (degrees). Param azi1 azimuth at point 1 (degrees). Param caps bitor'ed combination of Mask values specifying the capabilities the geodesic Line object should possess, i.e., which quantities can be returned in calls to Line.Position() and Line.GenPosition().

lat1 should be in the range [-90, +90].

The Mask values are: - caps |= Latitude for the latitude lat2; this is added automatically, - caps |= Longitude for the latitude lon2, - caps |= Azimuth for the latitude azi2; this is added automatically, - caps |= Distance for the distance s12, - caps |= ReducedLength for the reduced length m12, - caps |= GeodesicScale for the geodesic scales M12 and M21, - caps |= Area for the area S12, - caps |= DistanceIn permits the length of the geodesic to be given in terms of s12; without this capability the length can only be specified in terms of arc length.

A value of caps = 0 is treated as Latitude | Longitude | Azimuth | DistanceIn (to support the solution of the "standard" direct problem).

func (*Ellipsoid) PolygonInit

func (e *Ellipsoid) PolygonInit(polyline bool) Polygon

PolygonInit initializes a polygon. Param polyline for polyline instead of a polygon.

If polyline is not set, then the sequence of vertices and edges added by Polygon.AddPoint() and Polygon.AddEdge() define a polygon and the perimeter and area are returned by Polygon.Compute(). If polyline is set, then the vertices and edges define a polyline and only the perimeter is returned by Polygon.Compute().

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.

func (*Ellipsoid) Radius

func (e *Ellipsoid) Radius() float64

Radius of the Ellipsoid

func (*Ellipsoid) Spherical

func (e *Ellipsoid) Spherical() bool

Spherical returns true if the ellipsoid was initialized using NewSpherical.

type Flags added in v0.3.2

type Flags uint

Flag values for the flags argument to GenPosition

const (
	NoFlags    Flags = 0       /**< No flags */
	ArcMode    Flags = 1 << 0  /**< Position given in terms of arc distance */
	LongUnroll Flags = 1 << 15 /**< Unroll the longitude */
)

type Line added in v0.3.2

type Line struct {
	// contains filtered or unexported fields
}

Line is an object containing information about a single geodesic. This must be by LineInit(), DirectLine(), GenDirectLine(), or InverseLine() before use.

func (*Line) A13 added in v0.3.5

func (l *Line) A13() float64

A13 returns the length to reference point

func (*Line) Azi1 added in v0.3.5

func (l *Line) Azi1() float64

Azi1 returns the starting azimuth

func (*Line) GenPosition added in v0.3.2

func (l *Line) GenPosition(
	flags Flags, s12_a12 float64,
	lat2, lon2, azi2, s12, m12, M12, M21, S12 *float64,
) float64

GenPosition is the general position function.

Param flags bitor'ed combination of Flags; flags & ArcMode determines the meaning of s12_a12 and flags & LongUnroll "unrolls" lon2; if flags & ArcMode is 0, then l must have been initialized with caps |= DistanceIn. Param s12_a12 if flags & ArcMode is 0, this is the distance from point 1 to point 2 (meters); otherwise it is the arc length from point 1 to point 2 (degrees); it can be negative. Out param lat2 pointer to the latitude of point 2 (degrees). Out param lon2 pointer to the longitude of point 2 (degrees); requires that l was initialized with caps |= Longitude. Out param azi2 pointer to the (forward) azimuth at point 2 (degrees). Out param s12 pointer to the distance from point 1 to point 2 (meters); requires that l was initialized with caps |= Distance. Out param m12 pointer to the reduced length of geodesic (meters); requires that l was initialized with caps |= ReducedLength. Out param M12 pointer to the geodesic scale of point 2 relative to point 1 (dimensionless); requires that l was initialized with caps |= GeodesicScale. Out param M21 pointer to the geodesic scale of point 1 relative to point 2 (dimensionless); requires that l was initialized with caps |= GeodesicScale. Out param S12 pointer to the area under the geodesic (meters<sup>2</sup>); requires that l was initialized with caps |= GEOD_AREA. Returns a12 arc length from point 1 to point 2 (degrees).

l must have been initialized with a call to geod_lineinit() with caps |= DistanceIn. The value azi2 returned is in the range [-180, +180]. Any of the "return" arguments plat2, etc., may be replaced by nil, if you do not need some quantities computed. Requesting a value which l is not capable of computing is not an error; the corresponding argument will not be altered.

With flags & LongUnroll bit set, the longitude is "unrolled" so that the quantity lon2 - lon1 indicates how many times and in what sense the geodesic encircles the ellipsoid.

func (*Line) GenSetDistance added in v0.3.2

func (l *Line) GenSetDistance(flags Flags, s13_a13 float64)

GenSetDistance specifies position of point 3 in terms of either distance or arc length.

Param flags; either NoFlags or ArcMode to determining the meaning of the s13_a13. Param s13_a13; if flags = NoFlags, this is the distance from point 1 to point 3 (meters); if flags = ArcMode, it is the arc length from point 1 to point 3 (degrees); it can be negative.

If flags = NoFlags, this calls Line.SetDistance(). If flags = ArcMode, the s13 is only set if the Line object has been constructed with caps |= Distance.

func (*Line) Lat1 added in v0.3.5

func (l *Line) Lat1() float64

Lat1 returns the starting latitude

func (*Line) Lon1 added in v0.3.5

func (l *Line) Lon1() float64

Lon1 returns the starting longitude

func (*Line) Position added in v0.3.2

func (l *Line) Position(s12 float64, lat2, lon2, azi2 *float64)

Position computes the position along a geodesic Line.

Param s12 distance from point 1 to point 2 (meters); it can be negative. Out param lat2 pointer to the latitude of point 2 (degrees). Out param lon2 pointer to the longitude of point 2 (degrees); requires that l was initialized with caps |= Longitude. Out param azi2 pointer to the (forward) azimuth at point 2 (degrees).

l must have been initialized with a call, e.g., to LineInit(), with caps |= DistanceIn (or caps = 0). The values of lon2 and azi2 returned are in the range [-180, +180]. Any of the "return" arguments plat2, etc., may be replaced by nil, if you do not need some quantities computed.

func (*Line) S13 added in v0.3.5

func (l *Line) S13() float64

S13 returns distance to reference point

func (*Line) SetDistance added in v0.3.2

func (l *Line) SetDistance(s13 float64)

SetDistance specifies position of point 3 in terms of distance.

Param s13 si the distance from point 1 to point 3 (meters); it can be negative.

This is only useful if the line object has been constructed with caps |= DistanceIn.

type Mask added in v0.3.2

type Mask uint

Mask values for the caps argument to InverseLine

const (
	None          Mask = 0                   /**< Calculate nothing */
	Latitude      Mask = 1 << 7              /**< Calculate latitude */
	Longitude     Mask = 1<<8 | 1<<3         /**< Calculate longitude */
	Azimuth       Mask = 1 << 9              /**< Calculate azimuth */
	Distance      Mask = 1<<10 | 1<<0        /**< Calculate distance */
	DistanceIn    Mask = 1<<11 | 1<<0 | 1<<1 /**< Allow distance as input  */
	ReducedLength Mask = 1<<12 | 1<<0 | 1<<2 /**< Calculate reduced length */
	GeodesicScale Mask = 1<<13 | 1<<0 | 1<<2 /**< Calculate geodesic scale */
	Area          Mask = 1<<14 | 1<<4        /**< Calculate reduced length */
	All           Mask = 0x7F80 | 0x1F       /**< Calculate everything */
)

type Polygon

type Polygon struct {
	// contains filtered or unexported fields
}

Polygon struct for accumulating information about a geodesic polygon. Used for computing the perimeter and area of a polygon. This must be initialized from Ellipsoid.PolygonInit before use.

func (*Polygon) AddEdge

func (p *Polygon) AddEdge(azi, s float64)

AddEdge adds an edge to the polygon or polyline.

Param azi is the azimuth at current point (degrees). Param s is the distance from current point to next point (meters).

func (*Polygon) AddPoint

func (p *Polygon) AddPoint(lat, lon float64)

AddPoint adds a point to the polygon or polyline.

Param lat is the latitude of the point (degrees). Param lon is the longitude of the point (degrees).

func (*Polygon) Clear

func (p *Polygon) Clear()

Clear the polygon, allowing a new polygon to be started.

func (*Polygon) Compute

func (p *Polygon) Compute(clockwise, sign bool, area, perimeter *float64) uint

Compute the results for a polygon

Param reverse, if set then clockwise (instead of counter-clockwise) traversal counts as a positive area. Param sign, if set 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 param area is a pointer to the area of the polygon (meters-squared); Out param perimeter is a pointer to the perimeter of the polygon or length of the polyline (meters). Returns the number of points.

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. Arbitrarily complex polygons are allowed. In the case of self-intersecting polygons the area is accumulated "algebraically", e.g., the areas of the 2 loops in a figure-8 polygon will partially cancel. There's no need to "close" the polygon by repeating the first vertex. Set pA or pP to nil, if you do not want the corresponding quantity returned.

More points can be added to the polygon after this call.

func (*Polygon) TestEdge added in v0.3.2

func (p *Polygon) TestEdge(azi, s float64, reverse, sign bool, area, perimeter *float64) uint

TestEdge returns the results assuming a tentative final test point is added via an azimuth and distance; 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 Polygon.AddEdge() and Polygon.Compute() are used. Param azi is the azimuth at current point (degrees). Param s is the distance from current point to final test point (meters). Param reverse if set then clockwise (instead of counter-clockwise) traversal counts as a positive area. Param sign if set 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 param area is a pointer to the area of the polygon (meters-squared); only set if polyline is non-zero in the call to PolygonInit(). Out param perimeter is a pointer to the perimeter of the polygon or length of the polyline (meters). Returns the number of points

func (*Polygon) TestPoint added in v0.3.2

func (p *Polygon) TestPoint(lat, lon float64, reverse, sign bool, area, perimeter *float64) uint

TestPoint returns 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 Polygon.AddPoint() and Polygon.Compute() are used.

Param lat is the latitude of the test point (degrees). Param lon is the longitude of the test point (degrees). Param reverse if set then clockwise (instead of counter-clockwise) traversal counts as a positive area. Param sign if set 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 param area is a pointer to the area of the polygon (meters-squared); only set if polyline is non-zero in the call to PolygonInit(). Out apram perimeter is a pointer to the perimeter of the polygon or length of the polyline (meters). Returns the number of points.

lat should be in the range [-90,+90].

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL