Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@turf/mask
Advanced tools
@turf/mask is a module in the Turf.js library that allows you to create a mask from a polygon. This mask can be used to clip or hide parts of other geometries that fall outside the polygon. It is particularly useful in geospatial analysis for focusing on specific areas of interest.
Create a Mask
This feature allows you to create a mask from a given polygon. The mask can then be used to clip other geometries, effectively hiding parts of them that fall outside the polygon.
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[-5, 52],
[-4, 52],
[-4, 53],
[-5, 53],
[-5, 52]
]]);
const mask = turf.mask(polygon);
console.log(JSON.stringify(mask));
Clip Geometry with Mask
This feature demonstrates how to use the mask to clip a line geometry. The resulting geometry will only include the parts of the line that fall within the mask polygon.
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[-5, 52],
[-4, 52],
[-4, 53],
[-5, 53],
[-5, 52]
]]);
const mask = turf.mask(polygon);
const line = turf.lineString([[-6, 51], [-3, 54]]);
const clipped = turf.mask(line, mask);
console.log(JSON.stringify(clipped));
The turf-clip package provides functionalities to clip geometries using polygons. It is similar to @turf/mask but focuses more on clipping rather than masking.
The jsts (JavaScript Topology Suite) library offers a wide range of spatial operations, including clipping and masking. It is more comprehensive than @turf/mask but also more complex to use.
The geojson-merge package allows you to merge multiple GeoJSON objects into one. While it doesn't offer masking directly, it can be used in conjunction with other tools to achieve similar results.
Takes any type of polygon and an optional mask and returns a polygon exterior ring with holes.
Parameters
polygon
(FeatureCollection | Feature<(Polygon | MultiPolygon)>) GeoJSON Polygon used as interior rings or holes.mask
[Feature<Polygon>] GeoJSON Polygon used as the exterior ring (if undefined, the world extent is used)Examples
var polygon = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[112, -21], [116, -36], [146, -39], [153, -24], [133, -10], [112, -21]]]
}
}
var mask = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[90, -55], [170, -55], [170, 10], [90, 10], [90, -55]]]
}
}
var masked = turf.mask(polygon, mask);
//addToMap
var addToMap = [masked]
Returns Feature<Polygon> Masked Polygon (exterior ring with holes).
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/mask
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
FAQs
turf mask module
The npm package @turf/mask receives a total of 188,440 weekly downloads. As such, @turf/mask popularity was classified as popular.
We found that @turf/mask 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.