使用Pyproj转换地心坐标至站心坐标:from_crs方法报错求助
地心坐标到站心坐标转换的Pyproj问题解决办法
我尝试用Pyproj实现地心坐标(geocent)到站心坐标(topocentric)的转换,以下代码可以正常运行:
transformer = pyproj.Transformer.from_pipeline('+proj=topocentric +lat_0=-54.510097 +lon_0=-67.115486 +h_0=135')
但改用from_crs配合字典参数的写法就报错:
transformer = pyproj.Transformer.from_crs( {"proj":'geocent'}, {"proj":'topocentric', 'lat_0':-54.510097, 'lon_0':-67.115486, 'h_0':135}, )
抛出的异常信息:
ProjError: Input is not a transformation.: (Internal Proj Error: pipeline: Pipeline: Mismatched units between step 1 and 2)
我更倾向于用字典(类JSON格式)参数而非拼接字符串,下面是解决办法:
问题根源
geocent坐标系默认没有绑定椭球体参数,而topocentric会自动使用WGS84作为默认椭球,导致两者的基准/单位不匹配,触发转换错误。
修复代码
给两边的坐标系都明确指定相同的椭球或基准即可,示例如下:
方式1:指定椭球(ellps)
transformer = pyproj.Transformer.from_crs( {"proj": "geocent", "ellps": "WGS84"}, {"proj": "topocentric", "lat_0": -54.510097, "lon_0": -67.115486, "h_0": 135, "ellps": "WGS84"}, )
方式2:指定基准(datum)
transformer = pyproj.Transformer.from_crs( {"proj": "geocent", "datum": "WGS84"}, {"proj": "topocentric", "lat_0": -54.510097, "lon_0": -67.115486, "h_0": 135, "datum": "WGS84"}, )
原理说明
使用from_pipeline时,Pyproj会自动补全站心坐标系的默认椭球参数,并隐式构建完整的转换链路;但from_crs要求输入的两个坐标系必须基准一致,明确指定椭球/基准后,两边的转换逻辑对齐,就能正常完成地心到站心的坐标转换。
内容的提问来源于stack exchange,提问作者Darius
相关产品推荐
相关产品推荐

