Opened 4 years ago

Closed 4 years ago

#4817 closed defect (fixed)

ST_Transform fails when both +geoidgrids and +nadgrids are present

Reported by: aberenyi Owned by: pramsey
Priority: medium Milestone: PostGIS 3.1.2
Component: postgis Version: 3.0.x
Keywords: Cc:

Description

The following works just fine using cs2cs.

$ echo 16.582941335 47.710445103 291.7692| cs2cs -f "%.3f" +init=epsg:4326 +to +proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +k_0=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +nadgrids=etrs2eov_notowgs.gsb +geoidgrids=geoid_eht2014.gtx +units=m +no_defs

However, the same transformation fails in PostGIS.

$ psql -d db -c "SELECT ST_AsEWKT(ST_Transform(ST_GeomFromText('POINT(16.582941335 47.710445103 291.7692)', 4326), '+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +k_0=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +nadgrids=etrs2eov_notowgs.gsb +geoidgrids=geoid_eht2014.gtx +units=m +no_defs'))"

ERROR: proj_crs_is_swapped: proj_crs_get_coordinate_system returned NULL CONTEXT: SQL function "st_transform" statement 1

Interestingly, if I omit either +geoidgrids or +nadgrids ST_Transform doesn't throw an error, but the coordinates are off.

$ psql -d db -c "SELECT ST_AsEWKT(ST_Transform(ST_GeomFromText('POINT(16.582941335 47.710445103 291.7692)', 4326), '+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +k_0=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +geoidgrids=geoid_eht2014.gtx +units=m +no_defs'))"

POINT(465007.88411299663 265848.07307208166 246.45166349798842) (formatting omitted for brewity)

$ psql -d db -c "SELECT ST_AsEWKT(ST_Transform(ST_GeomFromText('POINT(16.582941335 47.710445103 291.7692)', 4326), '+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +k_0=0.99993 +x_0=650000 +y_0=200000 +ellps=GRS67 +nadgrids=etrs2eov_notowgs.gsb +units=m +no_defs'))"

POINT(465092.51654231607 265877.1140839074 291.7692)

This suggests that I can work around the problem by using a 2-step approach, but I'd like to aviod that if possible.

What am I doing wrong?

Env:

$ psql -d db -c "SELECT PostGIS_Full_Version();" POSTGIS="3.1.0dev 50b1e70" [EXTENSION] PGSQL="120" GEOS="3.9.0dev-CAPI-1.14.0" PROJ="7.2.0" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.3.1" WAGYU="0.5.0 (Internal)"

Change History (6)

comment:1 by pramsey, 4 years ago

Milestone: PostGIS 3.1.0PostGIS 3.1.1

comment:2 by pramsey, 4 years ago

Milestone: PostGIS 3.1.1PostGIS 3.1.2

comment:3 by Paul Ramsey <pramsey@…>, 4 years ago

In 8f8a563/git:

Handle more deeply nested CRS objects when extracting CS objects to find axis ordering. References #4817

comment:4 by Paul Ramsey <pramsey@…>, 4 years ago

In 11efb9f/git:

Handle more deeply nested CRS objects when extracting CS objects to find axis ordering. References #4817

comment:5 by Paul Ramsey <pramsey@…>, 4 years ago

In 552d774/git:

Handle more deeply nested CRS objects when extracting CS objects to find axis ordering. References #4817

comment:6 by pramsey, 4 years ago

Resolution: fixed
Status: newclosed

Patched back to 3.1 and 3.0.

Note: See TracTickets for help on using tickets.