Geographical
| Name | Description | Example |
|---|---|---|
| earth_distance | Returns the orthodromic distance between two points (given as their latitude and longitude in degrees) in meters | |
| geo_polygon | Creates a spherical polygon represented by points with geographical coordinates | |
| geo_radius | Creates a spherical cap represented by a center with geographical coordinates and a radius in km |
Geographical functions geo_polygon and geo_radius construct geographical values, on which queries for testing geographic containment may be applied. For a detailed description and examples of usage, see the Geographical Containment section.
Earth Distance
Returns the orthodromic distance in meters between two points specified by their latitude and longitude in degrees.
Definition
| Argument | Type | Meaning |
|---|---|---|
lat1 |
| Latitude of the first point in degrees |
lon1 |
| Longitude of the first point in degrees |
lat2 |
| Latitude of the second point in degrees |
lon2 |
| Longitude of the second point in degrees |
Example
All the following expressions result in true:
Geographical Point
To specify a point with geographical coordinates, use an array of length two, which contains number values latitude and longitude as its elements, respectively:
Geographical Polygon
Creates a spherical polygon represented by points with geographical coordinates, on which queries of testing for geographical containment may be applied.
Definition
| Argument | Type | Meaning |
|---|---|---|
polygon points |
| The boundary of the polygon |
strict |
| Optional. Boolean specifying if any non-valid polygon results in an error. Default if not provided: |
- A polygon is specified as an array of geographical coordinates of at least 3 points
- The points of a polygon can be specified in both CW and CCW orders
- The interior of a polygon is such that the polygon encloses at most half of the sphere (from two possible interpretations of a polygon, the one with the smaller area is considered). The interior does not include the boundary, except for the points
To avoid ambiguity of the requests, the following requirements should be kept:
- No two points of a polygon may share coordinates (the first and the last point are presumed to be connected automatically),
- Edges of a polygon may not cross anywhere but in the points
By default, if any of the requirements above are not fulfilled, the geo containment query will be handled on a best-effort basis.
Should you want to enable strict checking, set the boolean parameter strict to true. In that case, any failure to comply with the requirements will result in an error.
Example
Geographical Radius
Creates a spherical cap represented by a center point with geographical coordinates and a radius in km, on which queries of testing for geographical containment may be applied.
Definition
| Argument | Type | Meaning |
|---|---|---|
center point | Coordinates of the center of the | |
radius |
| Length of the |
Everything that is within the orthodromic distance of a given radius to the center point is contained within the geo_radius (inclusively).
Nothing is contained within a geo_radius with a negative radius, and everything is contained within a geo_radius with a radius larger than half of the Earth Equator’s length.
Example
Geographical Containment
Geographical values geo_polygon and geo_radius support the in operator for checking containtment of a geographical point. The result of the operator is truthy if the point is contained within the given geographical value. The syntax of such a query is: point in geographical value.
Examples
All the following expressions result in true: