MEASUREMENT
COORDINATE MUTATION
TRANSFORMATION
FEATURE_CONVERSION
MISC
HELPER
RANDOM
GRIDS
AGGREGATION
META
ASSERTIONS
BOOLEANS
UNIT CONVERSION
DATA
JOINS
CLASSIFICATION

featureOf

featureOf函数用于断言一个要素是否属于某个图层中(即该图层是否具有该要素)。

使用方法

turf.featureOf(feature, layer)

参数

  • feature:传入一个Feature类型的对象。
  • layer:传入一个FeatureCollection类型的对象,表示某一图层。

返回值

如果该图层包含该要素,则返回true,否则返回false

示例

var pt = {
  "type": "Feature",
  "properties": {
    "marker-color": "#0F0"
  },
  "geometry": {
    "type": "Point",
    "coordinates": [-77.032, 38.913]
  }
};
var polygons = {
  "type": "FeatureCollection",
  "features": [{
    "type": "Feature",
    "properties": {
      "fill": "#0F0"
    },
    "geometry": {
      "type": "Polygon",
      "coordinates": [[
        [-77.032, 38.913],
        [-77.024, 38.913],
        [-77.024, 38.916],
        [-77.032, 38.916],
        [-77.032, 38.913]
      ]]
    }
  }]
};

// 判断pt是否属于polygons图层
var isContained = turf.featureOf(pt, polygons);  // true

异常

  • 如果传入的对象不符合上述要求,则该函数将抛出异常。