pj_utils.c
6.36 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/******************************************************************************
* $Id: pj_utils.c,v 1.5 2007/03/12 14:05:35 fwarmerdam Exp $
*
* Project: PROJ.4
* Purpose: Some utility functions we don't want to bother putting in
* their own source files.
* Author: Frank Warmerdam, warmerdam@pobox.com
*
******************************************************************************
* Copyright (c) 2001, 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_utils.c,v $
* Revision 1.5 2007/03/12 14:05:35 fwarmerdam
* Removed duplicate towgs84 definition code.
*
* Revision 1.4 2005/07/06 14:04:09 fwarmerdam
* Improved precision of es encoding for pj_latlong_from_proj() per:
* http://bugzilla.remotesensing.org/show_bug.cgi?id=881
*
* Revision 1.3 2002/12/14 20:14:00 warmerda
* added pj_is_geocent, added +pm support to pj_get_def
*
* Revision 1.2 2002/04/30 17:01:51 warmerda
* Removed printf() statement.
*
* Revision 1.1 2001/04/05 04:22:46 warmerda
* New
*
*/
#define PJ_LIB__
#include "projects.h"
#include <string.h>
#include <math.h>
/************************************************************************/
/* pj_is_latlong() */
/* */
/* Returns TRUE if this coordinate system object is */
/* geographic. */
/************************************************************************/
int pj_is_latlong( PJ *pj )
{
return pj == NULL || pj->is_latlong;
}
/************************************************************************/
/* pj_is_geocent() */
/* */
/* Returns TRUE if this coordinate system object is geocentric. */
/************************************************************************/
int pj_is_geocent( PJ *pj )
{
return pj != NULL && pj->is_geocent;
}
/************************************************************************/
/* pj_latlong_from_proj() */
/* */
/* Return a PJ* definition defining the lat/long coordinate */
/* system on which a projection is based. If the coordinate */
/* system passed in is latlong, a clone of the same will be */
/* returned. */
/************************************************************************/
PJ *pj_latlong_from_proj( PJ *pj_in )
{
char defn[512];
int got_datum = FALSE;
pj_errno = 0;
strcpy( defn, "+proj=latlong" );
if( pj_param(pj_in->params, "tdatum").i )
{
got_datum = TRUE;
sprintf( defn+strlen(defn), " +datum=%s",
pj_param(pj_in->params,"sdatum").s );
}
else if( pj_param(pj_in->params, "tellps").i )
{
sprintf( defn+strlen(defn), " +ellps=%s",
pj_param(pj_in->params,"sellps").s );
}
else if( pj_param(pj_in->params, "ta").i )
{
sprintf( defn+strlen(defn), " +a=%s",
pj_param(pj_in->params,"sa").s );
if( pj_param(pj_in->params, "tb").i )
sprintf( defn+strlen(defn), " +b=%s",
pj_param(pj_in->params,"sb").s );
else if( pj_param(pj_in->params, "tes").i )
sprintf( defn+strlen(defn), " +es=%s",
pj_param(pj_in->params,"ses").s );
else if( pj_param(pj_in->params, "tf").i )
sprintf( defn+strlen(defn), " +f=%s",
pj_param(pj_in->params,"sf").s );
else
sprintf( defn+strlen(defn), " +es=%.16g",
pj_in->es );
}
else
{
pj_errno = -13;
return NULL;
}
if( !got_datum )
{
if( pj_param(pj_in->params, "ttowgs84").i )
sprintf( defn+strlen(defn), " +towgs84=%s",
pj_param(pj_in->params,"stowgs84").s );
if( pj_param(pj_in->params, "tnadgrids").i )
sprintf( defn+strlen(defn), " +nadgrids=%s",
pj_param(pj_in->params,"snadgrids").s );
}
/* copy over some other information related to ellipsoid */
if( pj_param(pj_in->params, "tR").i )
sprintf( defn+strlen(defn), " +R=%s",
pj_param(pj_in->params,"sR").s );
if( pj_param(pj_in->params, "tR_A").i )
sprintf( defn+strlen(defn), " +R_A" );
if( pj_param(pj_in->params, "tR_V").i )
sprintf( defn+strlen(defn), " +R_V" );
if( pj_param(pj_in->params, "tR_a").i )
sprintf( defn+strlen(defn), " +R_a" );
if( pj_param(pj_in->params, "tR_lat_a").i )
sprintf( defn+strlen(defn), " +R_lat_a=%s",
pj_param(pj_in->params,"sR_lat_a").s );
if( pj_param(pj_in->params, "tR_lat_g").i )
sprintf( defn+strlen(defn), " +R_lat_g=%s",
pj_param(pj_in->params,"sR_lat_g").s );
/* copy over prime meridian */
if( pj_param(pj_in->params, "tpm").i )
sprintf( defn+strlen(defn), " +pm=%s",
pj_param(pj_in->params,"spm").s );
return pj_init_plus( defn );
}