Skip to main content

Module geosparql

Module geosparql 

Source
Expand description

GeoSPARQL geometry support: a WKT (Well-Known Text) literal parser and the real geometry predicates the SPARQL extension functions dispatch to (geof:distance, geof:sfContains, sfWithin, sfIntersects, sfTouches).

This replaces the “Simplified” placeholders in sparql_extensions.rs (which returned hardcoded true/false or an arbitrary threshold) with genuine computation over parsed geometry. Distances use the haversine great-circle formula (lon/lat degrees, WGS-84 mean radius); topological predicates use planar tests (ray-casting point-in-polygon, segment intersection).

Scope: POINT, LINESTRING, POLYGON (with holes), and their MULTI variants — the WKT subset GeoSPARQL data uses in practice. Z/M coordinates are parsed and ignored (2D predicates). An optional SRID/<uri> prefix (geo:wktLiteral values sometimes carry <crs> POINT(...)) is skipped.

Structs§

Coord
A 2-D coordinate (x, y).

Enums§

GeoFn
The GeoSPARQL extension functions this engine implements.
GeoValue
Result of a GeoSPARQL predicate: a boolean (sf* topology) or a metric.
Geometry
A parsed WKT geometry. Coordinates are (x, y) = (longitude, latitude) for geographic data.

Constants§

GEO_FUNCTION_IRIS
Canonical function IRIs, keyed by GeoFn. Parser and evaluator agree on these so a geof:<local> call hashes to the same Function::Custom id both sides compute.

Functions§

contains
geof:sfContains — does a contain b? Implemented for the common case of a polygon containing a point / all points of another geometry.
distance_metres
Great-circle distance in metres between two geometries’ representative points (haversine). For non-point geometries the centroid of the coordinate set is used — a documented approximation adequate for geof:distance.
eval_geo_fn
Evaluate a GeoFn over two already-parsed geometries.
geo_fn_for_hash
Map a function-IRI hash back to a GeoFn (used by the evaluator to dispatch a Function::Custom(hash)).
geo_function_iri
Canonical IRI for a geof:<local> function name, if recognised. Lets the parser expand a geof: call to the standard IRI even when the query did not declare the prefix.
intersects
geof:sfIntersects — do a and b share any point? Covers point-in-polygon, shared vertices, and segment crossings between line/polygon boundaries.
parse_wkt
Parse a WKT literal into a Geometry. Accepts an optional leading CRS URI (<http://…/CRS84> POINT(…)) which is skipped. Case-insensitive keywords.
touches
geof:sfTouches — geometries share a boundary point but no interior. A pragmatic test: they intersect, but neither contains an interior point of the other (approximated as: they intersect and no vertex of one is strictly inside a polygon of the other).
within
geof:sfWithina within bb contains a.