Cloud

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 POINT geographies. Multi-part geometries such as POLYGON, LINESTRING, and MULTIPOINT are not supported.

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:

  • geographytext: Returns EWKB hex string

  • textgeography: Parses WKT or EWKB string

  • geographygeometry: Removes SRID

  • geometrygeography: Adds SRID=4326

Casting between geography and point is not supported.

Functions

The following functions work with geography values:

Function Description Return type

st_astext(geography)

Returns the WKT representation

text

st_astext(geography, max_digits)

Returns the WKT representation with limited decimal digits

text

st_asewkt(geography)

Returns the Extended WKT representation (includes SRID)

text

st_asewkt(geography, max_digits)

Returns the Extended WKT representation with limited decimal digits

text

st_distance(geography, geography)

Returns the geodetic distance in meters using the WGS84 ellipsoid

double precision

st_distance(geography, geography, use_spheroid)

Returns the geodetic distance in meters. Set use_spheroid to false for a faster spherical approximation.

double precision

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