TIFF *tif=(TIFF*)0; GTIF *gtif=(GTIF*)0; /* GeoKey-level descriptor */ // Read (Open) the TIFF file tif=XTIFFOpen(tiffFilePath, "r"); if(!tif){ tmpstr.Format("Error reading %s GeoTIFF file", tiffFilePath); MessageBox(tmpstr, "File Import", MB_OK); return 2; // Return error reading tiff file } /* Open GTIF Key parser */ gtif = GTIFNew(tif); if (!gtif){ tmpstr.Format("Error reading %s GeoTIFF file", tiffFilePath); MessageBox(tmpstr, "File Import", MB_OK); return 2; // Return error reading tiff file } int versions[3]; /* Get the GeoTIFF directory info */ GTIFDirectoryInfo(gtif,versions,0); if (versions[MAJOR] > 1) { //printf("this file is too new for me\n"); tmpstr.Format("Error reading %s GeoTIFF file", tiffFilePath); MessageBox(tmpstr, "File Import", MB_OK); return 2; // Return error reading tiff file } // 6.2.1 GeoTIFF Configuration Keys geocode_t modelTypeCode, rasterModelType; GTIFKeyGet(gtif, GTModelTypeGeoKey, &modelTypeCode, 0,1); /* Model Type Codes */ GTIFKeyGet(gtif, GTRasterTypeGeoKey, &rasterModelType, 0, 1); /* Raster Type Codes */ //6.2.2 Geographic CS Parameter Keys geocode_t geoCDTypeCode, geodeticDatumCode, primeMeridiumCode, linearUnitCode, linearUnitValue, angularUnitCode, angularUnitValue, ellipsoideCode, semiMajorAxis, semiMinorAxis, geoInvertFlattening, angularUnitsCode, primeMeridianLongitude; GTIFKeyGet(gtif, GeographicTypeGeoKey, &geoCDTypeCode, 0, 1); /* Geographic CS Type Codes */ GTIFKeyGet(gtif, GeogGeodeticDatumGeoKey, &geodeticDatumCode, 0, 1); /* Geodetic Datum Codes */ GTIFKeyGet(gtif, GeogPrimeMeridianGeoKey, &primeMeridiumCode, 0, 1); /* Prime Meridian Codes */ GTIFKeyGet(gtif, GeogLinearUnitsGeoKey, &linearUnitCode, 0, 1); /* Linear Units Codes */ GTIFKeyGet(gtif, GeogLinearUnitSizeGeoKey, &linearUnitValue, 0, 1); /* Linear Units (meters) */ GTIFKeyGet(gtif, GeogAngularUnitsGeoKey, &angularUnitCode, 0, 1); /* Angular Units Codes */ GTIFKeyGet(gtif, GeogAngularUnitSizeGeoKey, &angularUnitValue, 0, 1); /* Angular Units (radians) */ GTIFKeyGet(gtif, GeogEllipsoidGeoKey, &ellipsoideCode, 0, 1); /* Ellipsoid Codes */ GTIFKeyGet(gtif, GeogSemiMajorAxisGeoKey, &semiMajorAxis, 0, 1); /* Geographic Semi Major Axis (GeogLinearUnits) */ GTIFKeyGet(gtif, GeogSemiMinorAxisGeoKey, &semiMinorAxis, 0, 1); /* Geographic Semi Minor Axis (GeogLinearUnits) */ GTIFKeyGet(gtif, GeogInvFlatteningGeoKey, &geoInvertFlattening, 0, 1); /* Geographic Invert Flattening (ratio) */ GTIFKeyGet(gtif, GeogAzimuthUnitsGeoKey, &angularUnitsCode, 0, 1); /* Angular Units Codes */ GTIFKeyGet(gtif, GeogPrimeMeridianLongGeoKey, &primeMeridianLongitude, 0, 1); /* Prime Meridian Longitude (GeogAngularUnit) */ //6.2.3 Projected CS Parameter Keys geocode_t projCSSystemCode, ProjCode, projCoordTransfCode, linearUnitsCode, linearUnitSize,projStdParallel1,projStdParallel2,projNatOriginLong, projNatOriginLat, projFalseEasting, projFalseNorthing, projFalseOriginLong, projFalseOriginLat,projFalseOriginEasting,projFalseOriginNorthing, projCenterLong,projCenterLat,projCenterEasting,projCenterNorthing, projScaleAtNatOrigin, projScaleAtCenter, projAzimuthAngle, projStraightVertPoleLong; GTIFKeyGet(gtif, ProjectedCSTypeGeoKey, &projCSSystemCode, 0, 1); /* Projected CS Type Codes */ GTIFKeyGet(gtif, ProjectionGeoKey, &ProjCode, 0, 1); /* Projection Code */ GTIFKeyGet(gtif, ProjCoordTransGeoKey, &projCoordTransfCode, 0, 1); /* Coordinate Transformation Codes */ GTIFKeyGet(gtif, ProjLinearUnitsGeoKey, &linearUnitsCode, 0, 1); /* Linear Units Codes */ GTIFKeyGet(gtif, ProjLinearUnitSizeGeoKey, &linearUnitSize, 0, 1); /* Linear Units Size (meters) */ GTIFKeyGet(gtif, ProjStdParallel1GeoKey, &projStdParallel1, 0, 1); /* ProjStdParallel1 (GeogAngularUnit) */ GTIFKeyGet(gtif, ProjStdParallel2GeoKey, &projStdParallel2, 0, 1); /* ProjStdParallel2 (GeogAngularUnit) */ GTIFKeyGet(gtif, ProjNatOriginLongGeoKey, &projNatOriginLong, 0, 1); /* ProjNatOriginLong (GeogAngularUnit) */ GTIFKeyGet(gtif, ProjNatOriginLatGeoKey, &projNatOriginLat, 0, 1); /* ProjNatOriginLat (GeogAngularUnit) */ GTIFKeyGet(gtif, ProjFalseEastingGeoKey, &projFalseEasting, 0, 1); /* ProjFalseEasting (ProjLinearUnits) */ GTIFKeyGet(gtif, ProjFalseNorthingGeoKey, &projFalseNorthing, 0, 1); /* ProjFalseNorthing (ProjLinearUnits) */ GTIFKeyGet(gtif, ProjFalseOriginLongGeoKey, &projFalseOriginLong, 0, 1); /* ProjFalseOriginLong (GeogAngularUnit ) */ GTIFKeyGet(gtif, ProjFalseOriginLatGeoKey, &projFalseOriginLat, 0, 1); /* ProjFalseOriginLat (GeogAngularUnit ) */ GTIFKeyGet(gtif, ProjFalseOriginEastingGeoKey, &projFalseOriginEasting, 0, 1); /* ProjFalseOriginEasting (ProjLinearUnits ) */ GTIFKeyGet(gtif, ProjFalseOriginNorthingGeoKey, &projFalseOriginNorthing, 0, 1); /* ProjFalseOriginNorthing (ProjLinearUnits ) */ GTIFKeyGet(gtif, ProjCenterLongGeoKey, &projCenterLong, 0, 1); /* ProjCenterLong (GeogAngularUnit ) */ GTIFKeyGet(gtif, ProjCenterLatGeoKey, &projCenterLat, 0, 1); /* ProjCenterLat (GeogAngularUnit ) */ GTIFKeyGet(gtif, ProjCenterEastingGeoKey, &projCenterEasting, 0, 1); /* ProjCenterEasting (ProjLinearUnits ) */ GTIFKeyGet(gtif, ProjCenterNorthingGeoKey, &projCenterNorthing, 0, 1); /* ProjCenterNorthing (ProjLinearUnits ) */ GTIFKeyGet(gtif, ProjScaleAtNatOriginGeoKey, &projScaleAtNatOrigin, 0, 1); /* ProjScaleAtNatOrigin (ratio) */ GTIFKeyGet(gtif, ProjScaleAtCenterGeoKey, &projScaleAtCenter, 0, 1); /* ProjScaleAtCenter (ratio ) */ GTIFKeyGet(gtif, ProjAzimuthAngleGeoKey, &projAzimuthAngle, 0, 1); /* ProjAzimuthAngle (GeogAzimuthUnit ) */ GTIFKeyGet(gtif, ProjStraightVertPoleLongGeoKey, &projStraightVertPoleLong, 0, 1); /* ProjStraightVertPoleLong (GeogAzimuthUnit ) */ //6.2.4 Vertical CS Keys geocode_t verticalCSType, verticalDatum, verticalUnits; GTIFKeyGet(gtif, VerticalCSTypeGeoKey, &verticalCSType, 0, 1); /* Vertical CS Type Codes */ GTIFKeyGet(gtif, VerticalDatumGeoKey, &verticalDatum, 0, 1); /* Vertical CS Datum Codes */ GTIFKeyGet(gtif, VerticalUnitsGeoKey, &verticalUnits, 0, 1); /* Linear Units Codes */ /* get rid of the key parser */ GTIFFree(gtif); // Close raw and tiff file and free memory _TIFFfree(buf); XTIFFClose(tif);