All Projects → mapbox → Cheap Ruler

mapbox / Cheap Ruler

Licence: isc
Fast approximations for common geodesic measurements 🌐

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Cheap Ruler

cheap-ruler-cpp
Fast approximations for common geodesic measurements
Stars: ✭ 32 (-90.42%)
Mutual labels:  fast, distance, measurements
Candyview
Implement any RecyclerView in just 1 Line. CandyView handles everything for you.
Stars: ✭ 15 (-95.51%)
Mutual labels:  library, fast
Polysnap
A work in progress polygon operations library with integer snap-rounding
Stars: ✭ 14 (-95.81%)
Mutual labels:  library, fast
Geotic
Entity Component System library for javascript
Stars: ✭ 97 (-70.96%)
Mutual labels:  library, fast
Towel
Throw in the towel.
Stars: ✭ 333 (-0.3%)
Mutual labels:  library, measurements
Pbf
A low-level, lightweight protocol buffers implementation in JavaScript.
Stars: ✭ 618 (+85.03%)
Mutual labels:  library, fast
Cdnjs
🤖 CDN assets - The #1 free and open source CDN built to make life easier for developers.
Stars: ✭ 9,270 (+2675.45%)
Mutual labels:  library, fast
Fastlib
一个Android项目级快速开发框架,节约大部分写常用功能时间以实现更多项目业务功能及体验上的优化。使用说明见wiki
Stars: ✭ 469 (+40.42%)
Mutual labels:  library, fast
Criterion
Microbenchmarking for Modern C++
Stars: ✭ 140 (-58.08%)
Mutual labels:  library, measurements
Store
A beautifully-simple framework-agnostic modern state management library.
Stars: ✭ 204 (-38.92%)
Mutual labels:  library, fast
Pubg mobile memory hacking examples
Pubg Mobile Emulator Gameloop Memory Hacking C++ code examples. Ex: Name, Coord, Bones, Weapons, Items, Box, Drop etc.
Stars: ✭ 224 (-32.93%)
Mutual labels:  library, distance
Liblognorm
a fast samples-based log normalization library
Stars: ✭ 81 (-75.75%)
Mutual labels:  library, fast
Xseries
Library for cross-version Minecraft Bukkit support and various efficient API methods.
Stars: ✭ 109 (-67.37%)
Mutual labels:  library, fast
Csv
[DEPRECATED] See https://github.com/p-ranav/csv2
Stars: ✭ 237 (-29.04%)
Mutual labels:  library, fast
Length.js
📏 JavaScript library for length units conversion.
Stars: ✭ 292 (-12.57%)
Mutual labels:  library, measurements
Cordova Plugin Device
Apache Cordova Plugin device
Stars: ✭ 327 (-2.1%)
Mutual labels:  library
Secure Storage Android
Store strings & credentials securely encrypted on your device
Stars: ✭ 333 (-0.3%)
Mutual labels:  library
Ccxt
A JavaScript / Python / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
Stars: ✭ 22,501 (+6636.83%)
Mutual labels:  library
Unstated Next
200 bytes to never think about React state management libraries ever again
Stars: ✭ 3,784 (+1032.93%)
Mutual labels:  library
Maroto
A maroto way to create PDFs. Maroto is inspired in Bootstrap and uses gofpdf. Fast and simple.
Stars: ✭ 334 (+0%)
Mutual labels:  fast

cheap-ruler Build Status

A collection of very fast approximations to common geodesic measurements. Useful for performance-sensitive code that measures things on a city scale. Can be an order of magnitude faster than corresponding Turf methods.

The approximations are based on the WGS84 ellipsoid model of the Earth, projecting coordinates to a flat surface that approximates the ellipsoid around a certain latitude. For distances under 500 kilometers and not on the poles, the results are very precise — within 0.1% margin of error compared to Vincenti formulas, and usually much less for shorter distances.

Usage

var ruler = new CheapRuler(35.05, 'miles'); // calculations around latitude 35
...
var distance = ruler.distance([30.51, 50.32], [30.52, 50.312]);
var lineLength = ruler.lineDistance(line.geometry.coordinates);
var bbox = ruler.bufferPoint([30.5, 50.5], 0.01);

Note: to get the full performance benefit, create a ruler object only once per a general area of calculation, and then reuse it as much as possible. Don't create a new ruler for every calculation.

Creating a ruler object

new CheapRuler(latitude[, units])

Creates a ruler object that will approximate measurements around the given latitude. Units are one of: kilometers (default), miles, nauticalmiles, meters, yards, feet, inches.

const ruler = new CheapRuler(50.5, 'meters');

CheapRuler.fromTile(y, z[, units])

Creates a ruler object from tile coordinates (y and z).

const ruler = CheapRuler.fromTile(1567, 12);

Ruler methods

distance(a, b)

Given two points of the form [longitude, latitude], returns the distance.

const distance = ruler.distance([30.5, 50.5], [30.51, 50.49]);

bearing(a, b)

Returns the bearing between two points in angles.

const bearing = ruler.bearing([30.5, 50.5], [30.51, 50.49]);

destination(p, dist, bearing)

Returns a new point given distance and bearing from the starting point.

const point = ruler.destination([30.5, 50.5], 0.1, 90);

offset(p, dx, dy)

Returns a new point given easting and northing offsets from the starting point.

const point = ruler.offset([30.5, 50.5], 10, 5); // 10km east and 5km north

lineDistance(line)

Given a line (an array of points), returns the total line distance.

const length = ruler.lineDistance([
    [-67.031, 50.458], [-67.031, 50.534],
    [-66.929, 50.534], [-66.929, 50.458]
]);

area(polygon)

Given a polygon (an array of rings, where each ring is an array of points), returns the area. Note that it returns the value in the specified units (square kilometers by default) rather than square meters as in turf.area.

const area = ruler.area([[
    [-67.031, 50.458], [-67.031, 50.534], [-66.929, 50.534],
    [-66.929, 50.458], [-67.031, 50.458]
]]);

pointToSegmentDistance(p, a, b)

Returns the distance from a point p to a line segment a to b.

const distance = ruler.pointToSegmentDistance([-77.034076, 38.882017],
    [-77.031669, 38.878605], [-77.029609, 38.881946]);

along(line, dist)

Returns the point at a specified distance along the line.

const point = ruler.along(line, 2.5);

pointOnLine(line, p)

Returns an object of the form {point, index, t}, where point is closest point on the line from the given point, index is the start index of the segment with the closest point, and t is a parameter from 0 to 1 that indicates where the closest point is on that segment.

const point = ruler.pointOnLine(line, [-67.04, 50.5]).point;

lineSlice(start, stop, line)

Returns a part of the given line between the start and the stop points (or their closest points on the line).

const part = ruler.lineSlice([-67.04, 50.5], [-67.05, 50.56], line);

lineSliceAlong(startDist, stopDist, line)

Returns a part of the given line between the start and the stop points indicated by distance along the line.

const part = ruler.lineSliceAlong(10, 20, line);

bufferPoint(p, buffer)

Given a point, returns a bounding box object ([w, s, e, n]) created from the given point buffered by a given distance.

const bbox = ruler.bufferPoint([30.5, 50.5], 0.01);

bufferBBox(bbox, buffer)

Given a bounding box, returns the box buffered by a given distance.

const bbox = ruler.bufferBBox([30.5, 50.5, 31, 51], 0.2);

insideBBox(p, bbox)

Returns true if the given point is inside in the given bounding box, otherwise false.

const inside = ruler.insideBBox([30.5, 50.5], [30, 50, 31, 51]);

Units conversion

Multipliers for converting between units are also exposed in CheapRuler.units:

// convert 50 meters to yards
50 * CheapRuler.units.yards / CheapRuler.units.meters;

If you don't specify units when creating a ruler object, you can use these constants to convert return values (using multiplication) and input arguments (using division) to any units:

// get distance between points in feet
const distanceInFeet = ruler.distance(a, b) * CheapRuler.units.feet;

// make a bbox from a point with a 200 inch buffer
const box = ruler.bufferPoint(p, 200 / CheapRuler.units.inches);

Install

Precision

A table that shows the margin of error for ruler.distance compared to node-vincenty (a state of the art distance formula):

lat 10° 20° 30° 40° 50° 60° 70° 80°
1km 0% 0% 0% 0% 0% 0% 0% 0% 0%
100km 0% 0% 0% 0% 0% 0% 0% 0.01% 0.03%
500km 0.01% 0.01% 0.01% 0.01% 0.02% 0.04% 0.08% 0.2% 0.83%
1000km 0.03% 0.03% 0.04% 0.06% 0.1% 0.17% 0.33% 0.8% 3.38%

Errors for all other methods are similar.

Related

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].