Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

turf-nearest

Package Overview
Dependencies
Maintainers
8
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-nearest - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

62

index.js

@@ -1,3 +0,61 @@

distance = require('turf-distance');
var distance = require('turf-distance');
/**
* Takes a {@link Point} feature and a {@link FeatureCollection} of Point features and returns the Point feature from the FeatureCollection closest to the input point.
*
* @module turf/nearest
* @category classification
* @param {Point} point the reference point
* @param {FeatureCollection} against a FeatureCollection of Point features
* @return {Feature} the closest Point feature in `against` to `point`
* @example
* var point = {
* "type": "Feature",
* "properties": {
* "marker-color": "#0f0"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [28.965797, 41.010086]
* }
* };
* var against = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [28.973865, 41.011122]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [28.948459, 41.024204]
* }
* }, {
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Point",
* "coordinates": [28.938674, 41.013324]
* }
* }
* ]
* };
*
* var nearest = turf.nearest(point, against);
* nearest.properties['marker-color'] = '#f00';
*
* var resultFeatures = against.features.concat(point);
* var result = {
* "type": "FeatureCollection",
* "features": resultFeatures
* };
*
* //=result
*/
module.exports = function(targetPoint, points){

@@ -23,2 +81,2 @@ var nearestPoint;

return nearestPoint;
}
}

15

package.json
{
"name": "turf-nearest",
"version": "1.0.1",
"version": "1.0.2",
"description": "turf nearest module",
"main": "index.js",
"scripts": {
"test": "node test.js"
"test": "node test.js",
"doc": "dox -r < index.js | doxme --readme > README.md"
},
"repository": {
"type": "git",
"url": "https://github.com/morganherlocker/turf-nearest.git"
"url": "https://github.com/Turfjs/turf-nearest.git"
},

@@ -22,8 +23,10 @@ "keywords": [

"bugs": {
"url": "https://github.com/morganherlocker/turf-nearest/issues"
"url": "https://github.com/Turfjs/turf-nearest/issues"
},
"homepage": "https://github.com/morganherlocker/turf-nearest",
"homepage": "https://github.com/Turfjs/turf-nearest",
"devDependencies": {
"benchmark": "^1.0.0",
"tape": "^3.0.3"
"tape": "^3.5.0",
"dox": "^0.6.1",
"doxme": "^1.4.3"
},

@@ -30,0 +33,0 @@ "dependencies": {

@@ -1,42 +0,54 @@

turf-nearest
============
[![Build Status](https://travis-ci.org/Turfjs/turf-nearest.svg)](https://travis-ci.org/Turfjs/turf-nearest)
# turf-nearest
Returns the nearest point feature.
[![build status](https://secure.travis-ci.org/Turfjs/turf-nearest.png)](http://travis-ci.org/Turfjs/turf-nearest)
###Install
turf nearest module
```sh
npm install turf-nearest
```
###Parameters
### `turf.nearest(point, against)`
|name|description|
|---|---|
|inPoint|a Point Features|
|inFeatures|a FeatureCollection|
Takes a Point feature and a FeatureCollection of Point features and returns the Point feature from the FeatureCollection closest to the input point.
###Usage
### Parameters
| parameter | type | description |
| --------- | ----------------- | ------------------------------------- |
| `point` | Point | the reference point |
| `against` | FeatureCollection | a FeatureCollection of Point features |
### Example
```js
nearest(inPoint, inFeatures)
var point = turf.point([28.965797, 41.010086]);
point.properties['marker-color'] = '#0f0';
var against = turf.featurecollection([
turf.point([28.973865, 41.011122]),
turf.point([28.948459, 41.024204]),
turf.point([28.938674, 41.013324])
]);
var nearest = turf.nearest(point, against);
nearest.properties['marker-color'] = '#f00';
var result = turf.featurecollection(
against.features.concat(point));
//=result
```
###Example
## Installation
```js
var nearest = require('turf-nearest')
var point = require('turf-point')
var featurecollection = require('turf-featurecollection')
Requires [nodejs](http://nodejs.org/).
var inPoint = point(-75.4, 39.4, {name: 'Location A'})
var pt1 = point(-75.343, 39.984, {name: 'Location B'})
var pt2 = point(-75.833, 39.284, {name: 'Location C'})
var pt3 = point(-75.534, 39.123, {name: 'Location D'})
var inFeatures = featurecollection([pt1, pt2, pt3])
```sh
$ npm install turf-nearest
```
var closestPoint = nearest(inPoint, inFeatures)
## Tests
console.log(closestPoint)
```
```sh
$ npm test
```
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc