Skip to content

PROJ

Reproject coordinates between CRSs and measure geodesic distances on the WGS84 ellipsoid

Connector software
Free and open source
Service credentials
Not needed
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/proj/index.md to help me query PROJ 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.

See what you can query

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
WITH eye AS (SELECT proj.main.transform(530600.0, 179700.0, 'EPSG:27700', 'EPSG:4326') AS o), sites(site, easting, northing) AS (VALUES ('Edinburgh Castle', 325160.0, 673490.0), ('Cardiff Castle', 318080.0, 176540.0), ('York Minster', 460350.0, 452230.0)), ll AS (SELECT site, proj.main.transform(easting, northing, 'EPSG:27700', 'EPSG:4326') AS p FROM sites) SELECT site, round(p.x, 4) AS lon, round(p.y, 4) AS lat, round(proj.main.geodesic_distance(o.x, o.y, p.x, p.y) / 1000, 1) AS km_from_london_eye
FROM ll
CROSS JOIN eye
ORDER BY km_from_london_eye
Result
site lon lat km_from_london_eye
Cardiff Castle -3.1811 51.4819 212.6
York Minster -1.0816 53.9626 281.5
Edinburgh Castle -3.2 55.9486 535

Quick start

Choose where to run PROJ, 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.

setup.sql
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;

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 'proj' AS proj (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-proj-worker'
);

3. Run a query

query.sql
WITH eye AS (SELECT proj.main.transform(530600.0, 179700.0, 'EPSG:27700', 'EPSG:4326') AS o), sites(site, easting, northing) AS (VALUES ('Edinburgh Castle', 325160.0, 673490.0), ('Cardiff Castle', 318080.0, 176540.0), ('York Minster', 460350.0, 452230.0)), ll AS (SELECT site, proj.main.transform(easting, northing, 'EPSG:27700', 'EPSG:4326') AS p FROM sites) SELECT site, round(p.x, 4) AS lon, round(p.y, 4) AS lat, round(proj.main.geodesic_distance(o.x, o.y, p.x, p.y) / 1000, 1) AS km_from_london_eye
FROM ll
CROSS JOIN eye
ORDER BY km_from_london_eye
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
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 'proj' AS proj (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-proj-worker'
);

Overview

CRS transforms (always_xy) + WGS84 geodesic distance/bearing via pyproj/PROJ.

Catalog

Everything proj exposes once attached — read straight from the worker's released build.

proj 1 schema
main 8 functions

CRS transforms (always_xy) + WGS84 geodesic distance/bearing via pyproj/PROJ

Schema examples (12)
Examples (12)

Transform a WGS84 lon/lat point to Web Mercator metres.

SELECT proj.main.transform(-122.42, 37.77, 'EPSG:4326', 'EPSG:3857');

Get the UTM zone number for a San Francisco lon/lat.

SELECT proj.main.to_utm(-122.42, 37.77).zone;

Project a WGS84 point to Web Mercator via the shorthand.

SELECT proj.main.to_webmercator(-122.4194, 37.7749);

Round-trip Web Mercator metres back to WGS84 lon/lat.

SELECT proj.main.from_webmercator(-13627665.27, 4547675.35);
8 more examples

Geodesic distance New York to London, in metres.

SELECT proj.main.geodesic_distance(-74.006, 40.7128, -0.1276, 51.5074);

Initial geodesic bearing from New York toward London, in degrees.

SELECT proj.main.geodesic_bearing(-74.006, 40.7128, -0.1276, 51.5074);

Human-readable name of the WGS84 CRS.

SELECT proj.main.crs_name('EPSG:4326');

Axis units of the Web Mercator CRS.

SELECT proj.main.crs_units('EPSG:3857');

Reproject British National Grid (EPSG:27700) easting/northing sites to WGS84 lon/lat and rank them by geodesic distance from the London Eye (Cardiff Castle 212.6 km, York Minster 281.5 km, Edinburgh Castle 535.0 km).

WITH eye AS (SELECT proj.main.transform(530600.0, 179700.0, 'EPSG:27700', 'EPSG:4326') AS o), sites(site, easting, northing) AS (VALUES ('Edinburgh Castle', 325160.0, 673490.0), ('Cardiff Castle', 318080.0, 176540.0), ('York Minster', 460350.0, 452230.0)), ll AS (SELECT site, proj.main.transform(easting, northing, 'EPSG:27700', 'EPSG:4326') AS p FROM sites) SELECT site, round(p.x, 4) AS lon, round(p.y, 4) AS lat, round(proj.main.geodesic_distance(o.x, o.y, p.x, p.y) / 1000, 1) AS km_from_london_eye
FROM ll
CROSS JOIN eye
ORDER BY km_from_london_eye;
Result
site lon lat km_from_london_eye
Cardiff Castle -3.1811 51.4819 212.6
York Minster -1.0816 53.9626 281.5
Edinburgh Castle -3.2 55.9486 535

Check straight-line UTM grid distances against the true WGS84 geodesic distance for three San Francisco survey segments (all in UTM zone 10): the grid figure runs 2.4-3.0 m short over these 6.6-7.9 km segments because of UTM's scale factor near the central meridian.

WITH segments(segment, lon1, lat1, lon2, lat2) AS (VALUES ('Ferry Building -> Golden Gate Bridge', -122.3937, 37.7955, -122.4783, 37.8199), ('Ferry Building -> Twin Peaks', -122.3937, 37.7955, -122.4477, 37.7544), ('Twin Peaks -> Golden Gate Bridge', -122.4477, 37.7544, -122.4783, 37.8199)), u AS (SELECT segment, lon1, lat1, lon2, lat2, proj.main.to_utm(lon1, lat1) AS a, proj.main.to_utm(lon2, lat2) AS b FROM segments) SELECT segment, a.zone AS utm_zone, round(sqrt(power(b.easting - a.easting, 2) + power(b.northing - a.northing, 2)), 1) AS utm_grid_m, round(proj.main.geodesic_distance(lon1, lat1, lon2, lat2), 1) AS geodesic_m
FROM u
ORDER BY segment;

Measure the true ground length of segments stored in Web Mercator (EPSG:3857) metres by converting their endpoints back to lon/lat: the same 5,000 Mercator metres is ~5,000 m near the equator (Quito) but only ~2,513 m at Oslo (lat 59.9).

WITH segments(segment, x1, y1, x2, y2) AS (VALUES ('Quito, 5 km east', -8738000.0, -24600.0, -8733000.0, -24600.0), ('Oslo, 5 km east', 1194000.0, 8381000.0, 1199000.0, 8381000.0)), ll AS (SELECT segment, x1, y1, x2, y2, proj.main.from_webmercator(x1, y1) AS a, proj.main.from_webmercator(x2, y2) AS b FROM segments) SELECT segment, round(a.lat, 2) AS lat, round(sqrt(power(x2 - x1, 2) + power(y2 - y1, 2))) AS mercator_m, round(proj.main.geodesic_distance(a.lon, a.lat, b.lon, b.lat)) AS geodesic_m
FROM ll
ORDER BY segment;

Distance (km) and initial compass bearing (degrees) from New York to five world cities, nearest first (London 5,585 km at 51 deg ... Sydney 15,988 km at 266 deg).

WITH destinations(city, lon, lat) AS (VALUES ('London', -0.1276, 51.5074), ('Paris', 2.3522, 48.8566), ('Tokyo', 139.6917, 35.6895), ('Sydney', 151.2093, -33.8688), ('Sao Paulo', -46.6333, -23.5505)) SELECT city, round(proj.main.geodesic_distance(-74.006, 40.7128, lon, lat) / 1000) AS distance_km, round(proj.main.geodesic_bearing(-74.006, 40.7128, lon, lat)) AS initial_bearing_deg
FROM destinations
ORDER BY distance_km;
Scalar functions
crs_name (crs VARCHAR) 1 example

Human-readable name of a CRS (e.g. 'WGS 84'); unknown CRS -> error

Arguments
crs VARCHAR
CRS identifier (EPSG code/string, e.g. 'EPSG:4326'). Unknown CRS -> error.
ReturnsVARCHAR
Example

Name of WGS84 ('WGS 84')

SELECT proj.crs_name('EPSG:4326');
Link
crs_units (crs VARCHAR) 1 example

Unit name of a CRS's first axis (e.g. 'degree', 'metre'); unknown CRS -> error

Arguments
crs VARCHAR
CRS identifier (EPSG code/string, e.g. 'EPSG:4326'). Unknown CRS -> error.
ReturnsVARCHAR
Example

Units of Web Mercator ('metre')

SELECT proj.crs_units('EPSG:3857');
Link
from_webmercator (x DOUBLE, y DOUBLE) 2 examples

Web Mercator (x, y) metres -> WGS84 STRUCT(lon, lat) (EPSG:3857->4326)

Arguments
x DOUBLE
Web Mercator easting (x) in metres.
y DOUBLE
Web Mercator northing (y) in metres.
ReturnsSTRUCT(lon DOUBLE, lat DOUBLE)
Examples (2)

Web Mercator metres back to San Francisco lon/lat

SELECT proj.from_webmercator(-13627665.27, 4547675.35);

Measure the true ground length of segments stored in Web Mercator (EPSG:3857) metres by converting their endpoints back to lon/lat: the same 5,000 Mercator metres is ~5,000 m near the equator (Quito) but only ~2,513 m at Oslo (lat 59.9).

WITH segments(segment, x1, y1, x2, y2) AS (VALUES ('Quito, 5 km east', -8738000.0, -24600.0, -8733000.0, -24600.0), ('Oslo, 5 km east', 1194000.0, 8381000.0, 1199000.0, 8381000.0)), ll AS (SELECT segment, x1, y1, x2, y2, proj.main.from_webmercator(x1, y1) AS a, proj.main.from_webmercator(x2, y2) AS b FROM segments) SELECT segment, round(a.lat, 2) AS lat, round(sqrt(power(x2 - x1, 2) + power(y2 - y1, 2))) AS mercator_m, round(proj.main.geodesic_distance(a.lon, a.lat, b.lon, b.lat)) AS geodesic_m
FROM ll
ORDER BY segment;
Link
geodesic_bearing (lon1 DOUBLE, lat1 DOUBLE, lon2 DOUBLE, lat2 DOUBLE) 2 examples

Initial geodesic bearing (forward azimuth) from point 1 to point 2, degrees [0,360)

Arguments
lon1 DOUBLE
Longitude of point 1 (-180..180).
lat1 DOUBLE
Latitude of point 1 (-90..90).
lon2 DOUBLE
Longitude of point 2 (-180..180).
lat2 DOUBLE
Latitude of point 2 (-90..90).
ReturnsDOUBLE
Examples (2)

Initial bearing from New York toward London

SELECT proj.geodesic_bearing(-74.006, 40.7128, -0.1276, 51.5074);

Distance (km) and initial compass bearing (degrees) from New York to five world cities, nearest first (London 5,585 km at 51 deg ... Sydney 15,988 km at 266 deg).

WITH destinations(city, lon, lat) AS (VALUES ('London', -0.1276, 51.5074), ('Paris', 2.3522, 48.8566), ('Tokyo', 139.6917, 35.6895), ('Sydney', 151.2093, -33.8688), ('Sao Paulo', -46.6333, -23.5505)) SELECT city, round(proj.main.geodesic_distance(-74.006, 40.7128, lon, lat) / 1000) AS distance_km, round(proj.main.geodesic_bearing(-74.006, 40.7128, lon, lat)) AS initial_bearing_deg
FROM destinations
ORDER BY distance_km;
Link
geodesic_distance (lon1 DOUBLE, lat1 DOUBLE, lon2 DOUBLE, lat2 DOUBLE) 2 examples

Accurate ellipsoidal (WGS84) geodesic distance between two points, in metres

Arguments
lon1 DOUBLE
Longitude of point 1 (-180..180).
lat1 DOUBLE
Latitude of point 1 (-90..90).
lon2 DOUBLE
Longitude of point 2 (-180..180).
lat2 DOUBLE
Latitude of point 2 (-90..90).
ReturnsDOUBLE
Examples (2)

New York to London (~5,585,000 m)

SELECT proj.geodesic_distance(-74.006, 40.7128, -0.1276, 51.5074);

Distance (km) and initial compass bearing (degrees) from New York to five world cities, nearest first (London 5,585 km at 51 deg ... Sydney 15,988 km at 266 deg).

WITH destinations(city, lon, lat) AS (VALUES ('London', -0.1276, 51.5074), ('Paris', 2.3522, 48.8566), ('Tokyo', 139.6917, 35.6895), ('Sydney', 151.2093, -33.8688), ('Sao Paulo', -46.6333, -23.5505)) SELECT city, round(proj.main.geodesic_distance(-74.006, 40.7128, lon, lat) / 1000) AS distance_km, round(proj.main.geodesic_bearing(-74.006, 40.7128, lon, lat)) AS initial_bearing_deg
FROM destinations
ORDER BY distance_km;
Link
to_utm (lon DOUBLE, lat DOUBLE) 3 examples

Project WGS84 (lon, lat) into its auto-selected UTM zone as STRUCT(easting, northing, zone, hemisphere, epsg); NULL/out-of-range -> NULL

Arguments
lon DOUBLE
Longitude in degrees (-180..180).
lat DOUBLE
Latitude in degrees (-90..90).
ReturnsSTRUCT of 5 fields
STRUCT 5 fields
  • eastingDOUBLE
  • northingDOUBLE
  • zoneINTEGER
  • hemisphereVARCHAR
  • epsgINTEGER
Examples (3)

UTM for San Francisco (zone 10N)

SELECT proj.to_utm(-122.42, 37.77);

UTM zone number for San Francisco (10)

SELECT proj.to_utm(-122.42, 37.77).zone;

Check straight-line UTM grid distances against the true WGS84 geodesic distance for three San Francisco survey segments (all in UTM zone 10): the grid figure runs 2.4-3.0 m short over these 6.6-7.9 km segments because of UTM's scale factor near the central meridian.

WITH segments(segment, lon1, lat1, lon2, lat2) AS (VALUES ('Ferry Building -> Golden Gate Bridge', -122.3937, 37.7955, -122.4783, 37.8199), ('Ferry Building -> Twin Peaks', -122.3937, 37.7955, -122.4477, 37.7544), ('Twin Peaks -> Golden Gate Bridge', -122.4477, 37.7544, -122.4783, 37.8199)), u AS (SELECT segment, lon1, lat1, lon2, lat2, proj.main.to_utm(lon1, lat1) AS a, proj.main.to_utm(lon2, lat2) AS b FROM segments) SELECT segment, a.zone AS utm_zone, round(sqrt(power(b.easting - a.easting, 2) + power(b.northing - a.northing, 2)), 1) AS utm_grid_m, round(proj.main.geodesic_distance(lon1, lat1, lon2, lat2), 1) AS geodesic_m
FROM u
ORDER BY segment;
Link
to_webmercator (lon DOUBLE, lat DOUBLE) 1 example

WGS84 (lon, lat) -> Web Mercator STRUCT(x, y) in metres (EPSG:4326->3857)

Arguments
lon DOUBLE
Longitude in degrees (WGS84).
lat DOUBLE
Latitude in degrees (WGS84).
ReturnsSTRUCT(x DOUBLE, y DOUBLE)
Example

San Francisco in Web Mercator metres

SELECT proj.to_webmercator(-122.4194, 37.7749);
Link
transform (x DOUBLE, y DOUBLE, from_crs VARCHAR, to_crs VARCHAR) 12 examples

Transform (x, y) from from_crs to to_crs as STRUCT(x, y); always_xy axis order. NULL coord -> NULL; unknown CRS -> error

Arguments
x DOUBLE
X / longitude / easting in from_crs.
y DOUBLE
Y / latitude / northing in from_crs.
from_crs VARCHAR
CRS identifier (EPSG code/string, e.g. 'EPSG:4326'). Unknown CRS -> error.
to_crs VARCHAR
CRS identifier (EPSG code/string, e.g. 'EPSG:4326'). Unknown CRS -> error.
ReturnsSTRUCT(x DOUBLE, y DOUBLE)
Examples (12)

WGS84 lon/lat to Web Mercator metres

SELECT proj.transform(-122.42, 37.77, 'EPSG:4326', 'EPSG:3857');

Reproject British National Grid (EPSG:27700) easting/northing sites to WGS84 lon/lat and rank them by geodesic distance from the London Eye (Cardiff Castle 212.6 km, York Minster 281.5 km, Edinburgh Castle 535.0 km).

WITH eye AS (SELECT proj.main.transform(530600.0, 179700.0, 'EPSG:27700', 'EPSG:4326') AS o), sites(site, easting, northing) AS (VALUES ('Edinburgh Castle', 325160.0, 673490.0), ('Cardiff Castle', 318080.0, 176540.0), ('York Minster', 460350.0, 452230.0)), ll AS (SELECT site, proj.main.transform(easting, northing, 'EPSG:27700', 'EPSG:4326') AS p FROM sites) SELECT site, round(p.x, 4) AS lon, round(p.y, 4) AS lat, round(proj.main.geodesic_distance(o.x, o.y, p.x, p.y) / 1000, 1) AS km_from_london_eye
FROM ll
CROSS JOIN eye
ORDER BY km_from_london_eye;
Result
site lon lat km_from_london_eye
Cardiff Castle -3.1811 51.4819 212.6
York Minster -1.0816 53.9626 281.5
Edinburgh Castle -3.2 55.9486 535
SELECT proj.main.transform(-122.42, 37.77, 'EPSG:4326', 'EPSG:3857') AS xy;
9 more examples
SELECT proj.main.to_utm(-122.42, 37.77) AS utm;
SELECT proj.main.to_webmercator(-122.4194, 37.7749) AS xy;
SELECT proj.main.from_webmercator(-13627665.27, 4547675.35) AS lonlat;
SELECT proj.main.geodesic_distance(-74.006, 40.7128, -0.1276, 51.5074) AS m;
SELECT proj.main.geodesic_bearing(-74.006, 40.7128, -0.1276, 51.5074) AS deg;
SELECT proj.main.crs_name('EPSG:4326') AS name;
SELECT proj.main.crs_units('EPSG:3857') AS units;
WITH segments(segment, x1, y1, x2, y2) AS (VALUES ('Quito, 5 km east', -8738000.0, -24600.0, -8733000.0, -24600.0), ('Oslo, 5 km east', 1194000.0, 8381000.0, 1199000.0, 8381000.0)), ll AS (SELECT segment, x1, y1, x2, y2, proj.main.from_webmercator(x1, y1) AS a, proj.main.from_webmercator(x2, y2) AS b FROM segments) SELECT segment, round(a.lat, 2) AS lat, round(sqrt(power(x2 - x1, 2) + power(y2 - y1, 2))) AS mercator_m, round(proj.main.geodesic_distance(a.lon, a.lat, b.lon, b.lat)) AS geodesic_m
FROM ll
ORDER BY segment;
WITH destinations(city, lon, lat) AS (VALUES ('London', -0.1276, 51.5074), ('Paris', 2.3522, 48.8566), ('Tokyo', 139.6917, 35.6895), ('Sydney', 151.2093, -33.8688), ('Sao Paulo', -46.6333, -23.5505)) SELECT city, round(proj.main.geodesic_distance(-74.006, 40.7128, lon, lat) / 1000) AS distance_km, round(proj.main.geodesic_bearing(-74.006, 40.7128, lon, lat)) AS initial_bearing_deg
FROM destinations
ORDER BY distance_km;
Link

Try these queries

Transform a WGS84 lon/lat point to Web Mercator metres.

SELECT proj.main.transform(-122.42, 37.77, 'EPSG:4326', 'EPSG:3857')

Uses transform

Get the UTM zone number for a San Francisco lon/lat.

SELECT proj.main.to_utm(-122.42, 37.77).zone

Uses to_utm

Project a WGS84 point to Web Mercator via the shorthand.

SELECT proj.main.to_webmercator(-122.4194, 37.7749)

Uses to_webmercator

Round-trip Web Mercator metres back to WGS84 lon/lat.

SELECT proj.main.from_webmercator(-13627665.27, 4547675.35)

Uses from_webmercator

Geodesic distance New York to London, in metres.

SELECT proj.main.geodesic_distance(-74.006, 40.7128, -0.1276, 51.5074)

Uses geodesic_distance

Initial geodesic bearing from New York toward London, in degrees.

SELECT proj.main.geodesic_bearing(-74.006, 40.7128, -0.1276, 51.5074)

Uses geodesic_bearing

22 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • What is the official human-readable name of the coordinate reference system identified by EPSG code 4326?
  • What are the linear axis units of the Web Mercator coordinate reference system, EPSG:3857?
  • Which UTM zone number contains the WGS84 location at longitude -122.42, latitude 37.77? Return just the zone number.

PROJ 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.