forked from JoshDullen/nproj4
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pj_inv3d.cs
52 lines (44 loc) · 1.29 KB
/
pj_inv3d.cs
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
using System;
using Free.Ports.Proj4.LibcStuff;
namespace Free.Ports.Proj4
{
public static partial class Proj
{
// general inverse projection
// inverse projection entry
public static LPZ pj_inv3d(XYZ xyz, PJ P)
{
LPZ lpz;
// can't do as much preliminary checking as with forward
if (xyz.x == Libc.HUGE_VAL || xyz.y == Libc.HUGE_VAL || xyz.z == Libc.HUGE_VAL)
{
lpz.lam = lpz.phi = lpz.z = Libc.HUGE_VAL;
pj_ctx_set_errno(P.ctx, -15);
return lpz;
}
Libc.errno = pj_errno = 0;
P.ctx.last_errno = 0;
xyz.x = (xyz.x * P.to_meter - P.x0) * P.ra; // descale and de-offset
xyz.y = (xyz.y * P.to_meter - P.y0) * P.ra;
// z is not scaled since that is handled by vto_meter before we get here
// Check for NULL pointer
if (P.inv3d != null)
{
lpz = P.inv3d(xyz); // inverse project
if (P.ctx.last_errno != 0) lpz.lam = lpz.phi = lpz.z = Libc.HUGE_VAL;
else
{
lpz.lam += P.lam0; // reduce from del lp.lam
if (!P.over) lpz.lam = adjlon(lpz.lam); // adjust longitude to CM
// This maybe redundant and never used
if (P.geoc && Math.Abs(Math.Abs(lpz.phi) - HALFPI) > EPS12) lpz.phi = Math.Atan(P.one_es * Math.Tan(lpz.phi));
}
}
else
{
lpz.lam = lpz.phi = lpz.z = Libc.HUGE_VAL;
}
return lpz;
}
}
}