ST_PointFromText function
The ST_PointFromText function takes a well-known text (WKT) format or a GeoJSON format of a point and, optionally, a spatial reference system identifier as input parameters and returns the corresponding point.
- A WKT format
- GeoJSON format
The recommended function for achieving the same result is the ST_Point function. It is recommended because of its flexibility: ST_Point takes additional forms of input as well as the WKT or GeoJSON formats.
If the specified WKT or GeoJSON format is null, then null is returned.
For details about the supported formats, see Supported data formats.
Syntax
Parameters
- wkt
- A value of type VARCHAR or CLOB(2G) that contains the WKT format of the resulting point.
- geojson
- A value of type VARCHAR or CLOB(2G) that represents the resulting point using GeoJSON.
- srs_id
- A value of type INTEGER that identifies the spatial reference system for the resulting point.
If the srs_id parameter is omitted, the spatial reference system with the numeric identifier 4326 is used.
If srs_id does not identify a spatial reference system listed in the catalog view SYSGEO.ST_SPATIAL_REFERENCE_SYSTEMS, then an exception condition is raised (SQLSTATE 38SU1).
Return type
ST_Point
Examples
- Example 1:
-
This example illustrates how ST_PointFromText can be used to create and insert a point from its well-known text representation. The record that is inserted has ID = 1110, and the geometry is a point in spatial reference system 1. The point is in the WKT format of a point. The X and Y coordinates for this geometry are: (30, 40).
The following SELECT statement returns the polygon that was recorded in the table:CREATE TABLE sample_points (id INTEGER, geometry ST_Point) INSERT INTO sample_points VALUES (1110, ST_PointFromText ('point (30 40)', 1) )
Results:SELECT id, CAST( ST_AsText( geometry ) AS VARCHAR(35) ) POINTS FROM sample_points WHERE id = 1110
ID POINTS ----------- --------------------------------------- 1110 POINT (30.000000 40.000000)
- Example 2:
-
This example illustrates how ST_PointFromText can be used to create and insert a point from its GeoJSON representation using the geometry data from Example 1.
The record that is inserted has ID = 1111, and the geometry is a point in spatial reference system 4326 (the default). The point is in the GeoJSON format of a point.CREATE TABLE sample_points (id INTEGER, geometry ST_Point) INSERT INTO sample_points VALUES (1111, ST_PointFromText ('{ "type": "point", "coordinates": [30, 40] }') )
The following SELECT statement returns the polygon that was recorded in the table:SELECT id, CAST( ST_AsText( geometry ) AS VARCHAR(35) ) POINTS FROM sample_points WHERE id = 1111
Results:ID POINTS ----------- --------------------------------------- 1111 POINT (30.000000000 40.000000000)