geo_normalize.h File Reference

Include file for extended projection definition normalization api. More...

#include <stdio.h>
#include "geotiff.h"
Include dependency graph for geo_normalize.h:

Go to the source code of this file.

Data Structures

struct  GTIFDefn
 Holds a definition of a coordinate system in normalized form. More...

Defines

#define MAX_GTIF_PROJPARMS   10
#define MapSys_UTM_North   -9001
#define MapSys_UTM_South   -9002
#define MapSys_State_Plane_27   -9003
#define MapSys_State_Plane_83   -9004
#define HAVE_GTIFPROJ4

Functions

int CPL_DLL GTIFGetPCSInfo (int nPCSCode, char **ppszEPSGName, short *pnProjOp, short *pnUOMLengthCode, short *pnGeogCS)
int CPL_DLL GTIFGetProjTRFInfo (int nProjTRFCode, char **ppszProjTRFName, short *pnProjMethod, double *padfProjParms)
int CPL_DLL GTIFGetGCSInfo (int nGCSCode, char **ppszName, short *pnDatum, short *pnPM, short *pnUOMAngle)
int CPL_DLL GTIFGetDatumInfo (int nDatumCode, char **ppszName, short *pnEllipsoid)
int CPL_DLL GTIFGetEllipsoidInfo (int nEllipsoid, char **ppszName, double *pdfSemiMajor, double *pdfSemiMinor)
int CPL_DLL GTIFGetPMInfo (int nPM, char **ppszName, double *pdfLongToGreenwich)
double CPL_DLL GTIFAngleStringToDD (const char *pszAngle, int nUOMAngle)
int CPL_DLL GTIFGetUOMLengthInfo (int nUOMLengthCode, char **ppszUOMName, double *pdfInMeters)
int CPL_DLL GTIFGetUOMAngleInfo (int nUOMAngleCode, char **ppszUOMName, double *pdfInDegrees)
double CPL_DLL GTIFAngleToDD (double dfAngle, int nUOMAngle)
void CPL_DLL GTIFFreeMemory (char *)
void CPL_DLL GTIFDeaccessCSV (void)
int CPL_DLL GTIFGetDefn (GTIF *psGTIF, GTIFDefn *psDefn)
void CPL_DLL GTIFPrintDefn (GTIFDefn *, FILE *)
void CPL_DLL GTIFFreeDefn (GTIF *)
void CPL_DLL SetCSVFilenameHook (const char *(*CSVFileOverride)(const char *))
 Override CSV file search method.
const char CPL_DLL * GTIFDecToDMS (double, const char *, int)
int CPL_DLL GTIFMapSysToPCS (int MapSys, int Datum, int nZone)
int CPL_DLL GTIFMapSysToProj (int MapSys, int nZone)
int CPL_DLL GTIFPCSToMapSys (int PCSCode, int *pDatum, int *pZone)
 Translate a PCS_ code into a UTM or State Plane map system, a datum, and a zone if possible.
int CPL_DLL GTIFProjToMapSys (int ProjCode, int *pZone)
 Translate a Proj_ code into a UTM or State Plane map system, and a zone if possible.
char CPL_DLL * GTIFGetProj4Defn (GTIFDefn *)
int CPL_DLL GTIFProj4ToLatLong (GTIFDefn *, int, double *, double *)
int CPL_DLL GTIFProj4FromLatLong (GTIFDefn *, int, double *, double *)
int CPL_DLL GTIFSetFromProj4 (GTIF *gtif, const char *proj4)

Detailed Description

Include file for extended projection definition normalization api.


Function Documentation

int CPL_DLL GTIFGetDefn ( GTIF psGTIF,
GTIFDefn psDefn 
)
Parameters:
psGTIF GeoTIFF information handle as returned by GTIFNew.
psDefn Pointer to an existing GTIFDefn structure. This structure does not need to have been pre-initialized at all.
Returns:
TRUE if the function has been successful, otherwise FALSE.

This function reads the coordinate system definition from a GeoTIFF file, and normalizes it into a set of component information using definitions from CSV (Comma Seperated Value ASCII) files derived from EPSG tables. This function is intended to simplify correct support for reading files with defined PCS (Projected Coordinate System) codes that wouldn't otherwise be directly known by application software by reducing it to the underlying projection method, parameters, datum, ellipsoid, prime meridian and units.

The application should pass a pointer to an existing uninitialized GTIFDefn structure, and GTIFGetDefn() will fill it in. The fuction currently always returns TRUE but in the future will return FALSE if CSV files are not found. In any event, all geokeys actually found in the file will be copied into the GTIFDefn. However, if the CSV files aren't found codes implied by other codes will not be set properly.

GTIFGetDefn() will not generally work if the EPSG derived CSV files cannot be found. By default a modest attempt will be made to find them, but in general it is necessary for the calling application to override the logic to find them. This can be done by calling the SetCSVFilenameHook() function to override the search method based on application knowledge of where they are found.

The normalization methodology operates by fetching tags from the GeoTIFF file, and then setting all other tags implied by them in the structure. The implied relationships are worked out by reading definitions from the various EPSG derived CSV tables.

For instance, if a PCS (ProjectedCSTypeGeoKey) is found in the GeoTIFF file this code is used to lookup a record in the horiz_cs.csv CSV file. For example given the PCS 26746 we can find the name (NAD27 / California zone VI), the GCS 4257 (NAD27), and the ProjectionCode 10406 (California CS27 zone VI). The GCS, and ProjectionCode can in turn be looked up in other tables until all the details of units, ellipsoid, prime meridian, datum, projection (LambertConfConic_2SP) and projection parameters are established. A full listgeo dump of a file for this result might look like the following, all based on a single PCS value:

% listgeo -norm ~/data/geotiff/pci_eg/spaf27.tif
Geotiff_Information:
   Version: 1
   Key_Revision: 1.0
   Tagged_Information:
      ModelTiepointTag (2,3):
         0                0                0                
         1577139.71       634349.176       0                
      ModelPixelScaleTag (1,3):
         195.509321       198.32184        0                
      End_Of_Tags.
   Keyed_Information:
      GTModelTypeGeoKey (Short,1): ModelTypeProjected
      GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
      ProjectedCSTypeGeoKey (Short,1): PCS_NAD27_California_VI
      End_Of_Keys.
   End_Of_Geotiff.
PCS = 26746 (NAD27 / California zone VI)
Projection = 10406 (California CS27 zone VI)
Projection Method: CT_LambertConfConic_2SP
   ProjStdParallel1GeoKey: 33.883333
   ProjStdParallel2GeoKey: 32.766667
   ProjFalseOriginLatGeoKey: 32.166667
   ProjFalseOriginLongGeoKey: -116.233333
   ProjFalseEastingGeoKey: 609601.219202
   ProjFalseNorthingGeoKey: 0.000000
GCS: 4267/NAD27
Datum: 6267/North American Datum 1927
Ellipsoid: 7008/Clarke 1866 (6378206.40,6356583.80)
Prime Meridian: 8901/Greenwich (0.000000)
Projection Linear Units: 9003/US survey foot (0.304801m)

Note that GTIFGetDefn() does not inspect or return the tiepoints and scale. This must be handled seperately as it normally would. It is intended to simplify capture and normalization of the coordinate system definition. Note that GTIFGetDefn() also does the following things:

  1. Convert all angular values to decimal degrees.
  2. Convert all linear values to meters.
  3. Return the linear units and conversion to meters for the tiepoints and scale (though the tiepoints and scale remain in their native units).
  4. When reading projection parameters a variety of differences between different GeoTIFF generators are handled, and a normalized set of parameters for each projection are always returned.

Code fields in the GTIFDefn are filled with KvUserDefined if there is not value to assign. The parameter lists for each of the underlying projection transform methods can be found at the Projections page. Note that nParms will be set based on the maximum parameter used. Some of the parameters may not be used in which case the GTIFDefn::ProjParmId[] will be zero. This is done to retain correspondence to the EPSG parameter numbering scheme.

The geotiff_proj4.c module distributed with libgeotiff can be used as an example of code that converts a GTIFDefn into another projection system.

See also:
GTIFKeySet(), SetCSVFilenameHook()

References GTIFDefn::CTProjection, GTIFDefn::Datum, GTIFDefn::DefnSet, GTIFDefn::Ellipsoid, GTIFDefn::GCS, GTIFDefn::MapSys, GTIFDefn::Model, GTIFDefn::nParms, GTIFDefn::PCS, GTIFDefn::PM, GTIFDefn::PMLongToGreenwich, GTIFDefn::ProjCode, GTIFDefn::Projection, GTIFDefn::ProjParm, GTIFDefn::ProjParmId, GTIFDefn::SemiMajor, GTIFDefn::SemiMinor, GTIFDefn::UOMAngle, GTIFDefn::UOMAngleInDegrees, GTIFDefn::UOMLength, GTIFDefn::UOMLengthInMeters, and GTIFDefn::Zone.

01975 {
01976     int         i;
01977     short       nGeogUOMLinear;
01978     double      dfInvFlattening;
01979     
01980 /* -------------------------------------------------------------------- */
01981 /*      Initially we default all the information we can.                */
01982 /* -------------------------------------------------------------------- */
01983     psDefn->DefnSet = 1;
01984     psDefn->Model = KvUserDefined;
01985     psDefn->PCS = KvUserDefined;
01986     psDefn->GCS = KvUserDefined;
01987     psDefn->UOMLength = KvUserDefined;
01988     psDefn->UOMLengthInMeters = 1.0;
01989     psDefn->UOMAngle = KvUserDefined;
01990     psDefn->UOMAngleInDegrees = 1.0;
01991     psDefn->Datum = KvUserDefined;
01992     psDefn->Ellipsoid = KvUserDefined;
01993     psDefn->SemiMajor = 0.0;
01994     psDefn->SemiMinor = 0.0;
01995     psDefn->PM = KvUserDefined;
01996     psDefn->PMLongToGreenwich = 0.0;
01997 
01998     psDefn->ProjCode = KvUserDefined;
01999     psDefn->Projection = KvUserDefined;
02000     psDefn->CTProjection = KvUserDefined;
02001 
02002     psDefn->nParms = 0;
02003     for( i = 0; i < MAX_GTIF_PROJPARMS; i++ )
02004     {
02005         psDefn->ProjParm[i] = 0.0;
02006         psDefn->ProjParmId[i] = 0;
02007     }
02008 
02009     psDefn->MapSys = KvUserDefined;
02010     psDefn->Zone = 0;
02011 
02012 /* -------------------------------------------------------------------- */
02013 /*      Do we have any geokeys?                                         */
02014 /* -------------------------------------------------------------------- */
02015     {
02016         int     nKeyCount = 0;
02017         int     anVersion[3];
02018         GTIFDirectoryInfo( psGTIF, anVersion, &nKeyCount );
02019 
02020         if( nKeyCount == 0 )
02021         {
02022             psDefn->DefnSet = 0;
02023             return FALSE;
02024         }
02025     }
02026 
02027 /* -------------------------------------------------------------------- */
02028 /*      Try to get the overall model type.                              */
02029 /* -------------------------------------------------------------------- */
02030     GTIFKeyGet(psGTIF,GTModelTypeGeoKey,&(psDefn->Model),0,1);
02031 
02032 /* -------------------------------------------------------------------- */
02033 /*      Extract the Geog units.                                         */
02034 /* -------------------------------------------------------------------- */
02035     nGeogUOMLinear = 9001; /* Linear_Meter */
02036     GTIFKeyGet(psGTIF, GeogLinearUnitsGeoKey, &nGeogUOMLinear, 0, 1 );
02037 
02038 /* -------------------------------------------------------------------- */
02039 /*      Try to get a PCS.                                               */
02040 /* -------------------------------------------------------------------- */
02041     if( GTIFKeyGet(psGTIF,ProjectedCSTypeGeoKey, &(psDefn->PCS),0,1) == 1
02042         && psDefn->PCS != KvUserDefined )
02043     {
02044         /*
02045          * Translate this into useful information.
02046          */
02047         GTIFGetPCSInfo( psDefn->PCS, NULL, &(psDefn->ProjCode),
02048                         &(psDefn->UOMLength), &(psDefn->GCS) );
02049     }
02050 
02051 /* -------------------------------------------------------------------- */
02052 /*       If we have the PCS code, but didn't find it in the CSV files   */
02053 /*      (likely because we can't find them) we will try some ``jiffy    */
02054 /*      rules'' for UTM and state plane.                                */
02055 /* -------------------------------------------------------------------- */
02056     if( psDefn->PCS != KvUserDefined && psDefn->ProjCode == KvUserDefined )
02057     {
02058         int     nMapSys, nZone;
02059         int     nGCS = psDefn->GCS;
02060 
02061         nMapSys = GTIFPCSToMapSys( psDefn->PCS, &nGCS, &nZone );
02062         if( nMapSys != KvUserDefined )
02063         {
02064             psDefn->ProjCode = (short) GTIFMapSysToProj( nMapSys, nZone );
02065             psDefn->GCS = (short) nGCS;
02066         }
02067     }
02068 
02069 /* -------------------------------------------------------------------- */
02070 /*      If the Proj_ code is specified directly, use that.              */
02071 /* -------------------------------------------------------------------- */
02072     if( psDefn->ProjCode == KvUserDefined )
02073         GTIFKeyGet(psGTIF, ProjectionGeoKey, &(psDefn->ProjCode), 0, 1 );
02074     
02075     if( psDefn->ProjCode != KvUserDefined )
02076     {
02077         /*
02078          * We have an underlying projection transformation value.  Look
02079          * this up.  For a PCS of ``WGS 84 / UTM 11'' the transformation
02080          * would be Transverse Mercator, with a particular set of options.
02081          * The nProjTRFCode itself would correspond to the name
02082          * ``UTM zone 11N'', and doesn't include datum info.
02083          */
02084         GTIFGetProjTRFInfo( psDefn->ProjCode, NULL, &(psDefn->Projection),
02085                             psDefn->ProjParm );
02086         
02087         /*
02088          * Set the GeoTIFF identity of the parameters.
02089          */
02090         psDefn->CTProjection = (short) 
02091             EPSGProjMethodToCTProjMethod( psDefn->Projection );
02092 
02093         SetGTParmIds( psDefn->CTProjection, psDefn->ProjParmId, NULL);
02094         psDefn->nParms = 7;
02095     }
02096 
02097 /* -------------------------------------------------------------------- */
02098 /*      Try to get a GCS.  If found, it will override any implied by    */
02099 /*      the PCS.                                                        */
02100 /* -------------------------------------------------------------------- */
02101     GTIFKeyGet(psGTIF, GeographicTypeGeoKey, &(psDefn->GCS), 0, 1 );
02102     if( psDefn->GCS < 1 || psDefn->GCS >= KvUserDefined )
02103         psDefn->GCS = KvUserDefined;
02104 
02105 /* -------------------------------------------------------------------- */
02106 /*      Derive the datum, and prime meridian from the GCS.              */
02107 /* -------------------------------------------------------------------- */
02108     if( psDefn->GCS != KvUserDefined )
02109     {
02110         GTIFGetGCSInfo( psDefn->GCS, NULL, &(psDefn->Datum), &(psDefn->PM),
02111                         &(psDefn->UOMAngle) );
02112     }
02113     
02114 /* -------------------------------------------------------------------- */
02115 /*      Handle the GCS angular units.  GeogAngularUnitsGeoKey           */
02116 /*      overrides the GCS or PCS setting.                               */
02117 /* -------------------------------------------------------------------- */
02118     GTIFKeyGet(psGTIF, GeogAngularUnitsGeoKey, &(psDefn->UOMAngle), 0, 1 );
02119     if( psDefn->UOMAngle != KvUserDefined )
02120     {
02121         GTIFGetUOMAngleInfo( psDefn->UOMAngle, NULL,
02122                              &(psDefn->UOMAngleInDegrees) );
02123     }
02124 
02125 /* -------------------------------------------------------------------- */
02126 /*      Check for a datum setting, and then use the datum to derive     */
02127 /*      an ellipsoid.                                                   */
02128 /* -------------------------------------------------------------------- */
02129     GTIFKeyGet(psGTIF, GeogGeodeticDatumGeoKey, &(psDefn->Datum), 0, 1 );
02130 
02131     if( psDefn->Datum != KvUserDefined )
02132     {
02133         GTIFGetDatumInfo( psDefn->Datum, NULL, &(psDefn->Ellipsoid) );
02134     }
02135 
02136 /* -------------------------------------------------------------------- */
02137 /*      Check for an explicit ellipsoid.  Use the ellipsoid to          */
02138 /*      derive the ellipsoid characteristics, if possible.              */
02139 /* -------------------------------------------------------------------- */
02140     GTIFKeyGet(psGTIF, GeogEllipsoidGeoKey, &(psDefn->Ellipsoid), 0, 1 );
02141 
02142     if( psDefn->Ellipsoid != KvUserDefined )
02143     {
02144         GTIFGetEllipsoidInfo( psDefn->Ellipsoid, NULL,
02145                               &(psDefn->SemiMajor), &(psDefn->SemiMinor) );
02146     }
02147 
02148 /* -------------------------------------------------------------------- */
02149 /*      Check for overridden ellipsoid parameters.  It would be nice    */
02150 /*      to warn if they conflict with provided information, but for     */
02151 /*      now we just override.                                           */
02152 /* -------------------------------------------------------------------- */
02153     GTIFKeyGet(psGTIF, GeogSemiMajorAxisGeoKey, &(psDefn->SemiMajor), 0, 1 );
02154     GTIFKeyGet(psGTIF, GeogSemiMinorAxisGeoKey, &(psDefn->SemiMinor), 0, 1 );
02155     
02156     if( GTIFKeyGet(psGTIF, GeogInvFlatteningGeoKey, &dfInvFlattening, 
02157                    0, 1 ) == 1 )
02158     {
02159         if( dfInvFlattening != 0.0 )
02160             psDefn->SemiMinor = 
02161                 psDefn->SemiMajor * (1 - 1.0/dfInvFlattening);
02162         else
02163             psDefn->SemiMinor = psDefn->SemiMajor;
02164     }
02165     
02166 /* -------------------------------------------------------------------- */
02167 /*      Get the prime meridian info.                                    */
02168 /* -------------------------------------------------------------------- */
02169     GTIFKeyGet(psGTIF, GeogPrimeMeridianGeoKey, &(psDefn->PM), 0, 1 );
02170 
02171     if( psDefn->PM != KvUserDefined )
02172     {
02173         GTIFGetPMInfo( psDefn->PM, NULL, &(psDefn->PMLongToGreenwich) );
02174     }
02175     else
02176     {
02177         GTIFKeyGet(psGTIF, GeogPrimeMeridianLongGeoKey,
02178                    &(psDefn->PMLongToGreenwich), 0, 1 );
02179 
02180         psDefn->PMLongToGreenwich =
02181             GTIFAngleToDD( psDefn->PMLongToGreenwich,
02182                            psDefn->UOMAngle );
02183     }
02184 
02185 /* -------------------------------------------------------------------- */
02186 /*      Have the projection units of measure been overridden?  We       */
02187 /*      should likely be doing something about angular units too,       */
02188 /*      but these are very rarely not decimal degrees for actual        */
02189 /*      file coordinates.                                               */
02190 /* -------------------------------------------------------------------- */
02191     GTIFKeyGet(psGTIF,ProjLinearUnitsGeoKey,&(psDefn->UOMLength),0,1);
02192 
02193     if( psDefn->UOMLength != KvUserDefined )
02194     {
02195         GTIFGetUOMLengthInfo( psDefn->UOMLength, NULL,
02196                               &(psDefn->UOMLengthInMeters) );
02197     }
02198 
02199 /* -------------------------------------------------------------------- */
02200 /*      Handle a variety of user defined transform types.               */
02201 /* -------------------------------------------------------------------- */
02202     if( GTIFKeyGet(psGTIF,ProjCoordTransGeoKey,
02203                    &(psDefn->CTProjection),0,1) == 1)
02204     {
02205         GTIFFetchProjParms( psGTIF, psDefn );
02206     }
02207 
02208 /* -------------------------------------------------------------------- */
02209 /*      Try to set the zoned map system information.                    */
02210 /* -------------------------------------------------------------------- */
02211     psDefn->MapSys = GTIFProjToMapSys( psDefn->ProjCode, &(psDefn->Zone) );
02212 
02213 /* -------------------------------------------------------------------- */
02214 /*      If this is UTM, and we were unable to extract the projection    */
02215 /*      parameters from the CSV file, just set them directly now,       */
02216 /*      since it's pretty easy, and a common case.                      */
02217 /* -------------------------------------------------------------------- */
02218     if( (psDefn->MapSys == MapSys_UTM_North
02219          || psDefn->MapSys == MapSys_UTM_South)
02220         && psDefn->CTProjection == KvUserDefined )
02221     {
02222         psDefn->CTProjection = CT_TransverseMercator;
02223         psDefn->nParms = 7;
02224         psDefn->ProjParmId[0] = ProjNatOriginLatGeoKey;
02225         psDefn->ProjParm[0] = 0.0;
02226             
02227         psDefn->ProjParmId[1] = ProjNatOriginLongGeoKey;
02228         psDefn->ProjParm[1] = psDefn->Zone*6 - 183.0;
02229         
02230         psDefn->ProjParmId[4] = ProjScaleAtNatOriginGeoKey;
02231         psDefn->ProjParm[4] = 0.9996;
02232         
02233         psDefn->ProjParmId[5] = ProjFalseEastingGeoKey;
02234         psDefn->ProjParm[5] = 500000.0;
02235         
02236         psDefn->ProjParmId[6] = ProjFalseNorthingGeoKey;
02237 
02238         if( psDefn->MapSys == MapSys_UTM_North )
02239             psDefn->ProjParm[6] = 0.0;
02240         else
02241             psDefn->ProjParm[6] = 10000000.0;
02242     }
02243 
02244     return TRUE;
02245 }

int CPL_DLL GTIFPCSToMapSys ( int  PCSCode,
int *  pDatum,
int *  pZone 
)

Translate a PCS_ code into a UTM or State Plane map system, a datum, and a zone if possible.

Parameters:
PCSCode The projection code (PCS_*) as would be stored in the ProjectedCSTypeGeoKey of a GeoTIFF file.
pDatum Pointer to an integer into which the datum code (GCS_*) is put if the function succeeds.
pZone Pointer to an integer into which the zone will be placed if the function is successful.
Returns:
Returns either MapSys_UTM_North, MapSys_UTM_South, MapSys_State_Plane_83, MapSys_State_Plane_27 or KvUserDefined. KvUserDefined indicates that the function failed to recognise the projection as UTM or State Plane.

The zone value is only set if the return code is other than KvUserDefined. For utm map system the returned zone will be between 1 and 60. For State Plane, the USGS state plane zone number is returned. For instance, Alabama East is zone 101.

The datum (really this is the GCS) is set to a GCS_ value such as GCS_NAD27.

This function is useful to recognise (most) UTM and State Plane coordinate systems, even if CSV files aren't available to translate them automatically. It is used as a fallback mechanism by GTIFGetDefn() for normalization when CSV files aren't found.

00542 {
00543     int         Datum = KvUserDefined, Proj = KvUserDefined;
00544     int         nZone = KvUserDefined, i;
00545 
00546 /* -------------------------------------------------------------------- */
00547 /*      UTM with various datums.  Note there are lots of PCS UTM        */
00548 /*      codes not done yet which use strange datums.                    */
00549 /* -------------------------------------------------------------------- */
00550     if( PCSCode >= PCS_NAD27_UTM_zone_3N && PCSCode <= PCS_NAD27_UTM_zone_22N )
00551     {
00552         Datum = GCS_NAD27;
00553         Proj = MapSys_UTM_North;
00554         nZone = PCSCode - PCS_NAD27_UTM_zone_3N + 3;
00555     }
00556     else if( PCSCode >= PCS_NAD83_UTM_zone_3N 
00557              && PCSCode <= PCS_NAD83_UTM_zone_23N )
00558     {
00559         Datum = GCS_NAD83;
00560         Proj = MapSys_UTM_North;
00561         nZone = PCSCode - PCS_NAD83_UTM_zone_3N + 3;
00562     }
00563 
00564     else if( PCSCode >= PCS_WGS72_UTM_zone_1N
00565              && PCSCode <= PCS_WGS72_UTM_zone_60N )
00566     {
00567         Datum = GCS_WGS_72;
00568         Proj = MapSys_UTM_North;
00569         nZone = PCSCode - PCS_WGS72_UTM_zone_1N + 1;
00570     }
00571     else if( PCSCode >= PCS_WGS72_UTM_zone_1S
00572              && PCSCode <= PCS_WGS72_UTM_zone_60S )
00573     {
00574         Datum = GCS_WGS_72;
00575         Proj = MapSys_UTM_South;
00576         nZone = PCSCode - PCS_WGS72_UTM_zone_1S + 1;
00577     }
00578 
00579     else if( PCSCode >= PCS_WGS72BE_UTM_zone_1N
00580              && PCSCode <= PCS_WGS72BE_UTM_zone_60N )
00581     {
00582         Datum = GCS_WGS_72BE;
00583         Proj = MapSys_UTM_North;
00584         nZone = PCSCode - PCS_WGS72BE_UTM_zone_1N + 1;
00585     }
00586     else if( PCSCode >= PCS_WGS72BE_UTM_zone_1S
00587              && PCSCode <= PCS_WGS72BE_UTM_zone_60S )
00588     {
00589         Datum = GCS_WGS_72BE;
00590         Proj = MapSys_UTM_South;
00591         nZone = PCSCode - PCS_WGS72BE_UTM_zone_1S + 1;
00592     }
00593 
00594     else if( PCSCode >= PCS_WGS84_UTM_zone_1N
00595              && PCSCode <= PCS_WGS84_UTM_zone_60N )
00596     {
00597         Datum = GCS_WGS_84;
00598         Proj = MapSys_UTM_North;
00599         nZone = PCSCode - PCS_WGS84_UTM_zone_1N + 1;
00600     }
00601     else if( PCSCode >= PCS_WGS84_UTM_zone_1S
00602              && PCSCode <= PCS_WGS84_UTM_zone_60S )
00603     {
00604         Datum = GCS_WGS_84;
00605         Proj = MapSys_UTM_South;
00606         nZone = PCSCode - PCS_WGS84_UTM_zone_1S + 1;
00607     }
00608     else if( PCSCode >= PCS_SAD69_UTM_zone_18N 
00609              && PCSCode <= PCS_SAD69_UTM_zone_22N )
00610     {
00611         Datum = KvUserDefined;
00612         Proj = MapSys_UTM_North;
00613         nZone = PCSCode - PCS_SAD69_UTM_zone_18N + 18;
00614     }
00615     else if( PCSCode >= PCS_SAD69_UTM_zone_17S
00616              && PCSCode <= PCS_SAD69_UTM_zone_25S )
00617     {
00618         Datum = KvUserDefined;
00619         Proj = MapSys_UTM_South;
00620         nZone = PCSCode - PCS_SAD69_UTM_zone_17S + 17;
00621     }
00622 
00623 /* -------------------------------------------------------------------- */
00624 /*      State Plane zones, first we translate any PCS_ codes to         */
00625 /*      a Proj_ code that we can get a handle on.                       */
00626 /* -------------------------------------------------------------------- */
00627     for( i = 0; StatePlaneTable[i] != KvUserDefined; i += 2 )
00628     {
00629         if( StatePlaneTable[i] == PCSCode )
00630             PCSCode = StatePlaneTable[i+1];
00631     }
00632 
00633     if( PCSCode <= 15900 && PCSCode >= 10000 )
00634     {
00635         if( (PCSCode % 100) >= 30 )
00636         {
00637             Proj = MapSys_State_Plane_83;
00638             Datum = GCS_NAD83;
00639         }
00640         else
00641         {
00642             Proj = MapSys_State_Plane_27;
00643             Datum = GCS_NAD27;
00644         }
00645         
00646         nZone = PCSCode - 10000;
00647         if( Datum == GCS_NAD83 )
00648             nZone -= 30;
00649     }
00650 
00651     if( pDatum != NULL )
00652         *pDatum = Datum;
00653 
00654     if( pZone != NULL )
00655         *pZone = nZone;
00656 
00657     return( Proj );
00658 }

int CPL_DLL GTIFProjToMapSys ( int  ProjCode,
int *  pZone 
)

Translate a Proj_ code into a UTM or State Plane map system, and a zone if possible.

Parameters:
ProjCode The projection code (Proj_*) as would be stored in the ProjectionGeoKey of a GeoTIFF file.
pZone Pointer to an integer into which the zone will be placed if the function is successful.
Returns:
Returns either MapSys_UTM_North, MapSys_UTM_South, MapSys_State_Plane_27, MapSys_State_Plane_83 or KvUserDefined. KvUserDefined indicates that the function failed to recognise the projection as UTM or State Plane.

The zone value is only set if the return code is other than KvUserDefined. For utm map system the returned zone will be between 1 and 60. For State Plane, the USGS state plane zone number is returned. For instance, Alabama East is zone 101.

This function is useful to recognise UTM and State Plane coordinate systems, and to extract zone numbers so the projections can be represented as UTM rather than as the underlying projection method such Transverse Mercator for instance.

00691 {
00692     int         nZone = KvUserDefined;
00693     int         MapSys = KvUserDefined;
00694 
00695 /* -------------------------------------------------------------------- */
00696 /*      Handle UTM.                                                     */
00697 /* -------------------------------------------------------------------- */
00698     if( ProjCode >= Proj_UTM_zone_1N && ProjCode <= Proj_UTM_zone_60N )
00699     {
00700         MapSys = MapSys_UTM_North;
00701         nZone = ProjCode - Proj_UTM_zone_1N + 1;
00702     }
00703     else if( ProjCode >= Proj_UTM_zone_1S && ProjCode <= Proj_UTM_zone_60S )
00704     {
00705         MapSys = MapSys_UTM_South;
00706         nZone = ProjCode - Proj_UTM_zone_1S + 1;
00707     }
00708 
00709 /* -------------------------------------------------------------------- */
00710 /*      Handle State Plane.  I think there are some anomolies in        */
00711 /*      here, so this is a bit risky.                                   */
00712 /* -------------------------------------------------------------------- */
00713     else if( ProjCode >= 10101 && ProjCode <= 15299 )
00714     {
00715         if( ProjCode % 100 >= 30 )
00716         {
00717             MapSys = MapSys_State_Plane_83;
00718             nZone = ProjCode - 10000 - 30;
00719         }
00720         else
00721         {
00722             MapSys = MapSys_State_Plane_27;
00723             nZone = ProjCode - 10000;
00724         }
00725     }
00726     
00727     if( pZone != NULL )
00728         *pZone = nZone;
00729 
00730     return( MapSys );
00731 }

void CPL_DLL SetCSVFilenameHook ( const char *(*)(const char *)  pfnNewHook  ) 

Override CSV file search method.

Parameters:
CSVFileOverride The pointer to a function which will return the full path for a given filename.

This function allows an application to override how the GTIFGetDefn() and related function find the CSV (Comma Separated Value) values required. The pfnHook argument should be a pointer to a function that will take in a CSV filename and return a full path to the file. The returned string should be to an internal static buffer so that the caller doesn't have to free the result.

Example:

The listgeo utility uses the following override function if the user specified a CSV file directory with the -t commandline switch (argument put into CSVDirName).

    ...
    SetCSVFilenameHook( CSVFileOverride );
    ...
static const char *CSVFileOverride( const char * pszInput )
{
    static char         szPath[1024];
ifdef WIN32
    sprintf( szPath, "%s\\%s", CSVDirName, pszInput );
else    
    sprintf( szPath, "%s/%s", CSVDirName, pszInput );
endif
    return( szPath );
}

00957 {
00958     pfnCSVFilenameHook = pfnNewHook;
00959 }


Generated on 8 Nov 2011 for libgeotiff-1.3.0 by  doxygen 1.6.1