Author Topic: google earth terrain import lisp ?  (Read 13408 times)

0 Members and 1 Guest are viewing this topic.

ymg

  • Guest
Re: google earth terrain import lisp ?
« Reply #15 on: January 05, 2015, 05:54:55 PM »
Allenjt,

Still works but partially, the particular method "GetPointOnTerrainFromScreenCoords"
we were speaking about does not.

It seems Google is letting go GE more and more.  Does not look good for
the future.  :-(

ymg

danallen

  • Guest
Re: google earth terrain import lisp ?
« Reply #16 on: January 05, 2015, 06:38:13 PM »
maybe Trimble will buy it like they did sketchup...

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: google earth terrain import lisp ?
« Reply #17 on: January 05, 2015, 08:30:02 PM »
Allenjt,

Still works but partially, the particular method "GetPointOnTerrainFromScreenCoords"
we were speaking about does not.

It seems Google is letting go GE more and more.  Does not look good for
the future.  :-(

ymg
I also must disagree with you. I use that very function with my current version.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ymg

  • Guest
Re: google earth terrain import lisp ?
« Reply #18 on: January 06, 2015, 09:27:57 AM »
allenjt,

I will verify with the latest version,  because I've stopped updating
when the first version 7 came out and reverted to v. 6

So maybe it was for only one version or a bug.

Google has also erase most of the documentation pertaining to the API.
However I could find it on the Wayback machine.

Thanks,

ymg

« Last Edit: January 06, 2015, 09:31:07 AM by ymg »

ymg

  • Guest
Re: google earth terrain import lisp ?
« Reply #19 on: January 06, 2015, 03:45:02 PM »
alanjt,

I verified by installing the latest GE
and running Vovka's "getzfrompoints".

Sorry to report that it no longer works
as I stated before.

Quote
$ (getzfrompoint 40 -62); With version 6.5 Result OK !
-5182.4
_$ (getzfrompoint 40 -62);With Latest version Result Wrong !
-1.41623e-009

ymg

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: google earth terrain import lisp ?
« Reply #20 on: January 06, 2015, 03:51:52 PM »
Execute it again after google earth has completely loaded.

Code: [Select]
Command: (getzfrompoint 40 -62)
-1.41623e-009

Command: (getzfrompoint 40 -62)
-5182.12
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ymg

  • Guest
Re: google earth terrain import lisp ?
« Reply #21 on: January 06, 2015, 04:20:11 PM »
alanjt,

Did try your suggestion and it does work.

However seems to be related to the first call
not functionning even if GE is completely loaded.
Further test seems to be that the first call for a given
Long, Lat returns a wrong results.

Second call result is OK

If so this is easy enough to work around,
although we probably are limited to 2500 pts
instead of 5000

ymg
« Last Edit: January 06, 2015, 04:31:56 PM by ymg »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: google earth terrain import lisp ?
« Reply #22 on: January 06, 2015, 04:49:26 PM »
alanjt,

Did try your suggestion and it does work.

However seems to be related to the first call
not functionning even if GE is completely loaded.
Further test seems to be that the first call for a given
Long, Lat returns a wrong results.

Second call result is OK

If so this is easy enough to work around,
although we probably are limited to 2500 pts
instead of 5000

ymg
I would think it would just be 1- for each session of autocad the command was executed.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ymg

  • Guest
Re: google earth terrain import lisp ?
« Reply #23 on: January 06, 2015, 06:04:46 PM »
alanjt,

Here a small test:

Code: [Select]
(defun test (/ long lat)
   (setq long -79.0
lat  49.11
   )  
   (repeat 10
     (print (getzfrompoint long lat))
     (print (getzfrompoint long lat))
     (print)
     (setq long (- long 0.1))
   )
 )


Quote
_1$ (test)

0.0
330.824

313.22
313.219

-7.08115e-010
296.83

-1.41623e-009
318.393

-7.08115e-010
334.706

-7.08115e-010
315.692

-2.12435e-009
313.809

308.181
315.999

-7.08115e-010
338.803

312.755
312.755
-80.0
_1$

ymg

ymg

  • Guest
Re: google earth terrain import lisp ?
« Reply #24 on: January 06, 2015, 08:02:11 PM »
alanjt,

Some more testing, and it turns out that we have to wait
for the (vlax-invoke-method  keyhole 'setViewParams lat lon 1000   0 0 5 5)
to settle down, and then do the (vlax-invoke keyhole 'GetPointOnTerrainFromScreenCoords 0 0)

I did it with a dummy counting loop up to 30000 and now I get repeating values.
Code: [Select]
(repeat 30000 (setq dummy nil))
Will look into the api documentation if there is a way to insure
that the view has settle down.

ymg

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: google earth terrain import lisp ?
« Reply #25 on: January 06, 2015, 11:46:58 PM »
Wow. That's really temperamental. Are you running the delay with repeat after each call to the keyhole, before getting the screen coord?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ymg

  • Guest
Re: google earth terrain import lisp ?
« Reply #26 on: January 07, 2015, 12:42:58 AM »
alanjt,

Here I've modified Vovka's routine and seem to get reliable results.
Note that there is no need to create the keyhole object.

Code - Auto/Visual Lisp: [Select]
  1. (defun getzfrompoint (lat long /  GE z)
  2.   (if (setq GE  (vlax-get-or-create-object "GoogleEarth.ApplicationGE"))
  3.     (progn
  4.       (while (/= 1 (vlax-invoke-method GE 'isinitialized)))
  5.       (while (/= 1 (vlax-invoke-method GE 'isonline)))
  6.     )
  7.   )
  8.  
  9.   (vlax-invoke-method GE 'SetCameraParams lat long 5000 2 5000 0 0 5)
  10.  
  11.   (repeat 50000 (setq dummy nil)); Works OK but will need to be adjusted depending on your system
  12.  
  13.   (setq z (vlax-get-property (vlax-invoke GE 'GetPointOnTerrainFromScreenCoords 0 0) 'Altitude))
  14.   z
  15. )
  16.  

I tried with waiting on streaming percentage to reach 100%, it did not work.
Code: [Select]
(while (not (= (vlax-get-property GE 'StreamingProgressPercentage) 100)))
Also tried the following based on getting the camera position, didn't work either:
Code: [Select]
(setq cam (vlax-invoke-method GE 'GetCamera t))
    (while (not (and (equal (vlax-get-property cam 'FocusPointLatitude) lat fuzz)(equal (vlax-get-property cam 'FocusPointLongitude) long fuzz)))
     (setq cam (vlax-invoke-method GE 'GetCamera t))
) ;Does not work reliably !!!

ymg
« Last Edit: January 07, 2015, 01:10:45 AM by ymg »

pedroantonio123

  • Guest
Re: google earth terrain import lisp ?
« Reply #27 on: January 22, 2015, 04:26:20 AM »
Hi YMG

Your code works perfectly.   :-)
Now it was just a routine need the Google Earth restart.
Once 2500 points have been read.
I have noticed that it is very slow then.
Normal reaction 0.0000000186, 0.0000020303 Busy
(getvar "CDATE")

Is it possible with a Lisp killprocess googleearth.exe
« Last Edit: January 22, 2015, 04:43:37 AM by pedroantonio123 »

ymg

  • Guest
Re: google earth terrain import lisp ?
« Reply #28 on: January 22, 2015, 08:03:25 AM »
Pedro,

Quote
Your code works perfectly

I still believe that it is a Dead-End, with all the restrictions and the speed of transfer.

As stated before, downloading hgt files for your area of interest would be a better way.

Here is a bit of code, based on Michael Puckett's Readstream to read an elevation
from an hgt file given the latitude and longitude. 

Bear in mind that this has not been thorougly tested,
and that for getting thousands of points it would be better to open the file only once.

Code - Auto/Visual Lisp: [Select]
  1. ;;  getHGT   by ymg                                                           ;
  2. ;;                                                                            ;
  3. ;;  Built on ReadStream by Michael Puckett                                    ;
  4. ;;  http://www.theswamp.org/index.php?topic=17465.0                           ;
  5. ;;                                                                            ;
  6. ;;  Reads a Single Elevation from an HGT file.                                ;
  7. ;;                                                                            ;
  8. ;;  Arguments:                                                                ;
  9. ;;                                                                            ;
  10. ;;      lat   Latitude, in Decimal Degrees.                                   ;
  11. ;;      lon   Longitude, in Decimal Degrees.                                  ;
  12. ;;                                                                            ;
  13. ;;  Returns:                                                                  ;
  14. ;;                                                                            ;
  15. ;;      Elevation as a Signed Short Integer [-32768..32767]                   ;
  16. ;;                                                                            ;
  17. ;;  Notes:                                                                    ;
  18. ;;                                                                            ;
  19. ;;      HGT files are assumed to be in dir "C:\\HGT\\",                       ;
  20. ;;      otherwise you will have to change it in code below.                   ;
  21. ;;                                                                            ;
  22. ;;      Works with 1" or 3" hgt files.                                        ;
  23. ;;                                                                            ;
  24.  
  25. (defun getHGT (lat lon / fso file stream rtn)
  26.     (vl-catch-all-apply
  27.        '(lambda (/ row col path size crw pos msb lsb)
  28.             (setq
  29.                 path     (strcat
  30.                               "C:\\HGT\\"
  31.                               (if (minusp lat) "S" "N")
  32.                               (if (< (abs lat) 10) "0" "")
  33.                               (itoa (abs (floor lat)))
  34.                               (if (minusp lon) "W" "E")
  35.                               (if (< (abs lon) 10) "0" "")
  36.                               (if (< (abs lon) 100) "0" "")
  37.                               (itoa (abs (floor lon)))
  38.                               ".hgt"
  39.                          )
  40.                 fso      (vlax-create-object "Scripting.FileSystemObject")
  41.                 file     (vlax-invoke fso 'GetFile path)
  42.                 stream   (vlax-invoke fso 'OpenTextFile path 1 0)      ;1 = Read, 0 = ASCII                
  43.                 size     (vlax-get file 'Size)
  44.                 crw      (fix (sqrt (/ size 2)))                       ; Number of columns or rows in file.
  45.                 row      (round (* (frac lat) crw))
  46.                 col      (round (* (frac lon) crw))
  47.                 pos      (* 2 (+ (* (1- row) crw) col))
  48.                 ***      (if (plusp pos) (vlax-invoke stream 'skip (- pos 2)))  ; Always returns nil        
  49.                 msb      (ascii (vlax-invoke stream 'read 1))                   ; hgt file are "Big Endian"
  50.                 lsb      (ascii (vlax-invoke stream 'read 1))
  51.                 rtn      (if (> (setq rtn (+ (* msb 256) lsb)) 32767) (- rtn 65536) rtn)
  52.             )
  53.             (vlax-invoke stream 'Close)
  54.         )
  55.     )
  56.    
  57.     (if stream (vlax-release-object stream))
  58.     (if file (vlax-release-object file))
  59.     (if fso (vlax-release-object fso))
  60.    
  61.     rtn
  62. )
  63.  
  64. (defun round (x) (floor (+ x 0.5))) ; Round to Nearest Integer              
  65. (defun frac  (x) (- x (floor x)))   ; (Graham, Knuth & Patashnik definition)
  66. (defun floor (x) (if (minusp (rem x 1)) (- (fix x) 1) (fix x)))
  67.  
  68.  

ymg
« Last Edit: January 22, 2015, 08:39:59 AM by ymg »