Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@turf/truncate
Advanced tools
@turf/truncate is a module in the Turf.js library that is used to truncate the precision of coordinates in GeoJSON data. This can be useful for reducing the size of GeoJSON files or for ensuring consistent precision across datasets.
Truncate Coordinates
This feature allows you to truncate the coordinates of a GeoJSON object to a specified precision. In this example, the coordinates of a point are truncated to 3 decimal places.
const truncate = require('@turf/truncate');
const point = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [70.123456789, 40.987654321] } };
const truncated = truncate(point, { precision: 3 });
console.log(truncated);
Truncate with Custom Options
This feature allows you to truncate the coordinates of a GeoJSON object with custom options. In this example, the coordinates of a LineString are truncated to 2 decimal places, and the number of coordinates is also limited to 2.
const truncate = require('@turf/truncate');
const lineString = { "type": "Feature", "geometry": { "type": "LineString", "coordinates": [[70.123456789, 40.987654321], [71.123456789, 41.987654321]] } };
const truncated = truncate(lineString, { precision: 2, coordinates: 2 });
console.log(truncated);
The geojson-precision package allows you to set the precision of GeoJSON coordinates. It is similar to @turf/truncate in that it helps reduce the size of GeoJSON files by limiting the number of decimal places in coordinates. However, it is a standalone package and not part of a larger geospatial library like Turf.js.
The simplify-geojson package is used to simplify GeoJSON geometries by reducing the number of points in the geometries. While it does not specifically truncate coordinate precision, it serves a similar purpose of reducing the size and complexity of GeoJSON data. It is more focused on simplifying shapes rather than just truncating coordinates.
Takes a GeoJSON Feature or FeatureCollection and truncates the precision of the geometry.
Parameters
geojson
(FeatureCollection | Feature<any>) any GeoJSON Feature, FeatureCollection, Geometry or GeometryCollection.precision
[number] coordinate decimal precision (optional, default 6
)coordinates
[number] maximum number of coordinates (primarly used to remove z coordinates) (optional, default 3
)mutate
[boolean] allows GeoJSON input to be mutated (significant performance increase if true) (optional, default false
)Examples
var point = turf.point([
70.46923055566859,
58.11088890802906,
1508
]);
var truncated = turf.truncate(point);
//addToMap
var addToMap = [truncated];
Returns (FeatureCollection | Feature<any>) layer with truncated geometry
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/truncate
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
4.6.0
@turf/clean-coords
Removes redundant coordinates from any GeoJSON Geometry.
(PR https://github.com/Turfjs/turf/pull/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 https://github.com/Turfjs/turf/pull/832 - Author @stebogit)@turf/clusters-dbscan
Takes a set of Points and partition them into clusters according to DBSCAN's data clustering algorithm.
(PR https://github.com/Turfjs/turf/pull/812 and https://github.com/Turfjs/turf/pull/851 - Author @DenisCarriere)
special mention to this incredibly instructive and fun interactive map by @DenisCarriere 😎👏
@turf/clusters
Provides getCluster
, clusterEach
, and clusterReduce
functions.
(PR https://github.com/Turfjs/turf/pull/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 https://github.com/Turfjs/turf/pull/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 https://github.com/Turfjs/turf/pull/856 and https://github.com/Turfjs/turf/pull/868 - Author @stebogit @tcql)@turf/boolean-equal
Determine whether two geometries of the same type have identical X,Y coordinate values.
(PR https://github.com/Turfjs/turf/pull/869 - Author @stebogit @tcql)centered
param default to true
in @turf/point-grid
(PR https://github.com/Turfjs/turf/pull/836 - Contributor @stebogit)MultiLineString
support for @turf/point-on-line
(PR https://github.com/Turfjs/turf/pull/838 - Contributor @stebogit)@turf/clusters
=> @turf/clusters-kmeans
, plus adds deprecated warning message to @turf/clusters@4.5.2
(See Issue https://github.com/Turfjs/turf/issues/845)@turf/clusters-kmeans
(See Issue https://github.com/Turfjs/turf/issues/850 - Contributor @DenisCarriere)segmentEach
and segmentReduce
functions to @turf/meta
(See Issue https://github.com/Turfjs/turf/issues/850 - Contributor @DenisCarriere)turf-www
; see Issue https://github.com/Turfjs/turf/issues/859
(PR https://github.com/Turfjs/turf/issues/857 + https://github.com/Turfjs/turf/issues/864 + https://github.com/Turfjs/turf/issues/870 - Contributor @DenisCarriere @stebogit)null
Geometry support across TurfJS modules (See Issue https://github.com/Turfjs/turf/issues/853)
(PR https://github.com/Turfjs/turf/issues/866 - Contributor @DenisCarriere)coordEach
/coordReduce
(@turf/meta) 🎉
(PR https://github.com/Turfjs/turf/issues/872 - Contributor @DenisCarriere)bbox
and id
params plus geometry
method to @turf/helpers
(PR https://github.com/Turfjs/turf/issues/877 - Contributor @DenisCarriere)@turf/truncate
to @turf/line-split
splitter
input to avoid approximation errors. Fixed #852
(PR https://github.com/Turfjs/turf/pull/855)@turf-mask
error (See Issue https://github.com/Turfjs/turf/issues/837)
(PR https://github.com/Turfjs/turf/pull/865 - Contributor @thiagoxvo)create-new-module
script error on LICENSE
file creation (See Issue https://github.com/Turfjs/turf/issues/861)
(commit df6986e)@turf/isobands
error on commonProperties
(See Issue https://github.com/Turfjs/turf/issues/831)
(commit 1663f07)FAQs
turf truncate module
The npm package @turf/truncate receives a total of 460,456 weekly downloads. As such, @turf/truncate popularity was classified as popular.
We found that @turf/truncate 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
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.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.