/** * Get Geotransform information for COSMO-SKYMED files * In case of success it stores the transformation * in adfGeoTransform. In case of failure it doesn't * modify adfGeoTransform * @param iProductType type of CSK subproduct, see HDF5CSKProduct */ void HDF5ImageDataset::CaptureCSKGeoTransform(int iProductType) { const char *pszSubdatasetName = GetSubdatasetName(); bHasGeoTransform = false; //If the product level is not L1C or L1D then //it doesn't have a valid projection if(iProductType == PROD_CSK_L1C || iProductType == PROD_CSK_L1D) { //If there is a subdataset if(pszSubdatasetName != NULL) { CPLString osULPath = pszSubdatasetName ; osULPath += "/Top Left East-North"; CPLString osLineSpacingPath = pszSubdatasetName; osLineSpacingPath += "/Line Spacing"; CPLString osColumnSpacingPath = pszSubdatasetName; osColumnSpacingPath += "/Column Spacing"; double *pdOutUL = NULL; double *pdLineSpacing = NULL; double *pdColumnSpacing = NULL; //If it could find the attributes on the metadata if(HDF5ReadDoubleAttr(osULPath.c_str(), &pdOutUL) == CE_Failure || HDF5ReadDoubleAttr(osLineSpacingPath.c_str(), &pdLineSpacing) == CE_Failure || HDF5ReadDoubleAttr(osColumnSpacingPath.c_str(), &pdColumnSpacing) == CE_Failure) { bHasGeoTransform = false; } else { // geotransform[1] : width of pixel // geotransform[4] : rotational coefficient, zero for north up images. // geotransform[2] : rotational coefficient, zero for north up images. // geotransform[5] : height of pixel (but negative) adfGeoTransform[0] = pdOutUL[0]; adfGeoTransform[1] = pdLineSpacing[0]; adfGeoTransform[2] = 0; adfGeoTransform[3] = pdOutUL[1]; adfGeoTransform[4] = 0; adfGeoTransform[5] = -pdColumnSpacing[0]; CPLFree(pdOutUL); CPLFree(pdLineSpacing); CPLFree(pdColumnSpacing); bHasGeoTransform = TRUE; } } } }
/** * Captures Geolocation information from a COSMO-SKYMED * file. * The geoid will allways be WGS84 * The projection type may be UTM or UPS, depending on the * latitude from the center of the image. * @param iProductType type of CSK subproduct, see HDF5CSKProduct */ void HDF5ImageDataset::CaptureCSKGeolocation(int iProductType) { double *dfProjFalseEastNorth; double *dfProjScaleFactor; double *dfCenterCoord; //Set the ellipsoid to WGS84 oSRS.SetWellKnownGeogCS( "WGS84" ); if(iProductType == PROD_CSK_L1C||iProductType == PROD_CSK_L1D) { //Check if all the metadata attributes are present if(HDF5ReadDoubleAttr("Map Projection False East-North", &dfProjFalseEastNorth) == CE_Failure|| HDF5ReadDoubleAttr("Map Projection Scale Factor", &dfProjScaleFactor) == CE_Failure|| HDF5ReadDoubleAttr("Map Projection Centre", &dfCenterCoord) == CE_Failure|| GetMetadataItem("Projection_ID") == NULL) { pszProjection = CPLStrdup(""); pszGCPProjection = CPLStrdup(""); CPLError( CE_Failure, CPLE_OpenFailed, "The CSK hdf5 file geolocation information is malformed\n" ); } else { //Fetch projection Type CPLString osProjectionID = GetMetadataItem("Projection_ID"); //If the projection is UTM if(EQUAL(osProjectionID,"UTM")) { // @TODO: use SetUTM oSRS.SetProjCS(SRS_PT_TRANSVERSE_MERCATOR); oSRS.SetTM(dfCenterCoord[0], dfCenterCoord[1], dfProjScaleFactor[0], dfProjFalseEastNorth[0], dfProjFalseEastNorth[1]); } else { //TODO Test! I didn't had any UPS projected files to test! //If the projection is UPS if(EQUAL(osProjectionID,"UPS")) { oSRS.SetProjCS(SRS_PT_POLAR_STEREOGRAPHIC); oSRS.SetPS(dfCenterCoord[0], dfCenterCoord[1], dfProjScaleFactor[0], dfProjFalseEastNorth[0], dfProjFalseEastNorth[1]); } } //Export Projection to Wkt. //In case of error then clean the projection if (oSRS.exportToWkt(&pszProjection) != OGRERR_NONE) pszProjection = CPLStrdup(""); CPLFree(dfCenterCoord); CPLFree(dfProjScaleFactor); CPLFree(dfProjFalseEastNorth); } } else { //Export GCPProjection to Wkt. //In case of error then clean the projection if(oSRS.exportToWkt(&pszGCPProjection) != OGRERR_NONE) pszGCPProjection = CPLStrdup(""); } }
/** * Retrieves and stores the GCPs from a COSMO-SKYMED dataset * It only retrieves the GCPs for L0, L1A and L1B products * for L1C and L1D products, geotransform is provided. * The GCPs provided will be the Image's corners. * @param iProductType type of CSK product @see HDF5CSKProductEnum */ void HDF5ImageDataset::CaptureCSKGCPs(int iProductType) { //Only retrieve GCPs for L0,L1A and L1B products if(iProductType == PROD_CSK_L0||iProductType == PROD_CSK_L1A|| iProductType == PROD_CSK_L1B) { int i; double *pdCornerCoordinates; nGCPCount=4; pasGCPList = (GDAL_GCP *) CPLCalloc(sizeof(GDAL_GCP),4); CPLString osCornerName[4]; double pdCornerPixel[4]; double pdCornerLine[4]; const char *pszSubdatasetName = GetSubdatasetName(); //Load the subdataset name first for(i=0;i <4;i++) osCornerName[i] = pszSubdatasetName; //Load the attribute name, and raster coordinates for //all the corners osCornerName[0] += "/Top Left Geodetic Coordinates"; pdCornerPixel[0] = 0; pdCornerLine[0] = 0; osCornerName[1] += "/Top Right Geodetic Coordinates"; pdCornerPixel[1] = GetRasterXSize(); pdCornerLine[1] = 0; osCornerName[2] += "/Bottom Left Geodetic Coordinates"; pdCornerPixel[2] = 0; pdCornerLine[2] = GetRasterYSize(); osCornerName[3] += "/Bottom Right Geodetic Coordinates"; pdCornerPixel[3] = GetRasterXSize(); pdCornerLine[3] = GetRasterYSize(); //For all the image's corners for(i=0;i<4;i++) { GDALInitGCPs( 1, pasGCPList + i ); CPLFree( pasGCPList[i].pszId ); pasGCPList[i].pszId = NULL; //Retrieve the attributes if(HDF5ReadDoubleAttr(osCornerName[i].c_str(), &pdCornerCoordinates) == CE_Failure) { CPLError( CE_Failure, CPLE_OpenFailed, "Error retrieving CSK GCPs\n" ); // Free on failure, e.g. in case of QLK subdataset. for( int i = 0; i < 4; i++ ) { if( pasGCPList[i].pszId ) CPLFree( pasGCPList[i].pszId ); if( pasGCPList[i].pszInfo ) CPLFree( pasGCPList[i].pszInfo ); } CPLFree( pasGCPList ); pasGCPList = NULL; nGCPCount = 0; break; } //Fill the GCPs name pasGCPList[i].pszId = CPLStrdup( osCornerName[i].c_str() ); //Fill the coordinates pasGCPList[i].dfGCPX = pdCornerCoordinates[1]; pasGCPList[i].dfGCPY = pdCornerCoordinates[0]; pasGCPList[i].dfGCPZ = pdCornerCoordinates[2]; pasGCPList[i].dfGCPPixel = pdCornerPixel[i]; pasGCPList[i].dfGCPLine = pdCornerLine[i]; //Free the returned coordinates CPLFree(pdCornerCoordinates); } } }