Skip to main content

Overview

TrailBase supports geospatial queries through SpatiaLite, a spatial extension for SQLite. Store and query geographic data including points, lines, polygons, and complex geometries.

Geospatial Data Types

TrailBase recognizes geometry columns with ST_IsValid check constraints:

Creating Geometries

From Well-Known Text (WKT)

Using Helper Functions

Coordinate Reference Systems

SRID 4326 (WGS 84): Standard latitude/longitude coordinates
  • Longitude: -180 to 180 (East/West)
  • Latitude: -90 to 90 (South/North)

Spatial Queries

Distance Calculations

Spatial Relationships

Query Parameters

TrailBase supports geospatial query parameters:

Within Query

Intersects Query

Contains Query

From the codebase:

GeoJSON Integration

TrailBase automatically converts geometry columns to GeoJSON in API responses:
API Response:

Requesting GeoJSON

Specify which geometry column to return as GeoJSON:

WASM Component Integration

Advanced Queries

Buffer Zones

Nearest Neighbor

Area and Length

Centroid

Real-Time Location Tracking

Geofencing

Performance Tips

1

Use spatial indexes

Create R-Tree indexes for geometry columns:
2

Bounding box first

Use bounding box for initial filtering, then precise geometry:
3

Simplify geometries

Reduce complexity for large polygons:
4

Cache calculations

Store frequently accessed spatial calculations

Complete Example

Next Steps

Vector Search

Combine with semantic search

Custom Endpoints

Build location APIs

Object Storage

Store map tiles

Jobs Scheduler

Periodic geo processing