AutoLISP 从邮政编码获取国家电网参考

问题描述 投票:0回答:2

我正在寻找在 CAD 中制作一个脚本,它将返回国家电网参考并输入邮政编码

例如 用户输入:AL1 1BY 退货:TL 14584 06989

我从操作系统“CodePoint - Open”获得了一个 CSV,它提供了邮政编码、东距、北距、纬度和经度,可用于获取部分网格参考,但获取前 2 个字母“TL”是主要的问题是 csv 没有提供这个,我不确定这是如何计算的。

我考虑过制作多个 CSV(AL.csv、DN.csv、SL.csv...),其中包含链接网格参考的邮政编码

AL.csv

AL1 1BY TL 14584 06989

AL1 1DQ TL 14524 06737

但这会导致速度读取超过 10,000 行以上时出现问题吗?

我还想知道是否可以使用 AutoLisp 实现 API 调用以使用邮政编码到 NGR 代码,但这不是我以前做过的事情,也不知道是否可能?

我还没有采取任何措施,因为我正在努力思考实现这一目标的最佳方法是什么。

autocad cad autolisp bricscad
2个回答
0
投票

我还没有读取过 10,000 多行,但您可以调整下面的代码,以便 DraftSight 记住第一次扫描后读取的内容。如果您需要 autolisp 函数的源代码,请检查此处

(defun C:Test01 (/ sFile FileID sLine sDelimiter lDetails sInfo *lPostCodes*)

    ;; Constant
    (setq sDelimiter " "); "\t" for tab deliminator

    ;; Manual File Path
    (setq sFile (getfiled "Select a file" "" "csv" 0))

    ; ;; Automatic file path
    ; (setq sFile "[Drive letter]:\\[File path]\\[File name.extension]")
    ; (setq sFile (findfile sFile))

    ;; Reading the file
    (setq FileID (open sFile "r"))
    (while (setq sLine (read-line FileID))
        
        ;; Reading contents
        (setq sInfo "")
        (while (> (strlen sLine) 0)
            (if (= (substr sLine 1 1) sDelimiter)
                (progn ;; True
                    (if (> (strlen sInfo) 0)(setq lDetails (cons sInfo lDetails)))
                    (setq sInfo "")
                );progn ; True
                ;; False
                (setq sInfo (strcat sInfo (substr sLine 1 1)))
            );if
            (setq sLine (substr sLine 2)); next character
        );while - Each character
        (if (/= (car lDetails) sInfo)(setq lDetails (cons sInfo lDetails)))

        ;; Updating list
        (setq lDetails (reverse lDetails))
        (setq *lPostCodes* (cons lDetails *lPostCodes*))
        (setq lDetails (list))
    );while - Each line
    
    ;; Closing the file
    (close FileID)

    ;; Returning value
    (setq *lPostCodes* (reverse *lPostCodes*))
    (princ "\nResults : ")(prin1 *lPostCodes*)(terpri)(princ)
);C:Test01
Command: TEST01
Results : (("AL1" "1BY" "TL" "14584" "06989") ("AL1" "1DQ" "TL" "14524" "06737"))

0
投票

几年前,我编写了一些 Lisp,从屏幕上单击的点返回各种 OSGB 地图图块引用。删除第一个坐标并连接两个数字后。我使用两个数组通过迭代第一个数组来找到匹配项,从而将数字转换为字母。

;;Get x,y coordinates by left clicking point on screen
(setq p1 (getpoint "\nSelect a point:"))

;;Convert x,y coordinates to strings and store in seporate variables
(setq xcor (rtos (nth 0 p1) 2 0))
(setq ycor (rtos (nth 1 p1) 2 0))

;;Get first character of x & y coordinates and concatinate
(setq xy (strcat (substr xcor 1 1)(substr ycor 1 1)))

;;Build an ordered array of numbers
(setq array1 (list "00" "07" "08" "09" "10" "11" "12" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45" "46" "50" "51" "52" "53" "54" "61" "62" "63"))

;;Build an ordered array of equivalent Ordnance Survey(GB) letters
(setq array2 (list "SV" "NL" "NF" "NA" "SW" "SR" "SM" "NW" "NR" "NM" "NG" "NB" "SX" "SS" "SN" "SH" "SC" "NX" "NS" "NN" "NH" "NC" "SY" "ST" "SO" "SJ" "SD" "NY" "NT" "NO" "NJ" "ND" "SZ" "SU" "SP" "SK" "SE" "NZ" "NU" "TV" "TQ" "TL" "TF" "TA" "TR" "TM" "TG"))

;;start counter at 0
(setq i 0)

;;Iterate through first array and return array position of matched number
(repeat 47
    (if (= xy (nth i array1))(setq j i))
    (setq i (1+ i))
)

;;Return value from 2nd array using matched array position
(prompt (strcat "OS prefix = " (nth j array2)))
© www.soinside.com 2019 - 2024. All rights reserved.