turf
0.0.14, released 8 weeks ago by scalabs.de
A turf.js-like geospatial analysis library working with GeoJSON, written in pure Dart.
What it does
Provides spatial operations, helper functions for creating GeoJSON data, and data classification and statistics tools for geospatial analysis. It works in Flutter applications on the web, mobile, and desktop, or in pure Dart applications on the server.
AI-written summary of version 0.0.14, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to perform spatial analysis or manipulate GeoJSON data in pure Dart or Flutter.
- You want a Dart port of turf.js functions like line slicing, distance calculation, and geometric transformations.
Skip it when
- You need nested GeometryCollections (which are explicitly not supported).
- You are looking for UI map widgets rather than a backend/logic geospatial analysis library.
Strengths
- Pure Dart implementation supporting mobile, web, desktop, and server.
- Strong GeoJSON object model with RFC 7946 compliant serializers via geotypes.
Weaknesses
- Nested GeometryCollections are not supported.
- Early version (0.0.14) meaning APIs may still evolve.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 6
Install the library with `dart pub add turf` and import the required files.
import 'package:turf/helpers.dart';
import 'package:turf/src/line_segment.dart';
Feature<Polygon> poly = Feature<Polygon>(
geometry: Polygon(coordinates: [
[
Position(0, 0),
Position(2, 2),
Position(0, 1),
Position(0, 0),
],
]),
);
void main() {
var total = segmentReduce<int>(
poly,
(previousValue, currentSegment, initialValue, featureIndex,
multiFeatureIndex, geometryIndex, segmentIndex) {
if (previousValue != null) {
previousValue++;
}
return previousValue;
},
0,
combineNestedGeometries: false,
);
print(total);
}Alternatives
Packages that do the same job and could replace turf.
- geodart
A geospatial library for Dart for working with vector features and geographic data.
59Compare - geoengine
Dart library for geospatial analysis, distance calculations, coordinate conversions and astronomy.
56Compare - geobase
Geospatial data structures, geometry calculations, geodesy, projections, and vector formats in Dart.
53Compare - vector_map
Pure‑Flutter vector map widget that renders GeoJSON data.
49Compare
Works with
Packages commonly used together with turf: ones it builds on, ones built on it, and its own family.
- rbushturf depends on itHigh-performance Dart R-tree spatial index for points and rectangles.
- geotypesturf depends on itLightweight library providing GeoJSON data types for Dart and Flutter
- sweepline_intersectionsBuilt on turfDetects intersections between polygons and polylines using a sweepline algorithm.
- mapbox_maps_flutterBuilt on turfOfficial Mapbox Maps SDK for Flutter to render interactive vector maps.