[Geotiff] Question on Elevation Data in GeoTiff

ckasturi chriskasturi at yahoo.com
Wed Oct 11 17:49:51 EDT 2006


I've seen a post about elevation data in the geotiff.  My understanding of
the thread related to this post is that the elevation data is one and the
same as the raster data.  Am I wrong?

I'm currently working on a project that has a proprietary geo database,
where I have an API to pull elevation data based on a rectangular set of
latitude and longitude coordinates, i.e. lower left (lat, lon), upper right
(lat, lon) -> array of elevation points in floating point format.  I'm
trying to write this data as a geotiff and am very confused as to how to do
so as I'm very new to this.  Basically, I have code shown at the end of the
post.  My problem is that when I try to use this tiff with osgdem or even a
viewing utility such as openEV, I am unable to see the elevation data.  My
concern is that I'm not storing the elevation data correctly or may be I am
not including the correct TIFF/GEOTIFF tags or keys.

Any help would be appreciated.

	unsigned short GeoKeyDirectory[] = {
	1,1,2,6,				// 1 - version 1, revision 1.2,  6 keys defined
	GTRasterTypeGeoKey  ,   0,1, 2,		// RasterPixelIsPoint
	GTModelTypeGeoKey   ,   0,1, 2,		// ModelTypeGeographic
	GeographicTypeGeoKey,   0,1, 4326,	// GCS_WGS_84
	VerticalCSTypeGeoKey,   0,1, 5030,	// VertCS_WGS_84_ellipsoid
	VerticalCitationGeoKey, 34737,16,0,	// ASCII parameter
	VerticalUnitsGeoKey,    0,1, 9001		// Linear_Meter
	};

	char VerticalCitationGeoKeyStr[] =  "WGS 84 Ellipsoid|";

	TIFF* tiffFile = XTIFFOpen("svc_area.tif","w");
	if (tiffFile)
	{
		// We need to set some values for basic tags before we can add any data
		TIFFSetField(tiffFile, TIFFTAG_IMAGEWIDTH, cols);
		TIFFSetField(tiffFile, TIFFTAG_IMAGELENGTH, rows);
		TIFFSetField(tiffFile, TIFFTAG_BITSPERSAMPLE, 16);
		TIFFSetField(tiffFile, TIFFTAG_SAMPLESPERPIXEL, 1);
		TIFFSetField(tiffFile, TIFFTAG_ROWSPERSTRIP, rows);
		TIFFSetField(tiffFile, TIFFTAG_COMPRESSION, 1 /* uncompressed */);
		TIFFSetField(tiffFile, TIFFTAG_PHOTOMETRIC, 1);
		TIFFSetField(tiffFile, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
		TIFFSetField(tiffFile, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

		TIFFSetField(tiffFile, TIFFTAG_XRESOLUTION, 150.0);
		TIFFSetField(tiffFile, TIFFTAG_YRESOLUTION, 150.0);
		TIFFSetField(tiffFile, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);

		TIFFSetField(tiffFile, TIFFTAG_SAMPLEFORMAT, 2);
		TIFFSetField(tiffFile,
TIFFTAG_GEOKEYDIRECTORY,sizeof(GeoKeyDirectory)/sizeof(unsigned
short),GeoKeyDirectory); 
		TIFFSetField(tiffFile, TIFFTAG_GEOASCIIPARAMS,VerticalCitationGeoKeyStr); 

		// between above and below there is code to fill the image buffer with 16
bit elevation data
		// which basically amounts to casting my floating point values to an int
and string it in the
		// buffer

		if (tiffFile)
		{
			// encode image
			double modeltiepoints[] =
{0.0,0.0,0.0,lowerLeftLon.asDecimalDegrees(),upperRightLat.asDecimalDegrees(),0.0};
			TIFFSetField(tiffFile,
TIFFTAG_GEOTIEPOINTS,sizeof(modeltiepoints)/sizeof(double),modeltiepoints); 
			double modelpixelscale[] = {0.00009752,0.000097,1.0};
			double modelpixelscale[] = {0.0001,0.0001,1.0};
			TIFFSetField(tiffFile,
TIFFTAG_GEOPIXELSCALE,sizeof(modelpixelscale)/sizeof(double),modelpixelscale); 
			TIFFWriteEncodedStrip(tiffFile, 0, buffer, cols * rows * sizeof(int));
				delete [] buffer;
			XTIFFClose(tiffFile);
		}

-- 
View this message in context: http://www.nabble.com/Question-on-Elevation-Data-in-GeoTiff-tf2426390.html#a6765615
Sent from the GeoTIFF mailing list archive at Nabble.com.



More information about the Geotiff mailing list