1 : /******************************************************************************
2 : * $Id: geo_extra.c 1568 2009-04-22 21:10:55Z warmerdam $
3 : *
4 : * Project: libgeotiff
5 : * Purpose: Code to normalize a few common PCS values without use of CSV
6 : * files.
7 : * Author: Frank Warmerdam, warmerda@home.com
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 1999, Frank Warmerdam
11 : *
12 : * Permission is hereby granted, free of charge, to any person obtaining a
13 : * copy of this software and associated documentation files (the "Software"),
14 : * to deal in the Software without restriction, including without limitation
15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : * and/or sell copies of the Software, and to permit persons to whom the
17 : * Software is furnished to do so, subject to the following conditions:
18 : *
19 : * The above copyright notice and this permission notice shall be included
20 : * in all copies or substantial portions of the Software.
21 : *
22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 : * DEALINGS IN THE SOFTWARE.
29 : *****************************************************************************/
30 :
31 : /*
32 : #include "geotiff.h"
33 : #include "geo_tiffp.h"
34 : #include "geo_keyp.h"
35 : */
36 :
37 : #include "geo_normalize.h"
38 : #include "geovalues.h"
39 :
40 : static int StatePlaneTable[] =
41 : {
42 : PCS_NAD83_Alabama_East, Proj_Alabama_CS83_East,
43 : PCS_NAD83_Alabama_West, Proj_Alabama_CS83_West,
44 :
45 : PCS_NAD83_Alaska_zone_1, Proj_Alaska_CS83_1,
46 : PCS_NAD83_Alaska_zone_2, Proj_Alaska_CS83_2,
47 : PCS_NAD83_Alaska_zone_3, Proj_Alaska_CS83_3,
48 : PCS_NAD83_Alaska_zone_4, Proj_Alaska_CS83_4,
49 : PCS_NAD83_Alaska_zone_5, Proj_Alaska_CS83_5,
50 : PCS_NAD83_Alaska_zone_6, Proj_Alaska_CS83_6,
51 : PCS_NAD83_Alaska_zone_7, Proj_Alaska_CS83_7,
52 : PCS_NAD83_Alaska_zone_8, Proj_Alaska_CS83_8,
53 : PCS_NAD83_Alaska_zone_9, Proj_Alaska_CS83_9,
54 : PCS_NAD83_Alaska_zone_10, Proj_Alaska_CS83_10,
55 :
56 : PCS_NAD83_California_1, Proj_California_CS83_1,
57 : PCS_NAD83_California_2, Proj_California_CS83_2,
58 : PCS_NAD83_California_3, Proj_California_CS83_3,
59 : PCS_NAD83_California_4, Proj_California_CS83_4,
60 : PCS_NAD83_California_5, Proj_California_CS83_5,
61 : PCS_NAD83_California_6, Proj_California_CS83_6,
62 :
63 : PCS_NAD83_Arizona_East, Proj_Arizona_CS83_east,
64 : PCS_NAD83_Arizona_Central, Proj_Arizona_CS83_Central,
65 : PCS_NAD83_Arizona_West, Proj_Arizona_CS83_west,
66 :
67 : PCS_NAD83_Arkansas_North, Proj_Arkansas_CS83_North,
68 : PCS_NAD83_Arkansas_South, Proj_Arkansas_CS83_South,
69 :
70 : PCS_NAD83_Colorado_North, Proj_Colorado_CS83_North,
71 : PCS_NAD83_Colorado_Central, Proj_Colorado_CS83_Central,
72 : PCS_NAD83_Colorado_South, Proj_Colorado_CS83_South,
73 :
74 : PCS_NAD83_Connecticut, Proj_Connecticut_CS83,
75 :
76 : PCS_NAD83_Delaware, Proj_Delaware_CS83,
77 :
78 : PCS_NAD83_Florida_East, Proj_Florida_CS83_East,
79 : PCS_NAD83_Florida_North, Proj_Florida_CS83_North,
80 : PCS_NAD83_Florida_West, Proj_Florida_CS83_West,
81 :
82 : PCS_NAD83_Hawaii_zone_1, Proj_Hawaii_CS83_1,
83 : PCS_NAD83_Hawaii_zone_2, Proj_Hawaii_CS83_2,
84 : PCS_NAD83_Hawaii_zone_3, Proj_Hawaii_CS83_3,
85 : PCS_NAD83_Hawaii_zone_4, Proj_Hawaii_CS83_4,
86 : PCS_NAD83_Hawaii_zone_5, Proj_Hawaii_CS83_5,
87 :
88 : PCS_NAD83_Georgia_East, Proj_Georgia_CS83_East,
89 : PCS_NAD83_Georgia_West, Proj_Georgia_CS83_West,
90 :
91 : PCS_NAD83_Idaho_East, Proj_Idaho_CS83_East,
92 : PCS_NAD83_Idaho_Central, Proj_Idaho_CS83_Central,
93 : PCS_NAD83_Idaho_West, Proj_Idaho_CS83_West,
94 :
95 : PCS_NAD83_Illinois_East, Proj_Illinois_CS83_East,
96 : PCS_NAD83_Illinois_West, Proj_Illinois_CS83_West,
97 :
98 : PCS_NAD83_Indiana_East, Proj_Indiana_CS83_East,
99 : PCS_NAD83_Indiana_West, Proj_Indiana_CS83_West,
100 :
101 : PCS_NAD83_Iowa_North, Proj_Iowa_CS83_North,
102 : PCS_NAD83_Iowa_South, Proj_Iowa_CS83_South,
103 :
104 : PCS_NAD83_Kansas_North, Proj_Kansas_CS83_North,
105 : PCS_NAD83_Kansas_South, Proj_Kansas_CS83_South,
106 :
107 : PCS_NAD83_Kentucky_North, Proj_Kentucky_CS83_North,
108 : PCS_NAD83_Kentucky_South, Proj_Kentucky_CS83_South,
109 :
110 : PCS_NAD83_Louisiana_North, Proj_Louisiana_CS83_North,
111 : PCS_NAD83_Louisiana_South, Proj_Louisiana_CS83_South,
112 :
113 : PCS_NAD83_Maine_East, Proj_Maine_CS83_East,
114 : PCS_NAD83_Maine_West, Proj_Maine_CS83_West,
115 :
116 : PCS_NAD83_Maryland, Proj_Maryland_CS83,
117 :
118 : PCS_NAD83_Massachusetts, Proj_Massachusetts_CS83_Mainland,
119 : PCS_NAD83_Massachusetts_Is, Proj_Massachusetts_CS83_Island,
120 :
121 : PCS_NAD83_Michigan_North, Proj_Michigan_CS83_North,
122 : PCS_NAD83_Michigan_Central, Proj_Michigan_CS83_Central,
123 : PCS_NAD83_Michigan_South, Proj_Michigan_CS83_South,
124 :
125 : PCS_NAD83_Minnesota_North, Proj_Minnesota_CS83_North,
126 : PCS_NAD83_Minnesota_Cent, Proj_Minnesota_CS83_Central,
127 : PCS_NAD83_Minnesota_South, Proj_Minnesota_CS83_South,
128 :
129 : PCS_NAD83_Mississippi_East, Proj_Mississippi_CS83_East,
130 : PCS_NAD83_Mississippi_West, Proj_Mississippi_CS83_West,
131 :
132 : PCS_NAD83_Missouri_East, Proj_Missouri_CS83_East,
133 : PCS_NAD83_Missouri_Central, Proj_Missouri_CS83_Central,
134 : PCS_NAD83_Missouri_West, Proj_Missouri_CS83_West,
135 :
136 : PCS_NAD83_Montana, Proj_Montana_CS83,
137 :
138 : PCS_NAD83_Nebraska, Proj_Nebraska_CS83,
139 :
140 : PCS_NAD83_Nevada_East, Proj_Nevada_CS83_East,
141 : PCS_NAD83_Nevada_Central, Proj_Nevada_CS83_Central,
142 : PCS_NAD83_Nevada_West, Proj_Nevada_CS83_West,
143 :
144 : PCS_NAD83_New_Hampshire, Proj_New_Hampshire_CS83,
145 :
146 : PCS_NAD83_New_Jersey, Proj_New_Jersey_CS83,
147 :
148 : PCS_NAD83_New_Mexico_East, Proj_New_Mexico_CS83_East,
149 : PCS_NAD83_New_Mexico_Cent, Proj_New_Mexico_CS83_Central,
150 : PCS_NAD83_New_Mexico_West, Proj_New_Mexico_CS83_West,
151 :
152 : PCS_NAD83_New_York_East, Proj_New_York_CS83_East,
153 : PCS_NAD83_New_York_Central, Proj_New_York_CS83_Central,
154 : PCS_NAD83_New_York_West, Proj_New_York_CS83_West,
155 : PCS_NAD83_New_York_Long_Is, Proj_New_York_CS83_Long_Island,
156 :
157 : PCS_NAD83_North_Carolina, Proj_North_Carolina_CS83,
158 :
159 : PCS_NAD83_North_Dakota_N, Proj_North_Dakota_CS83_North,
160 : PCS_NAD83_North_Dakota_S, Proj_North_Dakota_CS83_South,
161 :
162 : PCS_NAD83_Ohio_North, Proj_Ohio_CS83_North,
163 : PCS_NAD83_Ohio_South, Proj_Ohio_CS83_South,
164 :
165 : PCS_NAD83_Oklahoma_North, Proj_Oklahoma_CS83_North,
166 : PCS_NAD83_Oklahoma_South, Proj_Oklahoma_CS83_South,
167 :
168 : PCS_NAD83_Oregon_North, Proj_Oregon_CS83_North,
169 : PCS_NAD83_Oregon_South, Proj_Oregon_CS83_South,
170 :
171 : PCS_NAD83_Pennsylvania_N, Proj_Pennsylvania_CS83_North,
172 : PCS_NAD83_Pennsylvania_S, Proj_Pennsylvania_CS83_South,
173 :
174 : PCS_NAD83_Rhode_Island, Proj_Rhode_Island_CS83,
175 :
176 : PCS_NAD83_South_Carolina, Proj_South_Carolina_CS83,
177 :
178 : PCS_NAD83_South_Dakota_N, Proj_South_Dakota_CS83_North,
179 : PCS_NAD83_South_Dakota_S, Proj_South_Dakota_CS83_South,
180 :
181 : PCS_NAD83_Tennessee, Proj_Tennessee_CS83,
182 :
183 : PCS_NAD83_Texas_North, Proj_Texas_CS83_North,
184 : PCS_NAD83_Texas_North_Cen, Proj_Texas_CS83_North_Central,
185 : PCS_NAD83_Texas_Central, Proj_Texas_CS83_Central,
186 : PCS_NAD83_Texas_South_Cen, Proj_Texas_CS83_South_Central,
187 : PCS_NAD83_Texas_South, Proj_Texas_CS83_South,
188 :
189 : PCS_NAD83_Utah_North, Proj_Utah_CS83_North,
190 : PCS_NAD83_Utah_Central, Proj_Utah_CS83_Central,
191 : PCS_NAD83_Utah_South, Proj_Utah_CS83_South,
192 :
193 : PCS_NAD83_Vermont, Proj_Vermont_CS83,
194 :
195 : PCS_NAD83_Virginia_North, Proj_Virginia_CS83_North,
196 : PCS_NAD83_Virginia_South, Proj_Virginia_CS83_South,
197 :
198 : PCS_NAD83_Washington_North, Proj_Washington_CS83_North,
199 : PCS_NAD83_Washington_South, Proj_Washington_CS83_South,
200 :
201 : PCS_NAD83_West_Virginia_N, Proj_West_Virginia_CS83_North,
202 : PCS_NAD83_West_Virginia_S, Proj_West_Virginia_CS83_South,
203 :
204 : PCS_NAD83_Wisconsin_North, Proj_Wisconsin_CS83_North,
205 : PCS_NAD83_Wisconsin_Cen, Proj_Wisconsin_CS83_Central,
206 : PCS_NAD83_Wisconsin_South, Proj_Wisconsin_CS83_South,
207 :
208 : PCS_NAD83_Wyoming_East, Proj_Wyoming_CS83_East,
209 : PCS_NAD83_Wyoming_E_Cen, Proj_Wyoming_CS83_East_Central,
210 : PCS_NAD83_Wyoming_W_Cen, Proj_Wyoming_CS83_West_Central,
211 : PCS_NAD83_Wyoming_West, Proj_Wyoming_CS83_West,
212 :
213 : PCS_NAD83_Puerto_Rico_Virgin_Is, Proj_Puerto_Rico_Virgin_Is,
214 :
215 : PCS_NAD27_Alabama_East, Proj_Alabama_CS27_East,
216 : PCS_NAD27_Alabama_West, Proj_Alabama_CS27_West,
217 :
218 : PCS_NAD27_Alaska_zone_1, Proj_Alaska_CS27_1,
219 : PCS_NAD27_Alaska_zone_2, Proj_Alaska_CS27_2,
220 : PCS_NAD27_Alaska_zone_3, Proj_Alaska_CS27_3,
221 : PCS_NAD27_Alaska_zone_4, Proj_Alaska_CS27_4,
222 : PCS_NAD27_Alaska_zone_5, Proj_Alaska_CS27_5,
223 : PCS_NAD27_Alaska_zone_6, Proj_Alaska_CS27_6,
224 : PCS_NAD27_Alaska_zone_7, Proj_Alaska_CS27_7,
225 : PCS_NAD27_Alaska_zone_8, Proj_Alaska_CS27_8,
226 : PCS_NAD27_Alaska_zone_9, Proj_Alaska_CS27_9,
227 : PCS_NAD27_Alaska_zone_10, Proj_Alaska_CS27_10,
228 :
229 : PCS_NAD27_California_I, Proj_California_CS27_I,
230 : PCS_NAD27_California_II, Proj_California_CS27_II,
231 : PCS_NAD27_California_III, Proj_California_CS27_III,
232 : PCS_NAD27_California_IV, Proj_California_CS27_IV,
233 : PCS_NAD27_California_V, Proj_California_CS27_V,
234 : PCS_NAD27_California_VI, Proj_California_CS27_VI,
235 : PCS_NAD27_California_VII, Proj_California_CS27_VII,
236 :
237 : PCS_NAD27_Arizona_East, Proj_Arizona_Coordinate_System_east,
238 : PCS_NAD27_Arizona_Central, Proj_Arizona_Coordinate_System_Central,
239 : PCS_NAD27_Arizona_West, Proj_Arizona_Coordinate_System_west,
240 :
241 : PCS_NAD27_Arkansas_North, Proj_Arkansas_CS27_North,
242 : PCS_NAD27_Arkansas_South, Proj_Arkansas_CS27_South,
243 :
244 : PCS_NAD27_Colorado_North, Proj_Colorado_CS27_North,
245 : PCS_NAD27_Colorado_Central, Proj_Colorado_CS27_Central,
246 : PCS_NAD27_Colorado_South, Proj_Colorado_CS27_South,
247 :
248 : PCS_NAD27_Connecticut, Proj_Connecticut_CS27,
249 :
250 : PCS_NAD27_Delaware, Proj_Delaware_CS27,
251 :
252 : PCS_NAD27_Florida_East, Proj_Florida_CS27_East,
253 : PCS_NAD27_Florida_North, Proj_Florida_CS27_North,
254 : PCS_NAD27_Florida_West, Proj_Florida_CS27_West,
255 :
256 : PCS_NAD27_Hawaii_zone_1, Proj_Hawaii_CS27_1,
257 : PCS_NAD27_Hawaii_zone_2, Proj_Hawaii_CS27_2,
258 : PCS_NAD27_Hawaii_zone_3, Proj_Hawaii_CS27_3,
259 : PCS_NAD27_Hawaii_zone_4, Proj_Hawaii_CS27_4,
260 : PCS_NAD27_Hawaii_zone_5, Proj_Hawaii_CS27_5,
261 :
262 : PCS_NAD27_Georgia_East, Proj_Georgia_CS27_East,
263 : PCS_NAD27_Georgia_West, Proj_Georgia_CS27_West,
264 :
265 : PCS_NAD27_Idaho_East, Proj_Idaho_CS27_East,
266 : PCS_NAD27_Idaho_Central, Proj_Idaho_CS27_Central,
267 : PCS_NAD27_Idaho_West, Proj_Idaho_CS27_West,
268 :
269 : PCS_NAD27_Illinois_East, Proj_Illinois_CS27_East,
270 : PCS_NAD27_Illinois_West, Proj_Illinois_CS27_West,
271 :
272 : PCS_NAD27_Indiana_East, Proj_Indiana_CS27_East,
273 : PCS_NAD27_Indiana_West, Proj_Indiana_CS27_West,
274 :
275 : PCS_NAD27_Iowa_North, Proj_Iowa_CS27_North,
276 : PCS_NAD27_Iowa_South, Proj_Iowa_CS27_South,
277 :
278 : PCS_NAD27_Kansas_North, Proj_Kansas_CS27_North,
279 : PCS_NAD27_Kansas_South, Proj_Kansas_CS27_South,
280 :
281 : PCS_NAD27_Kentucky_North, Proj_Kentucky_CS27_North,
282 : PCS_NAD27_Kentucky_South, Proj_Kentucky_CS27_South,
283 :
284 : PCS_NAD27_Louisiana_North, Proj_Louisiana_CS27_North,
285 : PCS_NAD27_Louisiana_South, Proj_Louisiana_CS27_South,
286 :
287 : PCS_NAD27_Maine_East, Proj_Maine_CS27_East,
288 : PCS_NAD27_Maine_West, Proj_Maine_CS27_West,
289 :
290 : PCS_NAD27_Maryland, Proj_Maryland_CS27,
291 :
292 : PCS_NAD27_Massachusetts, Proj_Massachusetts_CS27_Mainland,
293 : PCS_NAD27_Massachusetts_Is, Proj_Massachusetts_CS27_Island,
294 :
295 : PCS_NAD27_Michigan_North, Proj_Michigan_CS27_North,
296 : PCS_NAD27_Michigan_Central, Proj_Michigan_CS27_Central,
297 : PCS_NAD27_Michigan_South, Proj_Michigan_CS27_South,
298 :
299 : PCS_NAD27_Minnesota_North, Proj_Minnesota_CS27_North,
300 : PCS_NAD27_Minnesota_Cent, Proj_Minnesota_CS27_Central,
301 : PCS_NAD27_Minnesota_South, Proj_Minnesota_CS27_South,
302 :
303 : PCS_NAD27_Mississippi_East, Proj_Mississippi_CS27_East,
304 : PCS_NAD27_Mississippi_West, Proj_Mississippi_CS27_West,
305 :
306 : PCS_NAD27_Missouri_East, Proj_Missouri_CS27_East,
307 : PCS_NAD27_Missouri_Central, Proj_Missouri_CS27_Central,
308 : PCS_NAD27_Missouri_West, Proj_Missouri_CS27_West,
309 :
310 : PCS_NAD27_Montana_North, Proj_Montana_CS27_North,
311 : PCS_NAD27_Montana_Central, Proj_Montana_CS27_Central,
312 : PCS_NAD27_Montana_South, Proj_Montana_CS27_South,
313 :
314 : PCS_NAD27_Nebraska_North, Proj_Nebraska_CS27_North,
315 : PCS_NAD27_Nebraska_South, Proj_Nebraska_CS27_South,
316 :
317 : PCS_NAD27_Nevada_East, Proj_Nevada_CS27_East,
318 : PCS_NAD27_Nevada_Central, Proj_Nevada_CS27_Central,
319 : PCS_NAD27_Nevada_West, Proj_Nevada_CS27_West,
320 :
321 : PCS_NAD27_New_Hampshire, Proj_New_Hampshire_CS27,
322 :
323 : PCS_NAD27_New_Jersey, Proj_New_Jersey_CS27,
324 :
325 : PCS_NAD27_New_Mexico_East, Proj_New_Mexico_CS27_East,
326 : PCS_NAD27_New_Mexico_Cent, Proj_New_Mexico_CS27_Central,
327 : PCS_NAD27_New_Mexico_West, Proj_New_Mexico_CS27_West,
328 :
329 : PCS_NAD27_New_York_East, Proj_New_York_CS27_East,
330 : PCS_NAD27_New_York_Central, Proj_New_York_CS27_Central,
331 : PCS_NAD27_New_York_West, Proj_New_York_CS27_West,
332 : PCS_NAD27_New_York_Long_Is, Proj_New_York_CS27_Long_Island,
333 :
334 : PCS_NAD27_North_Carolina, Proj_North_Carolina_CS27,
335 :
336 : PCS_NAD27_North_Dakota_N, Proj_North_Dakota_CS27_North,
337 : PCS_NAD27_North_Dakota_S, Proj_North_Dakota_CS27_South,
338 :
339 : PCS_NAD27_Ohio_North, Proj_Ohio_CS27_North,
340 : PCS_NAD27_Ohio_South, Proj_Ohio_CS27_South,
341 :
342 : PCS_NAD27_Oklahoma_North, Proj_Oklahoma_CS27_North,
343 : PCS_NAD27_Oklahoma_South, Proj_Oklahoma_CS27_South,
344 :
345 : PCS_NAD27_Oregon_North, Proj_Oregon_CS27_North,
346 : PCS_NAD27_Oregon_South, Proj_Oregon_CS27_South,
347 :
348 : PCS_NAD27_Pennsylvania_N, Proj_Pennsylvania_CS27_North,
349 : PCS_NAD27_Pennsylvania_S, Proj_Pennsylvania_CS27_South,
350 :
351 : PCS_NAD27_Rhode_Island, Proj_Rhode_Island_CS27,
352 :
353 : PCS_NAD27_South_Carolina_N, Proj_South_Carolina_CS27_North,
354 : PCS_NAD27_South_Carolina_S, Proj_South_Carolina_CS27_South,
355 :
356 : PCS_NAD27_South_Dakota_N, Proj_South_Dakota_CS27_North,
357 : PCS_NAD27_South_Dakota_S, Proj_South_Dakota_CS27_South,
358 :
359 : PCS_NAD27_Tennessee, Proj_Tennessee_CS27,
360 :
361 : PCS_NAD27_Texas_North, Proj_Texas_CS27_North,
362 : PCS_NAD27_Texas_North_Cen, Proj_Texas_CS27_North_Central,
363 : PCS_NAD27_Texas_Central, Proj_Texas_CS27_Central,
364 : PCS_NAD27_Texas_South_Cen, Proj_Texas_CS27_South_Central,
365 : PCS_NAD27_Texas_South, Proj_Texas_CS27_South,
366 :
367 : PCS_NAD27_Utah_North, Proj_Utah_CS27_North,
368 : PCS_NAD27_Utah_Central, Proj_Utah_CS27_Central,
369 : PCS_NAD27_Utah_South, Proj_Utah_CS27_South,
370 :
371 : PCS_NAD27_Vermont, Proj_Vermont_CS27,
372 :
373 : PCS_NAD27_Virginia_North, Proj_Virginia_CS27_North,
374 : PCS_NAD27_Virginia_South, Proj_Virginia_CS27_South,
375 :
376 : PCS_NAD27_Washington_North, Proj_Washington_CS27_North,
377 : PCS_NAD27_Washington_South, Proj_Washington_CS27_South,
378 :
379 : PCS_NAD27_West_Virginia_N, Proj_West_Virginia_CS27_North,
380 : PCS_NAD27_West_Virginia_S, Proj_West_Virginia_CS27_South,
381 :
382 : PCS_NAD27_Wisconsin_North, Proj_Wisconsin_CS27_North,
383 : PCS_NAD27_Wisconsin_Cen, Proj_Wisconsin_CS27_Central,
384 : PCS_NAD27_Wisconsin_South, Proj_Wisconsin_CS27_South,
385 :
386 : PCS_NAD27_Wyoming_East, Proj_Wyoming_CS27_East,
387 : PCS_NAD27_Wyoming_E_Cen, Proj_Wyoming_CS27_East_Central,
388 : PCS_NAD27_Wyoming_W_Cen, Proj_Wyoming_CS27_West_Central,
389 : PCS_NAD27_Wyoming_West, Proj_Wyoming_CS27_West,
390 :
391 : PCS_NAD27_Puerto_Rico, Proj_Puerto_Rico_CS27,
392 :
393 : KvUserDefined
394 : };
395 :
396 : /************************************************************************/
397 : /* GTIFMapSysToPCS() */
398 : /* */
399 : /* Given a Datum, MapSys and zone value generate the best PCS */
400 : /* code possible. */
401 : /************************************************************************/
402 :
403 0 : int GTIFMapSysToPCS( int MapSys, int Datum, int nZone )
404 :
405 : {
406 0 : int PCSCode = KvUserDefined;
407 :
408 0 : if( MapSys == MapSys_UTM_North )
409 : {
410 0 : if( Datum == GCS_NAD27 )
411 0 : PCSCode = PCS_NAD27_UTM_zone_3N + nZone - 3;
412 0 : else if( Datum == GCS_NAD83 )
413 0 : PCSCode = PCS_NAD83_UTM_zone_3N + nZone - 3;
414 0 : else if( Datum == GCS_WGS_72 )
415 0 : PCSCode = PCS_WGS72_UTM_zone_1N + nZone - 1;
416 0 : else if( Datum == GCS_WGS_72BE )
417 0 : PCSCode = PCS_WGS72BE_UTM_zone_1N + nZone - 1;
418 0 : else if( Datum == GCS_WGS_84 )
419 0 : PCSCode = PCS_WGS84_UTM_zone_1N + nZone - 1;
420 : }
421 0 : else if( MapSys == MapSys_UTM_South )
422 : {
423 0 : if( Datum == GCS_WGS_72 )
424 0 : PCSCode = PCS_WGS72_UTM_zone_1S + nZone - 1;
425 0 : else if( Datum == GCS_WGS_72BE )
426 0 : PCSCode = PCS_WGS72BE_UTM_zone_1S + nZone - 1;
427 0 : else if( Datum == GCS_WGS_84 )
428 0 : PCSCode = PCS_WGS84_UTM_zone_1S + nZone - 1;
429 : }
430 0 : else if( MapSys == MapSys_State_Plane_27 )
431 : {
432 : int i;
433 :
434 0 : PCSCode = 10000 + nZone;
435 0 : for( i = 0; StatePlaneTable[i] != KvUserDefined; i += 2 )
436 : {
437 0 : if( StatePlaneTable[i+1] == PCSCode )
438 0 : PCSCode = StatePlaneTable[i];
439 : }
440 :
441 : /* Old EPSG code was in error for Tennesse CS27, override */
442 0 : if( nZone == 4100 )
443 0 : PCSCode = 2204;
444 : }
445 0 : else if( MapSys == MapSys_State_Plane_83 )
446 : {
447 : int i;
448 :
449 0 : PCSCode = 10000 + nZone + 30;
450 :
451 0 : for( i = 0; StatePlaneTable[i] != KvUserDefined; i += 2 )
452 : {
453 0 : if( StatePlaneTable[i+1] == PCSCode )
454 0 : PCSCode = StatePlaneTable[i];
455 : }
456 :
457 : /* Old EPSG code was in error for Kentucky North CS83, override */
458 0 : if( nZone == 1601 )
459 0 : PCSCode = 2205;
460 : }
461 :
462 0 : return( PCSCode );
463 : }
464 :
465 : /************************************************************************/
466 : /* GTIFMapSysToProj() */
467 : /* */
468 : /* Given a MapSys and zone value generate the best Proj_ */
469 : /* code possible. */
470 : /************************************************************************/
471 :
472 0 : int GTIFMapSysToProj( int MapSys, int nZone )
473 :
474 : {
475 0 : int ProjCode = KvUserDefined;
476 :
477 0 : if( MapSys == MapSys_UTM_North )
478 : {
479 0 : ProjCode = Proj_UTM_zone_1N + nZone - 1;
480 : }
481 0 : else if( MapSys == MapSys_UTM_South )
482 : {
483 0 : ProjCode = Proj_UTM_zone_1S + nZone - 1;
484 : }
485 0 : else if( MapSys == MapSys_State_Plane_27 )
486 : {
487 0 : ProjCode = 10000 + nZone;
488 :
489 : /* Tennesse override */
490 0 : if( nZone == 4100 )
491 0 : ProjCode = 15302;
492 : }
493 0 : else if( MapSys == MapSys_State_Plane_83 )
494 : {
495 0 : ProjCode = 10000 + nZone + 30;
496 :
497 : /* Kentucky North override */
498 0 : if( nZone == 1601 )
499 0 : ProjCode = 15303;
500 : }
501 :
502 0 : return( ProjCode );
503 : }
504 :
505 : /************************************************************************/
506 : /* GTIFPCSToMapSys() */
507 : /************************************************************************/
508 :
509 : /**
510 : * Translate a PCS_ code into a UTM or State Plane map system, a datum,
511 : * and a zone if possible.
512 : *
513 : * @param PCSCode The projection code (PCS_*) as would be stored in the
514 : * ProjectedCSTypeGeoKey of a GeoTIFF file.
515 : *
516 : * @param pDatum Pointer to an integer into which the datum code (GCS_*)
517 : * is put if the function succeeds.
518 : *
519 : * @param pZone Pointer to an integer into which the zone will be placed
520 : * if the function is successful.
521 : *
522 : * @return Returns either MapSys_UTM_North, MapSys_UTM_South,
523 : * MapSys_State_Plane_83, MapSys_State_Plane_27 or KvUserDefined.
524 : * KvUserDefined indicates that the
525 : * function failed to recognise the projection as UTM or State Plane.
526 : *
527 : * The zone value is only set if the return code is other than KvUserDefined.
528 : * For utm map system the returned zone will be between 1 and 60. For
529 : * State Plane, the USGS state plane zone number is returned. For instance,
530 : * Alabama East is zone 101.
531 : *
532 : * The datum (really this is the GCS) is set to a GCS_ value such as GCS_NAD27.
533 : *
534 : * This function is useful to recognise (most) UTM and State Plane coordinate
535 : * systems, even if CSV files aren't available to translate them automatically.
536 : * It is used as a fallback mechanism by GTIFGetDefn() for normalization when
537 : * CSV files aren't found.
538 : */
539 :
540 976 : int GTIFPCSToMapSys( int PCSCode, int * pDatum, int * pZone )
541 :
542 : {
543 976 : int Datum = KvUserDefined, Proj = KvUserDefined;
544 976 : int nZone = KvUserDefined, i;
545 :
546 : /* -------------------------------------------------------------------- */
547 : /* UTM with various datums. Note there are lots of PCS UTM */
548 : /* codes not done yet which use strange datums. */
549 : /* -------------------------------------------------------------------- */
550 1800 : if( PCSCode >= PCS_NAD27_UTM_zone_3N && PCSCode <= PCS_NAD27_UTM_zone_22N )
551 : {
552 824 : Datum = GCS_NAD27;
553 824 : Proj = MapSys_UTM_North;
554 824 : nZone = PCSCode - PCS_NAD27_UTM_zone_3N + 3;
555 : }
556 152 : else if( PCSCode >= PCS_NAD83_UTM_zone_3N
557 : && PCSCode <= PCS_NAD83_UTM_zone_23N )
558 : {
559 0 : Datum = GCS_NAD83;
560 0 : Proj = MapSys_UTM_North;
561 0 : nZone = PCSCode - PCS_NAD83_UTM_zone_3N + 3;
562 : }
563 :
564 152 : else if( PCSCode >= PCS_WGS72_UTM_zone_1N
565 : && PCSCode <= PCS_WGS72_UTM_zone_60N )
566 : {
567 0 : Datum = GCS_WGS_72;
568 0 : Proj = MapSys_UTM_North;
569 0 : nZone = PCSCode - PCS_WGS72_UTM_zone_1N + 1;
570 : }
571 152 : else if( PCSCode >= PCS_WGS72_UTM_zone_1S
572 : && PCSCode <= PCS_WGS72_UTM_zone_60S )
573 : {
574 0 : Datum = GCS_WGS_72;
575 0 : Proj = MapSys_UTM_South;
576 0 : nZone = PCSCode - PCS_WGS72_UTM_zone_1S + 1;
577 : }
578 :
579 152 : else if( PCSCode >= PCS_WGS72BE_UTM_zone_1N
580 : && PCSCode <= PCS_WGS72BE_UTM_zone_60N )
581 : {
582 0 : Datum = GCS_WGS_72BE;
583 0 : Proj = MapSys_UTM_North;
584 0 : nZone = PCSCode - PCS_WGS72BE_UTM_zone_1N + 1;
585 : }
586 152 : else if( PCSCode >= PCS_WGS72BE_UTM_zone_1S
587 : && PCSCode <= PCS_WGS72BE_UTM_zone_60S )
588 : {
589 0 : Datum = GCS_WGS_72BE;
590 0 : Proj = MapSys_UTM_South;
591 0 : nZone = PCSCode - PCS_WGS72BE_UTM_zone_1S + 1;
592 : }
593 :
594 250 : else if( PCSCode >= PCS_WGS84_UTM_zone_1N
595 : && PCSCode <= PCS_WGS84_UTM_zone_60N )
596 : {
597 98 : Datum = GCS_WGS_84;
598 98 : Proj = MapSys_UTM_North;
599 98 : nZone = PCSCode - PCS_WGS84_UTM_zone_1N + 1;
600 : }
601 54 : else if( PCSCode >= PCS_WGS84_UTM_zone_1S
602 : && PCSCode <= PCS_WGS84_UTM_zone_60S )
603 : {
604 0 : Datum = GCS_WGS_84;
605 0 : Proj = MapSys_UTM_South;
606 0 : nZone = PCSCode - PCS_WGS84_UTM_zone_1S + 1;
607 : }
608 54 : else if( PCSCode >= PCS_SAD69_UTM_zone_18N
609 : && PCSCode <= PCS_SAD69_UTM_zone_22N )
610 : {
611 0 : Datum = KvUserDefined;
612 0 : Proj = MapSys_UTM_North;
613 0 : nZone = PCSCode - PCS_SAD69_UTM_zone_18N + 18;
614 : }
615 54 : else if( PCSCode >= PCS_SAD69_UTM_zone_17S
616 : && PCSCode <= PCS_SAD69_UTM_zone_25S )
617 : {
618 0 : Datum = KvUserDefined;
619 0 : Proj = MapSys_UTM_South;
620 0 : nZone = PCSCode - PCS_SAD69_UTM_zone_17S + 17;
621 : }
622 :
623 : /* -------------------------------------------------------------------- */
624 : /* State Plane zones, first we translate any PCS_ codes to */
625 : /* a Proj_ code that we can get a handle on. */
626 : /* -------------------------------------------------------------------- */
627 244000 : for( i = 0; StatePlaneTable[i] != KvUserDefined; i += 2 )
628 : {
629 243024 : if( StatePlaneTable[i] == PCSCode )
630 2 : PCSCode = StatePlaneTable[i+1];
631 : }
632 :
633 976 : if( PCSCode <= 15900 && PCSCode >= 10000 )
634 : {
635 2 : if( (PCSCode % 100) >= 30 )
636 : {
637 0 : Proj = MapSys_State_Plane_83;
638 0 : Datum = GCS_NAD83;
639 : }
640 : else
641 : {
642 2 : Proj = MapSys_State_Plane_27;
643 2 : Datum = GCS_NAD27;
644 : }
645 :
646 2 : nZone = PCSCode - 10000;
647 2 : if( Datum == GCS_NAD83 )
648 0 : nZone -= 30;
649 : }
650 :
651 976 : if( pDatum != NULL )
652 976 : *pDatum = Datum;
653 :
654 976 : if( pZone != NULL )
655 976 : *pZone = nZone;
656 :
657 976 : return( Proj );
658 : }
659 :
660 : /************************************************************************/
661 : /* GTIFProjToMapSys() */
662 : /************************************************************************/
663 :
664 : /**
665 : * Translate a Proj_ code into a UTM or State Plane map system, and a zone
666 : * if possible.
667 : *
668 : * @param ProjCode The projection code (Proj_*) as would be stored in the
669 : * ProjectionGeoKey of a GeoTIFF file.
670 : * @param pZone Pointer to an integer into which the zone will be placed
671 : * if the function is successful.
672 : *
673 : * @return Returns either MapSys_UTM_North, MapSys_UTM_South,
674 : * MapSys_State_Plane_27, MapSys_State_Plane_83 or KvUserDefined.
675 : * KvUserDefined indicates that the
676 : * function failed to recognise the projection as UTM or State Plane.
677 : *
678 : * The zone value is only set if the return code is other than KvUserDefined.
679 : * For utm map system the returned zone will be between 1 and 60. For
680 : * State Plane, the USGS state plane zone number is returned. For instance,
681 : * Alabama East is zone 101.
682 : *
683 : * This function is useful to recognise UTM and State Plane coordinate
684 : * systems, and to extract zone numbers so the projections can be
685 : * represented as UTM rather than as the underlying projection method such
686 : * Transverse Mercator for instance.
687 : */
688 :
689 980 : int GTIFProjToMapSys( int ProjCode, int * pZone )
690 :
691 : {
692 980 : int nZone = KvUserDefined;
693 980 : int MapSys = KvUserDefined;
694 :
695 : /* -------------------------------------------------------------------- */
696 : /* Handle UTM. */
697 : /* -------------------------------------------------------------------- */
698 1444 : if( ProjCode >= Proj_UTM_zone_1N && ProjCode <= Proj_UTM_zone_60N )
699 : {
700 464 : MapSys = MapSys_UTM_North;
701 464 : nZone = ProjCode - Proj_UTM_zone_1N + 1;
702 : }
703 516 : else if( ProjCode >= Proj_UTM_zone_1S && ProjCode <= Proj_UTM_zone_60S )
704 : {
705 0 : MapSys = MapSys_UTM_South;
706 0 : nZone = ProjCode - Proj_UTM_zone_1S + 1;
707 : }
708 :
709 : /* -------------------------------------------------------------------- */
710 : /* Handle State Plane. I think there are some anomolies in */
711 : /* here, so this is a bit risky. */
712 : /* -------------------------------------------------------------------- */
713 516 : else if( ProjCode >= 10101 && ProjCode <= 15299 )
714 : {
715 3 : if( ProjCode % 100 >= 30 )
716 : {
717 1 : MapSys = MapSys_State_Plane_83;
718 1 : nZone = ProjCode - 10000 - 30;
719 : }
720 : else
721 : {
722 2 : MapSys = MapSys_State_Plane_27;
723 2 : nZone = ProjCode - 10000;
724 : }
725 : }
726 :
727 980 : if( pZone != NULL )
728 980 : *pZone = nZone;
729 :
730 980 : return( MapSys );
731 : }
732 :
|