Skills2026年5月14日·1 分钟阅读

Turf.js — Advanced Geospatial Analysis for JavaScript

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

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Turf.js Overview
通用 CLI 安装命令
npx tokrepo install c0d619a3-4f4c-11f1-9bc6-00163e2b0d79

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产