Socket
Socket
Sign inDemoInstall

@turf/point-on-feature

Package Overview
Dependencies
62
Maintainers
7
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @turf/point-on-feature

turf point-on-feature module


Version published
Weekly downloads
443K
increased by18.93%
Maintainers
7
Created
Weekly downloads
 

Package description

What is @turf/point-on-feature?

@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.

What are @turf/point-on-feature's main functionalities?

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);

Other packages similar to @turf/point-on-feature

Readme

Source

@turf/point-on-feature

pointOnFeature

Takes a Feature or FeatureCollection and returns a Point guaranteed to be on the surface of the feature.

  • Given a Polygon, the point will be in the area of the polygon
  • Given a LineString, the point will be along the string
  • Given a Point, the point will the same as the input

Parameters

  • geojson GeoJSON any Feature or FeatureCollection

Examples

var 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.

Installation

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

Keywords

FAQs

Last updated on 17 Jan 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc