tag
函数用于根据指定的键和值将两个属性对象合并为一个新的属性对象。具体来说,它通过将一个属性对象中每个要素的指定键与另一个属性对象中相同键的值进行匹配,将两个属性对象合并到一起。
inProperties
:必需,类型为FeatureCollection
或Feature
。用于匹配的属性对象。joinProperty
:必需,类型为string
。用于匹配的属性对象的键。outProperty
:必需,类型为string
。输出属性对象的键。output
:可选,类型为object
。设置输出的属性值是否包含匹配的属性,如果为false
,则只输出输出属性对象的键。类型为FeatureCollection
,其中每个要素的属性包含指定的outProperty
键和值。
var inFeatures = turf.featureCollection([
turf.point([26.124515, 44.42676], { type: '起点' }),
turf.point([26.12152, 44.426369], { type: '终点' })
]);
var joinFeatures = turf.featureCollection([
turf.point([26.124515, 44.42676], { name: '工厂' }),
turf.point([26.12152, 44.426369], { name: '码头' })
]);
var joined = turf.tag(inFeatures, joinFeatures, 'name', '关键点');
// 输出:
// {
// "type": "FeatureCollection",
// "features": [
// {
// "type": "Feature",
// "properties": {
// "type": "起点",
// "关键点": "工厂"
// },
// "geometry": {
// "type": "Point",
// "coordinates": [26.124515, 44.42676]
// }
// },
// {
// "type": "Feature",
// "properties": {
// "type": "终点",
// "关键点": "码头"
// },
// "geometry": {
// "type": "Point",
// "coordinates": [26.12152, 44.426369]
// }
// }
// ]
// }
在该示例中,我们使用tag
函数将joinFeatures
对象中的name
属性与inFeature
对象中的属性进行匹配。输出的属性对象使用关键点
作为新的键,并将匹配的属性值赋给该键。