Author Topic: EPSG4326->EPSG3857 Formula  (Read 1908 times)

0 Members and 1 Guest are viewing this topic.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
EPSG4326->EPSG3857 Formula
« on: November 21, 2019, 09:07:55 PM »
Ok I'm stumped,

Trying to convert a formula from "C" to lisp.  The formula converts coordinates in Google EPSG4326 (WGS 84) to NOAA Data Viewer coordinates EPSG3857 (WGS 84).

The resultant points will be used to define an AOI (Area Of Interest) window.  So they can be a "little off".

Below is what I've got so far, the 2nd to last line is the culprit, I know nothing about "C" programing.

Any assistance in getting this line right would be great.

Code - Auto/Visual Lisp: [Select]
  1.  (defun EPSG4326->EPSG3857  ( vertex / smRadius smRange smLonToX smRadiansOverDegrees  vertex1  vertex2 y tan)
  2.  
  3.     (defun tan (x) (if (equal (cos x) 0.0 1.0e-16) (if (minusp x) -1.0e200 1.0e200) (/ (sin x) (cos x))))
  4.  
  5.     (setq
  6.       smRadius  6378136.98
  7.       smRange  (* smRadius  pi     2.0)
  8.       smLonToX (/ smRange        360.0)
  9.       smRadiansOverDegrees (/ pi 180.0)
  10.       vertex1  (*(car  vertex) smLonToX)
  11.       y          (cadr vertex)
  12.     )
  13.     (cond
  14.       ((> y  86.0)
  15.         (setq vertex2  smRange)
  16.       )
  17.       ((< y  -86.0)
  18.         (setq vertex2  -smRange)
  19.       )
  20.       (T
  21.         (setq
  22.           y (* y  smRadiansOverDegrees)
  23.           y (log  (+ (tan y) (/ 1.0 (cos y))))
  24.           vertex2 (* y  smRadius)
  25.         )
  26.       )
  27.     )
  28.     (list vertex1 vertex2)
  29.   );defun
  30.  

"C" Code -     y = Math.Log(Math.Tan(y) + (1.0 / Math.Cos(y)), Math.E);

This  (setq test  (EPSG4326->EPSG3857 (list -72.5 42.6)))

Should return this - (-8070663.08251234 5251284.60483522)

edit - This is now solved, posted code works fine.....

Thanks,

Bruce


« Last Edit: November 22, 2019, 07:33:28 AM by snownut2 »

dgpuertas

  • Newt
  • Posts: 80
Re: EPSG4326->EPSG3857 Formula
« Reply #1 on: November 22, 2019, 04:20:08 AM »

Mayby change

Code: [Select]
(log  (+ (vle-tan y) (/ 1.0 (cos y))(exp 1)))
to

Code: [Select]
(log  (+ (tan y) (/ 1.0 (cos y))(exp 1)))

And define:

Code: [Select]
(defun tan (x / co)
(if (zerop (setq co (cos x)))
   1.79e308  ;Infinit
(/ (sin x) co)))

Dlanor

  • Bull Frog
  • Posts: 263
Re: EPSG4326->EPSG3857 Formula
« Reply #2 on: November 22, 2019, 06:34:32 AM »
Code - Auto/Visual Lisp: [Select]
  1. (setq y (log  (+ (tan y) (/ 1.0 (cos y))))
  2. ;where
  3. (defun tan (x) (if (equal (cos x) 0.0 1.0e-16) (if (minusp x) -1.0e200 1.0e200) (/ (sin x) (cos x))))
  4.  

my "C" is very rusty, not used it for +20 years, but log in autolisp deals with natural logs and I don't  think you need the (exp 1) which as the memory dims is the base for the Math.Log

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: EPSG4326->EPSG3857 Formula
« Reply #3 on: November 22, 2019, 07:29:25 AM »
Thanks,

Dlanor that works perfectly, BricsCad has the vle-tan function so there is no need on my end to construct a tan function.

I will post it in the original code so it is useable for ACAD user. 

This transformation function will allow users to call the NOAA Data Access Viewer site and open at their AOI window. 

I am using it to assist the users in locating LIDAR data for later use.

Bruce

Dlanor

  • Bull Frog
  • Posts: 263
Re: EPSG4326->EPSG3857 Formula
« Reply #4 on: November 22, 2019, 09:35:57 AM »
No problem