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

@intelight/geolib

v2.0.22

Published

Fork of original Geolib library to perform geo specific tasks

Downloads

13

Readme

Geolib

Build Status

Library to provide basic geospatial operations like distance calculation, conversion of decimal coordinates to sexagesimal and vice versa, etc.

View demo

Install

npm install geolib

Calculates the distance between two geo coordinates

Takes 2 or 4 arguments. First 2 arguments must be objects that each have latitude and longitude properties (e.g. {latitude: 52.518611, longitude: 13.408056}). Coordinates can be in sexagesimal or decimal format. 3rd argument is accuracy (in meters). So a calculated distance of 1248 meters with an accuracy of 100 is returned as 1200 (accuracy 10 = 1250 etc.). 4th argument is precision in sub-meters (1 is meter presicion, 2 is decimeters, 3 is centimeters, etc).

Return value is always float and represents the distance in meters.

Calculates the distance between two geo coordinates but this method is far more inaccurate as compared to getDistance.

It can take up 2 to 3 arguments. start, end and accuracy can be defined in the same as in getDistance.

Return value is always float that represents the distance in meters.

Calculates the geographical center of all points in a collection of geo coordinates

Takes an object or array of coordinates and calculates the center of it.

Returns an object: {"latitude": centerLat, "longitude": centerLng}

Calculates the center of the bounds of geo coordinates.

Takes an array of coordinates, calculate the border of those, and gives back the center of that rectangle.

On polygons like political borders (eg. states), this may gives a closer result to human expectation, than getCenter, because that function can be disturbed by uneven distribution of point in different sides.

Imagine the US state Oklahoma: getCenter on that gives a southern point, because the southern border contains a lot more nodes, than the others.

Returns an object: {"latitude": centerLat, "longitude": centerLng}

Calculates the bounds of geo coordinates.

It returns maximum and minimum, latitude, longitude, and elevation (if provided) in form of an object of form:

Checks whether a point is inside of a polygon or not. Note: the polygon coords must be in correct order!

Returns true or false

Similar to is point inside: checks whether a point is inside of a circle or not.

Returns true or false

Gets rhumb line bearing of two points. Find out about the difference between rhumb line and great circle bearing on Wikipedia. Rhumb line should be fine in most cases:

http://en.wikipedia.org/wiki/Rhumb_line#General_and_mathematical_description

Function is heavily based on Doug Vanderweide's great PHP version (licensed under GPL 3.0) http://www.dougv.com/2009/07/13/calculating-the-bearing-and-compass-rose-direction-between-two-latitude-longitude-coordinates-in-php/

Returns calculated bearing as integer.

Gets great circle bearing of two points. See description of getRhumbLineBearing for more information. Returns calculated bearing as integer.

Gets the compass direction from an origin coordinate (originLL) to a destination coordinate (destLL). Bearing mode. Can be either circle or rhumbline (default). Returns an object with a rough (NESW) and an exact direction (NNE, NE, ENE, E, ESE, etc).

Sorts an object or array of coords by distance from a reference coordinate

Returns a sorted array [{latitude: x, longitude: y, distance: z, key: property}]

Finds the nearest coordinate to a reference coordinate.

Calculates the length of a collection of coordinates

Returns the length of the path in meters

Calculates the speed between two points within a given time span.

Returns the speed in options.unit (default is km/h).

Calculates if given point lies in a line formed by start and end.

Returns true or false

Converts a given distance (in meters) to another unit.

unit can be one of:

  • m (meter)
  • km (kilometers)
  • cm (centimeters)
  • mm (millimeters)
  • mi (miles)
  • sm (seamiles)
  • ft (foot)
  • in (inch)
  • yd (yards)

distance distance to be converted (source must be in meter)

round fractional digits

geolib.convertUnit('km', 14213, 2) // -> 14,21

Converts a sexagesimal coordinate to decimal format

geolib.sexagesimal2decimal("51° 29' 46\" N")

Converts a decimal coordinate to sexagesimal format

geolib.decimal2sexagesimal(51.49611111); // -> 51° 29' 46.00

Returns the latitude/longitude/elevation for a given point and converts it to decimal.

Works with:

  • longitude: longitude, lng, lon, 0 (GeoJSON array)
  • latitude: latitude, lat, 1 (GeoJSON array)
  • elevation: elevation, elev, alt, altitude, 2 (GeoJSON array)

geolib.latitude({lat: 51.49611, lng: 7.38896}); // -> 51.49611 geolib.longitude({lat: 51.49611, lng: 7.38896}); // -> 7.38896

Checks if a coordinate is already in decimal format and, if not, converts it to

Computes the destination point given an initial point, a distance (in meters) and a bearing (in degrees).

If no radius is given it defaults to the mean earth radius of 6371000 meter.

Returns an object: {"latitude": destLat, "longitude": destLng}

(Attention: this formula is not 100% accurate (but very close though))