joins

pointsWithinPolygon

npm install @turf/points-within-polygon

接收一个面要素和点要素(集合),计算并返回在该面要素内部的点

参数

入参 类型 描述
points Feature\ FeatureCollection<Point> 要计算的点要素
polygons FeatureCollection\ Geometry\ Feature<Polygon\ MultiPolygon> 面要素

返回

FeatureCollection<Point>

范例

  1. var points = turf.points([
  2. [-46.6318, -23.5523],
  3. [-46.6246, -23.5325],
  4. [-46.6062, -23.5513],
  5. [-46.663, -23.554],
  6. [-46.643, -23.557]
  7. ]);
  8. var searchWithin = turf.polygon([
  9. [
  10. [-46.653, -23.543],
  11. [-46.634, -23.5346],
  12. [-46.613, -23.543],
  13. [-46.614, -23.559],
  14. [-46.631, -23.567],
  15. [-46.653, -23.56],
  16. [-46.653, -23.543]
  17. ]
  18. ]);
  19. var ptsWithin = turf.pointsWithinPolygon(points, searchWithin); // [-46.6318, -23.5523]、[-46.643, -23.557]

tag

npm install @turf/tag

接收一组点要素集合和一组面要素集合,面要素内的点要素进行空间连接和属性继承

参数

入参 类型 描述
points FeatureCollection<Point> 点要素集合
polygons FeatureCollection<Polygon> 面要素集合
field String 面要素的要被继承的属性
outField String 点要素继承属性的重命名

返回

FeatureCollection<Point>

范例

  1. var pt1 = turf.point([-77, 44]);
  2. var pt2 = turf.point([-77, 38]);
  3. var poly1 = turf.polygon(
  4. [
  5. [
  6. [-81, 41],
  7. [-81, 47],
  8. [-72, 47],
  9. [-72, 41],
  10. [-81, 41]
  11. ]
  12. ],
  13. { pop: 3000 }
  14. );
  15. var poly2 = turf.polygon(
  16. [
  17. [
  18. [-81, 35],
  19. [-81, 41],
  20. [-72, 41],
  21. [-72, 35],
  22. [-81, 35]
  23. ]
  24. ],
  25. { pop: 1000 }
  26. );
  27. var points = turf.featureCollection([pt1, pt2]);
  28. var polygons = turf.featureCollection([poly1, poly2]);
  29. var tagged = turf.tag(points, polygons, "pop", "population");
  30. /*
  31. {
  32. type: "FeatureCollection",
  33. faetures: [
  34. {
  35. type: "Feature",
  36. geometry: {
  37. type: "Point",
  38. coordinates: [-77, 44]
  39. },
  40. properties: {
  41. population: 3000 // pop属性重命名为population
  42. }
  43. },
  44. {
  45. type: "Feature",
  46. geometry: {
  47. type: "Point",
  48. coordinates: [-77, 38]
  49. },
  50. properties: {
  51. population: 1000
  52. }
  53. }
  54. ]
  55. }
  56. */