static bool TransformTiffCorner(GTIF * gtif, GTIFDefn * defn, double x, double y, double& outLon, double& outLat) { /* Try to transform the coordinate into PCS space */ if( !GTIFImageToPCS( gtif, &x, &y ) ) return false; if( defn->Model == ModelTypeGeographic ) { outLon = x; outLat = y; return true; } else { if( GTIFProj4ToLatLong( defn, 1, &x, &y ) ) { outLon = x; outLat = y; return true; } int size = 0; tagtype_t type = TYPE_UNKNOWN; int key_count = GTIFKeyInfo(gtif, GTCitationGeoKey, &size, &type); if(key_count > 0 && key_count < 1024 && type == TYPE_ASCII && size == 1) { vector<char> ascii(key_count); int r = GTIFKeyGet(gtif, GTCitationGeoKey, &ascii[0], 0, key_count); if(r == key_count) { DebugAssert(ascii.back() == 0); string citation = string(&ascii[0]); if(citation == "PCS Name = WGS_1984_Web_Mercator_Auxiliary_Sphere") { char ** args = CSLTokenizeStringComplex("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs", " +", TRUE, FALSE); PJ * psPJ = pj_init( CSLCount(args), args ); CSLDestroy(args); if(psPJ) { projUV sUV; sUV.u = x; sUV.v = y; sUV = pj_inv( sUV, psPJ ); outLon = sUV.u * RAD_TO_DEG; outLat = sUV.v * RAD_TO_DEG; pj_free(psPJ); return true; } } } } } return false; }
static int GTIFReportACorner( GTIF *gtif, GTIFDefn *defn, FILE * fp_out, const char * corner_name, double x, double y, int inv_flag, int dec_flag ) { double x_saved, y_saved; /* Try to transform the coordinate into PCS space */ if( !GTIFImageToPCS( gtif, &x, &y ) ) return FALSE; x_saved = x; y_saved = y; fprintf( fp_out, "%-13s ", corner_name ); if( defn->Model == ModelTypeGeographic ) { if (dec_flag) { fprintf( fp_out, "(%s,", GTIFDecToDDec( x, "Long", 7 ) ); fprintf( fp_out, "%s)\n", GTIFDecToDDec( y, "Lat", 7 ) ); } else { fprintf( fp_out, "(%s,", GTIFDecToDMS( x, "Long", 2 ) ); fprintf( fp_out, "%s)\n", GTIFDecToDMS( y, "Lat", 2 ) ); } } else { fprintf( fp_out, "(%12.3f,%12.3f)", x, y ); if( GTIFProj4ToLatLong( defn, 1, &x, &y ) ) { if (dec_flag) { fprintf( fp_out, " (%s,", GTIFDecToDDec( x, "Long", 7 ) ); fprintf( fp_out, "%s)", GTIFDecToDDec( y, "Lat", 7 ) ); } else { fprintf( fp_out, " (%s,", GTIFDecToDMS( x, "Long", 2 ) ); fprintf( fp_out, "%s)", GTIFDecToDMS( y, "Lat", 2 ) ); } } fprintf( fp_out, "\n" ); } if( inv_flag && GTIFPCSToImage( gtif, &x_saved, &y_saved ) ) { fprintf( fp_out, " inverse (%11.3f,%11.3f)\n", x_saved, y_saved ); } return TRUE; }
static GeoPoint TiffPixelToGeoPoint(GTIF >if, GTIFDefn &defn, double x, double y) { if (!GTIFImageToPCS(>if, &x, &y)) return GeoPoint::Invalid(); if (defn.Model != ModelTypeGeographic && !GTIFProj4ToLatLong(&defn, 1, &x, &y)) return GeoPoint::Invalid(); return GeoPoint(Angle::Degrees(x), Angle::Degrees(y)); }