TsGeo - Format and Output - Cordinate

TsGeo allow to format Coordinate class into several outputs representation.

TsGeo allow to format the output in different styles:

  • Decimal Degrees
  • Decimal Minutes
  • DMS
  • GeoJSON

Decimal Degrees

import {Coordinate}       from "tsgeo/Coordinate";
import {DecimalDegrees}   from "tsgeo/Formatter/Coordinate/DecimalDegrees";

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

let coordinate = new Coordinate(19.820664, -155.468066);

console.log(coordinate.format(new DecimalDegrees()))         // Display "19.82066 -155.46807"
console.log(coordinate.format(new DecimalDegrees(', ', 3)))  // Display "19.821 -155.468"

Decimal Minutes

import {Coordinate}       from "tsgeo/Coordinate";
import {DecimalMinutes}   from "tsgeo/Formatter/Coordinate/DecimalMinutes";

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

let coordinate = new Coordinate(43.62310, -70.20787);
let formatter  = new DecimalMinutes();

console.log(coordinate.format(formatter))         // Display "43° 37.386′ -070° 12.472′"

formatter.setSeparator(', ')
      .useCardinalLetters(true)
      .setUnits(DecimalMinutes.UNITS_ASCII);

console.log(coordinate.format(formatter))         // Display "43° 37.386' N, 070° 12.472' W"

DMS

import {Coordinate}  from "tsgeo/Coordinate";
import {DMS}         from "tsgeo/Formatter/Coordinate/DMS";

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

let coordinate = new Coordinate(18.911306, -155.678268);
let formatter  = new DMS();

console.log(coordinate.format(formatter))         // Display "18° 54′ 41″ -155° 40′ 42″"

formatter.setSeparator(', ')
      .useCardinalLetters(true)
      .setUnits(DecimalMinutes.UNITS_ASCII);

console.log(coordinate.format(formatter))         // Display "18° 54' 41" N, 155° 40' 42" W"

GeoJSON

import {Coordinate}    from "tsgeo/Coordinate";
import {GeoJSON}       from "tsgeo/Formatter/Coordinate/GeoJSON";

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

let coordinate = new Coordinate(18.911306, -155.678268);

console.log(coordinate.format(new GeoJSON()))         // Display "{"type":"Point","coordinates":[-155.678268,18.911306]}"

Back Polyline


Add a comment