4326坐标转3857坐标
时间: 2024-06-16 22:07:46 浏览: 85
以下是将4326坐标转换为3857坐标的Python代码示例[^1]:
```python
from osgeo import ogr, osr
def transform_coordinates(lon, lat):
# 定义4326和3857坐标系
source = osr.SpatialReference()
source.ImportFromEPSG(4326)
target = osr.SpatialReference()
target.ImportFromEPSG(3857)
# 创建坐标转换器
transform = osr.CoordinateTransformation(source, target)
# 创建点对象
point = ogr.Geometry(ogr.wkbPoint)
point.AddPoint(lon, lat)
# 进行坐标转换
point.Transform(transform)
# 获取转换后的坐标
transformed_lon = point.GetX()
transformed_lat = point.GetY()
return transformed_lon, transformed_lat
# 示例使用
lon = 116.3975
lat = 39.9087
transformed_lon, transformed_lat = transform_coordinates(lon, lat)
print("3857坐标:", transformed_lon, transformed_lat)
```
阅读全文