After a bit of hiatus, TurfJS is resuming releases.
- ES Modules available for all packages
- Tree shaking should significantly reduce import size of @turf/turf
Determines if two features touch but do not intersect
Checks if the geometry is a valid according to the OGC Simple Feature Specification
Performs a quadrat analysis on a set of points
Creates a grid of rectangles from a bounding box
Typescript types for the options parameter have been fixed (PR Turfjs#1424 - Author @stevage)
Typescript types around the Feature's Properties will now be preserved. (PR Turfjs#1761 - Author @rugheid)
Typescript types for the 'reverse' option are now correct. Previously it was misnamed as 'reversed'. (PR Turfjs#1786 - Author @jonnycornwell)
No longer publishes an .mjs file.
No longer publishes an .mjs file.
- TurfJS now supports ES Modules (Related PR's)
- Optional parameters are now defined as an
Object
.
Takes a FeatureCollection of points, and a bounding box, and returns a FeatureCollection of Voronoi polygons. (PR Turfjs#1043 - Author @stevage)
Returns the shortest path from start to end without colliding with any feature in obstacles (PR Turfjs#956 - Author @stebogit)
Boolean-Parallel returns True if each segment of line1
is parallel to the correspondent segment of line2
(PR Turfjs#941 - Author @stebogit)
Takes a {@link Point} and a {@link LineString} and calculates the closest Point on the (Multi)LineString. (PR Turfjs#939 - Author @stebogit)
-
Updates
@turf/unkink-polygon
testing & addedflattenEach
instead of usingflatten
. (PR Turfjs#889) -
Add multi-geomtry support to
@turf/line-split
(PR Turfjs#1078) -
Improve
@turf/meta
lineEach
method to provide properties, id and bbox (PR Turfjs#1010)
-
Fixes
@turf/helpers
earth radius variable (PR Turfjs#1012) -
Fixes
@turf/polygon-tangents
bug (PR Turfjs#1058) -
Fixes
@turf/line-chunk
bug when the number of segments is integer (PR Turfjs#1046) -
Fixes
segmentEach
andsegmentReduce
methods in@turf/meta
to ensure something is returned (PR Turfjs#968)
- Optional parameters are now defined as an
Object
:
Before
var from = [-75.343, 39.984];
var to = [-75.534, 39.123];
var units = 'miles';
var distance = turf.distance(from, to, units);
After
var from = [-75.343, 39.984];
var to = [-75.534, 39.123];
var options = {units: 'miles'};
var distance = turf.distance(from, to, options);
- Reworked
@turf/random
PR Turfjs#994 - Deprecate
@turf/idw
Issue Turfjs#887 - Reworked Grid modules
@turf/point-grid/hex/square/triangle
PR Turfjs#1029 - Renamed Modules/Methods
-
@turf/inside
=>@turf/boolean-point-in-polygon
Turfjs#860 (comment) -
@turf/within
=>@turf/points-within-polygon
Turfjs#860 (comment) -
@turf/bezier
=>@turf/bezier-spline
Issue Turfjs#661 -
@turf/nearest
=>@turf/nearest-point
Turfjs#858 (comment) -
@turf/point-on-line
=>@turf/nearest-point-on-line
Turfjs#858 (comment) -
@turf/lineDistance
=>@turf/length
Turfjs#860 (comment) -
@turf/helpers
-
radians2degrees
=>radiansToDegrees
-
degrees2radians
=>degreesToRadians
-
distanceToDegrees
=>lengthToDegrees
-
distanceToRadians
=>lengthToRadians
-
radiansToDistance
=>radiansToLength
-
bearingToAngle
=>bearingToAzimuth
-
convertDistance
=>convertLength
-
-
- toMercator: Converts a WGS84 GeoJSON object into Mercator (EPSG:900913) projection
- toWgs84: Converts a Mercator (EPSG:900913) GeoJSON object into WGS84 projection
(PR Turfjs#927 - Author @stebogit)
Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the minimum distance between the point and any segment of the LineString
.
(PR Turfjs#925 - Author @stebogit)
Boolean-within returns true if the first geometry is completely within the second geometry. The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a) must not intersect the exterior of the secondary (geometry b). Boolean-within returns the exact opposite result of the @turf/boolean-contains
.
(PR Turfjs#924 - Author @rowanwins)
- Updates
@turf/unkink-polygon
testing & addedflattenEach
instead of usingflatten
. (PR Turfjs#889) @turf/concave
refactoring, replacing@turf/union
withgeojson-dissolve
to increase speed and added support tonull
geometries (PR Turfjs#907 - Contributor @stebogit @DenisCarriere)- Adds doc note on
@turf/polygonize
about "Edges must be correctly noded" (PR Turfjs#898 - Contributor @stebogit @NickCis) - Adds support to foreign Members to
@turf/clone
(PR Turfjs#904 - Contributor @DenisCarriere) - Extends support of any
GeoJSON
to@turf/simplify
(PR Turfjs#903 - Contributor @DenisCarriere @stebogit) - Adds new
isNumber
function and improves type checking for few@turf/helpers
methods (PR Turfjs#920 - Contributor @DenisCarriere @stebogit) - Adds throw errors to invalid
MultiPolygons
for@turf/simplify
(PR Turfjs#922 - Contributor @DenisCarriere)
- Fixes
@turf/bbox-clip
point intersection handling, adding sanity-checks the lineclip output (PR Turfjs#886) - Fixes
@turf/line-split
endpoint case handling applying@turf/truncate
onsplitter
(PR Turfjs#892 and Turfjs#855 - Contributor @stebogit) - Fixes
@turf/intersect
throwing "uncaught exception", adding@turf/truncate
to inputs and returningFeature<null>
if no geometry (PR Turfjs#890 - Contributor @stebogit @vicvolk) - Fixes
@turf/hex-grid
not properly cloning the last ring vertex (PR Turfjs#897 - Contributor @stebogit @DenisCarriere) - Fixes
@turf/boolean-disjoint
incorrect behaviour where a poly was completely contained within another poly (PR Turfjs#908 - Contributor @rowanwins) - Fixes
@turf/simplify
process pending on particular geometries, applying@turf/clean-coords
to input. (PR Turfjs#903 - Contributor @stebogit @DenisCarriere) - Fixes
boolean
properties not being translated with@turf/clone
(PR Turfjs#909 - Contributor @DenisCarriere) - Fixes
@turf/boolean-contains
incorrect output when checking two polygons (PR Turfjs#923 - Contributor @rowanwins @DenisCarriere)
@turf/clean-coords
Removes redundant coordinates from any GeoJSON Geometry. (PR Turfjs#875 - Author @stebogit)@turf/interpolate
Takes a set of points and estimates their 'property' values on a grid using the Inverse Distance Weighting (IDW) method.. (PR Turfjs#832 - Author @stebogit)@turf/clusters-dbscan
Takes a set of Points and partition them into clusters according to DBSCAN's data clustering algorithm. (PR Turfjs#812 and Turfjs#851 - Author @DenisCarriere)special mention to this incredibly instructive and fun interactive map by @DenisCarriere 😎👏
@turf/clusters
ProvidesgetCluster
,clusterEach
, andclusterReduce
functions. (PR Turfjs#847 - Author @DenisCarriere)@turf/boolean-point-on-line
Returns true if a point is on a line. Accepts a optional parameter to ignore the start and end vertices of the linestring. (PR Turfjs#858 - Author @rowanwins)@turf/boolean-overlap
Takes two features and returns true or false whether or not they overlap, i.e. whether any pair of edges on the two polygons intersect. If there are any edge intersections, the polygons overlap. (PR Turfjs#856 and Turfjs#868 - Author @stebogit @tcql)@turf/boolean-equal
Determine whether two geometries of the same type have identical X,Y coordinate values. (PR Turfjs#869 - Author @stebogit @tcql)
- Sets
centered
param default totrue
in@turf/point-grid
(PR Turfjs#836 - Contributor @stebogit) - Adds
MultiLineString
support for@turf/point-on-line
(PR Turfjs#838 - Contributor @stebogit) - Renames
@turf/clusters
=>@turf/clusters-kmeans
, plus adds deprecated warning message to@turf/[email protected]
(See Issue Turfjs#845) - Changes output type of
@turf/clusters-kmeans
(See Issue Turfjs#850 - Contributor @DenisCarriere) - Adds
segmentEach
andsegmentReduce
functions to@turf/meta
(See Issue Turfjs#850 - Contributor @DenisCarriere) - Adds tests and linting on JSDoc in TurfJS core from
turf-www
; see Issue Turfjs#859 (PR Turfjs#857 + Turfjs#864 + Turfjs#870 - Contributor @DenisCarriere @stebogit) - Introduces
null
Geometry support across TurfJS modules (See Issue Turfjs#853) (PR Turfjs#866 - Contributor @DenisCarriere) - Includes feature(Sub)Index in
coordEach
/coordReduce
(@turf/meta) 🎉 (PR Turfjs#872 - Contributor @DenisCarriere) - Adds
bbox
andid
params plusgeometry
method to@turf/helpers
(PR Turfjs#877 - Contributor @DenisCarriere)
- Applies
@turf/truncate
to@turf/line-split
splitter
input to avoid approximation errors. Fixed #852 (PR Turfjs#855) - Fixes
@turf-mask
error (See Issue Turfjs#837) (PR Turfjs#865 - Contributor @thiagoxvo) - Fixes
create-new-module
script error onLICENSE
file creation (See Issue Turfjs#861) (commit df6986e) - Fixes
@turf/isobands
error oncommonProperties
(See Issue Turfjs#831) (commit 1663f07)
-
@turf/clusters
Takes a set of points and partition them into clusters using the k-means clustering algorithm. (PR Turfjs#787 - Author @stebogit ) -
@turf/boolean-disjoint
Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set. (PR Turfjs#805 - Author @rowanwins) -
@turf/boolean-contains
Boolean-contains returns True if the second geometry is completely contained by the first geometry. The interiors of both geometries must intersect and, the interior and boundary of the secondary (geometry b) must not intersect the exterior of the primary (geometry a). Boolean-contains returns the exact opposite result of the@turf/boolean-within
. (PR Turfjs#797 - Author @rowanwins) -
@turf/boolean-crosses
Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than the maximum dimension of the two source geometries and the intersection set is interior to both source geometries. Boolean-Crosses returns t (TRUE) for only multipoint/polygon, multipoint/linestring, linestring/linestring, linestring/polygon, and linestring/multipolygon comparisons. (PR Turfjs#796 - Author @rowanwins) -
@turf/boolean-clockwise
Takes a ring and return true or false whether or not the ring is clockwise or counter-clockwise. (PR Turfjs#789 - Authors @morganherlocker @stebogit) -
@turf/clone
Prevents GeoJSON coordinates from being mutated, similar toJSON.parse(JSON.stringify(geojson))
. Only cloning the coordinates can be 3x-20x faster than the parse + stringify approach. (PR Turfjs#824 - Author @DenisCarriere)
convertArea
Converts a area to the requested unit. (PR Turfjs#821 - Author @wnordmann)- Adds mask option to
@turf/point-grid
(PR Turfjs#791) - New @turf/isolines based on MarchingSquares.js (PR Turfjs#781)
- Use ES6 modules / Add module.js to @turf/turf (PR Turfjs#793)
- Create-new-module script (PR Turfjs#823)
- Buffer - Drop circle buffer operation (PR Turfjs#786)
- Fixes
@turf/idw
bad property name #774 (PR Turfjs#800) - Fix for @turf/polygon-tangents - Resolves #785 (PR Turfjs#792)
@turf/line-offset
Adds a new lineOffset module as per this issue. Basically takes an input line and returns a new line offset by the distance. (PR Turfjs#729 - Author @rowanwins)@turf/polygonize
Polygonizes (Multi)LineString(s) into Polygons. Implementation of GEOSPolygonize function (geos::operation::polygonize::Polygonizer). (PR Turfjs#767 - Author @NickCis)@turf/transform-rotate
Rotates any geojson Feature or Geometry of a specified angle, around its centroid or a given pivot point; all rotations follow the right-hand rule. (Issue Turfjs#747 - Author @stebogit)@turf/transform-translate
Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line on the provided direction angle. (Issue Turfjs#747 - Author @stebogit)@turf/transform-scale
Scale a GeoJSON from a given point by a factor of scaling (ex: factor=2 would make the GeoJSON 200% larger). If a FeatureCollection is provided, the origin point will be calculated based on each individual Feature. (Issue Turfjs#747 - Author @stebogit)
- Support z-coordinate as input for
@turf/turf-tin
(PR Turfjs#772) - Adds properties parameter to
@turf/centroid
and@turf/center
(PR Turfjs#769) - Include Yarn.lock for all modules & Lerna uses Yarn (Issue Turfjs#704, Turfjs#765, PR Turfjs#766)
- Use
Tap
at root which enables code coverage reports (Issue Turfjs#328 & PR Turfjs#762) - Support z-coordinate as input for
@turf/pointplane
(PR Turfjs#754) - Add core tests - file management & package.json rules (PR Turfjs#749 & Turfjs#756)
- Website http://turfjs.org is back up and running (Issue Turfjs#777)
@turf/rhumb-destination
issue at 180th meridian (Issue Turfjs#770 & PR Turfjs#771)- Getting too large numbers for Longitude (Issue Turfjs#758 & PR Turfjs#763)
- Throw error if FeatureCollection not array #751 (PR Turfjs#760)
- Change default param coordinates to 3 @turf/truncate (PR Turfjs#757)
- along returns a point that is not found by
@turf/point-on-line
(Issue Turfjs#691) - Fix location of intersect point for
@turf/point-on-line
. (PR Turfjs#750) - Handle empty geometries as undefined
@turf/buffer
(PR Turfjs#746)
- Rhumb Line Modules (Turfjs#728)
@turf/polygon-tangents
Finds the tangents of a (Multi)Polygon from a Point. (Turfjs#708)@turf/rewind
Rewind LineString or Polygon outer ringclockwisecounter-clockwise and inner ringscounterclockwiseclockwise (Turfjs#700 & Turfjs#66)@turf/isobands
- Takes a grid FeatureCollection of Point features with z-values and an array of value breaks and generates filled contour isobands. (Turfjs#619)
- New function convertDistance to
@turf/helpers
(Turfjs#732) - Add ignoreBoundary param
@turf/inside
(Turfjs#706) - Add flattenEach/flattenReduce to
@turf/meta
. (Turfjs#712 & Turfjs#692) - New Feature
getGeom
&getGeomType
in@turf/invariant
(Turfjs#720) - Adds
round()
,radians2degrees()
anddegrees2radians()
toturf-helpers
(Turfjs#715) - ⭐️ New Add FeatureCollection & GeometryCollection support to
@turf/rewind
(Turfjs#741)
- Fix
@turf/circle
translate properties (Turfjs#717) - Apply equidistance
@turf/buffer
to polygons (Turfjs#660 & Turfjs#718) - Fix jsts empty (Multi)Polygon error
@turf/difference
(Turfjs#725) - Support Geometry Objects & Collection (Turfjs#710)
- New Reverse winding - Polygon CCW & Polygon CW
@turf/rewind
(Turfjs#741) - ⭐️ New Fix Feature GeometryCollection to
@turf/buffer
(Turfjs#739) - ⭐️ New Re-enable negative
radius
to@turf/buffer
(Turfjs#736)
- Add mutate param to
@turf/flip
- Add Geometry & GeometryCollection support to
@turf/truncate
@turf/inside
performance increase- Add properties param to
@turf/circle
- Added
bearingToAngle
method to turf-helpers
- Fix
@turf/buffer
points in high latitudes - lineIntersect returns the same point several times
@turf/flip
incorrect if z-elevation is present
- added centered param to point-grid (PR: Turfjs#650)
- Single
module.export
helpers, invariant & meta (Commit: https://github.com/Turfjs/turf/commit/9cebb2100cf545fec49488c80140909ab54358b5)
- Turf.invariant fails on string value as coordinate (PR: Turfjs#643)
- Handle precision=0 turf-truncate (PR: Turfjs#641)
- Added
radiansToDistance
,distanceToRadians
&distanceToDegrees
to Turf core library from@turf/helpers
. (Commit: https://github.com/Turfjs/turf/commit/a88d77a3e7f76860b3c138a716da8b603a407c8e) - Removed process.hrtime in
@turf/polygon-unkink
(issue: mclaeysb/simplepolygon#5)
Typescript definitions index.d.ts
added to all the packages.
Fix turf-line-slice bug with vertical linestrings.
This is a big change in Turf! 3.0.0 is a release that targets the development cycle of Turf, letting us work on it more and release more often.
Monorepo
Turf 3.x and forward is a monorepo project. We publish lots of little modules as usual, but there's one repo - turfjs/turf - that contains all the code and the issues for the Turf source code. We use lerna to link these packages together and make sure they work.
Why? We already had internal turf modules, like turf-meta
, and development
was harder and harder - we had a bunch of custom scripts to do releases and
tests, and these were just written for Turf. Lerna is from the very popular
and very well-maintained babel project, and it
works really well, and reduces maintainer sadness.
Simplicity
Turf grew a bunch of modules that weren't totally necessary, or were expressing only a line or two of JavaScript. We want to make things easier, but these modules didn't make code more expressive and they hid complexity where it didn't need to be hidden. Turf 3.x focuses on the core functionalities we need, making sure they're tested and performant.
turf-erase has been renamed turf-difference to make its name more similar to the equivalents in other libraries.
Removed modules: merge, sum, min, max, average, median, variance, deviation, filter, remove, jenks, quantile. See the upgrade guide below for replacements.
Upgrading from v2
If you were using turf-merge
turf-merge repeatedly called turf-union on an array of polygons. Here's how to implement the same thing without the special module
var clone = require('clone');
var union = require('turf-union');
function merge(polygons) {
var merged = clone(polygons.features[0]), features = polygons.features;
for (var i = 0, len = features.length; i < len; i++) {
var poly = features[i];
if (poly.geometry) merged = union(merged, poly);
}
return merged;
}
An alternative method that merges pairs of features recursively. With large numbers and similar complexity of input geometries this can speed up run time by factor 10. Choose depending on your use case.
var union = require('turf-union');
function mergeBin(polygons) {
var features = polygons.features;
do {
var merged = [], len = features.length;
for (var i = 0; i < len-1; i += 2) {
merged.push(turf.union(features[i], features[i+1]));
}
if (len % 2 !== 0) {
merged.push(features[len-1]);
}
features = merged;
} while(features.length > 1);
return features[0];
}
If you were using turf-sum, min, max, average, median, variance, deviation
The turf-collect
method provides the core of these statistical methods
and lets you bring your own statistical library, like simple-statistics
,
science.js
, or others.
For example, here's how to find the median of matched values with simple-statistics. Finding other statistics, like variance, mean, and so on simply use other methods from the statistics library.
var ss = require('simple-statistics');
var turf = require('@turf/turf');
var poly1 = turf.polygon([[[0,0],[10,0],[10,10],[0,10],[0,0]]]);
var poly2 = turf.polygon([[[10,0],[20,10],[20,20],[20,0],[10,0]]]);
var polyFC = turf.featureCollection([poly1, poly2]);
var pt1 = turf.point([5,5], {population: 200});
var pt2 = turf.point([1,3], {population: 600});
var pt3 = turf.point([14,2], {population: 100});
var pt4 = turf.point([13,1], {population: 200});
var pt5 = turf.point([19,7], {population: 300});
var ptFC = turf.featureCollection([pt1, pt2, pt3, pt4, pt5]);
// collects values from matching points into an array called 'values'
var collected = turf.collect(polyFC, ptFC, 'population', 'values');
// finds the median of those values.
collected.features.forEach(function (feature) {
feature.properties.median = ss.median(feature.properties.values);
});
console.log(JSON.stringify(collected, null, 2));
If you were using turf-filter, turf-remove
These modules were thin wrappers around native JavaScript methods: use Array.filter instead:
var filteredFeatures = features.filter(function(feature) {
return feature.properties.value > 10;
});
If you were using turf-jenks, turf-quantile
Use Array.map to get values, and then bring your own statistical calculation, like simple-statistics or science.js.
var values = features.map(function(feature) {
return feature.properties.value;
});
If you were using turf-extent
turf-extent's name was changed to turf-bbox. It is functionally the same.
turf.bbox(poly) // [minx, miny, maxx, maxy]
- turf-grid renamed turf-point-grid (turf.grid => turf.pointGrid)
- turf-hex renamed turf-hex-grid (turf.hex => turf.hexGrid)
- turf-hex-grid now has a required
unit
parameter - remove turf-isobands; use turf-isolines instead
- added turf-square-grid (turf.squareGrid)
- added turf-triangle-grid (turf.triangleGrid)
- constrain turf-point-grid to the bbox
- update all module dependencies to master
- add support for features in turf.intersection
- fix issues with turf.polygon coordinate wrapping inconsistencies
- add
unit
parameter to turf.concave
- harmonize turf-tin dependency tree
- fixes bug in turf-along
- added turf-line-slice for segmenting LineStrings with Points
- turf-point-on-line for calculating the closest Point from a Point to a LineString
- tin ~7x faster
- Fix mutability issues with
flip
,erase
: data passed to Turf should never be changed in place. - added turf-line-distance for geodesic measuring of LineStrings
- added turf-along for calculating a the location of a Point x distance along a LineString
- added turf-area for calculating the area of a given feature