Jump to content

Recommended Posts

Posted

I'm making a script which will draw a route line from a KML/ google earth in CAD, but I there co-ords given are in Long/Lat.

 

I'm currently sending the list of co-ords into my API to convert them server side, but this can be quite lengthy even with it all coordinates being converted concurrency, depending on the route length. is there a more simple way I can convert these which will also provide the speed? I understand the plotting of the route line in CAD will still take its time

Posted

There is a formula to convert latitude-longitude to a grid (northing-easting) - something I looked at a while ago when it was quiet in work. If I remember right the formula is dependent on your position in the world - the closer you are to the poles the more correction needed to make straight perpendicular lines.

 

If you have the formula that you are happy with then it should be possible to convert that to a LISP and see if it is quicker to do it within CAD, noting that while the conversion might be slower taking away the human speed element to send the coordinated to your API and then back again might make the process overall quicker.

 

Big-Al I suspect will be along shortly to tell you to use the function in civil 3d (mapimport) rather than creating something new. After that it will just need a rule of which points to connect as lines 

  • Funny 1
Posted

Yep import Lat Long is built in to CIV3D. 

 

Like Steven P had access to an external convert Lat Long program that produced XYZ file, it was for here in AUS.

 

Posted
On 10/11/2023 at 10:00 AM, BIGAL said:

Yep import Lat Long is built in to CIV3D. 

 

Like Steven P had access to an external convert Lat Long program that produced XYZ file, it was for here in AUS.

 

 

@BIGAL, I think this is what you are referring to:

https://geodesyapps.ga.gov.au/grid-coordinate-batch-processing

 

I think it used to be a small application named GEODD

  • Like 1
Posted

How about using program like QGIS which is free to do the conversion for you... You can take a the KML and covert it into DXF or Shape... then just import it or open in AutoCAD.

  • 7 months later...
Posted

revisiting this after a while, i stumbled across some code which ive converted into autolisp

 

(defun LatLongToEastNorth (latitude longitude / a b F0 lat0 lon0 N0 E0 e2 n n2 n3 cosLat sinLat nu rho eta2 Ma Mb Mc Md M cos3lat cos5lat tan2lat tan4lat I II III IIIA IV V VI dLon dLon2 dLon3 dLon4 dLon5 dLon6 N E)
  (setq latitude (deg2rad latitude)
        longitude (deg2rad longitude)
        a 6377563.396
        b 6356256.910
        F0 0.9996012717
        lat0 (deg2rad 49)
        lon0 (deg2rad -2)
        N0 -100000
        E0 400000
        e2 (- 1 (/ (* b b) (* a a)))
        n (/ (- a b) (+ a b))
        n2 (* n n)
        n3 (* n n n)
        cosLat (cos latitude)
        sinLat (sin latitude)
        nu (* a F0 (sqrt (- 1 (* e2 (* sinLat sinLat)))))
        rho (* a F0 (- 1 e2) (expt (- 1 (* e2 (* sinLat sinLat))) 1.5))
        eta2 (/ nu rho 1.0)
        Ma (* (+ 1 n (* (/ 5 4) n2) (* (/ 5 4) n3)) (- latitude lat0))
        Mb (* (+ (* 3 n) (* 3 n n) (* (/ 21 8) n3)) (sin (- latitude lat0)) (cos (+ latitude lat0)))
        Mc (* (+ (* (/ 15 8) n2) (* (/ 15 8) n3)) (sin (* 2 (- latitude lat0))) (cos (* 2 (+ latitude lat0))))
        Md (* (* (/ 35 24) n3) (sin (* 3 (- latitude lat0))) (cos (* 3 (+ latitude lat0))))
        M (* b F0 (- Ma Mb Mc Md))
        cos3lat (* cosLat cosLat cosLat)
        cos5lat (* cos3lat (* cosLat cosLat))
        tan2lat (* (tan latitude) (tan latitude))
        tan4lat (* tan2lat tan2lat)
        I (+ M N0)
        II (* (/ nu 2) sinLat cosLat)
        III (* (/ nu 24) sinLat cos3lat (- 5 tan2lat (* 9 eta2)))
        IIIA (* (/ nu 720) sinLat cos5lat (- 61 (* 58 tan2lat) tan4lat))
        IV (* nu cosLat)
        V (* (/ nu 6) cos3lat (/ nu rho) (- tan2lat))
        VI (* (/ nu 120) cos5lat (- 5 (* 18 tan2lat) tan4lat (* 14 eta2) (* 58 tan2lat eta2)))
        dLon (- longitude lon0)
        dLon2 (* dLon dLon)
        dLon3 (* dLon2 dLon)
        dLon4 (* dLon3 dLon)
        dLon5 (* dLon4 dLon)
        dLon6 (* dLon5 dLon)
        N (+ I (* II dLon2) (* III dLon4) (* IIIA dLon6))
        E (+ E0 (* IV dLon) (* V dLon3) (* VI dLon5)))
  (list E N)
  
  (princ E)
  (princ " ")
  (princ N)
  (princ " ")
)

(defun deg2rad (degrees)
  (* degrees (/ pi 180))
)


(defun C:longlat ()
  (LatLongToEastNorth 51.500622 -0.12685776)
  (princ)
)

 

 

its returning kinda accurate but not accurate enough, the above code would return: 529460, 179679  but what i should actually be getting is 530113, 179628 (i used grid reference finder to get these converted)

I'm not sure if it could be lisp itself, because I''ve seen different code (js, C & Java) produce different results from its math library

I understand there are different 3rd party applications to convert this but I'm trying to create my own script to give me more flexibility with it, and move away for the API I'm currently using

  • Like 1
Posted

You reference tan function, for anyone following add this in:

 

(defun Tan( x / )
  (/ (sin x) (cos x))
)

 

 

 

Kind of accurate, it doesn't look like a consistent shift (like add 1 to every reference), could be something like rounding causing a shift, for example a, 6377563.396, might need to be accurate to 5 decimal places (that was just a guess - I don't know)

Posted

I've added that into it but it doesn't change much, ive tested a few different co-ords and pinned them onto grid reference. it seems that the more right of the UK i go my converter bringing it more NW (red is from grid reference, green is from my converter)
London 
image.png.a77cb819a6239833bba71bf37727ea79.png

 

portsmouth

image.png.b7f0571c2e139b6d069b0e45662c58e2.png

 

Dorset
image.png.c75499c4087aa629cd1cf1b9f0617a59.png

 

not sure if this is down to a wrong constants 

Posted

That's what I am thinking too - the further you go the larger the error is. I am assuming you are using UK NG constants?

 

I'll try to dig out what I looked at before and compare the values. I couldn't get it to work then, something in my maths I think, then the Boss wanted me to do stuff so it never got finished - what I was doing was just for interest rather than work, taking data of GPS watch to plot onto a map

Posted

im using WGS84 constants i believe (https://www.jpz.se/Html_filer/wgs_84.html),

ive tried OSGB ones but the values change very little but still the same issue with it overdoing the result

i had a working java code ill try find when i get home which didnt work in javascript.

yeah im looking to do the same thing, messing around with converting  KML files into bricscad for convenience aswell as a few otherthings

  • Like 1
Posted

This is going to be my most favourite code note ever!

 

";; This math is hideous in Lisp, but also pretty ugly in other languages.
;; I'm not going to pretend to understand exactly what's going on here."

Posted

got a job and half converting that from common lisp to autolisp, cheers ill have a look

  • Like 1
Posted

The maths is horrible and depends on where you are in the world as some of the values change, using an external program may be easiest if you can write to a file then read that file back in using lisp. I had something and allowed processing a list of lat longs and exporting the result also N&E to Lat long. It was like available at the Survey Generals Department. Have not used it for years dont have a copy.

Posted

slowly giving up with making my own lisp, struggling to get it to be accurate enough to use. think using an API might be my best bet and sacrifice the speed

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...