[英]Turf.js pointsWithinPolygon works for Polygon but not FeatureCollection
我正在尝试使用 Turf.js 在 FeatureCollection 的边界框中查找所有点。 根据文档,您可以为 function pointsWithinPolygon提供 Feature 或 FeatureCollection of Points。
使用文档中官方示例的修改版本,我收到以下错误消息:“Uncaught TypeError: Cannot read property '0' of undefined”。
var locationA = turf.point([-75.343, 39.984], {
name: 'Location A'
});
var locationB = turf.point([-75.833, 39.284], {
name: 'Location B'
});
var locationC = turf.point([-75.534, 39.123], {
name: 'Location C'
});
var collection = turf.featureCollection([
locationA,
locationB,
locationC
]);
var points = turf.points([
[-80, 30],
[-70, 30],
[-70, 50],
[-80, 50],
]);
console.log(turf.pointsWithinPolygon(points, collection)); // Doesn't work
知道这里出了什么问题或可能导致问题的原因吗? 该应用程序似乎适用于多边形,但不适用于特征集合。
var searchWithin = turf.polygon([[
[-46.653,-23.543],
[-46.634,-23.5346],
[-46.613,-23.543],
[-46.614,-23.559],
[-46.631,-23.567],
[-46.653,-23.560],
[-46.653,-23.543]
]]);
console.log(turf.pointsWithinPolygon(points, searchWithin)); // Works
为什么
console.log(turf.pointsWithinPolygon(points, collection)); // Doesn't work
根据文件在
https://turfjs.org/docs/#pointsWithinPolygon
pointsWithinPolygon(points, polygons)
参数:
points: Point(s)
polygons: (Multi)Polygon(s)
您的collection
[必须是 (Multi)Polygon(s)] 不符合要求,它只是 3 个点的集合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.