GeoJSON 格式

GeoJSON 格式定義在 RFC 7946中。

根據定義, GeoJSON 文件採用三種格式之一:
表 1. GeoJSON 格式
格式 範例
空間區域: 具有幾何佈置類型和座標的簡式幾何佈置,支援 OpenGIS 簡式特性實作所定義的類型 :Point、LineString、Polygon、MultiPoint、MultiLineString、MultiPolygon 和 GeometryCollection

{ "type": "Linestring", "coordinates": [[10.0, 11.2],
[10.5, 11.9]] }
空間有界限實體: 特性類型,它們是幾何佈置以及部分屬性; 類似於形狀檔,可包括形狀的屬性或 Placemarks 的 KML 資料夾

{ "type": "Feature", "geometry": { "type": "Point",
"coordinates": [10.0, 20.0] }, "properties": {
"signpost": "5", "last_check": "20200701" }
特性清單 :FeatureCollection

{ "type": "FeatureCollection", "features": [ { "type":
"Feature", "geometry": { "type": "Point",
"coordinates": [10.0, 5.0] }, }, { "type": "Feature",
"geometry": { "type": "LineString", "coordinates":
[[10.2, 1.0], [10.3, 2.0], [10.4, 2.5]] },
"properties": { "route": "341A7", "class": "local" } }
] }

GeoJSON 僅支援 WGS84(1984 年世界大地測量系統)。 這符合 Db2 Spatial Analytics 中的預設 srsid 4326。

使用 Db2 Spatial Analytics ,會套用下列對映,以從 GeoJSON 文件建構幾何佈置:
表 2. GeoJSON 至幾何佈置類型對映
名稱 目標類型 範例 備註
Point ST_Point 函數ST_Geometry 函數

{ "type": "point",
"coordinates": [ 10.0,
11.2 ] }
 
LineString ST_LineString 函數ST_Geometry 函數

{ "type": "Linestring",
"coordinates": [[10.0,
11.2], [10.5, 11.9]] }
 
Polygon ST_Polygon 函數ST_Geometry 函數

{ "type": "Polygon",
"coordinates": [[[10.0,
11.2], [10.5, 11.9],
[10.8, 12.0], [10.0,
11.2]]] }
可以有多個孔,即多個環。 線性環不需要遵循右側規則。
MultiPoint ST_MultiPoint 函數ST_Geometry 函數

{ "type": "MultiPoint",
"coordinates": [[10.0,
11.2], [10.5, 11.9]] )
 
MultiLineString ST_MultiLineString 函數ST_Geometry 函數

{ "type":
"MultiLinestring",
"coordinates": [[[10.0,
11.2], [10.5, 11.9]],
[[11.0, 12.2], [11.5,
12.9], [12.0, 13.0]] }
 
MultiPolygon ST_MultiPolygon 函數ST_Geometry 函數

{ "type":
"MultiPolygon",
"coordinates": [[[[10.0,
11.2], [10.5, 11.9],
[10.8, 12.0], [10.0,
11.2]]], [[[9.0, 11.2],
[10.5, 11.9], [10.3,
13.0], [9.0, 11.2]]]] }
 
GeometryCollection N/A

{ "type":
"GeometryCollection",
"geometries": [ {
"type": "Linestring",
"coordinates": [[10.0,
11.2], [10.5, 11.9]] },
{ "type": "Point",
"coordinates": [10.0,
20.0] } ] }
不支援巢狀集合或不同類型的集合。
bbox N/A   已略過。 將從座標計算外框值。
coordinates [longitude , latitude (,仰角)] (,) *

{ [1, 2] , [1, 2, 3] }
使用十進位值; 高度 (z 值) 是選用項目; 如果存在 4th 值,則會將它視為測量 m。
Feature 特性包含新增內容的單一幾何佈置物件。 因此,它會被視為如上述幾何類型所描述的。 內容元素以及 'id' 元素 (如果存在的話) 將被忽略。

{ "type": "Feature",
"geometry": { "type": "…",
"coordinates": […]
"properties": […] } }
 
FeatureCollection 一或多個特性。

{ "type":
"FeatureCollection",
"features": [ {"type":
"Feature", (…) }, {"type":
"Feature", (…) } ] }
特性不能是不同類型。
附註: 只要一般陣容在語法上有效,名稱/值配對的順序就不相關。 也就是說,例如, coordinates 元素是否列在 properties 元素之前或之後並不重要。

在 Db2 Spatial Analytics 中,將忽略名稱的大小寫。 例如, FeatureFEATUREfeature 都被接受。

如果幾何佈置類型定義遺漏 coordinates 物件,或 coordinates 物件是空的或空值,則會將幾何佈置視為空的幾何佈置。

FeatureCollection的限制:
  • 如果 FeatureCollection 包含多個點、多個線串或多個多邊形,則集合將儲存為相關聯的多重幾何形狀類型,前提是目標類型接受多重幾何形狀。
  • 將忽略不符合在 FeatureCollection 中找到的第一個幾何佈置類型的特性。 將針對此案例設定警告。