You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wrong result while using proj_create_crs_to_crs()? #2087
I'm not able to use proj_create_crs_to_crs() to get correct transformation between two CRSs defined using the traditional "+proj=..." string definition. For the sake of simplicity I use transformation of a location 48N 19E from "latlong" to "utm zone 34" in the following example.
When using Proj 6.3.1, both variant 1 and 2 return incorrect result: -1851536.106814 99013.628434 0.000000
In Proj 5.2.0 both variants result in an error -1 (no arguments in initialization list).
Expected Output
Variant 3 which uses pipelines returns the correct result in both Proj 6.3.1 and 5.2.0: 350812.124995 5318235.613731 0.000000
Environment Information
PROJ version: 6.3.1 and 5.2.0
Operation System Information: Debian bullseye and buster.
When using Proj 6.3.1, both variant 1 and 2 return incorrect result:
-1851536.106814 99013.628434 0.000000
You are inputting radians when you should be inputting degrees. I suspect it will work fine if you skip the conversions from degrees to radians.
In Proj 5.2.0 both variants result in an error -1 (no arguments in initialization list).
Yeah, proj_create_from_crs_to_crs only takes EPSG-codes in PROJ 5.x, so inputting a proj-string will not work. Use functions from proj_api.h for that when using 5.x
Variant 3 which uses pipelines returns the correct result in both Proj 6.3.1 and 5.2.0:
350812.124995 5318235.613731 0.000000
Yes, because here it is correct to input radians.
The problem you are facing is that with PROJ 6 and later proj_create_crs_to_crs respects the input units of the CRS, which more or less always means using degrees rather than radians. Behind the scenes the PJ object returned contains an elaborate pipeline. As seen by this call to projinfo:
proj_create is the tool for super users that knows what they are doing. You supply the pipeline so you are expected to know what it needs to perform correctly. proj_create_crs_to_crs holds your hand as much as possible.
1) I still can't get proj_create_crs_to_crs() working in 6.3.1 for one variant of krovak projection.
PJ* P = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "+proj=krovak +czech +ellps=bessel +towgs84=485.021,169.465,483.839,7.786342,4.397554,4.102655,0", "+proj=utm +zone=34", NULL);
res = proj_trans(P, PJ_FWD, proj_coord(379033, 1208895, 2025.31, 0));
returns the correct result 401375.61 5421243.27 2025.35
If I omit the parameter +czech which serves historically just to reverse the axes (from GIS west/north to Krovak's east/south) and reverse the sign of input coordinates:
PJ* P = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "+proj=krovak +ellps=bessel +towgs84=485.021,169.465,483.839,7.786342,4.397554,4.102655,0", "+proj=utm +zone=34", NULL);
res = proj_trans(P, PJ_FWD, proj_coord(-379033, -1208895, 2025.31, 0));
I get invalid result -1406406.553884 5757982.001626 2025.310000
I tried to use proj_normalize_for_visualization() and also tried swapping X/Y of the point without getting the right result.
cs2cs behaves the same as my examples in 6.3.1 (cct reports 'latitude or longitude exceeded limits' for some reason):
2) For how long it is expected that the proj_context_use_proj4_init_rules() will be supported?
Currently I use proj_create() with +pipeline operator and need to support ESRI and EPSG codes. Is this a viable approch also in Proj 7+ or it will become necessary to use proj_create_crs_to_crs() to use ESRI/EPSG definition in the long run?
Activity
kbevers commentedon Mar 21, 2020
You are inputting radians when you should be inputting degrees. I suspect it will work fine if you skip the conversions from degrees to radians.
Yeah,
proj_create_from_crs_to_crsonly takes EPSG-codes in PROJ 5.x, so inputting a proj-string will not work. Use functions fromproj_api.hfor that when using 5.xYes, because here it is correct to input radians.
The problem you are facing is that with PROJ 6 and later
proj_create_crs_to_crsrespects the input units of the CRS, which more or less always means using degrees rather than radians. Behind the scenes the PJ object returned contains an elaborate pipeline. As seen by this call toprojinfo:proj_createis the tool for super users that knows what they are doing. You supply the pipeline so you are expected to know what it needs to perform correctly.proj_create_crs_to_crsholds your hand as much as possible.Long story short, PROJ performs as expected.
mbudaj commentedon Mar 22, 2020
Thanks, that solved this case.
I have two subsequent questions, though:
1) I still can't get proj_create_crs_to_crs() working in 6.3.1 for one variant of
krovakprojection.returns the correct result
401375.61 5421243.27 2025.35If I omit the parameter
+czechwhich serves historically just to reverse the axes (from GIS west/north to Krovak's east/south) and reverse the sign of input coordinates:I get invalid result
-1406406.553884 5757982.001626 2025.310000I tried to use proj_normalize_for_visualization() and also tried swapping X/Y of the point without getting the right result.
cs2cs behaves the same as my examples in 6.3.1 (cct reports 'latitude or longitude exceeded limits' for some reason):
In 5.2.0, the cs2cs behaviour is consistent (although it ignores +towgs parameter):
2) For how long it is expected that the proj_context_use_proj4_init_rules() will be supported?
Currently I use proj_create() with
+pipelineoperator and need to support ESRI and EPSG codes. Is this a viable approch also in Proj 7+ or it will become necessary to use proj_create_crs_to_crs() to use ESRI/EPSG definition in the long run?