Examples: GeomFromGeoJSON

Teradata Vantageā„¢ JSON Data Type

prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1150-162K

Examples: Valid GeoJSON Geometry Objects

The following show examples of valid GeoJSON geometry objects. The objects are valid based on the GeoJSON format specification which you can access at: 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 (without Holes)

{ "type": "Polygon",
  "coordinates": [
    [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
  ]
}

Polygon (with Holes)

{ "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] ]
      }
  ]
}

Example: Converting a GeoJSON Value into an ST_Geometry Object

SELECT GeomFromGeoJSON('{ "type": "Point", "coordinates": [100.0, 0.0] }', 4326);

Result:

Result
------
POINT (100 0)

Example: Error - Passing a JSON Value That Is Not GeoJSON Compliant

In this example, an error is returned because "Poit" is not valid JSON geometry data.

SELECT GeomFromGeoJSON('{ "type": "Poit", "coordinates": [100.0, 0.0] }', 4326);

Result: The query returns an error.

*** Failure 9134 GeomFromGeoJSON: conversion from JSON text failed, invalid GeoJSON input.
                Statement# 1, Info =0