Viewing version 0.0.14. Open the latest package page.

turf

0.0.14

A turf.js-like geospatial analysis library working with GeoJSON, written in pure Dart.

Download archive

Readme

pub package dart unit tests dart publish License: MIT

TurfDart is a Dart library for spatial analysis. It includes traditional spatial operations, helper functions for creating GeoJSON data, and data classification and statistics tools. You can use TurfDart in your Flutter applications on the web, mobile and desktop or in pure Dart applications running on the server.

As the foundation, we are using Geotypes, a lightweight dart library that provides a strong GeoJSON object model and fully RFC 7946 compliant serializers.

Most of the functionality is a translation from turf.js, the progress can be found here.

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

polymorphism

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.

Changelog

0.0.14

  • Adds missing library exports

0.0.13

  • Fixes Polyline.decode on the web. It decoded each negative coordinate delta as a large positive number.

0.0.12

  • Implements support for GeoJSON "other members" / foreign members, including JSON serialization, deserialization, cloning, and copy helpers #222
  • Implements lineclip for clipping line strings and polygons to bounding boxes #235
  • Implements pointOnFeature, with tests, benchmarks, examples, and generated visualization fixtures #216
  • Adds library-level doc comments to all public libraries and fixes documentation reference warnings #257

0.0.11

  • Implements simplify for Feature<LineString> #183
  • Implements circle #187
  • Implements pointToLineDistance #189
  • Implements lineSliceAlong #190
  • Implements polygonTangents #212
  • Implements square #213
  • Implements envelope #215
  • Implements centerOfMass #221
  • Implements toMercator and toWgs84 #230
  • Implements flip #231
  • Implements randomLineString #242
  • Implements combine to convert feature collections to multi-geometries #245
  • Implements flatten to flatten Multi* geometries to their single counterparts #246
  • Fixes wrong conversion from meters to yards and from meters to inches #194
  • Fixes booleanIntersects false positive #196
  • CI/CD and tooling improvements #218 #247 #248 #252

0.0.10

  • Implements lineSlice #158
  • Introduce geotypes package for GeoJSON serialization
  • Other small improvements

0.0.9

  • Implements length, along #153
  • Documentation: Improves pub.dev scores by fixing bad links in Readme.md

0.0.8

  • Implements transformRotate, rhumbDistance, rhumbDestination, centroid #147
  • Introduce localCoordIndex in coordEach
  • Implements all the boolean* functions #91
  • Implements area function #123
  • Implements polygonSmooth function #127
  • Fixes missing parameter in nearest point on line #145
  • Other core improvements
  • Support for Dart 3

0.0.7

  • Implements nearestPointOn(Multi)Line #87
  • Implements explode function #93
  • Implements bbox-polygon and bbox, center, polyline functions #99
  • Updates the BBox-class constructor #100
  • Implements rhumbBearing function #109
  • Implements lineToPolygon and polygonToLine functions #104
  • Implements truncate function #111
  • Implements cleanCoord function #112
  • Some documentation & README improvements

0.0.6+3

  • Rename examples file

0.0.6+2

  • Added code examples
  • Fixed segment * callbacks

0.0.6

  • This is solely a quality release, without new functionality:
  • Documentation: improves pub.dev scores, raised documentation coverage, fixed typos
  • Return type fixes for the the meta extensions

0.0.5

  • Implements all meta functions and lineSegment
  • Adds a lot of documentation
  • Several bug and type fixes

0.0.4

  • Implements the featureEach and propEach meta function. #24
  • PR #43:
    • Several bugfixes with the deserialization of JSON
    • Several new constructors
    • Vector arithmetics operations

0.0.3

  • Null-safety support

0.0.2+3

Implements the geomEach meta function. #13

0.0.2+1

  • initialize lists and maps empty in constructors, if not provided

0.0.2

  • normalization for coordinates (Position)
  • and yes, it's still under heavy development

0.0.1

  • Initial version, still under heavy development

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add 'turf:0.0.14'
pubspec.yaml
name: turf
description: A turf.js-like geospatial analysis library working with GeoJSON, written in pure Dart.
version: 0.0.14
environment:
  sdk: ">=2.17.0 <4.0.0"
homepage: https://github.com/dartclub/turf_dart
repository: https://github.com/dartclub/turf_dart

dependencies:
  geotypes: ^0.0.2
  turf_equality: ^0.1.0
  turf_pip: ^0.0.2
  rbush: ^1.1.1
  sweepline_intersections: ^0.0.4
  path: ^1.9.0

dev_dependencies:
  lints: ^3.0.0
  test: ^1.24.3
  build_runner: ^2.4.5
  analyzer: ^6.4.0
  benchmark: ^0.3.0
  build_web_compilers: ^4.8.0

Version history

VersionPublishedArchiveSHA-256
0.0.1+1On demandDownload51f4e5dc…ee8d27
0.0.1+2On demandDownload4a03a731…e3f563
0.0.1+3On demandDownload813cfab1…4f8bd3
0.0.1+4On demandDownload95bad50e…7dc438
0.0.1+5On demandDownload01723bf2…c7dd6c
0.0.1+6On demandDownload7785c504…3c453c
0.0.2On demandDownload11ee6c32…579fe0
0.0.2+1On demandDownload5420cd4b…a90324
0.0.2+2On demandDownload4e480f30…d73d2f
0.0.2+3On demandDownloadcd42dd6c…ab7340
0.0.3On demandDownloadfa6f9566…7b9202
0.0.4On demandDownloade068e3f5…385cc4
0.0.5On demandDownload1a44b2c1…25d264
0.0.6On demandDownload13671f7b…78c45c
0.0.6+2On demandDownloadf22122fe…780dea
0.0.6+3On demandDownload08690b72…261da2
0.0.7On demandDownload153ddb7b…1ae4d5
0.0.8On demandDownload2be48cc7…41a0d6
0.0.9On demandDownloade5774828…58c350
0.0.10On demandDownload75347c45…cbe436
0.0.11On demandDownload961a9c5b…1bc812
0.0.12On demandDownload7684654c…f67256
0.0.13On demandDownload2265ade6…1effb4
0.0.14Cached · Upstream SHA-256 matchedDownload607db17e…492c5f

Dependencies

geotypes "^0.0.2"

path "^1.9.0"

rbush "^1.1.1"

sweepline_intersections "^0.0.4"

turf_equality "^0.1.0"

turf_pip "^0.0.2"