wgs84 gc02 bd09 坐标系转换excel宏

1,404次阅读
没有评论
Private Const PI As Double = 3.14159265358979
Private Const x_pi = 3.14159265358979 * 3000# / 180#
Private Const X_EARTH_RADIUS = 6378245
Private Const EE = 6.69342162296594E-03
 
Private Type Point
  lng     As Double
  lat     As Double
End Type
Private Function transform(lng As Double, lat As Double) As Point
   dlat = transformLat(lng - 105#, lat - 35#)
   dlng = transformlng(lng - 105#, lat - 35#)
   radlat = lat / 180# * PI
   magic = Math.Sin(radlat)
   magic = 1 - EE * magic * magic
   sqrtmagic = Sqr(magic)
   dlat = (dlat * 180#) / ((X_EARTH_RADIUS * (1 - EE)) / (magic * sqrtmagic) * PI)
   dlng = (dlng * 180#) / (X_EARTH_RADIUS / sqrtmagic * Math.Cos(radlat) * PI)
   mgLat = lat + dlat
   mglng = lng + dlng
   Dim ret As Point
   ret.lng = mglng
   ret.lat = mgLat
   transform = ret
 End Function
Private Function transformlng(x As Double, y As Double) As Double
   ret = 300# + x + 2# * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Sqr(Math.Abs(x))
   ret = ret + (20# * Math.Sin(6# * x * PI) + 20# * Math.Sin(2# * x * PI)) * 2# / 3#
   ret = ret + (20# * Math.Sin(x * PI) + 40# * Math.Sin(x / 3# * PI)) * 2# / 3#
   ret = ret + (150# * Math.Sin(x / 12# * PI) + 300# * Math.Sin(x / 30# * PI)) * 2# / 3#
   transformlng = ret
 End Function
Private Function transformLat(x As Double, y As Double) As Double
   ret = -100# + 2# * x + 3# * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Sqr(Math.Abs(x))
   ret = ret + (20# * Math.Sin(6# * x * PI) + 20# * Math.Sin(2# * x * PI)) * 2# / 3#
   ret = ret + (20# * Math.Sin(y * PI) + 40# * Math.Sin(y / 3# * PI)) * 2# / 3#
   ret = ret + (160# * Math.Sin(y / 12# * PI) + 320 * Math.Sin(y * PI / 30#)) * 2# / 3#
   transformLat = ret
 End Function
Private Function BD09toGCJ02(lng As Double, lat As Double) As Point
    Dim p As Point
    x = lng - 0.0065
    y = lat - 0.006
    Z = Sqr(x * x + y * y) - 0.00002 * Math.Sin(y * x_pi)
    theta = WorksheetFunction.Atan2(x, y) - 0.000003 * Math.Cos(x * x_pi)
    p.lng = Z * Math.Cos(theta)
    p.lat = Z * Math.Sin(theta)
    BD09toGCJ02 = p
End Function
Private Function GCJ02toBD09(lng As Double, lat As Double) As Point
    Dim p As Point
    Z = Sqr(lng * lng + lat * lat) + 0.00002 * Math.Sin(lat * x_pi)
    theta = WorksheetFunction.Atan2(lng, lat) + 0.000003 * Math.Cos(lng * x_pi)
    p.lng = Z * Math.Cos(theta) + 0.0065
    p.lat = Z * Math.Sin(theta) + 0.006
    GCJ02toBD09 = p
End Function
 
Private Function WGS84toGCJ02(lng As Double, lat As Double) As Point
    Dim p As Point
    dlat = transformLat(lng - 105#, lat - 35#)
    dlng = transformlng(lng - 105#, lat - 35#)
    radlat = lat / 180# * PI
    magic = Math.Sin(radlat)
    magic = 1 - EE * magic * magic
    sqrtmagic = Sqr(magic)
    dlat = (dlat * 180#) / ((X_EARTH_RADIUS * (1 - EE)) / (magic * sqrtmagic) * PI)
    dlng = (dlng * 180#) / (X_EARTH_RADIUS / sqrtmagic * Math.Cos(radlat) * PI)
    p.lat = lat + dlat
    p.lng = lng + dlng
    WGS84toGCJ02 = p
End Function
 
Public Function BD09toGCJ02Lng(lng As Double, lat As Double) As Double
    Dim p As Point
    p = BD09toGCJ02(lng, lat)
    BD09toGCJ02Lng = p.lng
End Function
Public Function BD09toGCJ02Lat(lng As Double, lat As Double) As Double
    Dim p As Point
    p = BD09toGCJ02(lng, lat)
    BD09toGCJ02Lat = p.lat
End Function
    
Public Function GCJ02toBD09Lat(lng As Double, lat As Double) As Double
    Dim p As Point
    p = GCJ02toBD09(lng, lat)
    GCJ02toBD09Lat = p.lat
End Function
    
Public Function GCJ02toBD09Lng(lng As Double, lat As Double) As Double
    Dim p As Point
    p = GCJ02toBD09(lng, lat)
    GCJ02toBD09Lng = p.lng
End Function
    
    
Public Function WGS84toGCJ02Lng(lng As Double, lat As Double) As Double
    Dim p As Point
    p = WGS84toGCJ02(lng, lat)
    WGS84toGCJ02Lng = p.lng
End Function
     
      
Public Function WGS84toGCJ02Lat(lng As Double, lat As Double) As Double
    Dim p As Point
    p = WGS84toGCJ02(lng, lat)
    WGS84toGCJ02Lat = p.lat
End Function
     
 
Public Function GCJ02toWGS84Lng(lng As Double, lat As Double) As Double
    Dim p As Point
    p = transform(lng, lat)
    mglng = lng * 2 - p.lng
    mgLat = lat * 2 - p.lat
    GCJ02toWGS84Lng = mglng
End Function
Public Function GCJ02toWGS84Lat(lng As Double, lat As Double) As Double
    Dim p As Point
    p = transform(lng, lat)
    mglng = lng * 2 - p.lng
    mgLat = lat * 2 - p.lat
    GCJ02toWGS84Lat = mgLat
End Function
 
Public Function WGS84toBD09Lat(lng As Double, lat As Double) As Double
    Dim p As Point
    p = WGS84toGCJ02(lng, lat)
    WGS84toBD09Lat = GCJ02toBD09Lat(p.lng, p.lat)
End Function
      
Public Function WGS84toBD09Lng(lng As Double, lat As Double) As Double
   Dim p As Point
    p = WGS84toGCJ02(lng, lat)
    WGS84toBD09Lng = GCJ02toBD09Lng(p.lng, p.lat)
End Function
 
Public Function BD09toWGS84Lat(lng As Double, lat As Double) As Double
    Dim p As Point
    p = BD09toGCJ02(lng, lat)
    BD09toWGS84Lat = GCJ02toWGS84Lat(p.lng, p.lat)
End Function
      
Public Function BD09toWGS84Lng(lng As Double, lat As Double) As Double
   Dim p As Point
    p = BD09toGCJ02(lng, lat)
    BD09toWGS84Lng = GCJ02toWGS84Lng(p.lng, p.lat)
End Function
 
正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)

文心AIGC

2023 年 6 月
 1234
567891011
12131415161718
19202122232425
2627282930  
文心AIGC
文心AIGC
人工智能ChatGPT,AIGC指利用人工智能技术来生成内容,其中包括文字、语音、代码、图像、视频、机器人动作等等。被认为是继PGC、UGC之后的新型内容创作方式。AIGC作为元宇宙的新方向,近几年迭代速度呈现指数级爆发,谷歌、Meta、百度等平台型巨头持续布局
文章搜索
热门文章
潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026 Jay 2025-12-22 09...
“昆山杯”第二十七届清华大学创业大赛决赛举行

“昆山杯”第二十七届清华大学创业大赛决赛举行

“昆山杯”第二十七届清华大学创业大赛决赛举行 一水 2025-12-22 17:04:24 来源:量子位 本届...
MiniMax海螺视频团队首次开源:Tokenizer也具备明确的Scaling Law

MiniMax海螺视频团队首次开源:Tokenizer也具备明确的Scaling Law

MiniMax海螺视频团队首次开源:Tokenizer也具备明确的Scaling Law 一水 2025-12...
清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开

清库存!DeepSeek突然补全R1技术报告,训练路径首次详细公开 Jay 2026-01-08 20:18:...
最新评论
ufabet ufabet มีเกมให้เลือกเล่นมากมาย: เกมเดิมพันหลากหลาย ครบทุกค่ายดัง
tornado crypto mixer tornado crypto mixer Discover the power of privacy with TornadoCash! Learn how this decentralized mixer ensures your transactions remain confidential.
ดูบอลสด ดูบอลสด Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Obrazy Sztuka Nowoczesna Obrazy Sztuka Nowoczesna Thank you for this wonderful contribution to the topic. Your ability to explain complex ideas simply is admirable.
ufabet ufabet Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
ufabet ufabet You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
ufabet ufabet Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
热评文章
摩尔线程的野心,不藏了

摩尔线程的野心,不藏了

摩尔线程的野心,不藏了 量子位的朋友们 2025-12-22 10:11:58 来源:量子位 上市后的仅15天...
摩尔线程的野心,不藏了

摩尔线程的野心,不藏了

摩尔线程的野心,不藏了 量子位的朋友们 2025-12-22 10:11:58 来源:量子位 上市后的仅15天...
AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身

AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身

AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身 量子位的朋友们 2025...
AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身

AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身

AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身 量子位的朋友们 2025...
真正面向大模型的AI Infra,必须同时懂模型、系统、产业|商汤大装置宣善明@MEET2026

真正面向大模型的AI Infra,必须同时懂模型、系统、产业|商汤大装置宣善明@MEET2026

真正面向大模型的AI Infra,必须同时懂模型、系统、产业|商汤大装置宣善明@MEET2026 量子位的朋友...