• Stars
    star
    9,163
  • Rank 3,931 (Top 0.08 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A modular geospatial engine written in JavaScript and TypeScript

turf

GitHub Actions Status Version Badge Gitter chat Backers on Open Collective Sponsors on Open Collective Coverage Status

A modular geospatial engine written in JavaScript

turfjs.org


Turf is a JavaScript library for spatial analysis. It includes traditional spatial operations, helper functions for creating GeoJSON data, and data classification and statistics tools. Turf can be added to your website as a client-side plugin, or you can run Turf server-side with Node.js (see below).

Installation

In Node.js

# get all of turf
npm install @turf/turf

# or get individual packages
npm install @turf/helpers
npm install @turf/buffer

In browser

Download the minified file, and include it in a script tag. This will expose a global variable named turf.

<script src="turf.min.js" charset="utf-8"></script>

You can also include it directly from a CDN:

<script src="https://cdn.jsdelivr.net/npm/@turf/turf@6/turf.min.js"></script>

TypeScript

TypeScript definitions are packaged with each module. No DefinitelyTyped packages required.

Other languages

Ports of Turf.js are available in:

  • Java (Android, Java SE)
  • Swift (iOS, macOS, tvOS, watchOS, Linux)
    • Turf for Swift is experimental and its public API is subject to change. Please use with care.

  • Dart/Flutter (Dart Web, Dart Native; Flutter for iOS, Android, macOS, Windows, Linux, Web)
    • The Turf for Dart port is still in progress, the implementation status can be found in the README.


Data in Turf

Turf uses GeoJSON for all geographic data. Turf expects the data to be standard WGS84 longitude, latitude coordinates. Check out geojson.io for a tool to easily create this data.

NOTE: Turf expects data in (longitude, latitude) order per the GeoJSON standard.

Most Turf functions work with GeoJSON features. These are pieces of data that represent a collection of properties (ie: population, elevation, zipcode, etc.) along with a geometry. GeoJSON has several geometry types such as:

  • Point
  • LineString
  • Polygon

Turf provides a few geometry functions of its own. These are nothing more than simple (and optional) wrappers that output plain old GeoJSON. For example, these two methods of creating a point are functionally equivalent:

// Note order: longitude, latitude.
var point1 = turf.point([-73.988214, 40.749128]);

var point2 = {
  type: 'Feature',
  geometry: {
    type: 'Point',
    // Note order: longitude, latitude.
    coordinates: [-73.988214, 40.749128]
  },
  properties: {}
};

Browser support

Turf packages are compiled to target ES2017. However, the browser version of @turf/turf is transpiled to also include support for IE11. If you are using these packages and need to target IE11, please transpile the following packages as part of your build:

@turf/*
robust-predicates
rbush
tinyqueue

Contributors

This project exists thanks to all the people who contribute. If you are interested in helping, check out the Contributing Guide.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

More Repositories

1

turf-node-example

an example of how to use Turf for a scripting task with node.
JavaScript
90
star
2

turf-server-example

[DEPRECATED] an example of using turf on a server with node.js
JavaScript
45
star
3

turf-inside

Checks to see if a point is inside of a polygon.
JavaScript
38
star
4

turf-distance

Calculates the distance between two point features in degrees, radians, miles, or kilometers.
JavaScript
31
star
5

turf-intersect

find the intersection of features
JavaScript
30
star
6

turf-www

turf website
MDX
28
star
7

awesome-turf

A collection of awesome projects in the turfjs ecosystem
22
star
8

turf-buffer

Buffers a point, linestring, or polygon Feature/FeatureCollection to a given radius. Units supported are miles, kilometers, and degrees.
JavaScript
22
star
9

turf-mapboxjs

Examples of Turfjs visualized with mapbox.js
HTML
13
star
10

turf-isobands

Takes a FeatureCollection of points with z values and an array of value breaks and generates filled contour isobands.
JavaScript
12
star
11

turf-bbox-clip

Clips a Feature by a bbox
JavaScript
8
star
12

turf-union

find the union of geographic features
JavaScript
8
star
13

turf-cut

Cut a polygon with a polyline
JavaScript
8
star
14

turf-line-to-polygon

Transforms a LineString geometry to a (closed) Polygon geometry.
JavaScript
8
star
15

turf-line-slice-at-intersection

Segment a LineString by Features
JavaScript
5
star
16

turf-point-grid

Takes a bounding box and a cell depth and outputs a feature collection of points in a grid.
JavaScript
4
star
17

turf-voronoi

Create voronoi polygons from a set of points
JavaScript
4
star
18

turf-rewind

Makes outer rings cw, inner rings ccw. Or reversed
JavaScript
4
star
19

turf-voronoi-constrained

Get Voronoi cells constrained to a Polygon
JavaScript
3
star
20

turf-donuts

Takes a set of overlapping polygons and returns non overlapping donuts.
JavaScript
3
star
21

turf-difference

erase spatial features
JavaScript
2
star
22

turf-weighted-centroid

JavaScript
2
star
23

turf-polygon-reduce

Gets the Pole of Inaccessibility of the input polygon
JavaScript
2
star
24

turf-jsts

A minimal subset of JSTS features bundled and compiled to ES5
JavaScript
2
star
25

turf-line-chunk

Divide a linestring into segments of specified length
JavaScript
2
star
26

turf-vincenty-direct

Vincenty's direct formula computes the location of a point which is a given distance and direction from another point.
JavaScript
2
star
27

turf-tin-constrained

poly2tri wrapper for TURF
JavaScript
1
star
28

turf-equal

determine whether two geojson objects are equal
JavaScript
1
star
29

turf-vincenty-inverse

Vincenty's inverse formula computes the geographical distance and direction between two given points.
JavaScript
1
star