Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROJ 6 issues with +init=epsg:2056 (CH1903+/LV95) #1597

Closed
dg0yt opened this issue Sep 11, 2019 · 5 comments
Closed

PROJ 6 issues with +init=epsg:2056 (CH1903+/LV95) #1597

dg0yt opened this issue Sep 11, 2019 · 5 comments

Comments

@dg0yt
Copy link
Contributor

dg0yt commented Sep 11, 2019

Using the old API with PROJ 6 instead of 4.9.3, we noticed wrong transformation results between EPSG:4326 and EPSG:2056 (CH1903+/LV95) (OpenOrienteering/mapper#1325). Even after switching to the new API (with legacy proj4 init rules enabled), results are correct only if the no_defs parameter is not used. Despite all the legacy stuff: This is a clear regression which should not happen at least when using the old API.

I was now able to create a test executable which uses the EPSG:2056 center of projection for demonstration. Note that only the last line is matching the expected results.

expected:    	2600000.00	1200000.00
pj_transform:	2599927.44	1199852.66	(+init=epsg:2056 +no_defs)
pj_transform:	2599927.44	1199852.66	(+init=epsg:2056)
pj_trans:    	2599927.44	1199852.66	(+init=epsg:2056 +no_defs)
pj_trans:    	2599999.82	1199999.69	(+init=epsg:2056)

proj-test.zip (updated)

@dg0yt dg0yt changed the title PRPJ 6 issues with EPSG:2056 (CH1903+/LV95) PROJ 6 issues with EPSG:2056 (CH1903+/LV95) Sep 11, 2019
@dg0yt dg0yt changed the title PROJ 6 issues with EPSG:2056 (CH1903+/LV95) PROJ 6 issues with +init=epsg:2056 (CH1903+/LV95) Sep 11, 2019
rouault added a commit to rouault/PROJ that referenced this issue Sep 11, 2019
rouault added a commit to rouault/PROJ that referenced this issue Sep 11, 2019
rouault added a commit to rouault/PROJ that referenced this issue Sep 11, 2019
…ixes OSGeo#1597)

Currently, +init=epsg:XXXX expansion from proj.db didn't make any effort
to try to add a +towgs84 clause. Now this will do using CRS::createBoundCRSToWGS84IfPossible()
Note that however this does not perfectly emulated PROJ4/PROJ5 epsg file
behaviour, and will only add a +towgs84 when it is valid for the whole
area of use of the CRS, whereas PROJ4/PROJ5 would add the one that was
valid for the largest sub-area of use.
The additiong of a +towgs84 clause will be thus more likely for a
projected CRS valid for a country, rather than for a geographic CRS valid
for a continent or a larger area, and thus whose transformations to WGS84
might be multiple.
The consequence of this shows up in some GIGS test that must be adapted to
add an explicit +towgs84 for source/target geographic CRS with value equal
to the one of the source/target projected CRS.
@rouault
Copy link
Member

rouault commented Sep 11, 2019

@dg0yt Potential fixes in #1600 . Note however as indicated in the PR that the commit really fixing your issue could be controversial. Basically one cannot expect PROJ6 to be perfectly backward compatible with previous PROJ versions. Hence the deprecation for the +init=epsg:XXXX syntax. Using proj_create_crs_to_crs(ctx, "EPSG:4326", "EPSG:2056", NULL) is the strongly recommended way of proceeding. Or fully expand the +init=epsg:XXXX to their "+proj= ...." content including +towgs84 clauses.
I'd note that, to make PR #1600 really work with your .cpp file you should change the setting of the 'c' argument passed to proj_trans() to initialize the z value as well, otherwise that can affect geographic <--> geocentric conversions if the z is some random value :

	c.lpz.lam = x;
	c.lpz.phi = y;
        c.lpz.z = 0;

@dg0yt
Copy link
Contributor Author

dg0yt commented Sep 11, 2019

you should change the setting of the 'c' argument passed to proj_trans() to initialize the z value as well, otherwise that can affect geographic <--> geocentric conversions if the z is some random value

Thanks for the hint. IIUC this also needs to be added to the migration documentation, because this is where the code comes from, except for not using scanf. And the example would need this in the loop body (or better do not overwrite c at all, to highlight the pure function style in the new API).

@rouault
Copy link
Member

rouault commented Sep 11, 2019

Thanks for the hint. IIUC this also needs to be added to the migration documentation, because this is where the code comes from

we'd welcome if you could submit a PR for that

@dg0yt
Copy link
Contributor Author

dg0yt commented Sep 11, 2019

Basically one cannot expect PROJ6 to be perfectly backward compatible with previous PROJ versions. Hence the deprecation for the +init=epsg:XXXX syntax. Using proj_create_crs_to_crs(ctx, "EPSG:4326", "EPSG:2056", NULL) is the strongly recommended way of proceeding. Or fully expand the +init=epsg:XXXX to their "+proj= ...." content including +towgs84 clauses.

I do understand that, and maybe it is best to leave it as it is. However, I see software being recompiled with the macro enabling the deprecated API, e.g. for the Debian proj transition, and this error has the potential to go unnoticed for a while. (Even the Potsdam bug in the new API seems to have gone unnoticed for a while.)

rouault added a commit to rouault/PROJ that referenced this issue Sep 15, 2019
rouault added a commit to rouault/PROJ that referenced this issue Sep 15, 2019
rouault added a commit to rouault/PROJ that referenced this issue Sep 15, 2019
kbevers added a commit that referenced this issue Sep 15, 2019
backporting bot pushed a commit that referenced this issue Sep 15, 2019
backporting bot pushed a commit that referenced this issue Sep 15, 2019
backporting bot pushed a commit that referenced this issue Sep 15, 2019
… support of +init=epsg:XXXX syntax (relates to #1597)
@rouault
Copy link
Member

rouault commented Sep 15, 2019

We've finally decided not to try to fix the pj_transform() use case, but rather document it: 73042b0

@rouault rouault closed this as completed Sep 15, 2019
rouault added a commit that referenced this issue Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants