pyproj4 / pyproj

Python interface to PROJ (cartographic projections and coordinate transformations library)
https://pyproj4.github.io/pyproj
MIT License
1.04k stars 211 forks source link

Transformer: EPSG:27700 to EPSG:4978 (3D) not returning PROJ string #1324

Closed romaintha closed 1 year ago

romaintha commented 1 year ago
from pyproj.transformer import Transformer, CRS
transformer = Transformer.from_crs(CRS(27700).to_3d(), CRS(4978).to_3d())
transformer.to_proj4()  # return None in 3.6.0

Problem description

So far with pyproj 3.2.1, running transformer.to_proj4() would return the proj string. Now in 3.6.0, it returns None

Environment Information

pyproj info: pyproj: 3.6.0 PROJ: 9.2.1 data dir: /home/romain/Envs/xxx/lib/python3.10/site-packages/pyproj/proj_dir/share/proj user_data_dir: /home/romain/.local/share/proj PROJ DATA (recommended version): 1.14 PROJ Database: 1.2 EPSG Database: v10.088 [2023-05-13] ESRI Database: ArcGIS Pro 3.1 [2023-19-01] IGNF Database: 3.1.0 [2019-05-24]

System: python: 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] executable: /home/romain/Envs/xxx/bin/python machine: Linux-5.19.0-46-generic-x86_64-with-glibc2.35

Python deps: certifi: 2023.5.7 Cython: 0.29.36 setuptools: 59.8.0 pip: 23.1.2

Installation method

pip

snowman2 commented 1 year ago

It appears there are multiple transformations to choose from now:

>>> from pyproj import CRS, Transformer
>>> transformer = Transformer.from_crs(CRS(27700).to_3d(), CRS(4978).to_3d())
>>> transformer.to_proj4()
>>> transformer
<Unknown Transformer: unknown>
Description: unavailable until proj_trans is called
Area of Use:
- undefined
>>> from pyproj.transformer import TransformerGroup
>>> group = TransformerGroup(CRS(27700).to_3d(), CRS(4978).to_3d())
>>> group
<TransformerGroup: best_available=True>
- transformers: 9
- unavailable_operations: 0
>>> group.transformers[0].to_proj4()
'+proj=pipeline +step +inv +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +step +proj=hgridshift +grids=uk_os_OSTN15_NTv2_OSGBtoETRS.tif +step +proj=cart +ellps=WGS84'
>>> group.transformers[1].to_proj4()
'+proj=pipeline +step +inv +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +step +proj=cart +ellps=airy +step +proj=helmert +x=446.448 +y=-125.157 +z=542.06 +rx=0.15 +ry=0.247 +rz=0.842 +s=-20.489 +convention=position_vector'
romaintha commented 1 year ago

Yet I find it confusing :

>>> from pyproj import CRS, Transformer
>>> transformer = Transformer.from_crs(CRS(27700).to_3d(), CRS(4978).to_3d())
>>> transform.transform(530695.017566992, 180664.24589561723, 0) 
(3977786.5987607674, -8197.39977027958, 4969041.230997906)
>>> transformer.to_proj4()

>>>

So for some reason it knows which transformation to use when .transform is called, but not when .to_proj4 is called

romaintha commented 1 year ago

It means that we have to upgrade our codebase? Everywhere we were using

transformer = Transformer.from_crs(in_crs, out_crs)

We need to do:

transformer = TransformerGroup(in_crs, out_crs)).transformers[0]
snowman2 commented 1 year ago

Closing as the behavior is expected.

snowman2 commented 1 year ago

Also see: https://proj.org/en/9.2/operations/operations_computation.html