Loading TOC...

geo:approx-center

geo:approx-center(
   $region as cts:region,
   [$options as xs:string*]
) as cts:point

Summary

Return a point approximating the center of the given region. For a point, this is the point itself. For a circle, it is the center point. For a box, it is the point whose latitude is half-way between the northern and southern limits and whose longitude is half-way between the western and eastern limits. For polygons, complex polygons, and linestrings, an approximate centroid is returned. This approximation is rough, and useful for quick comparisons.

Parameters
region A geospatial region.
options Options. The default is ().

Options include:

"box-percent=n"
An integer between 0 and 100 (default is 100) that indicates what percentage of a polygon's bounding box slivers should be used in constructing the approximate centroid. Lower numbers use fewer slivers, giving faster but less accurate results; larger numbers use more slivers, giving slower but more accurate results.
"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"
The precision use for this operation, including the interpretation of input values. Allowed values: float, double. Default: The precision of the governing coordinate system.

Usage Notes

The value of the precision option always takes precedence over the 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.

The precision of the returned region is determined by the precision option, if present. Otherwise, the precision of the returned region is determined by the precision of the governing coordinate system.

See Also

Example

(: Approximate center of London Zoo :)
geo:approx-center(
    cts:polygon((
      cts:point(51.5361190,-0.1590335),
      cts:point(51.5366529,-0.1568234),
      cts:point(51.5372001,-0.1537657),
      cts:point(51.5372868,-0.1527464),
      cts:point(51.5334561,-0.1509440),
      cts:point(51.5332359,-0.1517808),
      cts:point(51.5348643,-0.1584756),
      cts:point(51.5355250,-0.1592481),
      cts:point(51.5360522,-0.1590765)
  )))

==> cts:point(51.535511,-0.15516526)

Example

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:approx-center() :)
let $plan:= op:from-view('buildings', 'builds')
             =>op:bind(op:as('result',ogeo:approx-center(op:col('poly'))))
             =>op:select(('result', op:col('geoid')))
             =>op:order-by('result')

return $plan=>op:result()

(:
==>
rows representing the approximate center of the 'poly' column
:)

Example

xquery version "1.0-ml";
  xdmp:sql("select ST_Centroid(poly) from builds order by geoid limit 20")
(:
==>
rows representing the approximate center of the 'poly' column
:)

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.