ST_Distance(g1,g2)

Calculates the shortest distance between two spatial objects.The distance is measured in degrees.

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

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)) < small.radius;

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)) < 0.0005;

Note that this will return a distance in degrees.

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.