pj_apply_gridshift.cpp

来自「projapi是一个关于GIS行业投影转换的程序库」· C++ 代码 · 共 107 行

CPP
107
字号

#include "stdafx.h"
#define PJ_LIB__#include "projects.h"#include <string.h>#include <math.h>/************************************************************************//*                         pj_apply_gridshift()                         *//************************************************************************/int pj_apply_gridshift( const char *nadgrids, int inverse,                         long point_count, int point_offset,                        double *x, double *y, double *z ){    int grid_count = 0;    PJ_GRIDINFO   **tables;    int  i;    static int debug_count = 0;    pj_errno = 0;    tables = pj_gridlist_from_nadgrids( nadgrids, &grid_count);    if( tables == NULL || grid_count == 0 )        return pj_errno;    for( i = 0; i < point_count; i++ )    {        long io = i * point_offset;        LP   input, output;        int  itable;        input.phi = y[io];        input.lam = x[io];        output.phi = HUGE_VAL;        output.lam = HUGE_VAL;        /* keep trying till we find a table that works */        for( itable = 0; itable < grid_count; itable++ )        {            PJ_GRIDINFO *gi = tables[itable];            struct CTABLE *ct = gi->ct;            /* skip tables that don't match our point at all.  */            if( ct->ll.phi > input.phi || ct->ll.lam > input.lam                || ct->ll.phi + (ct->lim.phi-1) * ct->del.phi < input.phi                || ct->ll.lam + (ct->lim.lam-1) * ct->del.lam < input.lam )                continue;            /* If we have child nodes, check to see if any of them apply. */            if( gi->child != NULL )            {                PJ_GRIDINFO *child;                for( child = gi->child; child != NULL; child = child->next )                {                    struct CTABLE *ct1 = child->ct;                    if( ct1->ll.phi > input.phi || ct1->ll.lam > input.lam                      || ct1->ll.phi+(ct1->lim.phi-1)*ct1->del.phi < input.phi                      || ct1->ll.lam+(ct1->lim.lam-1)*ct1->del.lam < input.lam)                        continue;                    break;                }                /* we found a more refined child node to use */                if( child != NULL )                {                    gi = child;                    ct = child->ct;                }            }            /* load the grid shift info if we don't have it. */            if( ct->cvs == NULL && !pj_gridinfo_load( gi ) )            {                pj_errno = -38;                return pj_errno;            }                        output = nad_cvt( input, inverse, ct );            if( output.lam != HUGE_VAL )            {                break;            }        }        if( output.lam == HUGE_VAL )        {            pj_errno = -38;            return pj_errno;        }        else        {            y[io] = output.phi;            x[io] = output.lam;        }    }    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?