A geometry format conversion function is used to convert geometry values in an internal geometry format into values in the well-known text (WKT) or well-known binary (WKB) format, or to change the sequence of X and Y coordinates. OceanBase Database supports the following geometry 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 geometry format to their WKB representations and return binary results. The syntax is as follows:
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 geometry 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 geometry format to their WKT representations and return string results. The syntax is as follows:
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 geometry 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
Considerations for parameters
The return value for a geometry argument in a geometry format conversion function is non-NULL, except in the following cases:
- If any geometry argument is in an incorrect syntax format, the
ER_GIS_INVALID_DATAerror is returned. - If any geometry 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 geometry 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.