geo.distance( p1 as cts.point, p2 as cts.point, [options as String[]] ) as Number
Returns the distance (in units) between two points.
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.
const sf = cts.point(37, -122); const ny = cts.point(40, -73); geo.distance(sf, ny); => 2623.2017796533
// 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
// 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
// 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
// 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