Aggregation

collect

Joins attributes FeatureCollection of polygons with a FeatureCollection of points. 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.

collect
Parameters
polygons (FeatureCollection<Polygon>) polygons with values on which to aggregate
points (FeatureCollection<Point>) points to be aggregated
inProperty (string) property to be nested from
outProperty (string) property to be nested into
Returns
FeatureCollection<Polygon>: polygons with properties listed based on outField
Example
var poly1 = polygon([[[0,0],[10,0],[10,10],[0,10],[0,0]]]);
var poly2 = polygon([[[10,0],[20,10],[20,20],[20,0],[10,0]]]);
var polyFC = featurecollection([poly1, poly2]);
var pt1 = point([5,5], {population: 200});
var pt2 = point([1,3], {population: 600});
var pt3 = point([14,2], {population: 100});
var pt4 = point([13,1], {population: 200});
var pt5 = point([19,7], {population: 300});
var ptFC = featurecollection([pt1, pt2, pt3, pt4, pt5]);
var aggregated = aggregate(polyFC, ptFC, 'population', 'values');

aggregated.features[0].properties.values // => [200, 600]);

Measurement

along

Takes a line and returns a point at a specified distance along the line.

along
Parameters
line (Feature<LineString>) input line
distance (number) distance along the line
units ([String] (default miles) ) can be degrees, radians, miles, or kilometers
Returns
Feature<Point>: Point distance units along the line
Example
var line = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [-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 along = turf.along(line, 1, 'miles');

var result = {
  "type": "FeatureCollection",
  "features": [line, along]
};

//=result

area

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

area(input: (Feature | FeatureCollection)): Number
Parameters
input ((Feature | FeatureCollection)) input features
Returns
Number: area in square meters
Example
var polygons = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[
          [-67.031021, 10.458102],
          [-67.031021, 10.53372],
          [-66.929397, 10.53372],
          [-66.929397, 10.458102],
          [-67.031021, 10.458102]
        ]]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[
          [-66.919784, 10.397325],
          [-66.919784, 10.513467],
          [-66.805114, 10.513467],
          [-66.805114, 10.397325],
          [-66.919784, 10.397325]
        ]]
      }
    }
  ]
};

var area = turf.area(polygons);

//=area

bboxPolygon

Takes a bbox and returns an equivalent polygon.

bboxPolygon
Parameters
bbox (Array<number>) an Array of bounding box coordinates in the form: [xLow, yLow, xHigh, yHigh]
Returns
Feature<Polygon>: a Polygon representation of the bounding box
Example
var bbox = [0, 0, 10, 10];

var poly = turf.bboxPolygon(bbox);

//=poly

bearing

Takes two points and finds the geographic bearing between them.

bearing
Parameters
start (Feature<Point>) starting Point
end (Feature<Point>) ending Point
Returns
Number: bearing in decimal degrees
Example
var point1 = {
  "type": "Feature",
  "properties": {
    "marker-color": '#f00'
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-75.343, 39.984]
  }
};
var point2 = {
  "type": "Feature",
  "properties": {
    "marker-color": '#0f0'
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-75.534, 39.123]
  }
};

var points = {
  "type": "FeatureCollection",
  "features": [point1, point2]
};

//=points

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

//=bearing

center

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

center
Parameters
features (FeatureCollection) input features
Returns
Feature<Point>: a Point feature at the absolute center point of all input features
Example
var features = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.522259, 35.4691]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.502754, 35.463455]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.508269, 35.463245]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.516809, 35.465779]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.515372, 35.467072]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.509363, 35.463053]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.511123, 35.466601]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.518547, 35.469327]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.519706, 35.469659]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.517839, 35.466998]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.508678, 35.464942]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-97.514914, 35.463453]
      }
    }
  ]
};

var centerPt = turf.center(features);
centerPt.properties['marker-size'] = 'large';
centerPt.properties['marker-color'] = '#000';

var resultFeatures = features.features.concat(centerPt);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

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.

centroid
Parameters
features ((Feature | FeatureCollection)) input features
Returns
Feature<Point>: the centroid of the input features
Example
var poly = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [105.818939,21.004714],
      [105.818939,21.061754],
      [105.890007,21.061754],
      [105.890007,21.004714],
      [105.818939,21.004714]
    ]]
  }
};

var centroidPt = turf.centroid(poly);

var result = {
  "type": "FeatureCollection",
  "features": [poly, centroidPt]
};

//=result

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.

destination
Parameters
from (Feature<Point>) starting point
distance (number) distance from the starting point
bearing (number) ranging from -180 to 180
units ([String] (default kilometers) ) miles, kilometers, degrees, or radians
Returns
Feature<Point>: destination point
Example
var point = {
  "type": "Feature",
  "properties": {
    "marker-color": "#0f0"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-75.343, 39.984]
  }
};
var distance = 50;
var bearing = 90;
var units = 'miles';

var destination = turf.destination(point, distance, bearing, units);
destination.properties['marker-color'] = '#f00';

var result = {
  "type": "FeatureCollection",
  "features": [point, destination]
};

//=result

distance

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

distance
Parameters
from (Feature<Point>) origin point
to (Feature<Point>) destination point
units ([String] (default kilometers) ) can be degrees, radians, miles, or kilometers
Returns
Number: distance between the two points
Example
var from = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-75.343, 39.984]
  }
};
var to = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-75.534, 39.123]
  }
};
var units = "miles";

var points = {
  "type": "FeatureCollection",
  "features": [from, to]
};

//=points

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

//=distance

envelope

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

envelope
Parameters
fc (FeatureCollection) input features
Returns
Feature<Polygon>: a rectangular Polygon feature that encompasses all vertices
Example
var fc = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "name": "Location A"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [-75.343, 39.984]
      }
    }, {
      "type": "Feature",
      "properties": {
        "name": "Location B"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [-75.833, 39.284]
      }
    }, {
      "type": "Feature",
      "properties": {
        "name": "Location C"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [-75.534, 39.123]
      }
    }
  ]
};

var enveloped = turf.envelope(fc);

var resultFeatures = fc.features.concat(enveloped);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

lineDistance

Takes a line and measures its length in the specified units.

lineDistance
Parameters
line (Feature<LineString>) line to measure
units ([String] (default kilometers) ) can be degrees, radians, miles, or kilometers
Returns
Number: length of the input line
Example
var line = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [-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 length = turf.lineDistance(line, 'miles');

//=line

//=length

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.

midpoint
Parameters
from (Feature<Point>) first point
to (Feature<Point>) second point
Returns
Feature<Point>: a point midway between pt1 and pt2
Example
var pt1 = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [144.834823, -37.771257]
  }
};
var pt2 = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [145.14244, -37.830937]
  }
};

var midpointed = turf.midpoint(pt1, pt2);
midpointed.properties['marker-color'] = '#f00';


var result = {
  "type": "FeatureCollection",
  "features": [pt1, pt2, midpointed]
};

//=result

pointOnSurface

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

  • Given a Polygon, the point will be in the area of the polygon
  • Given a LineString, the point will be along the string
  • Given a Point, the point will the same as the input
pointOnSurface(fc: (Feature | FeatureCollection)): Feature
Parameters
fc ((Feature | FeatureCollection)) any feature or set of features
Returns
Feature: a point on the surface of input
Example
// create a random polygon
var polygon = turf.random('polygon');

//=polygon

var pointOnPolygon = turf.pointOnSurface(polygon);

var resultFeatures = polygon.features.concat(pointOnPolygon);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

square

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

square
Parameters
bbox (Array<number>) a bounding box
Returns
Array<number>: a square surrounding bbox
Example
var bbox = [-20,-20,-15,0];

var squared = turf.square(bbox);

var features = {
  "type": "FeatureCollection",
  "features": [
    turf.bboxPolygon(bbox),
    turf.bboxPolygon(squared)
  ]
};

//=features

Transformation

bezier

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

The bezier spline implementation is by Leszek Rybicki.

bezier
Parameters
line (Feature<LineString>) input LineString
resolution ([Number] (default 10000) ) time in milliseconds between points
sharpness ([Number] (default 0.85) ) a measure of how curvy the path should be between splines
Returns
Feature<LineString>: curved line
Example
var line = {
  "type": "Feature",
  "properties": {
    "stroke": "#f00"
  },
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [-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.bezier(line);
curved.properties = { stroke: '#0f0' };

var result = {
  "type": "FeatureCollection",
  "features": [line, curved]
};

//=result

buffer

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

buffer
Parameters
feature ((Feature | FeatureCollection)) input to be buffered
distance (number) distance to draw the buffer
unit (string) any of the options supported by turf units
Returns
(FeatureCollection<Polygon> | FeatureCollection<MultiPolygon> | Polygon | MultiPolygon): buffered features
Example
var pt = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-90.548630, 14.616599]
  }
};
var unit = 'miles';

var buffered = turf.buffer(pt, 500, unit);
var result = turf.featurecollection([buffered, pt]);

//=result

concave

Takes a set of points and returns a concave hull polygon.

Internally, this uses turf-tin to generate geometries.

concave(points: FeatureCollection<Point>, maxEdge: number, units: string): Feature<Polygon>
Parameters
points (FeatureCollection<Point>) input points
maxEdge (number) the size of an edge necessary for part of the hull to become concave (in miles)
units (string) used for maxEdge distance (miles or kilometers)
Returns
Feature<Polygon>: a concave hull
Throws
  • Error: if maxEdge parameter is missing
  • Error: if units parameter is missing
Example
var points = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.601226, 44.642643]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.591442, 44.651436]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.580799, 44.648749]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.573589, 44.641788]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.587665, 44.64533]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-63.595218, 44.64765]
      }
    }
  ]
};

var hull = turf.concave(points, 1, 'miles');

var resultFeatures = points.features.concat(hull);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

convex

Takes a set of points and returns a convex hull polygon.

Internally this uses the convex-hull module that implements a monotone chain hull.

convex
Parameters
featurecollection (FeatureCollection<Point>) input points
Returns
Feature<Polygon>: a convex hull
Example
var points = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [10.195312, 43.755225]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [10.404052, 43.8424511]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [10.579833, 43.659924]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [10.360107, 43.516688]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [10.14038, 43.588348]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [10.195312, 43.755225]
      }
    }
  ]
};

var hull = turf.convex(points);

var resultFeatures = points.features.concat(hull);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

difference

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

difference
Parameters
poly1 (Feature<Polygon>) input Polygon feaure
poly2 (Feature<Polygon>) Polygon feature to difference from poly1
Returns
Feature<Polygon>: a Polygon feature showing the area of poly1 excluding the area of poly2
Example
var poly1 = {
  "type": "Feature",
  "properties": {
    "fill": "#0f0"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-46.738586, -23.596711],
      [-46.738586, -23.458207],
      [-46.560058, -23.458207],
      [-46.560058, -23.596711],
      [-46.738586, -23.596711]
    ]]
  }
};
var poly2 = {
  "type": "Feature",
  "properties": {
    "fill": "#00f"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-46.650009, -23.631314],
      [-46.650009, -23.5237],
      [-46.509246, -23.5237],
      [-46.509246, -23.631314],
      [-46.650009, -23.631314]
    ]]
  }
};

var differenced = turf.difference(poly1, poly2);
differenced.properties.fill = '#f00';

var polygons = {
  "type": "FeatureCollection",
  "features": [poly1, poly2]
};

//=polygons

//=differenced

intersect

Takes two polygons and finds their intersection. If they share a border, returns the border; if they don't intersect, returns undefined.

intersect
Parameters
poly1 (Feature<Polygon>) the first polygon
poly2 (Feature<Polygon>) the second polygon
Returns
(Feature<Polygon> | undefined | Feature<MultiLineString>): if poly1 and poly2 overlap, returns a Polygon feature representing the area they overlap; if poly1 and poly2 do not overlap, returns undefined ; if poly1 and poly2 share a border, a MultiLineString of the locations where their borders are shared
Example
var poly1 = {
  "type": "Feature",
  "properties": {
    "fill": "#0f0"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-122.801742, 45.48565],
      [-122.801742, 45.60491],
      [-122.584762, 45.60491],
      [-122.584762, 45.48565],
      [-122.801742, 45.48565]
    ]]
  }
}
var poly2 = {
  "type": "Feature",
  "properties": {
    "fill": "#00f"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-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 polygons = {
  "type": "FeatureCollection",
  "features": [poly1, poly2]
};

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

//=polygons

//=intersection

simplify

Takes a LineString or Polygon and returns a simplified version. Internally uses simplify-js to perform simplification.

simplify
Parameters
feature ((Feature<(LineString | Polygon | MultiLineString | MultiPolygon)> | FeatureCollection | GeometryCollection)) feature to be simplified
tolerance (number) simplification tolerance
highQuality (boolean) whether or not to spend more time to create a higher-quality simplification with a different algorithm
Returns
(Feature<(LineString | Polygon | MultiLineString | MultiPolygon)> | FeatureCollection | GeometryCollection): a simplified feature
Example
var feature = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-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 tolerance = 0.01;

var simplified = turf.simplify(
 feature, tolerance, false);

//=feature

//=simplified

union

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

union
Parameters
poly1 (Feature<Polygon>) input polygon
poly2 (Feature<Polygon>) another input polygon
Returns
Feature<(Polygon | MultiPolygon)>: a combined Polygon or MultiPolygon feature
Example
var poly1 = {
  "type": "Feature",
  "properties": {
    "fill": "#0f0"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-82.574787, 35.594087],
      [-82.574787, 35.615581],
      [-82.545261, 35.615581],
      [-82.545261, 35.594087],
      [-82.574787, 35.594087]
    ]]
  }
};
var poly2 = {
  "type": "Feature",
  "properties": {
    "fill": "#00f"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-82.560024, 35.585153],
      [-82.560024, 35.602602],
      [-82.52964, 35.602602],
      [-82.52964, 35.585153],
      [-82.560024, 35.585153]
    ]]
  }
};
var polygons = {
  "type": "FeatureCollection",
  "features": [poly1, poly2]
};

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

//=polygons

//=union

Misc

combine

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

combine
Parameters
fc (FeatureCollection<(Point | LineString | Polygon)>) a FeatureCollection of any type
Returns
FeatureCollection<(MultiPoint | MultiLineString | MultiPolygon)>: a FeatureCollection of corresponding type to input
Example
var fc = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [19.026432, 47.49134]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [19.074497, 47.509548]
      }
    }
  ]
};

var combined = turf.combine(fc);

//=combined

explode

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

explode
Parameters
geojson ((Feature | FeatureCollection)) input features
Returns
FeatureCollection<point>: points representing the exploded input features
Throws
  • Error: if it encounters an unknown geometry type
Example
var poly = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [177.434692, -17.77517],
      [177.402076, -17.779093],
      [177.38079, -17.803937],
      [177.40242, -17.826164],
      [177.438468, -17.824857],
      [177.454948, -17.796746],
      [177.434692, -17.77517]
    ]]
  }
};

var points = turf.explode(poly);

//=poly

//=points

flip

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

flip
Parameters
input ((Feature | FeatureCollection)) input features
Returns
(Feature | FeatureCollection): a feature or set of features of the same type as input with flipped coordinates
Example
var serbia = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [20.566406, 43.421008]
  }
};

//=serbia

var saudiArabia = turf.flip(serbia);

//=saudiArabia

kinks

Takes a polygon and returns points at all self-intersections.

kinks
Parameters
polygon ((Feature<Polygon> | Polygon)) input polygon
Returns
FeatureCollection<Point>: self-intersections
Example
var poly = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-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);

var resultFeatures = kinks.intersections.features.concat(poly);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

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.

This can be useful for extracting only the part of a route between waypoints.

lineSlice
Parameters
point1 (Feature<Point>) starting point
point2 (Feature<Point>) stopping point
line ((Feature<LineString> | LineString)) line to slice
Returns
Feature<LineString>: sliced line
Example
var line = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [-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 = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-77.029609, 38.881946]
  }
};
var stop = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-77.021884, 38.889563]
  }
};

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

//=line

//=sliced

pointOnLine

Takes a Point and a LineString and calculates the closest Point on the LineString.

pointOnLine
Parameters
line (Feature<LineString>) line to snap to
point (Feature<Point>) point to snap from
Returns
Feature<Point>: closest point on the line to point
Example
var line = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [-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 = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-77.037076, 38.884017]
  }
};

var snapped = turf.pointOnLine(line, pt);
snapped.properties['marker-color'] = '#00f'

var result = {
  "type": "FeatureCollection",
  "features": [line, pt, snapped]
};

//=result

Helper

featureCollection

Takes one or more Features and creates a FeatureCollection.

featureCollection
Parameters
features (Array<Feature>) input features
Returns
FeatureCollection: a FeatureCollection of input features
Example
var features = [
 turf.point([-75.343, 39.984], {name: 'Location A'}),
 turf.point([-75.833, 39.284], {name: 'Location B'}),
 turf.point([-75.534, 39.123], {name: 'Location C'})
];

var fc = turf.featureCollection(features);

//=fc

feature

Wraps a GeoJSON Geometry in a GeoJSON Feature.

feature
Parameters
geometry (Geometry) input geometry
properties (Object) properties
Returns
FeatureCollection: a FeatureCollection of input features
Example
var geometry = {
     "type": "Point",
     "coordinates": [
       67.5,
       32.84267363195431
     ]
   }

var feature = turf.feature(geometry);

//=feature

lineString

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

lineString
Parameters
coordinates (Array<Array<number>>) an array of Positions
properties ([Object]) an Object of key-value pairs to add as properties
Returns
Feature<LineString>: a LineString feature
Throws
  • Error: if no coordinates are passed
Example
var linestring1 = turf.lineString([
[-21.964416, 64.148203],
[-21.956176, 64.141316],
[-21.93901, 64.135924],
[-21.927337, 64.136673]
]);
var linestring2 = turf.lineString([
[-21.929054, 64.127985],
[-21.912918, 64.134726],
[-21.916007, 64.141016],
	[-21.930084, 64.14446]
], {name: 'line 1', distance: 145});

//=linestring1

//=linestring2

multiLineString

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

multiLineString
Parameters
coordinates (Array<Array<Array<number>>>) an array of LineStrings
properties ([Object]) an Object of key-value pairs to add as properties
Returns
Feature<MultiLineString>: a MultiLineString feature
Throws
  • Error: if no coordinates are passed
Example
var multiLine = turf.multiLineString([[[0,0],[10,10]]]);

//=multiLine

point

Takes coordinates and properties (optional) and returns a new Point feature.

point
Parameters
coordinates (Array<number>) longitude, latitude position (each in decimal degrees)
properties ([Object]) an Object that is used as the Feature 's properties
Returns
Feature<Point>: a Point feature
Example
var pt1 = turf.point([-75.343, 39.984]);

//=pt1

polygon

Takes an array of LinearRings and optionally an Object with properties and returns a Polygon feature.

polygon
Parameters
coordinates (Array<Array<Array<number>>>) an array of LinearRings
properties ([Object]) a properties object
Returns
Feature<Polygon>: a Polygon feature
Throws
  • Error: throw an error if a LinearRing of the polygon has too few positions or if a LinearRing of the Polygon does not have matching Positions at the beginning & end.
Example
var polygon = turf.polygon([[
 [-2.275543, 53.464547],
 [-2.275543, 53.489271],
 [-2.215118, 53.489271],
 [-2.215118, 53.464547],
 [-2.275543, 53.464547]
]], { name: 'poly1', population: 400});

//=polygon

multiPoint

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

multiPoint
Parameters
coordinates (Array<Array<number>>) an array of Positions
properties ([Object]) an Object of key-value pairs to add as properties
Returns
Feature<MultiPoint>: a MultiPoint feature
Throws
  • Error: if no coordinates are passed
Example
var multiPt = turf.multiPoint([[0,0],[10,10]]);

//=multiPt

multiPolygon

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

multiPolygon
Parameters
coordinates (Array<Array<Array<Array<number>>>>) an array of Polygons
properties ([Object]) an Object of key-value pairs to add as properties
Returns
Feature<MultiPolygon>: a multipolygon feature
Throws
  • Error: if no coordinates are passed
Example
var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]);

//=multiPoly

geometryCollection

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

geometryCollection
Parameters
geometries (Array<{Geometry}>) an array of GeoJSON Geometries
properties ([Object]) an Object of key-value pairs to add as properties
Returns
Feature<GeometryCollection>: a geometrycollection feature
Example
var pt = {
    "type": "Point",
      "coordinates": [100, 0]
    };
var line = {
    "type": "LineString",
    "coordinates": [ [101, 0], [102, 1] ]
  };
var collection = turf.geometrycollection([[0,0],[10,10]]);

//=collection

Data

random

Generates random GeoJSON data, including Points and Polygons, for testing and experimentation.

random
Parameters
type ([String] (default 'point') ) type of features desired: 'points' or 'polygons'
count ([Number] (default 1) ) how many geometries should be generated.
options (Object) options relevant to the feature desired. Can include:
Name Description
options.bbox Array<number> a bounding box inside of which geometries are placed. In the case of Point features, they are guaranteed to be within this bounds, while Polygon features have their centroid within the bounds.
options.num_vertices [Number] (default 10) options.vertices the number of vertices added to polygon features.
options.max_radial_length [Number] (default 10) the total number of decimal degrees longitude or latitude that a polygon can extent outwards to from its center.
Returns
FeatureCollection: generated random features
Example
var points = turf.random('points', 100, {
  bbox: [-70, 40, -60, 60]
});

//=points

var polygons = turf.random('polygons', 4, {
  bbox: [-70, 40, -60, 60]
});

//=polygons

sample

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

sample
Parameters
featurecollection (FeatureCollection) set of input features
num (number) number of features to select
Returns
FeatureCollection: a FeatureCollection with n features
Example
var points = turf.random('points', 1000);

//=points

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

//=sample

Interpolation

isolines

Takes points with z-values and an array of value breaks and generates isolines.

isolines
Parameters
points (FeatureCollection<Point>) input points
z (string) the property name in points from which z-values will be pulled
resolution (number) resolution of the underlying grid
breaks (Array<number>) where to draw contours
Returns
FeatureCollection<LineString>: isolines
Example
// create random points with random
// z-values in their properties
var points = turf.random('point', 100, {
  bbox: [0, 30, 20, 50]
});
for (var i = 0; i < points.features.length; i++) {
  points.features[i].properties.z = Math.random() * 10;
}
var breaks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var isolined = turf.isolines(points, 'z', 15, breaks);
//=isolined

planepoint

Takes a triangular plane as a Polygon and a Point within that triangle and returns the z-value at that point. The Polygon needs to have properties a, b, and c that define the values at its three corners.

planepoint
Parameters
point (Feature<Point>) the Point for which a z-value will be calculated
triangle (Feature<Polygon>) a Polygon feature with three vertices
Returns
Number: the z-value for interpolatedPoint
Example
var point = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Point",
    "coordinates": [-75.3221, 39.529]
  }
};
var point = turf.point([-75.3221, 39.529]);
// triangle is a polygon with "a", "b",
// and "c" values representing
// the values of the coordinates in order.
var triangle = {
  "type": "Feature",
  "properties": {
    "a": 11,
    "b": 122,
    "c": 44
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-75.1221, 39.57],
      [-75.58, 39.18],
      [-75.97, 39.86],
      [-75.1221, 39.57]
    ]]
  }
};

var features = {
  "type": "FeatureCollection",
  "features": [triangle, point]
};

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

//=features

//=zValue

tin

Takes a set of points and the name of a z-value property 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.

This triangulates the points, as well as adds properties called a, b, and c representing the value of the given propertyName at each of the points that represent the corners of the triangle.

tin
Parameters
points (FeatureCollection<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
Example
// generate some random point data
var points = turf.random('points', 30, {
  bbox: [50, 30, 70, 50]
});
//=points
// 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')
for (var i = 0; i < tin.features.length; i++) {
  var properties  = tin.features[i].properties;
  // roughly turn the properties of each
  // triangle into a fill color
  // so we can visualize the result
  properties.fill = '#' + properties.a +
    properties.b + properties.c;
}
//=tin

Joins

inside

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.

inside
Parameters
point (Feature<Point>) input point
polygon (Feature<(Polygon | MultiPolygon)>) input polygon or multipolygon
Returns
Boolean: true if the Point is inside the Polygon; false if the Point is not inside the Polygon
Example
var pt1 = {
  "type": "Feature",
  "properties": {
    "marker-color": "#f00"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-111.467285, 40.75766]
  }
};
var pt2 = {
  "type": "Feature",
  "properties": {
    "marker-color": "#0f0"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-111.873779, 40.647303]
  }
};
var poly = {
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
      [-112.074279, 40.52215],
      [-112.074279, 40.853293],
      [-111.610107, 40.853293],
      [-111.610107, 40.52215],
      [-112.074279, 40.52215]
    ]]
  }
};

var features = {
  "type": "FeatureCollection",
  "features": [pt1, pt2, poly]
};

//=features

var isInside1 = turf.inside(pt1, poly);
//=isInside1

var isInside2 = turf.inside(pt2, poly);
//=isInside2

tag

Takes a set of points and a set of polygons and performs a spatial join.

tag
Parameters
points (FeatureCollection<Point>) input points
polygons (FeatureCollection<Polygon>) input polygons
field (string) property in polygons to add to joined Point features
outField (string) property in points in which to store joined property from `polygons
Returns
FeatureCollection<Point>: points with containingPolyId property containing values from polyId
Example
var bbox = [0, 0, 10, 10];
// create a triangular grid of polygons
var triangleGrid = turf.triangleGrid(bbox, 50, 'miles');
triangleGrid.features.forEach(function(f) {
  f.properties.fill = '#' +
    (~~(Math.random() * 16)).toString(16) +
    (~~(Math.random() * 16)).toString(16) +
    (~~(Math.random() * 16)).toString(16);
  f.properties.stroke = 0;
  f.properties['fill-opacity'] = 1;
});
var randomPoints = turf.random('point', 30, {
  bbox: bbox
});
var both = turf.featurecollection(
  triangleGrid.features.concat(randomPoints.features));

//=both

var tagged = turf.tag(randomPoints, triangleGrid,
                      'fill', 'marker-color');

//=tagged

Grids

hexGrid

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

hexGrid
Parameters
bbox (Array<number>) bounding box in [minX, minY, maxX, maxY] order
cellSize (number) dimension of cell in specified units
units (string) used in calculating cellWidth ('miles' or 'kilometers')
triangles (boolean) whether to return as triangles instead of hexagons
Returns
FeatureCollection<Polygon>: a hexagonal grid
Example
var bbox = [-96,31,-84,40];
var cellWidth = 50;
var units = 'miles';

var hexgrid = turf.hexGrid(bbox, cellWidth, units);

//=hexgrid

pointGrid

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

pointGrid
Parameters
bbox (Array<number>) extent in [minX, minY, maxX, maxY] order
cellSize (number) the distance across each cell
units ([string] (default kilometers) ) used in calculating cellWidth, can be degrees, radians, miles, or kilometers
Returns
FeatureCollection<Point>: grid of points
Example
var extent = [-70.823364, -33.553984, -70.473175, -33.302986];
var cellWidth = 3;
var units = 'miles';

var grid = turf.pointGrid(extent, cellWidth, units);

//=grid

squareGrid

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

squareGrid
Parameters
bbox (Array<number>) extent in [minX, minY, maxX, maxY] order
cellSize (number) width of each cell
units (string) units to use for cellWidth
Returns
FeatureCollection<Polygon>: grid a grid of polygons
Example
var extent = [-77.3876953125,38.71980474264239,-76.9482421875,39.027718840211605];
var cellWidth = 10;
var units = 'miles';

var squareGrid = turf.squareGrid(extent, cellWidth, units);

//=squareGrid

triangleGrid

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

triangleGrid
Parameters
bbox (Array<number>) extent in [minX, minY, maxX, maxY] order
cellSize (number) dimension of each cell
units (string) units to use for cellWidth
Returns
FeatureCollection<Polygon>: grid of polygons
Example
var extent = [-77.3876953125,38.71980474264239,-76.9482421875,39.027718840211605];
var cellWidth = 10;
var units = 'miles';

var triangleGrid = turf.triangleGrid(extent, cellWidth, units);

//=triangleGrid

within

Takes a set of points and a set of polygons and returns the points that fall within the polygons.

within
Parameters
points (FeatureCollection<Point>) input points
polygons (FeatureCollection<Polygon>) input polygons
Returns
FeatureCollection<Point>: points that land within at least one polygon
Example
var searchWithin = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [[
          [-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 points = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-46.6318, -23.5523]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-46.6246, -23.5325]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-46.6062, -23.5513]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-46.663, -23.554]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [-46.643, -23.557]
      }
    }
  ]
};

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

//=points

//=searchWithin

//=ptsWithin

Classification

nearest

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.

nearest
Parameters
targetPoint (Feature<Point>) the reference point
points (FeatureCollection<Point>) against input point set
Returns
Feature<Point>: the closest point in the set to the reference point
Example
var point = {
  "type": "Feature",
  "properties": {
    "marker-color": "#0f0"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [28.965797, 41.010086]
  }
};
var against = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [28.973865, 41.011122]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [28.948459, 41.024204]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [28.938674, 41.013324]
      }
    }
  ]
};

var nearest = turf.nearest(point, against);
nearest.properties['marker-color'] = '#f00';

var resultFeatures = against.features.concat(point);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

Meta

propEach

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

propEach(layer: Object, callback: Function)
Parameters
layer (Object) any GeoJSON object
callback (Function) a method that takes (value)
Example
var point = { type: 'Feature', geometry: null, properties: { foo: 1 } };
propEach(point, function(props) {
  // props is equal to { foo: 1}
});

coordEach

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

coordEach(layer: Object, callback: Function, excludeWrapCoord: [boolean])
Parameters
layer (Object) any GeoJSON object
callback (Function) a method that takes (value)
excludeWrapCoord ([boolean]) whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
Example
var point = { type: 'Point', coordinates: [0, 0] };
coordEach(point, function(coords) {
  // coords is equal to [0, 0]
});

coordReduce

Reduce coordinates 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 coordinates is unnecessary.

coordReduce(layer: Object, callback: Function, memo: Any, excludeWrapCoord: [boolean]): Any
Parameters
layer (Object) any GeoJSON object
callback (Function) a method that takes (memo, value) and returns a new memo
memo (Any) the starting value of memo: can be any type.
excludeWrapCoord ([boolean]) whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
Returns
Any: combined value

featureEach

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

featureEach(layer: Object, callback: Function)
Parameters
layer (Object) any GeoJSON object
callback (Function) a method that takes (value)
Example
var feature = { type: 'Feature', geometry: null, properties: {} };
featureEach(feature, function(feature) {
  // feature == feature
});

getCoord

Unwrap a coordinate from a Feature with a Point geometry, a Point geometry, or a single coordinate.

getCoord(obj: Any): Array<number>
Parameters
obj (Any) any value
Returns
Array<number>: a coordinate

Assertions

featureOf

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

featureOf(feature: Feature, type: string, name: string)
Parameters
feature (Feature) a feature with an expected geometry type
type (string) expected GeoJSON type
name (string) name of calling function
Throws
  • Error: error if value is not the expected type.

collectionOf

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

collectionOf(featurecollection: FeatureCollection, type: string, name: string)
Parameters
featurecollection (FeatureCollection) a featurecollection for which features will be judged
type (string) expected GeoJSON type
name (string) name of calling function
Throws
  • Error: if value is not the expected type.

bbox

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

bbox
Parameters
geojson ((Feature | FeatureCollection)) input features
Returns
Array<number>: the bounding box of input given as an array in WSEN order (west, south, east, north)
Example
var input = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [114.175329, 22.2524]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [114.170007, 22.267969]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [114.200649, 22.274641]
      }
    }, {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [114.186744, 22.265745]
      }
    }
  ]
};

var bbox = turf.bbox(input);

var bboxPolygon = turf.bboxPolygon(bbox);

var resultFeatures = input.features.concat(bboxPolygon);
var result = {
  "type": "FeatureCollection",
  "features": resultFeatures
};

//=result

circle

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

circle
Parameters
center (Feature<Point>) center point
radius (number) radius of the circle
steps (number) number of steps
units ([String] (default kilometers) ) miles, kilometers, degrees, or radians
Returns
Feature<Polygon>: circle polygon
Example
var center = {
  "type": "Feature",
  "properties": {
    "marker-color": "#0f0"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-75.343, 39.984]
  }
};
var radius = 5;
var steps = 10;
var units = 'kilometers';

var circle = turf.circle(center, radius, steps, units);

var result = {
  "type": "FeatureCollection",
  "features": [center, circle]
};

//=result

geojsonType

Enforce expectations about types of GeoJSON objects for Turf.

geojsonType(value: GeoJSON, type: string, name: string)
Parameters
value (GeoJSON) any GeoJSON object
type (string) expected GeoJSON type
name (string) name of calling function
Throws
  • Error: if value is not the expected type.

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.

propReduce(layer: Object, callback: Function, memo: Any): Any
Parameters
layer (Object) any GeoJSON object
callback (Function) a method that takes (memo, coord) and returns a new memo
memo (Any) the starting value of memo: can be any type.
Returns
Any: combined value

coordAll

Get all coordinates from any GeoJSON object, returning an array of coordinate arrays.

coordAll(layer: Object): Array<Array<Number>>
Parameters
layer (Object) any GeoJSON object
Returns
Array<Array<Number>>: coordinate position array

tesselate

Tesselates a Feature<Polygon> into a FeatureCollection<Polygon> of triangles using earcut.

tesselate
Parameters
polygon (Feature<Polygon>) the polygon to tesselate
Returns
FeatureCollection<Polygon>: a geometrycollection feature
Example
var polygon = {"type":"Feature","id":"USA-CA","properties":{"name":"California"},"geometry":{"type":"Polygon","coordinates":[[[-123.233256,42.006186],[-122.378853,42.011663],[-121.037003,41.995232],[-120.001861,41.995232],[-119.996384,40.264519],[-120.001861,38.999346],[-118.71478,38.101128],[-117.498899,37.21934],[-116.540435,36.501861],[-115.85034,35.970598],[-114.634459,35.00118],[-114.634459,34.87521],[-114.470151,34.710902],[-114.333228,34.448009],[-114.136058,34.305608],[-114.256551,34.174162],[-114.415382,34.108438],[-114.535874,33.933176],[-114.497536,33.697668],[-114.524921,33.54979],[-114.727567,33.40739],[-114.661844,33.034958],[-114.524921,33.029481],[-114.470151,32.843265],[-114.524921,32.755634],[-114.72209,32.717295],[-116.04751,32.624187],[-117.126467,32.536556],[-117.24696,32.668003],[-117.252437,32.876127],[-117.329114,33.122589],[-117.471515,33.297851],[-117.7837,33.538836],[-118.183517,33.763391],[-118.260194,33.703145],[-118.413548,33.741483],[-118.391641,33.840068],[-118.566903,34.042715],[-118.802411,33.998899],[-119.218659,34.146777],[-119.278905,34.26727],[-119.558229,34.415147],[-119.875891,34.40967],[-120.138784,34.475393],[-120.472878,34.448009],[-120.64814,34.579455],[-120.609801,34.858779],[-120.670048,34.902595],[-120.631709,35.099764],[-120.894602,35.247642],[-120.905556,35.450289],[-121.004141,35.461243],[-121.168449,35.636505],[-121.283465,35.674843],[-121.332757,35.784382],[-121.716143,36.195153],[-121.896882,36.315645],[-121.935221,36.638785],[-121.858544,36.6114],[-121.787344,36.803093],[-121.929744,36.978355],[-122.105006,36.956447],[-122.335038,37.115279],[-122.417192,37.241248],[-122.400761,37.361741],[-122.515777,37.520572],[-122.515777,37.783465],[-122.329561,37.783465],[-122.406238,38.15042],[-122.488392,38.112082],[-122.504823,37.931343],[-122.701993,37.893004],[-122.937501,38.029928],[-122.97584,38.265436],[-123.129194,38.451652],[-123.331841,38.566668],[-123.44138,38.698114],[-123.737134,38.95553],[-123.687842,39.032208],[-123.824765,39.366301],[-123.764519,39.552517],[-123.85215,39.831841],[-124.109566,40.105688],[-124.361506,40.259042],[-124.410798,40.439781],[-124.158859,40.877937],[-124.109566,41.025814],[-124.158859,41.14083],[-124.065751,41.442061],[-124.147905,41.715908],[-124.257444,41.781632],[-124.213628,42.000709],[-123.233256,42.006186]]]}};

var triangles = turf.tesselate(polygon);

//=triangles