TsGeo - Usage

TsGeo use mainly the class Coordinate for operation.

TsGeo use a DistanceInterface to compute a distance between 2 coordinates. Two interface are already defined in library:

There is an sample of code integration using Vincenty’s Formula:

import {Coordinate} from "tsgeo/Coordinate";
import {Vincenty}   from "tsgeo/Distance/Vincenty";

/* Add the following in a method of TS class */

let coordinate1 = new Coordinate(19.820664, -155.468066); // Mauna Kea Summit
let coordinate2 = new Coordinate(20.709722, -156.253333); // Haleakala Summit

console.log(coordinate1.getDistance(coordinate2, new Vincenty())); // returns 128130.850 (meters; ≈128 kilometers)

There is an sample of code integration using Haversine Formula:

import {Coordinate} from "tsgeo/Coordinate";
import {Haversine}   from "tsgeo/Distance/Haversine";

/* Add the following in a method of TS class */

let coordinate1 = new Coordinate(19.820664, -155.468066); // Mauna Kea Summit
let coordinate2 = new Coordinate(20.709722, -156.253333); // Haleakala Summit

console.log(coordinate1.getDistance(coordinate2, new Haversine())); // returns 128384.515 (meters; ≈128 kilometers)

More complex operations are possible. Please visit the following sections.

Geometry resources Retour Format and Output


Ajouter un commentaire