Gathering detailed insights and metrics for cheap-ruler
Gathering detailed insights and metrics for cheap-ruler
Gathering detailed insights and metrics for cheap-ruler
Gathering detailed insights and metrics for cheap-ruler
npm install cheap-ruler
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
417 Stars
113 Commits
32 Forks
105 Watching
1 Branches
546 Contributors
Updated on 13 Oct 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-4.8%
52,128
Compared to previous day
Last week
4.3%
284,997
Compared to previous week
Last month
3.8%
1,199,021
Compared to previous month
Last year
1,686.1%
8,769,790
Compared to previous year
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.
1var ruler = new CheapRuler(35.05, 'miles'); // calculations around latitude 35 2... 3var distance = ruler.distance([30.51, 50.32], [30.52, 50.312]); 4var lineLength = ruler.lineDistance(line.geometry.coordinates); 5var 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.
Creates a ruler object that will approximate measurements around the given latitude.
Units are one of: kilometers
(default), miles
, nauticalmiles
, meters
, yards
, feet
, inches
.
1const ruler = new CheapRuler(50.5, 'meters');
Creates a ruler object from tile coordinates (y
and z
).
1const ruler = CheapRuler.fromTile(1567, 12);
Given two points of the form [longitude, latitude]
, returns the distance.
1const distance = ruler.distance([30.5, 50.5], [30.51, 50.49]);
Returns the bearing between two points in angles.
1const bearing = ruler.bearing([30.5, 50.5], [30.51, 50.49]);
Returns a new point given distance and bearing from the starting point.
1const point = ruler.destination([30.5, 50.5], 0.1, 90);
Returns a new point given easting and northing offsets from the starting point.
1const point = ruler.offset([30.5, 50.5], 10, 5); // 10km east and 5km north
Given a line (an array of points), returns the total line distance.
1const length = ruler.lineDistance([ 2 [-67.031, 50.458], [-67.031, 50.534], 3 [-66.929, 50.534], [-66.929, 50.458] 4]);
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
.
1const area = ruler.area([[ 2 [-67.031, 50.458], [-67.031, 50.534], [-66.929, 50.534], 3 [-66.929, 50.458], [-67.031, 50.458] 4]]);
Returns the distance from a point p
to a line segment a
to b
.
1const distance = ruler.pointToSegmentDistance([-77.034076, 38.882017], 2 [-77.031669, 38.878605], [-77.029609, 38.881946]);
Returns the point at a specified distance along the line.
1const point = ruler.along(line, 2.5);
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.
1const point = ruler.pointOnLine(line, [-67.04, 50.5]).point;
Returns a part of the given line between the start and the stop points (or their closest points on the line).
1const part = ruler.lineSlice([-67.04, 50.5], [-67.05, 50.56], line);
Returns a part of the given line between the start and the stop points indicated by distance along the line.
1const part = ruler.lineSliceAlong(10, 20, line);
Given a point, returns a bounding box object ([w, s, e, n]
) created from the given point buffered by a given distance.
1const bbox = ruler.bufferPoint([30.5, 50.5], 0.01);
Given a bounding box, returns the box buffered by a given distance.
1const bbox = ruler.bufferBBox([30.5, 50.5, 31, 51], 0.2);
Returns true if the given point is inside in the given bounding box, otherwise false.
1const inside = ruler.insideBBox([30.5, 50.5], [30, 50, 31, 51]);
Multipliers for converting between units are also exposed in CheapRuler.units
:
1// convert 50 meters to yards 250 * 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:
1// get distance between points in feet
2const distanceInFeet = ruler.distance(a, b) * CheapRuler.units.feet;
3
4// make a bbox from a point with a 200 inch buffer
5const box = ruler.bufferPoint(p, 200 / CheapRuler.units.inches);
npm install cheap-ruler
A table that shows the margin of error for ruler.distance
compared to node-vincenty
(a state of the art distance formula):
lat | 0° | 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.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
Found 7/29 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More