Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@turf/area
Advanced tools
@turf/area is a module from the Turf.js library that allows you to calculate the area of GeoJSON polygons. It is useful for geospatial analysis and can handle complex polygons, including those with holes.
Calculate area of a simple polygon
This feature allows you to calculate the area of a simple polygon. The code sample demonstrates how to create a polygon and calculate its area using the @turf/area module.
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[-74.0059413, 40.7127837],
[-73.935242, 40.730610],
[-73.944158, 40.678178],
[-74.0059413, 40.7127837]
]]);
const area = turf.area(polygon);
console.log(area);
Calculate area of a polygon with holes
This feature allows you to calculate the area of a polygon that contains holes. The code sample demonstrates how to create such a polygon and calculate its area using the @turf/area module.
const turf = require('@turf/turf');
const polygonWithHole = turf.polygon([[
[-74.0059413, 40.7127837],
[-73.935242, 40.730610],
[-73.944158, 40.678178],
[-74.0059413, 40.7127837]
], [
[-73.965242, 40.7127837],
[-73.955242, 40.7227837],
[-73.945242, 40.7127837],
[-73.965242, 40.7127837]
]]);
const area = turf.area(polygonWithHole);
console.log(area);
Geolib is a library for geospatial calculations, including distance and area calculations. It is more general-purpose compared to @turf/area, which is specifically focused on area calculations for GeoJSON polygons.
Geojson-area is a lightweight library specifically designed to calculate the area of GeoJSON polygons. It is similar to @turf/area but is more focused and has fewer dependencies.
Takes one or more features and returns their area in square meters.
Parameters
geojson
(FeatureCollection | Feature<any>) input GeoJSON feature(s)Examples
var polygon = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[125, -15],
[113, -22],
[117, -37],
[130, -33],
[148, -39],
[154, -27],
[144, -15],
[125, -15]
]
]
}
}
var area = turf.area(polygon);
//=area => square meters
//=polygon
Returns number area in square meters
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/area
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
FAQs
turf area module
The npm package @turf/area receives a total of 521,314 weekly downloads. As such, @turf/area popularity was classified as popular.
We found that @turf/area 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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.