forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgxf_proj4.c
621 lines (493 loc) · 20.4 KB
/
gxf_proj4.c
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/******************************************************************************
* $Id$
*
* Project: GXF Reader
* Purpose: Handle GXF to PROJ.4 projection transformation.
* Author: Frank Warmerdam, [email protected]
*
******************************************************************************
* Copyright (c) 1998, Global Geomatics
* Copyright (c) 1998, 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.
****************************************************************************/
#include "gxfopen.h"
CPL_CVSID("$Id$")
#define SAFE_strcat(x,y) snprintf(x + strlen(x),sizeof(x) - strlen(x), "%s", y)
/************************************************************************/
/* GXFGetMapProjectionAsPROJ4() */
/************************************************************************/
/**
* Return the GXF Projection in PROJ.4 format.
*
* The returned string becomes owned by the caller, and should be freed
* with CPLFree() or VSIFree(). The return value will be "unknown" if
* no projection information is passed.
*
* The mapping of GXF projections to PROJ.4 format is not complete. Please
* see the gxf_proj4.c code to better understand limitations of this
* translation. In particular, PROJ.4 knows little about datums.
*
* For example, the following GXF definitions:
* <pre>
* #UNIT_LENGTH
* m,1
* #MAP_PROJECTION
* "NAD83 / UTM zone 19N"
* "GRS 1980",6378137,0.081819191,0
* "Transverse Mercator",0,-69,0.9996,500000,0
* </pre>
*
* Would translate to:
* <pre>
* +proj=tmerc +lat_0=0 +lon_0=-69 +k=0.9996 +x_0=500000 +y_0=0 +ellps=GRS80
* </pre>
*
* @param hGXF handle to GXF file, as returned by GXFOpen().
*
* @return string containing PROJ.4 projection.
*/
char *GXFGetMapProjectionAsPROJ4( GXFHandle hGXF )
{
GXFInfo_t *psGXF = (GXFInfo_t *) hGXF;
char **papszMethods = NULL;
char szPROJ4[512] = { 0 };
/* -------------------------------------------------------------------- */
/* If there was nothing in the file return "unknown". */
/* -------------------------------------------------------------------- */
if( CSLCount(psGXF->papszMapProjection) < 2 )
return( CPLStrdup( "unknown" ) );
/* -------------------------------------------------------------------- */
/* Parse the third line, looking for known projection methods. */
/* -------------------------------------------------------------------- */
if( psGXF->papszMapProjection[2] != NULL )
{
if( strlen(psGXF->papszMapProjection[2]) > 80 )
return( CPLStrdup( "" ) );
papszMethods = CSLTokenizeStringComplex(psGXF->papszMapProjection[2],
",", TRUE, TRUE );
}
if( papszMethods == NULL
|| papszMethods[0] == NULL
|| EQUAL(papszMethods[0],"Geographic") )
{
SAFE_strcat( szPROJ4, "+proj=longlat" );
}
#ifdef notdef
else if( EQUAL(papszMethods[0],"Lambert Conic Conformal (1SP)")
&& CSLCount(papszMethods) > 5 )
{
/* notdef: It isn't clear that this 1SP + scale method is even
supported by PROJ.4
Later note: It is not. */
SAFE_strcat( szPROJ4, "+proj=lcc" );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +k=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
}
#endif
else if( EQUAL(papszMethods[0],"Lambert Conic Conformal (2SP)")
|| EQUAL(papszMethods[0],"Lambert Conformal (2SP Belgium)") )
{
/* notdef: Note we are apparently losing whatever makes the
Belgium variant different than normal LCC, but hopefully
they are close! */
SAFE_strcat( szPROJ4, "+proj=lcc" );
if( CSLCount(papszMethods) > 1 )
{
SAFE_strcat( szPROJ4, " +lat_1=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
}
if( CSLCount(papszMethods) > 2 )
{
SAFE_strcat( szPROJ4, " +lat_2=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
}
if( CSLCount(papszMethods) > 3 )
{
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
}
if( CSLCount(papszMethods) > 4 )
{
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
}
if( CSLCount(papszMethods) > 5 )
{
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
}
if( CSLCount(papszMethods) > 6 )
{
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[6] );
}
}
else if( EQUAL(papszMethods[0],"Mercator (1SP)")
&& CSLCount(papszMethods) > 5 )
{
/* notdef: it isn't clear that +proj=merc support a scale of other
than 1.0 in PROJ.4 */
SAFE_strcat( szPROJ4, "+proj=merc" );
SAFE_strcat( szPROJ4, " +lat_ts=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +k=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
}
else if( EQUAL(papszMethods[0],"Mercator (2SP)")
&& CSLCount(papszMethods) > 4 )
{
/* notdef: it isn't clear that +proj=merc support a scale of other
than 1.0 in PROJ.4 */
SAFE_strcat( szPROJ4, "+proj=merc" );
SAFE_strcat( szPROJ4, " +lat_ts=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
}
else if( EQUAL(papszMethods[0],"Hotine Oblique Mercator")
&& CSLCount(papszMethods) > 7 )
{
/* Note that only the second means of specifying omerc is supported
by this code in GXF. */
SAFE_strcat( szPROJ4, "+proj=omerc" );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lonc=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +alpha=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
if( CPLAtof(papszMethods[4]) < 0.00001 )
{
SAFE_strcat( szPROJ4, " +not_rot" );
}
else
{
#ifdef notdef
if( CPLAtof(papszMethods[4]) + CPLAtof(papszMethods[3]) < 0.00001 )
/* ok */;
else
/* notdef: no way to specify arbitrary angles! */;
#endif
}
SAFE_strcat( szPROJ4, " +k=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[6] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[7] );
}
else if( EQUAL(papszMethods[0],"Laborde Oblique Mercator")
&& CSLCount(papszMethods) > 6 )
{
SAFE_strcat( szPROJ4, "+proj=labrd" );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +azi=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +k=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[6] );
}
else if( EQUAL(papszMethods[0],"New Zealand Map Grid")
&& CSLCount(papszMethods) > 4 )
{
SAFE_strcat( szPROJ4, "+proj=nzmg" );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
}
else if( EQUAL(papszMethods[0],"New Zealand Map Grid")
&& CSLCount(papszMethods) > 4 )
{
SAFE_strcat( szPROJ4, "+proj=nzmg" );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
}
else if( EQUAL(papszMethods[0],"Oblique Stereographic")
&& CSLCount(papszMethods) > 5 )
{
/* there is an option to produce +lat_ts, which we ignore */
SAFE_strcat( szPROJ4, "+proj=stere" );
SAFE_strcat( szPROJ4, " +lat_0=45" );
SAFE_strcat( szPROJ4, " +lat_ts=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +k=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
}
else if( EQUAL(papszMethods[0],"Polar Stereographic")
&& CSLCount(papszMethods) > 5 )
{
/* there is an option to produce +lat_ts, which we ignore */
SAFE_strcat( szPROJ4, "+proj=stere" );
SAFE_strcat( szPROJ4, " +lat_0=90" );
SAFE_strcat( szPROJ4, " +lat_ts=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +k=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
}
else if( EQUAL(papszMethods[0],"Swiss Oblique Cylindrical")
&& CSLCount(papszMethods) > 4 )
{
/* notdef: geotiff's geo_ctrans.inc says this is the same as
ObliqueMercator_Rosenmund, which GG's geotiff support just
maps directly to +proj=omerc, though I find that questionable. */
SAFE_strcat( szPROJ4, "+proj=omerc" );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lonc=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
}
else if( EQUAL(papszMethods[0],"Transverse Mercator")
&& CSLCount(papszMethods) > 5 )
{
/* notdef: geotiff's geo_ctrans.inc says this is the same as
ObliqueMercator_Rosenmund, which GG's geotiff support just
maps directly to +proj=omerc, though I find that questionable. */
SAFE_strcat( szPROJ4, "+proj=tmerc" );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +k=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
}
else if( EQUAL(papszMethods[0],"Transverse Mercator (South Oriented)")
&& CSLCount(papszMethods) > 5 )
{
/* notdef: I don't know how south oriented is different from
normal, and I don't find any mention of it in Geotiff;s geo_ctrans.
Translating as tmerc, but that is presumably wrong. */
SAFE_strcat( szPROJ4, "+proj=tmerc" );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +k=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
}
else if( EQUAL(papszMethods[0],"*Equidistant Conic")
&& CSLCount(papszMethods) > 6 )
{
SAFE_strcat( szPROJ4, "+proj=eqdc" );
SAFE_strcat( szPROJ4, " +lat_1=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lat_2=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[6] );
}
else if( EQUAL(papszMethods[0],"*Polyconic")
&& CSLCount(papszMethods) > 5 )
{
SAFE_strcat( szPROJ4, "+proj=poly" );
SAFE_strcat( szPROJ4, " +lat_0=" );
SAFE_strcat( szPROJ4, papszMethods[1] );
SAFE_strcat( szPROJ4, " +lon_0=" );
SAFE_strcat( szPROJ4, papszMethods[2] );
#ifdef notdef
/*not supported by PROJ.4 */
SAFE_strcat( szPROJ4, " +k=" );
SAFE_strcat( szPROJ4, papszMethods[3] );
#endif
SAFE_strcat( szPROJ4, " +x_0=" );
SAFE_strcat( szPROJ4, papszMethods[4] );
SAFE_strcat( szPROJ4, " +y_0=" );
SAFE_strcat( szPROJ4, papszMethods[5] );
}
else
{
SAFE_strcat( szPROJ4, "unknown" );
}
CSLDestroy( papszMethods );
/* -------------------------------------------------------------------- */
/* Now get the ellipsoid parameters. For a bunch of common */
/* ones we preserve the name. For the rest we just carry over */
/* the parameters. */
/* -------------------------------------------------------------------- */
if( CSLCount(psGXF->papszMapProjection) > 1 )
{
char **papszTokens;
if( strlen(psGXF->papszMapProjection[1]) > 80 )
return CPLStrdup("");
papszTokens = CSLTokenizeStringComplex(psGXF->papszMapProjection[1],
",", TRUE, TRUE );
if( EQUAL(papszTokens[0],"WGS 84") )
SAFE_strcat( szPROJ4, " +ellps=WGS84" );
else if( EQUAL(papszTokens[0],"*WGS 72") )
SAFE_strcat( szPROJ4, " +ellps=WGS72" );
else if( EQUAL(papszTokens[0],"*WGS 66") )
SAFE_strcat( szPROJ4, " +ellps=WGS66" );
else if( EQUAL(papszTokens[0],"*WGS 60") )
SAFE_strcat( szPROJ4, " +ellps=WGS60" );
else if( EQUAL(papszTokens[0],"Clarke 1866") )
SAFE_strcat( szPROJ4, " +ellps=clrk66" );
else if( EQUAL(papszTokens[0],"Clarke 1880") )
SAFE_strcat( szPROJ4, " +ellps=clrk80" );
else if( EQUAL(papszTokens[0],"GRS 1980") )
SAFE_strcat( szPROJ4, " +ellps=GRS80" );
else if( CSLCount( papszTokens ) > 2 )
{
snprintf( szPROJ4+strlen(szPROJ4), sizeof(szPROJ4)-strlen(szPROJ4),
" +a=%s +e=%s",
papszTokens[1], papszTokens[2] );
}
CSLDestroy(papszTokens);
}
/* -------------------------------------------------------------------- */
/* Extract the units specification. */
/* -------------------------------------------------------------------- */
if( psGXF->pszUnitName != NULL )
{
if( EQUAL(psGXF->pszUnitName,"ft") )
{
SAFE_strcat( szPROJ4, " +units=ft" );
}
else if( EQUAL(psGXF->pszUnitName,"ftUS") )
{
SAFE_strcat( szPROJ4, " +units=us-ft" );
}
else if( EQUAL(psGXF->pszUnitName,"km") )
{
SAFE_strcat( szPROJ4, " +units=km" );
}
else if( EQUAL(psGXF->pszUnitName,"mm") )
{
SAFE_strcat( szPROJ4, " +units=mm" );
}
else if( EQUAL(psGXF->pszUnitName,"in") )
{
SAFE_strcat( szPROJ4, " +units=in" );
}
else if( EQUAL(psGXF->pszUnitName,"ftInd") )
{
SAFE_strcat( szPROJ4, " +units=ind-ft" );
}
else if( EQUAL(psGXF->pszUnitName,"lk") )
{
SAFE_strcat( szPROJ4, " +units=link" );
}
}
return( CPLStrdup( szPROJ4 ) );
}
/************************************************************************/
/* GXFGetPROJ4Position() */
/* */
/* Get the same information as GXFGetPosition(), but adjust */
/* to units to meters if we don't ``know'' the indicated */
/* units. */
/************************************************************************/
CPLErr GXFGetPROJ4Position( GXFHandle hGXF,
double * pdfXOrigin, double * pdfYOrigin,
double * pdfXPixelSize, double * pdfYPixelSize,
double * pdfRotation )
{
GXFInfo_t *psGXF = (GXFInfo_t *) hGXF;
char *pszProj;
/* -------------------------------------------------------------------- */
/* Get the raw position. */
/* -------------------------------------------------------------------- */
if( GXFGetPosition( hGXF,
pdfXOrigin, pdfYOrigin,
pdfXPixelSize, pdfYPixelSize,
pdfRotation ) == CE_Failure )
return( CE_Failure );
/* -------------------------------------------------------------------- */
/* Do we know the units in PROJ.4? Get the PROJ.4 string, and */
/* check for a +units definition. */
/* -------------------------------------------------------------------- */
pszProj = GXFGetMapProjectionAsPROJ4( hGXF );
if( strstr(pszProj,"+unit") == NULL && psGXF->pszUnitName != NULL )
{
if( pdfXOrigin != NULL )
*pdfXOrigin *= psGXF->dfUnitToMeter;
if( pdfYOrigin != NULL )
*pdfYOrigin *= psGXF->dfUnitToMeter;
if( pdfXPixelSize != NULL )
*pdfXPixelSize *= psGXF->dfUnitToMeter;
if( pdfYPixelSize != NULL )
*pdfYPixelSize *= psGXF->dfUnitToMeter;
}
CPLFree( pszProj );
return( CE_None );
}