This page was generated
July 7, 2010
4:03 PM
XQuery Built-In and Modules Function Reference

Built-In: Search - Geospatial Functions

The geospatial built-in functions are XQuery functions defined to operate on geospatial values.
Function Summary
cts:box Returns a geospatial box value.
cts:box-east Returns a box's eastern boundary.
cts:box-north Returns a box's northern boundary.
cts:box-south Returns a box's southern boundary.
cts:box-west Returns a box's western boundary.
cts:circle Returns a geospatial circle value.
cts:circle-center Returns a circle's center point.
cts:circle-radius Returns a circle's radius.
cts:distance Returns the distance (in miles) between two points.
cts:point Returns a point value.
cts:point-latitude Returns a point's latitude value.
cts:point-longitude Returns a point's longitude value.
cts:polygon Returns a geospatial polygon value.
cts:polygon-vertices Returns a polygon's vertices.
Function Detail
cts:box(
$south as xs:float,
$west as xs:float,
$north as xs:float,
$east as xs:float
)  as  cts:box
Summary:

Returns a geospatial box value.

Parameters:
$south : The southern boundary of the box.
$west : The western boundary of the box.
$north : The northern boundary of the box.
$east : The eastern boundary of the box.

Example:
cts:box(-122, 78, 30, 45)
=> [-122, 78, 30, 45] (as a cts:box)

cts:box-east(
$box as cts:box
)  as  xs:float
Summary:

Returns a box's eastern boundary.

Parameters:
$box : The box.

Example:
cts:box-east(cts:box(-122, 78, 30, 45))
=> 45

cts:box-north(
$box as cts:box
)  as  xs:float
Summary:

Returns a box's northern boundary.

Parameters:
$box : The box.

Example:
cts:box-north(cts:box(-122, 78, 30, 45))
=> 30

cts:box-south(
$box as cts:box
)  as  xs:float
Summary:

Returns a box's southern boundary.

Parameters:
$box : The box.

Example:
cts:box-south(cts:box(-122, 78, 30, 45))
=> -122

cts:box-west(
$box as cts:box
)  as  xs:float
Summary:

Returns a box's western boundary.

Parameters:
$box : The box.

Example:
cts:box-west(cts:box(-122, 78, 30, 45))
=> 78

cts:circle(
$radius as xs:float,
$center as cts:point
)  as  cts:circle
Summary:

Returns a geospatial circle value.

Parameters:
$radius : The radius of the circle. The units for the radius is determined at runtime by the cts:query options (miles is currently the only option).
$center : A point representing the center of the circle.

Example:
cts:circle(20, cts:point(37.655983, -122.425525))
=> @20 37.656,-122.426 (as a cts:circle)

cts:circle-center(
$circle as cts:circle
)  as  cts:point
Summary:

Returns a circle's center point.

Parameters:
$circle : The circle.

Example:
cts:circle-center(cts:circle(20, cts:point(37.655983, -122.425525)))
=> 37.655983, -122.425525 (as a cts:point)

cts:circle-radius(
$circle as cts:circle
)  as  xs:float
Summary:

Returns a circle's radius.

Parameters:
$circle : The circle.

Example:
cts:circle-radius(cts:circle(20, cts:point(37.655983, -122.425525)))
=> 20

cts:distance(
$p1 as cts:point,
$p2 as cts:point,
[$options as xs:string*]
)  as  xs:double
Summary:

Returns the distance (in miles) between two points.

Parameters:
$p1 : The first point.
$p2 : The second point.
$options (optional): Options for the operation. The default is ().

Options include:

"coordinate-system=wgs84"
Use the WGS84 coordinate system.
"units=miles"
Distance is measured in miles.

Example:
let $sf := cts:point(37, -122)
let $ny := cts:point(40, -73)
return
cts:distance($sf, $ny)

=> 2626.42211914063

cts:point(
$latitude as xs:float,
$longitude as xs:float
)  as  cts:point
Summary:

Returns a point value.

Parameters:
$latitude : The latitude of the point.
$longitude : The longitude of the point.

Example:
  cts:point(0.373899653086420E+02, -0.122078578406509E+03)

cts:point-latitude(
$point as cts:point
)  as  xs:float
Summary:

Returns a point's latitude value.

Parameters:
$point : The point.

Example:
  let $point := cts:point(37.270556, -118.672778)
  return
  cts:point-latitude($point)

cts:point-longitude(
$point as cts:point
)  as  xs:float
Summary:

Returns a point's longitude value.

Parameters:
$point : The point.

Example:
  let $point := cts:point(37.270556, -118.672778)
  return
  cts:point-longitude($point)

cts:polygon(
$vertices as cts:point*
)  as  cts:polygon
Summary:

Returns a geospatial polygon value.

Parameters:
$vertices : The vertices of the polygon, given in order. No edge may cover more than 180 degrees of either latitude or longitude. The polygon as a whole may not encompass both poles. These constraints are necessary to ensure an unambiguous interpretation of the polygon. There must be at least three vertices. The first vertex should be identical to the last vertex to close the polygon. vertexes.

Example:
  (: this polygon approximates the 94041 zip code :)
  let $points := (cts:point(0.373899653086420E+02, -0.122078578406509E+03),
    cts:point(0.373765400000000E+02, -0.122063772000000E+03),
    cts:point(0.373781400000000E+02, -0.122067972000000E+03),
    cts:point(0.373825650000000E+02, -0.122068365000000E+03),
    cts:point(0.373797400000000E+02, -0.122072172000000E+03),
    cts:point(0.373899400000000E+02, -0.122092573000000E+03),
    cts:point(0.373941400000000E+02, -0.122095573000000E+03),
    cts:point(0.373966400000000E+02, -0.122094173000000E+03),
    cts:point(0.373958400000000E+02, -0.122092373000000E+03),
    cts:point(0.374004400000000E+02, -0.122091273000000E+03),
    cts:point(0.374004400000000E+02, -0.122091273000000E+03),
    cts:point(0.373873400000000E+02, -0.122057872000000E+03),
    cts:point(0.373873400000000E+02, -0.122057872000000E+03),
    cts:point(0.373854400000000E+02, -0.122052672000000E+03),
    cts:point(0.373833400000000E+02, -0.122053372000000E+03),
    cts:point(0.373819400000000E+02, -0.122057572000000E+03),
    cts:point(0.373775400000000E+02, -0.122060872000000E+03),
    cts:point(0.373765400000000E+02, -0.122063772000000E+03) )
  return
  cts:polygon($points)

cts:polygon-vertices(
$polygon as cts:polygon
)  as  cts:point*
Summary:

Returns a polygon's vertices. The first vertex and last vertex will always be the same.

Parameters:
$polygon : The polygon.

Example:
  let $node := 
    <polygon zip="94041">
       0.373899653086420E+02,       -0.122078578406509E+03
       0.373765400000000E+02,       -0.122063772000000E+03
       0.373781400000000E+02,       -0.122067972000000E+03
       0.373825650000000E+02,       -0.122068365000000E+03
       0.373797400000000E+02,       -0.122072172000000E+03
       0.373899400000000E+02,       -0.122092573000000E+03
       0.373941400000000E+02,       -0.122095573000000E+03
       0.373966400000000E+02,       -0.122094173000000E+03
       0.373958400000000E+02,       -0.122092373000000E+03
       0.374004400000000E+02,       -0.122091273000000E+03
       0.374004400000000E+02,       -0.122091273000000E+03
       0.373873400000000E+02,       -0.122057872000000E+03
       0.373873400000000E+02,       -0.122057872000000E+03
       0.373854400000000E+02,       -0.122052672000000E+03
       0.373833400000000E+02,       -0.122053372000000E+03
       0.373819400000000E+02,       -0.122057572000000E+03
       0.373775400000000E+02,       -0.122060872000000E+03
       0.373765400000000E+02,       -0.122063772000000E+03
    </polygon>
    return
    cts:polygon-vertices(cts:polygon(fn:data($node)))