Skip to content

描述 ​

接收一组 points 和一组 polygons 和/或 multipolygons 并执行空间连接。

参数 ​

名称类型描述
pointsFeatureCollection<Point>输入点
polygonsFeatureCollection<Polygon | MultiPolygon>输入 (多)多边形
fieldstringpolygons 中要添加到连接的 {<Point>} 要素的属性
outFieldstringpoints 中存储从 polygons 连接的属性的属性

返回值 ​

FeatureCollection<Point> 具有 containingPolyId 属性的点,包含来自 polyId 的值

示例 ​

javascript
var pt1 = turf.point([-77, 44]);
var pt2 = turf.point([-77, 38]);
var poly1 = turf.polygon(
  [
    [
      [-81, 41],
      [-81, 47],
      [-72, 47],
      [-72, 41],
      [-81, 41],
    ],
  ],
  { pop: 3000 },
);
var poly2 = turf.polygon(
  [
    [
      [-81, 35],
      [-81, 41],
      [-72, 41],
      [-72, 35],
      [-81, 35],
    ],
  ],
  { pop: 1000 },
);

var points = turf.featureCollection([pt1, pt2]);
var polygons = turf.featureCollection([poly1, poly2]);

var tagged = turf.tag(points, polygons, "pop", "population");

安装 ​

javascript
$ npm install @turf/tag

import { tag } from "@turf/tag";
const result = tag(...);
javascript
$ npm install @turf/turf

import * as turf from "@turf/turf";
const result = turf.tag(...);