地理网格处理器编辑

将网格瓦片或单元格的地理网格定义转换为描述其形状的常规边界框或多边形。如果需要将瓦片形状作为空间可索引字段进行交互,这将很有用。例如,geotile 字段值 "4/8/3" 可以被索引为字符串字段,但这不会启用任何空间操作。相反,将其转换为值 "POLYGON ((0.0 40.979898069620134, 22.5 40.979898069620134, 22.5 55.77657301866769, 0.0 55.77657301866769, 0.0 40.979898069620134))",它可以被索引为 geo_shape 字段。

表 21. geo_grid 处理器选项

名称 必需 默认值 描述

field

-

要解释为地理瓦片的字段。字段格式由 tile_type 确定。

tile_type

-

理解三种瓦片格式:geohashgeotilegeohex

target_field

field

要将多边形形状分配到的字段,默认情况下 field 会就地更新。

parent_field

-

如果指定且存在父瓦片,则将该瓦片地址保存到此字段。

children_field

-

如果指定且存在子瓦片,则将这些瓦片地址保存到此字段,作为字符串数组。

non_children_field

-

如果指定且存在相交的非子瓦片,则将其地址保存到此字段,作为字符串数组。

precision_field

-

如果指定,则将瓦片精度(缩放)保存为整数到此字段。

ignore_missing

-

如果 truefield 不存在,则处理器会静默退出,不会修改文档。

target_format

"GeoJSON"

保存生成的 polygon 的格式。可以是 WKTGeoJSON

description

-

处理器的描述。用于描述处理器的目的或其配置。

if

-

有条件地执行处理器。请参阅 有条件地运行处理器

ignore_failure

false

忽略处理器的失败。请参阅 处理管道故障

on_failure

-

处理处理器的失败。请参阅 处理管道故障

tag

-

处理器的标识符。用于调试和指标。

为了演示此摄取处理器的用法,请考虑一个名为 geocells 的索引,其中包含一个类型为 geo_shape 的字段 geocell 的映射。为了使用 geotilegeohex 字段填充该索引,请定义两个摄取处理器

response = client.indices.create(
  index: 'geocells',
  body: {
    mappings: {
      properties: {
        geocell: {
          type: 'geo_shape'
        }
      }
    }
  }
)
puts response

response = client.ingest.put_pipeline(
  id: 'geotile2shape',
  body: {
    description: 'translate rectangular z/x/y geotile to bounding box',
    processors: [
      {
        geo_grid: {
          field: 'geocell',
          tile_type: 'geotile'
        }
      }
    ]
  }
)
puts response

response = client.ingest.put_pipeline(
  id: 'geohex2shape',
  body: {
    description: 'translate H3 cell to polygon',
    processors: [
      {
        geo_grid: {
          field: 'geocell',
          tile_type: 'geohex',
          target_format: 'wkt'
        }
      }
    ]
  }
)
puts response
PUT geocells
{
  "mappings": {
    "properties": {
      "geocell": {
        "type": "geo_shape"
      }
    }
  }
}

PUT _ingest/pipeline/geotile2shape
{
  "description": "translate rectangular z/x/y geotile to bounding box",
  "processors": [
    {
      "geo_grid": {
        "field": "geocell",
        "tile_type": "geotile"
      }
    }
  ]
}

PUT _ingest/pipeline/geohex2shape
{
  "description": "translate H3 cell to polygon",
  "processors": [
    {
      "geo_grid": {
        "field": "geocell",
        "tile_type": "geohex",
        "target_format": "wkt"
      }
    }
  ]
}

这两个管道可用于将文档索引到 geocells 索引中。 geocell 字段将是格式为 z/x/y 的矩形瓦片或 H3 单元格地址的字符串版本,具体取决于我们在索引文档时使用哪个摄取处理器。生成的几何图形将以 geo_shape 字段的形式表示和索引,以 GeoJSONWell-Known Text 格式。

示例:带有 GeoJSON 中的包络的矩形地理瓦片编辑

在此示例中,具有以 z/x/y 格式定义的值的 geocell 字段被索引为 GeoJSON 包络,因为上面的摄取处理器是使用默认的 target_format 定义的。

response = client.index(
  index: 'geocells',
  id: 1,
  pipeline: 'geotile2shape',
  body: {
    geocell: '4/8/5'
  }
)
puts response

response = client.get(
  index: 'geocells',
  id: 1
)
puts response
PUT geocells/_doc/1?pipeline=geotile2shape
{
  "geocell": "4/8/5"
}

GET geocells/_doc/1

响应显示了摄取处理器如何将 geocell 字段替换为可索引的 geo_shape

{
 "_index": "geocells",
  "_id": "1",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "found": true,
  "_source": {
    "geocell": {
      "type": "Envelope",
      "coordinates": [
        [ 0.0, 55.77657301866769 ],
        [ 22.5, 40.979898069620134 ]
      ]
    }
  }
}

Kibana map with showing the geotile at 4/8/5 and its four child cells

示例:带有 WKT 格式的多边形的六边形地理六边形编辑

在此示例中,具有 H3 字符串地址的 geocell 字段被索引为 WKT 多边形,因为此摄取处理器明确定义了 target_format

response = client.index(
  index: 'geocells',
  id: 1,
  pipeline: 'geohex2shape',
  body: {
    geocell: '811fbffffffffff'
  }
)
puts response

response = client.get(
  index: 'geocells',
  id: 1
)
puts response
PUT geocells/_doc/1?pipeline=geohex2shape
{
  "geocell": "811fbffffffffff"
}

GET geocells/_doc/1

响应显示了摄取处理器如何将 geocell 字段替换为可索引的 geo_shape

{
 "_index": "geocells",
  "_id": "1",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "found": true,
  "_source": {
    "geocell": "POLYGON ((1.1885095294564962 49.470279179513454, 2.0265689212828875 45.18424864858389, 7.509948452934623 43.786609335802495, 12.6773177459836 46.40695743262768, 12.345747342333198 50.55427505169064, 6.259687012061477 51.964770150370896, 3.6300085578113794 50.610463307239115, 1.1885095294564962 49.470279179513454))"
  }
}

Kibana map with showing an H3 cell

示例:丰富的瓦片详细信息编辑

geo_grid 处理器选项 中所述,还有许多其他字段可以设置,这些字段将丰富可用的信息。例如,对于 H3 瓦片,有 7 个子瓦片,但只有第一个完全包含在父瓦片中。其余六个仅部分与父瓦片重叠,并且存在另外六个非子瓦片与父瓦片重叠。这可以通过将父级和子级附加字段添加到摄取处理器来进行调查

response = client.ingest.put_pipeline(
  id: 'geohex2shape',
  body: {
    description: 'translate H3 cell to polygon with enriched fields',
    processors: [
      {
        geo_grid: {
          description: "Ingest H3 cells like '811fbffffffffff' and create polygons",
          field: 'geocell',
          tile_type: 'geohex',
          target_format: 'wkt',
          target_field: 'shape',
          parent_field: 'parent',
          children_field: 'children',
          non_children_field: 'nonChildren',
          precision_field: 'precision'
        }
      }
    ]
  }
)
puts response
PUT _ingest/pipeline/geohex2shape
{
  "description": "translate H3 cell to polygon with enriched fields",
  "processors": [
    {
      "geo_grid": {
        "description": "Ingest H3 cells like '811fbffffffffff' and create polygons",
        "field": "geocell",
        "tile_type": "geohex",
        "target_format": "wkt",
        "target_field": "shape",
        "parent_field": "parent",
        "children_field": "children",
        "non_children_field": "nonChildren",
        "precision_field": "precision"
      }
    }
  ]
}

索引文档以查看不同的结果

response = client.index(
  index: 'geocells',
  id: 1,
  pipeline: 'geohex2shape',
  body: {
    geocell: '811fbffffffffff'
  }
)
puts response

response = client.get(
  index: 'geocells',
  id: 1
)
puts response
PUT geocells/_doc/1?pipeline=geohex2shape
{
  "geocell": "811fbffffffffff"
}

GET geocells/_doc/1

此索引请求的响应

{
  "_index": "geocells",
  "_id": "1",
  "_version": 1,
  "_seq_no": 0,
  "_primary_term": 1,
  "found": true,
  "_source": {
    "parent": "801ffffffffffff",
    "geocell": "811fbffffffffff",
    "precision": 1,
    "shape": "POLYGON ((1.1885095294564962 49.470279179513454, 2.0265689212828875 45.18424864858389, 7.509948452934623 43.786609335802495, 12.6773177459836 46.40695743262768, 12.345747342333198 50.55427505169064, 6.259687012061477 51.964770150370896, 3.6300085578113794 50.610463307239115, 1.1885095294564962 49.470279179513454))",
    "children": [
      "821f87fffffffff",
      "821f8ffffffffff",
      "821f97fffffffff",
      "821f9ffffffffff",
      "821fa7fffffffff",
      "821faffffffffff",
      "821fb7fffffffff"
    ],
    "nonChildren": [
      "821ea7fffffffff",
      "82186ffffffffff",
      "82396ffffffffff",
      "821f17fffffffff",
      "821e37fffffffff",
      "82194ffffffffff"
    ]
  }
}

然后,这些附加信息将使您能够例如创建 H3 单元格、其子单元格及其相交的非子单元格的可视化。

Kibana map with three H3 layers: cell