📄 proj_api.cpp
字号:
// proj_api.cpp: implementation of the proj_api class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#define PJ_LIB__
#include "projects.h"
#ifndef UNICODE
#include <errno.h>
#endif
#include <math.h>
////////////////////////////////////////////////////////////////////
#define EPS 1.0e-12
C_NAMESPACE int pj_errno = 0;
///////////////////////////////////////////////////////////////////
int *pj_get_errno_ref()
{
return &pj_errno;
}
/* forward projection entry */
XY pj_fwd(LP lp, PJ *P)
{
XY xy;
double t;
/* check for forward and latitude or longitude overange */
if ((t = fabs(lp.phi)-HALFPI) > EPS || fabs(lp.lam) > 10.)
{
xy.x = xy.y = HUGE_VAL;
pj_errno = -14;
}
else /* proceed with projection */
{
errno = pj_errno = 0;
if (fabs(t) <= EPS)
lp.phi = lp.phi < 0. ? -HALFPI : HALFPI;
else if (P->geoc)
lp.phi = atan(P->rone_es * tan(lp.phi));
lp.lam -= P->lam0; /* compute del lp.lam */
if (!P->over)
lp.lam = adjlon(lp.lam); /* adjust del longitude */
xy = (*P->fwd)(lp, P); /* project */
if (pj_errno || (pj_errno = errno))
xy.x = xy.y = HUGE_VAL;
/* adjust for major axis and easting/northings */
else
{
xy.x = P->fr_meter * (P->a * xy.x + P->x0);
xy.y = P->fr_meter * (P->a * xy.y + P->y0);
}
}
return xy;
}
/* inverse projection entry */
LP pj_inv(XY xy, PJ *P)
{
LP lp;
/* can't do as much preliminary checking as with forward */
if (xy.x == HUGE_VAL || xy.y == HUGE_VAL)
{
lp.lam = lp.phi = HUGE_VAL;
pj_errno = -15;
}
errno = pj_errno = 0;
xy.x = (xy.x * P->to_meter - P->x0) * P->ra; /* descale and de-offset */
xy.y = (xy.y * P->to_meter - P->y0) * P->ra;
lp = (*P->inv)(xy, P); /* inverse project */
if (pj_errno || (pj_errno = errno))
lp.lam = lp.phi = HUGE_VAL;
else
{
lp.lam += P->lam0; /* reduce from del lp.lam */
if (!P->over)
lp.lam = adjlon(lp.lam); /* adjust longitude to CM */
if (P->geoc && fabs(fabs(lp.phi)-HALFPI) > EPS)
lp.phi = atan(P->one_es * tan(lp.phi));
}
return lp;
}
void * pj_malloc(size_t size)
{
return(malloc(size));
}
void pj_dalloc(void *ptr)
{
free(ptr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -