Turf中的feature函数可以将GeoJSON对象转换为Turf Feature对象。Turf Feature对象是指地理位置数据中包含一个几何图形和一个属性的数据格式。
turf.feature(geometry, properties?)将GeoJSON对象转换为Turf Feature对象。
参数:
geometry (Geometry | Feature | FeatureCollection):几何图形数据。properties (any):特征属性。可选参数。返回值:
Feature:Turf Feature对象。示例代码:
var geojson = {
"type": "Point",
"coordinates": [0, 0]
};
var feature = turf.feature(geojson, { name: 'test point' });
console.log(feature);
// {
// "type": "Feature",
// "properties": {
// "name": "test point"
// },
// "geometry": {
// "type": "Point",
// "coordinates": [0, 0]
// }
// }
geometry参数必须是一个包含几何信息的GeoJSON对象。如果参数是一个Feature对象,则Feature的geometry属性将被转换为turf.feature函数创建的Feature对象的geometry属性。properties参数是可选的。如果没有提供,则返回的Feature对象将只包含几何信息,没有属性信息。如果提供了属性信息,则属性信息将以键值对的形式加入到返回的Feature对象的properties属性中。