turf 0.0.9 turf: ^0.0.9 copied to clipboard
A turf.js-like geospatial analysis library working with GeoJSON, written in pure Dart.
turf.dart #
THIS PROJECT IS WORK IN PROCESS
A turf.js-like geospatial analysis library working with GeoJSON, written in pure Dart.
This includes a fully RFC 7946-compliant object-representation and serialization for GeoJSON.
Most of the implementation is a direct translation from turf.js.
Get started #
- Get the Dart tools
- Install the library with
dart pub add turf
- Import the library in your code and use it. For example:
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),
],
[
Position(0, 0),
Position(1, 1),
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);
// total == 6
}
GeoJSON Object Model #
Notable Design Decisions #
- Nested
GeometryCollections
(as described in RFC 7946 section 3.1.8) are not supported which takes a slightly firmer stance than the "should avoid" language in the specification
Tests and Benchmarks #
Tests are run with dart test
and benchmarks can be run with
dart run benchmark
Any new benchmarks must be named *_benchmark.dart
and reside in the
./benchmark
folder.
Components #
Measurement #
- ✅ along
- ✅ area
- ✅ bbox
- ✅ bboxPolygon
- ✅ bearing
- ✅ center
- ❌ centerOfMass
- ✅ centroid
- ✅ destination
- ✅ distance
- ❌ envelope
- ✅ length
- ✅ midpoint
- ❌ pointOnFeature
- ❌ polygonTangents
- ❌ pointToLineDistance
- ✅ rhumbBearing
- ✅ rhumbDestination
- ✅ rhumbDistance
- ❌ square
- ❌ greatCircle
Coordinate Mutation #
- ✅ cleanCoords
- ❌ flip
- ❌ rewind
- ❌ round
- ✅ truncate
Transformation #
- ❌ bboxClip
- ❌ bezierSpline
- ❌ buffer
- ❌ circle
- ✅ clone - implemented as a member function of each [GeoJSONObject]
- ❌ concave
- ❌ convex
- ❌ difference
- ❌ dissolve
- ❌ intersect
- ❌ lineOffset
- ✅ polygonSmooth
- ❌ simplify
- ❌ tesselate
- ✅ transformRotate
- ❌ transformTranslate
- ❌ transformScale
- ❌ union
- ❌ voronoi
- ✅ polyLineDecode
Feature Conversion #
- ❌ combine
- ✅ explode
- ❌ flatten
- ✅ lineToPolygon
- ❌ polygonize
- ✅ polygonToLine
MISC #
- ❌ ellipse
- ❌ kinks
- ❌ lineArc
- ❌ lineChunk
- ❌ lineIntersect
- ❌ lineOverlap
- ✅ lineSegment
- ❌ lineSlice
- ❌ lineSliceAlong
- ❌ lineSplit
- ❌ mask
- ✅ nearestPointOnLine
- ❌ sector
- ❌ shortestPath
- ❌ unkinkPolygon
Random #
- ❌ randomPosition
- ❌ randomPoint
- ❌ randomLineString
- ❌ randomPolygon
Data #
- ❌ sample
Interpolation #
- ❌ interpolate
- ❌ isobands
- ❌ isolines
- ❌ planepoint
- ❌ tin
Joins #
- ❌ pointsWithinPolygon
- ❌ tag
Grids #
- ❌ hexGrid
- ❌ pointGrid
- ❌ squareGrid
- ❌ triangleGrid
Classification #
Aggregation #
- ❌ collect
- ❌ clustersDbscan
- ❌ clustersKmeans
META #
- ✅ coordAll
- ✅ coordEach
- ✅ coordReduce
- ✅ featureEach
- ✅ featureReduce
- ✅ flattenEach
- ✅ flattenReduce
- ✅ geomEach
- ✅ geomReduce
- ✅ propEach
- ✅ propReduce
- ✅ segmentEach
- ✅ segmentReduce
- ✅ getCluster
- ✅ clusterEach
- ✅ clusterReduce
Invariants #
Booleans #
- ✅ booleanClockwise
- ✅ booleanConcave
- ✅ booleanContains
- ✅ booleanCrosses
- ✅ booleanDisjoint
- ✅ booleanEqual
- ✅ booleanIntersects
- ❌ booleanOverlap
- ✅ booleanParallel
- ✅ booleanPointInPolygon
- ✅ booleanPointOnLine
- ❌ booleanWithin
Unit Conversion #
- ✅ bearingToAzimuth
- ✅ convertArea
- ✅ convertLength
- ✅ degreesToRadians
- ✅ lengthToRadians
- ✅ lengthToDegrees
- ✅ radiansToLength
- ✅ radiansToDegrees
- ❌ toMercator
- ❌ toWgs84