Trajectory
Reconstruct visits, dwell and trips from GPS observations
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Not available yet
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/trajectory/index.md to help me query Trajectory with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Count observations per synthetic entity
Example output · captured
- Connector release
- v0.3.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT entity_id, count(*)
FROM trajectory.main.sample_fixes
GROUP BY entity_id
ORDER BY entity_id
| entity_id | count_star() |
|---|---|
| crossing | 2 |
| stopped | 2 |
Quick start
Choose where to run Trajectory, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'trajectory' AS trajectory (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-trajectory-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'trajectory' AS trajectory (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-trajectory:0.3.0'
);
3. Run a query
SELECT entity_id, count(*)
FROM trajectory.main.sample_fixes
GROUP BY entity_id
ORDER BY entity_id
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'trajectory' AS trajectory
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT entity_id, count(*)
FROM trajectory.main.sample_fixes
GROUP BY entity_id
ORDER BY entity_id
Query Farm hosting is not available for Trajectory yet. Choose “On your machine” or “Self-host” to run it yourself, or talk to us about hosting.
Technical details
- Verified connector release
- v0.3.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'trajectory' AS trajectory (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-trajectory-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'trajectory' AS trajectory (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-trajectory:0.3.0'
);
Overview
GPS track analysis: turns timestamped position fixes into geofence visits, trips and explicit observation gaps, interpolating crossings between fixes but never inferring visits across long gaps, implausible speeds or poor-accuracy fixes. Sample fixes and fences are included.
GIS analysis
Reconstruct visits and trips from timestamped GPS rows, including geofence crossings between fixes. The worker buffers within an explicit point budget, sorts by entity and UTC time, intersects each piecewise-linear track with polygons, and emits visits, trips, and explicit observation gaps. Long gaps, implausible speeds and poor-accuracy fixes never create inferred visits. Durations and paths describe the linear interpolation model, not unobserved ground truth.
SQL workflow
Pass query results to the main schema functions, retaining IDs for joins. Use bundled synthetic data to try the executable examples without network access. CRS, coverage, inference limits and resource bounds are explicit function parameters.
Sources and references
- Shapely: the geometry engine behind track/geofence intersections and the WKB episode paths.
- pyproj (PROJ): coordinate transforms from the input CRS into a projected metre CRS for distances and speeds.
- OGC Simple Feature Access: the WKB geometry encoding used for fences and returned paths.
Catalog
Everything trajectory exposes once attached — read straight from the worker's
released build.
main 1 table · 1 function
Spatial functions and bundled inputs for trajectory analysis.
Schema examples (4)
Count observations per synthetic entity
SELECT entity_id, count(*)
FROM trajectory.main.sample_fixes
GROUP BY entity_id
ORDER BY entity_id;
| entity_id | count_star() |
|---|---|
| crossing | 2 |
| stopped | 2 |
Recover a visit even though neither recorded fix is inside the fence
SELECT entity_id, duration_s, fix_count
FROM trajectory.main.episodes((SELECT * FROM trajectory.main.sample_fixes))
WHERE episode_type='visit'
ORDER BY entity_id;
ASOF-join each reconstructed visit back to the last sample_fixes fix at or before its entry: the crossing entity entered the yard 30 seconds after its last fix and has zero fixes inside, while the stopped entity's visit starts at a recorded fix
SELECT v.entity_id, v.fence_id, v.started_at, f.observed_at AS last_fix_at,
date_diff('second', f.observed_at, v.started_at) AS seconds_after_fix,
v.fix_count
FROM trajectory.main.episodes((SELECT * FROM trajectory.main.sample_fixes)) AS v
ASOF JOIN trajectory.main.sample_fixes AS f ON v.entity_id = f.entity_id AND v.started_at >= f.observed_at
WHERE v.episode_type = 'visit'
ORDER BY v.entity_id, v.started_at;
Share of each entity's observed span (first to last sample_fixes fix) spent in fence visits: crossing spends 60 of 120 seconds in the yard (0.5), stopped all 600 seconds (1.0)
WITH span AS (SELECT entity_id, date_diff('second', min(observed_at), max(observed_at)) AS observed_s FROM trajectory.main.sample_fixes GROUP BY entity_id), visits AS (SELECT entity_id, sum(duration_s) AS visit_s FROM trajectory.main.episodes((SELECT * FROM trajectory.main.sample_fixes)) WHERE episode_type = 'visit' GROUP BY entity_id) SELECT span.entity_id, span.observed_s, coalesce(visits.visit_s, 0) AS visit_s, round(coalesce(visits.visit_s, 0) / span.observed_s, 3) AS visit_share
FROM span
LEFT JOIN visits USING (entity_id)
ORDER BY span.entity_id;
sample_fixes
Two synthetic GPS tracks demonstrating a between-fix crossing and a stop
Count observations per synthetic entity
SELECT entity_id, count(*)
FROM trajectory.main.sample_fixes
GROUP BY entity_id
ORDER BY entity_id;
| entity_id | count_star() |
|---|---|
| crossing | 2 |
| stopped | 2 |
episodes (data TABLE, analysis_crs := VARCHAR, fence_buffer_m := DOUBLE, fence_crs := VARCHAR, fences := VARCHAR, input_crs := VARCHAR, max_accuracy_m := DOUBLE, max_episodes := BIGINT, max_fence_vertices := BIGINT, max_fences := BIGINT, max_gap_s := DOUBLE, max_input_bytes := BIGINT, max_json_bytes := BIGINT, max_path_vertices := BIGINT, max_points := BIGINT, max_segment_splits := BIGINT, max_speed_m_s := DOUBLE, min_dwell_s := DOUBLE)
Reconstruct visits, dwell, trips and gaps from timestamped GPS rows
Recover a visit even though neither recorded fix is inside the fence
SELECT entity_id, duration_s, fix_count
FROM trajectory.main.episodes((SELECT * FROM trajectory.main.sample_fixes))
WHERE episode_type='visit'
ORDER BY entity_id;
ASOF-join each reconstructed visit back to the last sample_fixes fix at or before its entry: the crossing entity entered the yard 30 seconds after its last fix and has zero fixes inside, while the stopped entity's visit starts at a recorded fix
SELECT v.entity_id, v.fence_id, v.started_at, f.observed_at AS last_fix_at,
date_diff('second', f.observed_at, v.started_at) AS seconds_after_fix,
v.fix_count
FROM trajectory.main.episodes((SELECT * FROM trajectory.main.sample_fixes)) AS v
ASOF JOIN trajectory.main.sample_fixes AS f ON v.entity_id = f.entity_id AND v.started_at >= f.observed_at
WHERE v.episode_type = 'visit'
ORDER BY v.entity_id, v.started_at;
Share of each entity's observed span (first to last sample_fixes fix) spent in fence visits: crossing spends 60 of 120 seconds in the yard (0.5), stopped all 600 seconds (1.0)
WITH span AS (SELECT entity_id, date_diff('second', min(observed_at), max(observed_at)) AS observed_s FROM trajectory.main.sample_fixes GROUP BY entity_id), visits AS (SELECT entity_id, sum(duration_s) AS visit_s FROM trajectory.main.episodes((SELECT * FROM trajectory.main.sample_fixes)) WHERE episode_type = 'visit' GROUP BY entity_id) SELECT span.entity_id, span.observed_s, coalesce(visits.visit_s, 0) AS visit_s, round(coalesce(visits.visit_s, 0) / span.observed_s, 3) AS visit_share
FROM span
LEFT JOIN visits USING (entity_id)
ORDER BY span.entity_id;
Try these queries
Recover a visit even though neither recorded fix is inside the fence
SELECT entity_id, duration_s, fix_count
FROM trajectory.main.episodes((SELECT * FROM trajectory.main.sample_fixes))
WHERE episode_type='visit'
ORDER BY entity_id
Uses episodessample_fixes
ASOF-join each reconstructed visit back to the last sample_fixes fix at or before its entry: the crossing entity entered the yard 30 seconds after its last fix and has zero fixes inside, while the stopped entity's visit starts at a recorded fix
SELECT v.entity_id, v.fence_id, v.started_at, f.observed_at AS last_fix_at,
date_diff('second', f.observed_at, v.started_at) AS seconds_after_fix,
v.fix_count
FROM trajectory.main.episodes((SELECT * FROM trajectory.main.sample_fixes)) AS v
ASOF JOIN trajectory.main.sample_fixes AS f ON v.entity_id = f.entity_id AND v.started_at >= f.observed_at
WHERE v.episode_type = 'visit'
ORDER BY v.entity_id, v.started_at
Uses episodessample_fixes
Share of each entity's observed span (first to last sample_fixes fix) spent in fence visits: crossing spends 60 of 120 seconds in the yard (0.5), stopped all 600 seconds (1.0)
WITH span AS (SELECT entity_id, date_diff('second', min(observed_at), max(observed_at)) AS observed_s FROM trajectory.main.sample_fixes GROUP BY entity_id), visits AS (SELECT entity_id, sum(duration_s) AS visit_s FROM trajectory.main.episodes((SELECT * FROM trajectory.main.sample_fixes)) WHERE episode_type = 'visit' GROUP BY entity_id) SELECT span.entity_id, span.observed_s, coalesce(visits.visit_s, 0) AS visit_s, round(coalesce(visits.visit_s, 0) / span.observed_s, 3) AS visit_share
FROM span
LEFT JOIN visits USING (entity_id)
ORDER BY span.entity_id
Uses sample_fixesepisodes
Trajectory is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
ArcGIS
Maps & places
Live ArcGIS feature queries, server summaries and raster sampling from service URLs worldwide
Vector tiles (MVT)
Maps & places
Decode PMTiles, MBTiles, XYZ and .mvt vector tiles into DuckDB rows with GEOMETRY columns
Lidar
Maps & places
Classified point-cloud heights and vegetation clearance around power lines