PROJ icon indicating copy to clipboard operation
PROJ copied to clipboard

PROJ 7: Behaviour change when transforming an out of bounds point

Open Algunenano opened this issue 6 years ago • 4 comments

Hi,

This was initially reported in https://trac.osgeo.org/postgis/ticket/4642 as a failure in Postgis regress tests.

There is a change in behaviour between PROJ6 and PROJ7, or even between PROJ7 using proj-data and PROJ7 using datum-grid, where you get different results when you transform an out of bounds point to a SRS.

Previously PROJ (PROJ 6) would return POINT(Infinity Infinity), but now it is returning an error ERROR: transform: failed to load datum shift file (-38) when built with proj-data, or what is looks like a no-op when built with datum-grid.

The example using Postgis directly:

  • PROJ 6 with datum-grid:
Select ST_AsText(ST_Transform('SRID=4326; POINT (3 0)'::geometry, 4138));
        st_astext         
--------------------------
 POINT(Infinity Infinity)
(1 row)
  • PROJ 7 with datum-grid:
Select ST_AsText(ST_Transform('SRID=4326; POINT (3 0)'::geometry, 4138));
 st_astext  
------------
 POINT(3 0)
(1 row)
  • PROJ 7 with proj-data:
Select ST_AsText(ST_Transform('SRID=4326; POINT (3 0)'::geometry, 4138));
ERROR:  transform: failed to load datum shift file (-38)

Doing the transformation for a point within the bounds returns valid information but it is also inconsistent:

SELECT ST_AsEWKT(ST_Transform('SRID=4326; POINT(-169.50 56.5)'::geometry, 4138));
  • PROJ 6: SRID=4138;POINT(-169.497593643553 56.4989489444602).
  • PROJ 7 datum-grid: SRID=4138;POINT(-169.5 56.5)
  • PROJ 7 proj-data: SRID=4138;POINT(-169.497593643542 56.4989489444602)

This same issue happens with other SRSs like EPSG:4136 or EPSG:4137.

Expected Output

I don't know if this is a bug or an intended change in PROJ 7, but I would expect the result to be consistent between releases or, at least, between using proj-data and datum-grids.

Environment Information

  • PROJ 6 (from Arch repositories): 6.3.1
  • PROJ 7 built using master (https://github.com/OSGeo/PROJ/commit/86530f3146ec091c26652e60067088dc3e067fae).
  • When built with datum-grid, I used proj-datumgrid-1.8.zip.
  • When build with proj-data, I used proj-data-1.0RC1.tar.gz.

Algunenano avatar Feb 24 '20 09:02 Algunenano

Several remarks:

  • PROJ error handling is a complicated story, and certainly not the part where it shines most, so inconsistencies / changes are to be expected. That said the PJD_ERR_FAILED_TO_LOAD_GRID -38 error wasn't appropriate there, so I've changed it to PJD_ERR_GRID_AREA -48 per PR #1974. If I remember well, when doing PROJ 7 changes, I found that PROJ could erase the error code in a likely non-intended way and fixed that. Hence now you get a errno whereas previously it was cleared.

  • I don't reproduce with PROJ 7 the issue you have when using datum-grid. I'd note that datum-grid with PROJ 7 is not considered as the nominal use case, and proj-data should rather be used. That said, if the stgeorge file in $install/share/proj or PROJ_LIB, that should work. I get the same result as in PROJ 6 for the point within grid. See:

$ echo "56.5 -169.5 0" |   PROJ_LIB=data PROJ_DEBUG=3 src/cs2cs -d 8 EPSG:4326 EPSG:4138
pj_open_lib(proj.db): call fopen(data/proj.db) - succeeded
pj_open_lib(proj.ini): call fopen(data/proj.ini) - succeeded
pj_open_lib(us_noaa_stgeorge.tif): call fopen(data/us_noaa_stgeorge.tif) - failed
pj_open_lib(stgeorge): call fopen(data/stgeorge) - succeeded
[...]
56.49894894	-169.49759364 0.00000000
  • The slight difference (~ 1 micrometer) in results for the point within grid between using the datum-grid or proj-data file is likely just an artifact of the conversion to GeoTIFF where the original file had shifts in radians and now they are in arc-seconds. This is a insignificant difference.

rouault avatar Feb 24 '20 10:02 rouault

That said the PJD_ERR_FAILED_TO_LOAD_GRID -38 error wasn't appropriate there, so I've changed it to PJD_ERR_GRID_AREA -48 per PR #1974.

Yep, I built with your PR and now the error makes sense:

# Select ST_AsText(ST_Transform('SRID=4326; POINT (3 0)'::geometry, 4138));
ERROR:  transform: point not within available datum shift grids (-48)

Hence now you get a errno whereas previously it was cleared.

Seems reasonable. I'll change Postgis' test to avoid this error (it's testing a completely unrelated thing). Feel free to close the ticket when merging the PR.

Algunenano avatar Feb 24 '20 10:02 Algunenano

Hello,

I have noticed similar issue when try to make vertical grid shift. So I decided to write here instead of open new issue.

In case of PROJ 6 if you enter coordinates out of grid, it returned altitude = infiinity.

In proj 7 it returns error "point not within available datum shift grids". Proj 7 installed from OSGeo4W (proj-dev, version 7.2.0-39), proj-data is used (proj-dev-data, version 1.2-2). Example. Altitude is out of Great Britain vertical grid

echo 10.826215 51.178882 101.62 | cct +proj=vgridshift +grids=uk_os_OSGM15_GB.tif
cct: Running in very verbose mode
pj_open_lib(proj.db): call fopen(C:\OSGeo4W64\apps\proj-dev\share\proj\proj.db) - succeeded
pj_open_lib(proj.ini): call fopen(C:\OSGeo4W64\apps\proj-dev\share\proj\proj.ini) - succeeded
pj_ellipsoid - final: a=6378137.000 f=1/298.257, errno=0
pj_ellipsoid - final:    ellps=GRS80
Final: proj=vgridshift grids=uk_os_OSGM15_GB.tif ellps=GRS80 argc=3 pargc=2
pj_open_lib(uk_os_OSGM15_GB.tif): call fopen(C:\OSGeo4W64\apps\proj-dev\share\proj\uk_os_OSGM15_GB.tif) - succeeded
proj_vgrid_value: (10.826215, 51.178882) = inf
# Record 0 TRANSFORMATION ERROR: 10.826215 51.178882 101.62
 (point not within available datum shift grids)

Is it intended behavior in the Proj 7? Thanks for help!

GAnatoliy avatar Oct 12 '20 16:10 GAnatoliy

Is it intended behavior in the Proj 7?

yes

rouault avatar Oct 12 '20 17:10 rouault