Geo Module

From BaseX Documentation

Jump to: navigation, search

This XQuery 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 library.

Geometries included in GML 2 are: Point, LineString, LinearRing, Polygon, MultiPoint, MultiLineString, MultiPolygon, and MultiGeometry. All nodes queried by BaseX should be a valid geometry. The only geometry type which is not supported by BaseX right now is MultiGeometry. Moreover, the module provides no support for GML 3.

Contents

[edit] Conventions

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

[edit] General Functions

[edit] geo:dimension

Signatures geo:dimension($geometry as element(*)) as xs:integer
Summary Returns the dimension of the given geometry $geometry.
Errors GEO0001: the given element is not recognized as a valid geometry.
GEO0002: the given element cannot be read by reader for some reason.
Example
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>)

[edit] geo:geometry-type

Signatures geo:geometry-type($geometry as element(*)) as xs:QName
Summary Returns the name of the geometry type of given geometry $geometry, if the geometry is not recognized with an error massage.
Errors GEO0001: the given element is not recognized as a valid geometry.
GEO0002: the given element cannot be read by reader for some reason.
Example
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>)

[edit] geo:srid

Signatures geo:srid($geometry as element(*)) as xs:integer
Summary Returns the ID of the Spatial Reference System used by the given geometry $geometry. Spatial Reference System information is supported in the simple way defined in the SFS. A Spatial Reference System ID (SRID) is present in each Geometry object. Geometry provides basic accessor operations for this field, but no others. The SRID is represented as an integer (based on the OpenGIS Simple Features Specifications For SQL).
Here is a difference between the EXPath Geo Module and the implementation in BaseX, since the specification return the URI.
Errors GEO0001: the given element is not recognized as a valid geometry.
GEO0002: the given element cannot be read by reader for some reason.
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>
)

[edit] geo:envelope

Signatures geo:envelope($geometry as element(*)) as element(*)
Summary Returns the gml:Envelope of the given geometry $geometry. The envelope is the minimum bounding box of this geometry. If this Geometry is the empty geometry, returns an empty Point. If the Geometry is a point, returns a non-empty Point. Otherwise, returns a Polygon whose points are (minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy), (minx, miny).
Errors GEO0001: the given element is not recognized as a valid geometry.
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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>
)

[edit] geo:as-text

Signatures geo:as-text($geometry as element(*)) as xs:string
Summary Returns the WKT (Well-known Text) representation of the given geometry $geometry. The envelope is the minimum bounding box of this geometry
Errors GEO0001: the given element is not recognized as a valid geometry.
GEO0002: the given element cannot be read by reader for some reason.
Example
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>)

[edit] geo:as-binary

Signatures geo:as-binary($geometry as element(*)) as xs:base64Binary
Summary Returns the WKB (Well-known Binary) representation of the given geometry $geometry.
Errors GEO0001: the given element is not recognized as a valid geometry.
GEO0002: the given element cannot be read by reader for some reason.
Example
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>)

[edit] geo:is-simple

Signatures geo:is-simple($geometry as element(*)) as xs:boolean
Summary Returns whether the given geometry is simple $geometry and does not have has no anomalous geometric points (ie. the geometry does not self-intersect and does not pass through the same point more than once (may be a ring)).
Errors GEO0001: the given element is not recognized as a valid geometry.
GEO0002: the given element cannot be read by reader for some reason.
Example
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>
)

[edit] geo:boundary

Signatures geo:boundary($geometry as element(*)) as element(*)?
Summary Returns the boundary of the given geometry $geometry, in GML 2. The return value is a sequence of either gml:Point or gml:LinearRing elements as a GeometryCollection object. For a Point or MultiPoint, the boundary is the empty geometry, nothing is returned.
Errors GEO0001: the given element is not recognized as a valid geometry.
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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>
)

[edit] geo:num-geometries

Signatures geo:num-geometries($geometry as element(*)) as xs:integer
Summary Returns the number of geometry in a geometry-collection $geometry, in GML. For the geometries which are not a collection, it returns the instant value 1.
This function is implemented wider than the specification and accepts all types of geometries, while the specification limits it to the collection types (MultiPoint, MultiPolygon, ...).
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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>
)

[edit] geo:geometry-n

Signatures geo:geometry-n($geometry as element(*), $geoNumber as xs:integer) as element(*)
Summary Returns the Nth geometry in geometry-collection $geometry, in GML. For the geometries which are not a collection, it returns the geometry if geoNumber $geoNumber is 1.
This function is implemented wider than the specification and accepts all types of geometries, while the specification limits it to the collection types (MultiPoint, MultiPolygon, ...).
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0004: the the input index of geometry is out of range.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] geo:length

Signatures geo:length($geometry as element(*)) as xs:double
Summary Returns the length of the geometry $geometry. If the geometry is a point, zero value will be returned.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:num-points

Signatures geo:num-points($geometry as element(*)) as xs:integer
Summary Returns integer value of number of the points in the given geometry$geometry. It can be used not only for Lines, also any other geometry types, like MultiPolygon. For Point geometry it will return 1.
This is an implementation different from the EXPath geo specification, as it limits the input geometry type only to lines.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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>
)

[edit] geo:area

Signatures geo:area($geometry as element(*)) as xs:double
Summary Returns the area of the given geometry $geometry. For points and line the return value will be zero.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:centroid

Signatures geo:centroid($geometry as element(*)) as element(*)
Summary Returns the mathematical centroid of the given geometry $geometry, as a gml:Point. Based on the definition, this point is not always on the surface of the geometry $geometry.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] geo:point-on-surface

Signatures geo:point-on-surface($geometry as element(*)) as element(*)
Summary Returns an interior point on the given geometry $geometry, as a gml:Point. It is guaranteed to be on surface. Otherwise, the point may lie on the boundary of the geometry.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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>              
)

[edit] Spatial Predicate Functions

[edit] geo:equals

Signatures geo:equals($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean
Summary Returns whether geometry1 $geometry1 is spatially equal to $geometry2 $geometry2.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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>
)

[edit] geo:disjoint

Signatures geo:disjoint($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean
Summary Returns whether geometry1 $geometry1 is spatially disjoint from $geometry2 $geometry2 (they have no point in common, they do not intersect each other, and the DE-9IM Intersection Matrix for the two geometries is FF*FF****).
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:intersects

Signatures geo:intersects($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean
Summary Returns whether geometry1 $geometry1 is spatially intersects $geometry2 $geometry2. This is true if disjoint function of the two geometries returns false.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:touches

Signatures geo:touches($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean
Summary Returns whether geometry1 $geometry1 is spatially touches $geometry2 $geometry2.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:crosses

Signatures geo:crosses($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean
Summary Returns whether geometry1 $geometry1 is spatially crosses $geometry2 $geometry2. It means, 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).

Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:within

Signatures geo:within($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean
Summary Returns whether geometry1 $geometry1 is spatially within $geometry2 $geometry2.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:contains

Signatures geo:contains($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean
Summary Returns whether geometry1 $geometry1 spatially contains $geometry2 $geometry2. Returns true if within function of these two geometries also returns true.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:overlaps

Signatures geo:overlaps($geometry1 as element(*), $geometry2 as element(*)) as xs:boolean
Summary Returns whether geometry1 $geometry1 is spatially overlaps $geometry2 $geometry2.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:relate

Signatures geo:relate($geometry1 as element(*), $geometry2 as element(*), $intersectionMatrix as xs:string) as xs:boolean
Summary Returns whether relationships between the boundaries, interiors and exteriors of geometry1 $geometry1 and geometry2 $geometry2 match the pattern specified in intersectionMatrix $geometry2, which should have the length of 9 charachters.
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)

Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0006: the given matrix is invalid.
Example
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)

[edit] Analysis Functions

[edit] geo:distance

Signatures geo:distance($geometry1 as element(*), $geometry2 as element(*)) as xs:double
Summary Returns the shortest distance, in the units of the spatial reference system of geometry1 $geometry1, between the geometries, where that distance is the distance between a point on each of the geometries.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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)

[edit] geo:buffer

Signatures geo:buffer($geometry as element(*), $distance as xs:double) as element(*)
Summary Returns polygonal geometry representing the buffer by distance $distance of geometry $geometry a buffer area around this geometry having the given width, in the spatial reference system of 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 represent curves.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] geo:convex-hull

Signatures geo:convex-hull($geometry as element(*)) as element(*)
Summary Returns the convex hull geometry of the given geometry $geometry in GML, or the empty sequence. Actually returns the object of smallest dimension possible.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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>           
)

[edit] geo:intersection

Signatures geo:intersection($geometry1 as element(*), $geometry2 as element(*)) as element(*)?
Summary Returns the intersection geometry of geometry1 $geometry1 with geometry2 $geometry2, in GML or empty sequence if there is no intersection of these geometries.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] geo:union

Signatures geo:union($geometry1 as element(*), $geometry2 as element(*)) as element(*)
Summary Returns the union geometry of geometry1 $geometry1 with geometry2 $geometry2, in GML.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] geo:difference

Signatures geo:difference($geometry1 as element(*), $geometry2 as element(*)) as element(*)?
Summary Returns the difference geometry of geometry1 $geometry1 with geometry2 $geometry2, in GML, or empty sequence if the difference is empty, as a set of point in geometry1 $geometry1 and not included in geometry2 $geometry2.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] geo:sym-difference

Signatures geo:sym-difference($geometry1 as element(*), $geometry2 as element(*)) as element(*)?
Summary Returns the symmetric difference geometry of geometry1 $geometry1 with geometry2 $geometry2, in GML, or empty sequence if the difference is empty, as a set of point in one of the geometries and not included in the other.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] Functions Specific to Geometry Type

[edit] geo:x

Signatures geo:x($point as element(*)) as xs:double
Summary Returns the x coordinate of point $point. A point has to have an x coordinate.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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>)

[edit] geo:y

Signatures geo:y($point as element(*)) as xs:double?
Summary Returns the y coordinate of point $point. If the point does not have the y coordinate, 0 will be returned.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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>)

[edit] geo:z

Signatures geo:z($point as element(*)) as xs:double?
Summary Returns the z coordinate of point $point. If the point does not have the y coordinate, 0 will be returned.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
Example
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>)

[edit] geo:start-point

Signatures geo:start-point($line as element(*)) as element(*)
Summary Returns the starting point of the given line $line. $line has to be a single line, LineString or LinearRing.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0003: the given element has to be a line. Other geometries are not accepted.
Example
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>
)

[edit] geo:end-point

Signatures geo:end-point($line as element(*)) as element(*)
Summary Returns the ending point of the given line $line. $line has to be a single line, LineString or LinearRing.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0003: the given element has to be a line. Other geometries are not accepted.
Example
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>
)

[edit] geo:is-closed

Signatures geo:is-closed($line as element(*)) as xs:boolean
Summary Returns a boolean value that shows the line $line is a closed loop (start point and end point are the same) or not. $line has to be a line, as a geometry, LineString or LinearRing, and MultiLineString.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0003: the given element has to be a line. Other geometries are not accepted.
Example
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>
)

[edit] geo:is-ring

Signatures geo:is-ring($line as element(*)) as xs:boolean
Summary Returns a boolean value that shows the line $line is a ring (closed loop and single) or not. $line has to be a single line, as a geometry, LineString or LinearRing.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0003: the given element has to be a line. Other geometries are not accepted.
Example
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>
)

[edit] geo:point-n

Signatures geo:point-n($line as element(*)) as element(*)
Summary Returns the Nth point in the given line $geometry. $line has to be a single line, as a geometry, LineString or LinearRing.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0003: the given element has to be a line. Other geometries are not accepted.
GEO0004: the the input index of geometry is out of range.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] geo:exterior-ring

Signatures geo:exterior-ring($polygon as element(*)) as element(*)
Summary Returns the outer ring of the given polygon $geometry, as a gml:LineString.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0003: the given element has to be a polygon. Other geometries are not accepted.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] geo:num-interior-ring

Signatures geo:num-interior-ring($polygon as element(*)) as xs:integer
Summary Returns the number of interior rings in the given polygon $geometry.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0003: the given element has to be a polygon. Other geometries are not accepted.
Example
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>
)

[edit] geo:interior-ring-n

Signatures geo:interior-ring-n($polygon as element(*)) as element(*)
Summary Returns the outer ring of the given polygon $geometry, as a gml:LineString.
Errors GEO0001: the given element(s) is not recognized as a valid geometry (QName).
GEO0002: the given element cannot be read by reader for some reason.
GEO0003: the given element has to be a polygon. Other geometries are not accepted.
GEO0004: the the input index of geometry is out of range.
GEO0005: the output object cannot be written as an element by writer for some reason.
Example
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)

[edit] Errors

Code Description
GEO0001 Unrecognized Geo type.
GEO0002 The input GML node cannot be read by GMLreader.
GEO0003 Input geometry is not an appropriate geometry for this function.
GEO0004 The input index is out of range.
GEO0005 The result geometry can not be written by GMLwriter.
GEO0006 The input matrix is invalid.

[edit] Changelog

The module was introduced with Version 7.6.

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export