Purpose
The GeoJSONFromGeom function converts an ST_Geometry object into a JSON document that conforms to the GeoJSON standards.
Syntax
If you specify a RETURNS clause, you must enclose the function call in parenthesis.
Syntax Elements
- TD_SYSFNLIB
- The name of the database where the function is located.
- geom_expr
- An expression which evaluates to an ST_Geometry object that represents a Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, or GeometryCollection.
- precision
- An integer specifying the maximum number of decimal places in the coordinate values.
- RETURNS data_type
- Specifies that data_type is the return type of the function.
- integer
- Specifies the maximum length of the return type.
- CHARACTER SET
- The character set for the return value of the function, which can be LATIN or UNICODE.
- RETURNS STYLE column_expr
- Specifies that the return type of the function is the same as the data type of the specified column. The data type of the column must be VARCHAR, CLOB, or JSON.
Return Value
The result of this function is a JSON document which has a format that conforms to the GeoJSON standards as specified in http://geojson.org/geojson-spec.html.
If you do not specify a RETURNS clause, the default return type is JSON with UNICODE as the character set. The length of the return value is 64000 bytes, which supports up to 32000 UNICODE characters. This can result in a failure if the underlying ST_Geometry object exceeds 64000 bytes when converted to a GeoJSON value.
The usual rules apply for the maximum length of each data type.
Data Type | Character Set | Maximum Length (characters) |
---|---|---|
VARCHAR | LATIN | 64000 |
UNICODE | 32000 | |
CLOB | LATIN | 2097088000 |
UNICODE | 1048544000 | |
JSON | LATIN | 16776192 |
UNICODE | 8388096 |
Usage Notes
The GeoJSONFromGeom and GeomFromGeoJSON functions operate on or produce data in the JSON text format. They cannot be used on JSON data that is stored in one of the binary formats. However, JSON data stored in a binary format can be cast to/from its text representation to interact with these functions. The casting can be done implicitly, so little effort is needed to perform this operation.
ANSI Compliance
This function is not compliant with the ANSI SQL:2011 standard.