Options
All
  • Public
  • Public/Protected
  • All
Menu

Module turf

Index

Functions

aggregate

  • Calculates a series of aggregations for a set of points within a set of polygons. Sum, average, count, min, max, and deviation are supported.

    Parameters

    • polygons: FeatureCollection

      Polygons with values on which to aggregate

    • points: FeatureCollection

      Points to be aggregated

    • aggregations: Array<object>

      An array of aggregation objects

    Returns FeatureCollection

    Polygons with properties listed based on outField values in aggregations

along

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

    Parameters

    • line: Feature

      Input line

    • distance: number

      Distance along the line

    • Optional units: string

    Returns Feature

    Point along the line

area

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

    Parameters

    Returns number

    Area in square meters

average

  • Calculates the average value of a field for a set of points within a set of polygons.

    Parameters

    • polygons: FeatureCollection

      Polygons with values on which to average

    • points: FeatureCollection

      Points from which to calculate the average

    • field: string

      The field in the points features from which to pull values to average

    • outField: string

      The field in polygons to put results of the averages

    Returns FeatureCollection

    Polygons with the value of outField set to the calculated averages

bboxPolygon

  • bboxPolygon(bbox: Array<number>): Feature
  • Takes a bbox and returns an equivalent polygon.

    Parameters

    • bbox: Array<number>

      An Array of bounding box coordinates in the form: [xLow, yLow, xHigh, yHigh]

    Returns Feature

    A Polygon representation of the bounding box

bearing

  • Takes two points and finds the geographic bearing between them.

    Parameters

    Returns number

    Bearing in decimal degrees

bezier

  • bezier(line: Feature, resolution?: number, sharpness?: number): Feature
  • Takes a line and returns a curved version by applying a Bezier spline algorithm. The bezier spline implementation is by Leszek Rybicki.

    Parameters

    • line: Feature

      Input LineString

    • Optional resolution: number
    • Optional sharpness: number

    Returns Feature

    Curved line

buffer

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

    Parameters

    • feature: Feature | FeatureCollection

      Input to be buffered

    • distance: number

      Distance to draw the buffer

    • units: string

      'miles', 'kilometers', 'radians', or 'degrees'

    Returns Feature | FeatureCollection

    Buffered features

center

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

    Parameters

    Returns Feature

    A Point feature at the absolute center point of all input features

centroid

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

    Parameters

    Returns Feature

    The centroid of the input features

combine

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

    Parameters

    Returns FeatureCollection

    A FeatureCollection of corresponding type to input

concave

  • Takes a set of points and returns a concave hull polygon. Internally, this implements a Monotone chain algorithm.

    Parameters

    • points: FeatureCollection

      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

    A concave hull

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.

    Parameters

    Returns Feature

    A convex hull

count

  • Takes a set of points and a set of polygons and calculates the number of points that fall within the set of polygons.

    Parameters

    • polygons: FeatureCollection

      Input polygons

    • points: FeatureCollection

      Input points

    • countField: string

      A field to append to the attributes of the Polygon features representing Point counts

    Returns FeatureCollection

    Polygons with countField appended

destination

  • destination(start: Feature, distance: number, bearing: number, units: string): Feature
  • 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.

    Parameters

    • start: Feature

      Starting point

    • distance: number

      Distance from the starting point

    • bearing: number

      Ranging from -180 and 180

    • units: string

      'miles', 'kilometers', 'radians', or 'degrees'

    Returns Feature

    Destination point

deviation

  • Calculates the standard deviation value of a field for a set of points within a set of polygons.

    Parameters

    • polygons: FeatureCollection

      Input polygons

    • points: FeatureCollection

      Input points

    • inField: string

      The field in points from which to aggregate

    • outField: string

      The field to append to polygons representing deviation

    Returns FeatureCollection

    Polygons with appended field representing deviation

difference

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

    Parameters

    • poly1: Feature

      Input Polygon feaure

    • poly2: Feature

      Polygon feature to difference from poly1

    Returns Feature

    A Polygon feature showing the area of poly1 excluding the area of poly2

distance

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

    Parameters

    • from: Feature

      Origin point

    • to: Feature

      Destination point

    • Optional units: string

    Returns number

    Distance between the two points

envelope

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

    Parameters

    Returns Feature

    A rectangular Polygon feature that encompasses all vertices

explode

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

    Parameters

    Returns FeatureCollection

    Points representing the exploded input features

extent

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

    Parameters

    Returns Array<number>

    The bounding box of input given as an array in WSEN order (west, south, east, north)

featurecollection

  • Takes one or more Features and creates a FeatureCollection.

    Parameters

    • features: Array<Feature>

      Input features

    Returns FeatureCollection

    A FeatureCollection of input features

filter

  • Takes a FeatureCollection and filters it by a given property and value.

    Parameters

    • features: FeatureCollection

      Input features

    • key: string

      The property on which to filter

    • value: string

      The value of that property on which to filter

    Returns FeatureCollection

    A filtered collection with only features that match input key and value

flip

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

    Parameters

    Returns Feature | FeatureCollection

    A feature or set of features of the same type as input with flipped coordinates

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.

    Parameters

    • bbox: Array<number>

      Bounding box in [minX, minY, maxX, maxY] order

    • cellWidth: number

      Width of cell in specified units

    • units: string

      Used in calculating cellWidth ('miles' or 'kilometers')

    Returns FeatureCollection

    A hexagonal grid

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.

    Parameters

    • point: Feature

      Input point

    • polygon: Feature

      Input polygon or multipolygon

    Returns boolean

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

intersect

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

    Parameters

    Returns Feature

    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

isolines

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

    Parameters

    • points: FeatureCollection

      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

    Isolines

jenks

  • jenks(input: FeatureCollection, field: string, numberOfBreaks: number): Array<number>
  • Takes a set of features and returns an array of the Jenks Natural breaks for a given property.

    Parameters

    • input: FeatureCollection

      Input features

    • field: string

      The property in input on which to calculate Jenks natural breaks

    • numberOfBreaks: number

      Number of classes in which to group the data

    Returns Array<number>

    The break number for each class plus the minimum and maximum values

kinks

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

    Parameters

    Returns FeatureCollection

    Self-intersections

lineDistance

  • lineDistance(line: Feature, units: string): number
  • Takes a line and measures its length in the specified units.

    Parameters

    • line: Feature

      Line to measure

    • units: string

      'miles', 'kilometers', 'radians', or 'degrees'

    Returns number

    Length of the input line

lineSlice

  • Takes a line, a start Point, and a stop point and returns the line in between those points.

    Parameters

    Returns Feature

    Sliced line

linestring

  • linestring(coordinates: Array<Array<number>>, properties?: any): Feature
  • Creates a LineString based on a coordinate array. Properties can be added optionally.

    Parameters

    • coordinates: Array<Array<number>>

      An array of Positions

    • Optional properties: any

    Returns Feature

    A LineString feature

max

  • Calculates the maximum value of a field for a set of points within a set of polygons.

    Parameters

    • polygons: FeatureCollection

      Input polygons

    • points: FeatureCollection

      Input points

    • inField: string

      The field in input data to analyze

    • outField: string

      The field in which to store results

    Returns FeatureCollection

    Polygons with properties listed as outField values

median

  • Calculates the median value of a field for a set of points within a set of polygons.

    Parameters

    • polygons: FeatureCollection

      Input polygons

    • points: FeatureCollection

      Input points

    • inField: string

      The field in input data to analyze

    • outField: string

      The field in which to store results

    Returns FeatureCollection

    Polygons with properties listed as outField values

merge

  • Takes a set of polygons and returns a single merged polygon feature. If the input polygon features are not contiguous, this function returns a MultiPolygon feature.

    Parameters

    Returns Feature

    Merged polygon or multipolygon

midpoint

  • Takes two points and returns a point midway between them.

    Parameters

    Returns Feature

    A point midway between pt1 and pt2

min

  • Calculates the minimum value of a field for a set of points within a set of polygons.

    Parameters

    • polygons: FeatureCollection

      Input polygons

    • points: FeatureCollection

      Input points

    • inField: string

      The field in input data to analyze

    • outField: string

      The field in which to store results

    Returns FeatureCollection

    Polygons with properties listed as outField values

nearest

  • Takes a reference point and a set of points and returns the point from the set closest to the reference.

    Parameters

    Returns Feature

    The closest point in the set to the reference point

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.

    Parameters

    • interpolatedPoint: Feature

      The Point for which a z-value will be calculated

    • triangle: Feature

      A Polygon feature with three vertices

    Returns number

    The z-value for interpolatedPoint

point

  • point(coordinates: Array<number>, properties?: any): Feature
  • Takes coordinates and properties (optional) and returns a new Point feature.

    Parameters

    • coordinates: Array<number>

      Longitude, latitude position (each in decimal degrees)

    • Optional properties: any

    Returns Feature

    A Point feature

pointGrid

  • pointGrid(extent: Array<number>, cellWidth: number, units: string): FeatureCollection
  • Takes a bounding box and a cell depth and returns a set of points in a grid.

    Parameters

    • extent: Array<number>

      Extent in [minX, minY, maxX, maxY] order

    • cellWidth: number

      The distance across each cell

    • units: string

      Used in calculating cellWidth ('miles' or 'kilometers')

    Returns FeatureCollection

    Grid of points

pointOnLine

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

    Parameters

    Returns Feature

    Closest point on the line to point

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.

    Parameters

    Returns Feature

    A point on the surface of input

polygon

  • polygon(rings: Array<Array<Array<number>>>, properties?: any): Feature
  • Takes an array of LinearRings and optionally an Object with properties and returns a Polygon feature.

    Parameters

    • rings: Array<Array<Array<number>>>

      An array of LinearRings

    • Optional properties: any

    Returns Feature

    A Polygon feature

quantile

  • quantile(input: FeatureCollection, field: string, percentiles: Array<number>): Array<number>
  • Takes a FeatureCollection, a property name, and a set of percentiles and returns a quantile array.

    Parameters

    • input: FeatureCollection

      Set of features

    • field: string

      The property in input from which to retrieve quantile values

    • percentiles: Array<number>

      An Array of percentiles on which to calculate quantile values

    Returns Array<number>

    An array of the break values

random

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

    Parameters

    • Optional type: string
    • Optional count: number
    • Optional options: object
      • Optional bbox?: Array<number>
      • Optional max_radial_length?: number
      • Optional num_vertices?: number

    Returns FeatureCollection

    Generated random features

reclass

  • Takes a FeatureCollection, an input field, an output field, and an array of translations and outputs an identical FeatureCollection with the output field property populated.

    Parameters

    • input: FeatureCollection

      Set of input features

    • inField: string

      The field to translate

    • outField: string

      The field in which to store translated results

    • translations: Array<any>

      An array of translations

    Returns FeatureCollection

    A FeatureCollection with identical geometries to input but with outField populated.

remove

  • Takes a FeatureCollection of any type, a property, and a value and returns a FeatureCollection with features matching that property-value pair removed.

    Parameters

    • features: FeatureCollection

      Set of input features

    • property: string

      The property to remove

    • value: string

      The value to remove

    Returns FeatureCollection

    The resulting FeatureCollection without features that match the property-value pair

sample

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

    Parameters

    • features: FeatureCollection

      Set of input features

    • n: number

      Number of features to select

    Returns FeatureCollection

    A FeatureCollection with n features

simplify

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

    Parameters

    • feature: Feature | 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 | FeatureCollection | GeometryCollection

    A simplified feature

size

  • size(bbox: Array<number>, factor: number): Array<number>
  • Takes a bounding box and returns a new bounding box with a size expanded or contracted by a factor of X.

    Parameters

    • bbox: Array<number>

      A bounding box

    • factor: number

      The ratio of the new bbox to the input bbox

    Returns Array<number>

    The resized bbox

square

  • square(bbox: Array<number>): Array<number>
  • Takes a bounding box and calculates the minimum square bounding box that would contain the input.

    Parameters

    • bbox: Array<number>

      A bounding box

    Returns Array<number>

    A square surrounding bbox

squareGrid

  • squareGrid(extent: Array<number>, cellWidth: number, units: string): FeatureCollection
  • Takes a bounding box and a cell depth and returns a set of square polygons in a grid.

    Parameters

    • extent: Array<number>

      Extent in [minX, minY, maxX, maxY] order

    • cellWidth: number

      Width of each cell

    • units: string

      Used in calculating cellWidth ('miles' or 'kilometers')

    Returns FeatureCollection

    Grid of polygons

sum

  • Calculates the sum of a field for a set of points within a set of polygons.

    Parameters

    • polygons: FeatureCollection

      Input polygons

    • points: FeatureCollection

      Input points

    • inField: string

      The field in input data to analyze

    • outField: string

      The field in which to store results

    Returns FeatureCollection

    Polygons with properties listed as outField

tag

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

    Parameters

    • points: FeatureCollection

      Input points

    • polygons: FeatureCollection

      Input polygons

    • polyId: string

      Property in polygons to add to joined Point features

    • containingPolyId: string

      Property in points in which to store joined property from polygons

    Returns FeatureCollection

    Points with containingPolyId property containing values from polyId

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.

    Parameters

    Returns FeatureCollection

    TIN output

triangleGrid

  • triangleGrid(extent: Array<number>, cellWidth: number, units: string): FeatureCollection
  • Takes a bounding box and a cell depth and returns a set of triangular polygons in a grid.

    Parameters

    • extent: Array<number>

      Extent in [minX, minY, maxX, maxY] order

    • cellWidth: number

      Width of each cell

    • units: string

      Used in calculating cellWidth ('miles' or 'kilometers')

    Returns FeatureCollection

    Grid of triangles

union

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

    Parameters

    Returns Feature

    A combined Polygon or MultiPolygon feature

variance

  • Calculates the variance value of a field for a set of points within a set of polygons.

    Parameters

    • polygons: FeatureCollection

      Input polygons

    • points: FeatureCollection

      Input points

    • inField: string

      The field in input data to analyze

    • outField: string

      The field in which to store results

    Returns FeatureCollection

    Polygons with properties listed as outField

within

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

    Parameters

    Returns FeatureCollection

    Points that land within at least one polygon