Author Topic: Convert coordinate files to x,y  (Read 562 times)

0 Members and 1 Guest are viewing this topic.

Topographer

  • Bull Frog
  • Posts: 489
Convert coordinate files to x,y
« on: August 30, 2017, 04:15:27 am »
hI. I am searching for a lisp to convert coordinate files files to x,y  (*.txt)

1) p,x,y,z --->x,y
2) p,x,y ---->x,y
3) p x y z ---> x,y
4) p x y ----> x,y


i know that i can do it with excel but i need something faster.

Thanks





Topographer

  • Bull Frog
  • Posts: 489
Re: Convert coordinate files to x,y
« Reply #1 on: August 30, 2017, 05:41:52 am »
any ideas ?

Pad

  • Bull Frog
  • Posts: 298
Re: Convert coordinate files to x,y
« Reply #2 on: August 30, 2017, 07:14:24 am »
you could try this
http://www.lancaster.ac.uk/~steveb/cpaap/pfe/default.htm
and make yourself a macro for each variation.

Mark

  • Custom Title
  • Administrator
  • Seagull
  • Posts: 28155
Re: Convert coordinate files to x,y
« Reply #3 on: August 30, 2017, 08:04:44 am »
TheSwamp.org  (serving the CAD community since 2003)

Topographer

  • Bull Frog
  • Posts: 489
Re: Convert coordinate files to x,y
« Reply #4 on: August 30, 2017, 10:22:22 am »
i can not understand it can you give me an example for    p x y ----> x,y  ?

thanks

Topographer

  • Bull Frog
  • Posts: 489
Re: Convert coordinate files to x,y
« Reply #5 on: August 30, 2017, 11:10:41 am »
i am thinking something like this

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ )
  2.  
  3.  (setq title "select file"
  4.        fname (getfiled title path "txt" 0)
  5.        path  (if (setq tmp (vl-filename-directory fname))
  6.                (strcat tmp "\\")
  7.                ""
  8.              )
  9.  (setq f (open (strcat path
  10.                        ""
  11.                        (vl-filename-base fname)
  12.                        ".pl"
  13.                )
  14.                "w"
  15.          )
  16.  
  17.    (write-line (strcat (rtos (cadr i) 2 3)    
  18.                        ","
  19.                         (rtos (caddr i) 2 3)    
  20.  
  21.  
  22.                )
  23.                f
  24.    )
  25.  )
  26. )
  27. )
  28.  
  29.  

but is not working. Any ideas?

Thanks

mjfarrell

  • Seagull
  • Posts: 13978
  • Every Student their own Lesson
Re: Convert coordinate files to x,y
« Reply #6 on: August 30, 2017, 11:16:27 am »
can you post a sample of the  " coordinate files files"  to x,y you are starting with?
And what you want them to look like when done?

It might be possible to use QGIS or similar to do this.
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Mark

  • Custom Title
  • Administrator
  • Seagull
  • Posts: 28155
Re: Convert coordinate files to x,y
« Reply #7 on: August 30, 2017, 11:24:27 am »
i can not understand it can you give me an example for    p x y ----> x,y  ?
something like this
Code: [Select]
gawk "{print $2 $3 }" input-file.txt > output-file.txt
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Administrator
  • Seagull
  • Posts: 28155
Re: Convert coordinate files to x,y
« Reply #8 on: August 30, 2017, 11:38:13 am »
i can not understand it can you give me an example for    p x y ----> x,y  ?
It would actually be ...

Code: [Select]
gawk "{print $2\",\" $3 }" data.txt > outputfile.txt
Its all in that link i posted earlier.
TheSwamp.org  (serving the CAD community since 2003)

fools

  • Newt
  • Posts: 52
  • China
Re: Convert coordinate files to x,y
« Reply #9 on: August 30, 2017, 11:39:34 am »
i can not understand it can you give me an example for    p x y ----> x,y  ?

thanks

Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c:test (/ FF FFN TXT TXTS)
  2.  (SETQ ffn  (GETFILED "Select file" "" "txt" 0)
  3. ff   (OPEN ffn "r")
  4. txts nil
  5.  )
  6.  (WHILE (SETQ txt (READ-LINE ff)) (SETQ txts (CONS txt txts)))
  7.  (CLOSE ff)
  8.  ;;(VL-FILE-RENAME ffn (STRCAT (SUBSTR ffn 1 (- (STRLEN ffn) 3)) "bak"))
  9.  (SETQ txts (MAPCAR 'CDR (MAPCAR 'F_Str2Lst (MAPCAR 'F_NoExtraSpaces (REVERSE txts)))))
  10.  (SETQ ff (OPEN (STRCAT (SUBSTR ffn 1 (- (STRLEN ffn) 3)) "pl") "w"))
  11.  (FOREACH item txts (WRITE-LINE (STRCAT (CAR item) "," (CADR item)) ff))
  12.  (CLOSE ff)
  13. )
  14.  
  15. (DEFUN F_NoExtraSpaces (str / pos)
  16.  (SETQ str (VL-STRING-TRIM " " str))
  17.  (WHILE (SETQ pos (VL-STRING-SEARCH "  " str pos)) (SETQ str (VL-STRING-SUBST " " "  " str pos)))
  18.  str
  19. )
  20.  
  21. (DEFUN F_Str2Lst (str / pos)
  22.  (IF (SETQ pos (VL-STRING-SEARCH " " str))
  23.    (CONS (SUBSTR str 1 pos) (F_Str2Lst (SUBSTR str (+ (STRLEN " ") pos 1))))
  24.    (LIST str)
  25.  )
  26. )
Good good study , day day up . Sorry about my Chinglish .

Topographer

  • Bull Frog
  • Posts: 489
Re: Convert coordinate files to x,y
« Reply #10 on: August 30, 2017, 12:47:38 pm »
I attach a *.txt file with the coordinates.I try fools code but the *.pl file is empty

Topographer

  • Bull Frog
  • Posts: 489
Re: Convert coordinate files to x,y
« Reply #11 on: August 30, 2017, 12:58:33 pm »
i want the export file to be like this

Quote
318349.74,4231547.73
318445.61,4231568.79
318446.37,4231561.59
318443.36,4231549.82
318438.82,4231539.87
318428.56,4231532.33
318425.25,4231523.57
318428.55,4231513.05
318442.57,4231516.64
318455.87,4231506.94
318473.12,4231495.81
318473.84,4231490.78
318468.81,4231486.11
318468.45,4231473.18
318464.85,4231451.63
318460.90,4231446.96
318447.24,4231446.60
318439.70,4231458.45
318431.79,4231475.34
318424.60,4231475.34
318399.26,4231473.08
318390.21,4231473.39
318382.97,4231477.91
318379.64,4231487.26
318376.02,4231521.35
318372.99,4231537.20
318368.15,4231541.13
318354.88,4231545.65
318349.74,4231547.73



thanks

Mark

  • Custom Title
  • Administrator
  • Seagull
  • Posts: 28155
Re: Convert coordinate files to x,y
« Reply #12 on: August 30, 2017, 01:24:44 pm »
You're not even trying are you?

Code: [Select]
gawk "{print $2\",\" $3 }" 1.txt
318349.74,4231547.73
318445.61,4231568.79
318446.37,4231561.59
318443.36,4231549.82
318438.82,4231539.87
318428.56,4231532.33
318425.25,4231523.57
318428.55,4231513.05
318442.57,4231516.64
318455.87,4231506.94
318473.12,4231495.81
318473.84,4231490.78
318468.81,4231486.11
TheSwamp.org  (serving the CAD community since 2003)

Topographer

  • Bull Frog
  • Posts: 489
Re: Convert coordinate files to x,y
« Reply #13 on: August 30, 2017, 01:35:49 pm »
Mark i am not using scripts.I use only lisp codes

mjfarrell

  • Seagull
  • Posts: 13978
  • Every Student their own Lesson
Re: Convert coordinate files to x,y
« Reply #14 on: August 30, 2017, 02:37:32 pm »
yes you could read that file into QGIS (its free GIS software)

new layer from delimited file...
have it read your desired columns from that file

then export it as comma delimited file or shp file...or lots of formats.

no list/code/ or scripts required
Be your Best


Michael Farrell
http://primeservicesglobal.com/

MP

  • Seagull
  • Posts: 16985
  • brevity != aggression
Re: Convert coordinate files to x,y
« Reply #15 on: August 30, 2017, 03:08:19 pm »
Quick & Dirty concept code.

Code: [Select]
(defun _TSV->List ( tsvfilename / foo i handle s result )

    (defun foo ( s / result )
        (while (setq i (vl-string-position 9 s nil t))
            (setq
                result (cons (substr s (+ 2 i)) result)
                s      (substr s 1 i)
            )
        )
        (cons s result)
    )

    (if (setq handle (open tsvfilename "r"))
        (progn
            (while (setq s (read-line handle))
                (setq result (cons (foo s) result))
            )
            (close handle)
            (vl-remove 'nil (reverse result))
        )
    )
)

Code: [Select]
(defun _List->CSV ( lst tsvfilename / handle )

    (if (setq handle (open tsvfilename "w"))
        (progn
            (foreach r lst
                (princ (car r) handle)
                (foreach x (cdr r) (princ "," handle) (princ x handle))
                (princ "\n" handle)
            )
            (null (close handle))
        )
    )
)

Code: [Select]
;;  read it in
(setq lst (_TSV->List "c:\\docs\\tsv.txt"))
;;  abuse it
(setq alt (mapcar (function (lambda (r) (reverse (mapcar 'set '(x y) (cdr r))))) lst))
;;  write it out
(_List->CSV alt "c:\\docs\\csv_abused.txt")

;;   orig

0    318349.74    4231547.73
1    318445.61    4231568.79
2    318446.37    4231561.59
3    318443.36    4231549.82
4    318438.82    4231539.87
5    318428.56    4231532.33
...

;;   abused

4231547.73,318349.74
4231568.79,318445.61
4231561.59,318446.37
4231549.82,318443.36
4231539.87,318438.82
...


/2˘
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

VovKa

  • Swamp Rat
  • Posts: 819
  • Ukraine
Re: Convert coordinate files to x,y
« Reply #16 on: August 30, 2017, 03:30:22 pm »
no foo
Code: [Select]
(setq result (cons (read (strcat "(" s ")")) result))

MP

  • Seagull
  • Posts: 16985
  • brevity != aggression
Re: Convert coordinate files to x,y
« Reply #17 on: August 30, 2017, 05:01:27 pm »
If the data hosts non numerical items that technique would (undesirably) yield symbols instead of strings.

Cheers.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

fools

  • Newt
  • Posts: 52
  • China
Re: Convert coordinate files to x,y
« Reply #18 on: August 30, 2017, 06:57:20 pm »
I attach a *.txt file with the coordinates.I try fools code but the *.pl file is empty

My code is written very rough, just to show the way.
Change space to tab in function F_Str2Lst can convert correctly.

Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c:test (/ FF FFN TXT TXTS)
  2.  (SETQ ffn  (GETFILED "Select file" "" "txt" 0)
  3. ff   (OPEN ffn "r")
  4. txts nil
  5.  )
  6.  (WHILE (SETQ txt (READ-LINE ff)) (SETQ txts (CONS txt txts)))
  7.  (CLOSE ff)
  8.  ;;(VL-FILE-RENAME ffn (STRCAT (SUBSTR ffn 1 (- (STRLEN ffn) 3)) "bak"))
  9.  (SETQ txts (MAPCAR 'CDR (MAPCAR 'F_Str2Lst (MAPCAR 'F_NoExtraSpaces (REVERSE txts)))))
  10.  (SETQ ff (OPEN (STRCAT (SUBSTR ffn 1 (- (STRLEN ffn) 3)) "pl") "w"))
  11.  (FOREACH item txts (WRITE-LINE (STRCAT (CAR item) "," (CADR item)) ff))
  12.  (CLOSE ff)
  13. )
  14.  
  15. (DEFUN F_NoExtraSpaces (str / pos)
  16.  (SETQ str (VL-STRING-TRIM " " str))
  17.  (WHILE (SETQ pos (VL-STRING-SEARCH "  " str pos)) (SETQ str (VL-STRING-SUBST " " "  " str pos)))
  18.  str
  19. )
  20.  
  21. (DEFUN F_Str2Lst (str / pos)
  22.  (IF (SETQ pos (VL-STRING-SEARCH "\t" str))
  23.    (CONS (SUBSTR str 1 pos) (F_Str2Lst (SUBSTR str (+ (STRLEN "\t") pos 1))))
  24.    (LIST str)
  25.  )
  26. )
Good good study , day day up . Sorry about my Chinglish .

Topographer

  • Bull Frog
  • Posts: 489
Re: Convert coordinate files to x,y
« Reply #19 on: August 30, 2017, 07:08:35 pm »
Thank you   :smitten: :smitten:

fools

  • Newt
  • Posts: 52
  • China
Re: Convert coordinate files to x,y
« Reply #20 on: August 30, 2017, 07:10:47 pm »
no foo
Code: [Select]
(setq result (cons (read (strcat "(" s ")")) result))

Using read function maybe change data.

Code: [Select]
(SETQ str " 0   318349.74  4231547.73 ")
(read (strcat "(" str ")"))

result:
(0 318350.0 4.23155e+006)
Good good study , day day up . Sorry about my Chinglish .

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 947
  • class keyThumper<T>:ILazy<T>
Re: Convert coordinate files to x,y
« Reply #21 on: August 30, 2017, 11:53:10 pm »
hI. I am searching for a lisp to convert coordinate files files to x,y  (*.txt)

1) p,x,y,z --->x,y
2) p,x,y ---->x,y
3) p x y z ---> x,y
4) p x y ----> x,y


i know that i can do it with excel but i need something faster.

Thanks

to be more in line with the original requirements the translators would need to work successfully on this list.
with the addition of TABS as per the provided file.


0   300000.00   4000000.00 0.0
1   318445.61   4231568.79
2 318446.37,4231561.59,123
3   318443.36,4231549.82
4   318438.82      4231539.87    0.0
5   318428.56,   4231532.33,      0.0
6,318425.25,4231523.57,0.0
7,   318428.55,   4231513.05,   0.0
8   318442.57   4231516.64
9   318455.87   4231506.94
10   318473.12   4231495.81


just saying ...
called Kerry in my other life

Sometimes the question is more important than the answer.

fools

  • Newt
  • Posts: 52
  • China
Re: Convert coordinate files to x,y
« Reply #22 on: August 31, 2017, 01:20:40 am »
to be more in line with the original requirements the translators would need to work successfully on this list.
with the addition of TABS as per the provided file.

Thanks for remind. I change a function to increase versatility.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ FF FFN TXT TXTS)
  2.  (setq ffn  (getfiled "Select file" "" "txt" 0)
  3. ff   (open ffn "r")
  4. txts nil
  5.  )
  6.  (while (setq txt (read-line ff)) (setq txts (cons txt txts)))
  7.  (close ff)
  8.  (setq txts (mapcar '(lambda (x) (STD-STRSPLIT x "\t,; ")) (reverse txts)))
  9.  (setq txts
  10.   '(lambda (x) (vl-remove-if '(lambda (y) (and (not (equal "0" y)) (zerop (atof y)))) x))
  11.   txts
  12. )
  13.  )
  14.  (setq ff (open (strcat (substr ffn 1 (- (strlen ffn) 3)) "pl") "w"))
  15.  (foreach item txts (write-line (strcat (cadr item) "," (caddr item)) ff))
  16.  (close ff)
  17.  (princ)
  18. )
  19.  
  20. ;;; The order of chars in delim is not important.
  21. ;;; keeping null tokens, not as with std-strtok.
  22. ;;; Might be renamed to std-string-split
  23. ;;; by Vladimir Nesterowsky
  24. (defun STD-STRSPLIT (s delims / len s1 i c lst)
  25.  (setq delims (vl-string->list delims) ; fixed
  26. len    (strlen s)
  27. s1     ""
  28. i      (1+ len)
  29.  )
  30.  (while (> (setq i (1- i)) 0)
  31.    (setq c (substr s i 1))
  32.    (if (member (ascii c) delims)
  33.      (if (/= i len) ; "1,2," -> ("1" "2") and not ("1" "2" "")
  34. (setq lst (cons s1 lst)
  35.      s1  ""
  36. )
  37.      )
  38.      (setq s1 (strcat c s1))
  39.    )
  40.  )
  41.  (cons s1 lst) ; ",1,2" -> ("" "1" "2")
  42. )


1.txt
0   300000.00   4000000.00 0.0
1   318445.61   4231568.79
2 318446.37,4231561.59,123
3   318443.36,4231549.82
4   318438.82      4231539.87    0.0
5   318428.56,   4231532.33,      0.0
6,318425.25,4231523.57,0.0
7,   318428.55,   4231513.05,   0.0
8   318442.57   4231516.64
9   318455.87   4231506.94
10   318473.12   4231495.81

1.pl
300000.00,4000000.00
318445.61,4231568.79
318446.37,4231561.59
318443.36,4231549.82
318438.82,4231539.87
318428.56,4231532.33
318425.25,4231523.57
318428.55,4231513.05
318442.57,4231516.64
318455.87,4231506.94
318473.12,4231495.81
Good good study , day day up . Sorry about my Chinglish .

anhquang1989

  • Newt
  • Posts: 43
Re: Convert coordinate files to x,y
« Reply #23 on: August 31, 2017, 02:14:16 am »
This is the norm of my work. It may be right for you. please try
Import txt file, csv with the format: P Y Y Z Code
- different separators like comma, space, tab
- Still works well with other formats like
+ P X Y
+ P X Y Z
+ P Y X
+ P Y X Z
......

MP

  • Seagull
  • Posts: 16985
  • brevity != aggression
Re: Convert coordinate files to x,y
« Reply #24 on: August 31, 2017, 10:53:24 am »
to be more in line with the original requirements the translators would need to work successfully on this list.
with the addition of TABS as per the provided file.

0   300000.00   4000000.00 0.0
1   318445.61   4231568.79
2 318446.37,4231561.59,123
3   318443.36,4231549.82
4   318438.82      4231539.87    0.0
5   318428.56,   4231532.33,      0.0
6,318425.25,4231523.57,0.0
7,   318428.55,   4231513.05,   0.0
8   318442.57   4231516.64
9   318455.87   4231506.94
10   318473.12   4231495.81


just saying ...

Eschewing the important but I don't have time for "importance of well formed data" discussion I'll ante up this 2 minute quickie:

Code: [Select]
(defun _Normalize ( str )
    (foreach delim '(" " "," "\t")
        (foreach pattern (list (strcat " " delim) (strcat delim " "))
            (while (vl-string-search pattern str)
                (setq str (vl-string-subst delim pattern str))
            )
        )
    )         
    (vl-string-translate " \t" ",," str)
)

Code: [Select]
(progn
    (foreach test
       '(
            "0   300000.00   4000000.00 0.0"
            "1   318445.61   4231568.79"
            "2 318446.37,4231561.59,123"
            "3   318443.36,4231549.82"
            "4   318438.82      4231539.87    0.0"
            "5   318428.56,   4231532.33,      0.0"
            "6,318425.25,4231523.57,0.0"
            "7,   318428.55,   4231513.05,   0.0"
            "8 \t  318442.57   4231516.64"
            "9   318455.87 \t  4231506.94"
            "10   318473.12   4231495.81"   
        )
        (princ (strcat "\n" test " >> " (_Normalize test)))
    )   
    (princ)
)

0   300000.00   4000000.00 0.0        >> 0,300000.00,4000000.00,0.0
1   318445.61   4231568.79            >> 1,318445.61,4231568.79
2 318446.37,4231561.59,123            >> 2,318446.37,4231561.59,123
3   318443.36,4231549.82              >> 3,318443.36,4231549.82
4   318438.82      4231539.87    0.0  >> 4,318438.82,4231539.87,0.0
5   318428.56,   4231532.33,      0.0 >> 5,318428.56,4231532.33,0.0
6,318425.25,4231523.57,0.0            >> 6,318425.25,4231523.57,0.0
7,   318428.55,   4231513.05,   0.0   >> 7,318428.55,4231513.05,0.0
8   318442.57   4231516.64            >> 8,318442.57,4231516.64
9   318455.87    4231506.94           >> 9,318455.87,4231506.94
10   318473.12   4231495.81           >> 10,318473.12,4231495.81


Cheers.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Lee Mac

  • Seagull
  • Posts: 11781
  • AutoCAD 2015 Windows 7 London, England
Re: Convert coordinate files to x,y
« Reply #25 on: August 31, 2017, 01:36:25 pm »
Just to offer an alternative approach:
Code - Auto/Visual Lisp: [Select]
  1. (defun NormaliseList ( src dst lst / rgx rtn )
  2.    (if (setq rgx (vlax-create-object "vbscript.regexp"))
  3.        (progn
  4.            (vl-catch-all-apply
  5.               '(lambda nil
  6.                    (vlax-put-property rgx 'global actrue)
  7.                    (vlax-put-property rgx 'pattern src)
  8.                    (setq rtn (mapcar '(lambda ( x ) (vlax-invoke rgx 'replace x dst)) lst))
  9.                )
  10.            )
  11.            (vlax-release-object rgx)
  12.            rtn
  13.        )
  14.    )
  15. )
Code - Auto/Visual Lisp: [Select]
  1.    (NormaliseList
  2.        "[^\\s\\,]+[\\s\\,]+([^\\s\\,]+)[\\s\\,]+([^\\s\\,]+).*"
  3.        "$1,$2"
  4.       '(
  5.            "0   300000.00   4000000.00 0.0"
  6.            "1   318445.61   4231568.79"
  7.            "2 318446.37,4231561.59,123"
  8.            "3   318443.36,4231549.82"
  9.            "4   318438.82      4231539.87    0.0"
  10.            "5   318428.56,   4231532.33,      0.0"
  11.            "6,318425.25,4231523.57,0.0"
  12.            "7,   318428.55,   4231513.05,   0.0"
  13.            "8 \t  318442.57   4231516.64"
  14.            "9   318455.87 \t  4231506.94"
  15.            "10   318473.12   4231495.81"  
  16.        )
  17.    )
  18. )

Yields:

"300000.00,4000000.00"
"318445.61,4231568.79"
"318446.37,4231561.59"
"318443.36,4231549.82"
"318438.82,4231539.87"
"318428.56,4231532.33"
"318425.25,4231523.57"
"318428.55,4231513.05"
"318442.57,4231516.64"
"318455.87,4231506.94"
"318473.12,4231495.81"

MP

  • Seagull
  • Posts: 16985
  • brevity != aggression
Re: Convert coordinate files to x,y
« Reply #26 on: August 31, 2017, 02:39:54 pm »
Nicely done Lee, cheers.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Lee Mac

  • Seagull
  • Posts: 11781
  • AutoCAD 2015 Windows 7 London, England
Re: Convert coordinate files to x,y
« Reply #27 on: August 31, 2017, 05:42:42 pm »
Cheers Michael, same to you. :-)

fools

  • Newt
  • Posts: 52
  • China
Re: Convert coordinate files to x,y
« Reply #28 on: September 01, 2017, 09:39:54 pm »
Thanks Lee and MP, I learned a lot.
Good good study , day day up . Sorry about my Chinglish .

DEVITG

  • Bull Frog
  • Posts: 425
Re: Convert coordinate files to x,y
« Reply #29 on: September 02, 2017, 12:38:32 am »
Just put , or upload, or whats ever, your sample dwg and your sample xyz value file, as you do it by hand.

Keep it simple sir .. just KISS

Location @ Córdoba Argentina<br /><br />using acad 2008 under win XP

kdub

  • SuperMod
  • Swamp Rat
  • Posts: 947
  • class keyThumper<T>:ILazy<T>
Re: Convert coordinate files to x,y
« Reply #30 on: September 02, 2017, 02:01:09 am »
While that is generally good advice, and Michaels comments regarding data formatting ;
I can understand the desire to be able to handle various formatting structures.

Having one function to parse the data file irrespective of it's structure is definitely an advantage if we are dealing with data from various sources.

I hadn't imagined the format would be as mixed in ONE file as the example I posted but being able to process ANY of the formats would be handy.

Good generic solution Fools.
called Kerry in my other life

Sometimes the question is more important than the answer.

fools

  • Newt
  • Posts: 52
  • China
Re: Convert coordinate files to x,y
« Reply #31 on: September 02, 2017, 05:05:22 am »
While that is generally good advice, and Michaels comments regarding data formatting ;
I can understand the desire to be able to handle various formatting structures.

Having one function to parse the data file irrespective of it's structure is definitely an advantage if we are dealing with data from various sources.

I hadn't imagined the format would be as mixed in ONE file as the example I posted but being able to process ANY of the formats would be handy.

Good generic solution Fools.

Thanks.
I tested Lee, MP and my code by benchmark.lsp.
Before testing, I added some content to MP's code. Let three functions has same result.
MP's function is the fastest and mine is the slowest. So, MP's function is recommended, especially when the amount of data is large.
BTW, Lee use regular expression is very wise solution.
Good good study , day day up . Sorry about my Chinglish .

MP

  • Seagull
  • Posts: 16985
  • brevity != aggression
Re: Convert coordinate files to x,y
« Reply #32 on: September 04, 2017, 02:17:14 pm »
Thanks for the nod fools. That said, I wouldn't necessarily consider my normalize function as recommended. It was more of an acedemic response to a contrived challenge that doesn't tend to exist much in real life. That is, data is normally consistant (tho it may be ugly). Be it spawned from a spreadsheet, a database, a data collector ... whatever. As such -- and especially if you're concerned with performance -- tailored code will perform far better than my "try to do it all" function. Cheers.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About