pj_datum_set.c
6.07 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/******************************************************************************
* $Id: pj_datum_set.c,v 1.4 2007/11/29 21:06:50 fwarmerdam Exp $
*
* Project: PROJ.4
* Purpose: Apply datum definition to PJ structure from initialization string.
* Author: Frank Warmerdam, warmerda@home.com
*
******************************************************************************
* Copyright (c) 2000, Frank Warmerdam
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
******************************************************************************
*
* $Log: pj_datum_set.c,v $
* Revision 1.4 2007/11/29 21:06:50 fwarmerdam
* make sure we only look for 7 parameters
*
* Revision 1.3 2007/01/31 06:41:01 fwarmerdam
* dont parse more datum parameters than we have room for in datum_params[]
*
* Revision 1.2 2001/04/04 21:13:21 warmerda
* do arcsecond/radian and ppm datum parm transformation in pj_set_datum()
*
* Revision 1.1 2000/07/06 23:32:27 warmerda
* New
*
*/
#include "projects.h"
#include <string.h>
/* SEC_TO_RAD = Pi/180/3600 */
#define SEC_TO_RAD 4.84813681109535993589914102357e-6
/************************************************************************/
/* pj_datum_set() */
/************************************************************************/
int pj_datum_set(paralist *pl, PJ *projdef)
{
const char *name, *towgs84;
projdef->datum_type = PJD_UNKNOWN;
/* -------------------------------------------------------------------- */
/* Is there a datum definition in the parameters list? If so, */
/* add the defining values to the parameter list. Note that */
/* this will append the ellipse definition as well as the */
/* towgs84= and related parameters. It should also be pointed */
/* out that the addition is permanent rather than temporary */
/* like most other keyword expansion so that the ellipse */
/* definition will last into the pj_ell_set() function called */
/* after this one. */
/* -------------------------------------------------------------------- */
name = pj_param(pl,"sdatum").s;
if( name != NULL )
{
paralist *curr;
const char *s;
int i;
/* find the end of the list, so we can add to it */
for (curr = pl; curr && curr->next ; curr = curr->next) {}
/* find the datum definition */
for (i = 0; (s = pj_datums[i].id) && strcmp(name, s) ; ++i) {}
if (!s) { pj_errno = -9; return 1; }
if( pj_datums[i].ellipse_id && strlen(pj_datums[i].ellipse_id) > 0 )
{
char entry[100];
strcpy( entry, "ellps=" );
strncat( entry, pj_datums[i].ellipse_id, 80 );
if (curr)
{
curr->next = pj_mkparam(entry);
curr = curr->next;
}
}
if( pj_datums[i].defn && strlen(pj_datums[i].defn) > 0 )
{
if (curr)
curr->next = pj_mkparam(pj_datums[i].defn);
}
}
/* -------------------------------------------------------------------- */
/* Check for nadgrids parameter. */
/* -------------------------------------------------------------------- */
if( pj_param(pl,"snadgrids").s != NULL )
{
/* We don't actually save the value separately. It will continue
to exist int he param list for use in pj_apply_gridshift.c */
projdef->datum_type = PJD_GRIDSHIFT;
}
/* -------------------------------------------------------------------- */
/* Check for towgs84 parameter. */
/* -------------------------------------------------------------------- */
else if( (towgs84 = pj_param(pl,"stowgs84").s) != NULL )
{
int parm_count = 0;
const char *s;
memset( projdef->datum_params, 0, sizeof(double) * 7);
/* parse out the parameters */
for( s = towgs84; *s != '\0' && parm_count < 7; )
{
projdef->datum_params[parm_count++] = atof(s);
while( *s != '\0' && *s != ',' )
s++;
if( *s == ',' )
s++;
}
if( projdef->datum_params[3] != 0.0
|| projdef->datum_params[4] != 0.0
|| projdef->datum_params[5] != 0.0
|| projdef->datum_params[6] != 0.0 )
{
projdef->datum_type = PJD_7PARAM;
/* transform from arc seconds to radians */
projdef->datum_params[3] *= SEC_TO_RAD;
projdef->datum_params[4] *= SEC_TO_RAD;
projdef->datum_params[5] *= SEC_TO_RAD;
/* transform from parts per million to scaling factor */
projdef->datum_params[6] =
(projdef->datum_params[6]/1000000.0) + 1;
}
else
projdef->datum_type = PJD_3PARAM;
/* Note that pj_init() will later switch datum_type to
PJD_WGS84 if shifts are all zero, and ellipsoid is WGS84 or GRS80 */
}
return 0;
}