The ST_GeometryType() function
The ST_GeometryType() function takes an ST_Geometry object and returns its geometry type as a string.
Syntax
ST_GeometryType (g1 ST_Geometry)
Return type
VARCHAR(32) containing one of
the following text strings:
st_point
st_linestring
st_polygon
st_multipoint
st_multilinestring
st_multipolygon
Example
The geometrytype_test table
contains the g1 ST_Geometry column:
CREATE TABLE geometrytype_test(g1 ST_Geometry);
The
following INSERT statements insert each geometry subclass into the g1 column:
INSERT INTO geometrytype_test VALUES(
ST_GeomFromText('point (10.02 20.01)',1000)
);
INSERT INTO geometryType_test VALUES(
ST_GeomFromText('linestring (10.01 20.01, 10.01 30.01, 10.01 40.01)', 1000)
);
INSERT INTO geometrytype_test VALUES(
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 geometrytype_test VALUES(
ST_GeomFromText('multipoint (10.02 20.01,10.32 23.98,11.92 25.64)', 1000)
);
INSERT INTO geometrytype_test VALUES(
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 geometrytype_test VALUES(
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)
);
The following query lists the geometry type of
each subclass stored in the g1 geometry column:
SELECT ST_GeometryType(g1) Geometry_type
FROM geometrytype_test;
geometry_type st_point
geometry_type st_linestring
geometry_type st_polygon
geometry_type st_multipoint
geometry_type st_multilinestring
geometry_type st_multipolygon