@gretzky/loxodrome v0.2.1
loxodrome
Geodesy and navigational functions
Usage
Install with the package manager of your choice
// or yarn or pnpm
npm install @gretzky/loxodromeAPI
bearingDistanceTo({ from, to, useRhumbLine }): { initialBearing: number; finalBearing: number }
Returns the initial and final bearing distance between 2 points.
| Param | Type | Description | Default |
|---|---|---|---|
| from | Coordinates | set of starting coordinates | Required |
| to | Coordinates | set of ending coordinates | Required |
| useRhumbLine | boolean | whether or not to calculate along a rhumb line | Required |
bearingToDirection(bearing: number, compassPoints: CompassPoints): Windrose
Converts a bearing to a given compass windrose direction.
| Param | Type | Description | Default |
|---|---|---|---|
| bearing | number | bearing to convert | Required |
| compassPoints | CompassPoints | number of compass points to use | 16 |
convertDistance({ distance, from, to }): number
Converts a distance measurement from one distance unit to another.
| Param | Type | Description | Default |
|---|---|---|---|
| distance | number | distance to convert | Required |
| from | DistanceUnits | original unit | Required |
| to | DistanceUnits | unit to convert to | Required |
convertSpeed({ speed, from, to }): number
Converts a speed measurement from one unit to another.
| Param | Type | Description | Default |
|---|---|---|---|
| speed | number | speed to convert | Required |
| from | SpeedUnits | original unit | Required |
| to | SpeedUnits | unit to convert to | Required |
ddToDMS(dd: number, direction: "latitude" | "longitude"): string
Converts decimal degrees to decimal minutes
| Param | Type | Description | Default |
|---|---|---|---|
| degrees | number | decimal degrees to convert | Required |
| direction | "latitude" or "longitude" | direction of the degrees | Required |
getCenterOfCoordinates(coordinates: Coordinates[]): Coordinates
Get the latitude and longitude center of an array of coordiantes.
| Param | Type | Description | Default |
|---|---|---|---|
| coordinates | Coordinates[] | array of coordinates | Required |
getRhumbLine({ from, to }): number
Returns the rhumb line between 2 longitudes.
| Param | Type | Description | Default |
|---|---|---|---|
| from | number | starting longitude | Required |
| to | number | ending longitude | Required |
getWindroseDirections(compassPoints: CompassPoints): Windrose[]
Returns an array of windrose directions for a given number of compass points.
| Param | Type | Description | Default |
|---|---|---|---|
| compassPoints | CompassPoints | number of compass points to use | Required |
haversine({ from, to, useRhumbLine }): number
Returns the great-circle distance in kilometers between 2 sets of coordinates using the haversine formula.
| Param | Type | Description | Default |
|---|---|---|---|
| from | Coordinates | starting coordinates | Required |
| to | Coordinates | ending coordinates | Required |
| useRhumbLine | boolean | whether or not to get the distance along a rhumb line | false |
midpoint({ from, to, useRhumbLine }): Coordinates
Returns the midpoint coordinate set between 2 coordinates.
| Param | Type | Description | Default |
|---|---|---|---|
| from | Coordinates | starting coordinates | Required |
| to | Coordinates | ending coordinates | Required |
| useRhumbLine | boolean | whether or not to get the distance along a rhumb line | false |
pointsInRange({ from, to, range }): boolean
Returns whether or not 2 points are within a certain statue mile distance from each other.
| Param | Type | Description | Default |
|---|---|---|---|
| from | Coordinates | starting coordinates | Required |
| to | Coordinates | ending coordinates | Required |
| range | number | statute miles to fall within | false |
vincenty({ from, to }): number
Returns the geodetic distance in kilometers between 2 points using the Vincenty inverse formula.
| Param | Type | Description | Default |
|---|---|---|---|
| from | Coordinates | starting coordinates | Required |
| to | Coordinates | ending coordinates | Required |