Geospatial Data
Waratah knows geometry natively: geometry values are literals in your data, spatial questions are SPARQL functions, and an S2 cell index makes those questions fast. The support follows GeoSPARQL conventions, so existing geo RDF tends to work unchanged.
The plugin is always active — no setup, no flag.
Geometry literals
A geometry is a typed literal. The everyday form is WKT text with the
geo:wktLiteral datatype:
"POINT(153.02 -27.46)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>
Coordinates are normalized to CRS84 — longitude first, latitude second —
and the engine also reads the binary geo:wkbLiteral form. Attach the
literal to your resources like any other value (Turtle syntax, part of an
example dataset used throughout this page):
@prefix ex: <http://ex/> .
@prefix geo: <http://www.opengis.net/ont/geosparql#> .
ex:brisbane ex:name "Brisbane" ;
geo:hasGeometry "POINT(153.02 -27.46)"^^geo:wktLiteral .
ex:ipswich ex:name "Ipswich" ;
geo:hasGeometry "POINT(152.90 -27.60)"^^geo:wktLiteral .
ex:sydney ex:name "Sydney" ;
geo:hasGeometry "POINT(151.20 -33.87)"^^geo:wktLiteral .
Load it as you would any RDF file — for example into a running cluster:
waratah import places.ttl --connect
Validity and index completeness
A stored geometry must have a native indexed form. Waratah tolerates two narrow classes of defect:
-
Very small contact between polygon members of the same
MULTIPOLYGON: cumulative overlap no larger than 0.00000001 square degrees, or cumulative shared boundary no longer than 0.00000001 degrees. A shared edge means exactly collinear boundary segments; near-collinear edges are handled by the normal validity or overlap rule, not by a distance epsilon. -
An exactly retraced, zero-area spike in a polygon ring. The retraced edges must be exactly collinear. Waratah removes the backtracking only for spatial evaluation, after checking that the reduced geometry is valid and its area is unchanged within floating-point noise. The stored binary geometry and
STR()output keep the original coordinates; the spatial functions use the reduced valid region. Each accepted literal produces a warning with its subject and removed-vertex count, andwaratah importprints the total number reduced.
Larger contact totals, longer shared boundaries, non-collinear self-intersections, real member overlap, and all other parse, coordinate-reference-system, shape, or validation failures stop the insert or import with an error that identifies the problem.
This is deliberate: storing a geometry without its index postings would let an indexed spatial filter silently omit it. A geo index rebuild follows the same rule. If an existing geometry cannot be upgraded, the rebuild stops and leaves the index untrusted instead of marking an incomplete index as ready. A legacy native geometry with a tolerated spike but without the reduction marker must be re-ingested before it can be rebuilt safely.
An index built before this validation policy may omit a geometry that a new import would accept. Rebuild it on a stopped store after upgrading:
waratah geo rebuild-index --data-dir ./waratah-data
Geometry validation runs once per import chunk. If a chunk contains invalid geometry, that chunk is not written, but earlier chunks remain loaded. Fix the source geometry, re-ingest the corrected file, then rebuild the geo index from scratch on a stopped store with the command above.
The three spatial functions
| Function | True when |
|---|---|
|
Geometry |
|
Geometry |
|
The two geometries share at least one point. |
Each takes two geometry literals and returns a boolean; evaluation is an exact geometric computation (DE-9IM), not a bounding-box approximation.
Asking spatial questions
Which of our places are inside a rectangle over greater Brisbane?
PREFIX ex: <http://ex/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
SELECT ?name WHERE {
?place ex:name ?name ;
geo:hasGeometry ?loc .
FILTER(geof:sfWithin(?loc, "POLYGON((152.8 -27.7, 153.2 -27.7, 153.2 -27.2, 152.8 -27.2, 152.8 -27.7))"^^geo:wktLiteral))
}
Brisbane and Ipswich; Sydney is well outside. The same window as
sfContains with the arguments swapped answers equivalently:
FILTER(geof:sfContains("POLYGON((...))"^^geo:wktLiteral, ?loc))
The window does not have to be spelled inline — a VALUES row works the
same way:
VALUES ?window { "POLYGON((...))"^^geo:wktLiteral }
FILTER(geof:sfWithin(?loc, ?window))
How it answers fast
At load time, every geometry literal is covered by a small set of S2
cells (a hierarchical grid over the sphere) and those cell postings are
written to the storage index. When a query compares stored geometries
against a constant window — inline literal or VALUES-bound, as above —
the planner uses the window’s cell covering to read only candidate rows
from the index, then runs the exact geometric check on those candidates.
Queries where both geometries are variables cannot use the index; they
still answer correctly, evaluating the geometry pair by pair.
Tuning the covering
Four waratah start flags control how geometries are covered:
| Flag | Default | Meaning |
|---|---|---|
|
0 |
Coarsest S2 cell level in a covering. |
|
24 |
Finest S2 cell level (points always sit at the level-30 leaf). |
|
40 |
Maximum cells per covering — higher is finer-grained but larger indexes. |
|
0.1 |
Planar edge densification step in degrees: polygon and line-string
edges longer than this are subdivided before the covering so the
geodesic candidate index also covers the planar (WKT) region — on
continental-scale rings the geodesic and planar readings of the same
coordinates differ by up to ~1°, and without densification the index
silently misses geometries near such edges. |
These values must be identical on every process in the cluster, and changing them changes how the index is built — after a change, rebuild:
waratah geo rebuild-index --data-dir ./waratah-data
That wipes and recomputes every spatial posting under the current configuration.
Diagnosing the index
waratah geo census is a read-only inspection of the spatial index:
posting counts per S2 level, envelope coverage, and the statistics
histogram’s incidence mass. With --window it takes one query window (a
WKT literal, like a geof: conjunct would carry) and decomposes the
estimate the planner would make against what a full scan actually
returns:
waratah geo census --data-dir ./waratah-data \
--window 'POLYGON((152.8 -27.7, 153.2 -27.7, 153.2 -27.2, 152.8 -27.2, 152.8 -27.7))'