明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2712|回复: 14

[源码] 导入kml画图 kml2cad

[复制链接]
发表于 2020-10-30 13:43 | 显示全部楼层 |阅读模式
本帖最后由 wzg356 于 2022-3-17 15:05 编辑

此贴已包含在http://bbs.mjtd.com/forum.php?mo ... amp;_dsign=9ba1c0d7
请移步

kml文件最好为制式生成的
点标记-写点名文字
其他的标记划线
WGS84/国家2000椭球----两个椭球体参数相当,可实质互用
高斯投影转换
中央经线输入3/6整数-自动计算3度带/6度带的经线度数,其他正整数为实质输入的中央经线度数
使用2年了基本没发现问题

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2021-6-21 14:36 | 显示全部楼层
  1. ;;;功能:投影换带
  2. ;;作者:HUA
  3. ;;;创建日期:2020-8-18
  4. ;;;最后编辑日期:2020-8-20
  5. ;;;
  6. ;;;秒转度分秒 s->dd.mmss
  7. (defun Second2Dms(second / sign degree miniute second  dms)
  8.   (setq   sign (< second 0)
  9.       second (/ (abs second) 3600.0)
  10.       degree (fix second)
  11.       second (* (- second degree) 60.0)
  12.       miniute (fix second)
  13.       second (* (- second miniute) 60.0)
  14.       dms (+ degree (/ miniute 100.0) (/ second 10000.0))
  15.   )
  16.   (if sign (setq dms (- 0 dms)))
  17.   dms
  18. )
  19. ;;;
  20. ;;;角度转弧度 dd.mmss->rad
  21. (defun Dms2Rad(dms / sign degree miniute second rad)
  22.   (setq  sign  (<  dms 0)
  23.          dms  (abs dms)
  24.        degree (fix dms)
  25.        dms (* (- dms degree) 100)
  26.        miniute (fix dms)
  27.        second (* (- dms miniute) 100)   
  28.        rad (/ (* (+ degree (/ miniute 60.0) (/ second 3600.0)) PI) 180.0)
  29.   )
  30.   (if sign (setq rad  (- 0 rad)))
  31.   rad
  32. )
  33. ;;;
  34. ;;;弧度转角度 rad->dd.mmss
  35. (defun Rad2Dms(rad / sign degree miniute second dms)
  36.   (setq   sign (< rad 0)
  37.           rad (abs rad)
  38.       rad (/ (* rad 180.0) PI)
  39.       degree (fix rad)
  40.       rad (* (- rad degree) 60.0)
  41.       miniute (fix rad)
  42.       second (* (- rad miniute) 60.0)
  43.       dms (+ degree (/ miniute 100.0) (/ second 10000.0))
  44.   )
  45.   (if sign (setq dms (- 0 dms)))
  46.   dms
  47. )
  48. ;;;
  49. ;;;十进制角度转弧度 dd->rad
  50. (defun Degree2Rad(degree / sign rad)
  51.   (setq  sign  (<  degree 0)
  52.          degree   (abs degree )      
  53.        rad (/ (* degree  PI) 180.0)
  54.   )
  55.   (if sign (setq rad  (- 0 rad)))
  56.   rad
  57. )
  58. ;;;
  59. ;;;弧度转十进制角度 rad->dd
  60. (defun Rad2Degree(rad / sign degree)
  61.   (setq  sign  (<  rad 0)
  62.          rad (abs rad)
  63.          degree (/ (* rad 180.0) PI)
  64.   )
  65.   (if sign (setq degree  (- 0 degree)))
  66.   degree
  67. )
  68. ;;;
  69. ;;;54坐标系参数
  70. (defun PrjPoint_Krasovsky( / a f e2 e12 A1 A2 A3 A4 A5 A6 A7 tf )
  71.   (setq  a 6378245.0
  72.       f 298.3
  73.       tf (/ (- f 1) f)
  74.       e2  (- 1 (* tf tf))
  75.       tf (/ f (- f 1))
  76.       e12 (- (* tf tf) 1)
  77.       A1 6367558.4968749800000000
  78.       A2  -16036.4802694116000000
  79.       A3  16.8280668841393000
  80.       A4  -0.0219753089548841
  81.       A5 0.0000311310026601
  82.       A6 -0.0000000459827472
  83.       A7 0.0000000000679857      
  84.   )
  85.   (list a f e2 e12 A1 A2 A3 A4 A5 A6 A7)  
  86. )
  87. ;;;
  88. ;;;80坐标系参数
  89. (defun PrjPoint_IUGG1975(/ a f e2 e12 A1 A2 A3 A4 A5 A6 A7 tf)
  90.   (setq  a    6378140.0
  91.       f    298.257
  92.       tf (/ (- f 1) f)
  93.       e2  (- 1 (* tf tf))
  94.       tf (/ f (- f 1))
  95.       e12 (- (* tf tf) 1)
  96.       A1    6367452.1327884300000000
  97.       A2    -16038.5282286966000000
  98.       A3    16.8326464353061000
  99.       A4    -0.0219844636486152
  100.       A5    0.0000311484690908
  101.       A6    -0.0000000460151868
  102.       A7    0.0000000000680433      
  103.   )
  104.   (list a f e2 e12 A1 A2 A3 A4 A5 A6 A7)  
  105. )
  106. ;;;
  107. ;;;2000坐标系参数
  108. (defun PrjPoint_2000(/ a f e2 e12 A1 A2 A3 A4 A5 A6 A7 tf)
  109.   (setq  a    6378137.0
  110.       f    298.257222101
  111.       tf (/ (- f 1) f)
  112.       e2  (- 1 (* tf tf))
  113.       tf (/ f (- f 1))
  114.       e12 (- (* tf tf) 1)
  115.       A1    6367449.1457710400000000
  116.       A2    -16038.5087415914000000
  117.       A3    16.8326134276660000
  118.       A4    -0.0219844041401628
  119.       A5    0.0000311483615430
  120.       A6    -0.0000000460149936
  121.       A7    0.0000000000680429      
  122.   )
  123.    (list a f e2 e12 A1 A2 A3 A4 A5 A6 A7)  
  124. )
  125. ;;;
  126. ;;;BL转cadx,cady
  127. ;;;输入参数
  128. ;;;B,L为点位纬度和经度,单位为弧度
  129. ;;;L0为中央经线,单位为弧度
  130. ;;;prjType取值为0:北京54坐标系,1:西安80坐标系,2:CGCS2000坐标系
  131. ;;;输出CAD坐标x,y
  132. (defun PrjPoint:BL2xy(B L L0 prjType / a f e2 e12 A1 A2 A3 A4 A5 A6 A7 X N tanB tanB2 m m2 ng2 sinB cosB cadx cady)   
  133.     (cond
  134.     ((= 0 prjType) (mapcar 'set (list 'a 'f 'e2 'e12 'A1 'A2 'A3 'A4 'A5 'A6 'A7) (PrjPoint_Krasovsky)))
  135.     ((= 1 prjType) (mapcar 'set (list 'a 'f 'e2 'e12 'A1 'A2 'A3 'A4 'A5 'A6 'A7) (PrjPoint_IUGG1975)))
  136.     ((= 2 prjType) (mapcar 'set (list 'a 'f 'e2 'e12 'A1 'A2 'A3 'A4 'A5 'A6 'A7) (PrjPoint_2000)))
  137.     (T (alert "未知prjType参数值")(exit))
  138.   )
  139.   (setq  X       (+ (* A1 B) (* A2 (sin (* 2 B))) (*  A3 (sin (* 4 B))) (* A4 (sin (* 6 B))) (* A5  (sin (* 8 B))) (* A6 (sin (* 10 B))) (* A7 (sin (* 12 B))))
  140.       sinB   (sin B)  cosB   (cos B) tanB   (/ (sin B) (cos B))   tanB2   (* tanB tanB)
  141.       N      (/ a (sqrt (- 1 (* e2 sinB sinB))))
  142.       m      (* cosB (- L L0))  m2 (* m m)
  143.       ng2      (/ (* cosB cosB e2) (- 1 e2))
  144.       cady    (+ X (* N tanB (* (+ 0.5 (* (+ (/ (+ (- 5 tanB2) (* 9 ng2) (* 4 ng2 ng2)) 24.0) (/ (* (+ (- 61 (* 58 tanB2)) (* tanB2 tanB2)) m2) 72.0)) m2)) m2)))
  145.       cadx    (+ 500000 (* N m  (+ 1 (* m2 (+ (/ (+ (- 1 tanB2) ng2) 6.0) (/ (* m2 (-  (+ 5 (* tanB2 tanB2) (* 14 ng2)) (* 18 tanB2) (* 58 ng2 tanB2))) 120.0))))))   
  146.   )
  147.   (list cadx cady)  
  148. )
  149. ;;;
  150. ;;;cadx,cady转BL
  151. ;;;输入参数
  152. ;;;;pt为点位cad点坐标,
  153. ;;;L0为中央经线,单位为弧度
  154. ;;;prjType取值为0:北京54坐标系,1:西安80坐标系,2:CGCS2000坐标系
  155. ;;;输出经纬度B,L表,单位为dd.mmss
  156. (defun PrjPoint:xy2BL(pt L0 prjType / a f e2 e12 A1 A2 A3 A4 A5 A6 A7 sinB cosB tanB tanB2 N ng2 V yN preB0 B0 eta x y )
  157.   (cond
  158.     ((= 0 prjType) (mapcar 'set (list 'a 'f 'e2 'e12 'A1 'A2 'A3 'A4 'A5 'A6 'A7) (PrjPoint_Krasovsky)))
  159.     ((= 1 prjType) (mapcar 'set (list 'a 'f 'e2 'e12 'A1 'A2 'A3 'A4 'A5 'A6 'A7) (PrjPoint_IUGG1975)))
  160.     ((= 2 prjType) (mapcar 'set (list 'a 'f 'e2 'e12 'A1 'A2 'A3 'A4 'A5 'A6 'A7) (PrjPoint_2000)))
  161.     (T (alert "未知prjType参数值")(exit))
  162.   )
  163.   (setq   x    (cadr pt)
  164.       y    (- (car pt) 500000)
  165.       B0   (/ x A1)
  166.       eta  1
  167.   )  
  168.   (while (> eta  0.000000000048)
  169.     (setq  preB0  B0
  170.         B0   (/ (- x (+ (* A2 (sin (* 2 B0))) (* A3 (sin (* 4 B0))) (* A4 (sin (* 6 B0))) (* A5 (sin (* 8 B0))) (* A6 (sin (* 10 B0))) (* A7 (sin (* 12 B0))))) A1)
  171.         eta (abs (- B0 preB0))
  172.     )  
  173.   )  
  174.   (setq   sinB  (sin B0)
  175.       cosB   (cos B0)
  176.       tanB    (/ (sin B0) (cos B0))
  177.       tanB2   (* tanB tanB)
  178.       N      (/ a (sqrt (- 1 (* e2 sinB sinB))))
  179.       ng2      (/ (* cosB cosB e2) (- 1 e2))
  180.       V    (sqrt (+ 1 ng2))
  181.       yN    (/ y N)   
  182.       B    (- B0 (* (+ (- (* yN yN) (/ (* (- (+ 5 (* 3 tanB2) ng2) (* 9 ng2 tanB2)) yN yN yN yN) 12.0)) (/ (* (+ 61 (* 90 tanB2) (* 45 tanB2 tanB2)) yN yN yN yN yN yN) 360.0)) V V tanB 0.5))      
  183.       L    (+ L0 (/ (+ (- yN (/ (* (+ 1 (* 2 tanB2) ng2) yN yN yN) 6.0 )) (/ (* (+ 5 (* 28 tanB2) (* 24 tanB2 tanB2) (* 6 ng2) (* 8 ng2 tanB2)) yN yN yN yN yN) 120.0)) cosB))   
  184.   )
  185.   (list (Rad2Dms B) (Rad2Dms L))
  186. )
  187. ;;;
  188. ;;;cadx,cady转BL
  189. ;;;输入参数
  190. ;;;;pt为点位cad点坐标,
  191. ;;;L0为中央经线,单位为弧度
  192. ;;;prjType取值为0:北京54坐标系,1:西安80坐标系,2:CGCS2000坐标系
  193. ;;;输出经纬度B,L表,单位为dd.mmss
  194. (defun PrjPoint:xy2BL2(pt L0 prjType / a f e2 e12 A1 A2 A3 A4 A5 A6 A7 sinB cosB tanB tanB2 N ng2 V yN preB0 B0 eta x y )
  195.   (cond
  196.     ((= 0 prjType) (mapcar 'set (list 'a 'f 'e2 'e12 'A1 'A2 'A3 'A4 'A5 'A6 'A7) (PrjPoint_Krasovsky)))
  197.     ((= 1 prjType) (mapcar 'set (list 'a 'f 'e2 'e12 'A1 'A2 'A3 'A4 'A5 'A6 'A7) (PrjPoint_IUGG1975)))
  198.     ((= 2 prjType) (mapcar 'set (list 'a 'f 'e2 'e12 'A1 'A2 'A3 'A4 'A5 'A6 'A7) (PrjPoint_2000)))
  199.     (T (alert "未知prjType参数值")(exit))
  200.   )
  201.   (setq   x    (cadr pt)
  202.       y    (- (car pt) 500000)
  203.       B0   (/ x A1)
  204.       eta  1
  205.   )  
  206.   (while (> eta  0.000000000048)
  207.     (setq  preB0  B0
  208.         B0   (/ (- x (+ (* A2 (sin (* 2 B0))) (* A3 (sin (* 4 B0))) (* A4 (sin (* 6 B0))) (* A5 (sin (* 8 B0))) (* A6 (sin (* 10 B0))) (* A7 (sin (* 12 B0))))) A1)
  209.         eta (abs (- B0 preB0))
  210.     )  
  211.   )  
  212.   (setq   sinB  (sin B0)
  213.       cosB   (cos B0)
  214.       tanB    (/ (sin B0) (cos B0))
  215.       tanB2   (* tanB tanB)
  216.       N      (/ a (sqrt (- 1 (* e2 sinB sinB))))
  217.       ng2      (/ (* cosB cosB e2) (- 1 e2))
  218.       V    (sqrt (+ 1 ng2))
  219.       yN    (/ y N)   
  220.       B    (- B0 (* (+ (- (* yN yN) (/ (* (- (+ 5 (* 3 tanB2) ng2) (* 9 ng2 tanB2)) yN yN yN yN) 12.0)) (/ (* (+ 61 (* 90 tanB2) (* 45 tanB2 tanB2)) yN yN yN yN yN yN) 360.0)) V V tanB 0.5))      
  221.       L    (+ L0 (/ (+ (- yN (/ (* (+ 1 (* 2 tanB2) ng2) yN yN yN) 6.0 )) (/ (* (+ 5 (* 28 tanB2) (* 24 tanB2 tanB2) (* 6 ng2) (* 8 ng2 tanB2)) yN yN yN yN yN) 120.0)) cosB))   
  222.   )
  223.   (list (Rad2Degree L) (Rad2Degree B) )
  224. )

  225. ;;;;;;;;;;;;;;;;;;;;;;;;;;;


  226. (defun c:jw-2000 (   / l0 bb ll vvv str  )

  227. (setq l0 (getreal "\n请输入中央子午线经度dd.mmss:"))
  228. (setq bb (getreal "\n请输入待求点纬度dd.mmss:"))
  229. (setq ll (getreal "\n请输入待求点经度dd.mmss:"))

  230. (setq vvv(append(PrjPoint:BL2xy (dms2rad bb) (dms2rad ll) (dms2rad l0)2)'(0)))
  231. (setq str(strcat (rtos bb 2 3 )","(rtos ll 2 3 )))
  232. (entmake (list '(0 . "TEXT")'(8 . "jwd") (cons 1 str) (cons 10 vvv) (cons 40 2)))
  233. (entmake (list '(0 . "POINT")'(8 . "jwd") (cons 10 vvv)))
  234.   
  235.   )

  236. (defun vxs(e / p a b n ob q et d d1 en et)
  237.     (setq a(entget e)ob(vlax-ename->vla-object e)et(cdr(assoc 0 a))n 0 p nil d nil)
  238.     (cond((="LWPOLYLINE"et)
  239.     (repeat(length a)(setq b (nth n a) n (+ n 1))
  240.       (if (= 10 (car b))(progn
  241.         (setq q(list (cadr b) (caddr b))d1(vlax-curve-getDistAtPoint ob q))
  242.         (if p (if (not(member d1 d)) (setq p (append p (list q))d (append d (list d1))))
  243.           (setq p (list q)))))))
  244.    ((="POLYLINE"et)
  245.     (SETQ EN (ENTGET (SETQ E (ENTNEXT E))))
  246.     (WHILE (/= (CDR (ASSOC 0 EN)) "SEQEND")
  247.       (SETQ q (CDR (ASSOC 10 EN))d1(vlax-curve-getDistAtPoint ob q)q(reverse(cdr(reverse q))))
  248.       (if p(if (not(member d1 d)) (setq p (append p (list q))d (append d (list d1))))(setq p(list q)))
  249.       (SETQ EN (ENTGET (SETQ E (ENTNEXT E)))))
  250.     (setq p(reverse p))))P)

  251. (defun c:lw-bl2000 ( / p l0 zb jwd )

  252.   (vl-load-com)
  253. (setq l0 (getreal "\n请输入中央子午线经度dd.mmss:"))
  254. (setq p (car(entsel "\n请选择2000或者wgs84坐标多段线:")))

  255.   (setq zb (vxs p))
  256. (setq ffn (getfiled "选取/建立数据导出10进制经纬度文件" "" "txt" 1))
  257.   (setq ff (open ffn "w"))
  258. (foreach x zb
  259. (setq jwd (PrjPoint:xy2BL2 x (Dms2Rad l0) 2))

  260. (write-line (strcat (rtos (car jwd)2 9)","(rtos (cadr jwd)2 9)) ff)

  261.   )
  262. (close ff)
  263.        )

回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2020-11-6 15:12 | 显示全部楼层
松树石头哥 发表于 2020-11-6 10:35
请楼主说明如何使用!谢谢!!!!!

就是把kml文件的经纬度坐标转换为直角坐标并在cad画出来
kml文件是谷歌地球的文件,记录点、线、面等坐标信息

运行命令kml2cad,选择kml文件后指定中央经线(十进制度数)就行了

要有点经纬度坐标/直角地理坐标 /投影的基本概念
发表于 2020-11-1 13:54 | 显示全部楼层
发现了一个好的东西,谢谢楼主分享,先收藏起来
发表于 2020-11-3 19:11 | 显示全部楼层
怎么使用呢?
发表于 2020-11-4 08:42 | 显示全部楼层
怎么使用呢
发表于 2020-11-4 08:50 | 显示全部楼层
好东西,谢谢楼主分享。
发表于 2020-11-5 12:16 | 显示全部楼层
这么简单的东西也要收费?
发表于 2020-11-6 10:35 | 显示全部楼层
请楼主说明如何使用!谢谢!!!!!
 楼主| 发表于 2020-11-11 14:26 | 显示全部楼层
904772207 发表于 2020-11-5 12:16
这么简单的东西也要收费?

你也嗮一个看看
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-21 22:49 , Processed in 0.453470 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表