Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

159.9. libspatialindex-2.1.0

R-tree spatial indexing, under QGIS

Version 2.1.0, release 1
Shelf gis — GIS, maps, projections, GPS, navigation and location
Phase 41_system (System), 592 of 1047 in build order
Licence MIT
Homepage https://libspatialindex.org/
Build time 1.5 SBU
Installed size 1.8 MiB in 43 files
Recipe ports/core/gis/libspatialindex/kpkgbuild

About

libspatialindex is a C++ library of spatial indexes, the R-tree among them, with a C interface, libspatialindex_c, beside the C++ one. qgis indexes features with it for selection, snapping and nearest-neighbour search, and spyder reaches it through the Python rtree module.

Sources

Dependencies

Depends on: cmake, ninja.

Required by (2): qgis, spyder.

Patches

build.sh applies these; kpkg applies nothing by itself.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install libspatialindex'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/gis/libspatialindex.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/gis/libspatialindex
echo 'c59932395e98896038d59199f2e2453595df6d730ffbe09d69df2a661bcb619b  libspatialindex-2.1.0.tar.bz2' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/libspatialindex
SRC=$SRC_ROOT/libspatialindex-2.1.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf libspatialindex-2.1.0.tar.bz2 -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

patch -p1 -i "$PORT_SRC/nearest-neighbor-data-distance.patch"

cmake -S . -B build -G Ninja \
	-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
	-DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_INSTALL_LIBDIR=lib \
	-DBUILD_SHARED_LIBS=ON \
	-DBUILD_TESTING=OFF
cmake --build build
DESTDIR=$PKG cmake --install build
test -e "$PKG"/usr/lib/libspatialindex_c.so

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/libspatialindex, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf libspatialindex-2.1.0-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/libspatialindex, and runs the triggers its paths call for.

Contents

Installed libraries: libspatialindex.so, libspatialindex_c.so.

Installed directories: /usr/include/spatialindex, /usr/lib/cmake/libspatialindex, /usr/share/licenses/libspatialindex.

Short descriptions

libspatialindex.pc Generic C/C++ library for spatial indexing

Notes

nearest-neighbor-data-distance.patch makes nearestNeighborQuery measure each leaf entry through the data form of the comparator’s getMinimumDistance(). Unpatched, 2.1 measures every leaf entry through the bounding-box form, so the data form QGIS overrides, which measures a feature’s stored geometry, never runs: results are ranked by bounding box, and the maximum distance is tested against the box’s distance rather than the feature’s.

QGIS refuses libspatialindex 2.1 or later at configure time because of libspatialindex issue 276. The qgis port’s 10-libspatialindex_2_1.patch removes that refusal, which is correct only because this port carries the fix.