2

Is there an existing method or best practice for calculating Geoid height for a lat/lon location in PostGIS? I don't believe there is an "ST_" function.

I know that PostGIS makes use of GeographicLib for some calculations already and that GeographicLib has methods for calculating Geoid height.

1 Answer 1

1

Calculating, No. Looking up, Yes.

Pre-calculated data is available for the various Geoid models (EGM84, EGM96, EGM2008) in raster format. Here's an easy to use source:

https://sourceforge.net/projects/geographiclib/files/geoids-distrib/ or https://geographiclib.sourceforge.io/html/geoid.html#geoidinst

The raster files can be imported into your db using raster2pgsql. For example:

raster2pgsql -s 4326 -I -C -M egm2008-1.tif -F -t 100x100 myschema.geoid_egm2008 | psql -h localhost -p 5432 -U user -d db

And then querying:

SELECT ST_Value(rast, ST_SetSRID(ST_MakePoint(mod(-75.49393 + 360,360), 39.96002),4326))::numeric * 0.003 - 108
FROM myschema.geoid_egm2008
WHERE ST_Intersects(rast, ST_SetSRID(ST_MakePoint(mod(-75.49393 + 360,360), 39.96002),4326));
--Should be ~ -33.9943

Note the scaling & offsetting spec:

   # Offset -108
   # Scale 0.003
   # Origin 90N 0E

Explanation here: https://geographiclib.sourceforge.io/html/geoid.html#geoidformat

See here and here for further information on raster2pgsql tile size optimization and querying raster data.

Your Answer

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

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