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/transform-rotate
Advanced tools
@turf/transform-rotate is a module from the Turf.js library that allows you to rotate geometries by a specified angle around a given pivot point. This can be useful for various geospatial data manipulations, such as aligning features or creating rotated versions of existing geometries.
Rotate a Point
This feature allows you to rotate a point geometry by a specified angle. In this example, a point at coordinates [0, 0] is rotated by 45 degrees.
const turf = require('@turf/turf');
const point = turf.point([0, 0]);
const rotatedPoint = turf.transformRotate(point, 45);
console.log(rotatedPoint);
Rotate a Polygon
This feature allows you to rotate a polygon geometry by a specified angle. In this example, a square polygon is rotated by 90 degrees.
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[0, 0],
[1, 0],
[1, 1],
[0, 1],
[0, 0]
]]);
const rotatedPolygon = turf.transformRotate(polygon, 90);
console.log(rotatedPolygon);
Rotate around a Custom Pivot
This feature allows you to rotate a geometry around a custom pivot point. In this example, a line is rotated by 45 degrees around the pivot point [1, 1].
const turf = require('@turf/turf');
const line = turf.lineString([[0, 0], [2, 2]]);
const pivot = [1, 1];
const rotatedLine = turf.transformRotate(line, 45, { pivot });
console.log(rotatedLine);
JSTS (JavaScript Topology Suite) is a library for performing various geometric operations, including transformations like rotation. It offers a more comprehensive set of geometric operations compared to @turf/transform-rotate, but it may be more complex to use for simple tasks.
Geolib is a library for geospatial calculations and transformations. It provides functions for rotating points and other geometries, similar to @turf/transform-rotate, but it also includes a broader range of geospatial utilities such as distance calculations and bounding box operations.
Rotates any geojson Feature or Geometry of a specified angle, around its centroid
or a given pivot
point.
geojson
GeoJSON object to be rotated
angle
number of rotation in decimal degrees, positive clockwise
options
Object Optional parameters (optional, default {}
)
var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
var options = {pivot: [0, 25]};
var rotatedPoly = turf.transformRotate(poly, 10, options);
//addToMap
var addToMap = [poly, rotatedPoly];
rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
Returns GeoJSON the rotated GeoJSON feature
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 single module individually:
$ npm install @turf/transform-rotate
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf transform-rotate module
The npm package @turf/transform-rotate receives a total of 446,576 weekly downloads. As such, @turf/transform-rotate popularity was classified as popular.
We found that @turf/transform-rotate 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.