Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@turf/transform-translate
Advanced tools
@turf/transform-translate is a module from the Turf.js library that allows you to translate GeoJSON features by a specified distance along a given direction. This can be useful for tasks such as moving geometries, creating buffers, or simulating movement.
Translate a Point
This feature allows you to translate a point by a specified distance and direction. In this example, a point is translated 100 meters at a 45-degree angle.
const turf = require('@turf/turf');
const point = turf.point([-75.343, 39.984]);
const translatedPoint = turf.transformTranslate(point, 100, 45);
console.log(translatedPoint);
Translate a Polygon
This feature allows you to translate a polygon by a specified distance and direction. In this example, a polygon is translated 200 meters at a 90-degree angle.
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[-75.343, 39.984],
[-75.534, 39.123],
[-75.123, 39.123],
[-75.343, 39.984]
]]);
const translatedPolygon = turf.transformTranslate(polygon, 200, 90);
console.log(translatedPolygon);
Translate a LineString
This feature allows you to translate a LineString by a specified distance and direction. In this example, a LineString is translated 50 meters at a 180-degree angle.
const turf = require('@turf/turf');
const line = turf.lineString([[-75.343, 39.984], [-75.534, 39.123]]);
const translatedLine = turf.transformTranslate(line, 50, 180);
console.log(translatedLine);
Geolib is a library for geospatial calculations. It provides functions for distance calculations, finding points within a radius, and more. While it does not directly offer translation of geometries, it can be used to calculate new positions based on distance and bearing.
JSTS (JavaScript Topology Suite) is a library for performing various geometric operations. It includes functions for buffering, union, intersection, and more. While it does not specifically focus on translation, it offers a wide range of geometric manipulations.
Proj4js is a library for converting coordinates between different coordinate systems. While it does not provide translation functionalities, it is useful for transforming coordinates which can be a part of more complex geospatial workflows.
Moves any geojson Feature or Geometry of a specified distance along a Rhumb Line on the provided direction angle.
geojson
(GeoJSON | GeometryCollection) object to be translated
distance
number length of the motion; negative values determine motion in opposite direction
direction
number of the motion; angle from North in decimal degrees, positive clockwise
options
Object Optional parameters (optional, default {}
)
options.units
Units in which distance
will be express; miles, kilometers, degrees, or radians (optional, default 'kilometers'
)options.zTranslation
number length of the vertical motion, same unit of distance (optional, default 0
)options.mutate
boolean allows GeoJSON input to be mutated (significant performance increase if true) (optional, default false
)var poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
var translatedPoly = turf.transformTranslate(poly, 100, 35);
//addToMap
var addToMap = [poly, translatedPoly];
translatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
Returns (GeoJSON | GeometryCollection) the translated GeoJSON object
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-translate
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf transform-translate module
The npm package @turf/transform-translate receives a total of 712,242 weekly downloads. As such, @turf/transform-translate popularity was classified as popular.
We found that @turf/transform-translate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.