MarkLogic 12 EA 1 Product Documentation
geo.distance

geo.distance(
   p1 as cts.point,
   p2 as cts.point,
   [options as String[]]
) as Number

Summary

Returns the distance (in units) between two points.

Parameters
p1 The first point.
p2 The second point.
options Options for the operation. The default is ().

Options include:

"coordinate-system=string"
Use the given coordinate system. Valid values are:
wgs84
The WGS84 coordinate system with degrees as the angular unit.
wgs84/radians
The WGS84 coordinate system with radians as the angular unit.
wgs84/double
The WGS84 coordinate system at double precision with degrees as the angular unit.
wgs84/radians/double
The WGS84 coordinate system at double precision with radians as the angular unit.
etrs89
The ETRS89 coordinate system.
etrs89/double
The ETRS89 coordinate system at double precision.
raw
The raw (unmapped) coordinate system.
raw/double
The raw coordinate system at double precision.
"precision=value"
Use the coordinate system at the given precision. Allowed values: float and double.
"units=value"
Measure distance and the radii of circles in the specified units. Allowed values: miles (default), km, feet, meters.

Usage Notes

The value of the precision option takes precedence over that implied by the governing coordinate system name, including the value of the coordinate-system option. For example, if the governing coordinate system is "wgs84/double" and the precision option is "float", then the operation uses single precision.

See Also

Example

const sf = cts.point(37, -122);
const ny = cts.point(40, -73);
geo.distance(sf, ny);

=> 2623.2017796533

Example

// Optic example using the Value Processing Function op.geo.distance()
const op = require('/MarkLogic/optic');
const result=op.fromView('buildings', 'builds')
               .bindAs('result',op.geo.distance(op.col('interiorPoint'),cts.point('POINT(-98.83211485551952 36.1919336424082)'),'units=miles'))
               .select(['result', op.col('interiorPoint')])
               .orderBy('result')
               .result()
result;
// ==>
// rows representing the distance in miles between each point in the 'interiorPoint' column
// and the WKT point 'POINT(-98.83211485551952 36.1919336424082)'
// sorted by distance

Example

// GeoSPARQL example using the Value Processing Function op.geo.distance()
const op = require('/MarkLogic/optic');
const result=op.fromView('buildings', 'builds')
               .bindAs('result',op.geo.distance(op.col('interiorPoint'),cts.point('POINT(-98.83211485551952 36.1919336424082)'),'units=miles'))
               .select(['result', op.col('interiorPoint')])
               .orderBy('result')
               .result()
result;
// ==>
// rows representing the distance in miles between each point in the 'interiorPoint' column
// and the WKT point 'POINT(-98.83211485551952 36.1919336424082)'
// sorted by distance

Example

// SQL example using ST_Distance()
'use strict';
  xdmp.sql("select ST_Distance(interiorPoint, 'POINT(-98.83211485551952 36.1919336424082)', 'units=feet') from builds order by geoid limit 20")

// ==>
// rows representing the distance in feet between the interiorPoint column
// and the WKT point 'POINT(-98.83211485551952 36.1919336424082)'
// sorting by geoid

Example

// GeoSPARQL example using geof.distance()
const op = require('/MarkLogic/optic');
var query = 
`
PREFIX my: <http://example.org/ApplicationSchema#>
PREFIX geoml: <http://marklogic.com/geospatial#>
PREFIX cts: <http://marklogic.com/cts#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
 
SELECT *
WHERE { ?s my:hasExactGeometry ?o
  BIND(geof:distance(?o, 'POINT(39.801681875000014 66.64631330892108)', 'units=km') as ?distance)
  FILTER BOUND(?distance)
}
ORDER BY ?distance`

sem.sparql(query)
// ==>
// rows representing the distance in kilometers between each point in a triple's object (if exists)
// and the WKT point 'POINT(39.801681875000014 66.64631330892108)'
// sorting by distance
Powered by MarkLogic Server | Terms of Use | Privacy Policy