geography
The geography data type stores geodetic (spherical) spatial point values using the WGS84 coordinate system (SRID 4326). Unlike geometry, which uses planar coordinates, geography interprets coordinates as longitude and latitude on the Earth’s surface, and distance calculations return results in meters.
|
Redpanda SQL supports only |
Format
geography values can be specified in the following formats:
-
WKT:
POINT(longitude latitude)(SRID defaults to 4326) -
EWKT:
SRID=4326;POINT(longitude latitude) -
EWKB: A hex-encoded binary string (50 hex characters, includes SRID)
SELECT GEOGRAPHY 'POINT(-73.9857 40.7484)';
SRID handling
geography always uses SRID 4326 (WGS84). If you specify a different SRID, an error is returned.
Casting
geography supports the following casts:
-
geography→text: Returns EWKB hex string -
text→geography: Parses WKT or EWKB string -
geography→geometry: Removes SRID -
geometry→geography: Adds SRID=4326
|
Casting between |
Functions
The following functions work with geography values:
| Function | Description | Return type |
|---|---|---|
|
Returns the WKT representation |
|
|
Returns the WKT representation with limited decimal digits |
|
|
Returns the Extended WKT representation (includes SRID) |
|
|
Returns the Extended WKT representation with limited decimal digits |
|
|
Returns the geodetic distance in meters using the WGS84 ellipsoid |
|
|
Returns the geodetic distance in meters. Set |
|
Examples
Calculate the distance in meters between two geographic points (New York City and London):
SELECT ST_DISTANCE(
GEOGRAPHY 'POINT(-73.9857 40.7484)',
GEOGRAPHY 'POINT(-0.1278 51.5074)'
) AS distance_meters;
distance_meters
-------------------
5570222.179854498