Skip to content

rtree

Package rtree adds ready-made custom geometry callbacks for SQLite’s built-in R-Tree module, layered on gosqlite.org.Conn.RegisterRTreeGeometry.

The rtree and geopoly virtual tables are compiled into the underlying library and need no registration — CREATE VIRTUAL TABLE … USING rtree(…) works out of the box. This package only installs user geometry functions usable with the R-Tree MATCH operator:

CREATE VIRTUAL TABLE demo USING rtree(id, minX, maxX, minY, maxY);
-- rows whose box overlaps the circle of radius 5 centred at (10, 10):
SELECT id FROM demo WHERE id MATCH circle(10, 10, 5);

For arbitrary custom geometry, call gosqlite.org.Conn.RegisterRTreeGeometry (single bounding-box overlap test) or gosqlite.org.Conn.RegisterRTreeQuery (the richer query-callback form) directly.

For a typed handle that hides the CREATE VIRTUAL TABLE … USING rtree(…) column list and the overlap-predicate SQL — Create / Insert / InsertPoint / Search / SearchCircle / Delete / Drop — see Table.

import (
sqlite "gosqlite.org"
"gosqlite.org/ext/rtree"
)
if err := rtree.Register(conn); err != nil { ... }

Geometry functions are per-connection. For pool-wide install, blank-import the auto sub-package:

import _ "gosqlite.org/ext/rtree/auto"

Full API: pkg.go.dev/gosqlite.org/ext/rtree