closest-feature v1.0.2
closest-feature
About
Measure distances
NPM
npm install --save closest-feature
YARN
yarn add closest-feature
Use
// ES6
import closest from 'closest-feature';
// older
const closest = require('closest-feature').default;
let features = [
{ "type": "Feature", "properties": { "COUNTYNBR": "18", "NAME": "Herriman", "COUNTYSEAT": 0, "SHORTDESC": "HERRIMAN TOWN", "UPDATED": "2016\/09\/02", "FIPS": "34970", "ENTITYNBR": 3035, "SALESTAXID": "060", "IMSCOLOR": 1, "MINNAME": null, "POPLASTCEN": 22018, "POPLASTEST": 30835, "GNIS": "1428675", "Shape_Leng": 57216.656373500002, "Shape_Area": 55755135.693899997 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -111.999923241180639, 40.536929968126046 ],
...
[ -111.999923241180639, 40.536929968126046 ] ] ] } },
{ "type": "Feature", "properties": { "COUNTYNBR": "18", "NAME": "Riverton", "COUNTYSEAT": 0, "SHORTDESC": "RIVERTON", "UPDATED": "2016\/09\/02", "FIPS": "64340", "ENTITYNBR": 3060, "SALESTAXID": "118", "IMSCOLOR": 2, "MINNAME": null, "POPLASTCEN": 39330, "POPLASTEST": 41900, "GNIS": "1431862", "Shape_Leng": 34602.250230700003, "Shape_Area": 32683657.6131 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -111.999080957488104, 40.523382315465085 ],
...
[ -111.999080957488104, 40.523382315465085 ] ] ] } }
];
let props = closest([-112.09698739755993, 40.49797074565671], features);
console.log(props === features[0].properties) // true
ISC License (ISC)
Copyright 2017 Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC") Copyright (c) 1995-2003 by Internet Software Consortium
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.