geo:distance( $p1 as cts:point, $p2 as cts:point, [$options as xs:string*] ) as xs:double
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.
let $sf := cts:point(37, -122) let $ny := cts:point(40, -73) return geo:distance($sf, $ny) => 2623.2017796533
xquery version "1.0-ml"; import module namespace op = 'http://marklogic.com/optic' at 'MarkLogic/optic.xqy'; import module namespace ogeo = 'http://marklogic.com/optic/expression/geo' at 'MarkLogic/optic/optic-geo.xqy'; (: Optic example using the Value Processing Function ogeo:distance() :) let $plan:= op:from-view('buildings', 'builds') =>op:bind(op:as('result',ogeo:distance(op:col('interiorPoint'),cts:point('POINT(-98.83211485551952 36.1919336424082)'),'units=miles'))) =>op:select(('result', op:col('interiorPoint'))) =>op:order-by('result') return $plan=>op: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 :)
xquery version "1.0-ml"; (: SQL example using ST_Distance() :) xquery version "1.0-ml"; 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 :)
xquery version "1.0-ml"; (: GeoSPARQL example using geof:distance() :) let $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' return 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 :)