Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-proj4 / src / pj_datum_set.c @ 21615

History | View | Annotate | Download (5.79 KB)

1
/******************************************************************************
2
 * $Id: pj_datum_set.c,v 1.2 2001/04/04 21:13:21 warmerda Exp $
3
 *
4
 * Project:  PROJ.4
5
 * Purpose:  Apply datum definition to PJ structure from initialization string.
6
 * Author:   Frank Warmerdam, warmerda@home.com
7
 *
8
 ******************************************************************************
9
 * Copyright (c) 2000, Frank Warmerdam
10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a
12
 * copy of this software and associated documentation files (the "Software"),
13
 * to deal in the Software without restriction, including without limitation
14
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
 * and/or sell copies of the Software, and to permit persons to whom the
16
 * Software is furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included
19
 * in all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
 * DEALINGS IN THE SOFTWARE.
28
 ******************************************************************************
29
 *
30
 * $Log: pj_datum_set.c,v $
31
 * Revision 1.2  2001/04/04 21:13:21  warmerda
32
 * do arcsecond/radian and ppm datum parm transformation in pj_set_datum()
33
 *
34
 * Revision 1.1  2000/07/06 23:32:27  warmerda
35
 * New
36
 *
37
 */
38

    
39
#include <projects.h>
40
#include <string.h>
41

    
42
/* SEC_TO_RAD = Pi/180/3600 */
43
#define SEC_TO_RAD 4.84813681109535993589914102357e-6
44

    
45
/************************************************************************/
46
/*                            pj_datum_set()                            */
47
/************************************************************************/
48

    
49
int pj_datum_set(paralist *pl, PJ *projdef)
50

    
51
{
52
    const char *name, *towgs84, *nadgrids;
53

    
54
    projdef->datum_type = PJD_UNKNOWN;
55

    
56
/* -------------------------------------------------------------------- */
57
/*      Is there a datum definition in the parameters list?  If so,     */
58
/*      add the defining values to the parameter list.  Note that       */
59
/*      this will append the ellipse definition as well as the          */
60
/*      towgs84= and related parameters.  It should also be pointed     */
61
/*      out that the addition is permanent rather than temporary        */
62
/*      like most other keyword expansion so that the ellipse           */
63
/*      definition will last into the pj_ell_set() function called      */
64
/*      after this one.                                                 */
65
/* -------------------------------------------------------------------- */
66
    if( (name = pj_param(pl,"sdatum").s) != NULL )
67
    {
68
        paralist *curr;
69
        const char *s;
70
        int i;
71

    
72
        /* find the end of the list, so we can add to it */
73
        for (curr = pl; curr && curr->next ; curr = curr->next) {}
74
        
75
        /* find the datum definition */
76
        for (i = 0; (s = pj_datums[i].id) && strcmp(name, s) ; ++i) {}
77

    
78
        if (!s) { pj_errno = -9; return 1; }
79

    
80
        if( pj_datums[i].ellipse_id && strlen(pj_datums[i].ellipse_id) > 0 )
81
        {
82
            char        entry[100];
83
            
84
            strcpy( entry, "ellps=" );
85
            strncat( entry, pj_datums[i].ellipse_id, 80 );
86
            curr = curr->next = pj_mkparam(entry);
87
        }
88
        
89
        if( pj_datums[i].defn && strlen(pj_datums[i].defn) > 0 )
90
            curr = curr->next = pj_mkparam(pj_datums[i].defn);
91
    }
92

    
93
/* -------------------------------------------------------------------- */
94
/*      Check for nadgrids parameter.                                   */
95
/* -------------------------------------------------------------------- */
96
    if( (nadgrids = pj_param(pl,"snadgrids").s) != NULL )
97
    {
98
        /* We don't actually save the value separately.  It will continue
99
           to exist int he param list for use in pj_apply_gridshift.c */
100

    
101
        projdef->datum_type = PJD_GRIDSHIFT;
102
    }
103

    
104
/* -------------------------------------------------------------------- */
105
/*      Check for towgs84 parameter.                                    */
106
/* -------------------------------------------------------------------- */
107
    else if( (towgs84 = pj_param(pl,"stowgs84").s) != NULL )
108
    {
109
        int    parm_count = 0;
110
        const char *s;
111

    
112
        memset( projdef->datum_params, 0, sizeof(double) * 7);
113

    
114
        /* parse out the parameters */
115
        s = towgs84;
116
        for( s = towgs84; *s != '\0'; ) 
117
        {
118
            projdef->datum_params[parm_count++] = atof(s);
119
            while( *s != '\0' && *s != ',' )
120
                s++;
121
            if( *s == ',' )
122
                s++;
123
        }
124

    
125
        if( projdef->datum_params[3] != 0.0 
126
            || projdef->datum_params[4] != 0.0 
127
            || projdef->datum_params[5] != 0.0 
128
            || projdef->datum_params[6] != 0.0 )
129
        {
130
            projdef->datum_type = PJD_7PARAM;
131

    
132
            /* transform from arc seconds to radians */
133
            projdef->datum_params[3] *= SEC_TO_RAD;
134
            projdef->datum_params[4] *= SEC_TO_RAD;
135
            projdef->datum_params[5] *= SEC_TO_RAD;
136
            /* transform from parts per million to scaling factor */
137
            projdef->datum_params[6] = 
138
                (projdef->datum_params[6]/1000000.0) + 1;
139
        }
140
        else 
141
            projdef->datum_type = PJD_3PARAM;
142

    
143
        /* Note that pj_init() will later switch datum_type to 
144
           PJD_WGS84 if shifts are all zero, and ellipsoid is WGS84 or GRS80 */
145
    }
146

    
147
    return 0;
148
}