Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@turf/helpers
Advanced tools
The @turf/helpers package is part of the Turf.js library, which is a modular geospatial engine written in JavaScript. It provides functions to create various simple geometrical features such as points, lines, and polygons, and to manipulate these geometries in various ways. This package is particularly useful for developers working with geographic information systems (GIS) and spatial analysis in web applications.
Creating Points
This function creates a GeoJSON Point feature using the provided coordinates. It is useful for representing locations on a map.
const point = turf.point([5, 10]);
Creating LineStrings
This function creates a GeoJSON LineString feature from an array of positions. It is useful for mapping routes or paths.
const line = turf.lineString([[5, 10], [20, 40]]);
Creating Polygons
This function creates a GeoJSON Polygon feature from an array of linear rings. It is used to represent areas such as city boundaries or lakes.
const polygon = turf.polygon([[[5, 10], [20, 40], [40, 0], [5, 10]]]);
Leaflet is a leading open-source JavaScript library for mobile-friendly interactive maps. While Leaflet itself focuses more on map interactions and overlays, it can be used in conjunction with other tools for creating and manipulating geographic data, similar to @turf/helpers.
OpenLayers is another powerful open-source JavaScript library that handles various map-related tasks. It provides more comprehensive features for handling complex spatial operations compared to @turf/helpers, which is more focused on creating and manipulating simple geometrical features.
Wraps a GeoJSON Geometry in a GeoJSON Feature.
Parameters
Examples
var geometry = {
"type": "Point",
"coordinates": [110, 50]
};
var feature = turf.feature(geometry);
//=feature
Returns Feature a GeoJSON Feature
Takes coordinates and properties (optional) and returns a new Point feature.
Parameters
coordinates
Array<number> longitude, latitude position (each in decimal degrees)properties
[Object] an Object that is used as the Feature's
propertiesExamples
var point = turf.point([-75.343, 39.984]);
//=point
Returns Feature<Point> a Point feature
Takes an array of LinearRings and optionally an Object with properties and returns a Polygon feature.
Parameters
coordinates
Array<Array<Array<number>>> an array of LinearRingsproperties
[Object] a properties objectExamples
var polygon = turf.polygon([[
[-2.275543, 53.464547],
[-2.275543, 53.489271],
[-2.215118, 53.489271],
[-2.215118, 53.464547],
[-2.275543, 53.464547]
]], { name: 'poly1', population: 400});
//=polygon
Returns Feature<Polygon> a Polygon feature
Creates a LineString based on a coordinate array. Properties can be added optionally.
Parameters
coordinates
Array<Array<number>> an array of Positionsproperties
[Object] an Object of key-value pairs to add as propertiesExamples
var linestring1 = turf.lineString([
[-21.964416, 64.148203],
[-21.956176, 64.141316],
[-21.93901, 64.135924],
[-21.927337, 64.136673]
]);
var linestring2 = turf.lineString([
[-21.929054, 64.127985],
[-21.912918, 64.134726],
[-21.916007, 64.141016],
[-21.930084, 64.14446]
], {name: 'line 1', distance: 145});
//=linestring1
//=linestring2
Returns Feature<LineString> a LineString feature
Takes one or more Features and creates a FeatureCollection.
Parameters
Examples
var features = [
turf.point([-75.343, 39.984], {name: 'Location A'}),
turf.point([-75.833, 39.284], {name: 'Location B'}),
turf.point([-75.534, 39.123], {name: 'Location C'})
];
var collection = turf.featureCollection(features);
//=collection
Returns FeatureCollection a FeatureCollection of input features
Creates a Feature<MultiLineString> based on a coordinate array. Properties can be added optionally.
Parameters
coordinates
Array<Array<Array<number>>> an array of LineStringsproperties
[Object] an Object of key-value pairs to add as propertiesExamples
var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
//=multiLine
Returns Feature<MultiLineString> a MultiLineString feature
Creates a Feature<MultiPoint> based on a coordinate array. Properties can be added optionally.
Parameters
coordinates
Array<Array<number>> an array of Positionsproperties
[Object] an Object of key-value pairs to add as propertiesExamples
var multiPt = turf.multiPoint([[0,0],[10,10]]);
//=multiPt
Returns Feature<MultiPoint> a MultiPoint feature
Creates a Feature<MultiPolygon> based on a coordinate array. Properties can be added optionally.
Parameters
coordinates
Array<Array<Array<Array<number>>>> an array of Polygonsproperties
[Object] an Object of key-value pairs to add as propertiesExamples
var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
//=multiPoly
Returns Feature<MultiPolygon> a multipolygon feature
Creates a Feature<GeometryCollection> based on a coordinate array. Properties can be added optionally.
Parameters
geometries
Array<{Geometry}> an array of GeoJSON Geometriesproperties
[Object] an Object of key-value pairs to add as propertiesExamples
var pt = {
"type": "Point",
"coordinates": [100, 0]
};
var line = {
"type": "LineString",
"coordinates": [ [101, 0], [102, 1] ]
};
var collection = turf.geometryCollection([pt, line]);
//=collection
Returns Feature<GeometryCollection> a GeoJSON GeometryCollection Feature
Round number to precision
Parameters
Examples
round(120.4321)
//=120
round(120.4321, 2)
//=120.43
Returns number rounded number
Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit. Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
Parameters
radians
number in radians across the sphereunits
[string] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers. (optional, default kilometers
)Returns number distance
Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
Parameters
distance
number in real unitsunits
[string] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers. (optional, default kilometers
)Returns number radians
Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
Parameters
distance
number in real unitsunits
[string] can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers. (optional, default kilometers
)Returns number degrees
Converts any bearing angle from the north line direction (positive clockwise) and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
Parameters
bearing
number angle, between -180 and +180 degreesReturns number angle between 0 and 360 degrees
Converts an angle in radians to degrees
Parameters
radians
number angle in radiansReturns number degrees between 0 and 360 degrees
Converts an angle in degrees to radians
Parameters
degrees
number angle between 0 and 360 degreesReturns number angle in radians
Converts a distance to the requested unit. Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
Parameters
distance
number to be convertedoriginalUnit
string of the distancefinalUnit
[string] returned unit (optional, default kilometers
)Returns number the converted distance
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Install this module individually:
$ npm install @turf/helpers
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
4.3.0
@turf/polygon-tangents
Finds the tangents of a (Multi)Polygon from a Point. (https://github.com/Turfjs/turf/pull/708)@turf/rewind
Rewind LineString or Polygon outer ring ~clockwise~ counter-clockwise and inner rings ~counterclockwise~ clockwise (https://github.com/Turfjs/turf/pull/700 & https://github.com/Turfjs/turf/issues/66)@turf/isobands
- Takes a grid FeatureCollection of Point features with z-values and an array of value breaks and generates filled contour isobands. (https://github.com/Turfjs/turf/pull/619)@turf/helpers
(https://github.com/Turfjs/turf/pull/732)@turf/inside
(https://github.com/Turfjs/turf/pull/706)@turf/meta
. (https://github.com/Turfjs/turf/pull/712 & https://github.com/Turfjs/turf/issues/692)getGeom
& getGeomType
in @turf/invariant
(https://github.com/Turfjs/turf/pull/720)round()
, radians2degrees()
and degrees2radians()
to turf-helpers
(https://github.com/Turfjs/turf/pull/715)@turf/rewind
(https://github.com/Turfjs/turf/pull/741)@turf/circle
translate properties (https://github.com/Turfjs/turf/pull/717)@turf/buffer
to polygons (https://github.com/Turfjs/turf/issues/660 & https://github.com/Turfjs/turf/pull/718)@turf/difference
(https://github.com/Turfjs/turf/pull/725)@turf/line-intersect
(https://github.com/Turfjs/turf/pull/731)@turf/line-chunk
(https://github.com/Turfjs/turf/pull/726)@turf/line-segment
(https://github.com/Turfjs/turf/pull/727 & https://github.com/Turfjs/turf/pull/711)@turf/line-overlap
(https://github.com/Turfjs/turf/pull/711)@turf/rewind
(https://github.com/Turfjs/turf/pull/741)@turf/buffer
(https://github.com/Turfjs/turf/pull/739)radius
to @turf/buffer
(https://github.com/Turfjs/turf/pull/736)FAQs
turf helpers module
The npm package @turf/helpers receives a total of 2,401,400 weekly downloads. As such, @turf/helpers popularity was classified as popular.
We found that @turf/helpers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.