Main Page » Geo Functions

Geo Functions

This module contains functions that may be applied to geometry data conforming to the Open Geospatial Consortium (OGC) Simple Feature (SF) data model. It is based on the EXPath Geo Module and uses the JTS and GeoTools libraries.

The module supports geometries encoded in GML 2 and GML 3.2. The distinction is determined by the namespace of the input document. Geometries in the namespace http://www.opengis.net/gml/3.2 are processed as GML 3.2 and handled internally by the GeoTools XML parser. All other documents are treated as GML 2 and processed using the JTS GML reader. The GML 2 namespace is http://www.opengis.net/gml.

Functions that return GML elements preserve the input version: if the input geometry is GML 2, results are returned in GML 2; if the input geometry is GML 3.2, results are returned in GML 3.2.

For GML 2 input, the following geometry types are accepted: Point, LineString, LinearRing, Polygon, MultiPoint, MultiLineString, MultiPolygon. All nodes passed to the Geo functions must represent a valid geometry. The geometry type MultiGeometry is not supported. Note: Some operations may still produce a MultiGeometry element as a result (e.g., from set-like operations), even though MultiGeometry is not accepted as an input geometry.

For GML 3.2 input, the following geometry types are accepted: Point, LineString, LinearRing, Polygon, MultiPoint, MultiCurve, MultiSurface, MultiGeometry. All nodes passed to the Geo functions must represent a valid geometry.

Conventions

The module must be installed in the repository before it can be used:

REPO INSTALL https://files.basex.org/modules/expath/geo-12.2.jar

In order to use it, it needs to be imported in the header of the query:

import module namespace geo = 'http://expath.org/ns/geo';

All functions in this module are assigned to the http://expath.org/ns/geo namespace, which in the following is assumed to be bound to the geo prefix.

All errors are assigned to the http://expath.org/ns/error namespace, which is statically bound to the experr prefix.

General Functions

geo:dimension

Signature
geo:dimension(
  $geometry  as element(*)
) as xs:integer
Summary Returns the number of dimensions of the supplied geometry $geometry.
Errors
GEO0001 The supplied element is not recognized as a valid geometry.
GEO0002 The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:dimension(
  <gml:Point>
    <gml:coordinates>1,2</gml:coordinates>
  </gml:Point>
)
Returns the dimension of a GML Point geometry.

geo:geometry-type

Signature
geo:geometry-type(
  $geometry  as element(*)
) as xs:QName
SummaryReturns the name of the geometry type of the supplied geometry $geometry. If the geometry is not recognized, an error is raised.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:geometry-type(
  <gml:Point>
    <gml:coordinates>1,2</gml:coordinates>
  </gml:Point>
)
Returns the geometry type name of a GML Point.

geo:srid

Signature
geo:srid(
  $geometry  as element(*)
) as xs:integer
Summary Returns the ID of the Spatial Reference System used by the supplied geometry $geometry. Spatial Reference System information is supported in the simple way defined in the SFS: an SRID is present in each geometry object and can be accessed via basic accessor operations. The SRID is represented as an integer (based on the OpenGIS Simple Features Specifications for SQL).

This differs from the EXPath Geo Module specification, which returns a URI.

Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:srid(
  <gml:Polygon>
    <outerboundaryIs>
      <gml:LinearRing>
        <coordinates>
          -150,50 -150,60 -125,60 -125,50 -150,50
        </coordinates>
      </gml:LinearRing>
    </outerboundaryIs>
  </gml:Polygon>
)
Returns the SRID of a polygon geometry.

geo:envelope

Signature
geo:envelope(
  $geometry  as element(*)
) as element(*)
Summary Returns the gml:Envelope of the supplied geometry $geometry. The envelope is the minimum bounding box of this geometry. If the geometry is empty, an empty Point is returned. If the geometry is a point, a non-empty Point is returned. Otherwise, a Polygon is returned whose points are (minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy), (minx, miny).
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:envelope(
  <gml:LinearRing>
    <gml:coordinates>1,1 20,1 20,20 1,20 1,1</gml:coordinates>
  </gml:LinearRing>
)
Returns the bounding box of a linear ring geometry.

geo:as-text

Signature
geo:as-text(
  $geometry  as element(*)
) as xs:string
SummaryReturns the WKT (Well-known Text) representation of the supplied geometry $geometry.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:as-text(
  <gml:Point>
    <gml:coordinates>1,2</gml:coordinates>
  </gml:Point>
)
Returns the WKT representation of a point geometry.

geo:as-binary

Signature
geo:as-binary(
  $geometry  as element(*)
) as xs:base64Binary
SummaryReturns the WKB (Well-known Binary) representation of the supplied geometry $geometry.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:as-binary(
  <gml:Point>
    <gml:coordinates>1,2</gml:coordinates>
  </gml:Point>
)
Returns the WKB representation of a point geometry.

geo:is-simple

Signature
geo:is-simple(
  $geometry  as element(*)
) as xs:boolean
Summary Returns whether the supplied geometry $geometry is simple and has no anomalous geometric points (i.e., it does not self-intersect and does not pass through the same point more than once (may be a ring)).
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:is-simple(
  <gml:MultiLineString>
    <gml:LineString>
      <gml:coordinates>1,1 0,0 2,1</gml:coordinates>
    </gml:LineString>
    <gml:LineString>
      <gml:coordinates>2,1 3,3 4,4</gml:coordinates>
    </gml:LineString>
  </gml:MultiLineString>
)
Checks if a multilinestring geometry is simple.

geo:boundary

Signature
geo:boundary(
  $geometry  as element(*)
) as element(*)?
Summary Returns the boundary of the supplied geometry $geometry, in GML. The result is a sequence of either gml:Point or gml:LinearRing elements as a GeometryCollection object. For a Point or MultiPoint, the boundary is empty, and the empty sequence is returned.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:boundary(
  <gml:LineString>
    <gml:coordinates>1,1 0,0 2,1</gml:coordinates>
  </gml:LineString>
)
Returns the boundary of a linestring geometry.

geo:num-geometries

Signature
geo:num-geometries(
  $geometry  as element(*)
) as xs:integer
Summary Returns the number of geometries in the geometry collection $geometry, in GML. For geometries that are not collections, 1 is returned.

This implementation is broader than the EXPath specification: it accepts all geometry types, whereas the specification limits the input to collection types (MultiPoint, MultiPolygon, ...).

Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:num-geometries(
  <gml:MultiLineString>
    <gml:LineString>
      <gml:coordinates>1,1 0,0 2,1</gml:coordinates>
    </gml:LineString>
    <gml:LineString>
      <gml:coordinates>2,1 3,3 4,4</gml:coordinates>
    </gml:LineString>
  </gml:MultiLineString>
)
Returns the number of geometries in a multilinestring.

geo:geometry-n

Signature
geo:geometry-n(
  $geometry  as element(*),
  $n         as xs:integer
) as element(*)?
Summary Returns the Nth geometry in the geometry collection $geometry, in GML. For geometries that are not collections, the geometry itself is returned if $n is 1.

This implementation is broader than the EXPath specification: it accepts all geometry types, whereas the specification limits the input to collection types (MultiPoint, MultiPolygon, ...).

Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0004The supplied geometry index is out of range.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $line :=
  <gml:MultiLineString>
    <gml:LineString>
      <gml:coordinates>1,1 0,0 2,1</gml:coordinates>
    </gml:LineString>
    <gml:LineString>
      <gml:coordinates>2,1 3,3 4,4</gml:coordinates>
    </gml:LineString>
  </gml:MultiLineString>
return geo:geometry-n($line, 1)
Returns the first geometry of a multilinestring.

geo:length

Signature
geo:length(
  $geometry  as element(*)
) as xs:double
SummaryReturns the length of the supplied geometry $geometry. If the geometry is a point, 0 is returned.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>1,1 2,1 2,2 1,2 1,1</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>
return geo:length($polygon)
Returns the length of a polygon geometry.

geo:num-points

Signature
geo:num-points(
  $geometry  as element(*)
) as xs:integer
Summary Returns the number of points in the supplied geometry $geometry. It can be used not only for lines, but also for other geometry types such as MultiPolygon. For a Point geometry, 1 is returned.

This differs from the EXPath Geo specification, which limits the input geometry type to lines.

Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:num-points(
  <gml:LineString>
    <gml:coordinates>2,1 3,3 4,4</gml:coordinates>
  </gml:LineString>
)
Returns the number of points in a linestring.

geo:area

Signature
geo:area(
  $geometry  as element(*)
) as xs:double
SummaryReturns the area of the supplied geometry $geometry. For points and lines, 0 is returned.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>1,1 2,1 2,2 1,2 1,1</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>
return geo:area($polygon)
Returns the area of a polygon geometry.

geo:centroid

Signature
geo:centroid(
  $geometry  as element(*)
) as element(*)
Summary Returns the mathematical centroid of the supplied geometry $geometry, as a gml:Point. Based on the definition, this point is not always located on the surface of the geometry.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $point :=
  <gml:MultiPoint>
    <gml:Point><gml:coordinates>1,1</gml:coordinates></gml:Point>
    <gml:Point><gml:coordinates>10,10</gml:coordinates></gml:Point>
    <gml:Point><gml:coordinates>2,2</gml:coordinates></gml:Point>
  </gml:MultiPoint>
return geo:centroid($point)
Returns the centroid of a multipoint geometry.

geo:point-on-surface

Signature
geo:point-on-surface(
  $geometry  as element(*)
) as element(*)
Summary Computes an interior point of the supplied geometry $geometry, as a gml:Point. An interior point is guaranteed to lie in the interior of the Geometry, if it possible to calculate such a point exactly. Otherwise, the point may lie on the boundary of the geometry.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:point-on-surface(
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>1,1 2,1 2,2 1,2 1,1</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>
)
Returns a point on the surface of a polygon geometry.

Spatial Predicate Functions

geo:equals

Signature
geo:equals(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as xs:boolean
SummaryReturns whether $geometry1 is spatially equal to $geometry2.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:equals(
  <gml:LineString><gml:coordinates>1,1 55,99 2,1</gml:coordinates></gml:LineString>,
  <gml:LineString><gml:coordinates>1,1 1,1 55,99 2,1</gml:coordinates></gml:LineString>
)
Checks if two linestring geometries are spatially equal.

geo:disjoint

Signature
geo:disjoint(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as xs:boolean
Summary Returns whether $geometry1 is spatially disjoint from $geometry2 (they have no point in common, they do not intersect each other, and the DE-9IM intersection matrix is FF*FF****).
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $lines :=
  <gml:MultiLineString>
    <gml:LineString><gml:coordinates>1,1 0,0 2,1</gml:coordinates></gml:LineString>
    <gml:LineString><gml:coordinates>2,1 3,3 4,4</gml:coordinates></gml:LineString>
  </gml:MultiLineString>
let $line :=
  <gml:LineString><gml:coordinates>0,0 2,1 3,3</gml:coordinates></gml:LineString>
return geo:disjoint($lines, $line)
Checks whether a multilinestring and a linestring are disjoint.

geo:intersects

Signature
geo:intersects(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as xs:boolean
Summary Returns whether $geometry1 intersects $geometry2. This is true if the two geometries are not disjoint.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $lines :=
  <gml:MultiLineString>
    <gml:LineString><gml:coordinates>1,1 0,0 2,1</gml:coordinates></gml:LineString>
    <gml:LineString><gml:coordinates>2,1 3,3 4,4</gml:coordinates></gml:LineString>
  </gml:MultiLineString>
let $line :=
  <gml:LineString><gml:coordinates>0,0 2,1 3,3</gml:coordinates></gml:LineString>
return geo:intersects($lines, $line)
Checks whether a multilinestring and a linestring intersect.

geo:touches

Signature
geo:touches(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as xs:boolean
SummaryReturns whether $geometry1 spatially touches $geometry2.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $line :=
  <gml:LinearRing><gml:coordinates>1,1 2,1 5,3 1,1</gml:coordinates></gml:LinearRing>
let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing><gml:coordinates>1,1 2,1 5,3 1,1</gml:coordinates></gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>
return geo:touches($line, $polygon)
Checks whether a ring touches a polygon.

geo:crosses

Signature
geo:crosses(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as xs:boolean
Summary Returns whether $geometry1 spatially crosses $geometry2, i.e., the geometries have some but not all interior points in common. Returns true if the DE-9IM intersection matrix matches one of the following patterns:

T*T****** (for P/L, P/A, and L/A situations)

T*****T** (for L/P, A/P, and A/L situations)

0******** (for L/L situations)

Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $line :=
  <gml:LinearRing><gml:coordinates>1,1 2,1 5,3 1,1</gml:coordinates></gml:LinearRing>
let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing><gml:coordinates>1,1 2,1 5,3 1,1</gml:coordinates></gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>
return geo:crosses($line, $polygon)
Checks whether a ring crosses a polygon.

geo:within

Signature
geo:within(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as xs:boolean
SummaryReturns whether $geometry1 is spatially within $geometry2.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $line :=
  <gml:LinearRing><gml:coordinates>1,1 2,1 5,3 1,1</gml:coordinates></gml:LinearRing>
let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing><gml:coordinates>1,1 2,1 5,3 1,1</gml:coordinates></gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>
return geo:within($line, $polygon)
Checks whether a ring is within a polygon.

geo:contains

Signature
geo:contains(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as xs:boolean
Summary Returns whether $geometry1 spatially contains $geometry2. Returns true if geo:within($geometry2, $geometry1) is true.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $point :=
  <gml:Point><gml:coordinates>1,1</gml:coordinates></gml:Point>
let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing><gml:coordinates>1,1 2,1 5,3 1,1</gml:coordinates></gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>
return geo:contains($polygon, $point)
Checks whether a polygon contains a point.

geo:overlaps

Signature
geo:overlaps(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as xs:boolean
SummaryReturns whether $geometry1 spatially overlaps $geometry2.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $polygon1 :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>1,1 20,1 20,20 30,20 30,30 1,30 1,1</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
    <gml:innerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>2,2 3,2 3,3 2,3 2,2</gml:coordinates>
      </gml:LinearRing>
    </gml:innerBoundaryIs>
    <gml:innerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>10,10 19,10 19,19 10,19 10,10</gml:coordinates>
      </gml:LinearRing>
    </gml:innerBoundaryIs>
  </gml:Polygon>

let $polygon2 :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>1,1 2,1 5,3 1,1</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>

return geo:overlaps($polygon1, $polygon2)
Checks whether two polygons overlap.

geo:relate

Signature
geo:relate(
  $geometry1           as element(*),
  $geometry2           as element(*),
  $intersectionMatrix  as xs:string
) as xs:boolean
Summary Returns whether the relationships between the boundaries, interiors, and exteriors of $geometry1 and $geometry2 match the pattern specified in $intersectionMatrix. The matrix must have a length of 9 characters.

The values in the DE-9IM matrix can be:

  • T: the intersection is non-empty
  • F: the intersection is empty
  • *: any result
  • 0, 1, 2: expected dimension of the intersection result (point, curve, surface)
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0006The supplied intersection matrix is invalid.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $point :=
  <gml:Point><gml:coordinates>18,11</gml:coordinates></gml:Point>
let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>10,10 20,10 30,40 20,40 10,10</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>

return geo:relate($point, $polygon, "TF*FFFTT*")
Checks a spatial relationship between a point and a polygon using a DE-9IM matrix pattern.

Analysis Functions

geo:distance

Signature
geo:distance(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as xs:double
Summary Returns the shortest distance between $geometry1 and $geometry2, in the units of the spatial reference system of $geometry1. The distance is defined as the distance between a point on each of the geometries.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $line :=
  <gml:LinearRing>
    <gml:coordinates>10,400 20,200 30,100 20,100 10,400</gml:coordinates>
  </gml:LinearRing>
let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>10,10 20,10 30,40 20,40 10,10</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>

return geo:distance($line, $polygon)
Returns the distance between a linear ring and a polygon.

geo:buffer

Signature
geo:buffer(
  $geometry  as element(*),
  $distance  as xs:double
) as element(*)?
Summary Returns a polygonal geometry representing the buffer of width $distance around the supplied geometry $geometry, in the spatial reference system of the geometry. The buffer of a geometry is the Minkowski sum (or difference) of the geometry with a disc of radius abs($distance). The buffer is constructed using 8 segments per quadrant to approximate curves.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>10,10 20,10 30,40 20,40 10,10</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>

return geo:buffer($polygon, 3)
Returns a buffer polygon around the supplied polygon geometry.

geo:convex-hull

Signature
geo:convex-hull(
  $geometry  as element(*)
) as element(*)?
Summary Returns the convex hull geometry of the supplied geometry $geometry, in GML. The function returns the object of the smallest possible dimension.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:convex-hull(
  <gml:LinearRing>
    <gml:coordinates>10,400 20,200 30,100 20,100 10,400</gml:coordinates>
  </gml:LinearRing>
)
Returns the convex hull of a linear ring geometry.

geo:intersection

Signature
geo:intersection(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as element(*)?
Summary Returns the intersection geometry of $geometry1 and $geometry2, in GML, or the empty sequence if there is no intersection.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $line :=
  <gml:LinearRing>
    <gml:coordinates>10,400 20,200 30,100 20,100 10,400</gml:coordinates>
  </gml:LinearRing>
let $point :=
  <gml:Point><gml:coordinates>1.00,1.00</gml:coordinates></gml:Point>

return geo:intersection($line, $point)
Returns the intersection of a linear ring and a point.

geo:union

Signature
geo:union(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as element(*)?
SummaryReturns the union geometry of $geometry1 and $geometry2, in GML.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $line :=
  <gml:LinearRing>
    <gml:coordinates>10,400 20,200 30,100 20,100 10,400</gml:coordinates>
  </gml:LinearRing>
let $point :=
  <gml:Point><gml:coordinates>1.00,1.00</gml:coordinates></gml:Point>

return geo:union($line, $point)
Returns the union of a linear ring and a point.

geo:difference

Signature
geo:difference(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as element(*)?
Summary Returns the difference of $geometry1 and $geometry2, in GML, or the empty sequence if the difference is empty (i.e., the set of points in $geometry1 that are not included in $geometry2).
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $point :=
  <gml:Point><gml:coordinates>1.00,1.00</gml:coordinates></gml:Point>
let $line :=
  <gml:LineString><gml:coordinates>2,1 3,3 4,4</gml:coordinates></gml:LineString>

return geo:difference($point, $line)
Returns the difference of a point and a linestring.

geo:sym-difference

Signature
geo:sym-difference(
  $geometry1  as element(*),
  $geometry2  as element(*)
) as element(*)?
Summary Returns the symmetric difference of $geometry1 and $geometry2, in GML, or the empty sequence if the difference is empty (i.e., the set of points that are included in one of the geometries but not in the other).
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $point :=
  <gml:Point><gml:coordinates>1.00,1.00</gml:coordinates></gml:Point>
let $line :=
  <gml:LineString><gml:coordinates>2,1 3,3 4,4</gml:coordinates></gml:LineString>

return geo:sym-difference($point, $line)
Returns the symmetric difference of a point and a linestring.

Functions Specific to Geometry Type

geo:x

Signature
geo:x(
  $point  as element(*)
) as xs:double
SummaryReturns the x coordinate of the supplied point $point. A point must have an x coordinate.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:x(
  <gml:Point><gml:coordinates>1.00,1.00</gml:coordinates></gml:Point>
)
Returns the x coordinate of a point.

geo:y

Signature
geo:y(
  $point  as element(*)
) as xs:double
Summary Returns the y coordinate of the supplied point $point. If the point does not have a y coordinate, NaN is returned.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:y(
  <gml:Point><gml:coordinates>1.00,2.00</gml:coordinates></gml:Point>
)
Returns the y coordinate of a point.

geo:z

Signature
geo:z(
  $point  as element(*)
) as xs:double
Summary Returns the z coordinate of the supplied point $point. If the point does not have a z coordinate, NaN is returned.

This differs from the EXPath Geo Module specification, which returns an empty sequence.

Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:z(
  <gml:Point><gml:coordinates>1.00,1.00,3.00</gml:coordinates></gml:Point>
)
Returns the z coordinate of a point.

geo:start-point

Signature
geo:start-point(
  $line  as element(*)
) as element(*)
Summary Returns the starting point of the supplied line $line. The input must be a single line geometry (LineString or LinearRing).
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0003The supplied element must be a line; other geometries are not accepted.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:start-point(
  <gml:LineString>
    <gml:coordinates>2,1 3,3 4,4</gml:coordinates>
  </gml:LineString>
)
Returns the start point of a linestring.

geo:end-point

Signature
geo:end-point(
  $line  as element(*)
) as element(*)
Summary Returns the ending point of the supplied line $line. The input must be a single line geometry (LineString or LinearRing).
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0003The supplied element must be a line; other geometries are not accepted.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:end-point(
  <gml:LineString>
    <gml:coordinates>2,1 3,3 4,4</gml:coordinates>
  </gml:LineString>
)
Returns the end point of a linestring.

geo:is-closed

Signature
geo:is-closed(
  $line  as element(*)
) as xs:boolean
Summary Returns whether the supplied line $line forms a closed loop (i.e., the start point and end point are identical). The input must be a line geometry (LineString or LinearRing) or a MultiLineString.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0003The supplied element must be a line; other geometries are not accepted.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:is-closed(
  <gml:LineString>
    <gml:coordinates>2,1 3,3 4,4</gml:coordinates>
  </gml:LineString>
)
Checks whether a linestring is closed.

geo:is-ring

Signature
geo:is-ring(
  $line  as element(*)
) as xs:boolean
Summary Returns whether the supplied line $line is a ring (i.e., a single closed loop). The input must be a single line geometry (LineString or LinearRing).
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0003The supplied element must be a line; other geometries are not accepted.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:is-ring(
  <gml:LineString>
    <gml:coordinates>2,1 3,3 4,4</gml:coordinates>
  </gml:LineString>
)
Checks whether a linestring is a ring.

geo:point-n

Signature
geo:point-n(
  $line  as element(*),
  $n     as xs:integer
) as element(*)
Summary Returns the Nth point in the supplied line $line. The input must be a single line geometry (LineString or LinearRing).
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0003The supplied element must be a line; other geometries are not accepted.
GEO0004The supplied point index is out of range.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $line :=
  <gml:LineString>
    <gml:coordinates>2,1 3,3 4,4</gml:coordinates>
  </gml:LineString>
return geo:point-n($line, 1)
Returns the first point of a linestring.

geo:exterior-ring

Signature
geo:exterior-ring(
  $polygon  as element(*)
) as element(*)
SummaryReturns the outer ring of the supplied polygon $polygon as a gml:LineString.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0003The supplied element must be a polygon; other geometries are not accepted.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>10,10 20,10 30,40 20,40 10,10</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
  </gml:Polygon>
return geo:exterior-ring($polygon)
Returns the exterior ring of a polygon.

geo:num-interior-ring

Signature
geo:num-interior-ring(
  $polygon  as element(*)
) as xs:integer
SummaryReturns the number of interior rings of the supplied polygon $polygon.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0003The supplied element must be a polygon; other geometries are not accepted.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

geo:num-interior-ring(
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>1,1 20,1 20,20 30,20 30,30 1,30 1,1</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
    <gml:innerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>2,2 3,2 3,3 2,3 2,2</gml:coordinates>
      </gml:LinearRing>
    </gml:innerBoundaryIs>
    <gml:innerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>10,10 19,10 19,19 10,19 10,10</gml:coordinates>
      </gml:LinearRing>
    </gml:innerBoundaryIs>
  </gml:Polygon>
)
Counts interior rings of a polygon with two holes.

geo:interior-ring-n

Signature
geo:interior-ring-n(
  $polygon  as element(*),
  $n        as xs:integer
) as element(*)
SummaryReturns the Nth interior ring of the supplied polygon $polygon as a gml:LineString.
Errors
GEO0001The supplied element is not recognized as a valid geometry.
GEO0002The supplied geometry cannot be read by the underlying geometry reader.
GEO0003The supplied element must be a polygon; other geometries are not accepted.
GEO0004The supplied ring index is out of range.
GEO0005The output object cannot be written as an element by the underlying geometry writer.
Examples
import module namespace geo = 'http://expath.org/ns/geo';
declare namespace gml = 'http://www.opengis.net/gml';

let $polygon :=
  <gml:Polygon>
    <gml:outerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>1,1 20,1 20,20 30,20 30,30 1,30 1,1</gml:coordinates>
      </gml:LinearRing>
    </gml:outerBoundaryIs>
    <gml:innerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>2,2 3,2 3,3 2,3 2,2</gml:coordinates>
      </gml:LinearRing>
    </gml:innerBoundaryIs>
    <gml:innerBoundaryIs>
      <gml:LinearRing>
        <gml:coordinates>10,10 19,10 19,19 10,19 10,10</gml:coordinates>
      </gml:LinearRing>
    </gml:innerBoundaryIs>
  </gml:Polygon>
return geo:interior-ring-n($polygon, 1)
Returns the first interior ring of a polygon.

Errors

CodeDescription
GEO0001Unrecognized Geo type.
GEO0002The input GML node cannot be read by GMLreader.
GEO0003Input geometry is not an appropriate geometry for this function.
GEO0004The input index is out of range.
GEO0005The result geometry can not be written by GMLwriter.
GEO0006The input matrix is invalid.

Changelog

Version 13.0
  • Added: Module re-added with GML 3 support.

⚡Generated with XQuery