[gdal-dev] UK Ordnance Survey grid references

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] UK Ordnance Survey grid references

Paul Meems
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_transformations/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'.

Is this possible with GDAL? If so do I still make the changes mentioned on the webpage and how would the code look like to do this?

Thanks,

Paul

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: UK Ordnance Survey grid references

Even Rouault-2
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
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: UK Ordnance Survey grid references

Even Rouault-2
> and drop the last 2 figures and round appropriately

Hum, after reflexion, rounding is likely not appropriate, as you give a
position in a 100x100 square. So truncating should be rather done.

And if truncating is done, then I assume your input coordinates are in
EPSG:4326, since

$ echo "-2.02903211116781 53.4040442788744" | \
                gdaltransform -s_srs EPSG:4326 -t_srs EPSG:27700
398167.225983081 389691.930910573

Hence SJ981896 as you expected

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: UK Ordnance Survey grid references

Paul Meems
Thanks Even for your quick response and your full example.

You are right the coordinates are in EPSG:4326.
I will use this example.

Thanks,

Paul



Op za 27 apr. 2019 om 18:36 schreef Even Rouault <[hidden email]>:
> and drop the last 2 figures and round appropriately

Hum, after reflexion, rounding is likely not appropriate, as you give a
position in a 100x100 square. So truncating should be rather done.

And if truncating is done, then I assume your input coordinates are in
EPSG:4326, since

$ echo "-2.02903211116781 53.4040442788744" | \
                gdaltransform -s_srs EPSG:4326 -t_srs EPSG:27700
398167.225983081 389691.930910573

Hence SJ981896 as you expected

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev