例: 有効なGeoJSONジオメトリ オブジェクト
次に、有効なGeoJSONジオメトリ オブジェクトの例を示します。これらのオブジェクトはGeoJSON形式の仕様に基づく有効なものです。この仕様については、https://tools.ietf.org/html/rfc7946からアクセスできます。
Point
{ "type": "Point", "coordinates": [100.0, 0.0] }
LineString
{ "type": "LineString",
"coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
}
Polygon(穴なし)
{ "type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]
}
Polygon(穴あり)
{ "type": "Polygon",
"coordinates": [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
[ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
]
}
MultiPoint
{ "type": "MultiPoint",
"coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
}
MultiLineString
{ "type": "MultiLineString",
"coordinates": [
[ [100.0, 0.0], [101.0, 1.0] ],
[ [102.0, 2.0], [103.0, 3.0] ]
]
}
MultiPolygon
{ "type": "MultiPolygon",
"coordinates": [
[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
[[ 100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
]
}
GeometryCollection
{ "type": "GeometryCollection",
"geometries": [
{ "type": "Point",
"coordinates": [100.0, 0.0]
},
{ "type": "LineString",
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
}
]
}
例: GeoJSON値をST_Geometryオブジェクトに変換
SELECT GeomFromGeoJSON('{ "type": "Point", "coordinates": [100.0, 0.0] }', 4326);
結果:
Result ------ POINT (100 0)
例: エラー - GeoJSONに準拠しないJSON値を渡す処理
この例では、"Poit"が有効なJSONジオメトリ データではないためエラーが返されます。
SELECT GeomFromGeoJSON('{ "type": "Poit", "coordinates": [100.0, 0.0] }', 4326);
結果: クエリーはエラーを返します。
*** Failure 9134 GeomFromGeoJSON: conversion from JSON text failed, invalid GeoJSON input.
Statement# 1, Info =0