question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Building Compound CRS with WGS84 & EGM96?

See original GitHub issue

Disclaimer: I have read https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6 and am aware of the fact that PROJ now honors the axis order of a CRS when initialized with EPSG:xxxx.

Code Sample

I think I have found an inconsistency in the way the axis order is interpreted with EPSG:4326. Consider the following snippet:

import pyproj

ellipsoid = pyproj.CRS.from_epsg(4326)  # WGS84
geoid = pyproj.CRS.from_epsg(5773)  # EGM96
utm = pyproj.CRS.from_epsg(32610)  # UTM zone 10

lat, lon = 45, -122
for name, trf in zip(
    ["WGS84 -> EGM96", "WGS84 -> UTM"],
    [pyproj.Transformer.from_crs(ellipsoid, geoid), pyproj.Transformer.from_crs(ellipsoid, utm)],
):
    print(name, "lon, lat", trf.transform(lon, lat, 10))
    print(name, "lat, lon", trf.transform(lat, lon, 10))

It prints the following output:

WGS84 -> EGM96 lon, lat (-122.0, 45.0, 30.38683319091797)
WGS84 -> EGM96 lat, lon (45.0, -122.0, -inf)
WGS84 -> UTM lon, lat (inf, inf, inf)
WGS84 -> UTM lat, lon (578815.302916712, 4983436.768349296, 10.0)

Problem description

Since the axis order of EPSG:4326 is

Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)

I would expect to always have to pass x=lat, y=lon in a Transformer.transform call in order for everything to work correctly.

However as shown with the snippet above:

  1. when transforming datums from WGS84 to EGM96, it is the call with x=lon, y=lat that gives the correct output
  2. when transforming coordinates from WGS84 to UTM zone 10, as expected it is the call with x=lat, y=lon that gives the correct output.

Expected Output

I would expect to always have to pass x=lat, y=lon in Transformer.transform when my crs_from is EPSG:4326, irrespective of what my crs_to is.

Environment Information

2.6.1.post1

Installation method

pip wheel

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
snowman2commented, May 11, 2020

Side note, here is the shorthand version for the compound CRS:

>>> cc = CRS("EPSG:4326+5773")
>>> cc
<Compound CRS: EPSG:4326+5773>
Name: WGS 84 + EGM96 height
Axis Info [ellipsoidal|vertical]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
- H[up]: Gravity-related height (metre)
Area of Use:
- undefined
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
Sub CRS:
- WGS 84
- EGM96 height
1reaction
snowman2commented, May 11, 2020

Out of interest, is it expected that Transformer.transform manages to transform 3D coordinates from a 2D CRS to a Vertical CRS? Or does it work “by chance”?

It does some auto-conversions behind the scenes. But, with limited information it may or may not produce what you want. Probably where the axis-order inconsistencies come into play.

EDIT: There seems to be a small typo in the very last line of your answer. I think it should read:

Probably due to my environment missing the needed grid.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started - pyproj 3.4.1 documentation - GitHub Pages
Using CRS# · Find UTM CRS by Latitude and Longitude# · Transformations from CRS to CRS# · Converting between geographic and projection coordinates...
Read more >
python 3.x - Convertion between compound CRS with pyproj
I came across this example online, and it does work for me. import pyproj cmpd_crs = pyproj.crs.CompoundCRS(name="WGS 84 + EGM96 height", ...
Read more >
Vertical Datum transformation using Pyproj
My logic was to take a WGS84 coordinate with an ellipsoid elevation and try to convert that into NAD83 NADV88 (epsg:5498). But it...
Read more >
Compound coordinate systems for "World" - EPSG.io
WGS 84 + EGM96 height. EPSG:9707. Area of use: World Transform coordinates | Get position on a map · Search deprecated (1).
Read more >
Functions — PROJ 9.1.1 documentation
a compound CRS made from two object names separated with “ + “. e.g. “WGS 84 + EGM96 height” (added in 7.1). Example...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found