Socket
Socket
Sign inDemoInstall

@turf/helpers

Package Overview
Dependencies
Maintainers
4
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/helpers - npm Package Compare versions

Comparing version 5.0.4 to 5.1.0

lib/geojson.d.ts

192

index.d.ts

@@ -1,8 +0,16 @@

/// <reference types='geojson' />
import {
Id, Properties, BBox, Position,
Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon,
GeometryObject, GeoJSONObject, GeometryCollection, Geometry,
GeometryTypes, Types, CollectionTypes, Geometries,
Feature, FeatureCollection
} from './lib/geojson'
export {
Id, Properties, BBox, Position,
Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon,
GeometryObject, GeoJSONObject, GeometryCollection, Geometry,
GeometryTypes, Types, CollectionTypes, Geometries,
Feature, FeatureCollection
}
// GeoJSON Foreign Members
export type Id = string | number;
export type Properties = object;
export type BBox = [number, number, number, number];
// TurfJS Combined Types

@@ -13,32 +21,16 @@ export type Coord = Feature<Point> | Point | Position;

export type Units = 'miles' | 'nauticalmiles' | 'degrees' | 'radians' | 'inches' | 'yards' | 'meters' | 'metres' | 'kilometers' | 'kilometres';
export type Geometry = 'Point' | 'LineString' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon';
export type Grid = 'point' | 'square' | 'hex' | 'triangle';
export type Collection = 'FeatureCollection' | 'GeometryCollection';
export type Types = 'Feature' | Geometry | Collection;
export type Corners = 'sw' | 'se' | 'nw' | 'ne' | 'center' | 'centroid';
export type Lines = LineString | MultiLineString | Polygon | MultiPolygon;
export type AllGeoJSON = Feature | FeatureCollection | Geometry | GeometryCollection;
// GeoJSON Geometry Types
export type Position = GeoJSON.Position;
export type Point = GeoJSON.Point;
export type MultiPoint = GeoJSON.MultiPoint;
export type MultiLineString = GeoJSON.MultiLineString;
export type LineString = GeoJSON.LineString;
export type Polygon = GeoJSON.Polygon;
export type MultiPolygon = GeoJSON.MultiPolygon;
export type Geometries = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;
export type GeometryObject = GeoJSON.GeometryObject;
export type GeometryCollection = GeoJSON.GeometryCollection;
interface FeatureOptions {
id?: Id;
bbox?: BBox;
}
// GeoJSON Feature Objects
export type FeatureCollection<T extends GeometryObject> = GeoJSON.FeatureCollection<T>;
export type Feature<T extends GeometryObject> = GeoJSON.Feature<T>;
export interface FeatureGeometryCollection extends Feature<any> {
geometry: GeometryCollection;
interface GeometryOptions {
bbox?: BBox;
}
export interface ExtendedFeatureCollection<Feat extends Feature<any>> {
type: 'FeatureCollection';
features: Feat[];
}
export type AllGeoJSON = Feature<any> | FeatureCollection<any> | FeatureGeometryCollection | GeometryObject | GeometryCollection;

@@ -48,3 +40,3 @@ /**

*/
export function feature<T extends GeometryObject>(geometry: T, properties?: Properties, bbox?: BBox, id?: Id): Feature<T>;
export function feature<G extends Geometry | GeometryCollection, P = Properties>(geometry: G, properties?: P, options?: FeatureOptions): Feature<G, P>;

@@ -54,4 +46,4 @@ /**

*/
export function featureCollection<Geom extends GeometryObject>(features: Feature<Geom>[], bbox?: BBox, id?: Id): FeatureCollection<Geom>;
export function featureCollection(features: Feature<any>[], bbox?: BBox, id?: Id): FeatureCollection<any>;
export function featureCollection<G extends Geometry, P = Properties>(features: Feature<G, P>[], options?: FeatureOptions): FeatureCollection<G, P>;
export function featureCollection(features: Feature<any>[], options?: FeatureOptions): FeatureCollection<any>;

@@ -61,9 +53,9 @@ /**

*/
export function geometry(type: 'Point', coordinates: Position, bbox?: BBox): Point;
export function geometry(type: 'LineString', coordinates: Position[], bbox?: BBox): LineString;
export function geometry(type: 'Polygon', coordinates: Position[][], bbox?: BBox): Polygon;
export function geometry(type: 'MultiPoint', coordinates: Position[], bbox?: BBox): MultiPoint;
export function geometry(type: 'MultiLineString', coordinates: Position[][], bbox?: BBox): MultiLineString;
export function geometry(type: 'MultiPolygon', coordinates: Position[][][], bbox?: BBox): MultiPolygon;
export function geometry(type: Geometry | string, coordinates: any[], bbox?: BBox): GeometryObject;
export function geometry(type: 'Point', coordinates: Position, options?: GeometryOptions): Point;
export function geometry(type: 'LineString', coordinates: Position[], options?: GeometryOptions): LineString;
export function geometry(type: 'Polygon', coordinates: Position[][], options?: GeometryOptions): Polygon;
export function geometry(type: 'MultiPoint', coordinates: Position[], options?: GeometryOptions): MultiPoint;
export function geometry(type: 'MultiLineString', coordinates: Position[][], options?: GeometryOptions): MultiLineString;
export function geometry(type: 'MultiPolygon', coordinates: Position[][][], options?: GeometryOptions): MultiPolygon;
export function geometry(type: string, coordinates: any[], options?: GeometryOptions): Geometry;

@@ -73,18 +65,34 @@ /**

*/
export function point(coordinates: Position, properties?: Properties, bbox?: BBox, id?: Id): Feature<Point>;
export function point<P = Properties>(coordinates: Position, properties?: P, options?: FeatureOptions): Feature<Point, P>;
/**
* http://turfjs.org/docs/#points
*/
export function points<P = Properties>(coordinates: Position[], properties?: P, options?: FeatureOptions): FeatureCollection<Point, P>;
/**
* http://turfjs.org/docs/#polygon
*/
export function polygon(coordinates: Position[][], properties?: Properties, bbox?: BBox, id?: Id): Feature<Polygon>;
export function polygon<P = Properties>(coordinates: Position[][], properties?: P, options?: FeatureOptions): Feature<Polygon, P>;
/**
* http://turfjs.org/docs/#polygons
*/
export function polygons<P = Properties>(coordinates: Position[][][], properties?: P, options?: FeatureOptions): FeatureCollection<Polygon, P>;
/**
* http://turfjs.org/docs/#linestring
*/
export function lineString(coordinates: Position[], properties?: Properties, bbox?: BBox, id?: Id): Feature<LineString>;
export function lineString<P = Properties>(coordinates: Position[], properties?: P, options?: FeatureOptions): Feature<LineString, P>;
/**
* http://turfjs.org/docs/#linestrings
*/
export function lineStrings<P = Properties>(coordinates: Position[][], properties?: P, options?: FeatureOptions): FeatureCollection<LineString, P>;
/**
* http://turfjs.org/docs/#multilinestring
*/
export function multiLineString(coordinates: Position[][], properties?: Properties, bbox?: BBox, id?: Id): Feature<MultiLineString>;
export function multiLineString<P = Properties>(coordinates: Position[][], properties?: P, options?: FeatureOptions): Feature<MultiLineString, P>;

@@ -94,3 +102,3 @@ /**

*/
export function multiPoint(coordinates: Position[], properties?: Properties, bbox?: BBox, id?: Id): Feature<MultiPoint>;
export function multiPoint<P = Properties>(coordinates: Position[], properties?: P, options?: FeatureOptions): Feature<MultiPoint, P>;

@@ -100,3 +108,3 @@ /**

*/
export function multiPolygon(coordinates: Position[][][], properties?: Properties, bbox?: BBox, id?: Id): Feature<MultiPolygon>;
export function multiPolygon<P = Properties>(coordinates: Position[][][], properties?: P, options?: FeatureOptions): Feature<MultiPolygon, P>;

@@ -106,3 +114,3 @@ /**

*/
export function geometryCollection(geometries: GeometryObject[], properties?: Properties, bbox?: BBox, id?: Id): FeatureGeometryCollection;
export function geometryCollection<P = Properties>(geometries: Geometries[], properties?: P, options?: FeatureOptions): Feature<GeometryCollection, P>;

@@ -112,3 +120,3 @@ /**

*/
export function radiansToLength(radians: number, units?: Units): number
export function radiansToLength(radians: number, units?: Units): number;

@@ -118,3 +126,3 @@ /**

*/
export function lengthToRadians(distance: number, units?: Units): number
export function lengthToRadians(distance: number, units?: Units): number;

@@ -124,3 +132,3 @@ /**

*/
export function lengthToDegrees(distance: number, units?: Units): number
export function lengthToDegrees(distance: number, units?: Units): number;

@@ -130,3 +138,3 @@ /**

*/
export function bearingToAzimuth(bearing: number): number
export function bearingToAzimuth(bearing: number): number;

@@ -136,3 +144,3 @@ /**

*/
export function radiansToDegrees(radians: number): number
export function radiansToDegrees(radians: number): number;

@@ -142,3 +150,3 @@ /**

*/
export function degreesToRadians(degrees: number): number
export function degreesToRadians(degrees: number): number;

@@ -148,3 +156,3 @@ /**

*/
export function round(num: number, precision?: number): number
export function round(num: number, precision?: number): number;

@@ -154,3 +162,3 @@ /**

*/
export function convertLength(length: number, originalUnit: Units, finalUnit?: Units): number
export function convertLength(length: number, originalUnit: Units, finalUnit?: Units): number;

@@ -160,3 +168,3 @@ /**

*/
export function convertArea(area: number, originalUnit?: Units, finalUnit?: Units): number
export function convertArea(area: number, originalUnit?: Units, finalUnit?: Units): number;

@@ -166,3 +174,3 @@ /**

*/
export function isNumber(num: any): boolean
export function isNumber(num: any): boolean;

@@ -172,3 +180,3 @@ /**

*/
export function isObject(input: any): boolean
export function isObject(input: any): boolean;

@@ -184,11 +192,11 @@ /**

export const factors: {
meters: number
millimeters: number
centimeters: number
kilometers: number
miles: number
nauticalmiles: number
inches: number
yards: number
feet: number
meters: number;
millimeters: number;
centimeters: number;
kilometers: number;
miles: number;
nauticalmiles: number;
inches: number;
yards: number;
feet: number;
}

@@ -200,13 +208,13 @@

export const unitsFactors: {
meters: number
millimeters: number
centimeters: number
kilometers: number
miles: number
nauticalmiles: number
inches: number
yards: number
feet: number
radians: number
degrees: number
meters: number;
millimeters: number;
centimeters: number;
kilometers: number;
miles: number;
nauticalmiles: number;
inches: number;
yards: number;
feet: number;
radians: number;
degrees: number;
};

@@ -218,11 +226,21 @@

export const areaFactors: {
meters: number
millimeters: number
centimeters: number
kilometers: number
acres: number
miles: number
yards: number
feet: number
inches: number
meters: number;
millimeters: number;
centimeters: number;
kilometers: number;
acres: number;
miles: number;
yards: number;
feet: number;
inches: number;
};
/**
* Validate Id
*/
export function validateId(id: Id): void;
/**
* Validate BBox
*/
export function validateBBox(bbox: BBox): void;

@@ -73,4 +73,5 @@ /**

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a GeoJSON Feature

@@ -87,11 +88,16 @@ * @example

*/
export function feature(geometry, properties, bbox, id) {
export function feature(geometry, properties, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var bbox = options.bbox;
var id = options.id;
// Validation
if (geometry === undefined) throw new Error('geometry is required');
if (properties && properties.constructor !== Object) throw new Error('properties must be an Object');
if (bbox) {
if (!Array.isArray(bbox)) throw new Error('bbox must be an Array');
if (bbox.length !== 4) throw new Error('bbox must be an Array of 4 numbers');
}
if (id && ['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');
if (bbox) validateBBox(bbox);
if (id) validateId(id);
// Main
var feat = {type: 'Feature'};

@@ -112,3 +118,4 @@ if (id) feat.id = id;

* @param {Array<number>} coordinates Coordinates
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Geometry
* @returns {Geometry} a GeoJSON Geometry

@@ -123,3 +130,8 @@ * @example

*/
export function geometry(type, coordinates, bbox) {
export function geometry(type, coordinates, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var bbox = options.bbox;
// Validation

@@ -129,4 +141,5 @@ if (!type) throw new Error('type is required');

if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
if (bbox && bbox.length !== 4) throw new Error('bbox must be an Array of 4 numbers');
if (bbox) validateBBox(bbox);
// Main
var geom;

@@ -147,3 +160,3 @@ switch (type) {

/**
* Takes coordinates and properties (optional) and returns a new {@link Point} feature.
* Creates a {@link Point} {@link Feature} from a Position.
*

@@ -153,4 +166,5 @@ * @name point

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<Point>} a Point feature

@@ -162,7 +176,7 @@ * @example

*/
export function point(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
if (!Array.isArray(coordinates)) throw new Error('Coordinates must be an Array');
if (coordinates.length < 2) throw new Error('Coordinates must be at least 2 numbers long');
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) throw new Error('Coordinates must contain numbers');
export function point(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
if (coordinates.length < 2) throw new Error('coordinates must be at least 2 numbers long');
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) throw new Error('coordinates must contain numbers');

@@ -172,29 +186,50 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}
/**
* Takes an array of LinearRings and optionally an {@link Object} with properties and returns a {@link Polygon} feature.
* Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
*
* @name points
* @param {Array<Array<number>>} coordinates an array of Points
* @param {Object} [properties={}] Translate these properties to each Feature
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection<Point>} Point Feature
* @example
* var points = turf.points([
* [-75, 39],
* [-80, 45],
* [-78, 50]
* ]);
*
* //=points
*/
export function points(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
return featureCollection(coordinates.map(function (coords) {
return point(coords, properties);
}), options);
}
/**
* Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
*
* @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.
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<Polygon>} Polygon Feature
* @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});
* var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
*
* //=polygon
*/
export function polygon(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
export function polygon(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');

@@ -208,3 +243,3 @@ for (var i = 0; i < coordinates.length; i++) {

// Check if first point of Polygon contains two numbers
if (i === 0 && j === 0 && !isNumber(ring[0][0]) || !isNumber(ring[0][1])) throw new Error('Coordinates must contain numbers');
if (i === 0 && j === 0 && !isNumber(ring[0][0]) || !isNumber(ring[0][1])) throw new Error('coordinates must contain numbers');
if (ring[ring.length - 1][j] !== ring[0][j]) {

@@ -219,39 +254,54 @@ throw new Error('First and last Position are not equivalent.');

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}
/**
* Creates a {@link LineString} based on a
* coordinate array. Properties can be added optionally.
* Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
*
* @name polygons
* @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygon coordinates
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection<Polygon>} Polygon FeatureCollection
* @example
* var polygons = turf.polygons([
* [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
* [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
* ]);
*
* //=polygons
*/
export function polygons(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
return featureCollection(coordinates.map(function (coords) {
return polygon(coords, properties);
}), options);
}
/**
* Creates a {@link LineString} {@link Feature} from an Array of Positions.
*
* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<LineString>} LineString Feature
* @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});
* var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
* var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
*
* //=linestring1
*
* //=linestring2
*/
export function lineString(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
if (coordinates.length < 2) throw new Error('Coordinates must be an array of two or more positions');
export function lineString(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');
if (coordinates.length < 2) throw new Error('coordinates must be an array of two or more positions');
// Check if first point of LineString contains two numbers
if (!isNumber(coordinates[0][1]) || !isNumber(coordinates[0][1])) throw new Error('Coordinates must contain numbers');
if (!isNumber(coordinates[0][1]) || !isNumber(coordinates[0][1])) throw new Error('coordinates must contain numbers');

@@ -261,6 +311,33 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}
/**
* Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
*
* @name lineStrings
* @param {Array<Array<number>>} coordinates an array of LinearRings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection<LineString>} LineString FeatureCollection
* @example
* var linestrings = turf.lineStrings([
* [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
* [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
* ]);
*
* //=linestrings
*/
export function lineStrings(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
return featureCollection(coordinates.map(function (coords) {
return lineString(coords, properties);
}), options);
}
/**
* Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.

@@ -270,22 +347,33 @@ *

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {FeatureCollection} FeatureCollection of 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 locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
* var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
* var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
*
* var collection = turf.featureCollection(features);
* var collection = turf.featureCollection([
* locationA,
* locationB,
* locationC
* ]);
*
* //=collection
*/
export function featureCollection(features, bbox, id) {
export function featureCollection(features, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) throw new Error('options is invalid');
var bbox = options.bbox;
var id = options.id;
// Validation
if (!features) throw new Error('No features passed');
if (!Array.isArray(features)) throw new Error('features must be an Array');
if (bbox && bbox.length !== 4) throw new Error('bbox must be an Array of 4 numbers');
if (id && ['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');
if (bbox) validateBBox(bbox);
if (id) validateId(id);
// Main
var fc = {type: 'FeatureCollection'};

@@ -305,4 +393,5 @@ if (id) fc.id = id;

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<MultiLineString>} a MultiLineString feature

@@ -315,4 +404,4 @@ * @throws {Error} if no coordinates are passed

*/
export function multiLineString(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
export function multiLineString(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');

@@ -322,3 +411,3 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}

@@ -333,4 +422,5 @@

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<MultiPoint>} a MultiPoint feature

@@ -343,4 +433,4 @@ * @throws {Error} if no coordinates are passed

*/
export function multiPoint(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
export function multiPoint(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');

@@ -350,3 +440,3 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}

@@ -361,4 +451,5 @@

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<MultiPolygon>} a multipolygon feature

@@ -372,4 +463,4 @@ * @throws {Error} if no coordinates are passed

*/
export function multiPolygon(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
export function multiPolygon(coordinates, properties, options) {
if (!coordinates) throw new Error('coordinates is required');

@@ -379,3 +470,3 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}

@@ -390,4 +481,5 @@

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature

@@ -407,3 +499,3 @@ * @example

*/
export function geometryCollection(geometries, properties, bbox, id) {
export function geometryCollection(geometries, properties, options) {
if (!geometries) throw new Error('geometries is required');

@@ -415,3 +507,3 @@ if (!Array.isArray(geometries)) throw new Error('geometries must be an Array');

geometries: geometries
}, properties, bbox, id);
}, properties, options);
}

@@ -521,3 +613,3 @@

*
* @name degreesToradians
* @name degreesToRadians
* @param {number} degrees angle between 0 and 360 degrees

@@ -551,3 +643,3 @@ * @returns {number} angle in radians

* Converts a area to the requested unit.
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeter, acre, mile, yard, foot, inch
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches
* @param {number} area to be converted

@@ -601,2 +693,58 @@ * @param {string} [originalUnit='meters'] of the distance

/**
* Validate BBox
*
* @private
* @param {Array<number>} bbox BBox to validate
* @returns {void}
* @throws Error if BBox is not valid
* @example
* validateBBox([-180, -40, 110, 50])
* //=OK
* validateBBox([-180, -40])
* //=Error
* validateBBox('Foo')
* //=Error
* validateBBox(5)
* //=Error
* validateBBox(null)
* //=Error
* validateBBox(undefined)
* //=Error
*/
export function validateBBox(bbox) {
if (!bbox) throw new Error('bbox is required');
if (!Array.isArray(bbox)) throw new Error('bbox must be an Array');
if (bbox.length !== 4 && bbox.length !== 6) throw new Error('bbox must be an Array of 4 or 6 numbers');
bbox.forEach(function (num) {
if (!isNumber(num)) throw new Error('bbox must only contain numbers');
});
}
/**
* Validate Id
*
* @private
* @param {string|number} id Id to validate
* @returns {void}
* @throws Error if Id is not valid
* @example
* validateId([-180, -40, 110, 50])
* //=Error
* validateId([-180, -40])
* //=Error
* validateId('Foo')
* //=OK
* validateId(5)
* //=OK
* validateId(null)
* //=Error
* validateId(undefined)
* //=Error
*/
export function validateId(id) {
if (!id) throw new Error('id is required');
if (['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');
}
// Deprecated methods

@@ -603,0 +751,0 @@ export function radians2degrees() {

@@ -77,4 +77,5 @@ 'use strict';

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a GeoJSON Feature

@@ -91,14 +92,19 @@ * @example

*/
function feature(geometry, properties, bbox, id) {
if (geometry === undefined) throw new Error('geometry is required');
if (properties && properties.constructor !== Object) throw new Error('properties must be an Object');
if (bbox) {
if (!Array.isArray(bbox)) throw new Error('bbox must be an Array');
if (bbox.length !== 4) throw new Error('bbox must be an Array of 4 numbers');
}
if (id && ['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');
function feature(geometry, properties, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) { throw new Error('options is invalid'); }
var bbox = options.bbox;
var id = options.id;
// Validation
if (geometry === undefined) { throw new Error('geometry is required'); }
if (properties && properties.constructor !== Object) { throw new Error('properties must be an Object'); }
if (bbox) { validateBBox(bbox); }
if (id) { validateId(id); }
// Main
var feat = {type: 'Feature'};
if (id) feat.id = id;
if (bbox) feat.bbox = bbox;
if (id) { feat.id = id; }
if (bbox) { feat.bbox = bbox; }
feat.properties = properties || {};

@@ -116,3 +122,4 @@ feat.geometry = geometry;

* @param {Array<number>} coordinates Coordinates
* @param {Array<number>} [bbox] BBox [west, south, east, north]
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Geometry
* @returns {Geometry} a GeoJSON Geometry

@@ -127,9 +134,15 @@ * @example

*/
function geometry(type, coordinates, bbox) {
function geometry(type, coordinates, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) { throw new Error('options is invalid'); }
var bbox = options.bbox;
// Validation
if (!type) throw new Error('type is required');
if (!coordinates) throw new Error('coordinates is required');
if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
if (bbox && bbox.length !== 4) throw new Error('bbox must be an Array of 4 numbers');
if (!type) { throw new Error('type is required'); }
if (!coordinates) { throw new Error('coordinates is required'); }
if (!Array.isArray(coordinates)) { throw new Error('coordinates must be an Array'); }
if (bbox) { validateBBox(bbox); }
// Main
var geom;

@@ -145,3 +158,3 @@ switch (type) {

}
if (bbox) geom.bbox = bbox;
if (bbox) { geom.bbox = bbox; }
return geom;

@@ -151,3 +164,3 @@ }

/**
* Takes coordinates and properties (optional) and returns a new {@link Point} feature.
* Creates a {@link Point} {@link Feature} from a Position.
*

@@ -157,4 +170,5 @@ * @name point

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<Point>} a Point feature

@@ -166,7 +180,7 @@ * @example

*/
function point(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
if (!Array.isArray(coordinates)) throw new Error('Coordinates must be an Array');
if (coordinates.length < 2) throw new Error('Coordinates must be at least 2 numbers long');
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) throw new Error('Coordinates must contain numbers');
function point(coordinates, properties, options) {
if (!coordinates) { throw new Error('coordinates is required'); }
if (!Array.isArray(coordinates)) { throw new Error('coordinates must be an Array'); }
if (coordinates.length < 2) { throw new Error('coordinates must be at least 2 numbers long'); }
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) { throw new Error('coordinates must contain numbers'); }

@@ -176,29 +190,50 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}
/**
* Takes an array of LinearRings and optionally an {@link Object} with properties and returns a {@link Polygon} feature.
* Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
*
* @name points
* @param {Array<Array<number>>} coordinates an array of Points
* @param {Object} [properties={}] Translate these properties to each Feature
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection<Point>} Point Feature
* @example
* var points = turf.points([
* [-75, 39],
* [-80, 45],
* [-78, 50]
* ]);
*
* //=points
*/
function points(coordinates, properties, options) {
if (!coordinates) { throw new Error('coordinates is required'); }
if (!Array.isArray(coordinates)) { throw new Error('coordinates must be an Array'); }
return featureCollection(coordinates.map(function (coords) {
return point(coords, properties);
}), options);
}
/**
* Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
*
* @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.
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<Polygon>} Polygon Feature
* @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});
* var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
*
* //=polygon
*/
function polygon(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
function polygon(coordinates, properties, options) {
if (!coordinates) { throw new Error('coordinates is required'); }

@@ -212,3 +247,3 @@ for (var i = 0; i < coordinates.length; i++) {

// Check if first point of Polygon contains two numbers
if (i === 0 && j === 0 && !isNumber(ring[0][0]) || !isNumber(ring[0][1])) throw new Error('Coordinates must contain numbers');
if (i === 0 && j === 0 && !isNumber(ring[0][0]) || !isNumber(ring[0][1])) { throw new Error('coordinates must contain numbers'); }
if (ring[ring.length - 1][j] !== ring[0][j]) {

@@ -223,39 +258,54 @@ throw new Error('First and last Position are not equivalent.');

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}
/**
* Creates a {@link LineString} based on a
* coordinate array. Properties can be added optionally.
* Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
*
* @name polygons
* @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygon coordinates
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection<Polygon>} Polygon FeatureCollection
* @example
* var polygons = turf.polygons([
* [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
* [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
* ]);
*
* //=polygons
*/
function polygons(coordinates, properties, options) {
if (!coordinates) { throw new Error('coordinates is required'); }
if (!Array.isArray(coordinates)) { throw new Error('coordinates must be an Array'); }
return featureCollection(coordinates.map(function (coords) {
return polygon(coords, properties);
}), options);
}
/**
* Creates a {@link LineString} {@link Feature} from an Array of Positions.
*
* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<LineString>} LineString Feature
* @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});
* var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
* var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
*
* //=linestring1
*
* //=linestring2
*/
function lineString(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
if (coordinates.length < 2) throw new Error('Coordinates must be an array of two or more positions');
function lineString(coordinates, properties, options) {
if (!coordinates) { throw new Error('coordinates is required'); }
if (coordinates.length < 2) { throw new Error('coordinates must be an array of two or more positions'); }
// Check if first point of LineString contains two numbers
if (!isNumber(coordinates[0][1]) || !isNumber(coordinates[0][1])) throw new Error('Coordinates must contain numbers');
if (!isNumber(coordinates[0][1]) || !isNumber(coordinates[0][1])) { throw new Error('coordinates must contain numbers'); }

@@ -265,6 +315,33 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}
/**
* Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
*
* @name lineStrings
* @param {Array<Array<number>>} coordinates an array of LinearRings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection<LineString>} LineString FeatureCollection
* @example
* var linestrings = turf.lineStrings([
* [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
* [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
* ]);
*
* //=linestrings
*/
function lineStrings(coordinates, properties, options) {
if (!coordinates) { throw new Error('coordinates is required'); }
if (!Array.isArray(coordinates)) { throw new Error('coordinates must be an Array'); }
return featureCollection(coordinates.map(function (coords) {
return lineString(coords, properties);
}), options);
}
/**
* Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.

@@ -274,25 +351,36 @@ *

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {FeatureCollection} FeatureCollection of 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 locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
* var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
* var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
*
* var collection = turf.featureCollection(features);
* var collection = turf.featureCollection([
* locationA,
* locationB,
* locationC
* ]);
*
* //=collection
*/
function featureCollection(features, bbox, id) {
if (!features) throw new Error('No features passed');
if (!Array.isArray(features)) throw new Error('features must be an Array');
if (bbox && bbox.length !== 4) throw new Error('bbox must be an Array of 4 numbers');
if (id && ['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');
function featureCollection(features, options) {
// Optional Parameters
options = options || {};
if (!isObject(options)) { throw new Error('options is invalid'); }
var bbox = options.bbox;
var id = options.id;
// Validation
if (!features) { throw new Error('No features passed'); }
if (!Array.isArray(features)) { throw new Error('features must be an Array'); }
if (bbox) { validateBBox(bbox); }
if (id) { validateId(id); }
// Main
var fc = {type: 'FeatureCollection'};
if (id) fc.id = id;
if (bbox) fc.bbox = bbox;
if (id) { fc.id = id; }
if (bbox) { fc.bbox = bbox; }
fc.features = features;

@@ -309,4 +397,5 @@ return fc;

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<MultiLineString>} a MultiLineString feature

@@ -319,4 +408,4 @@ * @throws {Error} if no coordinates are passed

*/
function multiLineString(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
function multiLineString(coordinates, properties, options) {
if (!coordinates) { throw new Error('coordinates is required'); }

@@ -326,3 +415,3 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}

@@ -337,4 +426,5 @@

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<MultiPoint>} a MultiPoint feature

@@ -347,4 +437,4 @@ * @throws {Error} if no coordinates are passed

*/
function multiPoint(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
function multiPoint(coordinates, properties, options) {
if (!coordinates) { throw new Error('coordinates is required'); }

@@ -354,3 +444,3 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}

@@ -365,4 +455,5 @@

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<MultiPolygon>} a multipolygon feature

@@ -376,4 +467,4 @@ * @throws {Error} if no coordinates are passed

*/
function multiPolygon(coordinates, properties, bbox, id) {
if (!coordinates) throw new Error('No coordinates passed');
function multiPolygon(coordinates, properties, options) {
if (!coordinates) { throw new Error('coordinates is required'); }

@@ -383,3 +474,3 @@ return feature({

coordinates: coordinates
}, properties, bbox, id);
}, properties, options);
}

@@ -394,4 +485,5 @@

* @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
* @param {Object} [options={}] Optional Parameters
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature<GeometryCollection>} a GeoJSON GeometryCollection Feature

@@ -411,5 +503,5 @@ * @example

*/
function geometryCollection(geometries, properties, bbox, id) {
if (!geometries) throw new Error('geometries is required');
if (!Array.isArray(geometries)) throw new Error('geometries must be an Array');
function geometryCollection(geometries, properties, options) {
if (!geometries) { throw new Error('geometries is required'); }
if (!Array.isArray(geometries)) { throw new Error('geometries must be an Array'); }

@@ -419,3 +511,3 @@ return feature({

geometries: geometries
}, properties, bbox, id);
}, properties, options);
}

@@ -437,4 +529,4 @@

function round(num, precision) {
if (num === undefined || num === null || isNaN(num)) throw new Error('num is required');
if (precision && !(precision >= 0)) throw new Error('precision must be a positive number');
if (num === undefined || num === null || isNaN(num)) { throw new Error('num is required'); }
if (precision && !(precision >= 0)) { throw new Error('precision must be a positive number'); }
var multiplier = Math.pow(10, precision || 0);

@@ -454,7 +546,7 @@ return Math.round(num * multiplier) / multiplier;

function radiansToLength(radians, units) {
if (radians === undefined || radians === null) throw new Error('radians is required');
if (radians === undefined || radians === null) { throw new Error('radians is required'); }
if (units && typeof units !== 'string') throw new Error('units must be a string');
if (units && typeof units !== 'string') { throw new Error('units must be a string'); }
var factor = factors[units || 'kilometers'];
if (!factor) throw new Error(units + ' units is invalid');
if (!factor) { throw new Error(units + ' units is invalid'); }
return radians * factor;

@@ -473,7 +565,7 @@ }

function lengthToRadians(distance, units) {
if (distance === undefined || distance === null) throw new Error('distance is required');
if (distance === undefined || distance === null) { throw new Error('distance is required'); }
if (units && typeof units !== 'string') throw new Error('units must be a string');
if (units && typeof units !== 'string') { throw new Error('units must be a string'); }
var factor = factors[units || 'kilometers'];
if (!factor) throw new Error(units + ' units is invalid');
if (!factor) { throw new Error(units + ' units is invalid'); }
return distance / factor;

@@ -504,6 +596,6 @@ }

function bearingToAzimuth(bearing) {
if (bearing === null || bearing === undefined) throw new Error('bearing is required');
if (bearing === null || bearing === undefined) { throw new Error('bearing is required'); }
var angle = bearing % 360;
if (angle < 0) angle += 360;
if (angle < 0) { angle += 360; }
return angle;

@@ -520,3 +612,3 @@ }

function radiansToDegrees(radians) {
if (radians === null || radians === undefined) throw new Error('radians is required');
if (radians === null || radians === undefined) { throw new Error('radians is required'); }

@@ -530,3 +622,3 @@ var degrees = radians % (2 * Math.PI);

*
* @name degreesToradians
* @name degreesToRadians
* @param {number} degrees angle between 0 and 360 degrees

@@ -536,3 +628,3 @@ * @returns {number} angle in radians

function degreesToRadians(degrees) {
if (degrees === null || degrees === undefined) throw new Error('degrees is required');
if (degrees === null || degrees === undefined) { throw new Error('degrees is required'); }

@@ -553,4 +645,4 @@ var radians = degrees % 360;

function convertLength(length, originalUnit, finalUnit) {
if (length === null || length === undefined) throw new Error('length is required');
if (!(length >= 0)) throw new Error('length must be a positive number');
if (length === null || length === undefined) { throw new Error('length is required'); }
if (!(length >= 0)) { throw new Error('length must be a positive number'); }

@@ -562,3 +654,3 @@ return radiansToLength(lengthToRadians(length, originalUnit), finalUnit || 'kilometers');

* Converts a area to the requested unit.
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeter, acre, mile, yard, foot, inch
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches
* @param {number} area to be converted

@@ -570,10 +662,10 @@ * @param {string} [originalUnit='meters'] of the distance

function convertArea(area, originalUnit, finalUnit) {
if (area === null || area === undefined) throw new Error('area is required');
if (!(area >= 0)) throw new Error('area must be a positive number');
if (area === null || area === undefined) { throw new Error('area is required'); }
if (!(area >= 0)) { throw new Error('area must be a positive number'); }
var startFactor = areaFactors[originalUnit || 'meters'];
if (!startFactor) throw new Error('invalid original units');
if (!startFactor) { throw new Error('invalid original units'); }
var finalFactor = areaFactors[finalUnit || 'kilometers'];
if (!finalFactor) throw new Error('invalid final units');
if (!finalFactor) { throw new Error('invalid final units'); }

@@ -613,2 +705,58 @@ return (area / startFactor) * finalFactor;

/**
* Validate BBox
*
* @private
* @param {Array<number>} bbox BBox to validate
* @returns {void}
* @throws Error if BBox is not valid
* @example
* validateBBox([-180, -40, 110, 50])
* //=OK
* validateBBox([-180, -40])
* //=Error
* validateBBox('Foo')
* //=Error
* validateBBox(5)
* //=Error
* validateBBox(null)
* //=Error
* validateBBox(undefined)
* //=Error
*/
function validateBBox(bbox) {
if (!bbox) { throw new Error('bbox is required'); }
if (!Array.isArray(bbox)) { throw new Error('bbox must be an Array'); }
if (bbox.length !== 4 && bbox.length !== 6) { throw new Error('bbox must be an Array of 4 or 6 numbers'); }
bbox.forEach(function (num) {
if (!isNumber(num)) { throw new Error('bbox must only contain numbers'); }
});
}
/**
* Validate Id
*
* @private
* @param {string|number} id Id to validate
* @returns {void}
* @throws Error if Id is not valid
* @example
* validateId([-180, -40, 110, 50])
* //=Error
* validateId([-180, -40])
* //=Error
* validateId('Foo')
* //=OK
* validateId(5)
* //=OK
* validateId(null)
* //=Error
* validateId(undefined)
* //=Error
*/
function validateId(id) {
if (!id) { throw new Error('id is required'); }
if (['string', 'number'].indexOf(typeof id) === -1) { throw new Error('id must be a number or a string'); }
}
// Deprecated methods

@@ -650,4 +798,7 @@ function radians2degrees() {

exports.point = point;
exports.points = points;
exports.polygon = polygon;
exports.polygons = polygons;
exports.lineString = lineString;
exports.lineStrings = lineStrings;
exports.featureCollection = featureCollection;

@@ -669,2 +820,4 @@ exports.multiLineString = multiLineString;

exports.isObject = isObject;
exports.validateBBox = validateBBox;
exports.validateId = validateId;
exports.radians2degrees = radians2degrees;

@@ -671,0 +824,0 @@ exports.degrees2radians = degrees2radians;

{
"name": "@turf/helpers",
"version": "5.0.4",
"version": "5.1.0",
"description": "turf helpers module",
"main": "main",
"module": "index",
"jsnext:main": "index",
"main": "main.js",
"module": "main.mjs",
"types": "index.d.ts",

@@ -12,3 +11,5 @@ "files": [

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

@@ -18,3 +19,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"
},

@@ -47,2 +49,3 @@ "repository": {

"rollup": "*",
"rollup-plugin-buble": "*",
"tape": "*"

@@ -49,0 +52,0 @@ },

@@ -23,10 +23,11 @@ # @turf/helpers

Wraps a GeoJSON [Geometry](http://geojson.org/geojson-spec.html#geometry) in a GeoJSON [Feature](http://geojson.org/geojson-spec.html#feature-objects).
Wraps a GeoJSON [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1) in a GeoJSON [Feature](https://tools.ietf.org/html/rfc7946#section-3.2).
**Parameters**
- `geometry` **[Geometry](http://geojson.org/geojson-spec.html#geometry)** input geometry
- `geometry` **[Geometry](https://tools.ietf.org/html/rfc7946#section-3.1)** input geometry
- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the Feature

@@ -46,7 +47,7 @@ **Examples**

Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)** a GeoJSON Feature
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)** a GeoJSON Feature
## geometry
Creates a GeoJSON [Geometry](http://geojson.org/geojson-spec.html#geometry) from a Geometry string type & coordinates.
Creates a GeoJSON [Geometry](https://tools.ietf.org/html/rfc7946#section-3.1) from a Geometry string type & coordinates.
For GeometryCollection type use `helpers.geometryCollection`

@@ -58,3 +59,4 @@

- `coordinates` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>** Coordinates
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Geometry

@@ -72,7 +74,7 @@ **Examples**

Returns **[Geometry](http://geojson.org/geojson-spec.html#geometry)** a GeoJSON Geometry
Returns **[Geometry](https://tools.ietf.org/html/rfc7946#section-3.1)** a GeoJSON Geometry
## point
Takes coordinates and properties (optional) and returns a new [Point](http://geojson.org/geojson-spec.html#point) feature.
Creates a [Point](https://tools.ietf.org/html/rfc7946#section-3.1.2) [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) from a Position.

@@ -83,4 +85,5 @@ **Parameters**

- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the Feature

@@ -95,7 +98,33 @@ **Examples**

Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[Point](http://geojson.org/geojson-spec.html#point)>** a Point feature
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[Point](https://tools.ietf.org/html/rfc7946#section-3.1.2)>** a Point feature
## points
Creates a [Point](https://tools.ietf.org/html/rfc7946#section-3.1.2) [FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) from an Array of Point coordinates.
**Parameters**
- `coordinates` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>>** an array of Points
- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Translate these properties to each Feature (optional, default `{}`)
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the FeatureCollection
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the FeatureCollection
**Examples**
```javascript
var points = turf.points([
[-75, 39],
[-80, 45],
[-78, 50]
]);
//=points
```
Returns **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)&lt;[Point](https://tools.ietf.org/html/rfc7946#section-3.1.2)>** Point Feature
## polygon
Takes an array of LinearRings and optionally an [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) with properties and returns a [Polygon](http://geojson.org/geojson-spec.html#polygon) feature.
Creates a [Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) from an Array of LinearRings.

@@ -106,4 +135,5 @@ **Parameters**

- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the Feature

@@ -113,9 +143,3 @@ **Examples**

```javascript
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});
var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });

@@ -125,11 +149,32 @@ //=polygon

- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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.
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6)>** Polygon Feature
Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[Polygon](http://geojson.org/geojson-spec.html#polygon)>** a Polygon feature
## polygons
Creates a [Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) [FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) from an Array of Polygon coordinates.
**Parameters**
- `coordinates` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>>>>** an array of Polygon coordinates
- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the FeatureCollection
**Examples**
```javascript
var polygons = turf.polygons([
[[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
[[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
]);
//=polygons
```
Returns **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)&lt;[Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6)>** Polygon FeatureCollection
## lineString
Creates a [LineString](http://geojson.org/geojson-spec.html#linestring) based on a
coordinate array. Properties can be added optionally.
Creates a [LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4) [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) from an Array of Positions.

@@ -140,4 +185,5 @@ **Parameters**

- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the Feature

@@ -147,33 +193,46 @@ **Examples**

```javascript
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});
var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
//=linestring1
//=linestring2
```
- Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** if no coordinates are passed
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4)>** LineString Feature
Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[LineString](http://geojson.org/geojson-spec.html#linestring)>** a LineString feature
## lineStrings
Creates a [LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4) [FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) from an Array of LineString coordinates.
**Parameters**
- `coordinates` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>>** an array of LinearRings
- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the FeatureCollection
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the FeatureCollection
**Examples**
```javascript
var linestrings = turf.lineStrings([
[[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
[[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
]);
//=linestrings
```
Returns **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)&lt;[LineString](https://tools.ietf.org/html/rfc7946#section-3.1.4)>** LineString FeatureCollection
## featureCollection
Takes one or more [Features](http://geojson.org/geojson-spec.html#feature-objects) and creates a [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects).
Takes one or more [Features](https://tools.ietf.org/html/rfc7946#section-3.2) and creates a [FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3).
**Parameters**
- `features` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Feature](http://geojson.org/geojson-spec.html#feature-objects)>** input features
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier
- `features` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)>** input features
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the Feature

@@ -183,9 +242,11 @@ **Examples**

```javascript
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 locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
var collection = turf.featureCollection(features);
var collection = turf.featureCollection([
locationA,
locationB,
locationC
]);

@@ -195,3 +256,3 @@ //=collection

Returns **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)** a FeatureCollection of input features
Returns **[FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3)** FeatureCollection of Features

@@ -207,4 +268,5 @@ ## multiLineString

- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the Feature

@@ -221,3 +283,3 @@ **Examples**

Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[MultiLineString](http://geojson.org/geojson-spec.html#multilinestring)>** a MultiLineString feature
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[MultiLineString](https://tools.ietf.org/html/rfc7946#section-3.1.5)>** a MultiLineString feature

@@ -233,4 +295,5 @@ ## multiPoint

- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the Feature

@@ -247,3 +310,3 @@ **Examples**

Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[MultiPoint](http://geojson.org/geojson-spec.html#multipoint)>** a MultiPoint feature
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[MultiPoint](https://tools.ietf.org/html/rfc7946#section-3.1.3)>** a MultiPoint feature

@@ -259,4 +322,5 @@ ## multiPolygon

- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the Feature

@@ -273,3 +337,3 @@ **Examples**

Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon)>** a multipolygon feature
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7)>** a multipolygon feature

@@ -283,6 +347,7 @@ ## geometryCollection

- `geometries` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Geometry](http://geojson.org/geojson-spec.html#geometry)>** an array of GeoJSON Geometries
- `geometries` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Geometry](https://tools.ietf.org/html/rfc7946#section-3.1)>** an array of GeoJSON Geometries
- `properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object of key-value pairs to add as properties (optional, default `{}`)
- `bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** BBox [west, south, east, north]
- `id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional Parameters (optional, default `{}`)
- `options.bbox` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Bounding Box Array [west, south, east, north] associated with the Feature
- `options.id` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number))?** Identifier associated with the Feature

@@ -305,3 +370,3 @@ **Examples**

Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;[GeometryCollection](http://geojson.org/geojson-spec.html#geometrycollection)>** a GeoJSON GeometryCollection Feature
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)&lt;[GeometryCollection](https://tools.ietf.org/html/rfc7946#section-3.1.8)>** a GeoJSON GeometryCollection Feature

@@ -386,3 +451,3 @@ ## round

## degreesToradians
## degreesToRadians

@@ -413,3 +478,3 @@ Converts an angle in degrees to radians

Converts a area to the requested unit.
Valid units: kilometers, kilometres, meters, metres, centimetres, millimeter, acre, mile, yard, foot, inch
Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches

@@ -416,0 +481,0 @@ **Parameters**

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