5 #include <QDomDocument>
31 if ((
m_image = XTIFFOpen(inputName.expanded().toAscii().data(),
"r")) == NULL) {
33 QString(
"Could not open TIFF image [") + inputName.expanded().toAscii().data() +
"]",
_FILEINFO_);
39 TIFFGetField(
m_image, TIFFTAG_IMAGELENGTH, &height);
43 TIFFGetField(
m_image, TIFFTAG_IMAGEWIDTH, &width);
51 if ((
m_raster = (uint32 *) malloc(
sizeof(uint32) * imagesize)) == NULL) {
53 "Could not allocate enough memory",
_FILEINFO_);
65 "Image has an undefined photometric interpretation",
_FILEINFO_);
110 geocode_t rasterType;
111 geocode_t coordSysType;
113 if ((GTIFKeyGet(
m_geotiff, GTModelTypeGeoKey, &modelType, 0, 1) == 1) &&
114 ((modelType == 1) || (modelType == 2))) {
116 if ((GTIFKeyGet(
m_geotiff, GTRasterTypeGeoKey, &rasterType, 0, 1) == 1) &&
117 (rasterType == 1 || rasterType == 2)) {
122 if (GTIFKeyGet(
m_geotiff, ProjectedCSTypeGeoKey, &coordSysType, 0, 1) == 1) {
125 FileName transFile((QString)
"$base/translations/geotiff/" +
127 if (transFile.fileExists()) {
131 geoTiffCodeTranslater.Auto(outPvl);
139 if (GTIFKeyGet(
m_geotiff, GeographicTypeGeoKey, &geoCode, 0, 1) == 1) {
140 std::cout <<
"GeographicTypeGeoKey = " << geoCode << std::endl;
143 std::cout <<
"no GeographicTypeGeoKey" << std::endl;
146 if (GTIFKeyGet(
m_geotiff, GeogAngularUnitsGeoKey, &geoCode, 0, 1) == 1) {
147 std::cout <<
"GeogAngularUnitsGeoKey = " << geoCode << std::endl;
150 std::cout <<
"no GeogAngularUnitsGeoKey" << std::endl;
153 if (GTIFKeyGet(
m_geotiff, GeogEllipsoidGeoKey, &geoCode, 0, 1) == 1) {
154 std::cout <<
"GeogEllipsoidGeoKey = " << geoCode << std::endl;
157 std::cout <<
"no GeogEllipsoidGeoKey" << std::endl;
160 if (GTIFKeyGet(
m_geotiff, GeogSemiMajorAxisGeoKey, &geoCode, 0, 1) == 1) {
161 std::cout <<
"GeogSemiMajorAxisGeoKey = " << geoCode << std::endl;
164 std::cout <<
"no GeogSemiMajorAxisGeoKey" << std::endl;
167 if (GTIFKeyGet(
m_geotiff, GeogSemiMinorAxisGeoKey, &geoCode, 0, 1) == 1) {
168 std::cout <<
"GeogSemiMinorAxisGeoKey = " << geoCode << std::endl;
171 std::cout <<
"no GeogSemiMinorAxisGeoKey" << std::endl;
174 if (GTIFKeyGet(
m_geotiff, GeogInvFlatteningGeoKey, &geoCode, 0, 1) == 1) {
175 std::cout <<
"GeogInvFlatteningGeoKey = " << geoCode << std::endl;
178 std::cout <<
"no GeogInvFlatteningGeoKey" << std::endl;
181 if (GTIFKeyGet(
m_geotiff, ProjCoordTransGeoKey, &geoCode, 0, 1) == 1) {
182 std::cout <<
"ProjCoordTransGeoKey = " << geoCode << std::endl;
185 std::cout <<
"no ProjCoordTransGeoKey" << std::endl;
188 if (GTIFKeyGet(
m_geotiff, ProjLinearUnitsGeoKey, &geoCode, 0, 1) == 1) {
189 std::cout <<
"ProjLinearUnitsGeoKey = " << geoCode << std::endl;
192 std::cout <<
"no ProjLinearUnitsGeoKey" << std::endl;
195 if (GTIFKeyGet(
m_geotiff, ProjStdParallel1GeoKey, &geoCode, 0, 1) == 1) {
196 std::cout <<
"ProjStdParallel1GeoKey = " << geoCode << std::endl;
199 std::cout <<
"no ProjStdParallel1GeoKey" << std::endl;
202 if (GTIFKeyGet(
m_geotiff, ProjStdParallel2GeoKey, &geoCode, 0, 1) == 1) {
203 std::cout <<
"ProjStdParallel2GeoKey = " << geoCode << std::endl;
206 std::cout <<
"no ProjStdParallel2GeoKey" << std::endl;
209 if (GTIFKeyGet(
m_geotiff, ProjNatOriginLongGeoKey, &geoCode, 0, 1) == 1) {
210 std::cout <<
"ProjNatOriginLongGeoKey = " << geoCode << std::endl;
213 std::cout <<
"no ProjNatOriginLongGeoKey" << std::endl;
216 if (GTIFKeyGet(
m_geotiff, ProjNatOriginLatGeoKey, &geoCode, 0, 1) == 1) {
217 std::cout <<
"ProjNatOriginLatGeoKey = " << geoCode << std::endl;
220 std::cout <<
"no ProjNatOriginLatGeoKey" << std::endl;
223 if (GTIFKeyGet(
m_geotiff, ProjFalseEastingGeoKey, &geoCode, 0, 1) == 1) {
224 std::cout <<
"ProjFalseEastingGeoKey = " << geoCode << std::endl;
227 std::cout <<
"no ProjFalseEastingGeoKey" << std::endl;
230 if (GTIFKeyGet(
m_geotiff, ProjFalseNorthingGeoKey, &geoCode, 0, 1) == 1) {
231 std::cout <<
"ProjFalseNorthingGeoKey = " << geoCode << std::endl;
234 std::cout <<
"no ProjFalseNorthingGeoKey" << std::endl;
237 if (GTIFKeyGet(
m_geotiff, ProjFalseOriginLongGeoKey, &geoCode, 0, 1) == 1) {
238 std::cout <<
"ProjFalseOriginLongGeoKey = " << geoCode << std::endl;
241 std::cout <<
"no ProjFalseOriginLongGeoKey" << std::endl;
244 if (GTIFKeyGet(
m_geotiff, ProjFalseOriginLatGeoKey, &geoCode, 0, 1) == 1) {
245 std::cout <<
"ProjFalseOriginLatGeoKey = " << geoCode << std::endl;
248 std::cout <<
"no ProjFalseOriginLatGeoKey" << std::endl;
251 if (GTIFKeyGet(
m_geotiff, ProjFalseOriginEastingGeoKey, &geoCode, 0, 1) == 1) {
252 std::cout <<
"ProjFalseOriginEastingGeoKey = " << geoCode << std::endl;
255 std::cout <<
"no ProjFalseOriginEastingGeoKey" << std::endl;
258 if (GTIFKeyGet(
m_geotiff, ProjFalseOriginNorthingGeoKey, &geoCode, 0, 1) == 1) {
259 std::cout <<
"ProjFalseOriginNorthingGeoKey = " << geoCode << std::endl;
262 std::cout <<
"no ProjFalseOriginNorthingGeoKey" << std::endl;
265 if (GTIFKeyGet(
m_geotiff, ProjCenterLongGeoKey, &geoCode, 0, 1) == 1) {
266 std::cout <<
"ProjCenterLongGeoKey = " << geoCode << std::endl;
269 std::cout <<
"no ProjCenterLongGeoKey" << std::endl;
272 if (GTIFKeyGet(
m_geotiff, ProjCenterLatGeoKey, &geoCode, 0, 1) == 1) {
273 std::cout <<
"ProjCenterLatGeoKey = " << geoCode << std::endl;
276 std::cout <<
"no ProjCenterLatGeoKey" << std::endl;
279 if (GTIFKeyGet(
m_geotiff, ProjCenterEastingGeoKey, &geoCode, 0, 1) == 1) {
280 std::cout <<
"ProjCenterEastingGeoKey = " << geoCode << std::endl;
283 std::cout <<
"no ProjCenterEastingGeoKey" << std::endl;
286 if (GTIFKeyGet(
m_geotiff, ProjCenterNorthingGeoKey, &geoCode, 0, 1) == 1) {
287 std::cout <<
"ProjCenterNorthingGeoKey = " << geoCode << std::endl;
290 std::cout <<
"no ProjCenterNorthingGeoKey" << std::endl;
293 if (GTIFKeyGet(
m_geotiff, ProjScaleAtNatOriginGeoKey, &geoCode, 0, 1) == 1) {
294 std::cout <<
"ProjScaleAtNatOriginGeoKey = " << geoCode << std::endl;
297 std::cout <<
"no ProjScaleAtNatOriginGeoKey" << std::endl;
300 if (GTIFKeyGet(
m_geotiff, ProjAzimuthAngleGeoKey, &geoCode, 0, 1) == 1) {
301 std::cout <<
"ProjAzimuthAngleGeoKey = " << geoCode << std::endl;
304 std::cout <<
"no ProjAzimuthAngleGeoKey" << std::endl;
307 if (GTIFKeyGet(
m_geotiff, ProjStraightVertPoleLongGeoKey, &geoCode, 0, 1) == 1) {
308 std::cout <<
"ProjStraightVertPoleLongGeoKey = " << geoCode << std::endl;
311 std::cout <<
"no ProjStraightVertPoleLongGeoKey" << std::endl;
314 if (GTIFKeyGet(
m_geotiff, VerticalUnitsGeoKey, &geoCode, 0, 1) == 1) {
315 std::cout <<
"VerticalUnitsGeoKey = " << geoCode << std::endl;
318 std::cout <<
"no VerticalUnitsGeoKey" << std::endl;
343 double pixelResolution = mapGroup[
"PixelResolution"];
345 double localRadius = proj->
LocalRadius(trueScaleLat);
347 double scale = (2.0 *
Isis::PI * localRadius) / (360.0 * pixelResolution);
371 char *gdalMetadataBuf;
372 short int gdalMetadataCount = 0;
374 if (TIFFGetField(
m_image, 42112, &gdalMetadataCount, &gdalMetadataBuf) == 1) {
376 QString gdalMetadataQstring(gdalMetadataBuf);
378 QDomDocument gdalDoc(
"GDALMetaData");
379 if (gdalDoc.setContent(gdalMetadataQstring)) {
380 QDomElement gdalRoot = gdalDoc.documentElement();
381 if (gdalRoot.tagName() ==
"GDALMetadata") {
383 QDomNode gdalNode = gdalRoot.firstChild();
384 while (!gdalNode.isNull()) {
385 QDomElement gdalElement = gdalNode.toElement();
386 if (!gdalElement.isNull() ) {
387 if (gdalElement.tagName() ==
"Item") {
388 if (gdalElement.attribute(
"name",
"") ==
"WEST_LONGITUDE") {
389 QString westLon = gdalElement.text();
392 else if (gdalElement.attribute(
"name",
"") ==
"EAST_LONGITUDE") {
393 QString eastLon = gdalElement.text();
396 else if (gdalElement.attribute(
"name",
"") ==
"SOUTH_LATITUDE") {
397 QString southLat = gdalElement.text();
400 else if (gdalElement.attribute(
"name",
"") ==
"NORTH_LATITUDE") {
401 QString northLat = gdalElement.text();
407 gdalNode = gdalNode.nextSibling();
429 double *tiePoints = NULL;
430 short int tieCount = 0;
431 if (TIFFGetField(
m_image, TIFFTAG_GEOTIEPOINTS, &tieCount, &tiePoints) == 1) {
435 if (tiePoints[0] == 0.0 && tiePoints[1] == 0.0) {
438 x = (double)map[
"FalseEasting"] + tiePoints[3];
444 y = (double)map[
"FalseNorthing"] + tiePoints[4];
452 QString msg =
"The upper left X and Y can not be calculated. Unsupported tiepoint "
453 "type in Tiff file (i.e., not ( 0.0, 0.0))";
475 double *scales = NULL;
476 short int scaleCount = 0;
477 if (TIFFGetField(
m_image, TIFFTAG_GEOPIXELSCALE, &scaleCount, &scales) == 1) {
481 if ((scaleCount == 3) && (scales[0] > 0.0 && scales[1] > 0.0) && (scales[0] == scales[1])) {
485 QString msg =
"The pixel resolution could not be retrieved from the TIFF file. Unsupported "
486 "PixelScale tag values.";
517 m_photo == PHOTOMETRIC_MINISWHITE ||
518 m_photo == PHOTOMETRIC_MINISBLACK;
594 return TIFFGetR(pixel);
606 return TIFFGetG(pixel);
618 return TIFFGetB(pixel);
630 return TIFFGetA(pixel);