Primary libgeotiff include file. More...
#include "geo_config.h"#include "geokeys.h"

Go to the source code of this file.
Defines | |
| #define | GvCurrentVersion 1 |
| #define | LIBGEOTIFF_VERSION 1300 |
Typedefs | |
| typedef struct gtiff | GTIF |
| typedef struct _TIFFMethod | TIFFMethod |
| typedef unsigned short | tifftag_t |
| typedef unsigned short | geocode_t |
| typedef int(* | GTIFPrintMethod )(char *string, void *aux) |
| typedef int(* | GTIFReadMethod )(char *string, void *aux) |
Enumerations | |
| enum | tagtype_t { TYPE_BYTE = 1, TYPE_SHORT = 2, TYPE_LONG = 3, TYPE_RATIONAL = 4, TYPE_ASCII = 5, TYPE_FLOAT = 6, TYPE_DOUBLE = 7, TYPE_SBYTE = 8, TYPE_SSHORT = 9, TYPE_SLONG = 10, TYPE_UNKNOWN = 11 } |
Functions | |
| GTIF CPL_DLL * | GTIFNew (void *tif) |
| Given an open TIFF file, look for GTIF keys and values and return GTIF structure. | |
| GTIF CPL_DLL * | GTIFNewSimpleTags (void *tif) |
| GTIF CPL_DLL * | GTIFNewWithMethods (void *tif, TIFFMethod *) |
| void CPL_DLL | GTIFFree (GTIF *gtif) |
| This function deallocates an existing GeoTIFF access handle previously created with GTIFNew(). | |
| int CPL_DLL | GTIFWriteKeys (GTIF *gtif) |
| This function flushes all the GeoTIFF keys that have been set with the GTIFKeySet() function into the associated TIFF file. | |
| void CPL_DLL | GTIFDirectoryInfo (GTIF *gtif, int *versions, int *keycount) |
| int CPL_DLL | GTIFKeyInfo (GTIF *gtif, geokey_t key, int *size, tagtype_t *type) |
| int CPL_DLL | GTIFKeyGet (GTIF *gtif, geokey_t key, void *val, int index, int count) |
| This function reads the value of a single GeoKey from a GeoTIFF file. | |
| int CPL_DLL | GTIFKeySet (GTIF *gtif, geokey_t keyID, tagtype_t type, int count,...) |
| This function writes a geokey_t value to a GeoTIFF file. | |
| void CPL_DLL | GTIFPrint (GTIF *gtif, GTIFPrintMethod print, void *aux) |
| int CPL_DLL | GTIFImport (GTIF *gtif, GTIFReadMethod scan, void *aux) |
| char CPL_DLL * | GTIFKeyName (geokey_t key) |
| char CPL_DLL * | GTIFValueName (geokey_t key, int value) |
| char CPL_DLL * | GTIFTypeName (tagtype_t type) |
| char CPL_DLL * | GTIFTagName (int tag) |
| int CPL_DLL | GTIFKeyCode (char *key) |
| int CPL_DLL | GTIFValueCode (geokey_t key, char *value) |
| int CPL_DLL | GTIFTypeCode (char *type) |
| int CPL_DLL | GTIFTagCode (char *tag) |
| int CPL_DLL | GTIFImageToPCS (GTIF *gtif, double *x, double *y) |
| Translate a pixel/line coordinate to projection coordinates. | |
| int CPL_DLL | GTIFPCSToImage (GTIF *gtif, double *x, double *y) |
| Translate a projection coordinate to pixel/line coordinates. | |
Primary libgeotiff include file.
This is the defacto registry for valid GEOTIFF GeoKeys and their associated symbolic values. This is also the only file of the GeoTIFF library which needs to be included in client source code.
| void CPL_DLL GTIFFree | ( | GTIF * | gtif | ) |
This function deallocates an existing GeoTIFF access handle previously created with GTIFNew().
If the handle was used to write GeoTIFF keys to the TIFF file, the GTIFWriteKeys() function should be used to flush results to the file before calling GTIFFree(). GTIFFree() should be called before XTIFFClose() is called on the corresponding TIFF file handle.
00038 { 00039 int i; 00040 00041 if (!gtif) return; 00042 00043 /* Free parameter arrays */ 00044 if (gtif->gt_double) _GTIFFree (gtif->gt_double); 00045 if (gtif->gt_short) _GTIFFree (gtif->gt_short); 00046 00047 /* Free GeoKey arrays */ 00048 if (gtif->gt_keys) 00049 { 00050 for (i = 0; i < MAX_KEYS; i++) 00051 { 00052 if (gtif->gt_keys[i].gk_type == TYPE_ASCII) 00053 { 00054 _GTIFFree (gtif->gt_keys[i].gk_data); 00055 } 00056 } 00057 _GTIFFree (gtif->gt_keys); 00058 } 00059 if (gtif->gt_keyindex) _GTIFFree (gtif->gt_keyindex); 00060 00061 _GTIFFree (gtif); 00062 }
| int CPL_DLL GTIFImageToPCS | ( | GTIF * | gtif, | |
| double * | x, | |||
| double * | y | |||
| ) |
Translate a pixel/line coordinate to projection coordinates.
At this time this function does not support image to PCS translations for tiepoints-only definitions, only pixelscale and transformation matrix formulations.
| gtif | The handle from GTIFNew() indicating the target file. | |
| x | A pointer to the double containing the pixel offset on input, and into which the easting/longitude will be put on completion. | |
| y | A pointer to the double containing the line offset on input, and into which the northing/latitude will be put on completion. |
00119 { 00120 int res = FALSE; 00121 int tiepoint_count, count, transform_count; 00122 tiff_t *tif=gtif->gt_tif; 00123 double *tiepoints = 0; 00124 double *pixel_scale = 0; 00125 double *transform = 0; 00126 00127 00128 if (!(gtif->gt_methods.get)(tif, GTIFF_TIEPOINTS, 00129 &tiepoint_count, &tiepoints )) 00130 tiepoint_count = 0; 00131 00132 if (!(gtif->gt_methods.get)(tif, GTIFF_PIXELSCALE, &count, &pixel_scale )) 00133 count = 0; 00134 00135 if (!(gtif->gt_methods.get)(tif, GTIFF_TRANSMATRIX, 00136 &transform_count, &transform )) 00137 transform_count = 0; 00138 00139 /* -------------------------------------------------------------------- */ 00140 /* If the pixelscale count is zero, but we have tiepoints use */ 00141 /* the tiepoint based approach. */ 00142 /* -------------------------------------------------------------------- */ 00143 if( tiepoint_count > 6 && count == 0 ) 00144 { 00145 res = GTIFTiepointTranslate( tiepoint_count / 6, 00146 tiepoints, tiepoints + 3, 00147 *x, *y, x, y ); 00148 } 00149 00150 /* -------------------------------------------------------------------- */ 00151 /* If we have a transformation matrix, use it. */ 00152 /* -------------------------------------------------------------------- */ 00153 else if( transform_count == 16 ) 00154 { 00155 double x_in = *x, y_in = *y; 00156 00157 *x = x_in * transform[0] + y_in * transform[1] + transform[3]; 00158 *y = x_in * transform[4] + y_in * transform[5] + transform[7]; 00159 00160 res = TRUE; 00161 } 00162 00163 /* -------------------------------------------------------------------- */ 00164 /* For now we require one tie point, and a valid pixel scale. */ 00165 /* -------------------------------------------------------------------- */ 00166 else if( count < 3 || tiepoint_count < 6 ) 00167 { 00168 res = FALSE; 00169 } 00170 00171 else 00172 { 00173 *x = (*x - tiepoints[0]) * pixel_scale[0] + tiepoints[3]; 00174 *y = (*y - tiepoints[1]) * (-1 * pixel_scale[1]) + tiepoints[4]; 00175 00176 res = TRUE; 00177 } 00178 00179 /* -------------------------------------------------------------------- */ 00180 /* Cleanup */ 00181 /* -------------------------------------------------------------------- */ 00182 if(tiepoints) 00183 _GTIFFree(tiepoints); 00184 if(pixel_scale) 00185 _GTIFFree(pixel_scale); 00186 if(transform) 00187 _GTIFFree(transform); 00188 00189 return res; 00190 }
| int CPL_DLL GTIFKeyGet | ( | GTIF * | gtif, | |
| geokey_t | thekey, | |||
| void * | val, | |||
| int | index, | |||
| int | count | |||
| ) |
This function reads the value of a single GeoKey from a GeoTIFF file.
| gtif | The geotiff information handle from GTIFNew(). | |
| thekey | The geokey_t name (such as ProjectedCSTypeGeoKey). This must come from the list of legal geokey_t values (an enumeration) listed below. | |
| val | The val argument is a pointer to the variable into which the value should be read. The type of the variable varies depending on the geokey_t given. While there is no ready mapping of geokey_t values onto types, in general code values are of type short, citations are strings, and everything else is of type double. Note that pointer's to int should never be passed to GTIFKeyGet() for integer values as they will be shorts, and the int's may not be properly initialized (and will be grossly wrong on MSB systems). | |
| index | Indicates how far into the list of values for this geokey to offset. Should normally be zero. | |
| count | Indicates how many values to read. At this time all keys except for strings have only one value, so index should be zero, and count should be one. |
From geokeys.inc we see the following geokey_t values are possible:
-- 6.2.1 GeoTIFF Configuration Keys --
ValuePair( GTModelTypeGeoKey, 1024) -- Section 6.3.1.1 Codes -- ValuePair( GTRasterTypeGeoKey, 1025) -- Section 6.3.1.2 Codes -- ValuePair( GTCitationGeoKey, 1026) -- documentation --
-- 6.2.2 Geographic CS Parameter Keys --
ValuePair( GeographicTypeGeoKey, 2048) -- Section 6.3.2.1 Codes -- ValuePair( GeogCitationGeoKey, 2049) -- documentation -- ValuePair( GeogGeodeticDatumGeoKey, 2050) -- Section 6.3.2.2 Codes -- ValuePair( GeogPrimeMeridianGeoKey, 2051) -- Section 6.3.2.4 codes -- ValuePair( GeogLinearUnitsGeoKey, 2052) -- Section 6.3.1.3 Codes -- ValuePair( GeogLinearUnitSizeGeoKey, 2053) -- meters -- ValuePair( GeogAngularUnitsGeoKey, 2054) -- Section 6.3.1.4 Codes -- ValuePair( GeogAngularUnitSizeGeoKey, 2055) -- radians -- ValuePair( GeogEllipsoidGeoKey, 2056) -- Section 6.3.2.3 Codes -- ValuePair( GeogSemiMajorAxisGeoKey, 2057) -- GeogLinearUnits -- ValuePair( GeogSemiMinorAxisGeoKey, 2058) -- GeogLinearUnits -- ValuePair( GeogInvFlatteningGeoKey, 2059) -- ratio -- ValuePair( GeogAzimuthUnitsGeoKey, 2060) -- Section 6.3.1.4 Codes -- ValuePair( GeogPrimeMeridianLongGeoKey, 2061) -- GeoAngularUnit --
-- 6.2.3 Projected CS Parameter Keys -- -- Several keys have been renamed,-- -- and the deprecated names aliased for backward compatibility --
ValuePair( ProjectedCSTypeGeoKey, 3072) -- Section 6.3.3.1 codes -- ValuePair( PCSCitationGeoKey, 3073) -- documentation -- ValuePair( ProjectionGeoKey, 3074) -- Section 6.3.3.2 codes -- ValuePair( ProjCoordTransGeoKey, 3075) -- Section 6.3.3.3 codes -- ValuePair( ProjLinearUnitsGeoKey, 3076) -- Section 6.3.1.3 codes -- ValuePair( ProjLinearUnitSizeGeoKey, 3077) -- meters -- ValuePair( ProjStdParallel1GeoKey, 3078) -- GeogAngularUnit -- ValuePair( ProjStdParallelGeoKey,ProjStdParallel1GeoKey) -- ** alias ** -- ValuePair( ProjStdParallel2GeoKey, 3079) -- GeogAngularUnit -- ValuePair( ProjNatOriginLongGeoKey, 3080) -- GeogAngularUnit -- ValuePair( ProjOriginLongGeoKey,ProjNatOriginLongGeoKey) -- ** alias ** -- ValuePair( ProjNatOriginLatGeoKey, 3081) -- GeogAngularUnit -- ValuePair( ProjOriginLatGeoKey,ProjNatOriginLatGeoKey) -- ** alias ** -- ValuePair( ProjFalseEastingGeoKey, 3082) -- ProjLinearUnits -- ValuePair( ProjFalseNorthingGeoKey, 3083) -- ProjLinearUnits -- ValuePair( ProjFalseOriginLongGeoKey, 3084) -- GeogAngularUnit -- ValuePair( ProjFalseOriginLatGeoKey, 3085) -- GeogAngularUnit -- ValuePair( ProjFalseOriginEastingGeoKey, 3086) -- ProjLinearUnits -- ValuePair( ProjFalseOriginNorthingGeoKey, 3087) -- ProjLinearUnits -- ValuePair( ProjCenterLongGeoKey, 3088) -- GeogAngularUnit -- ValuePair( ProjCenterLatGeoKey, 3089) -- GeogAngularUnit -- ValuePair( ProjCenterEastingGeoKey, 3090) -- ProjLinearUnits -- ValuePair( ProjCenterNorthingGeoKey, 3091) -- ProjLinearUnits -- ValuePair( ProjScaleAtNatOriginGeoKey, 3092) -- ratio -- ValuePair( ProjScaleAtOriginGeoKey,ProjScaleAtNatOriginGeoKey) -- ** alias ** -- ValuePair( ProjScaleAtCenterGeoKey, 3093) -- ratio -- ValuePair( ProjAzimuthAngleGeoKey, 3094) -- GeogAzimuthUnit -- ValuePair( ProjStraightVertPoleLongGeoKey, 3095) -- GeogAngularUnit --
6.2.4 Vertical CS Keys
ValuePair( VerticalCSTypeGeoKey, 4096) -- Section 6.3.4.1 codes -- ValuePair( VerticalCitationGeoKey, 4097) -- documentation -- ValuePair( VerticalDatumGeoKey, 4098) -- Section 6.3.4.2 codes -- ValuePair( VerticalUnitsGeoKey, 4099) -- Section 6.3.1 (.x) codes --
00151 { 00152 int kindex = gtif->gt_keyindex[ thekey ]; 00153 GeoKey *key; 00154 gsize_t size; 00155 char *data; 00156 tagtype_t type; 00157 00158 if (!kindex) return 0; 00159 00160 key = gtif->gt_keys+kindex; 00161 if (!count) count = key->gk_count - index; 00162 if (count <=0) return 0; 00163 if (count > key->gk_count) count = key->gk_count; 00164 size = key->gk_size; 00165 type = key->gk_type; 00166 00167 if (count==1 && type==TYPE_SHORT) data = (char *)&key->gk_data; 00168 else data = key->gk_data; 00169 00170 _GTIFmemcpy( val, data + index*size, count*size ); 00171 00172 if (type==TYPE_ASCII) 00173 ((char *)val)[count-1] = '\0'; /* replace last char with NULL */ 00174 00175 return count; 00176 }
| int CPL_DLL GTIFKeySet | ( | GTIF * | gtif, | |
| geokey_t | keyID, | |||
| tagtype_t | type, | |||
| int | count, | |||
| ... | ||||
| ) |
This function writes a geokey_t value to a GeoTIFF file.
| gtif | The geotiff information handle from GTIFNew(). | |
| keyID | The geokey_t name (such as ProjectedCSTypeGeoKey). This must come from the list of legal geokey_t values (an enumeration) listed below. | |
| val | The val argument is a pointer to the variable into which the value should be read. The type of the variable varies depending on the geokey_t given. While there is no ready mapping of geokey_t values onto types, in general code values are of type short, citations are strings, and everything else is of type double. Note that pointer's to int should never be passed to GTIFKeyGet() for integer values as they will be shorts, and the int's may not be properly initialized (and will be grossly wrong on MSB systems). | |
| index | Indicates how far into the list of values for this geokey to offset. Should normally be zero. | |
| count | Indicates how many values to read. At this time all keys except for strings have only one value, so index should be zero, and count should be one. |
The key indicates the key name to be written to the file and should from the geokey_t enumeration (eg. ProjectedCSTypeGeoKey). The full list of possible geokey_t values can be found in geokeys.inc, or in the online documentation for GTIFKeyGet().
The type should be one of TYPE_SHORT, TYPE_ASCII, or TYPE_DOUBLE and will indicate the type of value being passed at the end of the argument list (the key value). The count should be one except for strings when it should be the length of the string (or zero to for this to be computed internally). As a special case a count of -1 can be used to request an existing key be deleted, in which no value is passed.
The actual value is passed at the end of the argument list, and should be a short, a double, or a char * value. Note that short and double values are passed by value rather than as pointers when count is 1, but as pointers if count is larger than 1.
Note that key values aren't actually flushed to the file until GTIFWriteKeys() is called. Till then the new values are just kept with the GTIF structure.
Example:
GTIFKeySet(gtif, GTRasterTypeGeoKey, TYPE_SHORT, 1,
RasterPixelIsArea);
GTIFKeySet(gtif, GTCitationGeoKey, TYPE_ASCII, 0,
"UTM 11 North / NAD27" );
00079 { 00080 va_list ap; 00081 int index = gtif->gt_keyindex[ keyID ]; 00082 int newvalues = 0; 00083 GeoKey *key; 00084 char *data = NULL; 00085 char *val = NULL; 00086 pinfo_t sval; 00087 double dval; 00088 00089 va_start(ap, count); 00090 /* pass singleton keys by value */ 00091 if (count>1 && type!=TYPE_ASCII) 00092 { 00093 val = va_arg(ap, char*); 00094 } 00095 else if( count == -1 ) 00096 { 00097 /* delete the indicated tag */ 00098 va_end(ap); 00099 00100 if( index < 1 ) 00101 return 0; 00102 00103 if (gtif->gt_keys[index].gk_type == TYPE_ASCII) 00104 { 00105 _GTIFFree (gtif->gt_keys[index].gk_data); 00106 } 00107 00108 while( index < gtif->gt_num_keys ) 00109 { 00110 _GTIFmemcpy( gtif->gt_keys + index, 00111 gtif->gt_keys + index + 1, 00112 sizeof(GeoKey) ); 00113 gtif->gt_keyindex[gtif->gt_keys[index].gk_key] = index; 00114 index++; 00115 } 00116 00117 gtif->gt_num_keys--; 00118 gtif->gt_nshorts -= sizeof(KeyEntry)/sizeof(pinfo_t); 00119 gtif->gt_keyindex[keyID] = 0; 00120 gtif->gt_flags |= FLAG_FILE_MODIFIED; 00121 00122 return 1; 00123 } 00124 else switch (type) 00125 { 00126 case TYPE_SHORT: sval=(pinfo_t) va_arg(ap, int); val=(char *)&sval; break; 00127 case TYPE_DOUBLE: dval=va_arg(ap, dblparam_t); val=(char *)&dval; break; 00128 case TYPE_ASCII: 00129 val=va_arg(ap, char*); 00130 count = strlen(val) + 1; /* force = string length */ 00131 break; 00132 default: 00133 assert( FALSE ); 00134 break; 00135 } 00136 va_end(ap); 00137 00138 /* We assume here that there are no multi-valued SHORTS ! */ 00139 if (index) 00140 { 00141 /* Key already exists */ 00142 key = gtif->gt_keys+index; 00143 if (type!=key->gk_type || count > key->gk_count) 00144 { 00145 /* need to reset data pointer */ 00146 key->gk_type = type; 00147 key->gk_count = count; 00148 key->gk_size = _gtiff_size[ type ]; 00149 newvalues = 1; 00150 } 00151 } 00152 else 00153 { 00154 /* We need to create the key */ 00155 if (gtif->gt_num_keys == MAX_KEYS) return 0; 00156 key = gtif->gt_keys + ++gtif->gt_num_keys; 00157 index = gtif->gt_num_keys; 00158 gtif->gt_keyindex[ keyID ] = index; 00159 key->gk_key = keyID; 00160 key->gk_type = type; 00161 key->gk_count = count; 00162 key->gk_size = _gtiff_size[ type ]; 00163 if (gtif->gt_keymin > keyID) gtif->gt_keymin=keyID; 00164 if (gtif->gt_keymax < keyID) gtif->gt_keymax=keyID; 00165 newvalues = 1; 00166 } 00167 00168 if (newvalues) 00169 { 00170 switch (type) 00171 { 00172 case TYPE_SHORT: 00173 if (count > 1) return 0; 00174 data = (char *)&key->gk_data; /* store value *in* data */ 00175 break; 00176 case TYPE_DOUBLE: 00177 key->gk_data = (char *)(gtif->gt_double + gtif->gt_ndoubles); 00178 data = key->gk_data; 00179 gtif->gt_ndoubles += count; 00180 break; 00181 case TYPE_ASCII: 00182 break; 00183 default: 00184 va_end(ap); 00185 return 0; 00186 } 00187 gtif->gt_nshorts += sizeof(KeyEntry)/sizeof(pinfo_t); 00188 } 00189 00190 /* this fixes a bug where if a request is made to write a duplicate 00191 key, we must initialize the data to a valid value. 00192 Bryan Wells (bryan@athena.bangor.autometric.com) */ 00193 00194 else /* no new values, but still have something to write */ 00195 { 00196 switch (type) 00197 { 00198 case TYPE_SHORT: 00199 if (count > 1) return 0; 00200 data = (char *)&key->gk_data; /* store value *in* data */ 00201 break; 00202 case TYPE_DOUBLE: 00203 data = key->gk_data; 00204 break; 00205 case TYPE_ASCII: 00206 break; 00207 default: 00208 return 0; 00209 } 00210 } 00211 00212 switch (type) 00213 { 00214 case TYPE_ASCII: 00215 /* throw away existing data and allocate room for new data */ 00216 if (key->gk_data != 0) 00217 { 00218 _GTIFFree(key->gk_data); 00219 } 00220 key->gk_data = (char *)_GTIFcalloc(count); 00221 key->gk_count = count; 00222 data = key->gk_data; 00223 break; 00224 default: 00225 break; 00226 } 00227 00228 _GTIFmemcpy(data, val, count*key->gk_size); 00229 00230 gtif->gt_flags |= FLAG_FILE_MODIFIED; 00231 return 1; 00232 }
| GTIF CPL_DLL* GTIFNew | ( | void * | tif | ) |
Given an open TIFF file, look for GTIF keys and values and return GTIF structure.
This function creates a GeoTIFF information interpretation handle (GTIF *) based on a passed in TIFF handle originally from XTIFFOpen(). Even though the argument (tif) is shown as type void *, it is really normally of type TIFF *.
The returned GTIF handle can be used to read or write GeoTIFF tags using the various GTIF functions. The handle should be destroyed using GTIFFree() before the file is closed with TIFFClose().
If the file accessed has no GeoTIFF keys, an valid (but empty) GTIF is still returned. GTIFNew() is used both for existing files being read, and for new TIFF files that will have GeoTIFF tags written to them.
00056 { 00057 TIFFMethod default_methods; 00058 _GTIFSetDefaultTIFF( &default_methods ); 00059 00060 return GTIFNewWithMethods( tif, &default_methods ); 00061 }
| int CPL_DLL GTIFPCSToImage | ( | GTIF * | gtif, | |
| double * | x, | |||
| double * | y | |||
| ) |
Translate a projection coordinate to pixel/line coordinates.
At this time this function does not support PCS to image translations for tiepoints-only based definitions, only matrix and pixelscale/tiepoints formulations are supposed.
| gtif | The handle from GTIFNew() indicating the target file. | |
| x | A pointer to the double containing the pixel offset on input, and into which the easting/longitude will be put on completion. | |
| y | A pointer to the double containing the line offset on input, and into which the northing/latitude will be put on completion. |
00216 { 00217 double *tiepoints = NULL; 00218 int tiepoint_count, count, transform_count = 0; 00219 double *pixel_scale = NULL; 00220 double *transform = NULL; 00221 tiff_t *tif=gtif->gt_tif; 00222 int result = FALSE; 00223 00224 /* -------------------------------------------------------------------- */ 00225 /* Fetch tiepoints and pixel scale. */ 00226 /* -------------------------------------------------------------------- */ 00227 if (!(gtif->gt_methods.get)(tif, GTIFF_TIEPOINTS, 00228 &tiepoint_count, &tiepoints )) 00229 tiepoint_count = 0; 00230 00231 if (!(gtif->gt_methods.get)(tif, GTIFF_PIXELSCALE, &count, &pixel_scale )) 00232 count = 0; 00233 00234 if (!(gtif->gt_methods.get)(tif, GTIFF_TRANSMATRIX, 00235 &transform_count, &transform )) 00236 transform_count = 0; 00237 00238 /* -------------------------------------------------------------------- */ 00239 /* If the pixelscale count is zero, but we have tiepoints use */ 00240 /* the tiepoint based approach. */ 00241 /* -------------------------------------------------------------------- */ 00242 if( tiepoint_count > 6 && count == 0 ) 00243 { 00244 result = GTIFTiepointTranslate( tiepoint_count / 6, 00245 tiepoints + 3, tiepoints, 00246 *x, *y, x, y ); 00247 } 00248 00249 /* -------------------------------------------------------------------- */ 00250 /* Handle matrix - convert to "geotransform" format, invert and */ 00251 /* apply. */ 00252 /* -------------------------------------------------------------------- */ 00253 else if( transform_count == 16 ) 00254 { 00255 double x_in = *x, y_in = *y; 00256 double gt_in[6], gt_out[6]; 00257 00258 gt_in[0] = transform[0]; 00259 gt_in[1] = transform[1]; 00260 gt_in[2] = transform[3]; 00261 gt_in[3] = transform[4]; 00262 gt_in[4] = transform[5]; 00263 gt_in[5] = transform[7]; 00264 00265 if( !inv_geotransform( gt_in, gt_out ) ) 00266 result = FALSE; 00267 else 00268 { 00269 *x = x_in * gt_out[0] + y_in * gt_out[1] + gt_out[2]; 00270 *y = x_in * gt_out[3] + y_in * gt_out[4] + gt_out[5]; 00271 00272 result = TRUE; 00273 } 00274 } 00275 00276 /* -------------------------------------------------------------------- */ 00277 /* For now we require one tie point, and a valid pixel scale. */ 00278 /* -------------------------------------------------------------------- */ 00279 else if( count >= 3 && tiepoint_count >= 6 ) 00280 { 00281 *x = (*x - tiepoints[3]) / pixel_scale[0] + tiepoints[0]; 00282 *y = (*y - tiepoints[4]) / (-1 * pixel_scale[1]) + tiepoints[1]; 00283 00284 result = TRUE; 00285 } 00286 00287 /* -------------------------------------------------------------------- */ 00288 /* Cleanup. */ 00289 /* -------------------------------------------------------------------- */ 00290 if(tiepoints) 00291 _GTIFFree(tiepoints); 00292 if(pixel_scale) 00293 _GTIFFree(pixel_scale); 00294 if(transform) 00295 _GTIFFree(transform); 00296 00297 return result; 00298 }
| int CPL_DLL GTIFWriteKeys | ( | GTIF * | gt | ) |
This function flushes all the GeoTIFF keys that have been set with the GTIFKeySet() function into the associated TIFF file.
| gt | The GeoTIFF handle returned by GTIFNew. |
GTIFWriteKeys() should be called before GTIFFree() is used to deallocate a GeoTIFF access handle.
00035 { 00036 int i; 00037 GeoKey *keyptr; 00038 KeyEntry *entptr; 00039 KeyHeader *header; 00040 TempKeyData tempData; 00041 int sortkeys[MAX_KEYS]; 00042 00043 if (!(gt->gt_flags & FLAG_FILE_MODIFIED)) return 1; 00044 00045 if( gt->gt_tif == NULL ) 00046 return 0; 00047 00048 tempData.tk_asciiParams = 0; 00049 tempData.tk_asciiParamsLength = 0; 00050 tempData.tk_asciiParamsOffset = 0; 00051 00052 /* Sort the Keys into numerical order */ 00053 if (!SortKeys(gt,sortkeys)) 00054 { 00055 /* XXX error: a key was not recognized */ 00056 } 00057 00058 /* Set up header of ProjectionInfo tag */ 00059 header = (KeyHeader *)gt->gt_short; 00060 header->hdr_num_keys = (pinfo_t) gt->gt_num_keys; 00061 header->hdr_version = GvCurrentVersion; 00062 header->hdr_rev_major = GvCurrentRevision; 00063 header->hdr_rev_minor = GvCurrentMinorRev; 00064 00065 /* Sum up the ASCII tag lengths */ 00066 for (i = 0; i < gt->gt_num_keys; i++) 00067 { 00068 keyptr = gt->gt_keys + sortkeys[i]; 00069 if (keyptr->gk_type == TYPE_ASCII) 00070 { 00071 tempData.tk_asciiParamsLength += keyptr->gk_count; 00072 } 00073 } 00074 if (tempData.tk_asciiParamsLength > 0) 00075 { 00076 tempData.tk_asciiParams = 00077 (char *)_GTIFcalloc(tempData.tk_asciiParamsLength + 1); 00078 tempData.tk_asciiParams[tempData.tk_asciiParamsLength] = '\0'; 00079 } 00080 00081 /* Set up the rest of SHORT array properly */ 00082 keyptr = gt->gt_keys; 00083 entptr = (KeyEntry*)(gt->gt_short + 4); 00084 for (i=0; i< gt->gt_num_keys; i++,entptr++) 00085 { 00086 if (!WriteKey(gt,&tempData,entptr,keyptr+sortkeys[i])) return 0; 00087 } 00088 00089 /* Write out the Key Directory */ 00090 (gt->gt_methods.set)(gt->gt_tif, GTIFF_GEOKEYDIRECTORY, gt->gt_nshorts, gt->gt_short ); 00091 00092 /* Write out the params directories */ 00093 if (gt->gt_ndoubles) 00094 (gt->gt_methods.set)(gt->gt_tif, GTIFF_DOUBLEPARAMS, gt->gt_ndoubles, gt->gt_double ); 00095 if (tempData.tk_asciiParamsLength > 0) 00096 { 00097 /* just to be safe */ 00098 tempData.tk_asciiParams[tempData.tk_asciiParamsLength] = '\0'; 00099 (gt->gt_methods.set)(gt->gt_tif, 00100 GTIFF_ASCIIPARAMS, 0, tempData.tk_asciiParams); 00101 } 00102 00103 gt->gt_flags &= ~FLAG_FILE_MODIFIED; 00104 00105 if (tempData.tk_asciiParamsLength > 0) 00106 { 00107 _GTIFFree (tempData.tk_asciiParams); 00108 } 00109 return 1; 00110 }
1.6.1