modules.gisOperators 模块帮助

本章节包含 modules.gisOperators 包中常用「GIS 数据操作」模块的说明和示例,例如:

  • 点/线/面等空间数据的基础几何处理

  • 坐标与空间属性相关的小工具模块

ConvexHullCenter

模块简介与适用场景

  • ConvexHullCenter 用于计算一组点样本的 **凸包中心**(取凸包顶点的均值),输出为 SingleResult``(端口:``OutputCenter)。

  • 当点数不足时会自动降级:

    • 仅 1 个点:中心为该点

    • 2 个点:中心为两点均值

    • >= 3 个点:先求凸包,再对凸包顶点求均值

  • 典型适用场景:

    • 以一组测点/钻孔/构筑物坐标快速估计 “区域中心”,用于图件定位、视图缩放中心或后续空间分析的参考点;

    • 从点集派生一个代表性位置(例如作为剖面/统计区域的中心点)。

端口说明

  • 输入端口 - InputTable:点样本表(TableData

  • 输出端口 - OutputCenter:中心坐标(SingleResult,包含 2 个 UnitResult:X/Y 或 经度/纬度)

快速上手示例:按 X/Y 坐标计算凸包中心

from gdisdk.dataclass.tables import TableData
from gdisdk.modules.gisOperators import ConvexHullCenter

# 列名建议使用默认约定:x_coordinate / y_coordinate
table = TableData(
    {
        "x_coordinate": [0.0, 1.0, 1.0, 0.0],
        "y_coordinate": [0.0, 0.0, 1.0, 1.0],
    },
    name="points",
    title="点样本",
)

mod = ConvexHullCenter(mname="HullCenter", by_xy=True)
mod.InputTable = table
mod.execute()

print(mod.OutputCenter.data)

快速上手示例:按经纬度计算凸包中心

from gdisdk.dataclass.tables import TableData
from gdisdk.modules.gisOperators import ConvexHullCenter

table = TableData(
    {
        "longitude": [118.78, 118.80, 118.79],
        "latitude": [32.04, 32.05, 32.06],
    }
)

mod = ConvexHullCenter(mname="HullCenterLonLat", by_xy=False)
mod.InputTable = table
out = mod.execute()

参数说明

ConvexHullCenter 参数一览

参数名

类型

默认值

说明

by_xy

bool

True

坐标来源选择:为 True 时从 x_coordinate / y_coordinate 计算;为 False 时从 longitude / latitude 计算。

x_column

str | None

None

自定义 X 坐标列名/列标题(仅 by_xy=True 时生效);为 None 时使用默认 x_coordinate

y_column

str | None

None

自定义 Y 坐标列名/列标题(仅 by_xy=True 时生效);为 None 时使用默认 y_coordinate

longitude_column

str | None

None

自定义经度列名/列标题(仅 by_xy=False 时生效);为 None 时使用默认 longitude

latitude_column

str | None

None

自定义纬度列名/列标题(仅 by_xy=False 时生效);为 None 时使用默认 latitude

Note

  • InputTable 为空(None 或空表),则 OutputCenter 输出 None

  • 输入表建议包含默认列名(x_coordinate/y_coordinatelongitude/latitude)。若你的表使用了字段元数据(title),也可以通过 “列标题” 等价访问这些字段(参见 端口类型 (Port Type) 中的 TableData 说明)。

  • 若你的点表列名并非默认约定,可用 x_column/y_columnlongitude_column/latitude_column 指定实际列名(或列标题),避免你在上游模块中手动改列名。

在 pipeline 中的使用方式

from gdisdk.pipeline.pipeline import PipeLine
from gdisdk.modules.readers import CsvReader
from gdisdk.modules.gisOperators import ConvexHullCenter

pipe = PipeLine(app_name="HullCenterDemo", app_title="计算凸包中心示例")

read_csv = CsvReader("ReadPoints")
read_csv.file = "points.csv"  # 需包含 x_coordinate/y_coordinate 或 longitude/latitude
read_csv.encoding = "auto"

center = ConvexHullCenter("Center", by_xy=True)

links = read_csv.OutputTable >> center.InputTable
pipe.add_links(links)
pipe.run()

out = center.OutputCenter

更多信息