Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@turf/point-on-feature
Advanced tools
@turf/point-on-feature is a module from the Turf.js library that allows you to find a point on a given GeoJSON feature. This can be useful for various geospatial analyses, such as finding the centroid of a polygon or a point on a line.
Find a point on a polygon
This feature allows you to find a point on a polygon. The code sample demonstrates how to create a polygon and then find a point on it using the @turf/point-on-feature module.
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[-81, 41],
[-81, 47],
[-72, 47],
[-72, 41],
[-81, 41]
]]);
const pointOnPolygon = turf.pointOnFeature(polygon);
console.log(pointOnPolygon);
Find a point on a line
This feature allows you to find a point on a line. The code sample demonstrates how to create a line and then find a point on it using the @turf/point-on-feature module.
const turf = require('@turf/turf');
const line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
const pointOnLine = turf.pointOnFeature(line);
console.log(pointOnLine);
The 'centroid' package calculates the centroid of a polygon. While @turf/point-on-feature can find a point on any feature, 'centroid' is specifically focused on finding the centroid of polygons.
The 'geojson-utils' package provides various utilities for working with GeoJSON data, including finding points on features. It offers a broader range of functionalities compared to @turf/point-on-feature, which is more specialized.
Takes a Feature or FeatureCollection and returns a Point guaranteed to be on the surface of the feature.
Parameters
geojson
(Feature | FeatureCollection) any Feature or FeatureCollectionExamples
// create a random polygon
var polygon = turf.randomPolygon();
var pointOnPolygon = turf.pointOnFeature(polygon);
//addToMap
var addToMap = [polygon, pointOnPolygon];
Returns Feature<Point> a point on the surface of input
Normalizes any GeoJSON to a FeatureCollection
Parameters
geojson
GeoJSON Any GeoJSONReturns FeatureCollection FeatureCollection
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/point-on-feature
Or install the Turf module that includes it as a function:
$ npm install @turf/turf
FAQs
turf point-on-feature module
We found that @turf/point-on-feature 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.