AWS Redshift - 将 GeoJSON 加载到几何字段

问题描述

目前无法使用复制命令将 GeoJSON 直接加载到 redshift 几何列中,但已在以下位置建议了一种解决方法:-

Copying GeoJSON data from S3 to Redshift

这涉及作为 WKT 摄取,然后使用空间函数转换为几何图形,但是我不完全确定如何从 geojson 到 wkt - 我确定必须有一些转换器可用。

但这就是我对空间数据的有限理解的地方 - 假设我想将如下所示的天气 geojson 对象加载到红移表中。

如果我理解正确,FeatureCollection 中的每个 Feature 都将是表中的一行,仅将 json 几何字段的内容加载到 GEOMETRY 类型的字段中,即该字段不采用任何属性属性特征。然后将使用传统数据类型将属性加载到完全独立的字段中。然后,如果我想将该功能导出为 geojson,则必须再次将几何图形和属性缝合在一起。

正确吗?

或者 GEOMETRY 类型实际上具有存储属性和几何字段内容功能吗?

{
  "type": "FeatureCollection","features": [
      {
          "type": "Feature","id": "abcd1234","geometry": {
              "type": "Multipolygon","coordinates": [
                  [
                      [
                          [
                              7.51,48.04
                          ],[
                              8.12,48.05
                          ],[
                              8.19,47.95
                          ]
                      ]
                  ]
              ]
          },"geometry_name": "contour","properties": {
              "identifier": "abcd1234","analysisTime": "2019-04-06T14:15:00Z","convectionCellType": "CELL_BASE","speed": 3,"area": "MSG","phasetype": null,"top": 10363,"intensityValue": null,"ice": true,"created_at": "2020-07-21T12:01:25.651Z"
          }
      }
    ],"totalFeatures": 1,"numberMatched": 1,"numberReturned": 1,"timeStamp": "2021-02-03T16:39:48.963Z","crs": {
        "type": "name","properties": {
            "name": "urn:ogc:def:crs:epsg::4326"
        }
    }
  }

解决方法

我发现 this Gist 提供了以下 Python 代码片段来进行转换:

from shapely.geometry import shape

o = {
   "coordinates": [[[23.314208,37.768469],[24.039306,38.214372],[23.314208,37.768469]]],"type": "Polygon"
}
geom = shape(o)

# Now it's very easy to get a WKT/WKB representation
geom.wkt
geom.wkb