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:
<gml:Point [srsDimension='2|3']?> <gml:pos [srsDimension='2|3']?>double_x double_y </gml:pos> </gml:Point>
<gml:LineString [srsDimension='2|3']?> <gml:posList [srsDimension='2|3']?> double_x1 double_y1 double_x2 double_y2 ... </gml:posList> </gml:LineString>
<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>
<gml:LinearRing [srsDimension='2|3']?> <gml:posList [srsDimension='2|3']?> double_x1 double_y1 double_x2 double_y2 ... </gml:posList> </gml:LinearRing>
<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>
<gml:Polygon [srsDimension='2|3']?> <gml:exterior> <gml:LinearRing> ... </gml:LinearRing> </gml:exterior> [<gml:interior> <gml:LinearRing> ... </gml:LinearRing> </gml:interior>]* </gml:Polygon>
<gml:MultiPoint [srsDimension='2|3']?> [<gml:Point> ... </gml:Point>]* </gml:MultiPoint>
<gml:MultiCurve [srsDimension='2|3']?> [<gml:LineString> ... </gml:LineString>]* </gml:MultiCurve>
<gml:MultiSurface [srsDimension='2|3']?> [<gml:Polygon> ... </gml:Polygon>]* </gml:MultiSurface>
<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)
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. |
declare function geo:area($geometry as element(*)) as xs:double external
Returns the area of this geometry.
Returns zero for Point and Lines.
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.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.
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.
declare function geo:dimension($geometry as element(*)) as xs:integer external
Return the dimension of the geo object.
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.
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.
declare function geo:end-point($line as element(*)) as element(gml:Point) external
Returns the end Point of a line.
declare function geo:envelope($geometry as element(*)) as element(gml:Envelope) external
The envelope is the minimum bounding box of this geometry.
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.
declare function geo:exterior-ring($polygon as element(gml:Polygon)) as element(gml:LinearRing) external
Return the exterior ring of a Polygon.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
declare function geo:length($geometry as element(*)) as xs:double external
Returns the length of the lines of this geometry.
Returns zero for Points.
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.
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.
declare function geo:num-interior-ring($polygon as element(gml:Polygon)) as xs:unsignedInt external
Return the number of interior rings of a Polygon.
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.
declare function geo:num-points($line as element(*)) as xs:unsignedInt external
Return the number of Points in a line.
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).
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.
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.
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.
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.
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.
declare function geo:start-point($line as element(*)) as element(gml:Point) external
Returns the start Point of a line.
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.
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****.
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.
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***.
declare function geo:x($point as element(gml:Point)) as xs:double external
Returns the X coordinate of a Point.
declare function geo:y($point as element(gml:Point)) as xs:double external
Returns the Y coordinate of a Point.
declare function geo:z($point as element(gml:Point)) as xs:double? external
Returns the Z coordinate of a Point, if is 3D.