gs_great_circle_distance_within(lon1,lat1,lon2,lat2,dist)
Returns 1 (true)
if the two spatial objects are within the specified distance of one another.
Parameters
Parameter | Type | Description |
---|---|---|
lon1 |
longitude |
A longitude defined in coordinates in decimal degrees (in WGS84) |
lat1 |
latitude |
A latitude defined in coordinates in decimal degrees (in WGS84) |
lon2 |
longitude |
A longitude defined in coordinates in decimal degrees (in WGS84) |
lat2 |
latitude |
A latitude defined in coordinates in decimal degrees (in WGS84) |
dist |
double |
The distance (in meters) that the points should be within each other |
Returns
boolean
Example
SELECT *
FROM geospock.default.events event
JOIN geospock.default.pois poi
ON gs_great_circle_distance_within(poi.longitude, poi.latitude, event.longitude, event.latitude, 10);
Usage
To define a geofence using GS_great_circle_distance_within()
, your query will look like this:
SELECT *
FROM geospock.default.events event
JOIN geospock.default.pois poi
ON gs_great_circle_distance_within(poi.longitude, poi.latitude, event.longitude, event.latitude, 10);
Note that this will return a distance in meters.
Note that this query uses the GeoSpock custom function gs_great_circle_distance_within
which has been optimized to run spatial join queries based on the distance (in meters) between two points using spherical geography.
Alternatively, you could use the other optimized spatial join function, GS_Distance_Within()
, instead:
SELECT *
FROM geospock.default.events event
JOIN geospock.default.pois poi
ON GS_Distance_Within(to_spherical_geography(ST_Point(poi.longitude, poi.latitude)), to_spherical_geography(ST_Point(event.longitude, event.latitude)), 10);
See GS_Distance_Within(sg1,sg2,dist) for more information.