data_sample
Randomly sample a specified number of features from a GeoJSON feature collection to create a representative subset for analysis or testing purposes.
Instructions
从特征集合中随机采样指定数量的特征。
此功能从输入的特征集合中随机选择指定数量的特征,返回一个新的特征集合。
Args: feature_collection: 输入特征集合 - 类型: str (JSON 字符串格式的 GeoJSON FeatureCollection) - 格式: 任何有效的 GeoJSON FeatureCollection - 示例: '{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-75.343, 39.984]}}, ...]}'
Returns: str: JSON 字符串格式的 GeoJSON FeatureCollection - 类型: GeoJSON FeatureCollection - 格式: {"type": "FeatureCollection", "features": [...]} - 示例: '{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-75.343, 39.984]}}, ...]}'
Raises: Exception: 当 JavaScript 执行失败、超时或输入数据格式错误时抛出异常
Example: >>> import asyncio >>> feature_collection = '{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-75.343, 39.984]}}, ...]}' >>> result = asyncio.run(sample(feature_collection, 5)) >>> print(result) '{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-75.343, 39.984]}}, ...]}'
Notes: - 输入参数 feature_collection 必须是有效的 JSON 字符串 - 采样数量不能超过输入特征集合中的特征总数 - 如果采样数量为0,返回空的特征集合 - 采样是随机进行的,每次调用可能得到不同的结果 - 依赖于 Turf.js 库和 Node.js 环境
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| feature_collection | Yes | ||
| num | Yes |