explaingit

turfjs/turf

10,365TypeScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A modular JavaScript library that brings GIS mapping analysis, distance, area, intersection, clustering, directly into browser or Node.js apps using standard GeoJSON data.

Mindmap

mindmap
  root((Turf.js))
    What it does
      Distance calculation
      Area measurement
      Point in polygon
      Shape combining
    Data format
      GeoJSON points
      GeoJSON polygons
      GeoJSON collections
    Where it runs
      Browser module
      Node.js backend
    Works with
      Leaflet
      Mapbox
      Any GeoJSON tool
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Check whether a delivery address falls inside a specific service area polygon on a map.

USE CASE 2

Calculate the distance between two user-placed map markers and display it in kilometers.

USE CASE 3

Measure the area of user-drawn regions on an interactive Leaflet or Mapbox map.

USE CASE 4

Cluster geographic data points server-side in a Node.js backend before sending them to a map.

Tech stack

TypeScriptJavaScriptNode.jsnpmGeoJSON

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

Turf is a JavaScript library for working with geographic data. It provides functions for spatial analysis: things like calculating the distance between two locations, finding whether a point falls inside a polygon, measuring areas, combining shapes, and running statistical calculations on geographic datasets. These are the kinds of operations you normally associate with dedicated mapping software or GIS (Geographic Information System) tools, but Turf makes them available directly in JavaScript code. The library works with a data format called GeoJSON, which is a standard way of representing geographic features (points, lines, polygons, collections of these) as JSON text. Most web mapping tools already speak GeoJSON, so Turf slots naturally into projects that use libraries like Leaflet or Mapbox to display maps. Turf can run in two places. In a browser, you include it as a JavaScript module on the page. On a server, you install it through npm (the Node.js package manager) and run it as part of a backend application. The library is modular, meaning you can install just the specific functions you need rather than pulling in the entire package, which keeps your project's file size down. The project is open source, funded through Open Collective where individuals and companies can become backers or sponsors. It is actively maintained and accepts contributions through GitHub. Official documentation and interactive examples are available at turfjs.org. Browser support targets any reasonably modern browser, and Node.js is treated as a first-class runtime environment.

Copy-paste prompts

Prompt 1
Using Turf.js, write JavaScript code that takes a user's GeoJSON point location and an array of GeoJSON service-area polygons, and returns the name of the area the user is currently inside.
Prompt 2
I'm building a Leaflet map app. Use @turf/distance to calculate the distance in kilometers between two markers the user has placed, and display the result in a popup.
Prompt 3
Write a Node.js script using @turf/turf that reads a GeoJSON file of city boundary polygons and logs the area of each city in square kilometers.
Open on GitHub → Explain another repo

← turfjs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.