Geotiff explores results summary
Cixiaoyong@21cn.com
GEOTIFF is a file with a TIFF format containing geographic information. Remember to ask questions on the GEOTIFF file read and write in the 9CBS forum, the answer is that the answer is limited to "just TIFF file plus a few labels ..." Yun Yun, and when I made a After in-depth research, it was found that although geotiff did just a special case of TIFF, it was not so simple to follow the norms. Here I am going to make my own learning, in order to in depth.
1 geotiff uses TIFF to express GEO (geography) information
TIFF's support for Geotiff has written into TIFF6.0, that is, GeOTIFF is a TIFF6.0 file that inherits the corresponding part of Tiff6.0 specification, all Geotiff unique information encodes some of Tiffff Reserved Tag (Tags), it does not have its own IFD (image file directory), binary structure, and other information that are invisible to TIFF.
It is used to describe a wide range of shaded parameters and type information of Geotiff popularity. If each message uses a tab that will require at least fewer or even hundreds of tags, which will exhaust a limited label resource defined by TIFF, on the other hand, although The private IFD provides thousands of free labels, but it is also limited because the tag value is invisible to readers that don't understand (because they don't know ifd_offset tag value points to a private IFD).
To avoid these problems, GEOTIFF uses a range of Keys (keys) to access this information, which is equivalent to the label, but it is abstracted on TIFF. Accurately it is a media label (Meta-tag). The key coexists with the formatted tag value, and the TIFF file processes other image data. Like the label, the ID number is also available from 0 to 65535, but unlike the label, all key ID numbers can be used for the parameter definition of geotiff.
2 Structure and Definition
These keys are also known as geokeys, all keys are indexed by the GeoKeyDirectoryTag tag, which is equivalent to a directory of the key to the GEO information. Its structure is as follows:
GeokeyDirectoryTag:
Tag = 34735 (87AF.H)
TYPE = SHORT (2-byte unsigned short)
N = variable,> = 4
Alias: ProjectionInfotag, Coordsysteminfotag
Owner: Spot Image, Inc.
It consists of heads and keys, as follows:
Header = {KeyDirectoryVersion, KeyRevision, MinorRevision, Numberofkeys}
KeyEntry = {keyid, tifftaglocation, count, value_offset}
Where TIFFTAGLOCATION indicates which tag storage value, if the value is 0, the value is a short type and is included in the value_offset element; otherwise, its value type is implied by TAG containing the value of Tiff-Type.
All key values are not a short type, and are stored under the following two TAGs, based on the following structure:
GeodoubleParamstag:
Tag = 34736 (87BO.H)
TYPE = Double (IEEE Double Precision)
N = variable
Owner: Spot Image, Inc. Note: This tag is used to store Double type GeoKeys, which is referenced by GeoKeyDirectoryTag. The meaning of any value in this Double array is determined by the geokedirectorytag reference. The float value must be converted to Double first.
Geoasciiparamstag:
TAG = 34737 (87b1.h)
TYPE = ASCII
Owner: Spot Image, Inc.
N = variable
example:
GeoKeyDirectoryTag = (1, 1, 2, 6,
1024, 0, 1, 2,
1026, 34737, 12, 0,
2048, 0, 1, 32767,
2049, 34737, 14, 12,
2050, 0, 1, 6,
2051, 34736, 1, 0)
Geodoubleparamstag (34736) = (1.5)
Geoasciiparamstag (34737) = ("Custom File | My GeoGraphic |")
The first line indicates that this is a version of the Geotiff GeoKey directory, the version of the key is Rev. 1.2, and 6 keys are defined in this tab.
The next line defines the first key (id = 1024 = gtmodeltypeGeoKey), the value is 2 (Geographic), placed directly in the element list (because TifftagLocation = 0);
The next line button 1026 (the gtcitationGeoKey) is listed in the Geoasciiparamstag (34737) array begins at offset 0, number to the 12th byte, so its value is "Custom File" ("|" is converted to end character)
Then the next line, the key 2051 (GeoglinearunitsizeGeoKey) is located in GeodoubleParamstag
(34736), the offset is 0, the value is 1.5
The value of Key2049 is "My Geographic".
3 geotiff coordinate system
GEOTIFF design makes the standard map coordinate system definition can be stored in the form of a single registered label. A description of the non-standard coordinate system is also supported. In order to switch between different coordinate inter-line, it can be implemented by using three four other TIFF tags.
However, in order to properly exchange between a variety of different clients and Geotiff providers, it is best to establish an automatic system to describe the map projections.
Under the TIFF / GEOTIFF framework, there are three different space available for coordinate system, and these three spaces are:
1. Raster space (image space) R, is used to represent a pixel value in an image;
a) Define tags related to Raster R and device space in standard TIFF6.0: such as a display, scanner, or printer
2. Equipment space D;
3. Model space M, used to represent the point on the earth.
a) Geographical coordinate system
b) Constant core coordinate system
c) Projection coordinate system
d) vertical coordinate system
Below is a view from Geotiff's view, the use of these three spaces and their respective coordinate systems.
4 read and write programs
Tell this, we have to start playing, see how we will read and write this kind of geotiff file, our goal only one, we write the key values required in the specification into the file and read, fortunately These tasks have been done, this is the famous libgeotiff, which is implemented on the basics of LibTIFF. Its main read and write function prototype is as follows:
GTIFFree (): Free GeoTIFF access handle GTIFGetDefn ():.. Read and Normalize GeoTIFF Definition GTIFKeyGet ():. Read GeoTIFF GeoKey GTIFKeySet ():. Write GeoTIFF GeoKey GTIFNew ():. Create GeoTIFF access handle GTIFWriteKeys (): Flush GeoTIFF Keys. Setcsvfilenamehook (): Override csv file search. Xtiffclose (): close geotiff file. XtifFopen (): Open geotiff file.
Below is a routine Makegeo.c:
/ *
* MakeGeo.c - Example Client Code for Libgeo Geographic
* Tiff tag support.
*
* Author: NILES D. Ritter
*
* Revision History:
* 31 October, 1995 Fixed Reverse Lat-long Coordinates NDR
*
* /
#include "geotiffio.h"
#include "xtiffio.h"
#include
Void SetuptiffDirectory (TIFF * TIF);
Void setupgeokeys (gtif * gtif);
Void WriteImage (TIFF * TIF);
#define width 20L
#define height 20L
void main ()
{
Char * fname = "newgeo.tif";
TIFF * TIF = (TIFF *) 0; / * Tiff-Level Descriptor * /
GTIF * gtif = (gtif *) 0; / * geokey-level descriptor * /
TIF = Xtiffopen (FNAME, "W");
IF (! TIF) goto failure;
GTIF = GTIFNEW (TIF);
IF (! gtif)
{
Printf ("Failed in GtifNew / N);
Goto failure;
}
SetuptiffDirectory (TIF);
Setupgeokeys (gtif);
WriteImage (TIF);
GtifwriteKeys (GTIF);
GTIFFREE (GTIF);
XtiffClose (TIF);
exit (0);
Failure:
Printf ("Failure In MakeGeo / N);
IF (TIF) Tifflose (TIF);
IF (gtif) GTIFFREE (GTIF);
EXIT (-1);
}
Void SetuptiffDirectory (Tiff * TIF)
{
Double Tiepoints [6] = {0, 0, 0, 130.0, 32.0, 0.0};
Double Pixscale [3] = {1,1,0};
TiffSetfield (TIF, TIFFTAG_IMAGEWIDTH, WIDTH); TIFFSETFIELD (TIF, TIFFTAG_IMAGELENGTH, Height);
TiffSetfield (TIF, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TiffSetfield (TIF, TIFFTAG_PHOTMELD, Photometric_minisblack);
TiffSetfield (TIF, TIFFTAG_PLANARCONFIG, Planarconfig_Contig);
TiffSetfield (TIF, Tifftag_BitsPersample, 8);
TiffSetfield (TIF, TIFFTAG_ROWSPERSTRIP, 20L);
TiffSetfield (TiF, Tifftag_geotiepoints, 6, TIEPOINTS);
TiffSetfield (TIF, Tifftag_geopixelscale, 3, Pixscale);
}
Void setupgeokeys (gtif * gtif)
{
GTIFKEYSET (GTIF, GTMODELTYPEGEOKEY, TYPE_SHORT, 1, MODELGRAPHIC);
GTIFKEYSET (GTIF, GTRASTERTYPEGEOKEY, TYPE_SHORT, 1, RASTERPIXELISAREA);
GTIFKEYSET (GTIF, GTCII, 0, "Just An Example";
GTIFKEYSET (GTIF, GeographicTypegeoKey, Type_Short, 1, KvuserDefined);
GTIFKEYSET (GTIF, GeoczionGeoKey, Type_ascii, 0, "EVEREST ELLIPSOID.");
GTIFKEYSET (GTIF, GeangularUnitsgeoKey, Type_Short, 1, Angular_degree);
GTIFKEYSET (GTIF, GeoGlinearunitsgeoKey, Type_Short, 1, Linear_meter);
GTIFKEYSET (GTIF, GeoggeodeticDatumgeoKey, Type_Short, 1, KvuserDefined);
GTIFKEYSET (GTIF, GeogellipsoidgeoKey, Type_Short, 1, Ellipse_everest_1830_1967_definition);
GTIFKEYSET (GTIF, GeogsemimajoraxisgeoKey, Type_double, 1, (Double) 6377298.556);
GTIFKEYSET (GTIF, GeoginvflatteninggeoKey, Type_double, 1, (Double) 300.8017);
}
Void WriteImage (TIFF * TIF)
{
INT I;
Char buffer [width];
MEMSET (buffer, 0, (size_t) width;
For (i = 0; i IF (! Tiffwritescanline (Tif, Buffer, I, 0)) TiffError ("WriteImage", "Failure In WriteScanline / N"; } This line is rushing, mainly thinking about breaking with you, hoping to pay more attention, I will constantly modify this. P.s. This article is copyrighted, no reprint or it is not allowed.