Turf

A modular geospatial engine written in JavaScript

README

turf
====== GitHub Actions Status [![Version Badge][npm-img]][npm-url] [![Gitter chat][gitter-img]][gitter-url] [![Backers on Open Collective][oc-backer-badge]](#backers) [![Sponsors on Open Collective][oc-sponsor-badge]](#sponsors) Coverage Status

[npm-img]: https://img.shields.io/npm/v/@turf/turf.svg
[npm-url]: https://www.npmjs.com/package/@turf/turf
[gitter-img]: https://badges.gitter.im/Turfjs/turf.svg
[gitter-url]: https://gitter.im/Turfjs/turf
[oc-backer-badge]: https://opencollective.com/turf/backers/badge.svg
[oc-sponsor-badge]: https://opencollective.com/turf/sponsors/badge.svg

A modular geospatial engine written in JavaScript


- - -

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


  1. ``` sh
  2. # get all of turf
  3. npm install @turf/turf

  4. # or get individual packages
  5. npm install @turf/helpers
  6. npm install @turf/buffer
  7. ```

In browser


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

  1. ``` html
  2. <script src="turf.min.js" charset="utf-8"></script>
  3. ```

You can also include it directly from a CDN:

  1. ``` html
  2. <script src="https://cdn.jsdelivr.net/npm/@turf/turf@6/turf.min.js"></script>
  3. ```

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:

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

  4. var point2 = {
  5.   type: 'Feature',
  6.   geometry: {
  7.     type: 'Point',
  8.     // Note order: longitude, latitude.
  9.     coordinates: [-73.988214, 40.749128]
  10.   },
  11.   properties: {}
  12. };
  13. ```

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:

  1. ```
  2. @turf/*
  3. robust-predicates
  4. rbush
  5. tinyqueue
  6. ```

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]