<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.matchRegions.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.matchRegions</api:function-name><api:suggest>cts.matchregions</api:suggest><api:suggest>cts</api:suggest><api:suggest>matchregions</api:suggest><api:function-link mode="xquery" fullname="cts:match-regions">/apidoc/8.0/cts:match-regions.xml</api:function-link><api:function mode="javascript" name="matchRegions" type="builtin" lib="cts" category="SearchBuiltins" subcategory="Geospatial Lexicon" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.matchRegions"><api:summary>
    Find regions in documents that have a spatial relationship to 
    one or more caller-supplied regions.
  </api:summary><api:params><api:param name="range-indexes" type="cts:reference*"><api:param-description>
      References to range indexes that store the string serialization
      of regions to match against.
    </api:param-description><api:param-name>range-indexes</api:param-name><api:param-type>cts.reference[]</api:param-type></api:param><api:param name="operation" type="xs:string"><api:param-description>
      The operation to test. Must be one of the following:
      <code xmlns="http://www.w3.org/1999/xhtml">"contains"</code>, <code xmlns="http://www.w3.org/1999/xhtml">"within"</code>, <code xmlns="http://www.w3.org/1999/xhtml">"overlaps"</code>,
      or <code xmlns="http://www.w3.org/1999/xhtml">"intersects"</code>. See the Usage Notes for details.
    </api:param-description><api:param-name>operation</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="regions" type="cts:region+"><api:param-description>
      One or more cts:region values to test against. A region matches if
      if it matches against any of these regions.
    </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>
      String options you can use to control the operation. The following
      options are supported:
      <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
        <dt>"coordinate-system=<em>value</em>"</dt>
        <dd>Use the given coordinate system. Valid values are
          <code>raw</code> and <code>wgs84</code> (default).</dd>
        <dt>"units=miles"</dt>
        <dd>Compute distances and the radii of circles using the given
          units. Other units should be converted using the
          <code>geo:distance-convert-units</code> function.</dd> 
        <dt>"strings"</dt>
        <dd>Return results as strings instead of as <code>cts:region</code>
          values.</dd>
        <dt>"any"</dt>
        <dd>Co-occurrences from any fragment should be included.</dd>
        <dt>"document"</dt>
        <dd>Co-occurrences from document fragments should be included.</dd>
        <dt>"properties"</dt>
        <dd>Co-occurrences from properties fragments should be included.</dd>
        <dt>"locks"</dt>
        <dd>Co-occurrences from locks fragments should be included.</dd>
        <dt>"fragment-frequency"</dt>
        <dd>Frequency should be the number of fragments with an
          included co-occurrence. This option is used with 
          <code>cts:frequency</code>.</dd>
        <dt>"item-frequency"</dt>
        <dd>Frequency should be the number of occurrences of an
          included co-occurrence. This option is used with 
          <code>cts:frequency</code>.</dd>
        <dt>"checked"</dt>
        <dd>Word positions should be checked when resolving the query.</dd>
        <dt>"unchecked"</dt>
        <dd>Word positions should not be checked when resolving the query.</dd>
        <dt>"too-many-positions-error"</dt>
        <dd>If too much memory is needed to perform positions calculations
          to check whether a document matches a query, return an 
          XDMP-TOOMANYPOSITIONS error, instead of accepting the document 
          as a match.</dd>
        <dt>"concurrent"</dt>
        <dd>Perform the work concurrently in another thread. This is a hint
        to the query optimizer to help parallelize the lexicon work, allowing
        the calling query to continue performing other work while the lexicon
        processing occurs.  This is especially useful in cases where multiple
        lexicon calls occur in the same query (for example, resolving many
        facets in a single query).</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="query" type="cts:query?" optional="true"><api:param-description>
      Limit the region comparison to documents that match this query.
      Also, compute frequencies from the set of included regions. The
      values do not need to match the query, but they must occur in fragments
      selected by the query. The fragments are not filtered ot ensure they
      match the query. Instead, they are selected in the same manner as
      <a href="/cts:search#unfiltered" xmlns="http://www.w3.org/1999/xhtml">"unfiltered" <code>cts:search</code></a> 
      operations.
    </api:param-description><api:param-name>query</api:param-name><api:param-type>cts.query?</api:param-type></api:param><api:param name="forest-ids" type="xs:unsignedLong*" optional="true"><api:param-description>
      A sequence of IDs of forests to which the search should be constrained.
      An empty sequence means search all forests in the databse. The default
      is an empty sequence.
    </api:param-description><api:param-name>forest-ids</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">This function matches regions in documents in the database satisfying
   the relationship <em>R1 op R2</em>, where <em>R1</em> is a region in
   a database document, <em>op</em> is the operator provided in the
   <code>operation</code> parameter, and <em>R2</em> is any of the regions 
   provided in the <code>regions</code> parameter. The <em>R1</em> regions
   under considerations are those in the indexes provided in the
   <code>range-indexes</code> parameter. The <em>R1</em> regions can be
   further constrained to those in documents that match a query.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">The operations have the following semantics:</p>
  <blockquote xmlns="http://www.w3.org/1999/xhtml"><dl>
    <dt>"contains"</dt>
    <dd>Matches regions in the given indexes that contain any of the 
     regions in <code>$regions</code>. That is, regions where
     <code>geo:region-contains($r1,$r2)</code> returns true for some
     region <code>$r1</code> occurring in the supplied indexes and region
     <code>$r2</code> in <code>$regions</code>.</dd>
    <dt>"intersects"</dt>
    <dd>Matches regions in the given indexes that intersect with any of the 
     regions in <code>$regions</code>. That is, regions where
     <code>geo:region-intersects($r1,$r2)</code> returns true for some
     region <code>$r1</code> occurring in the supplied indexes and region
     <code>$r2</code> in <code>$regions</code>.</dd>
    <dt>"overlaps"</dt>
    <dd>Matches regions in the given indexes that intersect with any of the 
     regions in <code>$regions</code>, exclusive of boundaries, and neither
     region contains the other. That is, regions where
     <code>geo:region-intersects($r1,$r2, ("boundaries-excluded") )</code> 
     for some region <code>$r1</code> occurring in the supplied indexes and 
     region <code>$r2</code> in <code>$regions</code>; and neither region
     includes the other.</dd>
    <dt>"within"</dt>
    <dd>Matches regions in the given indexes that are contained by any of
     of the regions in <code>$regions</code>. That is, regions where
     <code>geo:region-contains($r2,$r1)</code> returns true for some
     region <code>$r1</code> occurring in the supplied indexes and region
     <code>$r2</code> in <code>$regions</code>.</dd>
  </dl></blockquote>
  
  <p class="javascript" xmlns="http://www.w3.org/1999/xhtml">The return value is either an iterator over 
   <code>cts:region</code> values or an iterator over strings containing
   the serialized regions, depending on whether or not the 
   <code>strings</code> option is included.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">If the range indexes provided through the <code>range-indexes</code>
   parameter contain any string that cannot be parsed into a region, an
   error is thrown.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">Only one of "fragment-frequency" or "item-frequency" may be specified
   in the options parameter.  If neither "fragment-frequency" nor
   "item-frequency" is specified, then the default is "fragment-frequency".</p>
  <p xmlns="http://www.w3.org/1999/xhtml">Only one of "any", "document", "properties", or "locks"
   may be specified in the options parameter.
   If none of "any", "document", "properties", or "locks" are specified
   and there is a $query parameter, then the default is "document".
   If there is no $query parameter then the default is "any".</p>
  <p xmlns="http://www.w3.org/1999/xhtml">Only one of the "checked" or "unchecked" options may be specified
   in the options parameter.
   If neither "checked" nor "unchecked" are specified,
   then the default is "checked".</p>
  <p xmlns="http://www.w3.org/1999/xhtml">If "coordinate-system=<em>name</em>" is not specified in the options
   parameter, then the default coordinate system is used. If a lexicon with
   that coordinate system does not exist, an error is thrown.</p>
  </api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
cts.matchRegions(cts.elementReference('parcel'), 'intersects',
  [cts.polygon('POLYGON((1 1,2 2,0 1,1 1))'), cts.circle(10,cts.point(7,0))])

==&gt; Any parcel that intersects either the triangle with vertices 
    (1,1), (2,2), (0,1), or the circle of radius 10 centered at (7,0).
  </pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var africa = cts.polygon(
  'POLYGON((32.34375 34.74161249883172,37.265625 ' +
  '28.149503211544566,56.07421875 8.059229627200192,46.23046875 ' +
  '-41.244772343082076,4.04296875 -39.77476948529545,-33.75 ' +
  '29.53522956294847,7.03125 39.50404070558415,32.34375 34.74161249883172))')
cts.matchRegions(
  cts.jsonPropertyReference('country'), 'within', 
    africa, ['coordinate-system=wgs84'], 
    cts.jsonPropertyValueQuery('state-bird', ['eagle','turkey']))

==&gt; Every country in Africa that has either an eagle or a turkey as 
    its state bird.
  </pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var regionStrings = cts.matchRegions(
  cts.jsonPropertyReference('zone'), 'overlaps',
  cts.polygon([
    cts.point(0,0), cts.point(1,1),
    cts.point(0,2), cts.point(2,2),
    cts.point(2,0), cts.point(0,0)
  ]),
  ['coordinate-system=raw', 'strings']);
cts.search(cts.jsonPropertyRangeQuery('zone', '=', regionStrings))

==&gt; Every document that contains a zone which overlaps with the specified 
    polygon.
  </pre></api:example></api:function></api:function-page>