Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@turf/point-on-feature
Advanced tools
Package description
@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.
Readme
Takes a Feature or FeatureCollection and returns a Point guaranteed to be on the surface of the feature.
geojson
GeoJSON any Feature or FeatureCollectionvar polygon = turf.polygon([[
[116, -36],
[131, -32],
[146, -43],
[155, -25],
[133, -9],
[111, -22],
[116, -36]
]]);
var pointOnPolygon = turf.pointOnFeature(polygon);
//addToMap
var addToMap = [polygon, pointOnPolygon];
Returns Feature<Point> a point on the surface of input
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/point-on-feature
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf point-on-feature module
The npm package @turf/point-on-feature receives a total of 382,122 weekly downloads. As such, @turf/point-on-feature popularity was classified as popular.
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 7 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.