The ST_GeomFromText() function
The ST_GeomFromText() function takes a well-known text representation and a spatial reference ID and returns a geometry object.
Syntax
ST_GeomFromText(wkt lvarchar, SRID integer)
Return type
ST_Geometry
Example
The geometry_test table contains
the INTEGER gid column, which uniquely identifies each row,
and the g1 column, which stores the geometry:
CREATE TABLE geometry_test (gid smallint,
g1 ST_Geometry);
The
following INSERT statements insert the data into the gid and g1 columns
of the geometry_test table. The ST_GeomFromText() function
converts the text representation of each geometry into its corresponding
instantiable subclass:
INSERT INTO geometry_test VALUES(
1,
ST_GeomFromText('point (10.02 20.01)',1000)
);
INSERT INTO geometry_test VALUES(
2,
ST_GeomFromText('linestring (10.01 20.01, 10.01 30.01, 10.01 40.01)',1000)
);
INSERT INTO geometry_test VALUES(
3,
ST_GeomFromText('polygon ((10.02 20.01, 11.92 35.64, 25.02
34.15, 19.15 33.94, 10.02 20.01))',1000)
);
INSERT INTO geometry_test VALUES(
4,
ST_GeomFromText('multipoint (10.02 20.01,10.32 23.98,11.92 25.64)',1000)
);
INSERT INTO geometry_test VALUES(
5,
ST_GeomFromText('multilinestring ((10.02 20.01, 10.32 23.98,
11.92 25.64),(9.55 23.75,15.36 30.11))',1000)
);
INSERT INTO geometry_test VALUES(
6,
ST_GeomFromText('multipolygon (((10.02 20.01, 11.92 35.64,
25.02 34.15, 19.15 33.94, 10.02 20.01)),((51.71 21.73, 73.36
27.04, 71.52 32.87, 52.43 31.90, 51.71 21.73)))',1000)
);