geometry
The geometry data type stores planar (Cartesian) spatial point values as two double-precision coordinates. It uses Well-Known Text (WKT) and Well-Known Binary (WKB) formats for input and output.
|
Redpanda SQL supports only |
Format
geometry values can be specified in the following formats:
-
WKT:
POINT(x y)(space-separated coordinates) -
EWKT:
SRID=4326;POINT(x y)(SRID is accepted but ignored forgeometry) -
EWKB: A hex-encoded binary string (42 hex characters)
SELECT GEOMETRY 'POINT(0.1234 5.6789)';
Differences between geometry and geography
geometry |
geography |
|---|---|
Uses a Cartesian (planar) coordinate system |
Uses a geodetic (spherical) coordinate system |
SRID is ignored |
SRID is always 4326 (WGS84) |
|
|
Casting
geometry supports the following casts:
-
geometry→text: Returns WKB hex string -
text→geometry: Parses WKT or EWKB string -
geometry→geography: Adds SRID=4326 -
geography→geometry: Removes SRID -
geometry→point: Converts to(x,y)format -
point→geometry: Converts to WKB format
Functions
The following functions work with geometry values:
| Function | Description | Return type |
|---|---|---|
|
Returns the WKT representation of the geometry |
|
|
Returns the WKT representation with limited decimal digits |
|
|
Returns the Extended WKT representation |
|
|
Returns the Extended WKT representation with limited decimal digits |
|
|
Returns the Euclidean distance between two |
|
Examples
SELECT
ST_ASTEXT(GEOMETRY 'POINT(1.5 2.5)') AS wkt,
ST_DISTANCE(
GEOMETRY 'POINT(0 0)',
GEOMETRY 'POINT(3 4)'
) AS distance;
wkt | distance
----------------+----------
POINT(1.5 2.5) | 5