ArcMap中POI数据火星坐标、百度坐标、WGS-84坐标系转换
编写Arcpy代码块
新建py文件,编写Arcpy代码
坐标系转换的完整代码块如下:
# -*- coding: utf-8 -*-
import arcpy
import math
filename=arcpy.GetParameterAsText(0)
operatetype=arcpy.GetParameterAsText(1)
x_pi = 3.14159265358979324 * 3000.0 / 180.0
pi = 3.1415926535897932384626 # π
a = 6378245.0 # 长半轴
ee = 0.00669342162296594323 # 偏心率平方
def out_of_china(lng, lat):
"""
判断是否在国内,不在国内不做偏移
"""
return not (lng > 73.66 and lng < 135.05 and lat > 3.86 and lat < 53.55)
def gcj02_to_bd09(lng, lat):
"""
火星坐标系(GCJ-02)转百度坐标系(BD-09)
"""
z = math.sqrt(lng * lng + lat * lat) + 0.00002 * math.sin(lat * x_pi)
theta = math.atan2(lat, lng) + 0.000003 * math.cos(lng * x_pi)
bd_lng = z * math.cos(theta) + 0.0065
bd_lat = z * math.sin(theta) + 0.006
return [bd_lng, bd_lat]
def bd09_to_gcj02(bd_lon, bd_lat):
"""
百度坐标系(BD-09)转火星坐标系(GCJ-02)
"""
x = bd_lon - 0.0065
y = bd_lat - 0.006
z = math.sqrt(x * x + y * y) - 0.00002