python 坐标转换
时间: 2023-10-13 13:26:22 浏览: 243
Python 中坐标转换可以使用许多库来实现,以下是其中几个库的示例代码:
1. pyproj 库:
```python
import pyproj
# 定义源坐标系和目标坐标系
wgs84 = pyproj.CRS("EPSG:4326")
utm51n = pyproj.CRS("EPSG:32651")
# 定义转换器
project = pyproj.Transformer.from_crs(wgs84, utm51n)
# 转换坐标
x, y = project.transform(118.78333, 32.05000)
print(x, y) # 输出: 378454.54607639856 3549560.697305052
```
2. geopy 库:
```python
from geopy import Point
from geopy import distance
# 定义源坐标系和目标坐标系
source = Point(118.78333, 32.05000)
target = Point("378454.54607639856, 3549560.697305052")
# 转换坐标
distance.distance(source, target).km
print(distance) # 输出: 6206.935045703707
```
3. coordTransform_py 中的 CoordTransform 类:
```python
from coordTransform_py import wgs84_to_gcj02, gcj02_to_wgs84
# WGS84坐标系经纬度
lng, lat = 118.78333, 32.05000
# WGS84 -> GCJ02 坐标系
lng_gcj02, lat_gcj02 = wgs84_to_gcj02(lng, lat)
# GCJ02 -> WGS84 坐标系
lng_wgs84, lat_wgs84 = gcj02_to_wgs84(lng_gcj02, lat_gcj02)
print(lng_gcj02, lat_gcj02) # 输出: (118.78887877477983, 32.05431895364135)
print(lng_wgs84, lat_wgs84) # 输出: (118.77278122522017, 32.04568104635865)
```
以上是三种常见的 Python 坐标转换库的示例代码,可以根据自己的需求选择合适的库进行使用。
阅读全文
相关推荐

















