第04章 - 内置算子详解
OpenGIS DAF 内置了 9 个算子,按功能分为四类:空间运算、空间关系、属性操作、质检规则。本章逐一详解每个算子的用途、参数、输入输出约定与典型用法。
4.1 算子总览
| 分类 | 算子 ID | 用途 | 关键参数 |
|---|---|---|---|
| 空间运算 | buffer |
缓冲区分析 | distance(必填) |
| 空间运算 | clip |
裁剪 | 无 |
| 空间关系 | intersect_check |
相交检查 | use_second_input |
| 空间关系 | containment_check |
包含/包含于检查 | relationship |
| 属性操作 | field_calculator |
字段计算 | target_field/expression/field_type |
| 属性操作 | null_value_filler |
空值填充 | target_field/default_value/field_type |
| 属性操作 | coordinate_transform |
坐标系转换 | source_epsg/target_epsg |
| 质检规则 | attribute_completeness_checker |
属性完整性检查 | required_fields |
| 质检规则 | geometry_validity_checker |
几何有效性检查 | 无 |
提示:算子 ID 是方案中
operatorId字段的值。运行daf operator list可查看当前环境可用的全部算子及其分类。
4.2 空间运算算子
4.2.1 buffer(缓冲区)
对输入要素按指定距离生成缓冲区多边形。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
distance |
double | 是 | 缓冲距离(单位与输入坐标系一致) |
输入:单个输入 source。
示例(对学校点生成 800 米缓冲区):
{
"id": "buffer-schools",
"operatorId": "buffer",
"inputs": {
"source": { "type": "upstream", "sourceId": "transform-schools" }
},
"parameters": { "distance": 800 },
"output": {
"adapterType": "geojson",
"targetPath": "output/demo01/school-buffer-800m.geojson",
"isIntermediate": true
}
}
注意:缓冲距离的单位取决于输入数据的坐标系。若输入是经纬度(EPSG:4326),
distance: 800表示 800 度而非 800 米——这正是演示方案先做coordinate_transform(4326→3857 米制)再缓冲的原因。
4.2.2 clip(裁剪)
用裁剪面裁剪源要素。
参数:无。
输入:两个输入——source(被裁剪的要素)与 clip(裁剪面)。
语义要点:clip 采用逐面求交语义。一个源要素若与多个裁剪面相交,会输出多条结果(可能发生要素分裂)。这与 ogr2ogr / QGIS 中”先 union 裁剪面再裁剪”的语义不同。若需要后者,请先在数据准备阶段对裁剪面做合并。
示例(用城市边界裁剪学校缓冲区):
{
"id": "clip-service-area",
"operatorId": "clip",
"inputs": {
"source": { "type": "upstream", "sourceId": "buffer-schools" },
"clip": { "type": "upstream", "sourceId": "transform-boundary" }
},
"output": {
"adapterType": "geojson",
"targetPath": "output/demo01/school-service-area.geojson",
"isIntermediate": true
}
}
4.3 空间关系算子
空间关系算子通常配合 qcMode: true 使用,在质检模式下输出 issues 问题清单;也可作为普通算子运行。
4.3.1 intersect_check(相交检查)
检查要素之间是否相交。
参数:
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
use_second_input |
bool | true |
true:检查两个输入集合(source + target)之间的交叉;false:检查单个输入集合内部两两相交 |
输入:use_second_input=true 时需要 source + target 两个输入;false 时只需 source。
示例(检查地块两两重叠,use_second_input=false):
{
"id": "qc-landuse-overlap",
"operatorId": "intersect_check",
"inputs": {
"source": { "type": "external", "sourceId": "data/landuse.geojson" }
},
"parameters": { "use_second_input": false },
"output": { "adapterType": "console" },
"executionPolicy": { "qcMode": true }
}
4.3.2 containment_check(包含/包含于检查)
检查要素之间的包含关系。
参数:
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
relationship |
string | contains |
contains:检查 source 是否包含 target;within:检查 source 是否位于 target 内部 |
输入:source + target 两个输入。
示例(检查道路是否完全位于生态保护区内,relationship: within):
{
"id": "qc-road-in-ecozone",
"operatorId": "containment_check",
"inputs": {
"source": { "type": "external", "sourceId": "data/roads.geojson" },
"target": { "type": "external", "sourceId": "data/landuse.geojson" }
},
"parameters": { "relationship": "within" },
"output": { "adapterType": "console" },
"executionPolicy": { "qcMode": true }
}
4.4 属性操作算子
4.4.1 field_calculator(字段计算)
按表达式计算并写入目标字段。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
target_field |
string | 是 | 目标字段名 |
expression |
string | 是 | 计算表达式 |
field_type |
string | 是 | 结果类型:String/Integer/Double/Boolean/DateTime |
表达式语法:
- 字符串字面量:用双引号包裹,如
"服务区"; - 字段引用:用花括号包裹,如
{school_name}; - 算术运算:
+-*/与括号; - 纯数字:直接书写。
字段引用大小写敏感:表达式中的字段引用是大小写敏感的。Shapefile 读取的字段名通常为大写,PostGIS 写入/读取会折叠为小写。跨数据源方案需注意字段名实际大小写。
示例(拼接字符串,生成服务区标签):
{
"id": "label-zones",
"operatorId": "field_calculator",
"inputs": {
"source": { "type": "upstream", "sourceId": "clip-service-area" }
},
"parameters": {
"target_field": "zone_label",
"expression": "\"服务区-{school_name}\"",
"field_type": "String"
},
"output": {
"adapterType": "geojson",
"targetPath": "output/demo01/school-service-area-labeled.geojson",
"isIntermediate": true
}
}
4.4.2 null_value_filler(空值填充)
将目标字段中的空值(null)替换为指定默认值。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
target_field |
string | 是 | 目标字段名 |
default_value |
string | 是 | 填充的默认值 |
field_type |
string | 是 | 字段类型 |
示例(将 principal 字段的空值填充为”(未登记)”):
{
"id": "fill-principal",
"operatorId": "null_value_filler",
"inputs": {
"source": { "type": "upstream", "sourceId": "label-zones" }
},
"parameters": {
"target_field": "principal",
"default_value": "(未登记)",
"field_type": "String"
},
"output": {
"adapterType": "geojson",
"targetPath": "output/demo01/school-service-area-final.geojson"
}
}
4.4.3 coordinate_transform(坐标系转换)
将要素从源坐标系转换到目标坐标系。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
source_epsg |
int | 是 | 源坐标系 EPSG 编码 |
target_epsg |
int | 是 | 目标坐标系 EPSG 编码 |
示例(WGS84 经纬度 → Web 墨卡托米制):
{
"id": "transform-schools",
"operatorId": "coordinate_transform",
"inputs": {
"source": { "type": "external", "sourceId": "data/schools.geojson" }
},
"parameters": { "source_epsg": 4326, "target_epsg": 3857 },
"output": { "adapterType": "console", "isIntermediate": true }
}
CRS 传播:转换后的坐标系会随数据流传播到下游算子与最终输出。GeoJSON 输出会在头部写入
crs字段(如urn:ogc:def:crs:EPSG::3857),Shapefile 输出会生成对应的.prj文件。
4.5 质检规则算子
质检规则算子运行在 qcMode: true 下,输出 issues 问题清单,并参与质量评分。详见第 06 章。
4.5.1 attribute_completeness_checker(属性完整性检查)
检查指定字段是否缺失或为空。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
required_fields |
string | 是 | 必填字段名,逗号分隔 |
输出问题类型:
| 问题类型 | 严重级别 | 触发条件 |
|---|---|---|
ATTR_MISSING |
Error | 字段值为 null |
ATTR_EMPTY |
Warning | 字段值为空字符串 |
示例(检查学校 5 个必填字段):
{
"id": "qc-schools-attributes",
"operatorId": "attribute_completeness_checker",
"inputs": {
"source": { "type": "external", "sourceId": "data/schools.geojson" }
},
"parameters": { "required_fields": "school_name,principal,phone,capacity,built_year" },
"output": { "adapterType": "console" },
"executionPolicy": { "qcMode": true }
}
4.5.2 geometry_validity_checker(几何有效性检查)
检查要素几何是否有效。
参数:无。
输出问题类型:
| 问题类型 | 严重级别 | 触发条件 |
|---|---|---|
GEOM_EMPTY |
Error | 几何为空 |
GEOM_INVALID |
Error | 几何无效(自相交、环方向错误等) |
GEOM_NOT_SIMPLE |
Warning | 线几何不简单(自交) |
示例(检查道路几何):
{
"id": "qc-roads-geometry",
"operatorId": "geometry_validity_checker",
"inputs": {
"source": { "type": "external", "sourceId": "data/roads.geojson" }
},
"output": { "adapterType": "console" },
"executionPolicy": { "qcMode": true }
}
4.6 算子组合与数据流
算子通过方案的 inputs 绑定串联成 DAG。一个算子的输出可以作为下游算子的输入,形成处理流水线。演示方案 01 展示了完整的六步链:
coordinate_transform → buffer → clip → field_calculator → null_value_filler
其中 coordinate_transform 与 buffer 之间、clip 与 field_calculator 之间通过 upstream 绑定传递数据。算子本身不关心数据来自文件还是上游算子——统一通过 IFeatureSource 抽象访问。
4.7 本章小结
- OpenGIS DAF 内置 9 个算子,分属空间运算、空间关系、属性操作、质检规则四类;
- 空间运算算子(
buffer/clip)用于几何变换,注意clip的逐面求交语义与缓冲距离单位; - 空间关系算子(
intersect_check/containment_check)常用于质检,支持集合间与集合内两种模式; - 属性操作算子(
field_calculator/null_value_filler/coordinate_transform)处理字段与坐标系; - 质检规则算子(
attribute_completeness_checker/geometry_validity_checker)在qcMode下输出问题清单; - 算子通过
upstream绑定串联成 DAG,形成可复用的处理流水线。