Skip to content

Commit ce8307f

Browse files
committed
Internal libgeotiff: resync with upstream
1 parent c75fd78 commit ce8307f

File tree

2 files changed

+95
-60
lines changed

2 files changed

+95
-60
lines changed

gdal/frmts/gtiff/libgeotiff/geo_normalize.c

+8
Original file line numberDiff line numberDiff line change
@@ -2721,12 +2721,20 @@ const char *GTIFDecToDMS( double dfAngle, const char * pszAxis,
27212721
double dfRound;
27222722
int i;
27232723

2724+
if( !(dfAngle >= -360 && dfAngle <= 360) )
2725+
return "";
2726+
27242727
dfRound = 0.5/60;
27252728
for( i = 0; i < nPrecision; i++ )
27262729
dfRound = dfRound * 0.1;
27272730

27282731
nDegrees = (int) ABS(dfAngle);
27292732
nMinutes = (int) ((ABS(dfAngle) - nDegrees) * 60 + dfRound);
2733+
if( nMinutes == 60 )
2734+
{
2735+
nDegrees ++;
2736+
nMinutes = 0;
2737+
}
27302738
dfSeconds = ABS((ABS(dfAngle) * 3600 - nDegrees*3600 - nMinutes*60));
27312739

27322740
if( EQUAL(pszAxis,"Long") && dfAngle < 0.0 )

gdal/frmts/gtiff/libgeotiff/geotiff_proj4.c

+87-60
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@
3434
#include "geo_normalize.h"
3535
#include "geovalues.h"
3636
#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+
}
3767

3868
/************************************************************************/
3969
/* OSRProj4Tokenize() */
@@ -940,6 +970,21 @@ char * GTIFGetProj4Defn( GTIFDefn * psDefn )
940970
dfFalseNorthing );
941971
}
942972

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+
943988
/* -------------------------------------------------------------------- */
944989
/* Mercator */
945990
/* -------------------------------------------------------------------- */
@@ -1313,27 +1358,8 @@ char * GTIFGetProj4Defn( GTIFDefn * psDefn )
13131358
}*/
13141359
}
13151360
}
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);
13371363

13381364
strcat( szProjection, szUnits );
13391365

@@ -1343,9 +1369,6 @@ char * GTIFGetProj4Defn( GTIFDefn * psDefn )
13431369
return CPLStrdup( szProjection );
13441370
}
13451371

1346-
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
1347-
#include "proj_api.h"
1348-
13491372
/************************************************************************/
13501373
/* GTIFProj4FromLatLong() */
13511374
/* */
@@ -1357,9 +1380,11 @@ int GTIFProj4FromLatLong( GTIFDefn * psDefn, int nPoints,
13571380
double *padfX, double *padfY )
13581381

13591382
{
1360-
char *pszProjection, **papszArgs;
1361-
projPJ *psPJ;
1383+
char szLongLat[256];
1384+
char *pszProjection;
1385+
PJ *psPJ;
13621386
int i;
1387+
PJ_CONTEXT* ctx;
13631388

13641389
/* -------------------------------------------------------------------- */
13651390
/* Get a projection definition. */
@@ -1369,19 +1394,17 @@ int GTIFProj4FromLatLong( GTIFDefn * psDefn, int nPoints,
13691394
if( pszProjection == NULL )
13701395
return FALSE;
13711396

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();
13781398

1379-
psPJ = pj_init( CSLCount(papszArgs), papszArgs );
1399+
strcpy(szLongLat, "+proj=longlat ");
1400+
GTIFProj4AppendEllipsoid(psDefn, szLongLat);
13801401

1381-
CSLDestroy( papszArgs );
1402+
psPJ = proj_create_crs_to_crs( ctx, szLongLat, pszProjection, NULL );
1403+
CPLFree( pszProjection );
13821404

13831405
if( psPJ == NULL )
13841406
{
1407+
proj_context_destroy(ctx);
13851408
return FALSE;
13861409
}
13871410

@@ -1390,18 +1413,20 @@ int GTIFProj4FromLatLong( GTIFDefn * psDefn, int nPoints,
13901413
/* -------------------------------------------------------------------- */
13911414
for( i = 0; i < nPoints; i++ )
13921415
{
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;
13941421

1395-
sUV.u = padfX[i] * DEG_TO_RAD;
1396-
sUV.v = padfY[i] * DEG_TO_RAD;
1422+
coord = proj_trans(psPJ, PJ_FWD, coord);
13971423

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;
14021426
}
14031427

1404-
pj_free( psPJ );
1428+
proj_destroy( psPJ );
1429+
proj_context_destroy(ctx);
14051430

14061431
return TRUE;
14071432
}
@@ -1417,9 +1442,11 @@ int GTIFProj4ToLatLong( GTIFDefn * psDefn, int nPoints,
14171442
double *padfX, double *padfY )
14181443

14191444
{
1420-
char *pszProjection, **papszArgs;
1421-
projPJ *psPJ;
1445+
char szLongLat[256];
1446+
char *pszProjection;
1447+
PJ *psPJ;
14221448
int i;
1449+
PJ_CONTEXT* ctx;
14231450

14241451
/* -------------------------------------------------------------------- */
14251452
/* Get a projection definition. */
@@ -1429,19 +1456,17 @@ int GTIFProj4ToLatLong( GTIFDefn * psDefn, int nPoints,
14291456
if( pszProjection == NULL )
14301457
return FALSE;
14311458

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();
14381460

1439-
psPJ = pj_init( CSLCount(papszArgs), papszArgs );
1461+
strcpy(szLongLat, "+proj=longlat ");
1462+
GTIFProj4AppendEllipsoid(psDefn, szLongLat);
14401463

1441-
CSLDestroy( papszArgs );
1464+
psPJ = proj_create_crs_to_crs( ctx, pszProjection, szLongLat, NULL );
1465+
CPLFree( pszProjection );
14421466

14431467
if( psPJ == NULL )
14441468
{
1469+
proj_context_destroy(ctx);
14451470
return FALSE;
14461471
}
14471472

@@ -1450,18 +1475,20 @@ int GTIFProj4ToLatLong( GTIFDefn * psDefn, int nPoints,
14501475
/* -------------------------------------------------------------------- */
14511476
for( i = 0; i < nPoints; i++ )
14521477
{
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;
14571483

1458-
sUV = pj_inv( sUV, psPJ );
1484+
coord = proj_trans(psPJ, PJ_FWD, coord);
14591485

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;
14621488
}
14631489

1464-
pj_free( psPJ );
1490+
proj_destroy( psPJ );
1491+
proj_context_destroy(ctx);
14651492

14661493
return TRUE;
14671494
}

0 commit comments

Comments
 (0)