Programs for calculating distance between coordinates.
make
make clean
A binary will be located in ./bin
directory (bin/geodesic
).
geodesic [-i file] [-o file] [-k precision] [-p problem] [-f projection] [-s] [-a] [-h]
-p [direct|inverse|polygon]
Solve direct problem or inverse problem.
- Direct problem: Given a coordinate and a vector of distance and initial bearing, evaluate the destination coordinate and the final bearing.
- Inverse problem: Given 2 coordinates, evaluate the distance, the initial bearing and the final bearing.
- Polygon problem: Given a set of coordinates, evaluate the perimeter and area.
-f [sphere|ellipsoid|block]
Select projection for evaluating the azimuths and distances.
- Sphere projection employs the haversine algorithm and spherical triangle formula. Error is higher (error ~0.5%).
- Ellipsoid projection employs the Vincenty's algorithm with modifications by Charles Karney. It is more resource-intensive (2x sphere projection).
- Block projection means following parallels of latitude and meridians of longitude, assuming the Earth is an ellipsoid. For meridian arcs Bessel's series is implemented. All inputted coordinates should follow meridians of longitude and parallels of latitude.
-s
Different computations for different problems.
- Distance between coordinates for inverse problems.
- The destination coordinate for direct problems.
- The perimeter for polygon problems.
-a
Different computations for different problems.
- Initial and final bearings from one coordinate to the next for inverse problems.
- The final bearing for direct problems.
- The area for polygon problems.
-i [FILE|-]
Input file. -
signifies standard in (stdin). Defaults to stdin without the option.
-o [FILE|-]
Output file. -
signifies standard out (stdout). Defaults to stdout without the option.
-k [integer]
Set the number of decimal places in output. Default is 6.
Coordinates are given in the form of:
[coordinates1] [coordinates2] ... [coordinatesN]
, where
each coordinate is in the form of latitude,longitude
in decimals.
[
{
"distance": xxx,
"start_azimuth": xxx,
"end_azimuth": xxx
},
{
"distance": xxx,
"start_azimuth": xxx,
"end_azimuth": xxx
},
...
{
"distance": xxx,
"start_azimuth": xxx,
"end_azimuth": xxx
},
{
"total_distance": xxx
}
]
Where each set of pairs in array specifies the following:
distance
as the distance between the nth coordinate and the (n+1)th coordinate.start_azimuth
as the bearing at the nth coordinate, on the line from the nth coordinate to the (n+1)th coordinate.end_azimuth
as the bearing at the (n+1)th coordinate, on the line from the nth coordinate to the (n+1)th coordinate.
"total_distance"
specifies the total distance of the line joining all coordinates.
Vectors are given in the form of:
[start coordinate] [vector1] [vector2] ... [vectorN]
, where
each vector is in the form of distance:bearing
, in decimals and degrees respectively.
[
{
"coordinate": [xxx,xxx],
"azimuth": xxx
},
{
"coordinate": [xxx,xxx],
"azimuth": xxx
},
...
{
"coordinate": [xxx,xxx],
"azimuth": xxx
}
]
Where each set of pairs in array specifies the following:
coordinate
as the destination coordinate at the distance and bearing from the (n-1)th coordinate.azimuth
as the bearing atcoordinate
(nth coordinate), on the line from (n-1)th coordinate to nth coordinate.
Coordinates are given in the form of:
[coordinates1] [coordinates2] ... [coordinatesN] [coordinates1]
, where
each coordinate is in the form of latitude,longitude
in decimals.
Coordinates of a polygon should be specified in the counter-clockwise direction.
For polygons that include the poles, coordinates should be specified in the eastward direction for the North Pole, and the westward direction for the South Pole.
Note that coordinate1
must be placed at the end to close the polygon.
{
"perimeter": xxx,
"area": xxx
}
Where
perimeter
denotes the perimeter of the polygon.area
denotes the area of the polygon.
- All distances are provided in kilometres.
- All areas are provided in square kilometres.
- All angles are provided in degrees.
- For latitudes, positive is assumed for north.
- For longitudes, positive is assumed for east.
- For bearings, full bearing must be used.
allow_nan
should be set totrue
for parsing JSON, because azimuths may return aNaN
value for zero vectors depending on the algorithm.