A geometric format conversion function is used to convert geometric values in an internal geometric format into values in the WKT or WKB format, or to change the sequence of X and Y coordinates. OceanBase Database supports the following geometric format conversion functions in the current version: ST_AsBinary(), ST_AsWKB, ST_AsText(), and ST_AsWKT().
ST_AsBinary and ST_AsWKB
The ST_AsBinary() and ST_AsWKB() functions convert values in an internal geometric format to their WKB representations and return binary results. Syntax:
ST_AsBinary(g [, options]), ST_AsWKB(g [, options])
A return value of the functions has geographic coordinates (latitude and longitude) in the sequence specified by the spatial reference system (SRS) that is applied to the geometric arguments. You can specify the optional options argument to override the default sequence of axes.
SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@geo, 'axis-order=long-lat')));
ST_AsText and ST_AsWKT
The ST_AsText() and ST_AsWKT() functions convert values in an internal geometric format to their WKT representations and return string results. Syntax:
ST_AsText(g [, options]), ST_AsWKT(g [, options])
A return value of the functions has geographic coordinates (latitude and longitude) in the sequence specified by the spatial reference system (SRS) that is applied to the geometric arguments. You can specify the optional options argument to override the default sequence of axes.
obclient [test]> SET @geo = 'LINESTRING(0 6,6 12,12 18)';
Query OK, 0 rows affected
obclient [test]> SELECT ST_AsText(ST_GeomFromText(@geo));
+----------------------------------+
| ST_AsText(ST_GeomFromText(@geo)) |
+----------------------------------+
| LINESTRING(0 6,6 12,12 18) |
+----------------------------------+
1 row in set
Notes
The return value for a geometric argument in a geometric format conversion function is non-NULL, except in the following cases:
- If any geometric argument is in an incorrect syntax format, the
ER_GIS_INVALID_DATAerror is returned. - If any geometric argument is in an undefined SRS, the axes are output in the sequence in which they appear in the geometry, and the
ER_WARN_SRS_NOT_FOUND_AXIS_ORDERalert is returned. - By default, the geographic coordinates (latitude and longitude) are resolved in the sequence specified by the SRS of the geometric argument. You can specify the optional
optionsargument to override the default sequence of axes.optionsconsists of a comma-separated list ofkey=valuepairs.keycan only be set toaxis-order, andvaluecan belat-long,long-lat, orsrid-defined(default). IfoptionsisNULL, the return value isNULL. If theoptionsargument is invalid, an error is reported.