Skip to main content

Geometry Functions

This section describes the built-in functions for examining and manipulating GEOMETRY values.

Geometry Operators

The table below lists the operators that can be used with GEOMETRY values.

OperatorDescriptionExampleResult
&&Returns true if the geometries bounding boxes intersect. Equivalent to ST_IntersectsExtent.'POINT(5 5)'::GEOMETRY && 'LINESTRING(0 0, 10 20)'::GEOMETRYtrue

Built-in Geometry Functions

NameDescription
ST_GeomFromWKBCreates a geometry from Well-Known Binary (WKB) representation
ST_AsWKBReturns the Well-Known Binary (WKB) representation of the geometry
ST_AsWKTReturns the Well-Known Text (WKT) representation of the geometry
ST_Intersects_ExtentReturns true if the geometries bounding boxes intersect
ST_CRSReturns the Coordinate Reference System (CRS) identifier of the geometry
ST_SetCRSSets the Coordinate Reference System (CRS) identifier of the geometry

ST_GeomFromWKB function

Creates a geometry from Well-Known Binary (WKB) representation.

Query
SELECT ST_AsText(ST_GeomFromWKB('\x0101000000000000000000f03f0000000000000040'::BLOB)) AS geom;
Result
 geom------------- POINT (1 2)

ST_AsWKB function

Returns the Well-Known Binary (WKB) representation of the geometry. Alias: ST_AsBinary.

Query
SELECT ST_AsWKB('POINT(1 2)'::GEOMETRY) AS wkb;
Result
 wkb----------------------------------------------- \\x0101000000000000000000f03f0000000000000040

ST_AsWKT function

Returns the Well-Known Text (WKT) representation of the geometry. Alias: ST_AsText.

Query
SELECT ST_AsText('POINT(1 2)'::GEOMETRY) AS wkt;
Result
 wkt------------- POINT (1 2)

ST_Intersects_Extent function

Returns true if the geometries bounding boxes intersect. Alias: &&.

Query
SELECT ST_Intersects_Extent('POINT(5 5)'::GEOMETRY, 'LINESTRING(0 0, 10 20)'::GEOMETRY) AS intersects;
Result
 intersects------------ t

ST_CRS function

Returns the Coordinate Reference System (CRS) identifier of the geometry.

Query
SELECT ST_CRS('POINT(1 2)'::GEOMETRY('OGC:CRS84')) AS crs;
Result
 crs----------- OGC:CRS84

ST_SetCRS function

Sets the Coordinate Reference System (CRS) identifier of the geometry.

Query
SELECT typeof(ST_SetCRS('POINT(1 2)'::GEOMETRY, 'OGC:CRS84')) AS type;
Result
 type----------------------- GEOMETRY('OGC:CRS84')