Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/great-circle

Package Overview
Dependencies
Maintainers
4
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/great-circle - npm Package Compare versions

Comparing version 5.0.4 to 5.0.5

lib/arc.js

6

index.js
import { getCoord } from '@turf/invariant';
import { GreatCircle } from './arc';
import { GreatCircle } from './lib/arc';

@@ -8,4 +8,4 @@ /**

* @name greatCircle
* @param {Geometry|Feature<Point>|Array<number>} start source point feature
* @param {Geometry|Feature<Point>|Array<number>} end destination point feature
* @param {Coord} start source point feature
* @param {Coord} end destination point feature
* @param {Object} [options={}] Optional parameters

@@ -12,0 +12,0 @@ * @param {Object} [options.properties={}] line feature properties

'use strict';
var invariant = require('@turf/invariant');
/**
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
*/
/**
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
*/
/**
* Units of measurement factors based on 1 meter.
*/
/**
* Area of measurement factors based on 1 square meter.
*/
/**
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
*
* @name feature
* @param {Geometry} geometry input geometry
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature} a GeoJSON Feature
* @example
* var geometry = {
* "type": "Point",
* "coordinates": [110, 50]
* };
*
* var feature = turf.feature(geometry);
*
* //=feature
*/
/**
* Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
* For GeometryCollection type use `helpers.geometryCollection`
*
* @name geometry
* @param {string} type Geometry Type
* @param {Array<number>} coordinates Coordinates
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @returns {Geometry} a GeoJSON Geometry
* @example
* var type = 'Point';
* var coordinates = [110, 50];
*
* var geometry = turf.geometry(type, coordinates);
*
* //=geometry
*/
/**
* Takes coordinates and properties (optional) and returns a new {@link Point} feature.
*
* @name point
* @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees)
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<Point>} a Point feature
* @example
* var point = turf.point([-75.343, 39.984]);
*
* //=point
*/
/**
* Takes an array of LinearRings and optionally an {@link Object} with properties and returns a {@link Polygon} feature.
*
* @name polygon
* @param {Array<Array<Array<number>>>} coordinates an array of LinearRings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<Polygon>} a Polygon feature
* @throws {Error} throw an error if a LinearRing of the polygon has too few positions
* or if a LinearRing of the Polygon does not have matching Positions at the beginning & end.
* @example
* var polygon = turf.polygon([[
* [-2.275543, 53.464547],
* [-2.275543, 53.489271],
* [-2.215118, 53.489271],
* [-2.215118, 53.464547],
* [-2.275543, 53.464547]
* ]], { name: 'poly1', population: 400});
*
* //=polygon
*/
/**
* Creates a {@link LineString} based on a
* coordinate array. Properties can be added optionally.
*
* @name lineString
* @param {Array<Array<number>>} coordinates an array of Positions
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<LineString>} a LineString feature
* @throws {Error} if no coordinates are passed
* @example
* var linestring1 = turf.lineString([
* [-21.964416, 64.148203],
* [-21.956176, 64.141316],
* [-21.93901, 64.135924],
* [-21.927337, 64.136673]
* ]);
* var linestring2 = turf.lineString([
* [-21.929054, 64.127985],
* [-21.912918, 64.134726],
* [-21.916007, 64.141016],
* [-21.930084, 64.14446]
* ], {name: 'line 1', distance: 145});
*
* //=linestring1
*
* //=linestring2
*/
/**
* Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
*
* @name featureCollection
* @param {Feature[]} features input features
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {FeatureCollection} a FeatureCollection of input features
* @example
* var features = [
* turf.point([-75.343, 39.984], {name: 'Location A'}),
* turf.point([-75.833, 39.284], {name: 'Location B'}),
* turf.point([-75.534, 39.123], {name: 'Location C'})
* ];
*
* var collection = turf.featureCollection(features);
*
* //=collection
*/
/**
* Creates a {@link Feature<MultiLineString>} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiLineString
* @param {Array<Array<Array<number>>>} coordinates an array of LineStrings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<MultiLineString>} a MultiLineString feature
* @throws {Error} if no coordinates are passed
* @example
* var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
*
* //=multiLine
*/
/**
* Creates a {@link Feature<MultiPoint>} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiPoint
* @param {Array<Array<number>>} coordinates an array of Positions
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<MultiPoint>} a MultiPoint feature
* @throws {Error} if no coordinates are passed
* @example
* var multiPt = turf.multiPoint([[0,0],[10,10]]);
*
* //=multiPt
*/
/**
* Creates a {@link Feature<MultiPolygon>} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiPolygon
* @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygons
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<MultiPolygon>} a multipolygon feature
* @throws {Error} if no coordinates are passed
* @example
* var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
*
* //=multiPoly
*
*/
/**
* Creates a {@link Feature<GeometryCollection>} based on a
* coordinate array. Properties can be added optionally.
*
* @name geometryCollection
* @param {Array<Geometry>} geometries an array of GeoJSON Geometries
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {string|number} [id] Identifier
* @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature
* @example
* var pt = {
* "type": "Point",
* "coordinates": [100, 0]
* };
* var line = {
* "type": "LineString",
* "coordinates": [ [101, 0], [102, 1] ]
* };
* var collection = turf.geometryCollection([pt, line]);
*
* //=collection
*/
/**
* Round number to precision
*
* @param {number} num Number
* @param {number} [precision=0] Precision
* @returns {number} rounded number
* @example
* turf.round(120.4321)
* //=120
*
* turf.round(120.4321, 2)
* //=120.43
*/
/**
* Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @name radiansToLength
* @param {number} radians in radians across the sphere
* @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.
* @returns {number} distance
*/
/**
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @name lengthToRadians
* @param {number} distance in real units
* @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.
* @returns {number} radians
*/
/**
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
*
* @name lengthToDegrees
* @param {number} distance in real units
* @param {string} [units='kilometers'] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.
* @returns {number} degrees
*/
/**
* Converts any bearing angle from the north line direction (positive clockwise)
* and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
*
* @name bearingToAzimuth
* @param {number} bearing angle, between -180 and +180 degrees
* @returns {number} angle between 0 and 360 degrees
*/
/**
* Converts an angle in radians to degrees
*
* @name radiansToDegrees
* @param {number} radians angle in radians
* @returns {number} degrees between 0 and 360 degrees
*/
/**
* Converts an angle in degrees to radians
*
* @name degreesToradians
* @param {number} degrees angle between 0 and 360 degrees
* @returns {number} angle in radians
*/
/**
* Converts a length to the requested unit.
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @param {number} length to be converted
* @param {string} originalUnit of the length
* @param {string} [finalUnit='kilometers'] returned unit
* @returns {number} the converted length
*/
/**
* Converts a area to the requested unit.
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeter, acre, mile, yard, foot, inch
* @param {number} area to be converted
* @param {string} [originalUnit='meters'] of the distance
* @param {string} [finalUnit='kilometers'] returned unit
* @returns {number} the converted distance
*/
/**
* isNumber
*
* @param {*} num Number to validate
* @returns {boolean} true/false
* @example
* turf.isNumber(123)
* //=true
* turf.isNumber('foo')
* //=false
*/
function isNumber(num) {
return !isNaN(num) && num !== null && !Array.isArray(num);
}
/**
* isObject
*
* @param {*} input variable to validate
* @returns {boolean} true/false
* @example
* turf.isObject({elevation: 10})
* //=true
* turf.isObject('foo')
* //=false
*/
// Deprecated methods
/**
* Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.
*
* @name getCoord
* @param {Array<number>|Geometry<Point>|Feature<Point>} obj Object
* @returns {Array<number>} coordinates
* @example
* var pt = turf.point([10, 10]);
*
* var coord = turf.getCoord(pt);
* //= [10, 10]
*/
function getCoord(obj) {
if (!obj) { throw new Error('obj is required'); }
var coordinates = getCoords(obj);
// getCoord() must contain at least two numbers (Point)
if (coordinates.length > 1 && isNumber(coordinates[0]) && isNumber(coordinates[1])) {
return coordinates;
} else {
throw new Error('Coordinate is not a valid Point');
}
}
/**
* Unwrap coordinates from a Feature, Geometry Object or an Array of numbers
*
* @name getCoords
* @param {Array<number>|Geometry|Feature} obj Object
* @returns {Array<number>} coordinates
* @example
* var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);
*
* var coord = turf.getCoords(poly);
* //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]
*/
function getCoords(obj) {
if (!obj) { throw new Error('obj is required'); }
var coordinates;
// Array of numbers
if (obj.length) {
coordinates = obj;
// Geometry Object
} else if (obj.coordinates) {
coordinates = obj.coordinates;
// Feature
} else if (obj.geometry && obj.geometry.coordinates) {
coordinates = obj.geometry.coordinates;
}
// Checks if coordinates contains a number
if (coordinates) {
containsNumber(coordinates);
return coordinates;
}
throw new Error('No valid coordinates');
}
/**
* Checks if coordinates contains a number
*
* @name containsNumber
* @param {Array<any>} coordinates GeoJSON Coordinates
* @returns {boolean} true if Array contains a number
*/
function containsNumber(coordinates) {
if (coordinates.length > 1 && isNumber(coordinates[0]) && isNumber(coordinates[1])) {
return true;
}
if (Array.isArray(coordinates[0]) && coordinates[0].length) {
return containsNumber(coordinates[0]);
}
throw new Error('coordinates must only contain numbers');
}
/**
* Enforce expectations about types of GeoJSON objects for Turf.
*
* @name geojsonType
* @param {GeoJSON} value any GeoJSON object
* @param {string} type expected GeoJSON type
* @param {string} name name of calling function
* @throws {Error} if value is not the expected type.
*/
/**
* Enforce expectations about types of {@link Feature} inputs for Turf.
* Internally this uses {@link geojsonType} to judge geometry types.
*
* @name featureOf
* @param {Feature} feature a feature with an expected geometry type
* @param {string} type expected GeoJSON type
* @param {string} name name of calling function
* @throws {Error} error if value is not the expected type.
*/
/**
* Enforce expectations about types of {@link FeatureCollection} inputs for Turf.
* Internally this uses {@link geojsonType} to judge geometry types.
*
* @name collectionOf
* @param {FeatureCollection} featureCollection a FeatureCollection for which features will be judged
* @param {string} type expected GeoJSON type
* @param {string} name name of calling function
* @throws {Error} if value is not the expected type.
*/
/**
* Get Geometry from Feature or Geometry Object
*
* @param {Feature|Geometry} geojson GeoJSON Feature or Geometry Object
* @returns {Geometry|null} GeoJSON Geometry Object
* @throws {Error} if geojson is not a Feature or Geometry Object
* @example
* var point = {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [110, 40]
* }
* }
* var geom = turf.getGeom(point)
* //={"type": "Point", "coordinates": [110, 40]}
*/
/**
* Get Geometry Type from Feature or Geometry Object
*
* @throws {Error} **DEPRECATED** in v5.0.0 in favor of getType
*/
/**
* Get GeoJSON object's type, Geometry type is prioritize.
*
* @param {GeoJSON} geojson GeoJSON object
* @param {string} [name] name of the variable to display in error message
* @returns {string} GeoJSON type
* @example
* var point = {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [110, 40]
* }
* }
* var geom = turf.getType(point)
* //="Point"
*/
var D2R = Math.PI / 180;

@@ -41,2 +558,4 @@ var R2D = 180 / Math.PI;

Arc.prototype.json = function () {
var this$1 = this;
if (this.geometries.length <= 0) {

@@ -53,3 +572,3 @@ return {'geometry': { 'type': 'LineString', 'coordinates': null },

for (var i = 0; i < this.geometries.length; i++) {
multiline.push(this.geometries[i].coords);
multiline.push(this$1.geometries[i].coords);
}

@@ -64,2 +583,4 @@ return {'geometry': { 'type': 'MultiLineString', 'coordinates': multiline },

Arc.prototype.wkt = function () {
var this$1 = this;
var wkt_string = '';

@@ -69,6 +590,6 @@ var wkt = 'LINESTRING(';

for (var i = 0; i < this.geometries.length; i++) {
if (this.geometries[i].coords.length === 0) {
if (this$1.geometries[i].coords.length === 0) {
return 'LINESTRING(empty)';
} else {
var coords = this.geometries[i].coords;
var coords = this$1.geometries[i].coords;
coords.forEach(collect);

@@ -131,2 +652,4 @@ wkt_string += wkt.substring(0, wkt.length - 1) + ')';

GreatCircle.prototype.Arc = function (npoints, options) {
var this$1 = this;
var first_pass = [];

@@ -140,3 +663,3 @@ if (!npoints || npoints <= 2) {

var step = delta * i;
var pair = this.interpolate(step);
var pair = this$1.interpolate(step);
first_pass.push(pair);

@@ -255,4 +778,4 @@ }

* @name greatCircle
* @param {Geometry|Feature<Point>|Array<number>} start source point feature
* @param {Geometry|Feature<Point>|Array<number>} end destination point feature
* @param {Coord} start source point feature
* @param {Coord} end destination point feature
* @param {Object} [options={}] Optional parameters

@@ -276,3 +799,3 @@ * @param {Object} [options.properties={}] line feature properties

options = options || {};
if (typeof options !== 'object') throw new Error('options is invalid');
if (typeof options !== 'object') { throw new Error('options is invalid'); }
var properties = options.properties;

@@ -282,4 +805,4 @@ var npoints = options.npoints;

start = invariant.getCoord(start);
end = invariant.getCoord(end);
start = getCoord(start);
end = getCoord(end);
properties = properties || {};

@@ -286,0 +809,0 @@ npoints = npoints || 100;

{
"name": "@turf/great-circle",
"version": "5.0.4",
"version": "5.0.5",
"description": "turf great-circle module",
"main": "main",
"module": "index",
"jsnext:main": "index",
"module": "main.mjs",
"jsnext:main": "main.mjs",
"types": "index.d.ts",

@@ -12,4 +12,5 @@ "files": [

"index.d.ts",
"arc.js",
"main.js"
"main.js",
"main.mjs",
"lib"
],

@@ -19,3 +20,4 @@ "scripts": {

"test": "node -r @std/esm test.js",
"bench": "node -r @std/esm bench.js"
"bench": "node -r @std/esm bench.js",
"docs": "node ../../scripts/generate-readmes"
},

@@ -46,6 +48,8 @@ "repository": {

"@std/esm": "*",
"@turf/truncate": "^5.0.4",
"@turf/truncate": "*",
"benchmark": "*",
"load-json-file": "*",
"rollup": "*",
"rollup-plugin-buble": "*",
"rollup-plugin-node-resolve": "*",
"tape": "*",

@@ -52,0 +56,0 @@ "write-json-file": "*"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc