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

Module: Geospatial Supporting Functions - GML Functions

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