I'm trying to create a geotiff (elevation DEM data) file by using Libtiff.Net.
The problem is that I have never succeeded to add the following two tags:
TiffTag.GEOTIFF_MODELTIEPOINTTAG
TiffTag.GEOTIFF_MODELPIXELSCALETA
To add the tag, I wrote the code as follows:
tiff.SetField(TiffTag.GEOTIFF_MODELTIEPOINTTAG, 0.0, 0.0, 0.0, leftTopX, leftTopY, 0.0);
tiff.SetField(TiffTag.GEOTIFF_MODELPIXELSCALETAG, pixelScaleX, pixelScaleY, 0.0);
According to the description for the "SetField" method, the method returns "true" if the tag value was set successfully.
However, in my case, the method never returns when trying to add the above 2 tags.
(Other tags can be added without any problem.)
I already confirmed that the created geotiff does not contain the geographic information, by using other GIS softwares, such as ArcGIS.
Am I missing something or did something wrong?
Any hints or answers will be appreciated!
For your convenience, the code I write so far is the following:
public void WriteTiff()
{
using (var tiff = Tiff.Open("C:\\test\\newCreated.tif", "w"))
{
if (tiff == null)
return;
int width = 100;
int height = 100;
int byteDepth = 4;
int tileSize = 64;
//Geo info to add
double leftTopX = 10000;
double leftTopY = 15000;
double pixelScaleX = 1;
double pixelScaleY = 1;
//Set the basic tags
tiff.SetField(TiffTag.IMAGEWIDTH, width);
tiff.SetField(TiffTag.IMAGELENGTH, height);
tiff.SetField(TiffTag.SAMPLESPERPIXEL, 1);
tiff.SetField(TiffTag.BITSPERSAMPLE, 8 * byteDepth);
tiff.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
tiff.SetField(TiffTag.ROWSPERSTRIP, height);
tiff.SetField(TiffTag.XRESOLUTION, 88);
tiff.SetField(TiffTag.YRESOLUTION, 88);
tiff.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH);
tiff.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
tiff.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
tiff.SetField(TiffTag.COMPRESSION, Compression.NONE);
tiff.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);
tiff.SetField(TiffTag.SOFTWARE, "MyLib");
tiff.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.IEEEFP);
//Set the size of the tile
tiff.SetField(TiffTag.TILEWIDTH, tileSize);
tiff.SetField(TiffTag.TILELENGTH, tileSize);
//set the geographics info
//The following two lines never succeeded....
tiff.SetField(TiffTag.GEOTIFF_MODELTIEPOINTTAG, 0.0, 0.0, 0.0, leftTopX, leftTopY, 0.0);
tiff.SetField(TiffTag.GEOTIFF_MODELPIXELSCALETAG, pixelScaleX, pixelScaleY, 0.0);
//Write the tile data here
//........
//
}
}