turf
0.0.14A turf.js-like geospatial analysis library working with GeoJSON, written in pure Dart.
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.decodeon 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
lineclipfor 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
simplifyforFeature<LineString>#183 - Implements
circle#187 - Implements
pointToLineDistance#189 - Implements
lineSliceAlong#190 - Implements
polygonTangents#212 - Implements
square#213 - Implements
envelope#215 - Implements
centerOfMass#221 - Implements
toMercatorandtoWgs84#230 - Implements
flip#231 - Implements
randomLineString#242 - Implements
combineto convert feature collections to multi-geometries #245 - Implements
flattento flatten Multi* geometries to their single counterparts #246 - Fixes wrong conversion from meters to yards and from meters to inches #194
- Fixes
booleanIntersectsfalse 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
localCoordIndexincoordEach - Implements all the
boolean* functions #91 - Implements
areafunction #123 - Implements
polygonSmoothfunction #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
explodefunction #93 - Implements
bbox-polygonandbbox,center, polyline functions #99 - Updates the
BBox-class constructor #100 - Implements
rhumbBearingfunction #109 - Implements
lineToPolygonandpolygonToLinefunctions #104 - Implements
truncatefunction #111 - Implements
cleanCoordfunction #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
featureEachandpropEachmeta 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 turfpubspec.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
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1+1 | On demand | Download | 51f4e5dc…ee8d27 |
| 0.0.1+2 | On demand | Download | 4a03a731…e3f563 |
| 0.0.1+3 | On demand | Download | 813cfab1…4f8bd3 |
| 0.0.1+4 | On demand | Download | 95bad50e…7dc438 |
| 0.0.1+5 | On demand | Download | 01723bf2…c7dd6c |
| 0.0.1+6 | On demand | Download | 7785c504…3c453c |
| 0.0.2 | On demand | Download | 11ee6c32…579fe0 |
| 0.0.2+1 | On demand | Download | 5420cd4b…a90324 |
| 0.0.2+2 | On demand | Download | 4e480f30…d73d2f |
| 0.0.2+3 | On demand | Download | cd42dd6c…ab7340 |
| 0.0.3 | On demand | Download | fa6f9566…7b9202 |
| 0.0.4 | On demand | Download | e068e3f5…385cc4 |
| 0.0.5 | On demand | Download | 1a44b2c1…25d264 |
| 0.0.6 | On demand | Download | 13671f7b…78c45c |
| 0.0.6+2 | On demand | Download | f22122fe…780dea |
| 0.0.6+3 | On demand | Download | 08690b72…261da2 |
| 0.0.7 | On demand | Download | 153ddb7b…1ae4d5 |
| 0.0.8 | On demand | Download | 2be48cc7…41a0d6 |
| 0.0.9 | On demand | Download | e5774828…58c350 |
| 0.0.10 | On demand | Download | 75347c45…cbe436 |
| 0.0.11 | On demand | Download | 961a9c5b…1bc812 |
| 0.0.12 | On demand | Download | 7684654c…f67256 |
| 0.0.13 | On demand | Download | 2265ade6…1effb4 |
| 0.0.14 | Cached · Upstream SHA-256 matched | Download | 607db17e…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"