Skip to content
A modular geospatial engine written in JavaScript
JavaScript TypeScript
Branch: master
Clone or download

Latest commit

rowanwins Merge pull request #1894 from Turfjs/centroid-fix
Don't revisit wrapping coordinate when calculating centroid
Latest commit 3fa082c May 7, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Updated .github/ISSUE_TEMPLATE.md (optional) Mar 1, 2018
examples updated create-react-app package.json to at least appear as a boilerp… Oct 29, 2019
packages Merge branch 'master' into centroid-fix May 7, 2020
releases Create 5.2.0.md Dec 21, 2017
rollup-plugins Update typescript-export.js Oct 27, 2017
scripts Add Ts Progress script Jun 12, 2018
.eslintignore Add skmeans as dependency Aug 3, 2017
.eslintrc.js Fix linting issue Nov 1, 2017
.gitignore Standardize Typescript builds (#1849) Mar 15, 2020
.monorepolint.config.ts Standardize some devDependencies with monorepolint (#1884) Apr 15, 2020
.travis.yml Setup monorepolint (#1856) Mar 16, 2020
CHANGELOG.md Update changelog for new packages+version Mar 26, 2020
CODE_OF_CONDUCT.md add code of conduct (#495) Oct 10, 2016
CONTRIBUTING.md Update CONTRIBUTING.md Jun 28, 2018
LICENSE 2019 - revert grantee change to legal entity Mar 21, 2019
OPEN_COLLECTIVE.md Merge Dec 5, 2017
README.md npm package link fix in README (#1810) Jan 3, 2020
SEE_ALSO.md Create SEE_ALSO.md Jan 13, 2015
documentation.yml Add new modules to docs Feb 15, 2018
lerna.json v6.2.0-alpha.1 Mar 26, 2020
package.json Standardize some devDependencies with monorepolint (#1884) Apr 15, 2020
rollup.config.js Build Standardization (#1860) Mar 17, 2020
tsconfig.shared.json Tree shaking (#1869) Mar 24, 2020
yarn.lock Standardize some devDependencies with monorepolint (#1884) Apr 15, 2020

README.md

turf

Version Badge Travis CI Gitter chat Backers on Open Collective Sponsors on Open Collective Coverage Status Greenkeeper badge

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

npm install @turf/turf

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@5/turf.min.js"></script>

You can create light-weight turf builds with only the functions you need using the turfjs-builder UI or using browserify as described below.

Browserify

All of Turf's functions can also be installed as separate modules. This works well with tools like browserify where you want to install only the code you need. It also allows you to mix and match modules. This is the recommended usage pattern for most production environments. For example, to install the point and buffer modules use:

npm install @turf/helpers @turf/buffer

Bower [NOTE: Bower support has been dropped Jan 1st 2017]

Not recommended. Please don't use Bower. Use Browserify, Webpack, or the CDN instead.

TypeScript

TypeScript is supported internally within each module, no installs required.

Other languages

Ports of Turf.js are available in:

Turf for Swift is experimental and its public API is subject to change. Please use with care.


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: {}
};

Contributors

This project exists thanks to all the people who contribute. [Contribute].

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]

You can’t perform that action at this time.