ST_Distance

ST_Distance(g1,g2)

Calculates the shortest distance between two spatial objects. Note that this will return a distance in degrees. To obtain an accurate distance in meters, the to_spherical_geography() function should be used as described in the Presto documentation.

Parameters

Parameter Type Description
g1 Geometry The spatial location of the first location defined using the WKT notation
g2 Geometry The spatial location of the second location defined using the WKT notation

Returns

double - The degrees of arc

Usage

To define a geofence using ST_Distance(), your query will look like this:

SELECT *
FROM geospock.default.largetable AS large,
geospock.default.smalltable AS small
WHERE ST_Distance(ST_Point(small.longitude, small.latitude), ST_Point(large.longitude, large.latitude)) < small.radius;

Example

SELECT *
FROM geospock.default.largetable AS large,
geospock.default.smalltable AS small
WHERE ST_Distance(ST_Point(small.longitude, small.latitude), ST_Point(large.longitude, large.latitude)) < 0.0005;

If you are using a Hive table to provide the locations of the POIs, the relevant fields in that able must be named latitude and longitude in order for the optimization to take place. In addition, the fields must be of type double, decimal or float/real.