npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sgeo

v0.0.6

Published

Spherical coordinate library

Downloads

442

Readme

Spherical coordinate library

This library lets you compute distance, bearing, interpolations (mid points), and many other functions from a set of latitude / longitude pairs. Original code comes from http://www.movable-type.co.uk/scripts/latlong.html by Chris Veness

Installation

npm install sgeo

Usage

parseDMS

Parses string representing degrees/minutes/seconds into numeric degrees.

This is very flexible on formats, allowing signed decimal degrees, or deg-min-sec optionally suffixed by compass direction (NSEW). A variety of separators are accepted (eg 3º 37' 09"W) or fixed-width format without separators (eg 0033709W). Seconds and minutes may be omitted. (Note minimal validation is done).

var sgeo = require('sgeo');

var lat = sgeo.parseDMS('51 28 40.12 N');
var lon = sgeo.parseDMS('00 00 05.31 W');

toDMS

Convert decimal degrees to deg/min/sec format.

degree, prime, double-prime symbols are added, but sign is discarded, though no compass direction is added

var dms = sgeo.toDMS(12.34544, 'dms', 2);

latlon

Provides various functionalities for geodesy calculations.

Initializing coordinates

var sgeo = require('sgeo');
var p1 = new sgeo.latlon(51.0, -5.5);
var p2 = new sgeo.latlon(58.4778, -3.01);

console.log(p1.lat); //display latitude
console.log(p1.lng); //display longitude
console.log(p1); //toString()

Calculate distance (in km)

var dist = p1.distanceTo(p2);      
console.log(dist);
846.6

Calculate bearing (in degress clockwise from north 0 - 360)

var brng = p1.bearingTo(p2);       
console.log(brng);
9.871855132189069

Calculate midpoint

var pm = p1.midpointTo(p2);       
console.log(pm);
{ lat: 54.74522196955371, lng: -4.3700915168517 }

midpoint of multiple locations

var pm = sgeo.migpoint([p1, p2, p3]);
console.log(pm);

Interpolate points between p1 and p2

var inp = p1.interpolate(p2, 5);
console.dir(inp);
[ { lat: 51, lng: -5.499999999999999 },
  { lat: 52.87394889826373, lng: -4.959445475316697 },
  { lat: 54.74522196955371, lng: -4.370091516851731 },
  { lat: 56.613360847919104, lng: -3.7236677522713766 },
  { lat: 58.47780000000001, lng: -3.0099999999999985 } ]

latlon.finalBeearingTo

Returns final bearing arriving at supplied destination point from this point; the final bearing will differ from the initial bearing by varying degrees according to distance and latitude

latlon.destinationPoint

Returns the destination point from this point having traveled the given distance (in km) on the given initial bearing (bearing may vary before destination is reached)

latlon.intersection

Returns the point of intersection of two paths defined by point and bearing

latlon.rhumbDistanceTo

Returns the distance from this point to the supplied point, in km, travelling along a rhumb line

latlon.rhumbBearingTo

Returns the bearing from this point to the supplied point along a rhumb line, in degrees

latlon.rhumbDestinationPoint

Returns the destination point from this point having traveled the given distance (in km) on the given bearing along a rhumb line

latlon.rhumbMidpointTo

Returns the loxodromic midpoint (along a rhumb line) between this point and the supplied point.

sgeo.toLat

Convert numeric degrees to deg/min/sec latitude (suffixed with N/S)

sgeo.toLon

Convert numeric degrees to deg/min/sec longitude (suffixed with E/W)

sgeo.toBrng

Convert numeric degrees to deg/min/sec as a bearing

Attribution

Most of the code was originally written by Chris Veness at http://www.movable-type.co.uk/scripts/latlong.html