<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.elementPairGeospatialQuery.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.elementPairGeospatialQuery</api:function-name><api:suggest>cts.elementpairgeospatialquery</api:suggest><api:suggest>cts</api:suggest><api:suggest>elementpairgeospatialquery</api:suggest><api:function-link mode="xquery" fullname="cts:element-pair-geospatial-query">/apidoc/8.0/cts:element-pair-geospatial-query.xml</api:function-link><api:function mode="javascript" name="elementPairGeospatialQuery" type="builtin" lib="cts" category="SearchBuiltins" subcategory="cts:query Constructors" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.elementPairGeospatialQuery"><api:summary>
  Returns a <code xmlns="http://www.w3.org/1999/xhtml">cts:query</code> matching elements by name which has
  specific element children representing latitude and longitude values for
  a point contained within the given geographic box, circle, or polygon, or
  equal to the given point.
  Points that lie
  between the southern boundary and the northern boundary of a box,
  travelling northwards,
  and between the western boundary and the eastern boundary of the box,
  travelling eastwards, will match.
  Points contained within the given radius of the center point of a circle will
  match, using the curved distance on the surface of the Earth.
  Points contained within the given polygon will match, using great circle arcs
  over a spherical model of the Earth as edges.  An error may result
  if the polygon is malformed in some way.
  Points equal to the a given point will match, taking into account the fact
  that longitudes converge at the poles.
  Using the geospatial query constructors requires a valid geospatial
  license key; without a valid license key, searches that include
  geospatial queries will throw an exception.
</api:summary><api:params><api:param name="element-name" type="xs:QName*"><api:param-description>
    One or more parent element QNames to match.
    When multiple QNames are specified,
    the query matches if any QName matches.
  </api:param-description><api:param-name>element-name</api:param-name><api:param-type>xs.QName[]</api:param-type></api:param><api:param name="latitude-element-names" type="xs:QName*"><api:param-description>
    One or more latitude element QNames to match.
    When multiple QNames are specified, the query matches
    if any QName matches; however, only the first matching latitude
    child in any point instance will be checked.
  </api:param-description><api:param-name>latitude-element-names</api:param-name><api:param-type>xs.QName[]</api:param-type></api:param><api:param name="longitude-element-names" type="xs:QName*"><api:param-description>
    One or more longitude element QNames to match.
    When multiple QNames are specified, the query matches
    if any QName matches; however, only the first matching longitude
    child in any point instance will be checked.
  </api:param-description><api:param-name>longitude-element-names</api:param-name><api:param-type>xs.QName[]</api:param-type></api:param><api:param name="regions" type="cts:region*"><api:param-description>
    One or more geographic boxes, circles, polygons, or points. Where multiple
    regions are specified, the query matches if any region matches.
  </api:param-description><api:param-name>regions</api:param-name><api:param-type>cts.region[]</api:param-type></api:param><api:param name="options" type="xs:string*" optional="true"><api:param-description>
    Options to this query.  The default is ().
    <p xmlns="http://www.w3.org/1999/xhtml">Options include:</p>
      <blockquote xmlns="http://www.w3.org/1999/xhtml">
        <dl>
        <dt>"coordinate-system=wgs84"</dt>
        <dd>Use the WGS84 coordinate system.</dd>
        <dt>"units=miles"</dt>
        <dd>Distance (for circles) is measured in miles.</dd>
        <dt>"boundaries-included"</dt>
        <dd>Points on boxes', circles', and polygons' boundaries are counted
        as matching.  This is the default.</dd>
        <dt>"boundaries-excluded"</dt>
        <dd>Points on boxes', circles', and polygons' boundaries are not
    counted as matching.</dd>
        <dt>"boundaries-latitude-excluded"</dt>
        <dd>Points on boxes' latitude boundaries are not counted as
    matching.</dd>
        <dt>"boundaries-longitude-excluded"</dt>
        <dd>Points on boxes' longitude boundaries are not counted as
    matching.</dd>
        <dt>"boundaries-south-excluded"</dt>
        <dd>Points on the boxes' southern boundaries are not counted as
    matching.</dd>
        <dt>"boundaries-west-excluded"</dt>
        <dd>Points on the boxes' western boundaries are not counted as
    matching.</dd>
        <dt>"boundaries-north-excluded"</dt>
        <dd>Points on the boxes' northern boundaries are not counted as
    matching.</dd>
        <dt>"boundaries-east-excluded"</dt>
        <dd>Points on the boxes' eastern boundaries are not counted as
    matching.</dd>
        <dt>"boundaries-circle-excluded"</dt>
        <dd>Points on circles' boundary are not counted as matching.</dd>
        <dt>"boundaries-endpoints-excluded"</dt>
        <dd>Points on linestrings' boundary (the endpoints) are not counted as matching.</dd>
        <dt>"cached"</dt>
        <dd>Cache the results of this query in the list cache.</dd>
        <dt>"uncached"</dt>
        <dd>Do not cache the results of this query in the list cache.</dd>
        <dt>"score-function=<em>function</em>"</dt>
        <dd>Use the selected scoring function. The score function may be:
          <dl>
          <dt>linear</dt><dd>Use a linear function of the difference between the
          specified query value and the matching value in the index to calculate
          a score for this range query.</dd>
          <dt>reciprocal</dt><dd>Use a reciprocal function of the difference
          between the specified query value and the matching value in the
          index to calculate a score for this range query.</dd>
          <dt>zero</dt><dd>This range query does not contribute to the
          score. This is the default.</dd>
          </dl>
        </dd>
        <dt>"slope-factor=<em>number</em>"</dt>
        <dd>Apply the given number as a scaling factor to the slope of the
        scoring function. The default is 1.0.</dd>
        <dt>"synonym"</dt>
        <dd>Specifies that all of the terms in the $regions parameter are
        considered synonyms for scoring purposes.  The result is that
        occurances of more than one of the synonyms are scored as if
        there are more occurance of the same term (as opposed to
        having a separate term that contributes to score). </dd>
      </dl></blockquote>
  </api:param-description><api:param-name>options</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="weight" type="xs:double?" optional="true"><api:param-description>
    A weight for this query.  The default is 1.0.
  </api:param-description><api:param-name>weight</api:param-name><api:param-type>Number?</api:param-type></api:param></api:params><api:return>cts.elementPairGeospatialQuery</api:return><api:usage>
<p xmlns="http://www.w3.org/1999/xhtml">The point value is expressed in the content of the latitude and 
longitude elements (the latitude value in the latitude element, and the 
longitude value in the longitude element).
</p>
<p xmlns="http://www.w3.org/1999/xhtml">Point values and boundary specifications of boxes are given in degrees
relative to the WGS84 coordinate system.  Southern latitudes and Western
longitudes take negative values.  Longitudes will be wrapped to the range
(-180,+180) and latitudes will be clipped to the range (-90,+90).
</p>
<p xmlns="http://www.w3.org/1999/xhtml">If the northern boundary of a box is south of the southern boundary, no
points will  match. However, longitudes wrap around the globe, so that if
the western boundary is east of the eastern boundary,
then the box crosses the anti-meridian.
</p>
<p xmlns="http://www.w3.org/1999/xhtml">Special handling occurs at the poles, as all longitudes exist at latitudes
+90 and -90.
</p>
<p xmlns="http://www.w3.org/1999/xhtml">If neither "cached" nor "uncached" is present, it specifies "cached".</p>
  <p xmlns="http://www.w3.org/1999/xhtml">"score-function=linear" means that values that are further away from
  the bounds will score higher. "score-function=reciprocal" means that values
  that are closer to the bounds will score higher. The functions are scaled
  appropriately for different types, so that in general the default slope factor
  will provide useful results. Using a slope factor greater than 1 gives 
  distinct scores over a smaller range of values, and produces generally 
  higher scores.  Using a slope factor less than 1 gives distinct scores 
  over a wider range of values, and produces generally lower scores.
  </p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
// create documents with test data 
declareUpdate();
xdmp.documentInsert("/point01.xml", xdmp.unquote(
 ' &lt;item&gt;&lt;point&gt;&lt;lat&gt;10.5&lt;/lat&gt;&lt;long&gt;30.0&lt;/long&gt;&lt;/point&gt;&lt;/item&gt;' )),
        
xdmp.documentInsert("/point02.xml", xdmp.unquote(
 '  &lt;item&gt;&lt;point&gt;&lt;lat&gt;15.35&lt;/lat&gt;&lt;long&gt;35.34&lt;/long&gt;&lt;/point&gt;&lt;/item&gt;' )),

xdmp.documentInsert("/point03.xml", xdmp.unquote(
 '  &lt;item&gt;&lt;point&gt;&lt;lat&gt;5.11&lt;/lat&gt;&lt;long&gt;40.55&lt;/long&gt;&lt;/point&gt;&lt;/item&gt;' ));

******
// Now the following search:

cts.search(
  cts.elementPairGeospatialQuery(xs.QName("point"),
    xs.QName("lat"), xs.QName("long"), cts.box(10.0, 35.0, 20.0, 40.0)));

=&gt; returns /point02.xml:
   &lt;item&gt;&lt;point&gt;&lt;lat&gt;15.35&lt;/lat&gt;&lt;long&gt;35.34&lt;/long&gt;&lt;/point&gt;&lt;/item&gt;

******
// And the following search:

cts.search(
  cts.elementPairGeospatialQuery(xs.QName("point"),
    xs.QName("lat"), xs.QName("long"), cts.box(10.0, 40.0, 20.0, 35.0)));

=&gt;  returns /point01.xml (wrapping around the Earth):
    &lt;item&gt;&lt;point&gt;&lt;lat&gt;10.5&lt;/lat&gt;&lt;long&gt;30.0&lt;/long&gt;&lt;/point&gt;&lt;/item&gt;
:)
;

cts.search(
  cts.elementPairGeospatialQuery(xs.QName("point"),
    xs.QName("lat"), xs.QName("long"), cts.box(20.0, 35.0, 10.0, 40.0)));

=&gt; throws an XDMP-BADBOX error (because latitudes do not wrap)
</pre>
</api:example></api:function></api:function-page>