"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "geo_normalize.c" between
libgeotiff-1.5.1.tar.gz and libgeotiff-1.6.0.tar.gz

About: libgeotiff is a library (built on top of libtiff) for reading and writing coordinate system information from and to GeoTIFF files (GeoTIFF establishes a TIFF based interchange format for georeferenced raster imagery).

geo_normalize.c  (libgeotiff-1.5.1):geo_normalize.c  (libgeotiff-1.6.0)
skipping to change at line 108 skipping to change at line 108
# define CPL_UNUSED __attribute((__unused__)) # define CPL_UNUSED __attribute((__unused__))
#else #else
/* TODO: add cases for other compilers */ /* TODO: add cases for other compilers */
# define CPL_UNUSED # define CPL_UNUSED
#endif #endif
#endif #endif
CPL_INLINE static void CPL_IGNORE_RET_VAL_INT(CPL_UNUSED int unused) {} CPL_INLINE static void CPL_IGNORE_RET_VAL_INT(CPL_UNUSED int unused) {}
/************************************************************************/ /************************************************************************/
/* GTIFKeyGetSSHORT() */
/************************************************************************/
// Geotiff SHORT keys are supposed to be unsigned, but geo_normalize interface
// uses signed short...
static int GTIFKeyGetSSHORT( GTIF *gtif, geokey_t key, short* pnVal )
{
unsigned short sVal;
if( GTIFKeyGetSHORT(gtif, key, &sVal, 0, 1) == 1 )
{
memcpy(pnVal, &sVal, 2);
return 1;
}
return 0;
}
/************************************************************************/
/* GTIFGetPCSInfo() */ /* GTIFGetPCSInfo() */
/************************************************************************/ /************************************************************************/
static int GTIFGetPCSInfoEx( void* ctxIn,
int GTIFGetPCSInfoEx( PJ_CONTEXT* ctx,
int nPCSCode, char **ppszEPSGName, int nPCSCode, char **ppszEPSGName,
short *pnProjOp, short *pnUOMLengthCode, short *pnProjOp, short *pnUOMLengthCode,
short *pnGeogCS ) short *pnGeogCS )
{ {
PJ_CONTEXT* ctx = (PJ_CONTEXT*)ctxIn;
int nDatum; int nDatum;
int nZone; int nZone;
/* Deal with a few well known CRS */ /* Deal with a few well known CRS */
int Proj = GTIFPCSToMapSys( nPCSCode, &nDatum, &nZone ); int Proj = GTIFPCSToMapSys( nPCSCode, &nDatum, &nZone );
if ((Proj == MapSys_UTM_North || Proj == MapSys_UTM_South) && if ((Proj == MapSys_UTM_North || Proj == MapSys_UTM_South) &&
nDatum != KvUserDefined) nDatum != KvUserDefined)
{ {
const char* pszDatumName = NULL; const char* pszDatumName = NULL;
switch (nDatum) switch (nDatum)
skipping to change at line 160 skipping to change at line 177
if (pnUOMLengthCode) if (pnUOMLengthCode)
*pnUOMLengthCode = 9001; /* Linear_Meter */ *pnUOMLengthCode = 9001; /* Linear_Meter */
if (pnGeogCS) if (pnGeogCS)
*pnGeogCS = (short) nDatum; *pnGeogCS = (short) nDatum;
return TRUE; return TRUE;
} }
} }
if( nPCSCode == KvUserDefined )
return FALSE;
{ {
char szCode[12]; char szCode[12];
PJ* proj_crs; PJ* proj_crs;
sprintf(szCode, "%d", nPCSCode); sprintf(szCode, "%d", nPCSCode);
proj_crs = proj_create_from_database( proj_crs = proj_create_from_database(
ctx, "EPSG", szCode, PJ_CATEGORY_CRS, 0, NULL); ctx, "EPSG", szCode, PJ_CATEGORY_CRS, 0, NULL);
if( !proj_crs ) if( !proj_crs )
{ {
return FALSE; return FALSE;
skipping to change at line 394 skipping to change at line 414
return dfAngle; return dfAngle;
} }
/************************************************************************/ /************************************************************************/
/* GTIFGetGCSInfo() */ /* GTIFGetGCSInfo() */
/* */ /* */
/* Fetch the datum, and prime meridian related to a particular */ /* Fetch the datum, and prime meridian related to a particular */
/* GCS. */ /* GCS. */
/************************************************************************/ /************************************************************************/
static int GTIFGetGCSInfoEx( void* ctxIn,
int GTIFGetGCSInfoEx( PJ_CONTEXT* ctx,
int nGCSCode, char ** ppszName, int nGCSCode, char ** ppszName,
short * pnDatum, short * pnPM, short *pnUOMAngle ) short * pnDatum, short * pnPM, short *pnUOMAngle )
{ {
PJ_CONTEXT* ctx = (PJ_CONTEXT*)ctxIn;
int nDatum=0, nPM, nUOMAngle; int nDatum=0, nPM, nUOMAngle;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Handle some "well known" GCS codes directly */ /* Handle some "well known" GCS codes directly */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
const char * pszName = NULL; const char * pszName = NULL;
nPM = PM_Greenwich; nPM = PM_Greenwich;
nUOMAngle = Angular_DMS_Hemisphere; nUOMAngle = Angular_DMS_Hemisphere;
if( nGCSCode == GCS_NAD27 ) if( nGCSCode == GCS_NAD27 )
{ {
skipping to change at line 447 skipping to change at line 467
if( pnDatum != NULL ) if( pnDatum != NULL )
*pnDatum = (short) nDatum; *pnDatum = (short) nDatum;
if( pnPM != NULL ) if( pnPM != NULL )
*pnPM = (short) nPM; *pnPM = (short) nPM;
if( pnUOMAngle != NULL ) if( pnUOMAngle != NULL )
*pnUOMAngle = (short) nUOMAngle; *pnUOMAngle = (short) nUOMAngle;
return TRUE; return TRUE;
} }
if( nGCSCode == KvUserDefined )
return FALSE;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Search the database. */ /* Search the database. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
{ {
char szCode[12]; char szCode[12];
PJ* geod_crs; PJ* geod_crs;
sprintf(szCode, "%d", nGCSCode); sprintf(szCode, "%d", nGCSCode);
geod_crs = proj_create_from_database( geod_crs = proj_create_from_database(
skipping to change at line 578 skipping to change at line 601
} }
/************************************************************************/ /************************************************************************/
/* GTIFGetEllipsoidInfo() */ /* GTIFGetEllipsoidInfo() */
/* */ /* */
/* Fetch info about an ellipsoid. Axes are always returned in */ /* Fetch info about an ellipsoid. Axes are always returned in */
/* meters. SemiMajor computed based on inverse flattening */ /* meters. SemiMajor computed based on inverse flattening */
/* where that is provided. */ /* where that is provided. */
/************************************************************************/ /************************************************************************/
static int GTIFGetEllipsoidInfoEx( void* ctxIn,
int GTIFGetEllipsoidInfoEx( PJ_CONTEXT* ctx,
int nEllipseCode, char ** ppszName, int nEllipseCode, char ** ppszName,
double * pdfSemiMajor, double * pdfSemiMinor ) double * pdfSemiMajor, double * pdfSemiMinor )
{ {
PJ_CONTEXT* ctx = (PJ_CONTEXT*)ctxIn;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Try some well known ellipsoids. */ /* Try some well known ellipsoids. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
double dfSemiMajor=0.0; double dfSemiMajor=0.0;
double dfInvFlattening=0.0, dfSemiMinor=0.0; double dfInvFlattening=0.0, dfSemiMinor=0.0;
const char *pszName = NULL; const char *pszName = NULL;
if( nEllipseCode == Ellipse_Clarke_1866 ) if( nEllipseCode == Ellipse_Clarke_1866 )
{ {
pszName = "Clarke 1866"; pszName = "Clarke 1866";
skipping to change at line 635 skipping to change at line 658
if( pdfSemiMinor != NULL ) if( pdfSemiMinor != NULL )
*pdfSemiMinor = dfSemiMinor; *pdfSemiMinor = dfSemiMinor;
if( pdfSemiMajor != NULL ) if( pdfSemiMajor != NULL )
*pdfSemiMajor = dfSemiMajor; *pdfSemiMajor = dfSemiMajor;
if( ppszName != NULL ) if( ppszName != NULL )
*ppszName = CPLStrdup( pszName ); *ppszName = CPLStrdup( pszName );
return TRUE; return TRUE;
} }
if( nEllipseCode == KvUserDefined )
return FALSE;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Search the database. */ /* Search the database. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
{ {
char szCode[12]; char szCode[12];
PJ* ellipsoid; PJ* ellipsoid;
sprintf(szCode, "%d", nEllipseCode); sprintf(szCode, "%d", nEllipseCode);
ellipsoid = proj_create_from_database( ellipsoid = proj_create_from_database(
ctx, "EPSG", szCode, PJ_CATEGORY_ELLIPSOID, 0, NULL); ctx, "EPSG", szCode, PJ_CATEGORY_ELLIPSOID, 0, NULL);
skipping to change at line 689 skipping to change at line 715
return ret; return ret;
} }
/************************************************************************/ /************************************************************************/
/* GTIFGetPMInfo() */ /* GTIFGetPMInfo() */
/* */ /* */
/* Get the offset between a given prime meridian and Greenwich */ /* Get the offset between a given prime meridian and Greenwich */
/* in degrees. */ /* in degrees. */
/************************************************************************/ /************************************************************************/
static int GTIFGetPMInfoEx( void* ctxIn,
int GTIFGetPMInfoEx( PJ_CONTEXT* ctx,
int nPMCode, char ** ppszName, double *pdfOffset ) int nPMCode, char ** ppszName, double *pdfOffset )
{ {
PJ_CONTEXT* ctx = (PJ_CONTEXT*)ctxIn;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Use a special short cut for Greenwich, since it is so common. */ /* Use a special short cut for Greenwich, since it is so common. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
if( nPMCode == PM_Greenwich ) if( nPMCode == PM_Greenwich )
{ {
if( pdfOffset != NULL ) if( pdfOffset != NULL )
*pdfOffset = 0.0; *pdfOffset = 0.0;
if( ppszName != NULL ) if( ppszName != NULL )
*ppszName = CPLStrdup( "Greenwich" ); *ppszName = CPLStrdup( "Greenwich" );
return TRUE; return TRUE;
} }
if( nPMCode == KvUserDefined )
return FALSE;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Search the database. */ /* Search the database. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
{ {
char szCode[12]; char szCode[12];
PJ* pm; PJ* pm;
sprintf(szCode, "%d", nPMCode); sprintf(szCode, "%d", nPMCode);
pm = proj_create_from_database( pm = proj_create_from_database(
ctx, "EPSG", szCode, PJ_CATEGORY_PRIME_MERIDIAN, 0, NULL); ctx, "EPSG", szCode, PJ_CATEGORY_PRIME_MERIDIAN, 0, NULL);
skipping to change at line 762 skipping to change at line 792
proj_context_destroy(ctx); proj_context_destroy(ctx);
return ret; return ret;
} }
/************************************************************************/ /************************************************************************/
/* GTIFGetDatumInfo() */ /* GTIFGetDatumInfo() */
/* */ /* */
/* Fetch the ellipsoid, and name for a datum. */ /* Fetch the ellipsoid, and name for a datum. */
/************************************************************************/ /************************************************************************/
static int GTIFGetDatumInfoEx( void* ctxIn,
int GTIFGetDatumInfoEx( PJ_CONTEXT* ctx,
int nDatumCode, char ** ppszName, short * pnEllipsoid ) int nDatumCode, char ** ppszName, short * pnEllipsoid )
{ {
PJ_CONTEXT* ctx = (PJ_CONTEXT*)ctxIn;
const char* pszName = NULL; const char* pszName = NULL;
int nEllipsoid = 0; int nEllipsoid = 0;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Handle a few built-in datums. */ /* Handle a few built-in datums. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
if( nDatumCode == Datum_North_American_Datum_1927 ) if( nDatumCode == Datum_North_American_Datum_1927 )
{ {
nEllipsoid = Ellipse_Clarke_1866; nEllipsoid = Ellipse_Clarke_1866;
pszName = "North American Datum 1927"; pszName = "North American Datum 1927";
skipping to change at line 805 skipping to change at line 835
{ {
if( pnEllipsoid != NULL ) if( pnEllipsoid != NULL )
*pnEllipsoid = (short) nEllipsoid; *pnEllipsoid = (short) nEllipsoid;
if( ppszName != NULL ) if( ppszName != NULL )
*ppszName = CPLStrdup( pszName ); *ppszName = CPLStrdup( pszName );
return TRUE; return TRUE;
} }
if( nDatumCode == KvUserDefined )
return FALSE;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Search the database. */ /* Search the database. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
{ {
char szCode[12]; char szCode[12];
PJ* datum; PJ* datum;
sprintf(szCode, "%d", nDatumCode); sprintf(szCode, "%d", nDatumCode);
datum = proj_create_from_database( datum = proj_create_from_database(
ctx, "EPSG", szCode, PJ_CATEGORY_DATUM, 0, NULL); ctx, "EPSG", szCode, PJ_CATEGORY_DATUM, 0, NULL);
skipping to change at line 879 skipping to change at line 912
return ret; return ret;
} }
/************************************************************************/ /************************************************************************/
/* GTIFGetUOMLengthInfo() */ /* GTIFGetUOMLengthInfo() */
/* */ /* */
/* Note: This function should eventually also know how to */ /* Note: This function should eventually also know how to */
/* lookup length aliases in the UOM_LE_ALIAS table. */ /* lookup length aliases in the UOM_LE_ALIAS table. */
/************************************************************************/ /************************************************************************/
static int GTIFGetUOMLengthInfoEx( void* ctxIn,
int GTIFGetUOMLengthInfoEx( PJ_CONTEXT* ctx,
int nUOMLengthCode, int nUOMLengthCode,
char **ppszUOMName, char **ppszUOMName,
double * pdfInMeters ) double * pdfInMeters )
{ {
PJ_CONTEXT* ctx = (PJ_CONTEXT*)ctxIn;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* We short cut meter to save work and avoid failure for missing */ /* We short cut meter to save work and avoid failure for missing */
/* in the most common cases. */ /* in the most common cases. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
if( nUOMLengthCode == 9001 ) if( nUOMLengthCode == 9001 )
{ {
if( ppszUOMName != NULL ) if( ppszUOMName != NULL )
*ppszUOMName = CPLStrdup( "metre" ); *ppszUOMName = CPLStrdup( "metre" );
if( pdfInMeters != NULL ) if( pdfInMeters != NULL )
*pdfInMeters = 1.0; *pdfInMeters = 1.0;
skipping to change at line 920 skipping to change at line 953
if( nUOMLengthCode == 9003 ) if( nUOMLengthCode == 9003 )
{ {
if( ppszUOMName != NULL ) if( ppszUOMName != NULL )
*ppszUOMName = CPLStrdup( "US survey foot" ); *ppszUOMName = CPLStrdup( "US survey foot" );
if( pdfInMeters != NULL ) if( pdfInMeters != NULL )
*pdfInMeters = 12.0 / 39.37; *pdfInMeters = 12.0 / 39.37;
return TRUE; return TRUE;
} }
if( nUOMLengthCode == KvUserDefined )
return FALSE;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Search the units database for this unit. If we don't find */ /* Search the units database for this unit. If we don't find */
/* it return failure. */ /* it return failure. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
{ {
char szCode[12]; char szCode[12];
const char* pszName = NULL; const char* pszName = NULL;
sprintf(szCode, "%d", nUOMLengthCode); sprintf(szCode, "%d", nUOMLengthCode);
if( !proj_uom_get_info_from_database( if( !proj_uom_get_info_from_database(
skipping to change at line 958 skipping to change at line 994
int ret = GTIFGetUOMLengthInfoEx( int ret = GTIFGetUOMLengthInfoEx(
ctx, nUOMLengthCode, ppszUOMName, pdfInMeters); ctx, nUOMLengthCode, ppszUOMName, pdfInMeters);
proj_context_destroy(ctx); proj_context_destroy(ctx);
return ret; return ret;
} }
/************************************************************************/ /************************************************************************/
/* GTIFGetUOMAngleInfo() */ /* GTIFGetUOMAngleInfo() */
/************************************************************************/ /************************************************************************/
static int GTIFGetUOMAngleInfoEx( void* ctxIn,
int GTIFGetUOMAngleInfoEx( PJ_CONTEXT* ctx,
int nUOMAngleCode, int nUOMAngleCode,
char **ppszUOMName, char **ppszUOMName,
double * pdfInDegrees ) double * pdfInDegrees )
{ {
PJ_CONTEXT* ctx = (PJ_CONTEXT*)ctxIn;
const char *pszUOMName = NULL; const char *pszUOMName = NULL;
double dfInDegrees = 1.0; double dfInDegrees = 1.0;
switch( nUOMAngleCode ) switch( nUOMAngleCode )
{ {
case 9101: case 9101:
pszUOMName = "radian"; pszUOMName = "radian";
dfInDegrees = 180.0 / M_PI; dfInDegrees = 180.0 / M_PI;
break; break;
skipping to change at line 1378 skipping to change at line 1414
/************************************************************************/ /************************************************************************/
/* GTIFGetProjTRFInfo() */ /* GTIFGetProjTRFInfo() */
/* */ /* */
/* Transform a PROJECTION_TRF_CODE into a projection method, */ /* Transform a PROJECTION_TRF_CODE into a projection method, */
/* and a set of parameters. The parameters identify will */ /* and a set of parameters. The parameters identify will */
/* depend on the returned method, but they will all have been */ /* depend on the returned method, but they will all have been */
/* normalized into degrees and meters. */ /* normalized into degrees and meters. */
/************************************************************************/ /************************************************************************/
static int GTIFGetProjTRFInfoEx( void* ctxIn,
int GTIFGetProjTRFInfoEx( PJ_CONTEXT* ctx,
int nProjTRFCode, int nProjTRFCode,
char **ppszProjTRFName, char **ppszProjTRFName,
short * pnProjMethod, short * pnProjMethod,
double * padfProjParms ) double * padfProjParms )
{ {
PJ_CONTEXT* ctx = (PJ_CONTEXT*)ctxIn;
if ((nProjTRFCode >= Proj_UTM_zone_1N && nProjTRFCode <= Proj_UTM_zone_60N) || if ((nProjTRFCode >= Proj_UTM_zone_1N && nProjTRFCode <= Proj_UTM_zone_60N) ||
(nProjTRFCode >= Proj_UTM_zone_1S && nProjTRFCode <= Proj_UTM_zone_60S)) (nProjTRFCode >= Proj_UTM_zone_1S && nProjTRFCode <= Proj_UTM_zone_60S))
{ {
int bNorth; int bNorth;
int nZone; int nZone;
if (nProjTRFCode <= Proj_UTM_zone_60N) if (nProjTRFCode <= Proj_UTM_zone_60N)
{ {
bNorth = TRUE; bNorth = TRUE;
nZone = nProjTRFCode - Proj_UTM_zone_1N + 1; nZone = nProjTRFCode - Proj_UTM_zone_1N + 1;
} }
skipping to change at line 1427 skipping to change at line 1464
padfProjParms[2] = 0; padfProjParms[2] = 0;
padfProjParms[3] = 0; padfProjParms[3] = 0;
padfProjParms[4] = 0.9996; padfProjParms[4] = 0.9996;
padfProjParms[5] = 500000; padfProjParms[5] = 500000;
padfProjParms[6] = (bNorth) ? 0 : 10000000; padfProjParms[6] = (bNorth) ? 0 : 10000000;
} }
return TRUE; return TRUE;
} }
if( nProjTRFCode == KvUserDefined )
return FALSE;
{ {
int nProjMethod, i, anEPSGCodes[7]; int nProjMethod, i, anEPSGCodes[7];
double adfProjParms[7]; double adfProjParms[7];
char szCode[12]; char szCode[12];
const char* pszMethodCode = NULL; const char* pszMethodCode = NULL;
int nCTProjMethod; int nCTProjMethod;
PJ *transf; PJ *transf;
sprintf(szCode, "%d", nProjTRFCode); sprintf(szCode, "%d", nProjTRFCode);
transf = proj_create_from_database( transf = proj_create_from_database(
skipping to change at line 1618 skipping to change at line 1658
double * padfProjParms ) double * padfProjParms )
{ {
PJ_CONTEXT* ctx = proj_context_create(); PJ_CONTEXT* ctx = proj_context_create();
int ret = GTIFGetProjTRFInfoEx( int ret = GTIFGetProjTRFInfoEx(
ctx, nProjTRFCode, ppszProjTRFName, pnProjMethod, padfProjParms); ctx, nProjTRFCode, ppszProjTRFName, pnProjMethod, padfProjParms);
proj_context_destroy(ctx); proj_context_destroy(ctx);
return ret; return ret;
} }
/************************************************************************/ /************************************************************************/
/* GTIFKeyGetInternal() */
/************************************************************************/
static int GTIFKeyGetInternal( GTIF *psGTIF, geokey_t key,
void* pData,
int nIndex,
int nCount,
tagtype_t expected_tagtype )
{
tagtype_t tagtype;
if( !GTIFKeyInfo(psGTIF, key, NULL, &tagtype) )
return 0;
if( tagtype != expected_tagtype )
{
if( psGTIF->gt_error_callback )
{
psGTIF->gt_error_callback(
psGTIF,
LIBGEOTIFF_WARNING,
"Expected key %s to be of type %s. Got %s",
GTIFKeyName(key), GTIFTypeName(expected_tagtype),
GTIFTypeName(tagtype));
}
return 0;
}
return GTIFKeyGet( psGTIF, key, pData, nIndex, nCount );
}
/************************************************************************/
/* GTIFKeyGetSHORT() */
/************************************************************************/
static int GTIFKeyGetSHORT( GTIF *psGTIF, geokey_t key,
short* pnVal,
int nIndex,
int nCount )
{
return GTIFKeyGetInternal(psGTIF, key, pnVal, nIndex, nCount, TYPE_SHORT);
}
/************************************************************************/
/* GDALGTIFKeyGetDOUBLE() */
/************************************************************************/
static int GTIFKeyGetDOUBLE( GTIF *psGTIF, geokey_t key,
double* pdfVal,
int nIndex,
int nCount )
{
return GTIFKeyGetInternal(psGTIF, key, pdfVal, nIndex, nCount, TYPE_DOUBLE);
}
/************************************************************************/
/* GTIFFetchProjParms() */ /* GTIFFetchProjParms() */
/* */ /* */
/* Fetch the projection parameters for a particular projection */ /* Fetch the projection parameters for a particular projection */
/* from a GeoTIFF file, and fill the GTIFDefn structure out */ /* from a GeoTIFF file, and fill the GTIFDefn structure out */
/* with them. */ /* with them. */
/************************************************************************/ /************************************************************************/
static void GTIFFetchProjParms( GTIF * psGTIF, GTIFDefn * psDefn ) static void GTIFFetchProjParms( GTIF * psGTIF, GTIFDefn * psDefn )
{ {
skipping to change at line 2463 skipping to change at line 2450
if( nKeyCount == 0 ) if( nKeyCount == 0 )
{ {
psDefn->DefnSet = 0; psDefn->DefnSet = 0;
return FALSE; return FALSE;
} }
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Try to get the overall model type. */ /* Try to get the overall model type. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
GTIFKeyGetSHORT(psGTIF,GTModelTypeGeoKey,&(psDefn->Model),0,1); GTIFKeyGetSSHORT(psGTIF,GTModelTypeGeoKey,&(psDefn->Model));
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Extract the Geog units. */ /* Extract the Geog units. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
nGeogUOMLinear = 9001; /* Linear_Meter */ nGeogUOMLinear = 9001; /* Linear_Meter */
GTIFKeyGetSHORT(psGTIF, GeogLinearUnitsGeoKey, &nGeogUOMLinear, 0, 1 ); if( GTIFKeyGetSSHORT(psGTIF, GeogLinearUnitsGeoKey, &nGeogUOMLinear) == 1 )
{
psDefn->UOMLength = nGeogUOMLinear;
}
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Try to get a PCS. */ /* Try to get a PCS. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
if( GTIFKeyGetSHORT(psGTIF,ProjectedCSTypeGeoKey, &(psDefn->PCS),0,1) == 1 if( GTIFKeyGetSSHORT(psGTIF,ProjectedCSTypeGeoKey, &(psDefn->PCS)) == 1
&& psDefn->PCS != KvUserDefined ) && psDefn->PCS != KvUserDefined )
{ {
/* /*
* Translate this into useful information. * Translate this into useful information.
*/ */
GTIFGetPCSInfoEx( psGTIF->pj_context, GTIFGetPCSInfoEx( psGTIF->pj_context,
psDefn->PCS, NULL, &(psDefn->ProjCode), psDefn->PCS, NULL, &(psDefn->ProjCode),
&(psDefn->UOMLength), &(psDefn->GCS) ); &(psDefn->UOMLength), &(psDefn->GCS) );
} }
skipping to change at line 2507 skipping to change at line 2497
{ {
psDefn->ProjCode = (short) GTIFMapSysToProj( nMapSys, nZone ); psDefn->ProjCode = (short) GTIFMapSysToProj( nMapSys, nZone );
psDefn->GCS = (short) nGCS; psDefn->GCS = (short) nGCS;
} }
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* If the Proj_ code is specified directly, use that. */ /* If the Proj_ code is specified directly, use that. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
if( psDefn->ProjCode == KvUserDefined ) if( psDefn->ProjCode == KvUserDefined )
GTIFKeyGetSHORT(psGTIF, ProjectionGeoKey, &(psDefn->ProjCode), 0, 1 ); GTIFKeyGetSSHORT(psGTIF, ProjectionGeoKey, &(psDefn->ProjCode));
if( psDefn->ProjCode != KvUserDefined ) if( psDefn->ProjCode != KvUserDefined )
{ {
/* /*
* We have an underlying projection transformation value. Look * We have an underlying projection transformation value. Look
* this up. For a PCS of ``WGS 84 / UTM 11'' the transformation * this up. For a PCS of ``WGS 84 / UTM 11'' the transformation
* would be Transverse Mercator, with a particular set of options. * would be Transverse Mercator, with a particular set of options.
* The nProjTRFCode itself would correspond to the name * The nProjTRFCode itself would correspond to the name
* ``UTM zone 11N'', and doesn't include datum info. * ``UTM zone 11N'', and doesn't include datum info.
*/ */
skipping to change at line 2538 skipping to change at line 2528
SetGTParmIds( EPSGProjMethodToCTProjMethod(psDefn->Projection, TRUE), SetGTParmIds( EPSGProjMethodToCTProjMethod(psDefn->Projection, TRUE),
psDefn->Projection, psDefn->Projection,
psDefn->ProjParmId, NULL); psDefn->ProjParmId, NULL);
psDefn->nParms = 7; psDefn->nParms = 7;
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Try to get a GCS. If found, it will override any implied by */ /* Try to get a GCS. If found, it will override any implied by */
/* the PCS. */ /* the PCS. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
GTIFKeyGetSHORT(psGTIF, GeographicTypeGeoKey, &(psDefn->GCS), 0, 1 ); GTIFKeyGetSSHORT(psGTIF, GeographicTypeGeoKey, &(psDefn->GCS));
if( psDefn->GCS < 1 || psDefn->GCS >= KvUserDefined ) if( psDefn->GCS < 1 || psDefn->GCS >= KvUserDefined )
psDefn->GCS = KvUserDefined; psDefn->GCS = KvUserDefined;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Derive the datum, and prime meridian from the GCS. */ /* Derive the datum, and prime meridian from the GCS. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
if( psDefn->GCS != KvUserDefined ) if( psDefn->GCS != KvUserDefined )
{ {
GTIFGetGCSInfoEx( psGTIF->pj_context, GTIFGetGCSInfoEx( psGTIF->pj_context,
psDefn->GCS, NULL, &(psDefn->Datum), &(psDefn->PM), psDefn->GCS, NULL, &(psDefn->Datum), &(psDefn->PM),
&(psDefn->UOMAngle) ); &(psDefn->UOMAngle) );
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Handle the GCS angular units. GeogAngularUnitsGeoKey */ /* Handle the GCS angular units. GeogAngularUnitsGeoKey */
/* overrides the GCS or PCS setting. */ /* overrides the GCS or PCS setting. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
GTIFKeyGetSHORT(psGTIF, GeogAngularUnitsGeoKey, &(psDefn->UOMAngle), 0, 1 ); GTIFKeyGetSSHORT(psGTIF, GeogAngularUnitsGeoKey, &(psDefn->UOMAngle));
if( psDefn->UOMAngle != KvUserDefined ) if( psDefn->UOMAngle != KvUserDefined )
{ {
GTIFGetUOMAngleInfoEx( psGTIF->pj_context, GTIFGetUOMAngleInfoEx( psGTIF->pj_context,
psDefn->UOMAngle, NULL, psDefn->UOMAngle, NULL,
&(psDefn->UOMAngleInDegrees) ); &(psDefn->UOMAngleInDegrees) );
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Check for a datum setting, and then use the datum to derive */ /* Check for a datum setting, and then use the datum to derive */
/* an ellipsoid. */ /* an ellipsoid. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
GTIFKeyGetSHORT(psGTIF, GeogGeodeticDatumGeoKey, &(psDefn->Datum), 0, 1 ); GTIFKeyGetSSHORT(psGTIF, GeogGeodeticDatumGeoKey, &(psDefn->Datum));
if( psDefn->Datum != KvUserDefined ) if( psDefn->Datum != KvUserDefined )
{ {
GTIFGetDatumInfoEx( psGTIF->pj_context, GTIFGetDatumInfoEx( psGTIF->pj_context,
psDefn->Datum, NULL, &(psDefn->Ellipsoid) ); psDefn->Datum, NULL, &(psDefn->Ellipsoid) );
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Check for an explicit ellipsoid. Use the ellipsoid to */ /* Check for an explicit ellipsoid. Use the ellipsoid to */
/* derive the ellipsoid characteristics, if possible. */ /* derive the ellipsoid characteristics, if possible. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
GTIFKeyGetSHORT(psGTIF, GeogEllipsoidGeoKey, &(psDefn->Ellipsoid), 0, 1 ); GTIFKeyGetSSHORT(psGTIF, GeogEllipsoidGeoKey, &(psDefn->Ellipsoid));
if( psDefn->Ellipsoid != KvUserDefined ) if( psDefn->Ellipsoid != KvUserDefined )
{ {
GTIFGetEllipsoidInfoEx( psGTIF->pj_context, GTIFGetEllipsoidInfoEx( psGTIF->pj_context,
psDefn->Ellipsoid, NULL, psDefn->Ellipsoid, NULL,
&(psDefn->SemiMajor), &(psDefn->SemiMinor) ); &(psDefn->SemiMajor), &(psDefn->SemiMinor) );
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Check for overridden ellipsoid parameters. It would be nice */ /* Check for overridden ellipsoid parameters. It would be nice */
skipping to change at line 2610 skipping to change at line 2600
if( dfInvFlattening != 0.0 ) if( dfInvFlattening != 0.0 )
psDefn->SemiMinor = psDefn->SemiMinor =
psDefn->SemiMajor * (1 - 1.0/dfInvFlattening); psDefn->SemiMajor * (1 - 1.0/dfInvFlattening);
else else
psDefn->SemiMinor = psDefn->SemiMajor; psDefn->SemiMinor = psDefn->SemiMajor;
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Get the prime meridian info. */ /* Get the prime meridian info. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
GTIFKeyGetSHORT(psGTIF, GeogPrimeMeridianGeoKey, &(psDefn->PM), 0, 1 ); GTIFKeyGetSSHORT(psGTIF, GeogPrimeMeridianGeoKey, &(psDefn->PM));
if( psDefn->PM != KvUserDefined ) if( psDefn->PM != KvUserDefined )
{ {
GTIFGetPMInfoEx( psGTIF->pj_context, GTIFGetPMInfoEx( psGTIF->pj_context,
psDefn->PM, NULL, &(psDefn->PMLongToGreenwich) ); psDefn->PM, NULL, &(psDefn->PMLongToGreenwich) );
} }
else else
{ {
CPL_IGNORE_RET_VAL_INT(GTIFKeyGetDOUBLE(psGTIF, GeogPrimeMeridianLongGeo Key, CPL_IGNORE_RET_VAL_INT(GTIFKeyGetDOUBLE(psGTIF, GeogPrimeMeridianLongGeo Key,
&(psDefn->PMLongToGreenwich), 0, 1 )); &(psDefn->PMLongToGreenwich), 0, 1 ));
skipping to change at line 2641 skipping to change at line 2631
psDefn->TOWGS84Count = psDefn->TOWGS84Count =
(short)GTIFKeyGetDOUBLE(psGTIF, GeogTOWGS84GeoKey, psDefn->TOWGS84, 0, 7 ); (short)GTIFKeyGetDOUBLE(psGTIF, GeogTOWGS84GeoKey, psDefn->TOWGS84, 0, 7 );
#endif #endif
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Have the projection units of measure been overridden? We */ /* Have the projection units of measure been overridden? We */
/* should likely be doing something about angular units too, */ /* should likely be doing something about angular units too, */
/* but these are very rarely not decimal degrees for actual */ /* but these are very rarely not decimal degrees for actual */
/* file coordinates. */ /* file coordinates. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
GTIFKeyGetSHORT(psGTIF,ProjLinearUnitsGeoKey,&(psDefn->UOMLength),0,1); GTIFKeyGetSSHORT(psGTIF,ProjLinearUnitsGeoKey,&(psDefn->UOMLength));
if( psDefn->UOMLength != KvUserDefined ) if( psDefn->UOMLength != KvUserDefined )
{ {
GTIFGetUOMLengthInfoEx( psGTIF->pj_context, GTIFGetUOMLengthInfoEx( psGTIF->pj_context,
psDefn->UOMLength, NULL, psDefn->UOMLength, NULL,
&(psDefn->UOMLengthInMeters) ); &(psDefn->UOMLengthInMeters) );
} }
else else
{ {
CPL_IGNORE_RET_VAL_INT(GTIFKeyGetDOUBLE(psGTIF,ProjLinearUnitSizeGeoKey, &(psDefn->UOMLengthInMeters),0,1)); CPL_IGNORE_RET_VAL_INT(GTIFKeyGetDOUBLE(psGTIF,ProjLinearUnitSizeGeoKey, &(psDefn->UOMLengthInMeters),0,1));
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Handle a variety of user defined transform types. */ /* Handle a variety of user defined transform types. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
if( GTIFKeyGetSHORT(psGTIF,ProjCoordTransGeoKey, if( GTIFKeyGetSSHORT(psGTIF,ProjCoordTransGeoKey,
&(psDefn->CTProjection),0,1) == 1) &(psDefn->CTProjection)) == 1)
{ {
GTIFFetchProjParms( psGTIF, psDefn ); GTIFFetchProjParms( psGTIF, psDefn );
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Try to set the zoned map system information. */ /* Try to set the zoned map system information. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
psDefn->MapSys = GTIFProjToMapSys( psDefn->ProjCode, &(psDefn->Zone) ); psDefn->MapSys = GTIFProjToMapSys( psDefn->ProjCode, &(psDefn->Zone) );
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
skipping to change at line 2721 skipping to change at line 2711
{ {
int nDegrees, nMinutes; int nDegrees, nMinutes;
double dfSeconds; double dfSeconds;
char szFormat[30]; char szFormat[30];
static char szBuffer[50]; static char szBuffer[50];
const char *pszHemisphere = NULL; const char *pszHemisphere = NULL;
double dfRound; double dfRound;
int i; int i;
if( !(dfAngle >= -360 && dfAngle <= 360) )
return "";
dfRound = 0.5/60; dfRound = 0.5/60;
for( i = 0; i < nPrecision; i++ ) for( i = 0; i < nPrecision; i++ )
dfRound = dfRound * 0.1; dfRound = dfRound * 0.1;
nDegrees = (int) ABS(dfAngle); nDegrees = (int) ABS(dfAngle);
nMinutes = (int) ((ABS(dfAngle) - nDegrees) * 60 + dfRound); nMinutes = (int) ((ABS(dfAngle) - nDegrees) * 60 + dfRound);
if( nMinutes == 60 )
{
nDegrees ++;
nMinutes = 0;
}
dfSeconds = ABS((ABS(dfAngle) * 3600 - nDegrees*3600 - nMinutes*60)); dfSeconds = ABS((ABS(dfAngle) * 3600 - nDegrees*3600 - nMinutes*60));
if( EQUAL(pszAxis,"Long") && dfAngle < 0.0 ) if( EQUAL(pszAxis,"Long") && dfAngle < 0.0 )
pszHemisphere = "W"; pszHemisphere = "W";
else if( EQUAL(pszAxis,"Long") ) else if( EQUAL(pszAxis,"Long") )
pszHemisphere = "E"; pszHemisphere = "E";
else if( dfAngle < 0.0 ) else if( dfAngle < 0.0 )
pszHemisphere = "S"; pszHemisphere = "S";
else else
pszHemisphere = "N"; pszHemisphere = "N";
skipping to change at line 3050 skipping to change at line 3048
proj_context_destroy(psGTIF->pj_context); proj_context_destroy(psGTIF->pj_context);
} }
psGTIF->own_pj_context = FALSE; psGTIF->own_pj_context = FALSE;
psGTIF->pj_context = (PJ_CONTEXT*) pjContext; psGTIF->pj_context = (PJ_CONTEXT*) pjContext;
} }
/************************************************************************/ /************************************************************************/
/* GTIFGetPROJContext() */ /* GTIFGetPROJContext() */
/* */ /* */
/* Return the PROJ context attached to the GTIF handle. */ /* Return the PROJ context attached to the GTIF handle. */
/* If it has not yet been instanciated and instanciateIfNeeded=TRUE*/ /* If it has not yet been instantiated and instantiateIfNeeded=TRUE*/
/* then, it will be instanciated (and owned by GTIF handle). */ /* then, it will be instantiated (and owned by GTIF handle). */
/************************************************************************/ /************************************************************************/
void *GTIFGetPROJContext( GTIF *psGTIF, int instanciateIfNeeded, void *GTIFGetPROJContext( GTIF *psGTIF, int instantiateIfNeeded,
int* out_gtif_own_pj_context ) int* out_gtif_own_pj_context )
{ {
if( psGTIF->pj_context || !instanciateIfNeeded ) if( psGTIF->pj_context || !instantiateIfNeeded )
{ {
if( out_gtif_own_pj_context ) if( out_gtif_own_pj_context )
{ {
*out_gtif_own_pj_context = psGTIF->own_pj_context; *out_gtif_own_pj_context = psGTIF->own_pj_context;
} }
return psGTIF->pj_context; return psGTIF->pj_context;
} }
psGTIF->pj_context = proj_context_create(); psGTIF->pj_context = proj_context_create();
psGTIF->own_pj_context = psGTIF->pj_context != NULL; psGTIF->own_pj_context = psGTIF->pj_context != NULL;
if( out_gtif_own_pj_context ) if( out_gtif_own_pj_context )
 End of changes. 41 change blocks. 
85 lines changed or deleted 83 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)