Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 14, 2026·3 min de lecture

Turf.js — Advanced Geospatial Analysis for JavaScript

A modular geospatial analysis engine written in JavaScript and TypeScript for browsers and Node.js.

Introduction

Turf.js is a modular geospatial analysis library that brings GIS operations to JavaScript. It works with standard GeoJSON and runs in both the browser and Node.js, making it easy to perform spatial computations without a server-side GIS backend.

What Turf.js Does

  • Performs measurements: distance, area, length, bearing, and midpoint calculations
  • Runs spatial operations: buffer, union, intersect, difference, dissolve, and convex hull
  • Classifies data with point-in-polygon, nearest-point, and within-distance queries
  • Transforms geometry: simplify, bezier-spline, smooth polygons, and translate/rotate/scale
  • Generates features: grids (square, hex, triangle), random points, Voronoi, and TIN

Architecture Overview

Turf is organized as a monorepo of small, independently installable npm packages under the @turf scope. Each module operates on GeoJSON Feature or FeatureCollection objects and returns GeoJSON, making it composable with any mapping library. All computations run synchronously in a single thread; heavy workloads can be offloaded to Web Workers.

Self-Hosting & Configuration

  • Install the full library with @turf/turf or pick individual modules like @turf/buffer for smaller bundles
  • Use with any GeoJSON-producing API or mapping library (Leaflet, Mapbox GL, OpenLayers)
  • Tree-shakeable ESM builds keep bundle sizes minimal when importing selectively
  • No configuration or API keys required; it is a pure computation library
  • Run in Node.js for batch processing or server-side spatial queries

Key Features

  • Over 60 geospatial functions covering measurement, transformation, and classification
  • Pure GeoJSON in/out interface for maximum interoperability
  • Modular architecture: import only the functions you need
  • Works identically in browser and server environments
  • TypeScript definitions included for type-safe development

Comparison with Similar Tools

  • PostGIS — runs in PostgreSQL for server-side spatial queries; Turf.js runs client-side with no database
  • JSTS — Java Topology Suite port to JS; Turf.js offers a simpler API and broader function set
  • Shapely (Python) — similar spatial operations; Turf.js targets the JavaScript ecosystem
  • GEOS — C/C++ geometry engine; Turf.js is higher-level and browser-compatible
  • H3 — specialized hexagonal indexing; Turf.js covers general-purpose spatial analysis

FAQ

Q: How accurate are the distance calculations? A: Turf uses geodesic calculations (Haversine and Vincenty formulas) by default, providing accuracy suitable for most applications. For survey-grade work, consider a geodetic library.

Q: Can Turf handle large datasets in the browser? A: Turf operates synchronously, so processing millions of features may block the main thread. Use Web Workers for heavy computations or pre-process data server-side.

Q: Does Turf work with formats other than GeoJSON? A: Turf expects GeoJSON input. Convert Shapefiles, KML, or WKT to GeoJSON first using tools like ogr2ogr or toGeoJSON.

Q: Is Turf.js actively maintained? A: Yes. The Turf.js project is maintained under the Turfjs GitHub organization with regular releases and community contributions.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires