geo.ST_Distance() function

The geo.ST_Distance() function is experimental and subject to change at any time. By using this function, you accept the risks of experimental functions.

The geo.ST_Distance() function returns the distance between the specified region and specified geographic information system (GIS) geometry. Define distance units with the geo.units option.

Function type: Transformation

import "experimental/geo"

  region: {lat: 40.7, lon: -73.3, radius: 20.0},
  geometry: {lon: 39.7515, lat: 15.08433}

// Returns 10734.184618677662 (km)



The region to test. Specify record properties for the shape. See Region definitions.

Data type: Record


The GIS geometry to test. Can be either point or linestring geometry. See GIS geometry definitions.

Data type: Record


Calculate the distance between geographic points and a region
import "experimental/geo"

region = {
  minLat: 40.51757813,
  maxLat: 40.86914063,
  minLon: -73.65234375,
  maxLon: -72.94921875

  |> geo.toRows()
  |> map(fn: (r) => ({
    r with st_distance: ST_Distance(region: region, geometry: {lat:, lon: r.lon})
Find the point nearest to a geographic location
import "experimental/geo"

fixedLocation = {lat: 40.7, lon: -73.3}

  |> geo.toRows()
  |> map(fn: (r) => ({ r with
    _value: geo.ST_Distance(region: {lat:, lon: r.lon}, geometry: fixedLocation)
  |> min()

Cloud or OSS?

InfluxDB OSS 2.0 now generally available!

InfluxDB OSS 2.0 is now generally available and ready for production use. See the InfluxDB OSS 2.0 release notes.

For information about upgrading to InfluxDB OSS 2.0, see: