This page was generated
March  13,  2012
4:49  AM
XQuery & XSLT Built-In & Modules Function Reference

Module: Geospatial Supporting Functions

The MCGM module provides support for geospatial queries using MetaCarta geospatial markup.

To use the MCGM module as part of your own XQuery module, include the following line in your XQuery prolog:

import module namespace mcgm = "http://marklogic.com/geospatial/mcgm" at "/MarkLogic/geospatial/mcgm.xqy";

The library namespace prefix mcgm is not predefined in the server.

The GeoRSS module provides support for geospatial queries using GeoRSS/Simple markup.

To use the GeoRSS module as part of your own XQuery module, include the following line in your XQuery prolog:

import module namespace georss = "http://www.georss.org/georss" at "/MarkLogic/geospatial/georss.xqy";

The library namespace prefix georss is not predefined in the server.

The KML module provides support for geospatial queries using KML markup.

To use the KML module as part of your own XQuery module, include the following line in your XQuery prolog:

import module namespace kml = "http://earth.google.com/kml/2.0" at "/MarkLogic/geospatial/kml.xqy";

The library namespace prefix kml is not predefined in the server.

The Geo module provides support for geospatial queries using GML, KML, GeoRSS/Simple, or Metacarta Geospatial markup.

To use the Geo module as part of your own XQuery module, include the following line in your XQuery prolog:

import module namespace geo = "http://marklogic.com/geospatial" at "/MarkLogic/geospatial/geospatial.xqy";

The library namespace prefix geo is not predefined in the server.

The GML module provides support for geospatial queries using GML markup.

To use the GML module as part of your own XQuery module, include the following line in your XQuery prolog:

import module namespace gml = "http://www.opengis.net/gml" at "/MarkLogic/geospatial/gml.xqy";

The library namespace prefix gml is not predefined in the server.

Function Summary
geo:box Create a cts:point value from an element representing a box in one of the supported markup vocabularies.
geo:circle Create a cts:circle value from a radius and an element representing a point in one of the supported markup vocabularies.
geo:geospatial-query Returns a cts:query matching points within given regions.
geo:geospatial-query-from-elements Returns a cts:query matching points within given regions.
geo:interior-polygon Create a sequence of cts:polygon values from a polygon element in one of the supported markup vocabularies.
geo:point Create a cts:point value from an element representing a point in one of the supported markup vocabularies.
geo:polygon Create a cts:polygon value from a sequence of point elements in one of the supported markup vocabularies.
georss:circle Create a cts:circle value from a radius and GeoRSS point element.
georss:geospatial-query Returns a cts:query matching points within given regions.
georss:point Create a cts:point value from a GeoRSS point element.
gml:box Create a cts:box value from a GML Envelope element.
gml:circle Create a cts:circle value from a radius and GML Point element.
gml:geospatial-query Returns a cts:query matching points within given regions.
gml:geospatial-query-from-elements Returns a cts:query matching points within given regions.
gml:interior-polygon Create a sequence of cts:polygon values from a GML Polygon element.
gml:point Create a cts:point value from a GML Point element.
gml:polygon Create a cts:polygon value from a sequence of GML Point elements or a GML Polygon element.
gml:polygon Create a cts:polygon value from a GML Polygon element.
kml:box Create a cts:point value from a KML LatLongBox element.
kml:circle Create a cts:circle value from a radius and KML Point or Location element.
kml:geospatial-query Returns a cts:query matching points within given regions.
kml:geospatial-query-from-elements Returns a cts:query matching points within given regions.
kml:interior-polygon Create a sequence of cts:polygon values from a KML Polygon element.
kml:point Create a cts:point value from a KML Point or Location element.
kml:polygon Create a cts:polygon value from a KML polygon or a sequence of KML Point or Location elements.
kml:polygon Create a cts:polygon value from a KML Polygon element.
mcgm:circle Create a cts:circle value from a radius and MCGM Dot element.
mcgm:geospatial-query Returns a cts:query matching points within given regions.
mcgm:geospatial-query-from-elements Returns a cts:query matching points within given regions.
mcgm:point Create a cts:point value from a MCGM Dot element.
mcgm:polygon Construct a cts:polygon value from a sequence of MCGM Dot elements.
Function Detail
geo:box(
$box as element()
)  as   cts:box
Summary:

Create a cts:point value from an element representing a box in one of the supported markup vocabularies.

Parameters:
$box : An element representing a box.

Example:
  xquery version "1.0-ml";
  import module namespace geo = "http://marklogic.com/geospatial"
         at "/MarkLogic/geospatial/geospatial.xqy";
  declare namespace kml= "http://earth.google.com/kml/2.0";

  geo:box(
     <kml:LatLongBox>
       <kml:north>30</kml:north>
       <kml:south>12.5</kml:south>
       <kml:east>-122.24</kml:east>
       <kml:west>-127.24</kml:west>
     </kml:LatLongBox>)
  

geo:circle(
$radius as xs:double,
$center as element()
)  as   cts:circle
Summary:

Create a cts:circle value from a radius and an element representing a point in one of the supported markup vocabularies.

Parameters:
$radius : The radius of the circle, in miles.
$center : An element representing the point at the center of the circle.

Example:
  xquery version "1.0-ml";
  import module namespace geo = "http://marklogic.com/geospatial"
         at "/MarkLogic/geospatial/geospatial.xqy";

  geo:circle(47, <Dot Latitude="12.5" Longitude="-127.24"/>)
  

geo:geospatial-query(
$regions as cts:region*,
[$options as xs:string*],
[$weight as xs:double?]
)  as   cts:query
Summary:

Returns a cts:query matching points within given regions.

Parameters:
$regions : One or more geographic boxes, circles, polygons, or points. Where multiple boxes, circles, polygons, or points are specified, the query matches if any box, circle, polygon, or point matches.
$options (optional): Options to this query. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"boundaries-included"
Points on boxes' and circles' boundaries are counted as matching. This is the default.
"boundaries-excluded"
Points on boxes' and circles' boundaries are not counted as matching.
"boundaries-latitude-excluded"
Points on boxes' latitude boundaries are not counted as matching.
"boundaries-longitude-excluded"
Points on boxes' longitude boundaries are not counted as matching.
"boundaries-south-excluded"
Points on the boxes' southern boundaries are not counted as matching.
"boundaries-west-excluded"
Points on the boxes' western boundaries are not counted as matching.
"boundaries-north-excluded"
Points on the boxes' northern boundaries are not counted as matching.
"boundaries-east-excluded"
Points on the boxes' eastern boundaries are not counted as matching.
"boundaries-circle-excluded"
Points on circles' boundary are not counted as matching.
$weight (optional): A weight for this query. The default is 1.0.

Usage Notes:

The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).

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).

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.

Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.

The query constructed will examine points in all the supported geospatial markup vocabularies. If not all these vocabularies will be in use, it may be more efficient to use the query constructors for just the vocabulary or vocabularies that are in actual use.


Example:
xquery version "1.0-ml";
(: create a document with test data :)
declare namespace gml= "http://www.opengis.net/gml";
declare namespace georss= "http://www.georss.org/georss";

xdmp:document-insert("/points.xml",
<root xmlns:geo="http://marklogic.com/geospatial">
  <item><gml:Point><gml:pos>10.5 30.0</gml:pos></gml:Point></item>
  <item><georss:point>15.35 35.34</georss:point></item>
  <item><Dot Latitude="5.11" Longitude="40.55"/></item>
</root> );

xquery version "1.0-ml";
import module namespace geo = "http://marklogic.com/geospatial"
   at "/MarkLogic/geospatial/geospatial.xqy";
declare namespace gml= "http://www.opengis.net/gml";
declare namespace georss= "http://www.georss.org/georss";
declare namespace kml= "http://earth.google.com/kml/2.0";

cts:search(doc("/points.xml")//item, 
  geo:geospatial-query(
    geo:box(
      <gml:Envelope>
        <gml:lowerCorner>10.0 35.0</gml:lowerCorner>
        <gml:upperCorner>20.0 40.0</gml:upperCorner>
      </gml:Envelope>)
  ))
(:
  returns the following node: 
  <item><georss:point>15.35 35.34</georss:point></item>
:)
,

cts:search(doc("/points.xml")//item, 
  geo:geospatial-query(geo:box(
    <kml:LatLongBox>
      <kml:north>20.0</kml:north>
      <kml:south>10.0</kml:south>
      <kml:east>35.0</kml:east>
      <kml:west>40.0</kml:west>
    </kml:LatLongBox>
  )))
(:
  returns the following nodes (wrapping around the Earth):
  <item><gml:Point><gml:pos>10.5 30.0</gml:pos></gml:Point></item>
:)
,

cts:search(doc("/points.xml")//item, 
  geo:geospatial-query(
    cts:box(10.0, 35.0, 20.0, 40.0)))
(:
  returns the following node:
  <item><georss:point>15.35 35.34</georss:point></item>
:)
 

geo:geospatial-query-from-elements(
$regions as element()*,
[$options as xs:string*],
[$weight as xs:double?]
)  as   cts:query
Summary:

Returns a cts:query matching points within given regions.

Parameters:
$regions : One or more geographic boxes, circles, polygons, or points, represented by elements in one of the supported vocabularies. Where multiple boxes, circles, polygons, or points are specified, the query matches if any box, circle, polygon, or point matches.
$options (optional): Options to this query. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"boundaries-included"
Points on boxes' and circles' boundaries are counted as matching. This is the default.
"boundaries-excluded"
Points on boxes' and circles' boundaries are not counted as matching.
"boundaries-latitude-excluded"
Points on boxes' latitude boundaries are not counted as matching.
"boundaries-longitude-excluded"
Points on boxes' longitude boundaries are not counted as matching.
"boundaries-south-excluded"
Points on the boxes' southern boundaries are not counted as matching.
"boundaries-west-excluded"
Points on the boxes' western boundaries are not counted as matching.
"boundaries-north-excluded"
Points on the boxes' northern boundaries are not counted as matching.
"boundaries-east-excluded"
Points on the boxes' eastern boundaries are not counted as matching.
"boundaries-circle-excluded"
Points on circles' boundary are not counted as matching.
$weight (optional): A weight for this query. The default is 1.0.

Usage Notes:

The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).

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).

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.

Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.

The query constructed will examine points in all the supported geospatial markup vocabularies. If not all these vocabularies will be in use, it may be more efficient to use the query constructors for just the vocabulary or vocabularies that are in actual use.

This function will take into account interior polygons, if any, and properly construct the query to account for them.


Example:
xquery version "1.0-ml";
(: create a document with test data :)
declare namespace gml= "http://www.opengis.net/gml";
declare namespace georss= "http://www.georss.org/georss";

xdmp:document-insert("/points.xml",
<root xmlns:geo="http://marklogic.com/geospatial">
  <item><gml:Point><gml:pos>10.5 30.0</gml:pos></gml:Point></item>
  <item><georss:point>15.35 35.34</georss:point></item>
  <item><Dot Latitude="5.11" Longitude="40.55"/></item>
</root> );

xquery version "1.0-ml";
import module namespace geo = "http://marklogic.com/geospatial"
   at "/MarkLogic/geospatial/geospatial.xqy";
declare namespace gml= "http://www.opengis.net/gml";
declare namespace georss= "http://www.georss.org/georss";
declare namespace kml= "http://earth.google.com/kml/2.0";

cts:search(doc("/points.xml")//item, 
  geo:geospatial-query-from-elements(
    <gml:Envelope>
      <gml:lowerCorner>10.0 35.0</gml:lowerCorner>
      <gml:upperCorner>20.0 40.0</gml:upperCorner>
    </gml:Envelope>
  ) )
(:
  returns the following node: 
  <item><georss:point>15.35 35.34</georss:point></item>
:)
,

cts:search(doc("/points.xml")//item, 
  geo:geospatial-query-from-elements(
    <kml:LatLongBox>
      <kml:north>20.0</kml:north>
      <kml:south>10.0</kml:south>
      <kml:east>35.0</kml:east>
      <kml:west>40.0</kml:west>
    </kml:LatLongBox>
  ))
(:
  returns the following nodes (wrapping around the Earth):
  <item><georss:point>15.35 35.34</georss:point></item>
  <item><gml:Point><gml:pos>10.5 30.0</gml:pos></gml:Point></item>
:)


geo:interior-polygon(
$polygon as element()
)  as   cts:polygon*
Summary:

Create a sequence of cts:polygon values from a polygon element in one of the supported markup vocabularies. These polygons represent the interior polygons, if any.

Parameters:
$polygon : An elements representing the polygon.

Example:
  xquery version "1.0-ml";
  import module namespace geo = "http://marklogic.com/geospatial"
      at "/MarkLogic/geospatial/geospatial.xqy";
  declare namespace georss= "http://www.georss.org/georss";

  (: Returns empty; no interior polygon in this format :)
  geo:interior-polygon( 
    <georss:polygon>
      12.5,-127.24 15.25,-127.8 13.45,-126.1 12.5,-127.24
    </georss:polygon>
  ) 
  

geo:point(
$point as element()
)  as   cts:point
Summary:

Create a cts:point value from an element representing a point in one of the supported markup vocabularies.

Parameters:
$point : An element representing a point.

Example:
  xquery version "1.0-ml";
  import module namespace geo = "http://marklogic.com/geospatial"
         at "/MarkLogic/geospatial/geospatial.xqy";
  declare namespace gml= "http://www.opengis.net/gml";

  geo:point(<gml:Point><gml:pos>12.5 -127.24</gml:pos></gml:Point>)
  

geo:polygon(
$polygon-or-points as element()+
)  as   cts:polygon
Summary:

Create a cts:polygon value from a sequence of point elements in one of the supported markup vocabularies.

Parameters:
$polygon-or-points : A sequence of elements, each representing a vertex (point) of the polygon, or a polygon element. A polygon element from one of the supported markup vocabularies represents the exterior polygon for those vocabularies that include both exterior and interior polygons in their representation.

Example:
  xquery version "1.0-ml";
  import module namespace geo = "http://marklogic.com/geospatial"
         at "/MarkLogic/geospatial/geospatial.xqy";

  geo:polygon(( <Dot Latitude="12.5" Longitude="-127.24"/>,
                <Dot Latitude="15.25" Longitude="-127.8"/>,
                <Dot Latitude="13.45" Longitude="-126.1"/>,
                <Dot Latitude="12.5" Longitude="-127.24"/>
             ))
  

georss:circle(
$radius as xs:double,
$center as element(georss:point)
)  as   cts:circle
Summary:

Create a cts:circle value from a radius and GeoRSS point element.

Parameters:
$radius : The radius of the circle, in miles.
$center : A point element representing the center of the circle.

Example:
  xquery version "1.0-ml";
  import module namespace georss = "http://www.georss.org/georss"
         at "/MarkLogic/geospatial/georss.xqy";

  georss:circle(47, <georss:point>12.5 -127.24</georss:point>)
  

georss:geospatial-query(
$regions as cts:region*,
[$options as xs:string*],
[$weight as xs:double?]
)  as   cts:query
Summary:

Returns a cts:query matching points within given regions.

Parameters:
$regions : One or more geographic boxes, circles, or points. Where multiple boxes, circles, or points are specified, the query matches if any box, circle, or point matches.
$options (optional): Options to this query. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"boundaries-included"
Points on boxes' and circles' boundaries are counted as matching. This is the default.
"boundaries-excluded"
Points on boxes' and circles' boundaries are not counted as matching.
"boundaries-latitude-excluded"
Points on boxes' latitude boundaries are not counted as matching.
"boundaries-longitude-excluded"
Points on boxes' longitude boundaries are not counted as matching.
"boundaries-south-excluded"
Points on the boxes' southern boundaries are not counted as matching.
"boundaries-west-excluded"
Points on the boxes' western boundaries are not counted as matching.
"boundaries-north-excluded"
Points on the boxes' northern boundaries are not counted as matching.
"boundaries-east-excluded"
Points on the boxes' eastern boundaries are not counted as matching.
"boundaries-circle-excluded"
Points on circles' boundary are not counted as matching.
$weight (optional): A weight for this query. The default is 1.0.

Usage Notes:

The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).

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).

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.

Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.


Example:
xquery version "1.0-ml";

(: create a document with test data :)
xdmp:document-insert("/points.xml",
<root xmlns:georss="http://www.georss.org/georss">
  <item><georss:point>10.5 30.0</georss:point></item>
  <item><georss:point>15.35 35.34</georss:point></item>
  <item><georss:point>5.11 40.55</georss:point></item>
</root> );

xquery version "1.0-ml";
import module namespace georss = "http://www.georss.org/georss"
   at "/MarkLogic/geospatial/georss.xqy";

cts:search(doc("/points.xml")//item, 
  georss:geospatial-query(cts:box(10.0, 35.0, 20.0, 40.0)))
(:
  returns the following node: 
  <item><georss:point>15.35 35.34</georss:point></item>
:)
 

georss:point(
$point as element(georss:point)
)  as   cts:point
Summary:

Create a cts:point value from a GeoRSS point element.

Parameters:
$point : A point element.

Example:
  xquery version "1.0-ml";
  import module namespace georss = "http://www.georss.org/georss"
         at "/MarkLogic/geospatial/georss.xqy";

  georss:point(<georss:point>12.5 -127.24</georss:point>)
  

gml:box(
$box as element(gml:Envelope)
)  as   cts:box
Summary:

Create a cts:box value from a GML Envelope element.

Parameters:
$box : An Envelope element.

Example:
  xquery version "1.0-ml";
  import module namespace gml = "http://www.opengis.net/gml"
         at "/MarkLogic/geospatial/gml.xqy";

  gml:box(
     <gml:Envelope>
       <gml:lowerCorner>12.5 -127.24</gml:lowerCorner>
       <gml:upperCorner>30 -122.24</gml:upperCorner>
     </gml:Envelope>)
  

gml:circle(
$radius as xs:double,
$center as element(gml:Point)
)  as   cts:circle
Summary:

Create a cts:circle value from a radius and GML Point element.

Parameters:
$radius : The radius of the circle, in miles.
$center : A Point element representing the center of the circle.

Example:
  xquery version "1.0-ml";
  import module namespace gml = "http://www.opengis.net/gml"
         at "/MarkLogic/geospatial/gml.xqy";

  gml:circle(47, <gml:Point><gml:pos>12.5 -127.24</gml:pos></gml:Point>)
  

gml:geospatial-query(
$regions as cts:region*,
[$options as xs:string*],
[$weight as xs:double?]
)  as   cts:query
Summary:

Returns a cts:query matching points within given regions.

Parameters:
$regions : One or more geographic boxes, circles, polygons, or points. Where multiple boxes, circles, polygons, or points are specified, the query matches if any box, circle, polygon, or point matches.
$options (optional): Options to this query. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"boundaries-included"
Points on boxes' and circles' boundaries are counted as matching. This is the default.
"boundaries-excluded"
Points on boxes' and circles' boundaries are not counted as matching.
"boundaries-latitude-excluded"
Points on boxes' latitude boundaries are not counted as matching.
"boundaries-longitude-excluded"
Points on boxes' longitude boundaries are not counted as matching.
"boundaries-south-excluded"
Points on the boxes' southern boundaries are not counted as matching.
"boundaries-west-excluded"
Points on the boxes' western boundaries are not counted as matching.
"boundaries-north-excluded"
Points on the boxes' northern boundaries are not counted as matching.
"boundaries-east-excluded"
Points on the boxes' eastern boundaries are not counted as matching.
"boundaries-circle-excluded"
Points on circles' boundary are not counted as matching.
$weight (optional): A weight for this query. The default is 1.0.

Usage Notes:

The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).

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).

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.

Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.


Example:
xquery version "1.0-ml";

(: create a document with test data :)
xdmp:document-insert("/points.xml",
<root xmlns:gml="http://www.opengis.net/gml">
  <item><gml:Point><gml:pos>10.5 30.0</gml:pos></gml:Point></item>
  <item><gml:Point><gml:pos>15.35 35.34</gml:pos></gml:Point></item>
  <item><gml:Point><gml:pos>5.11 40.55</gml:pos></gml:Point></item>
</root> );

xquery version "1.0-ml";
import module namespace gml = "http://www.opengis.net/gml"
   at "/MarkLogic/geospatial/gml.xqy";

cts:search(doc("/points.xml")//item, 
  gml:geospatial-query(
    gml:box(
      <gml:Envelope>
        <gml:lowerCorner>10.0 35.0</gml:lowerCorner>
        <gml:upperCorner>20.0 40.0</gml:upperCorner>
      </gml:Envelope>) ))
(:
  returns the following node: 
  <item><gml:Point><gml:pos>15.35 35.34</gml:pos></gml:Point></item>
:)
,

cts:search(doc("/points.xml")//item, 
  gml:geospatial-query(gml:box(
    <gml:Envelope>
      <gml:lowerCorner>10.0 40.0</gml:lowerCorner>
      <gml:upperCorner>20.0 35.0</gml:upperCorner>
    </gml:Envelope>
  )))
(:
  returns the following nodes (wrapping around the Earth):
  <item><gml:Point><gml:pos>10.5 30.0</gml:pos></gml:Point></item>
:)
 

gml:geospatial-query-from-elements(
$regions as element()*,
[$options as xs:string*],
[$weight as xs:double?]
)  as   cts:query
Summary:

Returns a cts:query matching points within given regions.

Parameters:
$regions : One or more geographic boxes, circles, polygons, or points, represented as GML elements. Where multiple boxes, circles, polygons, or points are specified, the query matches if any box, circle, polygon, or point matches.
$options (optional): Options to this query. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"boundaries-included"
Points on boxes' and circles' boundaries are counted as matching. This is the default.
"boundaries-excluded"
Points on boxes' and circles' boundaries are not counted as matching.
"boundaries-latitude-excluded"
Points on boxes' latitude boundaries are not counted as matching.
"boundaries-longitude-excluded"
Points on boxes' longitude boundaries are not counted as matching.
"boundaries-south-excluded"
Points on the boxes' southern boundaries are not counted as matching.
"boundaries-west-excluded"
Points on the boxes' western boundaries are not counted as matching.
"boundaries-north-excluded"
Points on the boxes' northern boundaries are not counted as matching.
"boundaries-east-excluded"
Points on the boxes' eastern boundaries are not counted as matching.
"boundaries-circle-excluded"
Points on circles' boundary are not counted as matching.
$weight (optional): A weight for this query. The default is 1.0.

Usage Notes:

The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).

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).

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.

Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.

This function will take into account interior polygons, if any, and properly construct the query to account for them.


Example:
xquery version "1.0-ml";

(: create a document with test data :)
xdmp:document-insert("/points.xml",
<root xmlns:gml="http://www.opengis.net/gml">
  <item><gml:Point><gml:pos>10.5 30.0</gml:pos></gml:Point></item>
  <item><gml:Point><gml:pos>15.35 35.34</gml:pos></gml:Point></item>
  <item><gml:Point><gml:pos>5.11 40.55</gml:pos></gml:Point></item>
</root> );

xquery version "1.0-ml";
import module namespace gml = "http://www.opengis.net/gml"
   at "/MarkLogic/geospatial/gml.xqy";

cts:search(doc("/points.xml")//item, 
  gml:geospatial-query-from-elements(
      <gml:Envelope>
        <gml:lowerCorner>10.0 35.0</gml:lowerCorner>
        <gml:upperCorner>20.0 40.0</gml:upperCorner>
      </gml:Envelope>) )
(:
  returns the following node: 
  <item><gml:Point><gml:pos>15.35 35.34</gml:pos></gml:Point></item>
:)
,

cts:search(doc("/points.xml")//item, 
  gml:geospatial-query-from-elements(
    <gml:Envelope>
      <gml:lowerCorner>10.0 40.0</gml:lowerCorner>
      <gml:upperCorner>20.0 35.0</gml:upperCorner>
    </gml:Envelope>) )
(:
  returns the following nodes (wrapping around the Earth):
  <item><gml:Point><gml:pos>10.5 30.0</gml:pos></gml:Point></item>
:)
 
 

gml:interior-polygon(
$polygon as element(gml:Polygon)
)  as   cts:polygon*
Summary:

Create a sequence of cts:polygon values from a GML Polygon element. The polygons returned represent the interior polygons, if any.

Parameters:
$polygon : A Polygon element representing the polygon.

Example:
  xquery version "1.0-ml";
  import module namespace gml = "http://www.opengis.net/gml"
         at "/MarkLogic/geospatial/gml.xqy";

  (: Returns empty; no interior :)
  gml:interior-polygon(
    <gml:Polygon><gml:exterior><gml:LinearRing>
    <gml:pos>12.5 -127.24</gml:pos>
    <gml:pos>15.25 -127.8</gml:pos>
    <gml:pos>13.45 -126.1</gml:pos>
    <gml:pos>12.5 -127.24</gml:pos>
    </gml:LinearRing></gml:exterior></gml:Polygon>
  )
  

gml:point(
$point as element(gml:Point)
)  as   cts:point
Summary:

Create a cts:point value from a GML Point element.

Parameters:
$point : A Point element.

Example:
  xquery version "1.0-ml";
  import module namespace gml = "http://www.opengis.net/gml"
         at "/MarkLogic/geospatial/gml.xqy";

  gml:point(<gml:Point><gml:pos>12.5 -127.24</gml:pos></gml:Point>)
  

gml:polygon(
$polygon-or-points as element()+
)  as   cts:polygon
Summary:

Create a cts:polygon value from a sequence of GML Point elements or a GML Polygon element.

Parameters:
$polygon-or-points : A sequence of Point elements representing the vertices of the polygon or a Polygon element..

Example:
  xquery version "1.0-ml";
  import module namespace gml = "http://www.opengis.net/gml"
         at "/MarkLogic/geospatial/gml.xqy";

  gml:polygon((
    <gml:Point><gml:pos>12.5 -127.24</gml:pos></gml:Point>,
    <gml:Point><gml:pos>15.25 -127.8</gml:pos></gml:Point>,
    <gml:Point><gml:pos>13.45 -126.1</gml:pos></gml:Point>,
    <gml:Point><gml:pos>12.5 -127.24</gml:pos></gml:Point>
  ))
  

gml:polygon(
$polygon-or-points as element()+
)  as   cts:polygon
Summary:

Create a cts:polygon value from a GML Polygon element. The polygon returned represents the exterior polygon.

Parameters:
$polygon-or-points : A Polygon element representing the polygon.

Example:
  xquery version "1.0-ml";
  import module namespace gml = "http://www.opengis.net/gml"
         at "/MarkLogic/geospatial/gml.xqy";

  gml:polygon(
    <gml:Polygon><gml:exterior><gml:LinearRing>
    <gml:pos>12.5 -127.24</gml:pos>
    <gml:pos>15.25 -127.8</gml:pos>
    <gml:pos>13.45 -126.1</gml:pos>
    <gml:pos>12.5 -127.24</gml:pos>
    </gml:LinearRing></gml:exterior></gml:Polygon>
  )
  

kml:box(
$envelope as element(kml:LatLongBox)
)  as   cts:box
Summary:

Create a cts:point value from a KML LatLongBox element.

Parameters:
$envelope : A LatLongBox element.

Example:
  xquery version "1.0-ml";
  import module namespace kml = "http://earth.google.com/kml/2.0"
         at "/MarkLogic/geospatial/kml.xqy";

  kml:box(
     <kml:LatLongBox>
       <kml:north>30</kml:north>
       <kml:south>12.5</kml:south>
       <kml:east>-122.24</kml:east>
       <kml:west>-127.24</kml:west>
     </kml:LatLongBox>)
  

kml:circle(
$radius as xs:double,
$center as element()
)  as   cts:circle
Summary:

Create a cts:circle value from a radius and KML Point or Location element.

Parameters:
$radius : The radius of the circle, in miles.
$center : A KML Point or Location element representing the center of the circle.

Example:
  xquery version "1.0-ml";
  import module namespace kml = "http://earth.google.com/kml/2.0"
         at "/MarkLogic/geospatial/kml.xqy";

  kml:circle(47, 
	 <kml:Point>
		 <kml:coordinates>-127.24,12.5</kml:coordinates>
	 </kml:Point>)
  

kml:geospatial-query(
$regions as cts:region*,
[$options as xs:string*],
[$weight as xs:double?]
)  as   cts:query
Summary:

Returns a cts:query matching points within given regions.

Parameters:
$regions : One or more geographic boxes, circles, polygons, or points. Where multiple boxes, circles, polygons, or points are specified, the query matches if any box, circle, polygon, or point matches.
$options (optional): Options to this query. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"boundaries-included"
Points on boxes' and circles' boundaries are counted as matching. This is the default.
"boundaries-excluded"
Points on boxes' and circles' boundaries are not counted as matching.
"boundaries-latitude-excluded"
Points on boxes' latitude boundaries are not counted as matching.
"boundaries-longitude-excluded"
Points on boxes' longitude boundaries are not counted as matching.
"boundaries-south-excluded"
Points on the boxes' southern boundaries are not counted as matching.
"boundaries-west-excluded"
Points on the boxes' western boundaries are not counted as matching.
"boundaries-north-excluded"
Points on the boxes' northern boundaries are not counted as matching.
"boundaries-east-excluded"
Points on the boxes' eastern boundaries are not counted as matching.
"boundaries-circle-excluded"
Points on circles' boundary are not counted as matching.
$weight (optional): A weight for this query. The default is 1.0.

Usage Notes:

The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).

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).

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.

Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.


Example:
xquery version "1.0-ml";

(: create a document with test data :)
xdmp:document-insert("/points.xml",
<root xmlns:kml="http://earth.google.com/kml/2.0">
  <item><kml:Point><kml:coordinates>30.0,10.5</kml:coordinates></kml:Point></item>
  <item><kml:Point><kml:coordinates>35.34,15.35</kml:coordinates></kml:Point></item>
  <item><kml:Point><kml:coordinates>40.55,5.11</kml:coordinates></kml:Point></item>
</root> );

xquery version "1.0-ml";
import module namespace kml = "http://earth.google.com/kml/2.0"
   at "/MarkLogic/geospatial/kml.xqy";

cts:search(doc("/points.xml")//item, 
  kml:geospatial-query(
    kml:box(
      <kml:LatLongBox>
        <kml:north>20.0</kml:north>
        <kml:south>10.0</kml:south>
        <kml:east>40.0</kml:east>
        <kml:west>35.0</kml:west>
      </kml:LatLongBox>) ))
(:
  returns the following node: 
  <item><kml:Point><kml:coordinates>35.34,15.35</kml:coordinates></kml:Point></item>
:)
,

cts:search(doc("/points.xml")//item, 
  kml:geospatial-query(kml:box(
    <kml:LatLongBox>
      <kml:north>20.0</kml:north>
      <kml:south>10.0</kml:south>
      <kml:east>35.0</kml:east>
      <kml:west>40.0</kml:west>
    </kml:LatLongBox>) ))
(:
  returns the following nodes (wrapping around the Earth):
  <item><kml:Point><kml:coordinates>30.0,10.5</kml:coordinates></kml:Point></item>
:)
 

kml:geospatial-query-from-elements(
$regions as element()*,
[$options as xs:string*],
[$weight as xs:double?]
)  as   cts:query
Summary:

Returns a cts:query matching points within given regions.

Parameters:
$regions : One or more geographic boxes, circles, polygons, or points, represented as KML elements. Where multiple boxes, circles, polygons, or points are specified, the query matches if any box, circle, polygon, or point matches.
$options (optional): Options to this query. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"boundaries-included"
Points on boxes' and circles' boundaries are counted as matching. This is the default.
"boundaries-excluded"
Points on boxes' and circles' boundaries are not counted as matching.
"boundaries-latitude-excluded"
Points on boxes' latitude boundaries are not counted as matching.
"boundaries-longitude-excluded"
Points on boxes' longitude boundaries are not counted as matching.
"boundaries-south-excluded"
Points on the boxes' southern boundaries are not counted as matching.
"boundaries-west-excluded"
Points on the boxes' western boundaries are not counted as matching.
"boundaries-north-excluded"
Points on the boxes' northern boundaries are not counted as matching.
"boundaries-east-excluded"
Points on the boxes' eastern boundaries are not counted as matching.
"boundaries-circle-excluded"
Points on circles' boundary are not counted as matching.
$weight (optional): A weight for this query. The default is 1.0.

Usage Notes:

The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).

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).

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.

Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.

This function will take into account interior polygons, if any, and properly construct the query to account for them.


Example:
xquery version "1.0-ml";

(: create a document with test data :)
xdmp:document-insert("/points.xml",
<root xmlns:kml="http://earth.google.com/kml/2.0">
  <item><kml:Point><kml:coordinates>30.0,10.5</kml:coordinates></kml:Point></item>
  <item><kml:Point><kml:coordinates>35.34,15.35</kml:coordinates></kml:Point></item>
  <item><kml:Point><kml:coordinates>40.55,5.11</kml:coordinates></kml:Point></item>
</root> );

xquery version "1.0-ml";
import module namespace kml = "http://earth.google.com/kml/2.0"
   at "/MarkLogic/geospatial/kml.xqy";

cts:search(doc("/points.xml")//item, 
  kml:geospatial-query-from-elements(
      <kml:LatLongBox>
        <kml:north>20.0</kml:north>
        <kml:south>10.0</kml:south>
        <kml:east>40.0</kml:east>
        <kml:west>35.0</kml:west>
      </kml:LatLongBox>) )
(:
  returns the following node: 
  <item><kml:Point><kml:coordinates>35.34,15.35</kml:coordinates></kml:Point></item>
:)
,

cts:search(doc("/points.xml")//item, 
  kml:geospatial-query-from-elements(
    <kml:LatLongBox>
      <kml:north>20.0</kml:north>
      <kml:south>10.0</kml:south>
      <kml:east>35.0</kml:east>
      <kml:west>40.0</kml:west>
    </kml:LatLongBox>) )
(:
  returns the following nodes (wrapping around the Earth):
  <item><kml:Point><kml:coordinates>30.0,10.5</kml:coordinates></kml:Point></item>
:)
 

kml:interior-polygon(
$points as element(kml:Polygon)
)  as   cts:polygon*
Summary:

Create a sequence of cts:polygon values from a KML Polygon element. The returned polygons represent the interior polygons, if any.

Parameters:
$points : A KML Polygon element representing the polygon.

Example:
   xquery version "1.0-ml";
   import module namespace kml = "http://earth.google.com/kml/2.0"
         at "/MarkLogic/geospatial/kml.xqy";

  kml:interior-polygon(
    <kml:Polygon>
      <kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>
      -127.24,12.5 -127.8,15.25 -126.1,13.45 -127.24,12.5
      </kml:coordinates></kml:LinearRing></kml:outerBoundaryIs>
      <kml:innerBoundaryIs><kml:LinearRing><kml:coordinates>
      -127,13 127,-14 126,-14 127,-13
      </kml:coordinates></kml:LinearRing></kml:innerBoundaryIs>
    </kml:Polygon>
  )
  

kml:point(
$point as element()
)  as   cts:point
Summary:

Create a cts:point value from a KML Point or Location element.

Parameters:
$point : A Point or Location element.

Usage Notes:

The KML Point and Location elements include additional information that is not retained in the cts:point value. In particular, the elevation part of the point value will be dropped. Therefore two KML points at the same latitude and longitude with different elevations will nevertheless have equal cts:point values.

Example:
  xquery version "1.0-ml";
  import module namespace kml = "http://earth.google.com/kml/2.0"
         at "/MarkLogic/geospatial/kml.xqy";

  kml:point(
    <kml:Point>
      <kml:coordinates>-127.24,12.5,10.0</kml:coordinates>
    </kml:Point>)
  ,
  kml:point(
    <kml:Location>
      <kml:latitude>12.5</kml:latitude>
      <kml:longitude>-127.24</kml:longitude>
      <kml:altitude>10.0</kml:altitude>
    </kml:Location>)
  

kml:polygon(
$polygon-or-points as element()+
)  as   cts:polygon
Summary:

Create a cts:polygon value from a KML polygon or a sequence of KML Point or Location elements.

Parameters:
$polygon-or-points : A sequence of Point or Location elements representing the vertices of the polygon or a Polygon itself.

Example:
  xquery version "1.0-ml";
  import module namespace kml = "http://earth.google.com/kml/2.0"
         at "/MarkLogic/geospatial/kml.xqy";

  kml:polygon((
    <kml:Point><kml:coordinates>-127.24,12.5</kml:coordinates></kml:Point>,
    <kml:Point><kml:coordinates>-127.8,15.25</kml:coordinates></kml:Point>,
    <kml:Point><kml:coordinates>-126.1,13.45</kml:coordinates></kml:Point>,
    <kml:Point><kml:coordinates>-127.24,12.5</kml:coordinates></kml:Point>
  ))
  

kml:polygon(
$polygon-or-points as element()+
)  as   cts:polygon
Summary:

Create a cts:polygon value from a KML Polygon element. The polygon returned represents the exterior polygon.

Parameters:
$polygon-or-points : A KML Polygon element representing the polygon.

Example:
  xquery version "1.0-ml";
  import module namespace kml = "http://earth.google.com/kml/2.0"
         at "/MarkLogic/geospatial/kml.xqy";

  kml:polygon(
  <kml:Polygon><kml:outerBoundaryIs><kml:LinearRing>
   <kml:coordinates>-127.24,12.5 -127.8,15.25 -126.1,13.45 -127.24,12.5</kml:coordinates>
  </kml:LinearRing></kml:outerBoundaryIs></kml:Polygon>
  )
  

mcgm:circle(
$radius as xs:double,
$center as element(Dot)
)  as   cts:circle
Summary:

Create a cts:circle value from a radius and MCGM Dot element.

Parameters:
$radius : The radius of the circle, in miles.
$center : A Point element representing the center of the circle.

Example:
  xquery version "1.0-ml";
  import module namespace mcgm = "http://marklogic.com/geospatial/mcgm"
         at "/MarkLogic/geospatial/mcgm.xqy";

  mcgm:circle(47, <Dot Latitude="12.5" Longitude="-127.24"/>)
  

mcgm:geospatial-query(
$regions as cts:region*,
[$options as xs:string*],
[$weight as xs:double?]
)  as   cts:query
Summary:

Returns a cts:query matching points within given regions.

Parameters:
$regions : One or more geographic boxes, circles, polygons, or points. Where multiple boxes, circles, polygons, or points are specified, the query matches if any box, circle, polygon, or point matches.
$options (optional): Options to this query. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"boundaries-included"
Points on boxes' and circles' boundaries are counted as matching. This is the default.
"boundaries-excluded"
Points on boxes' and circles' boundaries are not counted as matching.
"boundaries-latitude-excluded"
Points on boxes' latitude boundaries are not counted as matching.
"boundaries-longitude-excluded"
Points on boxes' longitude boundaries are not counted as matching.
"boundaries-south-excluded"
Points on the boxes' southern boundaries are not counted as matching.
"boundaries-west-excluded"
Points on the boxes' western boundaries are not counted as matching.
"boundaries-north-excluded"
Points on the boxes' northern boundaries are not counted as matching.
"boundaries-east-excluded"
Points on the boxes' eastern boundaries are not counted as matching.
"boundaries-circle-excluded"
Points on circles' boundary are not counted as matching.
$weight (optional): A weight for this query. The default is 1.0.

Usage Notes:

The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).

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).

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.

Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.


Example:
xquery version "1.0-ml";

(: create a document with test data :)
xdmp:document-insert("/points.xml",
<root xmlns:mcgm="http://marklogic.com/geospatial/mcgm">
  <item><Dot Latitude="10.5" Longitude="30.0"/></item>
  <item><Dot Latitude="15.35" Longitude="35.34"/></item>
  <item><Dot Latitude="5.11" Longitude="40.55"/></item>
</root> );

xquery version "1.0-ml";
import module namespace mcgm = "http://marklogic.com/geospatial/mcgm"
   at "/MarkLogic/geospatial/mcgm.xqy";

cts:search(doc("/points.xml")//item, 
  mcgm:geospatial-query(
    cts:box(10.0, 35.0, 20.0, 40.0)))
(:
  returns the following node: 
  <item><Dot Latitude="15.35" Longitude="35.34"/></item>
:)
,

cts:search(doc("/points.xml")//item, 
  mcgm:geospatial-query(cts:box(10.0, 40.0, 20.0, 35.0)))
(:
  returns the following nodes (wrapping around the Earth):
  <item><Dot Latitude="10.5" Longitude="30.0"/></item>
:)
,
   
cts:search(doc("/points.xml")//item, 
  mcgm:geospatial-query(
    cts:box(10.0, 35.0, 20.0, 40.0)))
(:
  returns the following node:
  <item><Dot Latitude="15.35" Longitude="35.34"/></item>
:)


mcgm:geospatial-query-from-elements(
$regions as element(Dot)*,
[$options as xs:string*],
[$weight as xs:double?]
)  as   cts:query
Summary:

Returns a cts:query matching points within given regions.

Parameters:
$regions : One or more geographic regions, represented by MCGM elements. Where multiple regions are specified, the query matches if any region matches.
$options (optional): Options to this query. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"boundaries-included"
Points on boxes' and circles' boundaries are counted as matching. This is the default.
"boundaries-excluded"
Points on boxes' and circles' boundaries are not counted as matching.
"boundaries-latitude-excluded"
Points on boxes' latitude boundaries are not counted as matching.
"boundaries-longitude-excluded"
Points on boxes' longitude boundaries are not counted as matching.
"boundaries-south-excluded"
Points on the boxes' southern boundaries are not counted as matching.
"boundaries-west-excluded"
Points on the boxes' western boundaries are not counted as matching.
"boundaries-north-excluded"
Points on the boxes' northern boundaries are not counted as matching.
"boundaries-east-excluded"
Points on the boxes' eastern boundaries are not counted as matching.
"boundaries-circle-excluded"
Points on circles' boundary are not counted as matching.
$weight (optional): A weight for this query. The default is 1.0.

Usage Notes:

The point value is expressed in the content of the element as a pair of numbers, separated by whitespace and punctuation (excluding decimal points and sign characters).

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).

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.

Special handling occurs at the poles, as all longitudes exist at latitudes +90 and -90.



mcgm:point(
$point as element(Dot)
)  as   cts:point
Summary:

Create a cts:point value from a MCGM Dot element.

Parameters:
$point : A Dot element.

Example:
  xquery version "1.0-ml";
  import module namespace mcgm = "http://marklogic.com/geospatial/mcgm"
         at "/MarkLogic/geospatial/mcgm.xqy";

  mcgm:point(<Dot Latitude="12.5" Longitude="-127.24"/>)
  

mcgm:polygon(
$vertices as element(Dot)*
)  as   cts:polygon
Summary:

Construct a cts:polygon value from a sequence of MCGM Dot elements.

Parameters:
$vertices : A sequence of Dot elements representing the vertices of the polygon.

Example:
  xquery version "1.0-ml";
  import module namespace mcgm = "http://marklogic.com/geospatial/mcgm"
         at "/MarkLogic/geospatial/mcgm.xqy";

  mcgm:polygon(( <Dot Latitude="12.5" Longitude="-127.24"/>,
                 <Dot Latitude="15.25" Longitude="-127.8"/>,
                 <Dot Latitude="13.45" Longitude="-126.1"/>,
                 <Dot Latitude="12.5" Longitude="-127.24"/>
              ))