OGRErr OGRSXFDriver::DeleteDataSource(const char* pszName) { int iExt; //TODO: add more extensions if aplicable static const char *apszExtensions[] = { "szf", "rsc", "SZF", "RSC", NULL }; VSIStatBufL sStatBuf; if (VSIStatL(pszName, &sStatBuf) != 0) { CPLError(CE_Failure, CPLE_AppDefined, "%s does not appear to be a valid sxf file.", pszName); return OGRERR_FAILURE; } for (iExt = 0; apszExtensions[iExt] != NULL; iExt++) { const char *pszFile = CPLResetExtension(pszName, apszExtensions[iExt]); if (VSIStatL(pszFile, &sStatBuf) == 0) VSIUnlink(pszFile); } return OGRERR_NONE; }
OGRErr OGRShapeDriver::DeleteDataSource( const char *pszDataSource ) { int iExt; VSIStatBufL sStatBuf; static const char *apszExtensions[] = { "shp", "shx", "dbf", "sbn", "sbx", "prj", "idm", "ind", "qix", "cpg", NULL }; if( VSIStatL( pszDataSource, &sStatBuf ) != 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "%s does not appear to be a file or directory.", pszDataSource ); return OGRERR_FAILURE; } if( VSI_ISREG(sStatBuf.st_mode) && (EQUAL(CPLGetExtension(pszDataSource),"shp") || EQUAL(CPLGetExtension(pszDataSource),"shx") || EQUAL(CPLGetExtension(pszDataSource),"dbf")) ) { for( iExt=0; apszExtensions[iExt] != NULL; iExt++ ) { const char *pszFile = CPLResetExtension(pszDataSource, apszExtensions[iExt] ); if( VSIStatL( pszFile, &sStatBuf ) == 0 ) VSIUnlink( pszFile ); } } else if( VSI_ISDIR(sStatBuf.st_mode) ) { char **papszDirEntries = CPLReadDir( pszDataSource ); int iFile; for( iFile = 0; papszDirEntries != NULL && papszDirEntries[iFile] != NULL; iFile++ ) { if( CSLFindString( (char **) apszExtensions, CPLGetExtension(papszDirEntries[iFile])) != -1) { VSIUnlink( CPLFormFilename( pszDataSource, papszDirEntries[iFile], NULL ) ); } } CSLDestroy( papszDirEntries ); VSIRmdir( pszDataSource ); } return OGRERR_NONE; }
OGRErr OGRGeoconceptDriver::DeleteDataSource( const char *pszDataSource ) { VSIStatBufL sStatBuf; static const char * const apszExtensions[] = { "gxt", "txt", "gct", "gcm", "gcr", nullptr }; if( VSIStatL( pszDataSource, &sStatBuf ) != 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "%s does not appear to be a file or directory.", pszDataSource ); return OGRERR_FAILURE; } if( VSI_ISREG(sStatBuf.st_mode) && ( EQUAL(CPLGetExtension(pszDataSource),"gxt") || EQUAL(CPLGetExtension(pszDataSource),"txt") ) ) { for( int iExt=0; apszExtensions[iExt] != nullptr; iExt++ ) { const char *pszFile = CPLResetExtension(pszDataSource, apszExtensions[iExt] ); if( VSIStatL( pszFile, &sStatBuf ) == 0 ) VSIUnlink( pszFile ); } } else if( VSI_ISDIR(sStatBuf.st_mode) ) { char **papszDirEntries = VSIReadDir( pszDataSource ); for( int iFile = 0; papszDirEntries != nullptr && papszDirEntries[iFile] != nullptr; iFile++ ) { if( CSLFindString( const_cast<char **>( apszExtensions ), CPLGetExtension(papszDirEntries[iFile])) != -1) { VSIUnlink( CPLFormFilename( pszDataSource, papszDirEntries[iFile], nullptr ) ); } } CSLDestroy( papszDirEntries ); VSIRmdir( pszDataSource ); } return OGRERR_NONE; }
void wxGxOpenFileGDB::FillMetadata(bool bForce) { if (m_bIsMetadataFilled && !bForce) return; m_bIsMetadataFilled = true; wxGISDataset* pDSet = GetDatasetFast(); if (NULL == pDSet) { return; } VSIStatBufL BufL; wxULongLong nSize(0); wxDateTime dt(1,wxDateTime::Jan, 1900); int ret = VSIStatL(m_sPath, &BufL); if (ret == 0) { //nSize += BufL.st_size; //dt = wxDateTime(BufL.st_mtime); if (VSI_ISDIR(BufL.st_mode)) { char **papszItems = CPLReadDir(wxGxObjectContainer::GetPath()); if (papszItems && CSLCount(papszItems) > 0) { for (int i = 0; papszItems[i] != NULL; ++i) { if (wxGISEQUAL(papszItems[i], ".") || wxGISEQUAL(papszItems[i], "..")) continue; CPLString szFullPathFrom = CPLFormFilename(wxGxObjectContainer::GetPath(), papszItems[i], NULL); ret = VSIStatL(szFullPathFrom, &BufL); if (ret == 0) { nSize += BufL.st_size; wxDateTime dtt(BufL.st_mtime); if (dtt > dt) dt = dtt; } } } CSLDestroy(papszItems); } } m_nSize = nSize; m_dtMod = dt; wsDELETE(pDSet); }
/********************************************************************** * TABAdjustFilenameExtension() * * Because Unix filenames are case sensitive and MapInfo datasets often have * mixed cases filenames, we use this function to find the right filename * to use ot open a specific file. * * This function works directly on the source string, so the filename it * contains at the end of the call is the one that should be used. * * Returns TRUE if one of the extensions worked, and FALSE otherwise. * If none of the extensions worked then the original extension will NOT be * restored. **********************************************************************/ GBool TABAdjustFilenameExtension(char *pszFname) { VSIStatBufL sStatBuf; /*----------------------------------------------------------------- * First try using filename as provided *----------------------------------------------------------------*/ if (VSIStatL(pszFname, &sStatBuf) == 0) { return TRUE; } /*----------------------------------------------------------------- * Try using uppercase extension (we assume that fname contains a '.') *----------------------------------------------------------------*/ for( int i = static_cast<int>(strlen(pszFname))-1; i >= 0 && pszFname[i] != '.'; i-- ) { pszFname[i] = (char)toupper(pszFname[i]); } if (VSIStatL(pszFname, &sStatBuf) == 0) { return TRUE; } /*----------------------------------------------------------------- * Try using lowercase extension *----------------------------------------------------------------*/ for( int i = static_cast<int>(strlen(pszFname))-1; i >= 0 && pszFname[i] != '.'; i-- ) { pszFname[i] = (char)tolower(pszFname[i]); } if (VSIStatL(pszFname, &sStatBuf) == 0) { return TRUE; } /*----------------------------------------------------------------- * None of the extensions worked! * Try adjusting cases in the whole path and filename *----------------------------------------------------------------*/ return TABAdjustCaseSensitiveFilename(pszFname); }
int DIMAPDataset::Identify( GDALOpenInfo * poOpenInfo ) { if( poOpenInfo->nHeaderBytes >= 100 ) { if( strstr((const char *) poOpenInfo->pabyHeader, "<Dimap_Document" ) == NULL ) return FALSE; else return TRUE; } else if( poOpenInfo->bIsDirectory ) { VSIStatBufL sStat; CPLString osMDFilename = CPLFormCIFilename( poOpenInfo->pszFilename, "METADATA.DIM", NULL ); if( VSIStatL( osMDFilename, &sStat ) == 0 ) return TRUE; else return FALSE; } return FALSE; }
int TSXDataset::Identify( GDALOpenInfo *poOpenInfo ) { if (poOpenInfo->fpL == NULL || poOpenInfo->nHeaderBytes < 260) { if( poOpenInfo->bIsDirectory ) { CPLString osFilename = CPLFormCIFilename( poOpenInfo->pszFilename, CPLGetFilename( poOpenInfo->pszFilename ), "xml" ); /* Check if the filename contains TSX1_SAR (TerraSAR-X) or TDX1_SAR (TanDEM-X) */ if (!(EQUALN(CPLGetBasename( osFilename ), "TSX1_SAR", 8) || EQUALN(CPLGetBasename( osFilename ), "TDX1_SAR", 8))) return 0; VSIStatBufL sStat; if( VSIStatL( osFilename, &sStat ) == 0 ) return 1; } return 0; } /* Check if the filename contains TSX1_SAR (TerraSAR-X) or TDX1_SAR (TanDEM-X) */ if (!(EQUALN(CPLGetBasename( poOpenInfo->pszFilename ), "TSX1_SAR", 8) || EQUALN(CPLGetBasename( poOpenInfo->pszFilename ), "TDX1_SAR", 8))) return 0; /* finally look for the <level1Product tag */ if (!EQUALN((char *)poOpenInfo->pabyHeader, "<level1Product", 14)) return 0; return 1; }
static int OGRVFKDriverIdentify(GDALOpenInfo* poOpenInfo) { if( poOpenInfo->fpL == nullptr ) return FALSE; if( poOpenInfo->nHeaderBytes >= 2 && STARTS_WITH((const char*)poOpenInfo->pabyHeader, "&H") ) return TRUE; /* valid datasource can be also SQLite DB previously created by VFK driver, the real check is done by VFKReaderSQLite */ if ( poOpenInfo->nHeaderBytes >= 100 && STARTS_WITH((const char*)poOpenInfo->pabyHeader, "SQLite format 3") ) { // The driver is not ready for virtual file systems if( STARTS_WITH(poOpenInfo->pszFilename, "/vsi") ) return FALSE; VSIStatBufL sStat; if (VSIStatL(poOpenInfo->pszFilename, &sStat) == 0 && VSI_ISREG(sStat.st_mode)) { return GDAL_IDENTIFY_UNKNOWN; } } return FALSE; }
CPLErr GSBGDataset::Delete( const char *pszFilename ) { VSIStatBufL sStat; if( VSIStatL( pszFilename, &sStat ) != 0 ) { CPLError( CE_Failure, CPLE_FileIO, "Unable to stat() %s.\n", pszFilename ); return CE_Failure; } if( !VSI_ISREG( sStat.st_mode ) ) { CPLError( CE_Failure, CPLE_FileIO, "%s is not a regular file, not removed.\n", pszFilename ); return CE_Failure; } if( VSIUnlink( pszFilename ) != 0 ) { CPLError( CE_Failure, CPLE_FileIO, "Error unlinking %s.\n", pszFilename ); return CE_Failure; } return CE_None; }
int TSXDataset::Identify( GDALOpenInfo *poOpenInfo ) { if (poOpenInfo->fpL == NULL || poOpenInfo->nHeaderBytes < 260) { if( poOpenInfo->bIsDirectory ) { const CPLString osFilename = CPLFormCIFilename( poOpenInfo->pszFilename, CPLGetFilename( poOpenInfo->pszFilename ), "xml" ); /* Check if the filename contains TSX1_SAR (TerraSAR-X) or TDX1_SAR (TanDEM-X) */ if (!(STARTS_WITH_CI(CPLGetBasename( osFilename ), "TSX1_SAR") || STARTS_WITH_CI(CPLGetBasename( osFilename ), "TDX1_SAR"))) return 0; VSIStatBufL sStat; if( VSIStatL( osFilename, &sStat ) == 0 ) return 1; } return 0; } /* Check if the filename contains TSX1_SAR (TerraSAR-X) or TDX1_SAR (TanDEM-X) */ if (!(STARTS_WITH_CI(CPLGetBasename( poOpenInfo->pszFilename ), "TSX1_SAR") || STARTS_WITH_CI(CPLGetBasename( poOpenInfo->pszFilename ), "TDX1_SAR"))) return 0; /* finally look for the <level1Product tag */ if (!STARTS_WITH_CI(reinterpret_cast<char *>( poOpenInfo->pabyHeader ), "<level1Product") ) return 0; return 1; }
OGRDataSource *OGRPDFDriver::CreateDataSource( const char * pszName, char **papszOptions ) { /* -------------------------------------------------------------------- */ /* First, ensure there isn't any such file yet. */ /* -------------------------------------------------------------------- */ VSIStatBufL sStatBuf; if( VSIStatL( pszName, &sStatBuf ) == 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "It seems a file system object called '%s' already exists.", pszName ); return NULL; } /* -------------------------------------------------------------------- */ /* Try to create datasource. */ /* -------------------------------------------------------------------- */ OGRPDFDataSource *poDS; poDS = new OGRPDFDataSource(); if( !poDS->Create( pszName, papszOptions ) ) { delete poDS; return NULL; } else return poDS; }
int VSISubFileFilesystemHandler::Stat( const char * pszFilename, VSIStatBufL * psStatBuf ) { CPLString osSubFilePath; vsi_l_offset nOff, nSize; if( !DecomposePath( pszFilename, osSubFilePath, nOff, nSize ) ) { errno = ENOENT; return -1; } int nResult = VSIStatL( osSubFilePath, psStatBuf ); if( nResult == 0 ) { if( nSize != 0 ) psStatBuf->st_size = (long)nSize; else psStatBuf->st_size -= (long)nOff; } return nResult; }
static CPLErr OGRTABDriverDelete( const char *pszDataSource ) { GDALDataset* poDS = NULL; { // Make sure that the file opened by GDALOpenInfo is closed // when the object goes out of scope GDALOpenInfo oOpenInfo(pszDataSource, GA_ReadOnly); poDS = OGRTABDriverOpen(&oOpenInfo); } if( poDS == NULL ) return CE_Failure; char** papszFileList = poDS->GetFileList(); delete poDS; char** papszIter = papszFileList; while( papszIter && *papszIter ) { VSIUnlink( *papszIter ); papszIter ++; } CSLDestroy(papszFileList); VSIStatBufL sStatBuf; if( VSIStatL( pszDataSource, &sStatBuf ) == 0 && VSI_ISDIR(sStatBuf.st_mode) ) { VSIRmdir( pszDataSource ); } return CE_None; }
/** * \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(); }
int OGRTigerDataSource::Create( const char *pszNameIn, char **papszOptionsIn ) { VSIStatBufL stat; /* -------------------------------------------------------------------- */ /* Try to create directory if it doesn't already exist. */ /* -------------------------------------------------------------------- */ if( VSIStatL( pszNameIn, &stat ) != 0 ) { VSIMkdir( pszNameIn, 0755 ); } if( VSIStatL( pszNameIn, &stat ) != 0 || !VSI_ISDIR(stat.st_mode) ) { CPLError( CE_Failure, CPLE_AppDefined, "%s is not a directory, nor can be directly created as one.", pszNameIn ); return FALSE; } /* -------------------------------------------------------------------- */ /* Store various information. */ /* -------------------------------------------------------------------- */ pszPath = CPLStrdup( pszNameIn ); pszName = CPLStrdup( pszNameIn ); bWriteMode = true; SetOptionList( papszOptionsIn ); /* -------------------------------------------------------------------- */ /* Work out the version. */ /* -------------------------------------------------------------------- */ // nVersionCode = 1000; /* census 2000 */ nVersionCode = 1002; /* census 2002 */ if( GetOption("VERSION") != nullptr ) { nVersionCode = atoi(GetOption("VERSION")); nVersionCode = std::max(0, std::min(9999, nVersionCode)); } nVersion = TigerClassifyVersion(nVersionCode); return TRUE; }
/*! \brief VFKReaderSQLite constructor */ VFKReaderSQLite::VFKReaderSQLite(const char *pszFilename) : VFKReader(pszFilename) { const char *pszDbNameConf; CPLString pszDbName; CPLString osCommand; VSIStatBufL sStatBuf; bool bNewDb; /* open tmp SQLite DB (re-use DB file if already exists) */ pszDbNameConf = CPLGetConfigOption("OGR_VFK_DB_NAME", NULL); if (pszDbNameConf) { pszDbName = pszDbNameConf; } else { pszDbName.Printf("%s.db", m_pszFilename); } if (CSLTestBoolean(CPLGetConfigOption("OGR_VFK_DB_SPATIAL", "YES"))) m_bSpatial = TRUE; /* build geometry from DB */ else m_bSpatial = FALSE; /* store also geometry in DB */ bNewDb = TRUE; if (VSIStatL(pszDbName, &sStatBuf ) == 0) { if (CSLTestBoolean(CPLGetConfigOption("OGR_VFK_DB_OVERWRITE", "NO"))) { bNewDb = TRUE; /* overwrite existing DB */ VSIUnlink(pszDbName); } else { bNewDb = FALSE; /* re-use exising DB */ } } else { CPLError(CE_Warning, CPLE_AppDefined, "SQLite DB not found. Reading VFK data may take some time..."); } CPLDebug("OGR-VFK", "New DB: %s Spatial: %s", bNewDb ? "yes" : "no", m_bSpatial ? "yes" : "no"); if (SQLITE_OK != sqlite3_open(pszDbName, &m_poDB)) { CPLError(CE_Failure, CPLE_AppDefined, "Creating SQLite DB failed"); } else { char* pszErrMsg = NULL; sqlite3_exec(m_poDB, "PRAGMA synchronous = OFF", NULL, NULL, &pszErrMsg); sqlite3_free(pszErrMsg); } if (bNewDb) { /* new DB, create support metadata tables */ osCommand = "CREATE TABLE 'vfk_blocks' " "(file_name text, table_name text, num_records integer, " "num_geometries integer, table_defn text)"; ExecuteSQL(osCommand.c_str()); } }
// // Uses GDAL to create a temporary TIF file, using the band create options // copies the content to the destination buffer then erases the temp TIF // static CPLErr CompressTIF(buf_mgr &dst, buf_mgr &src, const ILImage &img, char **papszOptions) { CPLErr ret; GDALDriver *poTiffDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); VSIStatBufL statb; CPLString fname = uniq_memfname("mrf_tif_write"); GDALDataset *poTiff = poTiffDriver->Create(fname, img.pagesize.x, img.pagesize.y, img.pagesize.c, img.dt, papszOptions ); // Read directly to avoid double caching in GDAL // Unfortunately not possible for multiple bands if (img.pagesize.c == 1) { ret = poTiff->GetRasterBand(1)->WriteBlock(0,0,src.buffer); } else { ret = poTiff->RasterIO(GF_Write, 0,0,img.pagesize.x,img.pagesize.y, src.buffer, img.pagesize.x, img.pagesize.y, img.dt, img.pagesize.c, NULL, 0,0,0 #if GDAL_VERSION_MAJOR >= 2 ,NULL #endif ); } if (CE_None != ret) return ret; GDALClose(poTiff); // Check that we can read the file if (VSIStatL(fname, &statb)) { CPLError(CE_Failure,CPLE_AppDefined, "MRF: TIFF, can't stat %s", fname.c_str()); return CE_Failure; } if (size_t(statb.st_size) > dst.size) { CPLError(CE_Failure,CPLE_AppDefined, "MRF: TIFF, Tiff generated is too large"); return CE_Failure; } VSILFILE *pf = VSIFOpenL(fname,"rb"); if (pf == NULL) { CPLError(CE_Failure,CPLE_AppDefined, "MRF: TIFF, can't open %s", fname.c_str()); return CE_Failure; } VSIFReadL(dst.buffer, static_cast<size_t>(statb.st_size), 1, pf); dst.size = static_cast<size_t>(statb.st_size); VSIFCloseL(pf); VSIUnlink(fname); return CE_None; }
int SRTMHGTDataset::Identify( GDALOpenInfo * poOpenInfo ) { const char* fileName = CPLGetFilename(poOpenInfo->pszFilename); if( strlen(fileName) < 11 || fileName[7] != '.' ) return FALSE; CPLString osLCFilename(CPLString(fileName).tolower()); if( (osLCFilename[0] != 'n' && osLCFilename[0] != 's') || (osLCFilename[3] != 'e' && osLCFilename[3] != 'w') ) return FALSE; if( !STARTS_WITH(fileName, "/vsizip/") && osLCFilename.endsWith(".hgt.zip") ) { CPLString osNewName("/vsizip/"); osNewName += poOpenInfo->pszFilename; osNewName += "/"; osNewName += CPLString(fileName).substr(0, 7); osNewName += ".hgt"; GDALOpenInfo oOpenInfo(osNewName, GA_ReadOnly); return Identify(&oOpenInfo); } if( !STARTS_WITH(fileName, "/vsizip/") && osLCFilename.endsWith(".srtmswbd.raw.zip") ) { CPLString osNewName("/vsizip/"); osNewName += poOpenInfo->pszFilename; osNewName += "/"; osNewName += CPLString(fileName).substr(0, 7); osNewName += ".raw"; GDALOpenInfo oOpenInfo(osNewName, GA_ReadOnly); return Identify(&oOpenInfo); } if( !osLCFilename.endsWith(".hgt") && !osLCFilename.endsWith(".raw") && !osLCFilename.endsWith(".hgt.gz") ) return FALSE; /* -------------------------------------------------------------------- */ /* We check the file size to see if it is */ /* SRTM1 (below or above lat 50) or SRTM 3 */ /* -------------------------------------------------------------------- */ VSIStatBufL fileStat; if(VSIStatL(poOpenInfo->pszFilename, &fileStat) != 0) return FALSE; if(fileStat.st_size != 3601 * 3601 && fileStat.st_size != 3601 * 3601 * 2 && fileStat.st_size != 1801 * 3601 * 2 && fileStat.st_size != 1201 * 1201 * 2 ) return FALSE; return TRUE; }
void wxGxArchiveFolder::LoadChildren(void) { if(m_bIsChildrenLoaded) return; char **papszItems = CPLReadDir(m_sPath); if(papszItems == NULL) return; char **papszFileList = NULL; //remove unused items for(int i = CSLCount(papszItems) - 1; i >= 0; i-- ) { if( wxGISEQUAL(papszItems[i],".") || wxGISEQUAL(papszItems[i],"..") ) continue; CPLString szFileName = m_sPath; szFileName += "/"; szFileName += papszItems[i]; VSIStatBufL BufL; int ret = VSIStatL(szFileName, &BufL); if(ret == 0) { if(VSI_ISDIR(BufL.st_mode)) { wxString sCharset(wxT("cp-866")); wxGISAppConfig oConfig = GetConfig(); if(oConfig.IsOk()) sCharset = oConfig.Read(enumGISHKCU, wxString(wxT("wxGISCommon/zip/charset")), sCharset); wxString sFileName(papszItems[i], wxCSConv(sCharset)); GetArchiveFolder(this, sFileName, szFileName); } else { papszFileList = CSLAddString( papszFileList, szFileName ); } } } CSLDestroy( papszItems ); //load names wxGxCatalog *pCatalog = wxDynamicCast(GetGxCatalog(), wxGxCatalog); if(pCatalog) { wxArrayLong ChildrenIds; pCatalog->CreateChildren(this, papszFileList, ChildrenIds); for(size_t i = 0; i < ChildrenIds.GetCount(); ++i) pCatalog->ObjectAdded(ChildrenIds[i]); } CSLDestroy( papszFileList ); m_bIsChildrenLoaded = true; }
int OGRGeoconceptDataSource::Open( const char* pszName, bool bTestOpen, bool bUpdate ) { /* -------------------------------------------------------------------- */ /* Is the given path a directory or a regular file? */ /* -------------------------------------------------------------------- */ VSIStatBufL sStat; if( VSIStatL( pszName, &sStat ) != 0 || (!VSI_ISDIR(sStat.st_mode) && !VSI_ISREG(sStat.st_mode)) ) { if( !bTestOpen ) { CPLError( CE_Failure, CPLE_AppDefined, "%s is neither a file or directory, " "Geoconcept access failed.", pszName ); } return FALSE; } if( VSI_ISDIR(sStat.st_mode) ) { CPLDebug( "GEOCONCEPT", "%s is a directory, Geoconcept access is not yet supported.", pszName ); return FALSE; } if( VSI_ISREG(sStat.st_mode) ) { _bSingleNewFile = false; _bUpdate = bUpdate; _pszName = CPLStrdup( pszName ); if( !LoadFile( _bUpdate ? "a+t":"rt" ) ) { CPLDebug( "GEOCONCEPT", "Failed to open Geoconcept %s." " It may be corrupt.", pszName ); return FALSE; } return TRUE; } return _nLayers > 0; }
OGRDataSource *OGRGeoconceptDriver::CreateDataSource( const char* pszName, char** papszOptions ) { VSIStatBufL sStat; /* int bSingleNewFile = FALSE; */ if( pszName==nullptr || strlen(pszName)==0 ) { CPLError( CE_Failure, CPLE_AppDefined, "Invalid datasource name (null or empty)"); return nullptr; } /* -------------------------------------------------------------------- */ /* Is the target a valid existing directory? */ /* -------------------------------------------------------------------- */ if( VSIStatL( pszName, &sStat ) == 0 ) { if( !VSI_ISDIR(sStat.st_mode) ) { CPLError( CE_Failure, CPLE_AppDefined, "%s is not a valid existing directory.", pszName ); return nullptr; } } /* -------------------------------------------------------------------- */ /* Does it end with the extension .gxt indicating the user likely */ /* wants to create a single file set? */ /* -------------------------------------------------------------------- */ else if( EQUAL(CPLGetExtension(pszName),"gxt") || EQUAL(CPLGetExtension(pszName),"txt") ) { /* bSingleNewFile = TRUE; */ } /* -------------------------------------------------------------------- */ /* Return a new OGRDataSource() */ /* -------------------------------------------------------------------- */ OGRGeoconceptDataSource *poDS = new OGRGeoconceptDataSource(); if( !poDS->Create( pszName, papszOptions ) ) { delete poDS; return nullptr; } return poDS; }
static int mapcache_cache_tiff_vsi_stat( mapcache_cache_tiff *cache, const char* name, VSIStatBufL* pstat) { mapache_gdal_env_context context; int ret; set_gdal_context(cache, &context); ret = VSIStatL(name, pstat); restore_gdal_context(cache, &context); return ret; }
// Returns a string in /vsimem/ + prefix + count that doesn't exist when this function gets called // It is not completely safe, open the result as soon as possible CPLString uniq_memfname(const char *prefix) { // Define MRF_LOCAL_TMP to use local files instead of RAM // #define MRF_LOCAL_TMP #if defined(MRF_LOCAL_TMP) return CPLGenerateTempFilename(prefix); #else CPLString fname; VSIStatBufL statb; static unsigned int cnt=0; do fname.Printf("/vsimem/%s_%08x",prefix, cnt++); while (!VSIStatL(fname, &statb)); return fname; #endif }
int SAFEDataset::Identify( GDALOpenInfo *poOpenInfo ) { /* Check for the case where we're trying to read the calibrated data: */ if (STARTS_WITH_CI(poOpenInfo->pszFilename, "SENTINEL1_CALIB:")) { return TRUE; } /* Check for the case where we're trying to read the subdatasets: */ if (STARTS_WITH_CI(poOpenInfo->pszFilename, "SENTINEL1_DS:")) { return TRUE; } /* Check for directory access when there is a manifest.safe file in the directory. */ if( poOpenInfo->bIsDirectory ) { VSIStatBufL sStat; CPLString osMDFilename = CPLFormCIFilename( poOpenInfo->pszFilename, "manifest.safe", nullptr ); if( VSIStatL( osMDFilename, &sStat ) == 0 && VSI_ISREG(sStat.st_mode) ) { GDALOpenInfo oOpenInfo( osMDFilename, GA_ReadOnly, nullptr ); return Identify(&oOpenInfo); } return FALSE; } /* otherwise, do our normal stuff */ if( !EQUAL(CPLGetFilename(poOpenInfo->pszFilename), "manifest.safe") ) return FALSE; if( poOpenInfo->nHeaderBytes < 100 ) return FALSE; if( strstr((const char *) poOpenInfo->pabyHeader, "<xfdu:XFDU" ) == nullptr) return FALSE; // This driver doesn't handle Sentinel-2 data if( strstr((const char *) poOpenInfo->pabyHeader, "sentinel-2" ) != nullptr) return FALSE; return TRUE; }
CPLErr GDALDefaultOverviews::BuildOverviewsSubDataset( const char * pszPhysicalFile, const char * pszResampling, int nOverviews, int * panOverviewList, int nBands, int * panBandList, GDALProgressFunc pfnProgress, void * pProgressData) { if( osOvrFilename.length() == 0 ) { int iSequence = 0; VSIStatBufL sStatBuf; for( iSequence = 0; iSequence < 100; iSequence++ ) { osOvrFilename.Printf( "%s_%d.ovr", pszPhysicalFile, iSequence ); if( VSIStatL( osOvrFilename, &sStatBuf ) != 0 ) { CPLString osAdjustedOvrFilename; if( poDS->GetMOFlags() & GMO_PAM_CLASS ) { osAdjustedOvrFilename.Printf( ":::BASE:::%s_%d.ovr", CPLGetFilename(pszPhysicalFile), iSequence ); } else osAdjustedOvrFilename = osOvrFilename; poDS->SetMetadataItem( "OVERVIEW_FILE", osAdjustedOvrFilename, "OVERVIEWS" ); break; } } if( iSequence == 100 ) osOvrFilename = ""; } return BuildOverviews( NULL, pszResampling, nOverviews, panOverviewList, nBands, panBandList, pfnProgress, pProgressData ); }
GDALDataset* OGRJMLDataset::Create( const char *pszFilename, CPL_UNUSED int nXSize, CPL_UNUSED int nYSize, CPL_UNUSED int nBands, CPL_UNUSED GDALDataType eDT, CPL_UNUSED char **papszOptions ) { if (strcmp(pszFilename, "/dev/stdout") == 0) pszFilename = "/vsistdout/"; /* -------------------------------------------------------------------- */ /* Do not override exiting file. */ /* -------------------------------------------------------------------- */ VSIStatBufL sStatBuf; if( VSIStatL( pszFilename, &sStatBuf ) == 0 ) { CPLError(CE_Failure, CPLE_NotSupported, "You have to delete %s before being able to create it with the JML driver", pszFilename); return NULL; } OGRJMLDataset* poDS = new OGRJMLDataset(); /* -------------------------------------------------------------------- */ /* Create the output file. */ /* -------------------------------------------------------------------- */ poDS->bWriteMode = TRUE; poDS->SetDescription( pszFilename ); poDS->fp = VSIFOpenL( pszFilename, "w" ); if( poDS->fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Failed to create JML file %s.", pszFilename ); delete poDS; return NULL; } return poDS; }
NAMESPACE_MRF_START // Returns a string in /vsimem/ + prefix + count that doesn't exist when this function gets called // It is not thread safe, open the result as soon as possible static CPLString uniq_memfname(const char *prefix) { // Define MRF_LOCAL_TMP to use local files instead of RAM // #define MRF_LOCAL_TMP #if defined(MRF_LOCAL_TMP) return CPLGenerateTempFilename(prefix); #else CPLString fname; VSIStatBufL statb; static unsigned int cnt=0; do fname.Printf("/vsimem/%s_%08x",prefix, cnt++); while (!VSIStatL(fname, &statb)); return fname; #endif }
int SRTMHGTDataset::Identify( GDALOpenInfo * poOpenInfo ) { const char* fileName = CPLGetFilename(poOpenInfo->pszFilename); if( strlen(fileName) < 11 || !EQUALN(&fileName[7], ".hgt", 4) ) return FALSE; /* -------------------------------------------------------------------- */ /* We check the file size to see if it is 25,934,402 bytes */ /* (SRTM 1) or 2,884,802 bytes (SRTM 3) */ /* -------------------------------------------------------------------- */ VSIStatBufL fileStat; if(VSIStatL(poOpenInfo->pszFilename, &fileStat) != 0) return FALSE; if(fileStat.st_size != 25934402 && fileStat.st_size != 2884802) return FALSE; return TRUE; }
static void ProcessIdentifyTarget( const char *pszTarget, char **papszSiblingList, bool bRecursive, bool bReportFailures, bool bForceRecurse ) { GDALDriverH hDriver; VSIStatBufL sStatBuf; int i; hDriver = GDALIdentifyDriver( pszTarget, papszSiblingList ); if( hDriver != nullptr ) printf( "%s: %s\n", pszTarget, GDALGetDriverShortName( hDriver ) ); else if( bReportFailures ) printf( "%s: unrecognized\n", pszTarget ); if( !bForceRecurse && (!bRecursive || hDriver != nullptr) ) return; if( VSIStatL( pszTarget, &sStatBuf ) != 0 || !VSI_ISDIR( sStatBuf.st_mode ) ) return; papszSiblingList = VSIReadDir( pszTarget ); for( i = 0; papszSiblingList && papszSiblingList[i]; i++ ) { if( EQUAL(papszSiblingList[i],"..") || EQUAL(papszSiblingList[i],".") ) continue; CPLString osSubTarget = CPLFormFilename( pszTarget, papszSiblingList[i], nullptr ); ProcessIdentifyTarget( osSubTarget, papszSiblingList, bRecursive, bReportFailures, bForceRecurse ); } CSLDestroy(papszSiblingList); }
void VRTRasterBand::GetFileList(char*** ppapszFileList, int *pnSize, int *pnMaxSize, CPLHashSet* hSetFiles) { for( unsigned int iOver = 0; iOver < apoOverviews.size(); iOver++ ) { CPLString &osFilename = apoOverviews[iOver].osFilename; /* -------------------------------------------------------------------- */ /* Is the filename even a real filesystem object? */ /* -------------------------------------------------------------------- */ VSIStatBufL sStat; if( VSIStatL( osFilename, &sStat ) != 0 ) return; /* -------------------------------------------------------------------- */ /* Is it already in the list ? */ /* -------------------------------------------------------------------- */ if( CPLHashSetLookup(hSetFiles, osFilename) != NULL ) return; /* -------------------------------------------------------------------- */ /* Grow array if necessary */ /* -------------------------------------------------------------------- */ if (*pnSize + 1 >= *pnMaxSize) { *pnMaxSize = 2 + 2 * (*pnMaxSize); *ppapszFileList = (char **) CPLRealloc( *ppapszFileList, sizeof(char*) * (*pnMaxSize) ); } /* -------------------------------------------------------------------- */ /* Add the string to the list */ /* -------------------------------------------------------------------- */ (*ppapszFileList)[*pnSize] = CPLStrdup(osFilename); (*ppapszFileList)[(*pnSize + 1)] = NULL; CPLHashSetInsert(hSetFiles, (*ppapszFileList)[*pnSize]); (*pnSize) ++; } }