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

@ulrik.ek/wgs84

v1.0.3

Published

Basic library for computing small distances between WGS84 coordinates using a flat earth approximation.

Downloads

3

Readme

wgs84

Introduction

A tiny library fully implemented in Typescript to handle WGS84 coordinates in GeoJson and "small" distances between them with very high accuracy (~1 cm), based on a local, flat earth approximation.

  • All functions uses degrees for latitude and longitude, and meters for distances.
  • Parses and gives output in GeoJson using the Point definition. If you already have imported the typescript definition for Point in the geojson package you can use that (that is what I do in unit testing). Otherwise you can import Point from this package.
  • No dependencies to other NPM modules.
  • The math is based on Aviation Formulary V1.47 by Ed Williams.
  • Functions will throw Error if fed impossible values, e.g. incorrectly formatted GeoJSON or lat >= 90 degrees (math will not work!). Make sure to handle that!

Getting Started

Include in your project as any other NPM package

npm install @ulrik.ek/wgs84

Usage

import * as wgs84 from '@ulrik.ek/wgs84'; // The functions can obviously also be imported separately

// helper function to construct a GeoJSON Point
const lat = 15;
const lon = 25;
const p: wgs84.Point = wgs84.point(lat, lon);

// Getting a new point 100m north and 200m east of the first point
const p1: wgs84.Point = wgs84.pointEastOf(wgs84.pointNorthOf(p, 300), 400);
const newLat = p1.coordinates[1]; // GeoJSON uses [lon, lat] order!
const newLon = p1.coordinates[0];
console.log(`lat=${newLat}, lon=${newLon}`);

// get the distance along north between the 2 points
console.log(`Distance along north=${wgs84.distanceNorth(p, p1)}`);
console.log(`Distance along east=${wgs84.distanceEast(p, p1)}`);
console.log(`Total distance=${wgs84.distance(p, p1)}`);

This will produce the following output

lat=15.002711283642645, lon=25.003719230339353
Distance along north=300.00000000009265
Distance along east=400.00504064747975
Total distance=500.0040325271862

Documention

The following functions are available:

point(lat: number, lon: number, height?: number): Point;
R1(position: Point): number;
R2(position: Point): number;
distanceNorth(origin: Point, target: Point): number;
distanceEast(origin: Point, target: Point): number;
distanceUp(origin: Point, target: Point): number;
distance(origin: Point, target: Point): number;
bearing(origin: Point, target: Point): number;
pointNorthOf(origin: Point, dN: number): Point;
pointEastOf(origin: Point, dE: number): Point;
pointAbove(origin: Point, dH: number): Point;

Full Typedoc documentation

Build and Test

All functions are unit tested.