From 3fc509f9bf8f1db85d549f616119476d09b1c208 Mon Sep 17 00:00:00 2001 From: Gabor Szarnyas Date: Fri, 7 Mar 2025 09:27:54 +0100 Subject: [PATCH] Add example from docs See https://github.com/duckdb/duckdb-web/pull/4794 --- src/spatial/modules/proj/proj_module.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/spatial/modules/proj/proj_module.cpp b/src/spatial/modules/proj/proj_module.cpp index 7e9c0d3a..aa957542 100644 --- a/src/spatial/modules/proj/proj_module.cpp +++ b/src/spatial/modules/proj/proj_module.cpp @@ -372,6 +372,25 @@ struct ST_Transform { ); ---- POINT (544615.0239773799 6867874.103539125) + + -- Transform a geometry from OSG36 British National Grid EPSG:27700 to EPSG:4326 WGS84 + -- Standard transform is often fine for the first few decimal places before being wrong + -- which could result in an error starting at about 10m and possibly much more + SELECT ST_Transform(bng, 'EPSG:27700', 'EPSG:4326', xy := true) AS without_grid_file + FROM (SELECT ST_GeomFromText('POINT( 170370.718 11572.405 )') AS bng); + ---- + POINT (-5.202992651563592 49.96007490162923) + + -- By using an official NTv2 grid file, we can reduce the error down around the 9th decimal place + -- which in theory is below a millimetre, and in practise unlikely that your coordinates are that precise + -- British National Grid "NTv2 format files" download available here: + -- https://www.ordnancesurvey.co.uk/products/os-net/for-developers + SELECT ST_Transform(bng + , '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs +nadgrids=/full/path/to/OSTN15-NTv2/OSTN15_NTv2_OSGBtoETRS.gsb +type=crs' + , 'EPSG:4326', xy := true) AS with_grid_file + FROM (SELECT ST_GeomFromText('POINT( 170370.718 11572.405 )') AS bng) t; + ---- + POINT (-5.203046090608746 49.96006137018598) )"; //------------------------------------------------------------------------------------------------------------------