GeomFromGeoJSON Function Examples | Teradata Vantage - GeomFromGeoJSON Examples - Advanced SQL Engine - Teradata Database

JSON Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
gzn1554761068186.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1150
lifecycle
previous
Product Category
Teradata Vantageā„¢

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