std::string FindBoostDataBaseFile() { const char* pszBase = "date_time_zonespec"; const char* pszExt = "csv"; const char* pszFilename; const char* pszNinjaPath; const char* pszNinjaSharePath; char pszFilePath[MAX_PATH]; CPLGetExecPath(pszFilePath, MAX_PATH); pszNinjaPath = CPLGetPath(pszFilePath); pszNinjaSharePath = CPLProjectRelativeFilename(pszNinjaPath, "../share/windninja"); pszFilename = CPLFormFilename(CPLGetCurrentDir(), pszBase, pszExt); if(CPLCheckForFile((char*)pszFilename, NULL)) { return std::string((char*)pszFilename); } pszFilename = CPLFormFilename(pszNinjaPath, pszBase, pszExt); if(CPLCheckForFile((char*)pszFilename, NULL)) { return std::string((char*)pszFilename); } pszFilename = CPLFormFilename(pszNinjaSharePath, pszBase, pszExt); if(CPLCheckForFile((char*)pszFilename, NULL)) { return std::string((char*)pszFilename); } return std::string(); }
CPLString GetWorldFilePath(const CPLString &soPath) { //1. thirst and last char from ext and third char set w (e.g. jpw) CPLString sExt = CPLGetExtension(soPath); CPLString sNewExt; sNewExt += sExt[0]; sNewExt += sExt[sExt.size() - 1]; sNewExt += 'w'; CPLString szPath = (char*)CPLResetExtension(soPath, sNewExt); if(CPLCheckForFile((char*)szPath.c_str(), NULL)) return szPath; //4. add wx to ext sNewExt += 'x'; szPath = (char*)CPLResetExtension(soPath, sNewExt); if(CPLCheckForFile((char*)szPath.c_str(), NULL)) return szPath; //2. wld szPath = (char*)CPLResetExtension(soPath, "wld"); if(CPLCheckForFile((char*)szPath.c_str(), NULL)) return szPath; //3. add w to ext szPath = soPath + CPLString("w"); if(CPLCheckForFile((char*)szPath.c_str(), NULL)) return szPath; return CPLString(); }
/** * GDALMDReaderRapidEye() */ GDALMDReaderRapidEye::GDALMDReaderRapidEye(const char *pszPath, char **papszSiblingFiles) : GDALMDReaderBase(pszPath, papszSiblingFiles) { const char* pszDirName = CPLGetDirname(pszPath); const char* pszBaseName = CPLGetBasename(pszPath); const char* pszIMDSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("%s_metadata", pszBaseName), "xml" ); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osXMLSourceFilename = pszIMDSourceFilename; } else { pszIMDSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("%s_METADATA", pszBaseName), "XML" ); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osXMLSourceFilename = pszIMDSourceFilename; } } if(m_osXMLSourceFilename.size()) CPLDebug( "MDReaderRapidEye", "XML Filename: %s", m_osXMLSourceFilename.c_str() ); }
/** * GDALMDReaderOrbView() */ GDALMDReaderOrbView::GDALMDReaderOrbView(const char *pszPath, char **papszSiblingFiles) : GDALMDReaderBase(pszPath, papszSiblingFiles) { m_osIMDSourceFilename = GDALFindAssociatedFile( pszPath, "PVL", papszSiblingFiles, 0 ); const char* pszBaseName = CPLGetBasename(pszPath); const char* pszDirName = CPLGetDirname(pszPath); const char* pszRPBSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("%s_rpc", pszBaseName), "txt" ); if (CPLCheckForFile((char*)pszRPBSourceFilename, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPBSourceFilename; } else { pszRPBSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("%s_RPC", pszBaseName), "TXT" ); if (CPLCheckForFile((char*)pszRPBSourceFilename, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPBSourceFilename; } } if( m_osIMDSourceFilename.size() ) CPLDebug( "MDReaderOrbView", "IMD Filename: %s", m_osIMDSourceFilename.c_str() ); if( m_osRPBSourceFilename.size() ) CPLDebug( "MDReaderOrbView", "RPB Filename: %s", m_osRPBSourceFilename.c_str() ); }
/** * GDALMDReaderSpot() */ GDALMDReaderSpot::GDALMDReaderSpot(const char *pszPath, char **papszSiblingFiles) : GDALMDReaderPleiades(pszPath, papszSiblingFiles) { const char* pszIMDSourceFilename; const char* pszDirName = CPLGetDirname(pszPath); if(m_osIMDSourceFilename.empty()) { pszIMDSourceFilename = CPLFormFilename( pszDirName, "METADATA.DIM", NULL ); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } else { pszIMDSourceFilename = CPLFormFilename( pszDirName, "metadata.dim", NULL ); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } } } // if the file name ended on METADATA.DIM // Linux specific // example: R2_CAT_091028105025131_1\METADATA.DIM if(m_osIMDSourceFilename.empty()) { if(EQUAL(CPLGetFilename(pszPath), "IMAGERY.TIF")) { pszIMDSourceFilename = CPLSPrintf( "%s\\METADATA.DIM", CPLGetPath(pszPath)); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } else { pszIMDSourceFilename = CPLSPrintf( "%s\\metadata.dim", CPLGetPath(pszPath)); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } } } } if(m_osIMDSourceFilename.size()) CPLDebug( "MDReaderSpot", "IMD Filename: %s", m_osIMDSourceFilename.c_str() ); }
/** * GDALMDReaderLandsat() */ GDALMDReaderLandsat::GDALMDReaderLandsat(const char *pszPath, char **papszSiblingFiles) : GDALMDReaderBase(pszPath, papszSiblingFiles) { const char* pszBaseName = CPLGetBasename(pszPath); const char* pszDirName = CPLGetDirname(pszPath); size_t nBaseNameLen = strlen(pszBaseName); if( nBaseNameLen > 511 ) return; // split file name by _B or _b char szMetadataName[512] = {0}; size_t i; for(i = 0; i < nBaseNameLen; i++) { szMetadataName[i] = pszBaseName[i]; if(STARTS_WITH_CI(pszBaseName + i, "_B") || STARTS_WITH_CI(pszBaseName + i, "_b")) { break; } } // form metadata file name CPLStrlcpy(szMetadataName + i, "_MTL.txt", 9); const char* pszIMDSourceFilename = CPLFormFilename( pszDirName, szMetadataName, NULL ); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } else { CPLStrlcpy(szMetadataName + i, "_MTL.TXT", 9); pszIMDSourceFilename = CPLFormFilename( pszDirName, szMetadataName, NULL ); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } } if( !m_osIMDSourceFilename.empty() ) CPLDebug( "MDReaderLandsat", "IMD Filename: %s", m_osIMDSourceFilename.c_str() ); }
~GdalTestData() { /* SrtmFetch may leave a file */ if( CPLCheckForFile( (char*) pszFilename.c_str(), NULL ) ) { VSIUnlink( pszFilename.c_str() ); } if( NULL != fetch ) { delete fetch; } if( NULL != poDS ) { GDALClose( (GDALDatasetH) poDS ); } }
/** * \brief Find a file or folder in the WindNinja data path * * XXX: Refactored by Kyle 20130117 * * For example the date_time_zonespec.csv file is location in data. If * WINDNINJA_DATA is *not* defined, try to find the file relative to the bin * path, ie ../share/data, otherwise return WINDNINJA_DATA + filename. * * \param file file or folder to look for. * \return a full path to file */ std::string FindDataPath(std::string file) { const char* pszFilename; const char* pszNinjaPath; const char* pszNinjaDataPath; const char* pszCurDir; char pszExePath[MAX_PATH]; /* Check WINDNINJA_DATA */ VSIStatBufL sStat; pszNinjaDataPath = CPLGetConfigOption( "WINDNINJA_DATA", NULL ); if( pszNinjaDataPath != NULL ) { pszFilename = CPLFormFilename( pszNinjaDataPath, file.c_str(), NULL ); VSIStatL( pszFilename, &sStat ); if( VSI_ISREG( sStat.st_mode ) || VSI_ISDIR( sStat.st_mode ) ) { return std::string( pszFilename ); } } /* Check 'normal' installation location */ CPLGetExecPath( pszExePath, MAX_PATH ); pszNinjaPath = CPLGetPath( pszExePath ); pszNinjaDataPath = CPLProjectRelativeFilename(pszNinjaPath, "../share/windninja"); pszFilename = CPLFormFilename( pszNinjaDataPath, file.c_str(), NULL ); VSIStatL( pszFilename, &sStat ); if( VSI_ISREG( sStat.st_mode ) || VSI_ISDIR( sStat.st_mode ) ) { return std::string( pszFilename ); } /* Check the current directory */ pszCurDir = CPLGetCurrentDir(); pszFilename = CPLFormFilename( pszCurDir, file.c_str(), NULL ); CPLFree( (void*)pszCurDir ); if( CPLCheckForFile( (char*)pszFilename, NULL )) { return std::string( pszFilename ); } return std::string(); }
/* ** Fetch a nomads forecast from the NWS servers. The forecasts consist of grib ** files, one forecast for each forecast hour. The time starts and the nearest ** forecast hour *before* the reference time passed. If no reference time is ** passed, or it is not valid, now() is used. ** ** The forecasts are downloaded into a temporary directory. If the entire ** download succeeds, then the files are copied into the path specified. If ** the path specified is a zip file (ends in *.zip), then the forecast files ** are zipped. ** ** Available compile time configuration options: ** NOMADS_USE_IP: Use the ip address instead of the hostname. It ** possibly goes around dns lookup, but it's doubtfull. ** NOMADS_ENABLE_ASYNC: Allow for asynchronous connections to the ** server. ** NOMADS_EXPER_FORECASTS: Compile in forecasts that may not work with ** the current configuration, essentially ** unsupported (ie NARRE, RTMA). ** NOMADS_USE_VSI_READ: Use the VSI*L api for downloading. This will ** allow definition of chunk sizes for download, ** although it is probably unnecessary. See ** NOMADS_VSI_BLOCK_SIZE below. If not enabled, a ** single fetch is made for each file, which is ** faster. ** Available runtime configuration options: ** NOMADS_THREAD_COUNT: Number of threads to use for downloads if ** NOMADS_ENABLE_ASYNC is set to ON during ** compilation. Default is 4. ** NOMADS_VSI_BLOCK_SIZE: Number of bytes to request at a time when ** downloading files if NOMADS_USE_VSI_READ is ** set to ON during compilation. Default is 512. ** NOMADS_MAX_FCST_REWIND: Number of forecast run time steps to go back ** to attempt to get a full time frame. ** GDAL_HTTP_TIMEOUT: Timeout for HTTP requests in seconds. We should ** be able to set this reasonably low. ** ** \param pszModelKey The name key of the model to use, ie "nam_conus". For a ** listing of models, see nomads.ncep.gov or /see nomads.h ** ** \param pszRefTime The reference time to begin searching for forecasts from. ** The search starts at refrence time, then goes back until ** it hits a valid forecast time. If the download cannot be ** complete, it will step back NOMADS_MAX_FCST_REWIND ** foreacst times to attempt to get a full forecast. ** ** \param nHours The extent of hours to download forecasts from the reference ** time. If we step back, we will still grab all forecasts up ** until nHours from the reference time, not the forecast time. ** ** \param nStride The number of forecasts to skip in time steps. For example, ** if 12 hours of gfs is requested (normally 5 files/steps (0, ** 3, 6, 9, 12) with a stride of 2, you'd get 0, 6, 12 forecast ** hours. ** ** \param padfBbox The bounding box of the request in WGS84 decimal degrees. ** Order is xmin, xmax, ymax, ymin. ** ** \param pszDstVsiPath The location to write the files. If the location ** has an extension of ".zip", then the output files are ** written as a zip archive, otherwise to a path. ** ** \param papszOptions List of key=value options, unused. ** ** \param pfnProgress Optional progress function. ** ** \return NOMADS_OK(0) on success, NOMADS_ERR(1) otherwise. */ int NomadsFetch( const char *pszModelKey, const char *pszRefTime, int nHours, int nStride, double *padfBbox, const char *pszDstVsiPath, char ** papszOptions, GDALProgressFunc pfnProgress ) { const char **ppszKey = NULL; int nFcstHour = 0; int *panRunHours = NULL; int i = 0; int j = 0; int k = 0; int t = 0; int rc = 0; char **papszDownloadUrls = NULL; char **papszOutputFiles = NULL; char **papszFinalFiles = NULL; int nFilesToGet = 0; const char *pszTmpDir; const char *pszConfigOpt; int nFcstTries; int nMaxFcstRewind; int nrc; int bZip; void **pThreads; int nThreads; const char *pszThreadCount; NomadsThreadData *pasData; nomads_utc *ref, *end, *fcst; nrc = NOMADS_OK; CPLDebug( "NOMADS", "Fetching data for bounding box: %lf, %lf, %lf, %lf", padfBbox[0], padfBbox[1], padfBbox[2], padfBbox[3] ); ppszKey = NomadsFindModel( pszModelKey ); if( ppszKey == NULL ) { CPLError( CE_Failure, CPLE_AppDefined, "Could not find model key in nomads data" ); return NOMADS_ERR; } NomadsUtcCreate( &ref ); NomadsUtcCreate( &end ); rc = NOMADS_OK; if( pszRefTime ) { rc = NomadsUtcFromIsoFrmt( ref, pszRefTime ); } if( rc != NOMADS_OK || pszRefTime == NULL ) { NomadsUtcNow( ref ); } NomadsUtcCopy( end, ref ); NomadsUtcAddHours( end, nHours ); /* Disable unneeded reading of entire directories, good speedup */ CPLSetConfigOption( "GDAL_DISABLE_READDIR_ON_OPEN", "TRUE" ); pszConfigOpt = CPLGetConfigOption( "NOMADS_HTTP_TIMEOUT", "20" ); if( pszConfigOpt != NULL ) { CPLSetConfigOption( "GDAL_HTTP_TIMEOUT", pszConfigOpt ); } nMaxFcstRewind = atoi( CPLGetConfigOption( "NOMADS_MAX_FCST_REWIND", "2" ) ); if( nMaxFcstRewind < 1 || nMaxFcstRewind > 24 ) { nMaxFcstRewind = 2; } /* Go back at least 3 for rap, as it may not get updated all the time. */ if( EQUALN( pszModelKey, "rap", 3 ) || EQUALN( pszModelKey, "hrrr", 4 ) ) { nMaxFcstRewind = nMaxFcstRewind > 3 ? nMaxFcstRewind : 3; } #ifdef NOMADS_ENABLE_ASYNC pszThreadCount = CPLGetConfigOption( "NOMADS_THREAD_COUNT", "4" ); nThreads = atoi( pszThreadCount ); if( nThreads < 1 || nThreads > 96 ) { nThreads = 4; } pThreads = CPLMalloc( sizeof( void * ) * nThreads ); pasData = CPLMalloc( sizeof( NomadsThreadData ) * nThreads ); #else /* NOMADS_ENABLE_ASYNC */ /* Unused variables, set to null to so free is no-op */ nThreads = 1; pThreads = NULL; pasData = NULL; #endif /* NOMADS_ENABLE_ASYNC */ fcst = NULL; nFcstTries = 0; while( nFcstTries < nMaxFcstRewind ) { nrc = NOMADS_OK; fcst = NomadsSetForecastTime( ppszKey, ref, nFcstTries ); nFcstHour = fcst->ts->tm_hour; CPLDebug( "WINDNINJA", "Generated forecast time in utc: %s", NomadsUtcStrfTime( fcst, "%Y%m%dT%HZ" ) ); if( EQUAL( pszModelKey, "rtma_conus" ) ) { panRunHours = (int*)CPLMalloc( sizeof( int ) ); nFilesToGet = 1; } else { nFilesToGet = NomadsBuildForecastRunHours( ppszKey, fcst, end, nHours, nStride, &panRunHours ); } papszDownloadUrls = NomadsBuildForecastFileList( pszModelKey, nFcstHour, panRunHours, nFilesToGet, fcst, padfBbox ); if( papszDownloadUrls == NULL ) { CPLError( CE_Failure, CPLE_AppDefined, "Could not generate list of URLs to download, invalid data" ); nFcstTries++; NomadsUtcFree( fcst ); fcst = NULL; nrc = NOMADS_ERR; continue; } pszTmpDir = CPLStrdup( CPLGenerateTempFilename( NULL ) ); CPLDebug( "WINDNINJA", "Creating Temp directory: %s", pszTmpDir ); VSIMkdir( pszTmpDir, 0777 ); papszOutputFiles = NomadsBuildOutputFileList( pszModelKey, nFcstHour, panRunHours, nFilesToGet, pszTmpDir, FALSE ); if( papszOutputFiles == NULL ) { CPLError( CE_Failure, CPLE_AppDefined, "Could not generate list of URLs to download, invalid data" ); nFcstTries++; CSLDestroy( papszDownloadUrls ); NomadsUtcFree( fcst ); fcst = NULL; nrc = NOMADS_ERR; continue; } CPLAssert( CSLCount( papszDownloadUrls ) == nFilesToGet ); CPLAssert( CSLCount( papszOutputFiles ) == nFilesToGet ); if( pfnProgress ) { pfnProgress( 0.0, "Starting download...", NULL ); } /* Download one file and start over if it's not there. */ #ifdef NOMADS_USE_VSI_READ nrc = NomadsFetchVsi( papszDownloadUrls[0], papszOutputFiles[0] ); #else /* NOMADS_USE_VSI_READ */ nrc = NomadsFetchHttp( papszDownloadUrls[0], papszOutputFiles[0] ); #endif /* NOMADS_USE_VSI_READ */ if( nrc != NOMADS_OK ) { CPLError( CE_Warning, CPLE_AppDefined, "Failed to download forecast, " \ "stepping back one forecast run time step." ); nFcstTries++; CPLSleep( 1 ); /* ** Don't explicitly break here. We'll skip the while loop because ** nrc != NOMADS_OK, and we can clean up memory and shift times in ** one spot to avoid duplicate code. */ } /* Get the rest */ i = 1; while( i < nFilesToGet && nrc == NOMADS_OK ) { if( pfnProgress ) { if( pfnProgress( (double)i / nFilesToGet, CPLSPrintf( "Downloading %s...", CPLGetFilename( papszOutputFiles[i] ) ), NULL ) ) { CPLError( CE_Failure, CPLE_UserInterrupt, "Cancelled by user." ); nrc = NOMADS_ERR; nFcstTries = nMaxFcstRewind; break; } } #ifdef NOMADS_ENABLE_ASYNC k = i > nFilesToGet - nThreads ? (nFilesToGet - 1) % nThreads : nThreads; for( t = 0; t < k; t++ ) { pasData[t].pszUrl = papszDownloadUrls[i]; pasData[t].pszFilename = papszOutputFiles[i]; pThreads[t] = CPLCreateJoinableThread( NomadsFetchAsync, &pasData[t] ); i++; } for( t = 0; t < k; t++ ) { CPLJoinThread( pThreads[t] ); } for( t = 0; t < k; t++ ) { if( pasData[t].nErr ) { CPLError( CE_Warning, CPLE_AppDefined, "Threaded download failed, attempting " \ "serial download for %s", CPLGetFilename( pasData[t].pszFilename ) ); /* Try again, serially though */ if( CPLCheckForFile( (char *)pasData[t].pszFilename, NULL ) ); { VSIUnlink( pasData[t].pszFilename ); } #ifdef NOMADS_USE_VSI_READ rc = NomadsFetchVsi( pasData[t].pszUrl, pasData[t].pszFilename ); #else /* NOMADS_USE_VSI_READ */ rc = NomadsFetchHttp( pasData[t].pszUrl, pasData[t].pszFilename ); #endif /* NOMADS_USE_VSI_READ */ if( rc != NOMADS_OK ) { nrc = rc; } } } #else /* NOMADS_ENABLE_ASYNC */ #ifdef NOMADS_USE_VSI_READ nrc = NomadsFetchVsi( papszDownloadUrls[i], papszOutputFiles[i] ); #else /* NOMADS_USE_VSI_READ */ nrc = NomadsFetchHttp( papszDownloadUrls[i], papszOutputFiles[i] ); #endif /* NOMADS_USE_VSI_READ */ i++; #endif /* NOMADS_ENABLE_ASYNC */ if( nrc != NOMADS_OK ) { CPLError( CE_Warning, CPLE_AppDefined, "Failed to download forecast, " \ "stepping back one forecast run time step." ); nFcstTries++; CPLSleep( 1 ); break; } } /* ** XXX Cleanup XXX ** After each loop we can get rid of the urls, but we can only get rid ** of the others if they are to be reallocated in the next loop. Any ** cleanup in the else nrc == NOMADS_OK clause should be cleaned up in ** the nrc == NOMADS_OK outside the loop. Those are held so we can ** process the output files and zip them into an archive. */ CSLDestroy( papszDownloadUrls ); NomadsUtcFree( fcst ); if( nrc == NOMADS_OK ) { break; } else { CPLFree( (void*)panRunHours ); CSLDestroy( papszOutputFiles ); CPLUnlinkTree( pszTmpDir ); CPLFree( (void*)pszTmpDir ); } } if( nrc == NOMADS_OK ) { bZip = EQUAL( CPLGetExtension( pszDstVsiPath ), "zip" ) ? TRUE : FALSE; papszFinalFiles = NomadsBuildOutputFileList( pszModelKey, nFcstHour, panRunHours, nFilesToGet, pszDstVsiPath, bZip ); CPLFree( (void*)panRunHours ); if( CPLCheckForFile( (char*)pszDstVsiPath, NULL ) ) { CPLUnlinkTree( pszDstVsiPath ); } if( !bZip ) { VSIMkdir( pszDstVsiPath, 0777 ); } nrc = NomadsZipFiles( papszOutputFiles, papszFinalFiles ); CSLDestroy( papszOutputFiles ); CSLDestroy( papszFinalFiles ); if( nrc != NOMADS_OK ) { CPLError( CE_Failure, CPLE_AppDefined, "Could not copy files into path, unknown i/o failure" ); CPLUnlinkTree( pszDstVsiPath ); } CPLUnlinkTree( pszTmpDir ); CPLFree( (void*)pszTmpDir ); } CPLFree( (void*)pasData ); CPLFree( (void**)pThreads ); NomadsUtcFree( ref ); NomadsUtcFree( end ); CPLSetConfigOption( "GDAL_HTTP_TIMEOUT", NULL ); CPLSetConfigOption( "GDAL_DISABLE_READDIR_ON_OPEN", NULL ); if( nrc == NOMADS_OK && pfnProgress ) { pfnProgress( 1.0, NULL, NULL ); } return nrc; }
bool wxGxPrjFactory::GetChildren(wxGxObject* pParent, char** &pFileNames, wxArrayLong & pChildrenIds) { bool bCheckNames = CSLCount(pFileNames) < CHECK_DUBLES_MAX_COUNT; for(int i = CSLCount(pFileNames) - 1; i >= 0; i-- ) { CPLString szExt = CPLGetExtension(pFileNames[i]); wxGxObject* pGxObj = NULL; if(wxGISEQUAL(szExt, "prj")) { bool bAdd = true; for(int j = 0; prj_notadd_exts[j] != NULL; ++j ) { if(CPLCheckForFile((char*)CPLResetExtension(pFileNames[i], prj_notadd_exts[j]), NULL)) { bAdd = false; break; } } if(bAdd) { pGxObj = GetGxObject(pParent, GetConvName(pFileNames[i]), pFileNames[i], enumESRIPrjFile, bCheckNames); } pFileNames = CSLRemoveStrings( pFileNames, i, 1, NULL ); } else if(wxGISEQUAL(szExt, "qpj")) { bool bAdd = true; for(int j = 0; prj_notadd_exts[j] != NULL; ++j ) { if(CPLCheckForFile((char*)CPLResetExtension(pFileNames[i], prj_notadd_exts[j]), NULL)) { bAdd = false; break; } } if(bAdd) { pGxObj = GetGxObject(pParent, GetConvName(pFileNames[i]), pFileNames[i], enumQPJfile, bCheckNames); } pFileNames = CSLRemoveStrings( pFileNames, i, 1, NULL ); } else if(wxGISEQUAL(szExt, "spr")) { pGxObj = GetGxObject(pParent, GetConvName(pFileNames[i]), pFileNames[i], enumSPRfile, bCheckNames); pFileNames = CSLRemoveStrings( pFileNames, i, 1, NULL ); } if(pGxObj) { pChildrenIds.Add(pGxObj->GetId()); pGxObj = NULL; } } return true; }
bool wxGxRasterFactory::GetChildren(wxGxObject* pParent, char** &pFileNames, wxArrayLong & pChildrenIds) { bool bCheckNames = CSLCount(pFileNames) < CHECK_DUBLES_MAX_COUNT; for(int i = CSLCount(pFileNames) - 1; i >= 0; i-- ) { wxGxObject* pGxObj = NULL; CPLString szExt = CPLGetExtension(pFileNames[i]); CPLString szPath; bool bContinue(false); unsigned int j; for(j = 0; j < sizeof(raster_exts) / sizeof(raster_exts[0]); ++j) { if(wxGISEQUAL(szExt, raster_exts[j].sExt) ) { if(raster_exts[j].bAvailable) { CPLString szPath(pFileNames[i]); pGxObj = GetGxObject(pParent, GetConvName(szPath), szPath, raster_exts[j].eType, bCheckNames); if(pGxObj != NULL) pChildrenIds.Add(pGxObj->GetId()); } pFileNames = CSLRemoveStrings( pFileNames, i, 1, NULL ); bContinue = true; break; } } if(bContinue) continue; if(wxGISEQUAL(szExt, "prj")) { if(pFileNames) { unsigned int j; for(j = 0; j < sizeof(raster_exts) / sizeof(raster_exts[0]); ++j) { szPath = (char*)CPLResetExtension(pFileNames[i], raster_exts[j].sExt); if(CPLCheckForFile((char*)szPath.c_str(), NULL)) { pFileNames = CSLRemoveStrings( pFileNames, i, 1, NULL ); bContinue = true; break; } } } } if(bContinue) continue; for( j = 0; raster_add_exts[j] != NULL; ++j ) { if(wxGISEQUAL(szExt, raster_add_exts[j])) { pFileNames = CSLRemoveStrings( pFileNames, i, 1, NULL ); break; } } } return true; }
int OGRSXFDataSource::Open( const char * pszFilename, int bUpdateIn) { size_t nObjectsRead; int nFileHeaderSize; if (bUpdateIn) { return FALSE; } pszName = pszFilename; fpSXF = VSIFOpenL(pszName, "rb"); if ( fpSXF == NULL ) { CPLError(CE_Warning, CPLE_OpenFailed, "SXF open file %s failed", pszFilename); return FALSE; } //read header nFileHeaderSize = sizeof(SXFHeader); SXFHeader stSXFFileHeader; nObjectsRead = VSIFReadL(&stSXFFileHeader, nFileHeaderSize, 1, fpSXF); if (nObjectsRead != 1) { CPLError(CE_Failure, CPLE_None, "SXF head read failed"); CloseFile(); return FALSE; } //check version oSXFPassport.version = 0; if (stSXFFileHeader.nHeaderLength > 256) //if size == 400 then version >= 4 { oSXFPassport.version = stSXFFileHeader.nFormatVersion[2]; } else { oSXFPassport.version = stSXFFileHeader.nFormatVersion[1]; } if ( oSXFPassport.version < 3 ) { CPLError(CE_Failure, CPLE_NotSupported , "SXF File version not supported"); CloseFile(); return FALSE; } // read description if (ReadSXFDescription(fpSXF, oSXFPassport) != OGRERR_NONE) { CPLError(CE_Failure, CPLE_NotSupported, "SXF. Wrong description."); CloseFile(); return FALSE; } //read flags if (ReadSXFInformationFlags(fpSXF, oSXFPassport) != OGRERR_NONE) { CPLError(CE_Failure, CPLE_NotSupported, "SXF. Wrong state of the data."); CloseFile(); return FALSE; } if (oSXFPassport.informationFlags.bProjectionDataCompliance == false) { CPLError( CE_Failure, CPLE_NotSupported, "SXF. Data are not corresponde to the projection." ); CloseFile(); return FALSE; } //read spatial data if (ReadSXFMapDescription(fpSXF, oSXFPassport) != OGRERR_NONE) { CPLError(CE_Failure, CPLE_NotSupported, "SXF. Wrong state of the data."); CloseFile(); return FALSE; } if(oSXFPassport.informationFlags.bRealCoordinatesCompliance == false ) { CPLError( CE_Warning, CPLE_NotSupported, "SXF. Given material may be rotated in the conditional system of coordinates" ); } /*---------------- TRY READ THE RSC FILE HEADER -----------------------*/ CPLString soRSCRileName; const char* pszRSCRileName = CPLGetConfigOption("SXF_RSC_FILENAME", ""); if (CPLCheckForFile((char *)pszRSCRileName, NULL) == TRUE) { soRSCRileName = pszRSCRileName; } if(soRSCRileName.empty()) { pszRSCRileName = CPLResetExtension(pszFilename, "rsc"); if (CPLCheckForFile((char *)pszRSCRileName, NULL) == TRUE) { soRSCRileName = pszRSCRileName; } } if(soRSCRileName.empty()) { pszRSCRileName = CPLResetExtension(pszFilename, "RSC"); if (CPLCheckForFile((char *)pszRSCRileName, NULL) == TRUE) { soRSCRileName = pszRSCRileName; } } //1. Create layers from RSC file or create default set of layers from osm.rsc if (soRSCRileName.empty()) { CPLError(CE_Warning, CPLE_None, "RSC file for %s not exist", pszFilename); } else { VSILFILE* fpRSC; fpRSC = VSIFOpenL(soRSCRileName, "rb"); if (fpRSC == NULL) { CPLError(CE_Warning, CPLE_OpenFailed, "RSC file %s open failed", soRSCRileName.c_str()); } else { CPLDebug( "OGRSXFDataSource", "RSC Filename: %s", soRSCRileName.c_str() ); CreateLayers(fpRSC); VSIFCloseL(fpRSC); } } if (nLayers == 0)//create default set of layers { CreateLayers(); } FillLayers(); return TRUE; }
static CPLXMLNode *FindTreeByURL( CPLXMLNode *** ppapsRoot, char *** ppapszResourceHREF, const char *pszURL ) { if( *ppapsRoot == NULL || ppapszResourceHREF == NULL ) return NULL; //if found in ppapszResourceHREF int i, nItems; char *pszLocation; if( ( i = CSLFindString( *ppapszResourceHREF, pszURL )) >= 0 ) { //return corresponding psRoot return (*ppapsRoot)[i]; } else { CPLXMLNode *psSrcTree = NULL, *psSibling; pszLocation = CPLStrdup( pszURL ); //if it is part of filesystem if( CPLCheckForFile( pszLocation, NULL) ) {//filesystem psSrcTree = CPLParseXMLFile( pszURL ); } else if( CPLHTTPEnabled() ) {//web resource CPLErrorReset(); CPLHTTPResult *psResult = CPLHTTPFetch( pszURL, NULL ); if( psResult != NULL ) { if( psResult->nDataLen > 0 && CPLGetLastErrorNo() == 0) psSrcTree = CPLParseXMLString( (const char*)psResult->pabyData ); CPLHTTPDestroyResult( psResult ); } } //report error in case the resource cannot be retrieved. if( psSrcTree == NULL ) CPLError( CE_Failure, CPLE_NotSupported, "Could not access %s", pszLocation ); CPLFree( pszLocation ); /************************************************************************/ /* In the external GML resource we will only need elements */ /* identified by a "gml:id". So trim them. */ /************************************************************************/ psSibling = psSrcTree; while( psSibling != NULL ) { TrimTree( psSibling ); psSibling = psSibling->psNext; } //update to lists nItems = CSLCount(*ppapszResourceHREF); *ppapszResourceHREF = CSLAddString( *ppapszResourceHREF, pszURL ); *ppapsRoot = (CPLXMLNode**)CPLRealloc(*ppapsRoot, (nItems+2)*sizeof(CPLXMLNode*)); (*ppapsRoot)[nItems] = psSrcTree; (*ppapsRoot)[nItems+1] = NULL; //return the tree return (*ppapsRoot)[nItems]; } }
int GNMFileNetwork::CheckNetworkExist(const char *pszFilename, char **papszOptions) { // check if path exist // if path exist check if network already present and OVERWRITE option // else create the path bool bOverwrite = CSLFetchBoolean(papszOptions, "OVERWRITE", FALSE); if(m_soName.empty()) { const char* pszNetworkName = CSLFetchNameValue(papszOptions, GNM_MD_NAME); if( NULL != pszNetworkName ) { m_soName = pszNetworkName; } } if(FormPath(pszFilename, papszOptions) != CE_None) { return TRUE; } if (CPLCheckForFile((char*)m_soNetworkFullName.c_str(), NULL)) { char **papszFiles = CPLReadDir( m_soNetworkFullName ); if( CSLCount(papszFiles) == 0 ) { return FALSE; } // search for base GNM files for(int i = 0; papszFiles[i] != NULL; i++ ) { if( EQUAL(papszFiles[i],".") || EQUAL(papszFiles[i],"..") ) continue; if( EQUAL(CPLGetBasename(papszFiles[i]), GNM_SYSLAYER_META) || EQUAL(CPLGetBasename(papszFiles[i]), GNM_SYSLAYER_GRAPH) || EQUAL(CPLGetBasename(papszFiles[i]), GNM_SYSLAYER_FEATURES) || EQUAL(papszFiles[i], GNM_SRSFILENAME) ) { if(bOverwrite) { const char* pszDeleteFile = CPLFormFilename( m_soNetworkFullName, papszFiles[i], NULL); CPLDebug("GNM", "Delete file: %s", pszDeleteFile); if( VSIUnlink(pszDeleteFile) != 0 ) { return TRUE; } } else { return TRUE; } } } CSLDestroy( papszFiles ); } else { if (VSIMkdir(m_soNetworkFullName, 0755) != 0) { return TRUE; } } return FALSE; }
int GDALDefaultOverviews::HaveMaskFile( char ** papszSiblingFiles, const char *pszBasename ) { /* -------------------------------------------------------------------- */ /* Have we already checked for masks? */ /* -------------------------------------------------------------------- */ if( bCheckedForMask ) return poMaskDS != NULL; if( papszSiblingFiles == NULL ) papszSiblingFiles = papszInitSiblingFiles; /* -------------------------------------------------------------------- */ /* Are we an overview? If so we need to find the corresponding */ /* overview in the base files mask file (if there is one). */ /* -------------------------------------------------------------------- */ if( poBaseDS != NULL && poBaseDS->oOvManager.HaveMaskFile() ) { GDALRasterBand * const poBaseBand = poBaseDS->GetRasterBand(1); GDALRasterBand * poBaseMask = poBaseBand != NULL ? poBaseBand->GetMaskBand() : NULL; const int nOverviewCount = poBaseMask != NULL ? poBaseMask->GetOverviewCount() : 0; for( int iOver = 0; iOver < nOverviewCount; iOver++ ) { GDALRasterBand * const poOverBand = poBaseMask->GetOverview( iOver ); if( poOverBand == NULL ) continue; if( poOverBand->GetXSize() == poDS->GetRasterXSize() && poOverBand->GetYSize() == poDS->GetRasterYSize() ) { poMaskDS = poOverBand->GetDataset(); break; } } bCheckedForMask = true; bOwnMaskDS = false; CPLAssert( poMaskDS != poDS ); return poMaskDS != NULL; } /* -------------------------------------------------------------------- */ /* Are we even initialized? If not, we apparently don't want */ /* to support overviews and masks. */ /* -------------------------------------------------------------------- */ if( poDS == NULL ) return FALSE; /* -------------------------------------------------------------------- */ /* Check for .msk file. */ /* -------------------------------------------------------------------- */ bCheckedForMask = true; if( pszBasename == NULL ) pszBasename = poDS->GetDescription(); // Don't bother checking for masks of masks. if( EQUAL(CPLGetExtension(pszBasename),"msk") ) return FALSE; if( !GDALCanFileAcceptSidecarFile(pszBasename) ) return FALSE; CPLString osMskFilename; osMskFilename.Printf( "%s.msk", pszBasename ); std::vector<char> achMskFilename; achMskFilename.resize(osMskFilename.size() + 1); memcpy(&(achMskFilename[0]), osMskFilename.c_str(), osMskFilename.size() + 1); bool bExists = CPL_TO_BOOL( CPLCheckForFile( &achMskFilename[0], papszSiblingFiles ) ); osMskFilename = &achMskFilename[0]; #if !defined(WIN32) if( !bExists && !papszSiblingFiles ) { osMskFilename.Printf( "%s.MSK", pszBasename ); memcpy(&(achMskFilename[0]), osMskFilename.c_str(), osMskFilename.size() + 1); bExists = CPL_TO_BOOL( CPLCheckForFile( &achMskFilename[0], papszSiblingFiles ) ); osMskFilename = &achMskFilename[0]; } #endif if( !bExists ) return FALSE; /* -------------------------------------------------------------------- */ /* Open the file. */ /* -------------------------------------------------------------------- */ poMaskDS = static_cast<GDALDataset *>( GDALOpenEx( osMskFilename, GDAL_OF_RASTER | (poDS->GetAccess() == GA_Update ? GDAL_OF_UPDATE : 0), NULL, NULL, papszInitSiblingFiles )); CPLAssert( poMaskDS != poDS ); if( poMaskDS == NULL ) return FALSE; bOwnMaskDS = true; return TRUE; }
void GDALDefaultOverviews::OverviewScan() { if( bCheckedForOverviews || poDS == NULL ) return; bCheckedForOverviews = true; CPLDebug( "GDAL", "GDALDefaultOverviews::OverviewScan()" ); /* -------------------------------------------------------------------- */ /* Open overview dataset if it exists. */ /* -------------------------------------------------------------------- */ if( pszInitName == NULL ) pszInitName = CPLStrdup(poDS->GetDescription()); if( !EQUAL(pszInitName,":::VIRTUAL:::") && GDALCanFileAcceptSidecarFile(pszInitName) ) { if( bInitNameIsOVR ) osOvrFilename = pszInitName; else osOvrFilename.Printf( "%s.ovr", pszInitName ); std::vector<char> achOvrFilename; achOvrFilename.resize(osOvrFilename.size() + 1); memcpy(&(achOvrFilename[0]), osOvrFilename.c_str(), osOvrFilename.size() + 1); bool bExists = CPL_TO_BOOL( CPLCheckForFile( &achOvrFilename[0], papszInitSiblingFiles ) ); osOvrFilename = &achOvrFilename[0]; #if !defined(WIN32) if( !bInitNameIsOVR && !bExists && !papszInitSiblingFiles ) { osOvrFilename.Printf( "%s.OVR", pszInitName ); memcpy(&(achOvrFilename[0]), osOvrFilename.c_str(), osOvrFilename.size() + 1); bExists = CPL_TO_BOOL( CPLCheckForFile( &achOvrFilename[0], papszInitSiblingFiles ) ); osOvrFilename = &achOvrFilename[0]; if( !bExists ) osOvrFilename.Printf( "%s.ovr", pszInitName ); } #endif if( bExists ) { poODS = static_cast<GDALDataset *>( GDALOpenEx( osOvrFilename, GDAL_OF_RASTER | (poDS->GetAccess() == GA_Update ? GDAL_OF_UPDATE : 0), NULL, NULL, papszInitSiblingFiles ) ); } } /* -------------------------------------------------------------------- */ /* We didn't find that, so try and find a corresponding aux */ /* file. Check that we are the dependent file of the aux */ /* file. */ /* */ /* We only use the .aux file for overviews if they already have */ /* overviews existing, or if USE_RRD is set true. */ /* -------------------------------------------------------------------- */ if( !poODS && !EQUAL(pszInitName,":::VIRTUAL:::") && GDALCanFileAcceptSidecarFile(pszInitName) ) { bool bTryFindAssociatedAuxFile = true; if( papszInitSiblingFiles ) { CPLString osAuxFilename = CPLResetExtension( pszInitName, "aux"); int iSibling = CSLFindString( papszInitSiblingFiles, CPLGetFilename(osAuxFilename) ); if( iSibling < 0 ) { osAuxFilename = pszInitName; osAuxFilename += ".aux"; iSibling = CSLFindString( papszInitSiblingFiles, CPLGetFilename(osAuxFilename) ); if( iSibling < 0 ) bTryFindAssociatedAuxFile = false; } } if( bTryFindAssociatedAuxFile ) { poODS = GDALFindAssociatedAuxFile( pszInitName, poDS->GetAccess(), poDS ); } if( poODS ) { const bool bUseRRD = CPLTestBool(CPLGetConfigOption("USE_RRD","NO")); bOvrIsAux = true; if( GetOverviewCount(1) == 0 && !bUseRRD ) { bOvrIsAux = false; GDALClose( poODS ); poODS = NULL; } else { osOvrFilename = poODS->GetDescription(); } } } /* -------------------------------------------------------------------- */ /* If we still don't have an overview, check to see if we have */ /* overview metadata referencing a remote (i.e. proxy) or local */ /* subdataset overview dataset. */ /* -------------------------------------------------------------------- */ if( poODS == NULL ) { const char *pszProxyOvrFilename = poDS->GetMetadataItem( "OVERVIEW_FILE", "OVERVIEWS" ); if( pszProxyOvrFilename != NULL ) { if( STARTS_WITH_CI(pszProxyOvrFilename, ":::BASE:::") ) { const CPLString osPath = CPLGetPath(poDS->GetDescription()); osOvrFilename = CPLFormFilename( osPath, pszProxyOvrFilename+10, NULL ); } else { osOvrFilename = pszProxyOvrFilename; } CPLPushErrorHandler(CPLQuietErrorHandler); poODS = static_cast<GDALDataset *>(GDALOpen(osOvrFilename, poDS->GetAccess())); CPLPopErrorHandler(); } } /* -------------------------------------------------------------------- */ /* If we have an overview dataset, then mark all the overviews */ /* with the base dataset Used later for finding overviews */ /* masks. Uggg. */ /* -------------------------------------------------------------------- */ if( poODS ) { const int nOverviewCount = GetOverviewCount(1); for( int iOver = 0; iOver < nOverviewCount; iOver++ ) { GDALRasterBand * const poBand = GetOverview( 1, iOver ); GDALDataset * const poOverDS = poBand != NULL ? poBand->GetDataset() : NULL; if( poOverDS != NULL ) { poOverDS->oOvManager.poBaseDS = poDS; poOverDS->oOvManager.poDS = poOverDS; } } } }
/** * GDALMDReaderGeoEye() */ GDALMDReaderGeoEye::GDALMDReaderGeoEye(const char *pszPath, char **papszSiblingFiles) : GDALMDReaderBase(pszPath, papszSiblingFiles) { const char* pszBaseName = CPLGetBasename(pszPath); const char* pszDirName = CPLGetDirname(pszPath); size_t nBaseNameLen = strlen(pszBaseName); if( nBaseNameLen > 511 ) return; // get _metadata.txt file // split file name by _rgb_ or _pan_ char szMetadataName[512] = {0}; size_t i; for(i = 0; i < nBaseNameLen; i++) { szMetadataName[i] = pszBaseName[i]; if(EQUALN(pszBaseName + i, "_rgb_", 5) || EQUALN(pszBaseName + i, "_pan_", 5)) { break; } } // form metadata file name CPLStrlcpy(szMetadataName + i, "_metadata.txt", 14); const char* pszIMDSourceFilename = CPLFormFilename( pszDirName, szMetadataName, NULL ); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } else { CPLStrlcpy(szMetadataName + i, "_METADATA.TXT", 14); pszIMDSourceFilename = CPLFormFilename( pszDirName, szMetadataName, NULL ); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } } // get _rpc.txt file const char* pszRPBSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("%s_rpc", pszBaseName), "txt" ); if (CPLCheckForFile((char*)pszRPBSourceFilename, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPBSourceFilename; } else { pszRPBSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("%s_RPC", pszBaseName), "TXT" ); if (CPLCheckForFile((char*)pszRPBSourceFilename, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPBSourceFilename; } } if( m_osIMDSourceFilename.size() ) CPLDebug( "MDReaderGeoEye", "IMD Filename: %s", m_osIMDSourceFilename.c_str() ); if( m_osRPBSourceFilename.size() ) CPLDebug( "MDReaderGeoEye", "RPB Filename: %s", m_osRPBSourceFilename.c_str() ); }
/** * GDALMDReaderALOS() */ GDALMDReaderALOS::GDALMDReaderALOS(const char *pszPath, char **papszSiblingFiles) : GDALMDReaderBase(pszPath, papszSiblingFiles) { CPLString osDirName = CPLGetDirname(pszPath); CPLString osBaseName = CPLGetBasename(pszPath); const char* pszIMDSourceFilename = CPLFormFilename(osDirName, "summary", ".txt"); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } else { pszIMDSourceFilename = CPLFormFilename( osDirName, "SUMMARY", ".TXT"); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } } const char *pszHDRFileName; if( osBaseName.size() >= 6 ) { // check if this is separate band or whole image // test without 6 symbols pszHDRFileName = CPLFormFilename(osDirName, CPLSPrintf("HDR%s", osBaseName + 6), "txt"); if (CPLCheckForFile((char*)pszHDRFileName, papszSiblingFiles)) { m_osHDRSourceFilename = pszHDRFileName; } else { pszHDRFileName = CPLFormFilename(osDirName, CPLSPrintf("HDR%s", osBaseName + 6), "TXT"); if (CPLCheckForFile((char*)pszHDRFileName, papszSiblingFiles)) { m_osHDRSourceFilename = pszHDRFileName; } } } // test without 3 symbols if( osBaseName.size() >= 3 && m_osHDRSourceFilename.empty()) { pszHDRFileName = CPLFormFilename(osDirName, CPLSPrintf("HDR%s", osBaseName + 3), "txt"); if (CPLCheckForFile((char*)pszHDRFileName, papszSiblingFiles)) { m_osHDRSourceFilename = pszHDRFileName; } else { pszHDRFileName = CPLFormFilename(osDirName, CPLSPrintf("HDR%s", osBaseName + 3), "TXT"); if (CPLCheckForFile((char*)pszHDRFileName, papszSiblingFiles)) { m_osHDRSourceFilename = pszHDRFileName; } } } // test without 6 symbols const char *pszRPCFileName; if( osBaseName.size() >= 6 ) { pszRPCFileName = CPLFormFilename(osDirName, CPLSPrintf("RPC%s", osBaseName + 6), "txt"); if (CPLCheckForFile((char*)pszRPCFileName, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPCFileName; } else { pszRPCFileName = CPLFormFilename(osDirName, CPLSPrintf("RPC%s", osBaseName + 6), "TXT"); if (CPLCheckForFile((char*)pszRPCFileName, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPCFileName; } } } // test without 3 symbols if( osBaseName.size() >= 3 && m_osRPBSourceFilename.empty()) { pszRPCFileName = CPLFormFilename(osDirName, CPLSPrintf("RPC%s", osBaseName + 3), "txt"); if (CPLCheckForFile((char*)pszRPCFileName, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPCFileName; } else { pszRPCFileName = CPLFormFilename(osDirName, CPLSPrintf("RPC%s", osBaseName + 3), "TXT"); if (CPLCheckForFile((char*)pszRPCFileName, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPCFileName; } } } if(m_osIMDSourceFilename.size()) CPLDebug( "MDReaderALOS", "IMD Filename: %s", m_osIMDSourceFilename.c_str() ); if(m_osHDRSourceFilename.size()) CPLDebug( "MDReaderALOS", "HDR Filename: %s", m_osHDRSourceFilename.c_str() ); if(m_osRPBSourceFilename.size()) CPLDebug( "MDReaderALOS", "RPB Filename: %s", m_osRPBSourceFilename.c_str() ); }
int GDALDefaultOverviews::HaveMaskFile( char ** papszSiblingFiles, const char *pszBasename ) { /* -------------------------------------------------------------------- */ /* Have we already checked for masks? */ /* -------------------------------------------------------------------- */ if( bCheckedForMask ) return poMaskDS != NULL; if( papszSiblingFiles == NULL ) papszSiblingFiles = papszInitSiblingFiles; /* -------------------------------------------------------------------- */ /* Are we an overview? If so we need to find the corresponding */ /* overview in the base files mask file (if there is one). */ /* -------------------------------------------------------------------- */ if( poBaseDS != NULL && poBaseDS->oOvManager.HaveMaskFile() ) { int iOver, nOverviewCount = 0; GDALRasterBand *poBaseBand = poBaseDS->GetRasterBand(1); GDALRasterBand *poBaseMask = NULL; if( poBaseBand != NULL ) poBaseMask = poBaseBand->GetMaskBand(); if( poBaseMask ) nOverviewCount = poBaseMask->GetOverviewCount(); for( iOver = 0; iOver < nOverviewCount; iOver++ ) { GDALRasterBand *poOverBand = poBaseMask->GetOverview( iOver ); if (poOverBand == NULL) continue; if( poOverBand->GetXSize() == poDS->GetRasterXSize() && poOverBand->GetYSize() == poDS->GetRasterYSize() ) { poMaskDS = poOverBand->GetDataset(); break; } } bCheckedForMask = TRUE; bOwnMaskDS = FALSE; CPLAssert( poMaskDS != poDS ); return poMaskDS != NULL; } /* -------------------------------------------------------------------- */ /* Are we even initialized? If not, we apparently don't want */ /* to support overviews and masks. */ /* -------------------------------------------------------------------- */ if( poDS == NULL ) return FALSE; /* -------------------------------------------------------------------- */ /* Check for .msk file. */ /* -------------------------------------------------------------------- */ CPLString osMskFilename; bCheckedForMask = TRUE; if( pszBasename == NULL ) pszBasename = poDS->GetDescription(); // Don't bother checking for masks of masks. if( EQUAL(CPLGetExtension(pszBasename),"msk") ) return FALSE; osMskFilename.Printf( "%s.msk", pszBasename ); int bExists = CPLCheckForFile( (char *) osMskFilename.c_str(), papszSiblingFiles ); #if !defined(WIN32) if( !bExists && !papszSiblingFiles ) { osMskFilename.Printf( "%s.MSK", pszBasename ); bExists = CPLCheckForFile( (char *) osMskFilename.c_str(), papszSiblingFiles ); } #endif if( !bExists ) return FALSE; /* -------------------------------------------------------------------- */ /* Open the file. */ /* -------------------------------------------------------------------- */ GDALOpenInfo oOpenInfo(osMskFilename, poDS->GetAccess(), papszInitSiblingFiles); poMaskDS = (GDALDataset *) GDALOpenInternal( oOpenInfo, NULL ); CPLAssert( poMaskDS != poDS ); if( poMaskDS == NULL ) return FALSE; bOwnMaskDS = TRUE; return TRUE; }
void GDALDefaultOverviews::OverviewScan() { if( bCheckedForOverviews || poDS == NULL ) return; bCheckedForOverviews = true; CPLDebug( "GDAL", "GDALDefaultOverviews::OverviewScan()" ); /* -------------------------------------------------------------------- */ /* Open overview dataset if it exists. */ /* -------------------------------------------------------------------- */ int bExists; if( pszInitName == NULL ) pszInitName = CPLStrdup(poDS->GetDescription()); if( !EQUAL(pszInitName,":::VIRTUAL:::") ) { if( bInitNameIsOVR ) osOvrFilename = pszInitName; else osOvrFilename.Printf( "%s.ovr", pszInitName ); bExists = CPLCheckForFile( (char *) osOvrFilename.c_str(), papszInitSiblingFiles ); #if !defined(WIN32) if( !bInitNameIsOVR && !bExists && !papszInitSiblingFiles ) { osOvrFilename.Printf( "%s.OVR", pszInitName ); bExists = CPLCheckForFile( (char *) osOvrFilename.c_str(), papszInitSiblingFiles ); if( !bExists ) osOvrFilename.Printf( "%s.ovr", pszInitName ); } #endif if( bExists ) { GDALOpenInfo oOpenInfo(osOvrFilename, poDS->GetAccess(), papszInitSiblingFiles); poODS = (GDALDataset*) GDALOpenInternal( oOpenInfo, NULL ); } } /* -------------------------------------------------------------------- */ /* We didn't find that, so try and find a corresponding aux */ /* file. Check that we are the dependent file of the aux */ /* file. */ /* */ /* We only use the .aux file for overviews if they already have */ /* overviews existing, or if USE_RRD is set true. */ /* -------------------------------------------------------------------- */ if( !poODS && !EQUAL(pszInitName,":::VIRTUAL:::") ) { int bTryFindAssociatedAuxFile = TRUE; if( papszInitSiblingFiles ) { CPLString osAuxFilename = CPLResetExtension( pszInitName, "aux"); int iSibling = CSLFindString( papszInitSiblingFiles, CPLGetFilename(osAuxFilename) ); if( iSibling < 0 ) { osAuxFilename = pszInitName; osAuxFilename += ".aux"; iSibling = CSLFindString( papszInitSiblingFiles, CPLGetFilename(osAuxFilename) ); if( iSibling < 0 ) bTryFindAssociatedAuxFile = FALSE; } } if (bTryFindAssociatedAuxFile) { poODS = GDALFindAssociatedAuxFile( pszInitName, poDS->GetAccess(), poDS ); } if( poODS ) { int bUseRRD = CSLTestBoolean(CPLGetConfigOption("USE_RRD","NO")); bOvrIsAux = TRUE; if( GetOverviewCount(1) == 0 && !bUseRRD ) { bOvrIsAux = FALSE; GDALClose( poODS ); poODS = NULL; } else { osOvrFilename = poODS->GetDescription(); } } } /* -------------------------------------------------------------------- */ /* If we still don't have an overview, check to see if we have */ /* overview metadata referencing a remote (ie. proxy) or local */ /* subdataset overview dataset. */ /* -------------------------------------------------------------------- */ if( poODS == NULL ) { const char *pszProxyOvrFilename = poDS->GetMetadataItem( "OVERVIEW_FILE", "OVERVIEWS" ); if( pszProxyOvrFilename != NULL ) { if( EQUALN(pszProxyOvrFilename,":::BASE:::",10) ) { CPLString osPath = CPLGetPath(poDS->GetDescription()); osOvrFilename = CPLFormFilename( osPath, pszProxyOvrFilename+10, NULL ); } else osOvrFilename = pszProxyOvrFilename; CPLPushErrorHandler(CPLQuietErrorHandler); poODS = (GDALDataset *) GDALOpen(osOvrFilename,poDS->GetAccess()); CPLPopErrorHandler(); } } /* -------------------------------------------------------------------- */ /* If we have an overview dataset, then mark all the overviews */ /* with the base dataset Used later for finding overviews */ /* masks. Uggg. */ /* -------------------------------------------------------------------- */ if( poODS ) { int nOverviewCount = GetOverviewCount(1); int iOver; for( iOver = 0; iOver < nOverviewCount; iOver++ ) { GDALRasterBand *poBand = GetOverview( 1, iOver ); GDALDataset *poOverDS = NULL; if( poBand != NULL ) poOverDS = poBand->GetDataset(); if( poOverDS != NULL ) { poOverDS->oOvManager.poBaseDS = poDS; poOverDS->oOvManager.poDS = poOverDS; } } } }
/** * GDALMDReaderPleiades() */ GDALMDReaderPleiades::GDALMDReaderPleiades(const char *pszPath, char **papszSiblingFiles) : GDALMDReaderBase(pszPath, papszSiblingFiles) { const char* pszBaseName = CPLGetBasename(pszPath); size_t nBaseNameLen = strlen(pszBaseName); if( nBaseNameLen < 4 || nBaseNameLen > 511 ) return; const char* pszDirName = CPLGetDirname(pszPath); const char* pszIMDSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("DIM_%s", pszBaseName + 4), "XML" ); const char* pszRPBSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("RPC_%s", pszBaseName + 4), "XML" ); // find last underline char sBaseName[512]; int nLastUnderline = 0; for(size_t i = 4; i < nBaseNameLen; i++) { sBaseName[i - 4] = pszBaseName[i]; if(pszBaseName[i] == '_') nLastUnderline = i - 4; } sBaseName[nLastUnderline] = 0; if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } else { pszIMDSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("DIM_%s", sBaseName), "XML" ); if (CPLCheckForFile((char*)pszIMDSourceFilename, papszSiblingFiles)) { m_osIMDSourceFilename = pszIMDSourceFilename; } } if (CPLCheckForFile((char*)pszRPBSourceFilename, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPBSourceFilename; } else { pszRPBSourceFilename = CPLFormFilename( pszDirName, CPLSPrintf("RPC_%s", sBaseName), "XML" ); if (CPLCheckForFile((char*)pszRPBSourceFilename, papszSiblingFiles)) { m_osRPBSourceFilename = pszRPBSourceFilename; } } if( m_osIMDSourceFilename.size() ) CPLDebug( "MDReaderPleiades", "IMD Filename: %s", m_osIMDSourceFilename.c_str() ); if( m_osRPBSourceFilename.size() ) CPLDebug( "MDReaderPleiades", "RPB Filename: %s", m_osRPBSourceFilename.c_str() ); }