along

Takes a LineString and returns a Point at a specified distance along the line.

Arguments

ArgumentTypeDescription
lineFeature <LineString>input line
distancenumberdistance along the line
options(Object)Optional parameters: see below

Options

PropTypeDefaultDescription
unitsstring"kilometers"can be degrees, radians, miles, or kilometers

Returns

Feature <Point> - Point distance units along the line

npm install @turf/along

Example

var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
var options = {units: 'miles'};

var along = turf.along(line, 200, options);

area

Takes one or more features and returns their area in square meters.

Arguments

ArgumentTypeDescription
geojsonGeoJSONinput GeoJSON feature(s)

Returns

number - area in square meters

npm install @turf/area

Example

var polygon = turf.polygon([[[125, -15], [113, -22], [154, -27], [144, -15], [125, -15]]]);

var area = turf.area(polygon);

bbox

Takes a set of features, calculates the bbox of all input features, and returns a bounding box.

Arguments

ArgumentTypeDescription
geojsonGeoJSONany GeoJSON object

Returns

BBox - bbox extent in minX, minY, maxX, maxY order

npm install @turf/bbox

Example

var line = turf.lineString([[-74, 40], [-78, 42], [-82, 35]]);
var bbox = turf.bbox(line);
var bboxPolygon = turf.bboxPolygon(bbox);

bboxPolygon

Takes a bbox and returns an equivalent polygon.

Arguments

ArgumentTypeDescription
bboxBBoxextent in minX, minY, maxX, maxY order
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
propertiesProperties{}Translate properties to Polygon
id(string|number){}Translate Id to Polygon

Returns

Feature <Polygon> - a Polygon representation of the bounding box

npm install @turf/bbox-polygon

Example

var bbox = [0, 0, 10, 10];

var poly = turf.bboxPolygon(bbox);

bearing

Takes two points and finds the geographic bearing between them, i.e. the angle measured in degrees from the north line (0 degrees)

Arguments

ArgumentTypeDescription
startCoordstarting Point
endCoordending Point
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
finalbooleanfalsecalculates the final bearing if true

Returns

number - bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)

npm install @turf/bearing

Example

var point1 = turf.point([-75.343, 39.984]);
var point2 = turf.point([-75.534, 39.123]);

var bearing = turf.bearing(point1, point2);

center

Takes a Feature or FeatureCollection and returns the absolute center point of all features.

Arguments

ArgumentTypeDescription
geojsonGeoJSONGeoJSON to be centered
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
propertiesObject{}Translate GeoJSON Properties to Point
bboxObject{}Translate GeoJSON BBox to Point
idObject{}Translate GeoJSON Id to Point

Returns

Feature <Point> - a Point feature at the absolute center point of all input features

npm install @turf/center

Example

var features = turf.points([
  [-97.522259, 35.4691],
  [-97.502754, 35.463455],
  [-97.508269, 35.463245]
]);

var center = turf.center(features);

centerOfMass

Takes any Feature or a FeatureCollection and returns its center of mass using this formula: Centroid of Polygon.

Arguments

ArgumentTypeDescription
geojsonGeoJSONGeoJSON to be centered
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
propertiesObject{}Translate Properties to Feature

Returns

Feature <Point> - the center of mass

npm install @turf/center-of-mass

Example

var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);

var center = turf.centerOfMass(polygon);

centroid

Takes one or more features and calculates the centroid using the mean of all vertices. This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.

Arguments

ArgumentTypeDescription
geojsonGeoJSONGeoJSON to be centered
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
propertiesObject{}an Object that is used as the

Returns

Feature <Point> - the centroid of the input features

npm install @turf/centroid

Example

var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);

var centroid = turf.centroid(polygon);

destination

Takes a Point and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers; and bearing in degrees. This uses the Haversine formula to account for global curvature.

Arguments

ArgumentTypeDescription
originCoordstarting point
distancenumberdistance from the origin point
bearingnumberranging from -180 to 180
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'miles, kilometers, degrees, or radians
propertiesObject{}Translate properties to Point

Returns

Feature <Point> - destination point

npm install @turf/destination

Example

var point = turf.point([-75.343, 39.984]);
var distance = 50;
var bearing = 90;
var options = {units: 'miles'};

var destination = turf.destination(point, distance, bearing, options);

distance

Calculates the distance between two points in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.

Arguments

ArgumentTypeDescription
from(Coord|Point)origin point or coordinate
to(Coord|Point)destination point or coordinate
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'can be degrees, radians, miles, or kilometers

Returns

number - distance between the two points

npm install @turf/distance

Example

var from = turf.point([-75.343, 39.984]);
var to = turf.point([-75.534, 39.123]);
var options = {units: 'miles'};

var distance = turf.distance(from, to, options);

envelope

Takes any number of features and returns a rectangular Polygon that encompasses all vertices.

Arguments

ArgumentTypeDescription
geojsonGeoJSONinput features

Returns

Feature <Polygon> - a rectangular Polygon feature that encompasses all vertices

npm install @turf/envelope

Example

var features = turf.featureCollection([
  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 enveloped = turf.envelope(features);

length

Takes a GeoJSON and measures its length in the specified units, (Multi)Point 's distance are ignored.

Arguments

ArgumentTypeDescription
geojsonFeature <(LineString|MultiLineString)>GeoJSON to measure
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstringkilometerscan be degrees, radians, miles, or kilometers

Returns

number - length of GeoJSON

npm install @turf/length

Example

var line = turf.lineString([[115, -32], [131, -22], [143, -25], [150, -34]]);
var length = turf.length(line, {units: 'miles'});

midpoint

Takes two points and returns a point midway between them. The midpoint is calculated geodesically, meaning the curvature of the earth is taken into account.

Arguments

ArgumentTypeDescription
point1Coordfirst point
point2Coordsecond point

Returns

Feature <Point> - a point midway between pt1 and pt2

npm install @turf/midpoint

Example

var point1 = turf.point([144.834823, -37.771257]);
var point2 = turf.point([145.14244, -37.830937]);

var midpoint = turf.midpoint(point1, point2);

pointOnFeature

Takes a Feature or FeatureCollection and returns a Point guaranteed to be on the surface of the feature.

Arguments

ArgumentTypeDescription
geojsonGeoJSONany Feature or FeatureCollection

Returns

Feature <Point> - a point on the surface of input

npm install @turf/point-on-feature

Example

var polygon = turf.polygon([[
  [116, -36],
  [131, -32],
  [146, -43],
  [155, -25],
  [133, -9],
  [111, -22],
  [116, -36]
]]);

var pointOnPolygon = turf.pointOnFeature(polygon);

polygonTangents

Finds the tangents of a (Multi)Polygon from a Point.

Arguments

ArgumentTypeDescription
ptCoordto calculate the tangent points from
polygonFeature <(Polygon|MultiPolygon)>to get tangents from

Returns

FeatureCollection <Point> - Feature Collection containing the two tangent points

npm install @turf/polygon-tangents

Example

var polygon = turf.polygon([[[11, 0], [22, 4], [31, 0], [31, 11], [21, 15], [11, 11], [11, 0]]]);
var point = turf.point([61, 5]);

var tangents = turf.polygonTangents(point, polygon)

pointToLineDistance

Returns the minimum distance between a Point and a LineString , being the distance from a line the minimum distance between the point and any segment of the LineString.

Arguments

ArgumentTypeDescription
pt(Feature <Point>|Array )Feature or Geometry
lineFeature <LineString>GeoJSON Feature or Geometry
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring"kilometers"can be anything supported by turf/convertLength (ex: degrees, radians, miles, or kilometers)
methodstring"geodesic"wether to calculate the distance based on geodesic (spheroid) or planar (flat) method. Valid options are 'geodesic' or 'planar'.

Returns

number - distance between point and line

npm install @turf/point-to-line-distance

Example

var pt = turf.point([0, 0]);
var line = turf.lineString([[1, 1],[-1, 1]]);

var distance = turf.pointToLineDistance(pt, line, {units: 'miles'});
//=69.11854715938406

rhumbBearing

Takes two points and finds the bearing angle between them along a Rhumb line i.e. the angle measured in degrees start the north line (0 degrees)

Arguments

ArgumentTypeDescription
startCoordstarting Point
endCoordending Point
options(Object)Optional parameters: see below

Options

PropTypeDefaultDescription
finalbooleanfalsecalculates the final bearing if true

Returns

number - bearing from north in decimal degrees, between -180 and 180 degrees (positive clockwise)

npm install @turf/rhumb-bearing

Example

var point1 = turf.point([-75.343, 39.984], {"marker-color": "#F00"});
var point2 = turf.point([-75.534, 39.123], {"marker-color": "#00F"});

var bearing = turf.rhumbBearing(point1, point2);

rhumbDestination

Returns the destination Point having travelled the given distance along a Rhumb line from the origin Point with the (varant) given bearing.

Arguments

ArgumentTypeDescription
originCoordstarting point
distancenumberdistance from the starting point
bearingnumbervarant bearing angle ranging from -180 to 180 degrees from north
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'can be degrees, radians, miles, or kilometers
propertiesObject{}translate properties to destination point

Returns

Feature <Point> - Destination point.

npm install @turf/rhumb-destination

Example

var pt = turf.point([-75.343, 39.984], {"marker-color": "F00"});
var distance = 50;
var bearing = 90;
var options = {units: 'miles'};

var destination = turf.rhumbDestination(pt, distance, bearing, options);

rhumbDistance

Calculates the distance along a rhumb line between two points in degrees, radians, miles, or kilometers.

Arguments

ArgumentTypeDescription
fromCoordorigin point
toCoorddestination point
options(Object)Optional parameters: see below

Options

PropTypeDefaultDescription
unitsstring"kilometers"can be degrees, radians, miles, or kilometers

Returns

number - distance between the two points

npm install @turf/rhumb-distance

Example

var from = turf.point([-75.343, 39.984]);
var to = turf.point([-75.534, 39.123]);
var options = {units: 'miles'};

var distance = turf.rhumbDistance(from, to, options);

square

Takes a bounding box and calculates the minimum square bounding box that would contain the input.

Arguments

ArgumentTypeDescription
bboxBBoxextent in west, south, east, north order

Returns

BBox - a square surrounding bbox

npm install @turf/square

Example

var bbox = [-20, -20, -15, 0];
var squared = turf.square(bbox);

greatCircle

Calculate great circles routes as LineString or MultiLineString. If the start and end points span the antimeridian, the resulting feature will be split into a MultiLineString .

Arguments

ArgumentTypeDescription
startCoordsource point feature
endCoorddestination point feature
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
propertiesObject{}line feature properties
npointsnumber100number of points
offsetnumber10offset controls the likelyhood that lines will be split which cross the dateline. The higher the number the more likely.

Returns

Feature <(LineString|MultiLineString)> - great circle line feature

npm install @turf/great-circle

Example

var start = turf.point([-122, 48]);
var end = turf.point([-77, 39]);

var greatCircle = turf.greatCircle(start, end, {properties: {name: 'Seattle to DC'}});

cleanCoords

Removes redundant coordinates from any GeoJSON Geometry.

Arguments

ArgumentTypeDescription
geojson(Geometry|Feature)Feature or Geometry
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
mutatebooleanfalseallows GeoJSON input to be mutated

Returns

(Geometry|Feature) - the cleaned input Feature/Geometry

npm install @turf/clean-coords

Example

var line = turf.lineString([[0, 0], [0, 2], [0, 5], [0, 8], [0, 8], [0, 10]]);
var multiPoint = turf.multiPoint([[0, 0], [0, 0], [2, 2]]);

turf.cleanCoords(line).geometry.coordinates;
//= [[0, 0], [0, 10]]

turf.cleanCoords(multiPoint).geometry.coordinates;
//= [[0, 0], [2, 2]]

flip

Takes input features and flips all of their coordinates from [x, y] to [y, x].

Arguments

ArgumentTypeDescription
geojsonGeoJSONinput features
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

GeoJSON - a feature or set of features of the same type as input with flipped coordinates

npm install @turf/flip

Example

var serbia = turf.point([20.566406, 43.421008]);

var saudiArabia = turf.flip(serbia);

rewind

Rewind (Multi)LineString or (Multi)Polygon outer ring counterclockwise and inner rings clockwise (Uses Shoelace Formula ).

Arguments

ArgumentTypeDescription
geojsonGeoJSONinput GeoJSON Polygon
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
reversebooleanfalseenable reverse winding
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

GeoJSON - rewind Polygon

npm install @turf/rewind

Example

var polygon = turf.polygon([[[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]]);

var rewind = turf.rewind(polygon);

round

Round number to precision

Arguments

ArgumentTypeDescription
numnumberNumber
precisionnumberPrecision

Returns

number - rounded number

npm install @turf/helpers

Note: round is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the round method.

Example

turf.round(120.4321)
//=120

turf.round(120.4321, 2)
//=120.43

truncate

Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.

Arguments

ArgumentTypeDescription
geojsonGeoJSONany GeoJSON Feature, FeatureCollection, Geometry or GeometryCollection.
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
precisionnumber6coordinate decimal precision
coordinatesnumber3maximum number of coordinates (primarly used to remove z coordinates)
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

GeoJSON - layer with truncated geometry

npm install @turf/truncate

Example

var point = turf.point([
    70.46923055566859,
    58.11088890802906,
    1508
]);
var options = {precision: 3, coordinates: 2};
var truncated = turf.truncate(point, options);
//=truncated.geometry.coordinates => [70.469, 58.111]

bboxClip

Takes a Feature and a bbox and clips the feature to the bbox using lineclip. May result in degenerate edges when clipping Polygons.

Arguments

ArgumentTypeDescription
featureFeature <(LineString|MultiLineString|Polygon|MultiPolygon)>feature to clip to the bbox
bboxBBoxextent in minX, minY, maxX, maxY order

npm install @turf/bbox-clip

Example

var bbox = [0, 0, 10, 10];
var poly = turf.polygon([[[2, 2], [8, 4], [12, 8], [3, 7], [2, 2]]]);

var clipped = turf.bboxClip(poly, bbox);

bezierSpline

Takes a line and returns a curved version by applying a Bezier spline algorithm.

Arguments

ArgumentTypeDescription
lineFeature <LineString>input LineString
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
propertiesObject{}Translate properties to output
resolutionnumber10000time in milliseconds between points
sharpnessnumber0.85a measure of how curvy the path should be between splines

Returns

Feature <LineString> - curved line

npm install @turf/bezier-spline

Example

var line = turf.lineString([
  [-76.091308, 18.427501],
  [-76.695556, 18.729501],
  [-76.552734, 19.40443],
  [-74.61914, 19.134789],
  [-73.652343, 20.07657],
  [-73.157958, 20.210656]
]);

var curved = turf.bezierSpline(line);

buffer

Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees.

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Geometry|Feature )input to be buffered
radiusnumberdistance to draw the buffer (negative values are allowed)
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring"kilometers"any of the options supported by turf units
stepsnumber8number of steps

Returns

(FeatureCollection|Feature <(Polygon|MultiPolygon)>|undefined) - buffered features

npm install @turf/buffer

Example

var point = turf.point([-90.548630, 14.616599]);
var buffered = turf.buffer(point, 500, {units: 'miles'});

circle

Takes a Point and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision.

Arguments

ArgumentTypeDescription
center(Feature <Point>|Array )center point
radiusnumberradius of the circle
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
stepsnumber64number of steps
unitsstring'kilometers'miles, kilometers, degrees, or radians
propertiesObject{}properties

Returns

Feature <Polygon> - circle polygon

npm install @turf/circle

Example

var center = [-75.343, 39.984];
var radius = 5;
var options = {steps: 10, units: 'kilometers', properties: {foo: 'bar'}};
var circle = turf.circle(center, radius, options);

clone

Returns a cloned copy of the passed GeoJSON Object, including possible 'Foreign Members'. ~3-5x faster than the common JSON.parse + JSON.stringify combo method.

Arguments

ArgumentTypeDescription
geojsonGeoJSONGeoJSON Object

Returns

GeoJSON - cloned GeoJSON Object

npm install @turf/clone

Example

var line = turf.lineString([[-74, 40], [-78, 42], [-82, 35]], {color: 'red'});

var lineCloned = turf.clone(line);

concave

Takes a set of points and returns a concave hull Polygon or MultiPolygon. Internally, this uses turf-tin to generate geometries.

Arguments

ArgumentTypeDescription
pointsFeatureCollection <Point>input points
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
maxEdgenumberInfinitythe length (in 'units') of an edge necessary for part of the hull to become concave.
unitsstring'kilometers'can be degrees, radians, miles, or kilometers

Returns

(Feature <(Polygon|MultiPolygon)>|null) - a concave hull (null value is returned if unable to compute hull)

npm install @turf/concave

Example

var points = turf.featureCollection([
  turf.point([-63.601226, 44.642643]),
  turf.point([-63.591442, 44.651436]),
  turf.point([-63.580799, 44.648749]),
  turf.point([-63.573589, 44.641788]),
  turf.point([-63.587665, 44.64533]),
  turf.point([-63.595218, 44.64765])
]);
var options = {units: 'miles', maxEdge: 1};

var hull = turf.concave(points, options);

convex

Takes a Feature or a FeatureCollection and returns a convex hull Polygon.

Arguments

ArgumentTypeDescription
geojsonGeoJSONinput Feature or FeatureCollection
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
concavitynumberInfinity1 - thin shape. Infinity - convex hull.
propertiesObject{}Translate Properties to Feature

Returns

Feature <Polygon> - a convex hull

npm install @turf/convex

Example

var points = turf.featureCollection([
  turf.point([10.195312, 43.755225]),
  turf.point([10.404052, 43.8424511]),
  turf.point([10.579833, 43.659924]),
  turf.point([10.360107, 43.516688]),
  turf.point([10.14038, 43.588348]),
  turf.point([10.195312, 43.755225])
]);

var hull = turf.convex(points);

difference

Finds the difference between two polygons by clipping the second polygon from the first.

Arguments

ArgumentTypeDescription
polygon1Feature <(Polygon|MultiPolygon)>input Polygon feature
polygon2Feature <(Polygon|MultiPolygon)>Polygon feature to difference from polygon1

Returns

(Feature <(Polygon|MultiPolygon)>|null) - a Polygon or MultiPolygon feature showing the area of polygon1 excluding the area of polygon2 (if empty returns null )

npm install @turf/difference

Example

var polygon1 = turf.polygon([[
  [128, -26],
  [141, -26],
  [141, -21],
  [128, -21],
  [128, -26]
]], {
  "fill": "#F00",
  "fill-opacity": 0.1
});
var polygon2 = turf.polygon([[
  [126, -28],
  [140, -28],
  [140, -20],
  [126, -20],
  [126, -28]
]], {
  "fill": "#00F",
  "fill-opacity": 0.1
});

var difference = turf.difference(polygon1, polygon2);

dissolve

Dissolves a FeatureCollection of polygon features, filtered by an optional property name:value. Note that mulitpolygon features within the collection are not supported

Arguments

ArgumentTypeDescription
featureCollectionFeatureCollection <Polygon>input feature collection to be dissolved
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
propertyName(string)features with the same

Returns

FeatureCollection <Polygon> - a FeatureCollection containing the dissolved polygons

npm install @turf/dissolve

Example

var features = turf.featureCollection([
  turf.polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], {combine: 'yes'}),
  turf.polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0,-1]]], {combine: 'yes'}),
  turf.polygon([[[1,-1],[1, 0], [2, 0], [2, -1], [1, -1]]], {combine: 'no'}),
]);

var dissolved = turf.dissolve(features, {propertyName: 'combine'});

intersect

Takes two polygon or multi-polygon geometries and finds their polygonal intersection. If they don't intersect, returns null.

Arguments

ArgumentTypeDescription
poly1Feature <(Polygon|MultiPolygon)>the first polygon or multipolygon
poly2Feature <(Polygon|MultiPolygon)>the second polygon or multipolygon
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
propertiesObject{}Translate GeoJSON Properties to Feature

Returns

(Feature|null) - returns a feature representing the area they share (either a Polygon or MultiPolygon ). If they do not share any area, returns null.

npm install @turf/intersect

Example

var poly1 = turf.polygon([[
  [-122.801742, 45.48565],
  [-122.801742, 45.60491],
  [-122.584762, 45.60491],
  [-122.584762, 45.48565],
  [-122.801742, 45.48565]
]]);

var poly2 = turf.polygon([[
  [-122.520217, 45.535693],
  [-122.64038, 45.553967],
  [-122.720031, 45.526554],
  [-122.669906, 45.507309],
  [-122.723464, 45.446643],
  [-122.532577, 45.408574],
  [-122.487258, 45.477466],
  [-122.520217, 45.535693]
]]);

var intersection = turf.intersect(poly1, poly2);

lineOffset

Takes a line and returns a line at offset by the specified distance.

Arguments

ArgumentTypeDescription
geojson(Geometry|Feature <(LineString|MultiLineString)>)input GeoJSON
distancenumberdistance to offset the line (can be of negative value)
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'can be degrees, radians, miles, kilometers, inches, yards, meters

Returns

Feature <(LineString|MultiLineString)> - Line offset from the input line

npm install @turf/line-offset

Note: lineOffset is part of the @turf/line-offset module.

To use it as a stand-alone module will need to import @turf/line-offset and call the lineOffset method.

Example

var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]], { "stroke": "#F00" });

var offsetLine = turf.lineOffset(line, 2, {units: 'miles'});

polygonSmooth

Smooths a Polygon or MultiPolygon. Based on Chaikin's algorithm . Warning: may create degenerate polygons.

Arguments

ArgumentTypeDescription
inputPolys(FeatureCollection|Feature <(Polygon|MultiPolygon)>)(Multi)Polygon(s) to smooth
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
iterationsstring1THe number of times to smooth the polygon. A higher value means a smoother polygon.

Returns

FeatureCollection <Polygon> - FeatureCollection containing the smoothed polygon/poylgons

npm install @turf/polygon-smooth

Example

var polygon = turf.polygon([[[11, 0], [22, 4], [31, 0], [31, 11], [21, 15], [11, 11], [11, 0]]]);

var smoothed = turf.polygonSmooth(polygon, {iterations: 3})

simplify

Takes a GeoJSON object and returns a simplified version. Internally uses simplify-js to perform simplification using the Ramer-Douglas-Peucker algorithm.

Arguments

ArgumentTypeDescription
geojsonGeoJSONobject to be simplified
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
tolerancenumber1simplification tolerance
highQualitybooleanfalsewhether or not to spend more time to create a higher-quality simplification with a different algorithm
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

GeoJSON - a simplified GeoJSON

npm install @turf/simplify

Example

var geojson = turf.polygon([[
  [-70.603637, -33.399918],
  [-70.614624, -33.395332],
  [-70.639343, -33.392466],
  [-70.659942, -33.394759],
  [-70.683975, -33.404504],
  [-70.697021, -33.419406],
  [-70.701141, -33.434306],
  [-70.700454, -33.446339],
  [-70.694274, -33.458369],
  [-70.682601, -33.465816],
  [-70.668869, -33.472117],
  [-70.646209, -33.473835],
  [-70.624923, -33.472117],
  [-70.609817, -33.468107],
  [-70.595397, -33.458369],
  [-70.587158, -33.442901],
  [-70.587158, -33.426283],
  [-70.590591, -33.414248],
  [-70.594711, -33.406224],
  [-70.603637, -33.399918]
]]);
var options = {tolerance: 0.01, highQuality: false};
var simplified = turf.simplify(geojson, options);

tesselate

Tesselates a Feature into a FeatureCollection of triangles using earcut.

Arguments

ArgumentTypeDescription
polyFeature <Polygon>the polygon to tesselate

Returns

FeatureCollection <Polygon> - a geometrycollection feature

npm install @turf/tesselate

Example

var poly = turf.polygon([[[11, 0], [22, 4], [31, 0], [31, 11], [21, 15], [11, 11], [11, 0]]]);
var triangles = turf.tesselate(poly);

transformRotate

Rotates any geojson Feature or Geometry of a specified angle, around its centroid or a given pivot point.

Arguments

ArgumentTypeDescription
geojsonGeoJSONobject to be rotated
anglenumberof rotation in decimal degrees, positive clockwise
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
pivotCoord'centroid'point around which the rotation will be performed
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

GeoJSON - the rotated GeoJSON feature

npm install @turf/transform-rotate

Example

var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
var options = {pivot: [0, 25]};
var rotatedPoly = turf.transformRotate(poly, 10, options);

transformTranslate

Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line on the provided direction angle.

Arguments

ArgumentTypeDescription
geojsonGeoJSONobject to be translated
distancenumberlength of the motion; negative values determine motion in opposite direction
directionnumberof the motion; angle from North in decimal degrees, positive clockwise
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'in which
zTranslationnumber0length of the vertical motion, same unit of distance
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

GeoJSON - the translated GeoJSON object

npm install @turf/transform-translate

Example

var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
var translatedPoly = turf.transformTranslate(poly, 100, 35);

transformScale

Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger). If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature.

Arguments

ArgumentTypeDescription
geojsonGeoJSONGeoJSON to be scaled
factornumberof scaling, positive or negative values greater than 0
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
origin(string|Coord)'centroid'Point from which the scaling will occur (string options: sw/se/nw/ne/center/centroid)
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

GeoJSON - scaled GeoJSON

npm install @turf/transform-scale

Example

var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
var scaledPoly = turf.transformScale(poly, 3);

union

Takes two (Multi)Polygon(s) and returns a combined polygon. If the input polygons are not contiguous, this function returns a MultiPolygon feature.

Arguments

ArgumentTypeDescription
polygon1Feature <(Polygon|MultiPolygon)>input Polygon feature
polygon2Feature <(Polygon|MultiPolygon)>Polygon feature to difference from polygon1
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
propertiesObject{}Translate Properties to output Feature

Returns

Feature <(Polygon|MultiPolygon)> - a combined Polygon or MultiPolygon feature, or null if the inputs are empty

npm install @turf/union

Example

var poly1 = turf.polygon([[
    [-82.574787, 35.594087],
    [-82.574787, 35.615581],
    [-82.545261, 35.615581],
    [-82.545261, 35.594087],
    [-82.574787, 35.594087]
]], {"fill": "#0f0"});
var poly2 = turf.polygon([[
    [-82.560024, 35.585153],
    [-82.560024, 35.602602],
    [-82.52964, 35.602602],
    [-82.52964, 35.585153],
    [-82.560024, 35.585153]
]], {"fill": "#00f"});

var union = turf.union(poly1, poly2);

voronoi

Takes a FeatureCollection of points, and a bounding box, and returns a FeatureCollection of Voronoi polygons.

Arguments

ArgumentTypeDescription
pointsFeatureCollection <Point>to find the Voronoi polygons around.
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
bboxArray [-180,-85,180,-85]clipping rectangle, in

Returns

FeatureCollection <Polygon> - a set of polygons, one per input point.

npm install @turf/voronoi

Example

var options = {
  bbox: [-70, 40, -60, 60]
};
var points = turf.randomPoint(100, options);
var voronoiPolygons = turf.voronoi(points, options);

combine

Combines a FeatureCollection of Point , LineString , or Polygon features into MultiPoint , MultiLineString , or MultiPolygon features.

Arguments

ArgumentTypeDescription
fcFeatureCollection <(Point|LineString|Polygon)>a FeatureCollection of any type

Returns

FeatureCollection <(MultiPoint|MultiLineString|MultiPolygon)> - a FeatureCollection of corresponding type to input

npm install @turf/combine

Example

var fc = turf.featureCollection([
  turf.point([19.026432, 47.49134]),
  turf.point([19.074497, 47.509548])
]);

var combined = turf.combine(fc);

explode

Takes a feature or set of features and returns all positions as points.

Arguments

ArgumentTypeDescription
geojsonGeoJSONinput features

Returns

FeatureCollection <point> - points representing the exploded input features

Throws

Error - if it encounters an unknown geometry type

npm install @turf/explode

Example

var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);

var explode = turf.explode(polygon);

flatten

Flattens any GeoJSON to a FeatureCollection inspired by geojson-flatten.

Arguments

ArgumentTypeDescription
geojsonGeoJSONany valid GeoJSON Object

Returns

FeatureCollection - all Multi-Geometries are flattened into single Features

npm install @turf/flatten

Example

var multiGeometry = turf.multiPolygon([
  [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
  [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
  [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
]);

var flatten = turf.flatten(multiGeometry);

lineToPolygon

Converts (Multi)LineString(s) to Polygon(s).

Arguments

ArgumentTypeDescription
lines(FeatureCollection|Feature <(LineString|MultiLineString)>)Features to convert
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
propertiesObject{}translates GeoJSON properties to Feature
autoCompletebooleantrueauto complete linestrings (matches first & last coordinates)
orderCoordsbooleantruesorts linestrings to place outer ring at the first position of the coordinates
mutatebooleanfalsemutate the original linestring using autoComplete (matches first & last coordinates)

Returns

Feature <(Polygon|MultiPolygon)> - converted to Polygons

npm install @turf/line-to-polygon

Example

var line = turf.lineString([[125, -30], [145, -30], [145, -20], [125, -20], [125, -30]]);

var polygon = turf.lineToPolygon(line);

polygonize

Polygonizes (Multi)LineString(s) into Polygons.

Arguments

ArgumentTypeDescription
geoJson(FeatureCollection|Geometry|Feature <(LineString|MultiLineString)>)Lines in order to polygonize

Returns

FeatureCollection <Polygon> - Polygons created

Throws

Error - if geoJson is invalid.

npm install @turf/polygonize

polygonToLine

Converts a Polygon to (Multi)LineString or MultiPolygon to a FeatureCollection of (Multi)LineString.

Arguments

ArgumentTypeDescription
polyFeature <(Polygon|MultiPolygon)>Feature to convert
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
propertiesObject{}translates GeoJSON properties to Feature

Returns

(FeatureCollection|Feature <(LineString|MultiLinestring)>) - converted (Multi)Polygon to (Multi)LineString

npm install @turf/polygon-to-line

Example

var poly = turf.polygon([[[125, -30], [145, -30], [145, -20], [125, -20], [125, -30]]]);

var line = turf.polygonToLine(poly);

ellipse

Takes a Point and calculates the ellipse polygon given two semi-axes expressed in variable units and steps for precision.

Arguments

ArgumentTypeDescription
centerCoordcenter point
xSemiAxisnumbersemi (major) axis of the ellipse along the x-axis
ySemiAxisnumbersemi (minor) axis of the ellipse along the y-axis
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
anglenumber0angle of rotation in decimal degrees, positive clockwise
pivotCoord'origin'point around which the rotation will be performed
stepsnumber64number of steps
unitsstring'kilometers'unit of measurement for axes
propertiesObject{}properties

Returns

Feature <Polygon> - ellipse polygon

npm install @turf/ellipse

Example

var center = [-75, 40];
var xSemiAxis = 5;
var ySemiAxis = 2;
var ellipse = turf.ellipse(center, xSemiAxis, ySemiAxis);

kinks

Takes a linestring , multi-linestring , multi-polygon or polygon and returns points at all self-intersections.

Arguments

ArgumentTypeDescription
featureInFeature <(LineString|MultiLineString|MultiPolygon|Polygon)>input feature

Returns

FeatureCollection <Point> - self-intersections

npm install @turf/kinks

Example

var poly = turf.polygon([[
  [-12.034835, 8.901183],
  [-12.060413, 8.899826],
  [-12.03638, 8.873199],
  [-12.059383, 8.871418],
  [-12.034835, 8.901183]
]]);

var kinks = turf.kinks(poly);

lineArc

Creates a circular arc, of a circle of the given radius and center point, between bearing1 and bearing2; 0 bearing is North of center point, positive clockwise.

Arguments

ArgumentTypeDescription
centerCoordcenter point
radiusnumberradius of the circle
bearing1numberangle, in decimal degrees, of the first radius of the arc
bearing2numberangle, in decimal degrees, of the second radius of the arc
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
stepsnumber64number of steps
unitsstring'kilometers'miles, kilometers, degrees, or radians

Returns

Feature <LineString> - line arc

npm install @turf/line-arc

Example

var center = turf.point([-75, 40]);
var radius = 5;
var bearing1 = 25;
var bearing2 = 47;

var arc = turf.lineArc(center, radius, bearing1, bearing2);

lineChunk

Divides a LineString into chunks of a specified length. If the line is shorter than the segment length then the original line is returned.

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Geometry|Feature <(LineString|MultiLineString)>)the lines to split
segmentLengthnumberhow long to make each segment
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'units can be degrees, radians, miles, or kilometers
reversebooleanfalsereverses coordinates to start the first chunked segment at the end

Returns

FeatureCollection <LineString> - collection of line segments

npm install @turf/line-chunk

Example

var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);

var chunk = turf.lineChunk(line, 15, {units: 'miles'});

lineIntersect

Takes any LineString or Polygon GeoJSON and returns the intersecting point(s).

Arguments

ArgumentTypeDescription
line1GeoJSONany LineString or Polygon
line2GeoJSONany LineString or Polygon

Returns

FeatureCollection <Point> - point(s) that intersect both

npm install @turf/line-intersect

Example

var line1 = turf.lineString([[126, -11], [129, -21]]);
var line2 = turf.lineString([[123, -18], [131, -14]]);
var intersects = turf.lineIntersect(line1, line2);

lineOverlap

Takes any LineString or Polygon and returns the overlapping lines between both features.

Arguments

ArgumentTypeDescription
line1(Geometry|Feature <(LineString|MultiLineString|Polygon|MultiPolygon)>)any LineString or Polygon
line2(Geometry|Feature <(LineString|MultiLineString|Polygon|MultiPolygon)>)any LineString or Polygon
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
tolerancenumber0Tolerance distance to match overlapping line segments (in kilometers)

Returns

FeatureCollection <LineString> - lines(s) that are overlapping between both features

npm install @turf/line-overlap

Example

var line1 = turf.lineString([[115, -35], [125, -30], [135, -30], [145, -35]]);
var line2 = turf.lineString([[115, -25], [125, -30], [135, -30], [145, -25]]);

var overlapping = turf.lineOverlap(line1, line2);

lineSegment

Creates a FeatureCollection of 2-vertex LineString segments from a (Multi)LineString or (Multi)Polygon.

Arguments

ArgumentTypeDescription
geojsonGeoJSONGeoJSON Polygon or LineString

Returns

FeatureCollection <LineString> - 2-vertex line segments

npm install @turf/line-segment

Example

var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
var segments = turf.lineSegment(polygon);

lineSlice

Takes a line , a start Point , and a stop point and returns a subsection of the line in-between those points. The start & stop points don't need to fall exactly on the line.

Arguments

ArgumentTypeDescription
startPtCoordstarting point
stopPtCoordstopping point
line(Feature <LineString>|LineString)line to slice

Returns

Feature <LineString> - sliced line

npm install @turf/line-slice

Example

var line = turf.lineString([
    [-77.031669, 38.878605],
    [-77.029609, 38.881946],
    [-77.020339, 38.884084],
    [-77.025661, 38.885821],
    [-77.021884, 38.889563],
    [-77.019824, 38.892368]
]);
var start = turf.point([-77.029609, 38.881946]);
var stop = turf.point([-77.021884, 38.889563]);

var sliced = turf.lineSlice(start, stop, line);

lineSliceAlong

Takes a line , a specified distance along the line to a start Point , and a specified distance along the line to a stop point and returns a subsection of the line in-between those points.

Arguments

ArgumentTypeDescription
line(Feature <LineString>|LineString)input line
startDistnumberdistance along the line to starting point
stopDistnumberdistance along the line to ending point
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'can be degrees, radians, miles, or kilometers

Returns

Feature <LineString> - sliced line

npm install @turf/line-slice-along

Example

var line = turf.lineString([[7, 45], [9, 45], [14, 40], [14, 41]]);
var start = 12.5;
var stop = 25;
var sliced = turf.lineSliceAlong(line, start, stop, {units: 'miles'});

lineSplit

Split a LineString by another GeoJSON Feature.

Arguments

ArgumentTypeDescription
lineFeature <LineString>LineString Feature to split
splitterFeature Feature used to split line

Returns

FeatureCollection <LineString> - Split LineStrings

npm install @turf/line-split

Example

var line = turf.lineString([[120, -25], [145, -25]]);
var splitter = turf.lineString([[130, -15], [130, -35]]);

var split = turf.lineSplit(line, splitter);

mask

Takes any type of polygon and an optional mask and returns a polygon exterior ring with holes.

Arguments

ArgumentTypeDescription
polygon(FeatureCollection|Feature <(Polygon|MultiPolygon)>)GeoJSON Polygon used as interior rings or holes.
mask(Feature <Polygon>)GeoJSON Polygon used as the exterior ring (if undefined, the world extent is used)

Returns

Feature <Polygon> - Masked Polygon (exterior ring with holes).

npm install @turf/mask

Example

var polygon = turf.polygon([[[112, -21], [116, -36], [146, -39], [153, -24], [133, -10], [112, -21]]]);
var mask = turf.polygon([[[90, -55], [170, -55], [170, 10], [90, 10], [90, -55]]]);

var masked = turf.mask(polygon, mask);

nearestPointOnLine

Takes a Point and a LineString and calculates the closest Point on the (Multi)LineString.

Arguments

ArgumentTypeDescription
lines(Geometry|Feature <(LineString|MultiLineString)>)lines to snap to
pt(Geometry|Feature <Point>|Array )point to snap from
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'can be degrees, radians, miles, or kilometers

Returns

Feature <Point> - closest point on the line to point. The properties object will contain three values: index : closest point was found on nth line part, dist : distance between pt and the closest point, location : distance along the line between start and the closest point.

npm install @turf/nearest-point-on-line

Example

var line = turf.lineString([
    [-77.031669, 38.878605],
    [-77.029609, 38.881946],
    [-77.020339, 38.884084],
    [-77.025661, 38.885821],
    [-77.021884, 38.889563],
    [-77.019824, 38.892368]
]);
var pt = turf.point([-77.037076, 38.884017]);

var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});

sector

Creates a circular sector of a circle of given radius and center Point , between (clockwise) bearing1 and bearing2; 0 bearing is North of center point, positive clockwise.

Arguments

ArgumentTypeDescription
centerCoordcenter point
radiusnumberradius of the circle
bearing1numberangle, in decimal degrees, of the first radius of the sector
bearing2numberangle, in decimal degrees, of the second radius of the sector
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'miles, kilometers, degrees, or radians
stepsnumber64number of steps
propertiesProperties{}Translate properties to Feature Polygon

Returns

Feature <Polygon> - sector polygon

npm install @turf/sector

Example

var center = turf.point([-75, 40]);
var radius = 5;
var bearing1 = 25;
var bearing2 = 45;

var sector = turf.sector(center, radius, bearing1, bearing2);

shortestPath

Returns the shortest path from start to end without colliding with any Feature in obstacles

Arguments

ArgumentTypeDescription
startCoordpoint
endCoordpoint
optionsObjectoptional parameters

Options

PropTypeDefaultDescription
obstacles((Geometry|Feature|FeatureCollection <Polygon>))areas which path cannot travel
minDistance(number)minimum distance between shortest path and obstacles
unitsstring'kilometers'unit in which resolution & minimum distance will be expressed in; it can be degrees, radians, miles, kilometers, ...
resolutionnumber100distance between matrix points on which the path will be calculated

Returns

Feature <LineString> - shortest path between start and end

npm install @turf/shortest-path

Example

var start = [-5, -6];
var end = [9, -6];
var options = {
  obstacles: turf.polygon([[[0, -7], [5, -7], [5, -3], [0, -3], [0, -7]]])
};

var path = turf.shortestPath(start, end, options);

unkinkPolygon

Takes a kinked polygon and returns a feature collection of polygons that have no kinks. Uses simplepolygon internally.

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature <(Polygon|MultiPolygon)>)GeoJSON Polygon or MultiPolygon

Returns

FeatureCollection <Polygon> - Unkinked polygons

npm install @turf/unkink-polygon

Note: unkinkPolygon is part of the @turf/unkink-polygon module.

To use it as a stand-alone module will need to import @turf/unkink-polygon and call the unkinkPolygon method.

Example

var poly = turf.polygon([[[0, 0], [2, 0], [0, 2], [2, 2], [0, 0]]]);

var result = turf.unkinkPolygon(poly);

featureCollection

Takes one or more Features and creates a FeatureCollection.

Arguments

ArgumentTypeDescription
featuresArray <Feature>input features
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
bbox(Array )Bounding Box Array
id((string|number))Identifier associated with the Feature

Returns

FeatureCollection - FeatureCollection of Features

npm install @turf/helpers

Note: featureCollection is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the featureCollection method.

Example

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([
  locationA,
  locationB,
  locationC
]);

//=collection

feature

Wraps a GeoJSON Geometry in a GeoJSON Feature.

Arguments

ArgumentTypeDescription
geometryGeometryinput geometry
propertiesObjectan Object of key-value pairs to add as properties
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
bbox(Array )Bounding Box Array
id((string|number))Identifier associated with the Feature

Returns

Feature - a GeoJSON Feature

npm install @turf/helpers

Note: feature is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the feature method.

Example

var geometry = {
  "type": "Point",
  "coordinates": [110, 50]
};

var feature = turf.feature(geometry);

//=feature

geometryCollection

Creates a Feature based on a coordinate array. Properties can be added optionally.

Arguments

ArgumentTypeDescription
geometriesArray <Geometry>an array of GeoJSON Geometries
propertiesObjectan Object of key-value pairs to add as properties
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
bbox(Array )Bounding Box Array
id((string|number))Identifier associated with the Feature

Returns

Feature <GeometryCollection> - a GeoJSON GeometryCollection Feature

npm install @turf/helpers

Note: geometryCollection is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the geometryCollection method.

Example

var pt = turf.geometry("Point", [100, 0]);
var line = turf.geometry("LineString", [[101, 0], [102, 1]]);
var collection = turf.geometryCollection([pt, line]);

// => collection

lineString

Creates a LineString Feature from an Array of Positions.

Arguments

ArgumentTypeDescription
coordinatesArray >an array of Positions
propertiesObjectan Object of key-value pairs to add as properties
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
bbox(Array )Bounding Box Array
id((string|number))Identifier associated with the Feature

Returns

Feature <LineString> - LineString Feature

npm install @turf/helpers

Note: lineString is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the lineString method.

Example

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

multiLineString

Creates a Feature based on a coordinate array. Properties can be added optionally.

Arguments

ArgumentTypeDescription
coordinatesArray >>an array of LineStrings
propertiesObjectan Object of key-value pairs to add as properties
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
bbox(Array )Bounding Box Array
id((string|number))Identifier associated with the Feature

Returns

Feature <MultiLineString> - a MultiLineString feature

Throws

Error - if no coordinates are passed

npm install @turf/helpers

Note: multiLineString is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the multiLineString method.

Example

var multiLine = turf.multiLineString([[[0,0],[10,10]]]);

//=multiLine

multiPoint

Creates a Feature based on a coordinate array. Properties can be added optionally.

Arguments

ArgumentTypeDescription
coordinatesArray >an array of Positions
propertiesObjectan Object of key-value pairs to add as properties
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
bbox(Array )Bounding Box Array
id((string|number))Identifier associated with the Feature

Returns

Feature <MultiPoint> - a MultiPoint feature

Throws

Error - if no coordinates are passed

npm install @turf/helpers

Note: multiPoint is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the multiPoint method.

Example

var multiPt = turf.multiPoint([[0,0],[10,10]]);

//=multiPt

multiPolygon

Creates a Feature based on a coordinate array. Properties can be added optionally.

Arguments

ArgumentTypeDescription
coordinatesArray >>>an array of Polygons
propertiesObjectan Object of key-value pairs to add as properties
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
bbox(Array )Bounding Box Array
id((string|number))Identifier associated with the Feature

Returns

Feature <MultiPolygon> - a multipolygon feature

Throws

Error - if no coordinates are passed

npm install @turf/helpers

Note: multiPolygon is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the multiPolygon method.

Example

var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);

//=multiPoly

point

Creates a Point Feature from a Position.

Arguments

ArgumentTypeDescription
coordinatesArray longitude, latitude position (each in decimal degrees)
propertiesObjectan Object of key-value pairs to add as properties
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
bbox(Array )Bounding Box Array
id((string|number))Identifier associated with the Feature

Returns

Feature <Point> - a Point feature

npm install @turf/helpers

Note: point is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the point method.

Example

var point = turf.point([-75.343, 39.984]);

//=point

polygon

Creates a Polygon Feature from an Array of LinearRings.

Arguments

ArgumentTypeDescription
coordinatesArray >>an array of LinearRings
propertiesObjectan Object of key-value pairs to add as properties
optionsObjectOptional Parameters

Options

PropTypeDefaultDescription
bbox(Array )Bounding Box Array
id((string|number))Identifier associated with the Feature

Returns

Feature <Polygon> - Polygon Feature

npm install @turf/helpers

Note: polygon is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the polygon method.

Example

var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });

//=polygon

randomPosition

Returns a random position within a box.

Arguments

ArgumentTypeDescription
bboxArray a bounding box inside of which positions are placed.

Returns

Array - Position longitude, latitude

npm install @turf/random

Note: randomPosition is part of the @turf/random module.

To use it as a stand-alone module will need to import @turf/random and call the randomPosition method.

Example

var position = turf.randomPosition([-180, -90, 180, 90])
// => position

randomPoint

Returns a random point.

Arguments

ArgumentTypeDescription
countnumberhow many geometries will be generated
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
bboxArray [-180,-90,180,90]a bounding box inside of which geometries are placed.

Returns

FeatureCollection <Point> - GeoJSON FeatureCollection of points

npm install @turf/random

Note: randomPoint is part of the @turf/random module.

To use it as a stand-alone module will need to import @turf/random and call the randomPoint method.

Example

var points = turf.randomPoint(25, {bbox: [-180, -90, 180, 90]})
// => points

randomLineString

Returns a random linestring.

Arguments

ArgumentTypeDescription
countnumberhow many geometries will be generated
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
bboxArray [-180,-90,180,90]a bounding box inside of which geometries are placed.
num_verticesnumber10is how many coordinates each LineString will contain.
max_lengthnumber0.0001is the maximum number of decimal degrees that a vertex can be from its predecessor
max_rotationnumberMath.PI/8is the maximum number of radians that a line segment can turn from the previous segment.

Returns

FeatureCollection <LineString> - GeoJSON FeatureCollection of linestrings

npm install @turf/random

Note: randomLineString is part of the @turf/random module.

To use it as a stand-alone module will need to import @turf/random and call the randomLineString method.

Example

var lineStrings = turf.randomLineString(25, {bbox: [-180, -90, 180, 90]})
// => lineStrings

randomPolygon

Returns a random polygon.

Arguments

ArgumentTypeDescription
countnumberhow many geometries will be generated
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
bboxArray [-180,-90,180,90]a bounding box inside of which geometries are placed.
num_verticesnumber10is how many coordinates each LineString will contain.
max_radial_lengthnumber10is the maximum number of decimal degrees latitude or longitude that a vertex can reach out of the center of the Polygon.

Returns

FeatureCollection <Polygon> - GeoJSON FeatureCollection of polygons

npm install @turf/random

Note: randomPolygon is part of the @turf/random module.

To use it as a stand-alone module will need to import @turf/random and call the randomPolygon method.

Example

var polygons = turf.randomPolygon(25, {bbox: [-180, -90, 180, 90]})
// => polygons

sample

Takes a FeatureCollection and returns a FeatureCollection with given number of features at random.

Arguments

ArgumentTypeDescription
featurecollectionFeatureCollectionset of input features
numnumbernumber of features to select

Returns

FeatureCollection - a FeatureCollection with n features

npm install @turf/sample

Example

var points = turf.randomPoint(100, {bbox: [-80, 30, -60, 60]});

var sample = turf.sample(points, 5);

interpolate

Takes a set of points and estimates their 'property' values on a grid using the Inverse Distance Weighting (IDW) method.

Arguments

ArgumentTypeDescription
pointsFeatureCollection <Point>with known value
cellSizenumberthe distance across each grid point
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
gridTypestring'square'defines the output format based on a Grid Type (options: 'square' | 'point' | 'hex' | 'triangle')
propertystring'elevation'the property name in
unitsstring'kilometers'used in calculating cellSize, can be degrees, radians, miles, or kilometers
weightnumber1exponent regulating the distance-decay weighting

Returns

FeatureCollection <(Point|Polygon)> - grid of points or polygons with interpolated 'property'

npm install @turf/interpolate

Example

var points = turf.randomPoint(30, {bbox: [50, 30, 70, 50]});

// add a random property to each point
turf.featureEach(points, function(point) {
    point.properties.solRad = Math.random() * 50;
});
var options = {gridType: 'points', property: 'solRad', units: 'miles'};
var grid = turf.interpolate(points, 100, options);

isobands

Takes a square or rectangular grid FeatureCollection of Point features with z-values and an array of value breaks and generates filled contour isobands.

Arguments

ArgumentTypeDescription
pointGridFeatureCollection <Point>input points - must be square or rectangular
breaksArray where to draw contours
optionsObjectoptions on output

Options

PropTypeDefaultDescription
zPropertystring'elevation'the property name in
commonPropertiesObject{}GeoJSON properties passed to ALL isobands
breaksPropertiesArray []GeoJSON properties passed, in order, to the correspondent isoband (order defined by breaks)

Returns

FeatureCollection <MultiPolygon> - a FeatureCollection of MultiPolygon features representing isobands

npm install @turf/isobands

Note: isobands is part of the @turf/isobands module.

To use it as a stand-alone module will need to import @turf/isobands and call the isobands method.

isolines

Takes a grid FeatureCollection of Point features with z-values and an array of value breaks and generates isolines.

Arguments

ArgumentTypeDescription
pointGridFeatureCollection <Point>input points
breaksArray values of zProperty where to draw isolines
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
zPropertystring'elevation'the property name in
commonPropertiesObject{}GeoJSON properties passed to ALL isolines
breaksPropertiesArray []GeoJSON properties passed, in order, to the correspondent isoline; the breaks array will define the order in which the isolines are created

Returns

FeatureCollection <MultiLineString> - a FeatureCollection of MultiLineString features representing isolines

npm install @turf/isolines

Note: isolines is part of the @turf/isolines module.

To use it as a stand-alone module will need to import @turf/isolines and call the isolines method.

Example

// create a grid of points with random z-values in their properties
var extent = [0, 30, 20, 50];
var cellWidth = 100;
var pointGrid = turf.pointGrid(extent, cellWidth, {units: 'miles'});

for (var i = 0; i < pointGrid.features.length; i++) {
    pointGrid.features[i].properties.temperature = Math.random() * 10;
}
var breaks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

var lines = turf.isolines(pointGrid, breaks, {zProperty: 'temperature'});

planepoint

Takes a triangular plane as a Polygon and a Point within that triangle and returns the z-value at that point. The Polygon should have properties a , b , and c that define the values at its three corners. Alternatively, the z-values of each triangle point can be provided by their respective 3rd coordinate if their values are not provided as properties.

Arguments

ArgumentTypeDescription
pointCoordthe Point for which a z-value will be calculated
triangleFeature <Polygon>a Polygon feature with three vertices

Returns

number - the z-value for interpolatedPoint

npm install @turf/planepoint

Example

var point = turf.point([-75.3221, 39.529]);
// "a", "b", and "c" values represent the values of the coordinates in order.
var triangle = turf.polygon([[
  [-75.1221, 39.57],
  [-75.58, 39.18],
  [-75.97, 39.86],
  [-75.1221, 39.57]
]], {
  "a": 11,
  "b": 122,
  "c": 44
});

var zValue = turf.planepoint(point, triangle);
point.properties.zValue = zValue;

tin

Takes a set of points and creates a Triangulated Irregular Network , or a TIN for short, returned as a collection of Polygons. These are often used for developing elevation contour maps or stepped heat visualizations.

Arguments

ArgumentTypeDescription
pointsFeatureCollection <Point>input points
z(String)name of the property from which to pull z values This is optional: if not given, then there will be no extra data added to the derived triangles.

Returns

FeatureCollection <Polygon> - TIN output

npm install @turf/tin

Note: tin is part of the @turf/tin module.

To use it as a stand-alone module will need to import @turf/tin and call the tin method.

Example

// generate some random point data
var points = turf.randomPoint(30, {bbox: [50, 30, 70, 50]});

// add a random property to each point between 0 and 9
for (var i = 0; i < points.features.length; i++) {
  points.features[i].properties.z = ~~(Math.random() * 9);
}
var tin = turf.tin(points, 'z');

pointsWithinPolygon

Finds Points or MultiPoint coordinate positions that fall within (Multi)Polygon(s).

Arguments

ArgumentTypeDescription
points(Feature|FeatureCollection <(Point|MultiPoint)>)Point(s) or MultiPoint(s) as input search
polygons(FeatureCollection|Geometry|Feature <(Polygon|MultiPolygon)>)(Multi)Polygon(s) to check if points are within

Returns

FeatureCollection <(Point|MultiPoint)> - Point(s) or MultiPoint(s) with positions that land within at least one polygon. The geometry type will match what was passsed in

npm install @turf/points-within-polygon

Example

var points = turf.points([
    [-46.6318, -23.5523],
    [-46.6246, -23.5325],
    [-46.6062, -23.5513],
    [-46.663, -23.554],
    [-46.643, -23.557]
]);

var searchWithin = turf.polygon([[
    [-46.653,-23.543],
    [-46.634,-23.5346],
    [-46.613,-23.543],
    [-46.614,-23.559],
    [-46.631,-23.567],
    [-46.653,-23.560],
    [-46.653,-23.543]
]]);

var ptsWithin = turf.pointsWithinPolygon(points, searchWithin);

tag

Takes a set of points and a set of polygons and/or multipolygons and performs a spatial join.

Arguments

ArgumentTypeDescription
pointsFeatureCollection <Point>input points
polygonsFeatureCollection <(Polygon|MultiPolygon)>input (multi)polygons
fieldstringproperty in polygons to add to joined { } features
outFieldstringproperty in points in which to store joined property from polygons

Returns

FeatureCollection <Point> - points with containingPolyId property containing values from polyId

npm install @turf/tag

Example

var pt1 = turf.point([-77, 44]);
var pt2 = turf.point([-77, 38]);
var poly1 = turf.polygon([[
  [-81, 41],
  [-81, 47],
  [-72, 47],
  [-72, 41],
  [-81, 41]
]], {pop: 3000});
var poly2 = turf.polygon([[
  [-81, 35],
  [-81, 41],
  [-72, 41],
  [-72, 35],
  [-81, 35]
]], {pop: 1000});

var points = turf.featureCollection([pt1, pt2]);
var polygons = turf.featureCollection([poly1, poly2]);

var tagged = turf.tag(points, polygons, 'pop', 'population');

hexGrid

Takes a bounding box and the diameter of the cell and returns a FeatureCollection of flat-topped hexagons or triangles ( Polygon features) aligned in an "odd-q" vertical grid as described in Hexagonal Grids.

Arguments

ArgumentTypeDescription
bboxBBoxextent in minX, minY, maxX, maxY order
cellSidenumberlength of the side of the the hexagons or triangles, in units. It will also coincide with the radius of the circumcircle of the hexagons.
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'used in calculating cell size, can be degrees, radians, miles, or kilometers
propertiesObject{}passed to each hexagon or triangle of the grid
mask(Feature <Polygon>)if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
trianglesbooleanfalsewhether to return as triangles instead of hexagons

Returns

FeatureCollection <Polygon> - a hexagonal grid

npm install @turf/hex-grid

Example

var bbox = [-96,31,-84,40];
var cellSide = 50;
var options = {units: 'miles'};

var hexgrid = turf.hexGrid(bbox, cellSide, options);

pointGrid

Creates a Point grid from a bounding box, FeatureCollection or Feature.

Arguments

ArgumentTypeDescription
bboxArray extent in minX, minY, maxX, maxY order
cellSidenumberthe distance between points, in units
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'used in calculating cellSide, can be degrees, radians, miles, or kilometers
mask(Feature <(Polygon|MultiPolygon)>)if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
propertiesObject{}passed to each point of the grid

Returns

FeatureCollection <Point> - grid of points

npm install @turf/point-grid

Example

var extent = [-70.823364, -33.553984, -70.473175, -33.302986];
var cellSide = 3;
var options = {units: 'miles'};

var grid = turf.pointGrid(extent, cellSide, options);

squareGrid

Creates a square grid from a bounding box.

Arguments

ArgumentTypeDescription
bboxArray extent in minX, minY, maxX, maxY order
cellSidenumberof each cell, in units
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'used in calculating cellSide, can be degrees, radians, miles, or kilometers
mask(Feature <(Polygon|MultiPolygon)>)if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
propertiesObject{}passed to each point of the grid

Returns

FeatureCollection <Polygon> - grid a grid of polygons

npm install @turf/square-grid

Example

var bbox = [-95, 30 ,-85, 40];
var cellSide = 50;
var options = {units: 'miles'};

var squareGrid = turf.squareGrid(bbox, cellSide, options);

triangleGrid

Takes a bounding box and a cell depth and returns a set of triangular polygons in a grid.

Arguments

ArgumentTypeDescription
bboxArray extent in minX, minY, maxX, maxY order
cellSidenumberdimension of each cell
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring'kilometers'used in calculating cellSide, can be degrees, radians, miles, or kilometers
mask(Feature <Polygon>)if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
propertiesObject{}passed to each point of the grid

Returns

FeatureCollection <Polygon> - grid of polygons

npm install @turf/triangle-grid

Example

var bbox = [-95, 30 ,-85, 40];
var cellSide = 50;
var options = {units: 'miles'};

var triangleGrid = turf.triangleGrid(bbox, cellSide, options);

nearestPoint

Takes a reference point and a FeatureCollection of Features with Point geometries and returns the point from the FeatureCollection closest to the reference. This calculation is geodesic.

Arguments

ArgumentTypeDescription
targetPointCoordthe reference point
pointsFeatureCollection <Point>against input point set

Returns

Feature <Point> - the closest point in the set to the reference point

npm install @turf/nearest-point

Example

var targetPoint = turf.point([28.965797, 41.010086], {"marker-color": "#0F0"});
var points = turf.featureCollection([
    turf.point([28.973865, 41.011122]),
    turf.point([28.948459, 41.024204]),
    turf.point([28.938674, 41.013324])
]);

var nearest = turf.nearestPoint(targetPoint, points);

collect

Merges a specified property from a FeatureCollection of points into a FeatureCollection of polygons. Given an inProperty on points and an outProperty for polygons, this finds every point that lies within each polygon, collects the inProperty values from those points, and adds them as an array to outProperty on the polygon.

Arguments

ArgumentTypeDescription
polygonsFeatureCollection <Polygon>polygons with values on which to aggregate
pointsFeatureCollection <Point>points to be aggregated
inPropertystringproperty to be nested from
outPropertystringproperty to be nested into

Returns

FeatureCollection <Polygon> - polygons with properties listed based on outField

npm install @turf/collect

Example

var poly1 = turf.polygon([[[0,0],[10,0],[10,10],[0,10],[0,0]]]);
var poly2 = turf.polygon([[[10,0],[20,10],[20,20],[20,0],[10,0]]]);
var polyFC = turf.featureCollection([poly1, poly2]);
var pt1 = turf.point([5,5], {population: 200});
var pt2 = turf.point([1,3], {population: 600});
var pt3 = turf.point([14,2], {population: 100});
var pt4 = turf.point([13,1], {population: 200});
var pt5 = turf.point([19,7], {population: 300});
var pointFC = turf.featureCollection([pt1, pt2, pt3, pt4, pt5]);
var collected = turf.collect(polyFC, pointFC, 'population', 'values');
var values = collected.features[0].properties.values
//=values => [200, 600]

clustersDbscan

Takes a set of points and partition them into clusters according to https://en.wikipedia.org/wiki/DBSCAN data clustering algorithm.

Arguments

ArgumentTypeDescription
pointsFeatureCollection <Point>to be clustered
maxDistancenumberMaximum Distance between any point of the cluster to generate the clusters (kilometers only)
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
unitsstring"kilometers"in which
mutatebooleanfalseAllows GeoJSON input to be mutated
minPointsnumber3Minimum number of points to generate a single cluster, points which do not meet this requirement will be classified as an 'edge' or 'noise'.

Returns

FeatureCollection <Point> - Clustered Points with an additional two properties associated to each Feature:

npm install @turf/clusters-dbscan

Example

// create random points with random z-values in their properties
var points = turf.randomPoint(100, {bbox: [0, 30, 20, 50]});
var maxDistance = 100;
var clustered = turf.clustersDbscan(points, maxDistance);

clustersKmeans

Takes a set of points and partition them into clusters using the k-mean. It uses the k-means algorithm

Arguments

ArgumentTypeDescription
pointsFeatureCollection <Point>to be clustered
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
numberOfClustersnumberMath.sqrt(numberOfPoints/2)numberOfClusters that will be generated
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

FeatureCollection <Point> - Clustered Points with an additional two properties associated to each Feature:

npm install @turf/clusters-kmeans

Example

// create random points with random z-values in their properties
var points = turf.randomPoint(100, {bbox: [0, 30, 20, 50]});
var options = {numberOfClusters: 7};
var clustered = turf.clustersKmeans(points, options);

coordAll

Get all coordinates from any GeoJSON object.

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON object

Returns

Array > - coordinate position array

npm install @turf/meta

Note: coordAll is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the coordAll method.

Example

var features = turf.featureCollection([
  turf.point([26, 37], {foo: 'bar'}),
  turf.point([36, 53], {hello: 'world'})
]);

var coords = turf.coordAll(features);
//= [[26, 37], [36, 53]]

coordEach

Iterate over coordinates in any GeoJSON object, similar to Array.forEach()

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON object
callbackFunctiona method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex)
excludeWrapCoordbooleanwhether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.

Returns

undefined - undefined

npm install @turf/meta

Note: coordEach is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the coordEach method.

Example

var features = turf.featureCollection([
  turf.point([26, 37], {"foo": "bar"}),
  turf.point([36, 53], {"hello": "world"})
]);

turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
  //=currentCoord
  //=coordIndex
  //=featureIndex
  //=multiFeatureIndex
  //=geometryIndex
});

coordReduce

Reduce coordinates in any GeoJSON object, similar to Array.reduce()

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Geometry|Feature)any GeoJSON object
callbackFunctiona method that takes (previousValue, currentCoord, coordIndex)
initialValue(*)Value to use as the first argument to the first call of the callback.
excludeWrapCoordbooleanwhether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.

Returns

* - The value that results from the reduction.

npm install @turf/meta

Note: coordReduce is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the coordReduce method.

Example

var features = turf.featureCollection([
  turf.point([26, 37], {"foo": "bar"}),
  turf.point([36, 53], {"hello": "world"})
]);

turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
  //=previousValue
  //=currentCoord
  //=coordIndex
  //=featureIndex
  //=multiFeatureIndex
  //=geometryIndex
  return currentCoord;
});

featureEach

Iterate over features in any GeoJSON object, similar to Array.forEach.

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON object
callbackFunctiona method that takes (currentFeature, featureIndex)

Returns

undefined - undefined

npm install @turf/meta

Note: featureEach is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the featureEach method.

Example

var features = turf.featureCollection([
  turf.point([26, 37], {foo: 'bar'}),
  turf.point([36, 53], {hello: 'world'})
]);

turf.featureEach(features, function (currentFeature, featureIndex) {
  //=currentFeature
  //=featureIndex
});

featureReduce

Reduce features in any GeoJSON object, similar to Array.reduce().

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON object
callbackFunctiona method that takes (previousValue, currentFeature, featureIndex)
initialValue(*)Value to use as the first argument to the first call of the callback.

Returns

* - The value that results from the reduction.

npm install @turf/meta

Note: featureReduce is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the featureReduce method.

Example

var features = turf.featureCollection([
  turf.point([26, 37], {"foo": "bar"}),
  turf.point([36, 53], {"hello": "world"})
]);

turf.featureReduce(features, function (previousValue, currentFeature, featureIndex) {
  //=previousValue
  //=currentFeature
  //=featureIndex
  return currentFeature
});

flattenEach

Iterate over flattened features in any GeoJSON object, similar to Array.forEach.

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON object
callbackFunctiona method that takes (currentFeature, featureIndex, multiFeatureIndex)

npm install @turf/meta

Note: flattenEach is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the flattenEach method.

Example

var features = turf.featureCollection([
    turf.point([26, 37], {foo: 'bar'}),
    turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
]);

turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) {
  //=currentFeature
  //=featureIndex
  //=multiFeatureIndex
});

flattenReduce

Reduce flattened features in any GeoJSON object, similar to Array.reduce().

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON object
callbackFunctiona method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex)
initialValue(*)Value to use as the first argument to the first call of the callback.

Returns

* - The value that results from the reduction.

npm install @turf/meta

Note: flattenReduce is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the flattenReduce method.

Example

var features = turf.featureCollection([
    turf.point([26, 37], {foo: 'bar'}),
    turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
]);

turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {
  //=previousValue
  //=currentFeature
  //=featureIndex
  //=multiFeatureIndex
  return currentFeature
});

getCoord

Unwrap a coordinate from a Point Feature, Geometry or a single coordinate.

Arguments

ArgumentTypeDescription
coord(Array |Geometry <Point>|Feature <Point>)GeoJSON Point or an Array of numbers

Returns

Array - coordinates

npm install @turf/invariant

Note: getCoord is part of the @turf/invariant module.

To use it as a stand-alone module will need to import @turf/invariant and call the getCoord method.

Example

var pt = turf.point([10, 10]);

var coord = turf.getCoord(pt);
//= [10, 10]

getCoords

Unwrap coordinates from a Feature, Geometry Object or an Array

Arguments

ArgumentTypeDescription
coords(Array |Geometry|Feature)Feature, Geometry Object or an Array

Returns

Array - coordinates

npm install @turf/invariant

Note: getCoords is part of the @turf/invariant module.

To use it as a stand-alone module will need to import @turf/invariant and call the getCoords method.

Example

var poly = turf.polygon([[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]);

var coords = turf.getCoords(poly);
//= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]]

getGeom

Get Geometry from Feature or Geometry Object

Arguments

ArgumentTypeDescription
geojson(Feature|Geometry)GeoJSON Feature or Geometry Object

Returns

(Geometry|null) - GeoJSON Geometry Object

Throws

Error - if geojson is not a Feature or Geometry Object

npm install @turf/invariant

Note: getGeom is part of the @turf/invariant module.

To use it as a stand-alone module will need to import @turf/invariant and call the getGeom method.

Example

var point = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [110, 40]
  }
}
var geom = turf.getGeom(point)
//={"type": "Point", "coordinates": [110, 40]}

getType

Get GeoJSON object's type, Geometry type is prioritize.

Arguments

ArgumentTypeDescription
geojsonGeoJSONGeoJSON object
namestringname of the variable to display in error message (unused)

Returns

string - GeoJSON type

npm install @turf/invariant

Note: getType is part of the @turf/invariant module.

To use it as a stand-alone module will need to import @turf/invariant and call the getType method.

Example

var point = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [110, 40]
  }
}
var geom = turf.getType(point)
//="Point"

geomEach

Iterate over each geometry in any GeoJSON object, similar to Array.forEach()

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON object
callbackFunctiona method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)

Returns

undefined - undefined

npm install @turf/meta

Note: geomEach is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the geomEach method.

Example

var features = turf.featureCollection([
    turf.point([26, 37], {foo: 'bar'}),
    turf.point([36, 53], {hello: 'world'})
]);

turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
  //=currentGeometry
  //=featureIndex
  //=featureProperties
  //=featureBBox
  //=featureId
});

geomReduce

Reduce geometry in any GeoJSON object, similar to Array.reduce().

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON object
callbackFunctiona method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
initialValue(*)Value to use as the first argument to the first call of the callback.

Returns

* - The value that results from the reduction.

npm install @turf/meta

Note: geomReduce is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the geomReduce method.

Example

var features = turf.featureCollection([
    turf.point([26, 37], {foo: 'bar'}),
    turf.point([36, 53], {hello: 'world'})
]);

turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
  //=previousValue
  //=currentGeometry
  //=featureIndex
  //=featureProperties
  //=featureBBox
  //=featureId
  return currentGeometry
});

propEach

Iterate over properties in any GeoJSON object, similar to Array.forEach()

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature)any GeoJSON object
callbackFunctiona method that takes (currentProperties, featureIndex)

Returns

undefined - undefined

npm install @turf/meta

Note: propEach is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the propEach method.

Example

var features = turf.featureCollection([
    turf.point([26, 37], {foo: 'bar'}),
    turf.point([36, 53], {hello: 'world'})
]);

turf.propEach(features, function (currentProperties, featureIndex) {
  //=currentProperties
  //=featureIndex
});

propReduce

Reduce properties in any GeoJSON object into a single value, similar to how Array.reduce works. However, in this case we lazily run the reduction, so an array of all properties is unnecessary.

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature)any GeoJSON object
callbackFunctiona method that takes (previousValue, currentProperties, featureIndex)
initialValue(*)Value to use as the first argument to the first call of the callback.

Returns

* - The value that results from the reduction.

npm install @turf/meta

Note: propReduce is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the propReduce method.

Example

var features = turf.featureCollection([
    turf.point([26, 37], {foo: 'bar'}),
    turf.point([36, 53], {hello: 'world'})
]);

turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {
  //=previousValue
  //=currentProperties
  //=featureIndex
  return currentProperties
});

segmentEach

Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach() (Multi)Point geometries do not contain segments therefore they are ignored during this operation.

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON
callbackFunctiona method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex)

Returns

undefined - undefined

npm install @turf/meta

Note: segmentEach is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the segmentEach method.

Example

var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);

// Iterate over GeoJSON by 2-vertex segments
turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
  //=currentSegment
  //=featureIndex
  //=multiFeatureIndex
  //=geometryIndex
  //=segmentIndex
});

// Calculate the total number of segments
var total = 0;
turf.segmentEach(polygon, function () {
    total++;
});

segmentReduce

Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce() (Multi)Point geometries do not contain segments therefore they are ignored during this operation.

Arguments

ArgumentTypeDescription
geojson(FeatureCollection|Feature|Geometry)any GeoJSON
callbackFunctiona method that takes (previousValue, currentSegment, currentIndex)
initialValue(*)Value to use as the first argument to the first call of the callback.

Returns

undefined - undefined

npm install @turf/meta

Note: segmentReduce is part of the @turf/meta module.

To use it as a stand-alone module will need to import @turf/meta and call the segmentReduce method.

Example

var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);

// Iterate over GeoJSON by 2-vertex segments
turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
  //= previousSegment
  //= currentSegment
  //= featureIndex
  //= multiFeatureIndex
  //= geometryIndex
  //= segmentIndex
  return currentSegment
});

// Calculate the total number of segments
var initialValue = 0
var total = turf.segmentReduce(polygon, function (previousValue) {
    previousValue++;
    return previousValue;
}, initialValue);

getCluster

Get Cluster

Arguments

ArgumentTypeDescription
geojsonFeatureCollectionGeoJSON Features
filter*Filter used on GeoJSON properties to get Cluster

Returns

FeatureCollection - Single Cluster filtered by GeoJSON Properties

npm install @turf/clusters

Note: getCluster is part of the @turf/clusters module.

To use it as a stand-alone module will need to import @turf/clusters and call the getCluster method.

Example

var geojson = turf.featureCollection([
    turf.point([0, 0], {'marker-symbol': 'circle'}),
    turf.point([2, 4], {'marker-symbol': 'star'}),
    turf.point([3, 6], {'marker-symbol': 'star'}),
    turf.point([5, 1], {'marker-symbol': 'square'}),
    turf.point([4, 2], {'marker-symbol': 'circle'})
]);

// Create a cluster using K-Means (adds `cluster` to GeoJSON properties)
var clustered = turf.clustersKmeans(geojson);

// Retrieve first cluster (0)
var cluster = turf.getCluster(clustered, {cluster: 0});
//= cluster

// Retrieve cluster based on custom properties
turf.getCluster(clustered, {'marker-symbol': 'circle'}).length;
//= 2
turf.getCluster(clustered, {'marker-symbol': 'square'}).length;
//= 1

clusterEach

clusterEach

Arguments

ArgumentTypeDescription
geojsonFeatureCollectionGeoJSON Features
property(string|number)GeoJSON property key/value used to create clusters
callbackFunctiona method that takes (cluster, clusterValue, currentIndex)

Returns

undefined - undefined

npm install @turf/clusters

Note: clusterEach is part of the @turf/clusters module.

To use it as a stand-alone module will need to import @turf/clusters and call the clusterEach method.

Example

var geojson = turf.featureCollection([
    turf.point([0, 0]),
    turf.point([2, 4]),
    turf.point([3, 6]),
    turf.point([5, 1]),
    turf.point([4, 2])
]);

// Create a cluster using K-Means (adds `cluster` to GeoJSON properties)
var clustered = turf.clustersKmeans(geojson);

// Iterate over each cluster
turf.clusterEach(clustered, 'cluster', function (cluster, clusterValue, currentIndex) {
    //= cluster
    //= clusterValue
    //= currentIndex
})

// Calculate the total number of clusters
var total = 0
turf.clusterEach(clustered, 'cluster', function () {
    total++;
});

// Create an Array of all the values retrieved from the 'cluster' property
var values = []
turf.clusterEach(clustered, 'cluster', function (cluster, clusterValue) {
    values.push(clusterValue);
});

clusterReduce

Reduce clusters in GeoJSON Features, similar to Array.reduce()

Arguments

ArgumentTypeDescription
geojsonFeatureCollectionGeoJSON Features
property(string|number)GeoJSON property key/value used to create clusters
callbackFunctiona method that takes (previousValue, cluster, clusterValue, currentIndex)
initialValue(*)Value to use as the first argument to the first call of the callback.

Returns

* - The value that results from the reduction.

npm install @turf/clusters

Note: clusterReduce is part of the @turf/clusters module.

To use it as a stand-alone module will need to import @turf/clusters and call the clusterReduce method.

Example

var geojson = turf.featureCollection([
    turf.point([0, 0]),
    turf.point([2, 4]),
    turf.point([3, 6]),
    turf.point([5, 1]),
    turf.point([4, 2])
]);

// Create a cluster using K-Means (adds `cluster` to GeoJSON properties)
var clustered = turf.clustersKmeans(geojson);

// Iterate over each cluster and perform a calculation
var initialValue = 0
turf.clusterReduce(clustered, 'cluster', function (previousValue, cluster, clusterValue, currentIndex) {
    //=previousValue
    //=cluster
    //=clusterValue
    //=currentIndex
    return previousValue++;
}, initialValue);

// Calculate the total number of clusters
var total = turf.clusterReduce(clustered, 'cluster', function (previousValue) {
    return previousValue++;
}, 0);

// Create an Array of all the values retrieved from the 'cluster' property
var values = turf.clusterReduce(clustered, 'cluster', function (previousValue, cluster, clusterValue) {
    return previousValue.concat(clusterValue);
}, []);

collectionOf

Enforce expectations about types of FeatureCollection inputs for Turf. Internally this uses geojsonType to judge geometry types.

Arguments

ArgumentTypeDescription
featureCollectionFeatureCollectiona FeatureCollection for which features will be judged
typestringexpected GeoJSON type
namestringname of calling function

Throws

Error - if value is not the expected type.

npm install @turf/invariant

Note: collectionOf is part of the @turf/invariant module.

To use it as a stand-alone module will need to import @turf/invariant and call the collectionOf method.

containsNumber

Checks if coordinates contains a number

Arguments

ArgumentTypeDescription
coordinatesArray GeoJSON Coordinates

Returns

boolean - true if Array contains a number

npm install @turf/invariant

Note: containsNumber is part of the @turf/invariant module.

To use it as a stand-alone module will need to import @turf/invariant and call the containsNumber method.

geojsonType

Enforce expectations about types of GeoJSON objects for Turf.

Arguments

ArgumentTypeDescription
valueGeoJSONany GeoJSON object
typestringexpected GeoJSON type
namestringname of calling function

Throws

Error - if value is not the expected type.

npm install @turf/invariant

Note: geojsonType is part of the @turf/invariant module.

To use it as a stand-alone module will need to import @turf/invariant and call the geojsonType method.

featureOf

Enforce expectations about types of Feature inputs for Turf. Internally this uses geojsonType to judge geometry types.

Arguments

ArgumentTypeDescription
featureFeaturea feature with an expected geometry type
typestringexpected GeoJSON type
namestringname of calling function

Throws

Error - error if value is not the expected type.

npm install @turf/invariant

Note: featureOf is part of the @turf/invariant module.

To use it as a stand-alone module will need to import @turf/invariant and call the featureOf method.

booleanClockwise

Takes a ring and return true or false whether or not the ring is clockwise or counter-clockwise.

Arguments

ArgumentTypeDescription
line(Feature <LineString>|LineString|Array >)to be evaluated

Returns

boolean - true/false

npm install @turf/boolean-clockwise

Example

var clockwiseRing = turf.lineString([[0,0],[1,1],[1,0],[0,0]]);
var counterClockwiseRing = turf.lineString([[0,0],[1,0],[1,1],[0,0]]);

turf.booleanClockwise(clockwiseRing)
//=true
turf.booleanClockwise(counterClockwiseRing)
//=false

booleanConcave

Takes a polygon and return true or false as to whether it is concave or not.

Arguments

ArgumentTypeDescription
polygonFeature <Polygon>to be evaluated

Returns

boolean - true/false

npm install @turf/boolean-concave

Example

var convexPolygon = turf.polygon([[[0,0],[0,1],[1,1],[1,0],[0,0]]]);

turf.booleanConcave(convexPolygon)
//=false

booleanContains

Boolean-contains returns True if the second geometry is completely contained by the first geometry. The interiors of both geometries must intersect and, the interior and boundary of the secondary (geometry b) must not intersect the exterior of the primary (geometry a). Boolean-contains returns the exact opposite result of the @turf/boolean-within.

Arguments

ArgumentTypeDescription
feature1(Geometry|Feature )GeoJSON Feature or Geometry
feature2(Geometry|Feature )GeoJSON Feature or Geometry

Returns

boolean - true/false

npm install @turf/boolean-contains

Example

var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
var point = turf.point([1, 2]);

turf.booleanContains(line, point);
//=true

booleanCrosses

Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than the maximum dimension of the two source geometries and the intersection set is interior to both source geometries.

Arguments

ArgumentTypeDescription
feature1(Geometry|Feature )GeoJSON Feature or Geometry
feature2(Geometry|Feature )GeoJSON Feature or Geometry

Returns

boolean - true/false

npm install @turf/boolean-crosses

Example

var line1 = turf.lineString([[-2, 2], [4, 2]]);
var line2 = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);

var cross = turf.booleanCrosses(line1, line2);
//=true

booleanDisjoint

Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.

Arguments

ArgumentTypeDescription
feature1(Geometry|Feature )GeoJSON Feature or Geometry
feature2(Geometry|Feature )GeoJSON Feature or Geometry

Returns

boolean - true/false

npm install @turf/boolean-disjoint

Example

var point = turf.point([2, 2]);
var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);

turf.booleanDisjoint(line, point);
//=true

booleanEqual

Determine whether two geometries of the same type have identical X,Y coordinate values. See http://edndoc.esri.com/arcsde/9.0/general_topics/understand_spatial_relations.htm

Arguments

ArgumentTypeDescription
feature1(Geometry|Feature)GeoJSON input
feature2(Geometry|Feature)GeoJSON input

Returns

boolean - true if the objects are equal, false otherwise

npm install @turf/boolean-equal

Example

var pt1 = turf.point([0, 0]);
var pt2 = turf.point([0, 0]);
var pt3 = turf.point([1, 1]);

turf.booleanEqual(pt1, pt2);
//= true
turf.booleanEqual(pt2, pt3);
//= false

booleanIntersects

Boolean-intersects returns (TRUE) two geometries intersect.

Arguments

ArgumentTypeDescription
feature1(Geometry|Feature )GeoJSON Feature or Geometry
feature2(Geometry|Feature )GeoJSON Feature or Geometry

Returns

boolean - true/false

npm install @turf/boolean-intersects

Example

var point = turf.point([2, 2]);
var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);

turf.booleanIntersects(line, point);
//=true

booleanOverlap

Compares two geometries of the same dimension and returns true if their intersection set results in a geometry different from both but of the same dimension. It applies to Polygon/Polygon, LineString/LineString, Multipoint/Multipoint, MultiLineString/MultiLineString and MultiPolygon/MultiPolygon. In other words, it returns true if the two geometries overlap, provided that neither completely contains the other.

Arguments

Returns

boolean - true/false

npm install @turf/boolean-overlap

Example

var poly1 = turf.polygon([[[0,0],[0,5],[5,5],[5,0],[0,0]]]);
var poly2 = turf.polygon([[[1,1],[1,6],[6,6],[6,1],[1,1]]]);
var poly3 = turf.polygon([[[10,10],[10,15],[15,15],[15,10],[10,10]]]);

turf.booleanOverlap(poly1, poly2)
//=true
turf.booleanOverlap(poly2, poly3)
//=false

booleanParallel

Boolean-Parallel returns True if each segment of line1 is parallel to the correspondent segment of line2

Arguments

ArgumentTypeDescription
line1(Geometry|Feature <LineString>)GeoJSON Feature or Geometry
line2(Geometry|Feature <LineString>)GeoJSON Feature or Geometry

Returns

boolean - true/false if the lines are parallel

npm install @turf/boolean-parallel

Example

var line1 = turf.lineString([[0, 0], [0, 1]]);
var line2 = turf.lineString([[1, 0], [1, 1]]);

turf.booleanParallel(line1, line2);
//=true

booleanPointInPolygon

Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon. The polygon can be convex or concave. The function accounts for holes.

Arguments

ArgumentTypeDescription
pointCoordinput point
polygonFeature <(Polygon|MultiPolygon)>input polygon or multipolygon
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
ignoreBoundarybooleanfalseTrue if polygon boundary should be ignored when determining if the point is inside the polygon otherwise false.

Returns

boolean - true if the Point is inside the Polygon; false if the Point is not inside the Polygon

npm install @turf/boolean-point-in-polygon

Example

var pt = turf.point([-77, 44]);
var poly = turf.polygon([[
  [-81, 41],
  [-81, 47],
  [-72, 47],
  [-72, 41],
  [-81, 41]
]]);

turf.booleanPointInPolygon(pt, poly);
//= true

booleanPointOnLine

Returns true if a point is on a line. Accepts a optional parameter to ignore the start and end vertices of the linestring.

Arguments

ArgumentTypeDescription
ptCoordGeoJSON Point
lineFeature <LineString>GeoJSON LineString
optionsObjectOptional parameters: see below

Options

PropTypeDefaultDescription
ignoreEndVerticesbooleanfalsewhether to ignore the start and end vertices.
epsilon(number)Fractional number to compare with the cross product result. Useful for dealing with floating points such as lng/lat points

Returns

boolean - true/false

npm install @turf/boolean-point-on-line

Example

var pt = turf.point([0, 0]);
var line = turf.lineString([[-1, -1],[1, 1],[1.5, 2.2]]);
var isPointOnLine = turf.booleanPointOnLine(pt, line);
//=true

booleanWithin

Boolean-within returns true if the first geometry is completely within the second geometry. The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a) must not intersect the exterior of the secondary (geometry b). Boolean-within returns the exact opposite result of the @turf/boolean-contains.

Arguments

ArgumentTypeDescription
feature1(Geometry|Feature )GeoJSON Feature or Geometry
feature2(Geometry|Feature )GeoJSON Feature or Geometry

Returns

boolean - true/false

npm install @turf/boolean-within

Example

var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
var point = turf.point([1, 2]);

turf.booleanWithin(point, line);
//=true

bearingToAzimuth

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

Arguments

ArgumentTypeDescription
bearingnumberangle, between -180 and +180 degrees

Returns

number - angle between 0 and 360 degrees

npm install @turf/helpers

Note: bearingToAzimuth is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the bearingToAzimuth method.

convertArea

Converts a area to the requested unit. Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares

Arguments

ArgumentTypeDescription
areanumberto be converted
originalUnitUnitsof the distance
finalUnitUnitsreturned unit

Returns

number - the converted area

npm install @turf/helpers

Note: convertArea is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the convertArea method.

convertLength

Converts a length to the requested unit. Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet

Arguments

ArgumentTypeDescription
lengthnumberto be converted
originalUnitUnitsof the length
finalUnitUnitsreturned unit

Returns

number - the converted length

npm install @turf/helpers

Note: convertLength is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the convertLength method.

degreesToRadians

Converts an angle in degrees to radians

Arguments

ArgumentTypeDescription
degreesnumberangle between 0 and 360 degrees

Returns

number - angle in radians

npm install @turf/helpers

Note: degreesToRadians is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the degreesToRadians method.

lengthToRadians

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

Arguments

ArgumentTypeDescription
distancenumberin real units
unitsstringcan be degrees, radians, miles, inches, yards, metres, meters, kilometres, kilometers.

Returns

number - radians

npm install @turf/helpers

Note: lengthToRadians is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the lengthToRadians method.

lengthToDegrees

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

Arguments

ArgumentTypeDescription
distancenumberin real units
unitsstringcan be degrees, radians, miles, inches, yards, metres, meters, kilometres, kilometers.

Returns

number - degrees

npm install @turf/helpers

Note: lengthToDegrees is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the lengthToDegrees method.

radiansToLength

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

Arguments

ArgumentTypeDescription
radiansnumberin radians across the sphere
unitsstringcan be degrees, radians, miles, inches, yards, metres, meters, kilometres, kilometers.

Returns

number - distance

npm install @turf/helpers

Note: radiansToLength is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the radiansToLength method.

radiansToDegrees

Converts an angle in radians to degrees

Arguments

ArgumentTypeDescription
radiansnumberangle in radians

Returns

number - degrees between 0 and 360 degrees

npm install @turf/helpers

Note: radiansToDegrees is part of the @turf/helpers module.

To use it as a stand-alone module will need to import @turf/helpers and call the radiansToDegrees method.

toMercator

Converts a WGS84 GeoJSON object into Mercator (EPSG:900913) projection

Arguments

ArgumentTypeDescription
geojson(GeoJSON|Position)WGS84 GeoJSON object
options(Object)Optional parameters: see below

Options

PropTypeDefaultDescription
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

GeoJSON - Projected GeoJSON

npm install @turf/projection

Note: toMercator is part of the @turf/projection module.

To use it as a stand-alone module will need to import @turf/projection and call the toMercator method.

Example

var pt = turf.point([-71,41]);
var converted = turf.toMercator(pt);

toWgs84

Converts a Mercator (EPSG:900913) GeoJSON object into WGS84 projection

Arguments

ArgumentTypeDescription
geojson(GeoJSON|Position)Mercator GeoJSON object
options(Object)Optional parameters: see below

Options

PropTypeDefaultDescription
mutatebooleanfalseallows GeoJSON input to be mutated (significant performance increase if true)

Returns

GeoJSON - Projected GeoJSON

npm install @turf/projection

Note: toWgs84 is part of the @turf/projection module.

To use it as a stand-alone module will need to import @turf/projection and call the toWgs84 method.

Example

var pt = turf.point([-7903683.846322424, 5012341.663847514]);
var converted = turf.toWgs84(pt);