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 2
)mutate
[boolean] allows GeoJSON input to be mutated (significant performance increase if true) (optional, default false
)Examples
var point = {
"type": "Feature",
"properties": {}
"geometry": {
"type": "Point",
"coordinates": [
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.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 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.