34
34
#include "geo_normalize.h"
35
35
#include "geovalues.h"
36
36
#include "geo_tiffp.h"
37
+ #include "proj.h"
38
+
39
+ /************************************************************************/
40
+ /* GTIFProj4AppendEllipsoid() */
41
+ /************************************************************************/
42
+
43
+ static void GTIFProj4AppendEllipsoid (GTIFDefn * psDefn , char * pszProjection )
44
+ {
45
+ /* ==================================================================== */
46
+ /* Handle ellipsoid information. */
47
+ /* ==================================================================== */
48
+ if ( psDefn -> Ellipsoid == Ellipse_WGS_84 )
49
+ strcat ( pszProjection , "+ellps=WGS84 " );
50
+ else if ( psDefn -> Ellipsoid == Ellipse_Clarke_1866 )
51
+ strcat ( pszProjection , "+ellps=clrk66 " );
52
+ else if ( psDefn -> Ellipsoid == Ellipse_Clarke_1880 )
53
+ strcat ( pszProjection , "+ellps=clrk80 " );
54
+ else if ( psDefn -> Ellipsoid == Ellipse_GRS_1980 )
55
+ strcat ( pszProjection , "+ellps=GRS80 " );
56
+ else
57
+ {
58
+ if ( psDefn -> SemiMajor != 0.0 && psDefn -> SemiMinor != 0.0 )
59
+ {
60
+ sprintf ( pszProjection + strlen (pszProjection ),
61
+ "+a=%.3f +b=%.3f " ,
62
+ psDefn -> SemiMajor ,
63
+ psDefn -> SemiMinor );
64
+ }
65
+ }
66
+ }
37
67
38
68
/************************************************************************/
39
69
/* OSRProj4Tokenize() */
@@ -940,6 +970,21 @@ char * GTIFGetProj4Defn( GTIFDefn * psDefn )
940
970
dfFalseNorthing );
941
971
}
942
972
973
+ /* -------------------------------------------------------------------- */
974
+ /* Oblique Mercator */
975
+ /* -------------------------------------------------------------------- */
976
+ else if ( psDefn -> CTProjection == CT_ObliqueMercator_Laborde )
977
+ {
978
+ sprintf ( szProjection + strlen (szProjection ),
979
+ "+proj=labrd +lat_0=%.9f +lon_0=%.9f +azi=%.9f +k=%f +x_0=%.3f +y_0=%.3f " ,
980
+ psDefn -> ProjParm [0 ],
981
+ psDefn -> ProjParm [1 ],
982
+ psDefn -> ProjParm [2 ],
983
+ psDefn -> ProjParm [4 ],
984
+ dfFalseEasting ,
985
+ dfFalseNorthing );
986
+ }
987
+
943
988
/* -------------------------------------------------------------------- */
944
989
/* Mercator */
945
990
/* -------------------------------------------------------------------- */
@@ -1313,27 +1358,8 @@ char * GTIFGetProj4Defn( GTIFDefn * psDefn )
1313
1358
}*/
1314
1359
}
1315
1360
}
1316
- /* ==================================================================== */
1317
- /* Handle ellipsoid information. */
1318
- /* ==================================================================== */
1319
- if ( psDefn -> Ellipsoid == Ellipse_WGS_84 )
1320
- strcat ( szProjection , "+ellps=WGS84 " );
1321
- else if ( psDefn -> Ellipsoid == Ellipse_Clarke_1866 )
1322
- strcat ( szProjection , "+ellps=clrk66 " );
1323
- else if ( psDefn -> Ellipsoid == Ellipse_Clarke_1880 )
1324
- strcat ( szProjection , "+ellps=clrk80 " );
1325
- else if ( psDefn -> Ellipsoid == Ellipse_GRS_1980 )
1326
- strcat ( szProjection , "+ellps=GRS80 " );
1327
- else
1328
- {
1329
- if ( psDefn -> SemiMajor != 0.0 && psDefn -> SemiMinor != 0.0 )
1330
- {
1331
- sprintf ( szProjection + strlen (szProjection ),
1332
- "+a=%.3f +b=%.3f " ,
1333
- psDefn -> SemiMajor ,
1334
- psDefn -> SemiMinor );
1335
- }
1336
- }
1361
+
1362
+ GTIFProj4AppendEllipsoid (psDefn , szProjection );
1337
1363
1338
1364
strcat ( szProjection , szUnits );
1339
1365
@@ -1343,9 +1369,6 @@ char * GTIFGetProj4Defn( GTIFDefn * psDefn )
1343
1369
return CPLStrdup ( szProjection );
1344
1370
}
1345
1371
1346
- #define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
1347
- #include "proj_api.h"
1348
-
1349
1372
/************************************************************************/
1350
1373
/* GTIFProj4FromLatLong() */
1351
1374
/* */
@@ -1357,9 +1380,11 @@ int GTIFProj4FromLatLong( GTIFDefn * psDefn, int nPoints,
1357
1380
double * padfX , double * padfY )
1358
1381
1359
1382
{
1360
- char * pszProjection , * * papszArgs ;
1361
- projPJ * psPJ ;
1383
+ char szLongLat [256 ];
1384
+ char * pszProjection ;
1385
+ PJ * psPJ ;
1362
1386
int i ;
1387
+ PJ_CONTEXT * ctx ;
1363
1388
1364
1389
/* -------------------------------------------------------------------- */
1365
1390
/* Get a projection definition. */
@@ -1369,19 +1394,17 @@ int GTIFProj4FromLatLong( GTIFDefn * psDefn, int nPoints,
1369
1394
if ( pszProjection == NULL )
1370
1395
return FALSE;
1371
1396
1372
- /* -------------------------------------------------------------------- */
1373
- /* Parse into tokens for pj_init(), and initialize the projection. */
1374
- /* -------------------------------------------------------------------- */
1375
-
1376
- papszArgs = CSLTokenizeStringComplex ( pszProjection , " +" , TRUE, FALSE );
1377
- free ( pszProjection );
1397
+ ctx = proj_context_create ();
1378
1398
1379
- psPJ = pj_init ( CSLCount (papszArgs ), papszArgs );
1399
+ strcpy (szLongLat , "+proj=longlat " );
1400
+ GTIFProj4AppendEllipsoid (psDefn , szLongLat );
1380
1401
1381
- CSLDestroy ( papszArgs );
1402
+ psPJ = proj_create_crs_to_crs ( ctx , szLongLat , pszProjection , NULL );
1403
+ CPLFree ( pszProjection );
1382
1404
1383
1405
if ( psPJ == NULL )
1384
1406
{
1407
+ proj_context_destroy (ctx );
1385
1408
return FALSE;
1386
1409
}
1387
1410
@@ -1390,18 +1413,20 @@ int GTIFProj4FromLatLong( GTIFDefn * psDefn, int nPoints,
1390
1413
/* -------------------------------------------------------------------- */
1391
1414
for ( i = 0 ; i < nPoints ; i ++ )
1392
1415
{
1393
- projUV sUV ;
1416
+ PJ_COORD coord ;
1417
+ coord .xyzt .x = padfX [i ];
1418
+ coord .xyzt .y = padfY [i ];
1419
+ coord .xyzt .z = 0 ;
1420
+ coord .xyzt .t = 0 ;
1394
1421
1395
- sUV .u = padfX [i ] * DEG_TO_RAD ;
1396
- sUV .v = padfY [i ] * DEG_TO_RAD ;
1422
+ coord = proj_trans (psPJ , PJ_FWD , coord );
1397
1423
1398
- sUV = pj_fwd ( sUV , psPJ );
1399
-
1400
- padfX [i ] = sUV .u ;
1401
- padfY [i ] = sUV .v ;
1424
+ padfX [i ] = coord .xyzt .x ;
1425
+ padfY [i ] = coord .xyzt .y ;
1402
1426
}
1403
1427
1404
- pj_free ( psPJ );
1428
+ proj_destroy ( psPJ );
1429
+ proj_context_destroy (ctx );
1405
1430
1406
1431
return TRUE;
1407
1432
}
@@ -1417,9 +1442,11 @@ int GTIFProj4ToLatLong( GTIFDefn * psDefn, int nPoints,
1417
1442
double * padfX , double * padfY )
1418
1443
1419
1444
{
1420
- char * pszProjection , * * papszArgs ;
1421
- projPJ * psPJ ;
1445
+ char szLongLat [256 ];
1446
+ char * pszProjection ;
1447
+ PJ * psPJ ;
1422
1448
int i ;
1449
+ PJ_CONTEXT * ctx ;
1423
1450
1424
1451
/* -------------------------------------------------------------------- */
1425
1452
/* Get a projection definition. */
@@ -1429,19 +1456,17 @@ int GTIFProj4ToLatLong( GTIFDefn * psDefn, int nPoints,
1429
1456
if ( pszProjection == NULL )
1430
1457
return FALSE;
1431
1458
1432
- /* -------------------------------------------------------------------- */
1433
- /* Parse into tokens for pj_init(), and initialize the projection. */
1434
- /* -------------------------------------------------------------------- */
1435
-
1436
- papszArgs = CSLTokenizeStringComplex ( pszProjection , " +" , TRUE, FALSE );
1437
- free ( pszProjection );
1459
+ ctx = proj_context_create ();
1438
1460
1439
- psPJ = pj_init ( CSLCount (papszArgs ), papszArgs );
1461
+ strcpy (szLongLat , "+proj=longlat " );
1462
+ GTIFProj4AppendEllipsoid (psDefn , szLongLat );
1440
1463
1441
- CSLDestroy ( papszArgs );
1464
+ psPJ = proj_create_crs_to_crs ( ctx , pszProjection , szLongLat , NULL );
1465
+ CPLFree ( pszProjection );
1442
1466
1443
1467
if ( psPJ == NULL )
1444
1468
{
1469
+ proj_context_destroy (ctx );
1445
1470
return FALSE;
1446
1471
}
1447
1472
@@ -1450,18 +1475,20 @@ int GTIFProj4ToLatLong( GTIFDefn * psDefn, int nPoints,
1450
1475
/* -------------------------------------------------------------------- */
1451
1476
for ( i = 0 ; i < nPoints ; i ++ )
1452
1477
{
1453
- projUV sUV ;
1454
-
1455
- sUV .u = padfX [i ];
1456
- sUV .v = padfY [i ];
1478
+ PJ_COORD coord ;
1479
+ coord .xyzt .x = padfX [i ];
1480
+ coord .xyzt .y = padfY [i ];
1481
+ coord .xyzt .z = 0 ;
1482
+ coord .xyzt .t = 0 ;
1457
1483
1458
- sUV = pj_inv ( sUV , psPJ );
1484
+ coord = proj_trans ( psPJ , PJ_FWD , coord );
1459
1485
1460
- padfX [i ] = sUV . u * RAD_TO_DEG ;
1461
- padfY [i ] = sUV . v * RAD_TO_DEG ;
1486
+ padfX [i ] = coord . xyzt . x ;
1487
+ padfY [i ] = coord . xyzt . y ;
1462
1488
}
1463
1489
1464
- pj_free ( psPJ );
1490
+ proj_destroy ( psPJ );
1491
+ proj_context_destroy (ctx );
1465
1492
1466
1493
return TRUE;
1467
1494
}
0 commit comments