[gdal-dev] UK Ordnance Survey grid references
Even Rouault
even.rouault at spatialys.com
Sat Apr 27 09:17:12 PDT 2019
On samedi 27 avril 2019 17:09:51 CEST Paul Meems wrote:
> Hi,
>
> I'm not sure if this is the correct list, it might be I need to ask this on
> the proj4-list.
> Because I'm not a member of that list, I try here first.
>
> Can GDAL/OGR/Proj4 convert lat/long coordinates to Ordnance Survey grid
> references?
> I've been searching for an answer and found only this page:
> https://digimap.edina.ac.uk/webhelp/digimapgis/projections_and_transformatio
> ns/transformations_in_gdalogr.htm suggesting
> it is possible with GDAL after some changes.
> But I can't find an example of how to convert '-2.02903211116781,
> 53.4040442788744' to 'SJ981896'.
I'm not a specialist of this grid reference, but based on the information
https://en.wikipedia.org/wiki/Ordnance_Survey_National_Grid
here's how I would do the conversion.
First, in which CRS are those coordinates: in OSGB36 (EPSG:4277) or WGS84 (EPSG:4326) ?
Anyway given that the grid coordinates have 6 figures, thus 3 figures
for easting and northing, SJ981896 has only 100 meter precision (the page you
reference is just about using more accurate datum shift parameters, but this is
only if you are interested in ~1 meter precision, not 100 meter precision)
Let's assume they are already in OSGB36, and transform them to the
"OSGB 1936 / British National Grid" projected CRS (EPSG:27700):
$ echo "-2.02903211116781 53.4040442788744" | \
gdaltransform -s_srs EPSG:4277 -t_srs EPSG:27700
==> 398070.067760347 389720.9200866 0
So let drop the sub-meter precision and isolate the figures that are multiple of 100km in those coordinates:
3 98070, 3 89720
and drop the last 2 figures and round appropriately, to get only 4 digits
3 981, 3 897
Now let's find the square of 100km x 100km whose bottom left coordinate is
x=3 and y=3, which according to
https://en.wikipedia.org/wiki/Ordnance_Survey_National_Grid#/media/File:British_National_Grid.svg
is SJ (SV is located at x=0 and y=0)
Hence SJ981897
So GDAL & PROJ handle the transformation from geographic to projected coordinates.
The formatting of the projected coordinates to the national grid reference
is left as an exercice to users :-)
(I'd be surprised if there is no code in the wild that would do the whole conversion)
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list