blob: c6052ad4b37286f29defe127b31349e12be960a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
47
48
49
50
51
52
53
54
55
56
57
|
#define PJ_LIB__
#include <projects.h>
#include <errno.h>
# define EPS 1.0e-12
/* 3D inverse transformation */
LPZ pj_inv3d (XYZ xyz, PJ *P) {
LPZ lpz;
LPZ err;
/* cannot const-initialize this due to MSVC's broken (non const) HUGE_VAL */
err.lam = err.phi = err.z = HUGE_VAL;
if (0==P->inv3d)
return err;
/* can't do as much preliminary checking as with forward */
if (xyz.x == HUGE_VAL || xyz.y == HUGE_VAL || xyz.z == HUGE_VAL ) {
pj_ctx_set_errno( P->ctx, -15);
return err;
}
P->ctx->last_errno = errno = pj_errno = 0;
/* de-scale and de-offset */
/* z is not de-scaled since that is handled by vto_meter before we get here */
xyz.x = (xyz.x * P->to_meter - P->x0);
xyz.y = (xyz.y * P->to_meter - P->y0);
/* Classic proj.4 functions expect plane coordinates in units of the semimajor axis */
/* Multiplying by ra, rather than dividing by a because the CALCOFI projection */
/* stomps on a and hence depends on this */
if (P->right==PJ_IO_UNITS_CLASSIC) {
xyz.x *= P->ra;
xyz.y *= P->ra;
}
/* Do inverse transformation */
lpz = (*P->inv3d) (xyz, P);
if (P->ctx->last_errno)
return err;
if ((P->left==PJ_IO_UNITS_CLASSIC)||(P->left==PJ_IO_UNITS_RADIANS)) {
/* reduce from del lp.lam */
lpz.lam += P->lam0;
/* adjust longitude to central meridian */
if (!P->over)
lpz.lam = adjlon(lpz.lam);
/* This may be redundant and never used */
if (P->geoc && fabs(fabs(lpz.phi)-M_HALFPI) > EPS)
lpz.phi = atan(P->one_es * tan(lpz.phi));
}
return lpz;
}
|