Skip to content

ST_GEOGFROMGEOJSON

Constructs a GEOGRAPHY object from GeoJSON Geometry Object.

See also:

Syntax

sql
ST_GEOGFROMGEOJSON(<input>)

Arguments

  • <input>: A JSONB containing GeoJSON geometry

Returns

Returns a GEOGRAPHY object representing the input GeoJSON geometry

Examples

sql
SELECT ST_GEOGFROMGEOJSON('{"type":"Point","coordinates":[1,1]}');
-- POINT(1 1)

SELECT '
{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}
'::JSONB:$.geometry::GEOGRAPHY;
-- POINT(125.6 10.1)

SELECT feature:$.geometry::GEOGRAPHY
FROM FLATTEN(
    '
{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [102.0, 0.5]
        },
        "properties": {
            "prop0": "value0"
        }
    }, {
        "type": "Feature",
        "geometry": {
            "type": "LineString",
            "coordinates": [
                [102.0, 0.0],
                [103.0, 1.0],
                [104.0, 0.0],
                [105.0, 1.0]
            ]
        },
        "properties": {
            "prop0": "value0",
            "prop1": 0.0
        }
    }]
}
    ':$.features, $.value AS feature
) AS f;
              geometry
-------------------------------------
 POINT(102 0.5)
 LINESTRING(102 0,103 1,104 0,105 1)
(2 rows)

Note: This function is equivalent to casting JSONB to GEOGRAPHY using the ::GEOGRAPHY syntax.