http://expath.org/ns/geo

View as XML or JSON.

Function library providing geo processing using Simple Features api API GMLSF format. It uses the GEOS third party library, license LGPL. Version 3.2.2 or above is required.

The data format supported is GML SF profile 0/1. This is a subset of GML, and covers the basic geometries of Point, Line and Surface and collections of those. GMLSF nodes have the namespace "http://www.opengis.net/gml".

Possible GMLSF geometric structures are:

Point
<gml:Point [srsDimension='2|3']?>
    <gml:pos [srsDimension='2|3']?>double_x double_y </gml:pos>
  </gml:Point>
LineString
<gml:LineString [srsDimension='2|3']?>
    <gml:posList [srsDimension='2|3']?> double_x1 double_y1 double_x2 double_y2 ... </gml:posList>
  </gml:LineString>
Curve
<gml:Curve [srsDimension='2|3']?>
    <gml:segments>
    [<gml:LineStringSegment interpolation="linear" [srsDimension='2|3']?>
       <gml:posList [srsDimension='2|3']?> double_x1 double_y1 double_x2 double_y2 ... </gml:posList>;
     <gml:LineStringSegment>]*
    </gml:segments>
  </gml:Curve>
LinearRing
<gml:LinearRing [srsDimension='2|3']?>
    <gml:posList [srsDimension='2|3']?> double_x1 double_y1 double_x2 double_y2 ... </gml:posList>
  </gml:LinearRing>
Surface
<gml:Surface [srsDimension='2|3']?>
    <gml:patches>
    [<gml:PolygonPatch [srsDimension='2|3']?>
       <gml:exterior>
         <gml:LinearRing> ... </gml:LinearRing>
       </gml:exterior>
       <gml:interior>
         <gml:LinearRing> ... </gml:LinearRing>
       </gml:interior>]*
     </gml:PolygonPatch>]*
    </gml:patches>
  </gml:Surface>
Polygon
<gml:Polygon [srsDimension='2|3']?>
    <gml:exterior>
      <gml:LinearRing> ... </gml:LinearRing>
    </gml:exterior>
    [<gml:interior>
       <gml:LinearRing> ... </gml:LinearRing>
     </gml:interior>]*
  </gml:Polygon>
MultiPoint
<gml:MultiPoint [srsDimension='2|3']?>
    [<gml:Point> ... </gml:Point>]*
  </gml:MultiPoint>
MultiCurve
<gml:MultiCurve [srsDimension='2|3']?>
    [<gml:LineString> ... </gml:LineString>]*
  </gml:MultiCurve>
MultiSurface
<gml:MultiSurface [srsDimension='2|3']?>
    [<gml:Polygon> ... </gml:Polygon>]*
  </gml:MultiSurface>
  
MultiGeometry (this is from GML 3 schema)
<gml:MultiGeometry [srsDimension='2|3']?>
     [<gml:geometryMember>
          ...one geometry...
     </gml:geometryMember>]*
    [<gml:geometryMembers>
      ...a list of geometries...
    </gml:geometryMembers>]?
  </gml:MultiGeometry>

Note: When using gml:posList, it is possible to replace this element with a list of gml:pos.

Note: XLink referencing is not supported.

Note: The srsDimension optional attribute specifies the coordinate dimension. The default value is 2 (for 2D). Another possible value is 3 (for 3D) in which case every point has to have three double values (x, y, z). This is an extension borrowed from GML 3 spec.

The operations made on 3D objects work only on x-y coordinates, the z coordinate is not taken into account. When returning the result, the original z-coordinates of the points are preserved. For computed points, the z-coordinate is interpolated.

The coordinates values have to be in cartesian coordinates, not in polar coordinates. Converting between coordinate systems and doing projections from polar to cartesian is outside the scope of this geo module.

For operations between two geometries, the DE-9IM matrix is used. The DE-9IM matrix is defined like this:

Interior Boundary Exterior
Interior dim(intersection of interior1 and interior2) dim(intersection of interior1 and boundary2) dim(intersection of interior1 and exterior2)
Boundary dim(intersection of boundary1 and interior2) dim(intersection of boundary1 and boundary2) dim(intersection of boundary1 and exterior2)
Exterior dim(intersection of exterior1 and interior2) dim(intersection of exterior1 and boundary2) dim(intersection of exterior1 and exterior2)

The values in the DE-9IM can be T, F, *, 0, 1, 2.

- T means the intersection gives a non-empty result.

- F means the intersection gives an empty result.

- * means any result.

- 0, 1, 2 gives the expected dimension of the result (point, curve, surface)

Function Summary

area ($geometry as element(*)) as xs:double external

Returns the area of this geometry.

as-binary ($geometry as element(*)) as xs:base64Binary external

Return the Well-known Binary Representation of Geometry.

as-text ($geometry as element(*)) as xs:string external

Return the Well-known Text Representation of Geometry.

boundary ($geometry as element(*)) as element(*)* external

A boundary is a set that represents the limit of an geometry.

bounding-polygons ($polyhedral-surface as element(gml:Surface), $polygon as element(*)) as element(gml:PolygonPatch)* external

Return the list of PolygonPatches that share a boundary with the given $polygon.

buffer ($geometry as element(*), $distance as xs:double) as element(*) external

Returns a polygon that represents all Points whose distance from this geometric object is less than or equal to distance.

centroid ($geometry as element(*)) as element(gml:Point) external

Returns a Point that is the mathematical centroid of this geometry.

contains ($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 contains geometry2.

convex-hull ($geometry as element(*)) as element(*) external

Returns the smallest convex Polygon that contains all the points in the Geometry.

coordinate-dimension ($geometry as element(*)) as xs:integer external

Return the coordinate dimension of the geo object, as specified in the srsDimension attribute.

covers ($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 covers geometry2.

crosses ($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 crosses geometry2.

difference ($geometry1 as element(*), $geometry2 as element(*)) as element(*)? external

Returns a geometric object that represents the Point set difference of geometry1 and geometry2.

dimension ($geometry as element(*)) as xs:integer external

Return the dimension of the geo object.

disjoint ($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 does not touch or intersects geometry2.

distance ($geometry1 as element(*), $geometry2 as element(*)) as xs:double external

Compute the shortest distance between any two Points in geometry1 and geometry2.

end-point ($line as element(*)) as element(gml:Point) external

Returns the end Point of a line.

envelope ($geometry as element(*)) as element(gml:Envelope) external

The envelope is the minimum bounding box of this geometry.

equals ($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if the two geometries are equal.

exterior-ring ($polygon as element(gml:Polygon)) as element(gml:LinearRing) external

Return the exterior ring of a Polygon.

geometry-n ($geometry as element(*), $n as xs:unsignedInt) as element(*) external

Return the n-th geometry in the collection.

geometry-type ($geometry as element(*)) as xs:QName? external

Return the qname type of geo object.

interior-ring-n ($polygon as element(gml:Polygon), $n as xs:unsignedInt) as element(gml:LinearRing) external

Return the n-th interior ring of a Polygon.

intersection ($geometry1 as element(*), $geometry2 as element(*)) as element(*)? external

Returns a geometric object that represents the Point set intersection of geometry1 and geometry2.

intersects ($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 intersects geometry2.

is-3d ($geometry as element(*)) as xs:boolean external

Checks if this geometric object is 2D or 3D, as specified in srsDimension optional attribute.

is-closed ($geom as element(*)) as xs:boolean external

Checks if the line is closed loop.

is-empty ($geometry as element(*)?) as xs:boolean external

Checks if the argument is empty or not and if it is a valid geometry or not.

is-measured ($geometry as element(*)) as xs:boolean external

Checks if this geometric object has measurements.

is-ring ($line as element(*)) as xs:boolean external

Checks if the line is a ring.

is-simple ($geometry as element(*)) as xs:boolean external

Checks if this geometric object has no anomalous geometric points, such as self intersection or self tangency.

is-within-distance ($geometry1 as element(*), $geometry2 as element(*), $distance as xs:double) as xs:boolean external

Checks if geometry2 is within a certain distance of geometry1.

length ($geometry as element(*)) as xs:double external

Returns the length of the lines of this geometry.

m ($point as element(gml:Point)) as xs:double? external

Should return the Measure of a Point, but is not implemented, because it is not specified in GMLSF.

num-geometries ($geometry as element(*)) as xs:unsignedInt external

Return the number of geometries in the collection, or 1 for non-collection.

num-interior-ring ($polygon as element(gml:Polygon)) as xs:unsignedInt external

Return the number of interior rings of a Polygon.

num-patches ($polyhedral-surface as element(gml:Surface)) as xs:integer external

Return the number of surface patches inside a gml:Surface.

num-points ($line as element(*)) as xs:unsignedInt external

Return the number of Points in a line.

overlaps ($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 overlaps with geometry2.

patch-n ($polyhedral-surface as element(gml:Surface), $n as xs:unsignedInt) as element(gml:PolygonPatch) external

Return the n-th Surface patch of a Surface.

point-n ($line as element(*), $n as xs:unsignedInt) as element(gml:Point) external

Return the n-th Point in a line.

point-on-surface ($geometry as element(*)) as element(gml:Point) external

Returns a Point that is interior of this geometry.

relate ($geometry1 as element(*), $geometry2 as element(*), $intersection_matrix as xs:string) as xs:boolean external

Checks if geometry1 relates with geometry2 relative to a DE-9IM matrix.

srid ($geometry as element(*)) as xs:anyURI? external

Return the srid URI of geo object.

start-point ($line as element(*)) as element(gml:Point) external

Returns the start Point of a line.

sym-difference ($geometry1 as element(*), $geometry2 as element(*)) as element(*)? external

Returns a geometric object that represents the Point set symmetric difference of geometry1 and geometry2.

touches ($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 touches geometry2.

union ($geometry1 as element(*), $geometry2 as element(*)) as element(*) external

Returns a geometric object that represents the Point set union of geometry1 and geometry2.

within ($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 is within geometry2.

x ($point as element(gml:Point)) as xs:double external

Returns the X coordinate of a Point.

y ($point as element(gml:Point)) as xs:double external

Returns the Y coordinate of a Point.

z ($point as element(gml:Point)) as xs:double? external

Returns the Z coordinate of a Point, if is 3D.

Functions

area#1

declare  function geo:area($geometry as element(*)) as xs:double external

Returns the area of this geometry.

Returns zero for Point and Lines.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:double
geometry area as xs:double.

as-binary#1

declare  function geo:as-binary($geometry as element(*)) as xs:base64Binary external

Return the Well-known Binary Representation of Geometry.

This is defined in the Simple Features spec from OGC.

gml:Curve is represented as MultiLineString.

gml:Surface is represented as MultiPolygon.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:base64Binary
the Well-known Binary Representation for the geo object as base64.

as-text#1

declare  function geo:as-text($geometry as element(*)) as xs:string external

Return the Well-known Text Representation of Geometry.

This is defined in the Simple Features spec from OGC.

gml:Curve is represented as MultiLineString.

gml:Surface is represented as MultiPolygon.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:string
the Well-known Text Representation for the geo object.

boundary#1

declare  function geo:boundary($geometry as element(*)) as element(*)* external

A boundary is a set that represents the limit of an geometry.

For a Point or MultiPoint, the boundary is the empty geometry, nothing is returned.

For a LineString, the boundary is the MultiPoint set of start point and end point.

For a LinearRing, the boundary is empty MultiPoint.

For a Curve, it is treated as a MultiCurve.

For a Polygon, the boundary is the MultiCurve set of exterior and interior rings.

For a Surface, the boundary is the MultiCurve set formed from the exterior ring of all patches seen as a single surface and all the interior rings from all patches.

For MultiCurve, the boundary is the MultiPoint set of all start and end points that appear in an odd number of linestrings.

For MultiGeometry, a sequence of boundaries is returned, corresponding to each child geometry.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:LinearRing, gml:Curve, gml:Polygon, gml:Surface, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

element(*)*
the boundary of a Geometry as a set of Geometries of the next lower dimension.

bounding-polygons#2

declare  function geo:bounding-polygons($polyhedral-surface as element(gml:Surface), $polygon as element(*)) as element(gml:PolygonPatch)* external

Return the list of PolygonPatches that share a boundary with the given $polygon.

The gml:PolygonPatch has the same content as gml:Polygon.

This function tests the exterior ring of each polygon patch if it overlaps with the exterior ring of the given polygon.

Parameters

polyhedral-surface as element(gml:Surface)
node of one of GMLSF objects: gml:Surface
polygon as element(*)
, of type gml:Polygon or gml:PolygonPatch

Returns

element(gml:PolygonPatch)*
the list of neibourghing gml:PolygonPatch-es

buffer#2

declare  function geo:buffer($geometry as element(*), $distance as xs:double) as element(*) external

Returns a polygon that represents all Points whose distance from this geometric object is less than or equal to distance.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
distance as xs:double
the distance from geometry, expressed in units of the current coordinate system

Returns

element(*)
new geometry surrounding the input geometry.

centroid#1

declare  function geo:centroid($geometry as element(*)) as element(gml:Point) external

Returns a Point that is the mathematical centroid of this geometry.

The result is not guaranteed to be on the surface.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

element(gml:Point)
centroid Point.

contains#2

declare  function geo:contains($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 contains geometry2.

Returns true if within(geometry2, geometry1) is true.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if geometry1 contains geometry2.

convex-hull#1

declare  function geo:convex-hull($geometry as element(*)) as element(*) external

Returns the smallest convex Polygon that contains all the points in the Geometry.

Actually returns the object of smallest dimension possible (possible Point or LineString).

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

element(*)
the convex polygon node.

coordinate-dimension#1

declare  function geo:coordinate-dimension($geometry as element(*)) as xs:integer external

Return the coordinate dimension of the geo object, as specified in the srsDimension attribute.

Only two-dimensional and three-dimensional coordinates are supported.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:integer
2 for 2D, 3 for 3D.

covers#2

declare  function geo:covers($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 covers geometry2.

It has to fulfill one of these conditions:

- every point of geometry2 is a point of geometry1.

- the DE-9IM Intersection Matrix for the two geometries is T*****FF* or *T****FF* or ***T**FF* or ****T*FF*.

Unlike contains it does not distinguish between points in the boundary and in the interior of geometries.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if geometry1 covers geometry2.

crosses#2

declare  function geo:crosses($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 crosses geometry2.

That is if the geometries have some but not all interior points in common.

Returns true if the DE-9IM intersection matrix for the two geometries is:

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

This applies for situations: P/L, P/A, L/L, L/A, L/P, A/P and A/L.

For other situations it returns false.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if geometry1 crosses geometry2.

difference#2

declare  function geo:difference($geometry1 as element(*), $geometry2 as element(*)) as element(*)? external

Returns a geometric object that represents the Point set difference of geometry1 and geometry2. Points that are in geometry1 and are not in geometry2.

If difference is empty geometry, empty sequence is returned.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

element(*)?
point set geometry node.

dimension#1

declare  function geo:dimension($geometry as element(*)) as xs:integer external

Return the dimension of the geo object.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:integer
0 for point, 1 for line, 2 for surface.

disjoint#2

declare  function geo:disjoint($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 does not touch or intersects geometry2.

It has to fulfill these conditions:

- they have no point in common

- the DE-9IM Intersection Matrix for the two geometries is FF*FF****.

- geometry1 does not intersect geometry2.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if geometry1 and geometry2 are disjoint.

distance#2

declare  function geo:distance($geometry1 as element(*), $geometry2 as element(*)) as xs:double external

Compute the shortest distance between any two Points in geometry1 and geometry2.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:double
minimum distance as xs:double.

end-point#1

declare  function geo:end-point($line as element(*)) as element(gml:Point) external

Returns the end Point of a line.

Parameters

line as element(*)
node of one of GMLSF objects: gml:LineString, gml:LinearRing, gml:Curve

Returns

element(gml:Point)
the end gml:Point, constructed with the last coordinates in the line.

envelope#1

declare  function geo:envelope($geometry as element(*)) as element(gml:Envelope) external

The envelope is the minimum bounding box of this geometry.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

element(gml:Envelope)
An gml:Envelope element with content <gml:Envelope> <gml:lowerCorner>minx miny</gml:lowerCorner> <gml:upperCorner>maxx maxy</gml:upperCorner> </gml:Envelope>

equals#2

declare  function geo:equals($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if the two geometries are equal.

Note: Does not work for gml:Surface and gml:MultiSurface if they have multiple Polygons.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if the DE-9IM intersection matrix for the two Geometrys is T*F**FFF*.

exterior-ring#1

declare  function geo:exterior-ring($polygon as element(gml:Polygon)) as element(gml:LinearRing) external

Return the exterior ring of a Polygon.

Parameters

polygon as element(gml:Polygon)
node of one of GMLSF objects: gml:Polygon

Returns

element(gml:LinearRing)
the original gml:LinearRing node for exterior ring

geometry-n#2

declare  function geo:geometry-n($geometry as element(*), $n as xs:unsignedInt) as element(*) external

Return the n-th geometry in the collection.

Return this geometry if it is not a collection.

For gml:Point, gml:LineString, gml:LinearRing, gml:Polygon, return this item if n is zero, otherwise error.

For gml:Curve and gml:Surface, they are treated as geometric collections.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
n as xs:unsignedInt
zero-based index in the collection

Returns

element(*)
n-th geometry in collection. The node is the original node, not a copy.

geometry-type#1

declare  function geo:geometry-type($geometry as element(*)) as xs:QName? external

Return the qname type of geo object.

Returns empty sequence if the geometry is not recognized.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:QName?
"gml:Point" for Point, "gml:LineString" for LineString, "gml:Curve" for Curve, "gml:LineString" for LinearRing, "gml:Surface" for Surface, "gml:Polygon" for Polygon and PolygonPatch, "gml:MultiPoint" for MultiPoint, "gml:MultiCurve" for MultiCurve, "gml:MultiSurface" for MultiSurface, "gml:MultiGeometry" for MultiGeometry

interior-ring-n#2

declare  function geo:interior-ring-n($polygon as element(gml:Polygon), $n as xs:unsignedInt) as element(gml:LinearRing) external

Return the n-th interior ring of a Polygon.

Parameters

polygon as element(gml:Polygon)
node of one of GMLSF objects: gml:Polygon
n as xs:unsignedInt
index in the list of interior rings, zero based.

Returns

element(gml:LinearRing)
n-th interior ring. The node is the original node, not a copy.

intersection#2

declare  function geo:intersection($geometry1 as element(*), $geometry2 as element(*)) as element(*)? external

Returns a geometric object that represents the Point set intersection of geometry1 and geometry2.

For intersection of two polygons interiors, returns a polygon.

If intersection is void, empty sequence is returned.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

element(*)?
point set geometry node.

intersects#2

declare  function geo:intersects($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 intersects geometry2.

This is true if disjoint returns false.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if geometry1 and geometry2 are not disjoint.

is-3d#1

declare  function geo:is-3d($geometry as element(*)) as xs:boolean external

Checks if this geometric object is 2D or 3D, as specified in srsDimension optional attribute.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if $geometry is 3D.

is-closed#1

declare  function geo:is-closed($geom as element(*)) as xs:boolean external

Checks if the line is closed loop. That is, if the start Point is same with end Point.

For gml:Curve, checks if the start point of the first segment is the same with the last point of the last segment. It also checks that all the segments are connected together, and returns false if they aren't.

For gml:MultiCurve, checks recursively for each LineString.

For gml:Surface, checks if the exterior boundary of each patch touches completely other patches, so the Surface encloses a solid. For this to happen there is a need for 3D objects, and full 3D processing is not supported in GEOS library, so the function always returns false in this case.

Parameters

geom as element(*)
node of one of GMLSF objects: gml:LineString, gml:LinearRing, gml:Curve, gml:MultiCurve, gml:Surface

Returns

xs:boolean
true if the line or surface is closed.

is-empty#1

declare  function geo:is-empty($geometry as element(*)?) as xs:boolean external

Checks if the argument is empty or not and if it is a valid geometry or not.

A geometry is considered empty if it has no points.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if $geometry is not a valid gmlsf object or if is empty.

is-measured#1

declare  function geo:is-measured($geometry as element(*)) as xs:boolean external

Checks if this geometric object has measurements.

Measurements is not supported in this geo module, so the function returns false.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
false.

is-ring#1

declare  function geo:is-ring($line as element(*)) as xs:boolean external

Checks if the line is a ring. That is, if the line is closed and simple.

Parameters

line as element(*)
node of one of GMLSF objects: gml:LineString, gml:LinearRing, gml:Curve

Returns

xs:boolean
true if the line is a closed ring.

is-simple#1

declare  function geo:is-simple($geometry as element(*)) as xs:boolean external

Checks if this geometric object has no anomalous geometric points, such as self intersection or self tangency.

Does not work for gml:Surface and gml:MultiGeometry.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:LinearRing, gml:Curve, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface

Returns

xs:boolean
true if $geometry is simple.

is-within-distance#3

declare  function geo:is-within-distance($geometry1 as element(*), $geometry2 as element(*), $distance as xs:double) as xs:boolean external

Checks if geometry2 is within a certain distance of geometry1.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
distance as xs:double
the distance from geometry1, expressed in units of the current coordinate system

Returns

xs:boolean
true if distance from geometry1 to geometry2 is less than $distance.

length#1

declare  function geo:length($geometry as element(*)) as xs:double external

Returns the length of the lines of this geometry.

Returns zero for Points.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:double
geometry length as xs:double.

m#1

declare  function geo:m($point as element(gml:Point)) as xs:double? external

Should return the Measure of a Point, but is not implemented, because it is not specified in GMLSF.

Parameters

point as element(gml:Point)
node of one of GMLSF objects: gml:Point

Returns

xs:double?
always empty sequence

num-geometries#1

declare  function geo:num-geometries($geometry as element(*)) as xs:unsignedInt external

Return the number of geometries in the collection, or 1 for non-collection.

For gml:Point, gml:LineString, gml:LinearRing, gml:Polygon, return 1.

For gml:Curve and gml:Surface, they are treated as geometric collections.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:unsignedInt
number of geometries in collection

num-interior-ring#1

declare  function geo:num-interior-ring($polygon as element(gml:Polygon)) as xs:unsignedInt external

Return the number of interior rings of a Polygon.

Parameters

polygon as element(gml:Polygon)
node of one of GMLSF objects: gml:Polygon

Returns

xs:unsignedInt
the number of interior rings

num-patches#1

declare  function geo:num-patches($polyhedral-surface as element(gml:Surface)) as xs:integer external

Return the number of surface patches inside a gml:Surface.

This function has the same effect as num-geometries(), only it is restricted to gml:Surface.

Parameters

polyhedral-surface as element(gml:Surface)
node of one of GMLSF objects: gml:Surface

Returns

xs:integer
the number of surface patches

num-points#1

declare  function geo:num-points($line as element(*)) as xs:unsignedInt external

Return the number of Points in a line.

Parameters

line as element(*)
node of one of GMLSF objects: gml:LineString, gml:LinearRing, gml:Curve, gml:MultiCurve

Returns

xs:unsignedInt
number of points in the line

overlaps#2

declare  function geo:overlaps($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 overlaps with geometry2.

Returns true if DE-9IM intersection matrix for the two geometries is T*T***T** (for two points or two surfaces) or * 1*T***T** (for two curves).

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if geometry1 overlaps geometry2.

patch-n#2

declare  function geo:patch-n($polyhedral-surface as element(gml:Surface), $n as xs:unsignedInt) as element(gml:PolygonPatch) external

Return the n-th Surface patch of a Surface.

Only polygonal Surfaces are supported, so a gml:PolygonPatch is returned.

The gml:PolygonPatch has the same content as gml:Polygon.

This function has the same effect as geometry-n(), only it is restricted to gml:Surface.

Parameters

polyhedral-surface as element(gml:Surface)
node of one of GMLSF objects: gml:Surface
n as xs:unsignedInt
index in the list of surface patches, zero based.

Returns

element(gml:PolygonPatch)
n-th polygon patch. The node is the original node, not a copy.

point-n#2

declare  function geo:point-n($line as element(*), $n as xs:unsignedInt) as element(gml:Point) external

Return the n-th Point in a line.

Parameters

line as element(*)
node of one of GMLSF objects: gml:LineString, gml:LinearRing, gml:Curve, gml:MultiCurve
n as xs:unsignedInt
index in the list of coordinates, zero based.

Returns

element(gml:Point)
n-th point in the line, zero-based. The node is gml:Point constructed with n-th coordinate from line.

point-on-surface#1

declare  function geo:point-on-surface($geometry as element(*)) as element(gml:Point) external

Returns a Point that is interior of this geometry.

If it cannot be inside the geometry, then it will be on the boundary.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

element(gml:Point)
a Point inside the geometry.

relate#3

declare  function geo:relate($geometry1 as element(*), $geometry2 as element(*), $intersection_matrix as xs:string) as xs:boolean external

Checks if geometry1 relates with geometry2 relative to a DE-9IM matrix.

The DE-9IM matrix is defined like this:

Interior Boundary Exterior
Interior dim(intersection of interior1 and interior2) dim(intersection of interior1 and boundary2) dim(intersection of interior1 and exterior2)
Boundary dim(intersection of boundary1 and interior2) dim(intersection of boundary1 and boundary2) dim(intersection of boundary1 and exterior2)
Exterior dim(intersection of exterior1 and interior2) dim(intersection of exterior1 and boundary2) dim(intersection of exterior1 and exterior2)

The values in the DE-9IM can be T, F, *, 0, 1, 2 .

- T means the intersection gives a non-empty result.

- F means the intersection gives an empty result.

- * means any result.

- 0, 1, 2 gives the expected dimension of the result (point, curve, surface)

For example, the matrix of "T*T***T**" checks for intersections of interior1 with interior2, interior1 with exterior2 and exterior1 with interior2.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:LinearRing, gml:Polygon
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:LinearRing, gml:Polygon
intersection_matrix as xs:string
the DE-9IM matrix, with nine chars, three chars for each line in DE-9IM matrix.

Returns

xs:boolean
true if geometry1 relates to geometry2 according to the intersection matrix.

srid#1

declare  function geo:srid($geometry as element(*)) as xs:anyURI? external

Return the srid URI of geo object.

SRID is contained in the srsName attribute in the geo element, or one of the parents, or in the boundedBy/Envelope element in one of the parents.

This function searches recursively from this element up to the top-most parent.

Parameters

geometry as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:anyURI?
the SRID if it is found

start-point#1

declare  function geo:start-point($line as element(*)) as element(gml:Point) external

Returns the start Point of a line.

Parameters

line as element(*)
node of one of GMLSF objects: gml:LineString, gml:LinearRing, gml:Curve

Returns

element(gml:Point)
the starting gml:Point, constructed with the first coordinates in the line.

sym-difference#2

declare  function geo:sym-difference($geometry1 as element(*), $geometry2 as element(*)) as element(*)? external

Returns a geometric object that represents the Point set symmetric difference of geometry1 and geometry2. Points that are in geometry1 and are not in geometry2 and points that are in geometry2 and are not in geometry1.

If difference is empty geometry, empty sequence is returned.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

element(*)?
point set geometry node.

touches#2

declare  function geo:touches($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 touches geometry2.

Returns true if the DE-9IM intersection matrix for the two geometries is FT*******, F**T***** or F***T****.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if geometry1 touches geometry2.

union#2

declare  function geo:union($geometry1 as element(*), $geometry2 as element(*)) as element(*) external

Returns a geometric object that represents the Point set union of geometry1 and geometry2.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

element(*)
point set geometry node.

within#2

declare  function geo:within($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean external

Checks if geometry1 is within geometry2.

Returns true if the DE-9IM intersection matrix for the two geometries is T*F**F***.

Parameters

geometry1 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry
geometry2 as element(*)
node of one of GMLSF objects: gml:Point, gml:LineString, gml:Curve, gml:LinearRing, gml:Surface, gml:Polygon, gml:MultiPoint, gml:MultiCurve, gml:MultiSurface, gml:MultiGeometry

Returns

xs:boolean
true if geometry1 is within geometry2.

x#1

declare  function geo:x($point as element(gml:Point)) as xs:double external

Returns the X coordinate of a Point.

Parameters

point as element(gml:Point)
node of one of GMLSF objects: gml:Point

Returns

xs:double
the X coordinate

y#1

declare  function geo:y($point as element(gml:Point)) as xs:double external

Returns the Y coordinate of a Point.

Parameters

point as element(gml:Point)
node of one of GMLSF objects: gml:Point

Returns

xs:double
the Y coordinate

z#1

declare  function geo:z($point as element(gml:Point)) as xs:double? external

Returns the Z coordinate of a Point, if is 3D.

Parameters

point as element(gml:Point)
node of one of GMLSF objects: gml:Point

Returns

xs:double?
the Z coordinate, or empty sequence if 2D