Turf-获取点范围内的geojson的所有特征

问题描述 投票:0回答:1

我有一个带有几个功能的geojson,例如街道的网格,并希望获得在特定点周围一定半径内的所有街道和其他要素。

我该如何用草皮做到这一点?我当时想遍历所有点,并将距离与turf.distance(from, to, options);进行比较。

但是也许有更好的方法。

这是背景中有地图的基础,但是我想在不使用任何地图框架的情况下进行计算。

在此示例中,它应返回街道特征+最近的距离。

enter image description here

谢谢!

geojson calculation turfjs
1个回答
0
投票

如果您可以将要查找的特征视为点(而不是直线),则一种快速而优雅的解决方案是使用geokdbush

根据其文档,它正在对地理空间最近邻搜索使用快速实现。

例如(假设圆心在[centerLong, centerLat]处:]

const KDBush = require('kdbush');
import * as geokdbush from 'geokdbush';

getLong = (p) => p.geometry.coordinates[0];
getLat = (p) => p.geometry.coordinates[1];

//build an index from all interesting (point) features  
const geoIndex = new KDBush(interestingFeaturesGeoJson.features, getLong, getLat);

//find the nearest ones to a specific point
const nearestPoints = geokdbush.around(geoIndex, centerLong, centerLat, 
        maxFeaturesToReturn, radiusInKm);
© www.soinside.com 2019 - 2024. All rights reserved.