4

Is there any specific feature to convert raster values (representing elevation) between basis systems, or do I just have to make do with manually adding the mean offset having looked it up from somewhere else?

In particular, I have raster data representing elevation above ODN that I want to convert to elevation above the WGS-84 ellipsoid.


This does not work:

SELECT ST_Transform('SRID=7405;POINT(545068 258591 8.51)'::geometry, 4979);

instead returning a point with XY transformed, but not Z. The result should be ~54.

2
  • The vertical datum conversion is likely going to vary across your area of interest so adding or subtracting some mean value is only going to degrade the quality of your data. There are posts here on GIS-SE for doing vertical datum conversions using GDAL and PyProj if that option works for you. Another alternative would be to create a lattice of points with elevation = 0 and use vDatum to do the vertical datum conversion. Then interpolate a surface from the conversion values to make your own local conversion grid. All this assumes the required gtx files are available for the UK.
    – GBG
    Commented Jan 26, 2023 at 16:24
  • @GBG I'm looking for a way to do it in PostGIS. It already has GDAL and the definitions for these SRs, and the data files for OSGM15 are available if it's missing for some reason.
    – OrangeDog
    Commented Jan 26, 2023 at 16:37

2 Answers 2

1

You will need to inject PROJ_NETWORK set to ON into your PostgreSQL start-up environment. And your PostgreSQL user will need write access to its home directory probably too.

See https://proj.org/usage/network.html

This is not fundamentally a PostGIS problem, it's a configuration of the underlying Proj library which you are seeing via PostGIS. You can see it at the commandline like this:

echo 545068 258591 8.51 | PROJ_NETWORK=ON cs2cs 'EPSG:7405' 'EPSG:4979'
5
  • what exactly is PostgreSQL start-up environment here? Commented Feb 2, 2023 at 9:26
  • @AmanBagrecha the environment variables for the postgresql process. E.g. defined with Environment= in a systemd unit or -e when using Docker.
    – OrangeDog
    Commented Feb 2, 2023 at 9:37
  • This works. You can prefetch all the data too, with e.g. projsync --system-directory --source-id uk_os. The package that tool is in may be proj-util or proj-bin depending on distribution.
    – OrangeDog
    Commented Feb 2, 2023 at 9:53
  • Can you show how to set this env up and at which location. I am confused with what you mentioned. Tried export PROJ_NETWORK=ON and that did not work. Tried adding to /etc/postgresql/14/main/environment and that did not work Commented Feb 2, 2023 at 10:51
  • @AmanBagrecha it depends how your postgres service is managed
    – OrangeDog
    Commented Feb 2, 2023 at 13:30
0

This works with PostGIS 2.5:

SELECT ST_Transform('SRID=7405;POINT(545068 258591 8.51)'::geometry, '+proj=longlat +datum=WGS84 +no_defs');

-- POINT(0.12155634533395 52.2064557410345 55.0274234022945)

But it does not work with PostGIS 3.0+:

SELECT ST_Transform('SRID=7405;POINT(545068 258591 8.51)'::geometry, '+proj=longlat +datum=WGS84 +no_defs');

-- POINT(0.12155638871122 52.206455740841434 8.51)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.