本文整理汇总了C++中VSIFCloseL函数的典型用法代码示例。如果您正苦于以下问题:C++ VSIFCloseL函数的具体用法?C++ VSIFCloseL怎么用?C++ VSIFCloseL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VSIFCloseL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EQUAL
/**********************************************************************
* IMapInfoFile::SmartOpen()
*
* Use this static method to automatically open any flavor of MapInfo
* dataset. This method will detect the file type, create an object
* of the right type, and open the file.
*
* Call GetFileClass() on the returned object if you need to find out
* its exact type. (To access format-specific methods for instance)
*
* Returns the new object ptr. , or NULL if the open failed.
**********************************************************************/
IMapInfoFile *IMapInfoFile::SmartOpen(const char *pszFname,
GBool bUpdate,
GBool bTestOpenNoError /*=FALSE*/)
{
IMapInfoFile *poFile = nullptr;
int nLen = 0;
if (pszFname)
nLen = static_cast<int>(strlen(pszFname));
if (nLen > 4 && (EQUAL(pszFname + nLen-4, ".MIF") ||
EQUAL(pszFname + nLen-4, ".MID") ) )
{
/*-------------------------------------------------------------
* MIF/MID file
*------------------------------------------------------------*/
poFile = new MIFFile;
}
else if (nLen > 4 && EQUAL(pszFname + nLen-4, ".TAB"))
{
/*-------------------------------------------------------------
* .TAB file ... is it a TABFileView or a TABFile?
* We have to read the .tab header to find out.
*------------------------------------------------------------*/
char *pszAdjFname = CPLStrdup(pszFname);
GBool bFoundFields = FALSE;
GBool bFoundView = FALSE;
GBool bFoundSeamless = FALSE;
TABAdjustFilenameExtension(pszAdjFname);
VSILFILE *fp = VSIFOpenL(pszAdjFname, "r");
const char *pszLine = nullptr;
while(fp && (pszLine = CPLReadLineL(fp)) != nullptr)
{
while (isspace(static_cast<unsigned char>(*pszLine))) pszLine++;
if (STARTS_WITH_CI(pszLine, "Fields"))
bFoundFields = TRUE;
else if (STARTS_WITH_CI(pszLine, "create view"))
bFoundView = TRUE;
else if (STARTS_WITH_CI(pszLine, "\"\\IsSeamless\" = \"TRUE\""))
bFoundSeamless = TRUE;
}
if (bFoundView)
poFile = new TABView;
else if (bFoundFields && bFoundSeamless)
poFile = new TABSeamless;
else if (bFoundFields)
poFile = new TABFile;
if (fp)
VSIFCloseL(fp);
CPLFree(pszAdjFname);
}
/*-----------------------------------------------------------------
* Perform the open() call
*----------------------------------------------------------------*/
if (poFile && poFile->Open(pszFname, bUpdate ? TABReadWrite : TABRead, bTestOpenNoError) != 0)
{
delete poFile;
poFile = nullptr;
}
if (!bTestOpenNoError && poFile == nullptr)
{
CPLError(CE_Failure, CPLE_FileIO,
"%s could not be opened as a MapInfo dataset.", pszFname);
}
return poFile;
}
示例2: CPLError
//.........这里部分代码省略.........
"out. Try increasing " \
"LCP_MAX_DOWNLOAD_TRIES or "
"LCP_DOWNLOAD_WAIT" );
return SURF_FETCH_E_TIMEOUT;
}
/*-----------------------------------------------------------------------------
* Download the landfire model
*-----------------------------------------------------------------------------*/
pszUrl = CPLSPrintf( LF_DOWNLOAD_JOB_TEMPLATE, m_JobId.c_str() );
m_poResult = CPLHTTPFetch( pszUrl, NULL );
CHECK_HTTP_RESULT( "Failed to get job status" );
/*
** Parse the URL from the returned string
*/
std::string ss((const char*) m_poResult->pabyData );
CPLHTTPDestroyResult( m_poResult );
std::size_t pos1 = ss.find("https://");
std::size_t pos2 = ss.find(".zip");
std::string url = ss.substr(pos1, (pos2+4-pos1));
pszUrl = url.c_str();
m_poResult = CPLHTTPFetch( pszUrl, NULL );
CHECK_HTTP_RESULT( "Failed to get job status" );
nSize = m_poResult->nDataLen;
VSILFILE *fout;
const char *pszTmpZip = CPLFormFilename( NULL,
CPLGenerateTempFilename( "NINJA_LCP_CLIENT" ),
".zip" );
fout = VSIFOpenL( pszTmpZip, "w+" );
if( NULL == fout )
{
CPLError( CE_Warning, CPLE_AppDefined, "Failed to create output file" );
CPLHTTPDestroyResult( m_poResult );
return SURF_FETCH_E_IO_ERR;
}
VSIFWriteL( m_poResult->pabyData, nSize, 1, fout );
VSIFCloseL( fout );
CPLHTTPDestroyResult( m_poResult );
/*
** Extract the lcp and the prj file, and 'save as'
*/
char **papszFileList = NULL;
std::string osPathInZip;
const char *pszVSIZip = CPLSPrintf( "/vsizip/%s", pszTmpZip );
CPLDebug( "LCP_CLIENT", "Extracting lcp from %s", pszVSIZip );
papszFileList = VSIReadDirRecursive( pszVSIZip );
int bFound = FALSE;
std::string osFullPath;
for( int i = 0; i < CSLCount( papszFileList ); i++ )
{
osFullPath = papszFileList[i];
if( osFullPath.find( "Landscape_1.lcp" ) != std::string::npos )
{
osPathInZip = CPLGetPath( papszFileList[i] );
CPLDebug( "LCP_CLIENT", "Found lcp in: %s", osPathInZip.c_str() );
bFound = TRUE;
break;
}
}
CSLDestroy( papszFileList );
if( !bFound )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Failed to find lcp in archive" );
//VSIUnlink( pszTmpZip );
return SURF_FETCH_E_IO_ERR;
}
int nError = 0;
const char *pszFileToFind = CPLSPrintf( "%s/Landscape_1.lcp",
osPathInZip.c_str() );
nError = ExtractFileFromZip( pszTmpZip, pszFileToFind, filename );
if( nError )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Failed to extract LCP from zip." );
VSIUnlink( pszTmpZip );
return SURF_FETCH_E_IO_ERR;
}
pszFileToFind = CPLSPrintf( "%s/Landscape_1.prj", osPathInZip.c_str() );
nError = ExtractFileFromZip( pszTmpZip, pszFileToFind,
CPLFormFilename( CPLGetPath( filename ),
CPLGetBasename( filename ),
".prj" ) );
if( nError )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Failed to extract PRJ from zip." );
return SURF_FETCH_E_IO_ERR;
}
if( !CSLTestBoolean( CPLGetConfigOption( "LCP_KEEP_ARCHIVE", "FALSE" ) ) )
{
VSIUnlink( pszTmpZip );
}
return SURF_FETCH_E_NONE;
}
示例3: CPLError
GDALDataset *GSAGDataset::CreateCopy( const char *pszFilename,
GDALDataset *poSrcDS,
int bStrict, char **papszOptions,
GDALProgressFunc pfnProgress,
void *pProgressData )
{
if( pfnProgress == NULL )
pfnProgress = GDALDummyProgress;
int nBands = poSrcDS->GetRasterCount();
if (nBands == 0)
{
CPLError( CE_Failure, CPLE_NotSupported,
"GSAG driver does not support source dataset with zero band.\n");
return NULL;
}
else if (nBands > 1)
{
if( bStrict )
{
CPLError( CE_Failure, CPLE_NotSupported,
"Unable to create copy, Golden Software ASCII Grid "
"format only supports one raster band.\n" );
return NULL;
}
else
CPLError( CE_Warning, CPLE_NotSupported,
"Golden Software ASCII Grid format only supports one "
"raster band, first band will be copied.\n" );
}
if( !pfnProgress( 0.0, NULL, pProgressData ) )
{
CPLError( CE_Failure, CPLE_UserInterrupt, "User terminated\n" );
return NULL;
}
VSILFILE *fp = VSIFOpenL( pszFilename, "w+b" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to create file '%s' failed.\n",
pszFilename );
return NULL;
}
int nXSize = poSrcDS->GetRasterXSize();
int nYSize = poSrcDS->GetRasterYSize();
double adfGeoTransform[6];
poSrcDS->GetGeoTransform( adfGeoTransform );
std::ostringstream ssHeader;
ssHeader.precision( nFIELD_PRECISION );
ssHeader.setf( std::ios::uppercase );
ssHeader << "DSAA\x0D\x0A";
ssHeader << nXSize << " " << nYSize << "\x0D\x0A";
ssHeader << adfGeoTransform[0] + adfGeoTransform[1] / 2 << " "
<< adfGeoTransform[1] * (nXSize - 0.5) + adfGeoTransform[0]
<< "\x0D\x0A";
ssHeader << adfGeoTransform[5] * (nYSize - 0.5) + adfGeoTransform[3] << " "
<< adfGeoTransform[3] + adfGeoTransform[5] / 2
<< "\x0D\x0A";
if( VSIFWriteL( (void *)ssHeader.str().c_str(), 1, ssHeader.str().length(),
fp ) != ssHeader.str().length() )
{
VSIFCloseL( fp );
CPLError( CE_Failure, CPLE_FileIO,
"Unable to create copy, writing header failed.\n" );
return NULL;
}
/* Save the location and write placeholders for the min/max Z value */
vsi_l_offset nRangeStart = VSIFTellL( fp );
const char *szDummyRange = "0.0000000000001 0.0000000000001\x0D\x0A";
size_t nDummyRangeLen = strlen( szDummyRange );
if( VSIFWriteL( (void *)szDummyRange, 1, nDummyRangeLen,
fp ) != nDummyRangeLen )
{
VSIFCloseL( fp );
CPLError( CE_Failure, CPLE_FileIO,
"Unable to create copy, writing header failed.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Copy band data. */
/* -------------------------------------------------------------------- */
double *pdfData = (double *)VSIMalloc2( nXSize, sizeof( double ) );
if( pdfData == NULL )
{
VSIFCloseL( fp );
CPLError( CE_Failure, CPLE_OutOfMemory,
"Unable to create copy, unable to allocate line buffer.\n" );
//.........这里部分代码省略.........
示例4: CPLError
GDALDataset *E00GRIDDataset::Open( GDALOpenInfo * poOpenInfo )
{
if (!Identify(poOpenInfo) || poOpenInfo->fpL == nullptr )
return nullptr;
/* -------------------------------------------------------------------- */
/* Find dataset characteristics */
/* -------------------------------------------------------------------- */
VSILFILE* fp = poOpenInfo->fpL;
poOpenInfo->fpL = nullptr;
if (poOpenInfo->eAccess == GA_Update)
{
CPLError( CE_Failure, CPLE_NotSupported,
"The E00GRID driver does not support update access to existing"
" datasets.\n" );
VSIFCloseL(fp);
return nullptr;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
E00GRIDDataset *poDS = new E00GRIDDataset();
if (strstr((const char*)poOpenInfo->pabyHeader, "\r\n") != nullptr)
poDS->nBytesEOL = 2;
poDS->fp = fp;
/* read EXP 0 or EXP 1 line */
const char* pszLine = CPLReadLine2L(fp, 81, nullptr);
if (pszLine == nullptr)
{
CPLDebug("E00GRID", "Bad 1st line");
delete poDS;
return nullptr;
}
bool bCompressed = STARTS_WITH_CI(pszLine, "EXP 1");
E00ReadPtr e00ReadPtr = nullptr;
if (bCompressed)
{
VSIRewindL(fp);
e00ReadPtr = E00ReadCallbackOpen(poDS,
E00GRIDDataset::ReadNextLine,
E00GRIDDataset::Rewind);
if (e00ReadPtr == nullptr)
{
delete poDS;
return nullptr;
}
E00ReadNextLine(e00ReadPtr);
poDS->e00ReadPtr = e00ReadPtr;
}
/* skip GRD 2 line */
if (e00ReadPtr)
pszLine = E00ReadNextLine(e00ReadPtr);
else
pszLine = CPLReadLine2L(fp, 81, nullptr);
if (pszLine == nullptr || !STARTS_WITH_CI(pszLine, "GRD 2"))
{
CPLDebug("E00GRID", "Bad 2nd line");
delete poDS;
return nullptr;
}
/* read ncols, nrows and nodata value */
if (e00ReadPtr)
pszLine = E00ReadNextLine(e00ReadPtr);
else
pszLine = CPLReadLine2L(fp, 81, nullptr);
if (pszLine == nullptr || strlen(pszLine) <
E00_INT_SIZE+E00_INT_SIZE+2+E00_DOUBLE_SIZE)
{
CPLDebug("E00GRID", "Bad 3rd line");
delete poDS;
return nullptr;
}
const int nRasterXSize = atoi(pszLine);
const int nRasterYSize = atoi(pszLine + E00_INT_SIZE);
if (!GDALCheckDatasetDimensions(nRasterXSize, nRasterYSize) ||
/* ASCII format. Huge rasters do not make sense */
nRasterXSize > 100000 ||
nRasterYSize > 100000 )
{
delete poDS;
return nullptr;
}
GDALDataType eDT = GDT_Float32;
if (STARTS_WITH_CI(pszLine + E00_INT_SIZE + E00_INT_SIZE, " 1"))
eDT = GDT_Int32;
else if (STARTS_WITH_CI(pszLine + E00_INT_SIZE + E00_INT_SIZE, " 2"))
eDT = GDT_Float32;
else
{
//.........这里部分代码省略.........
示例5: OGRSQLiteExecuteSQL
OGRLayer * OGRSQLiteExecuteSQL( GDALDataset* poDS,
const char *pszStatement,
OGRGeometry *poSpatialFilter,
CPL_UNUSED const char *pszDialect )
{
char* pszTmpDBName = (char*) CPLMalloc(256);
snprintf(pszTmpDBName, 256, "/vsimem/ogr2sqlite/temp_%p.db", pszTmpDBName);
OGRSQLiteDataSource* poSQLiteDS = NULL;
int nRet;
int bSpatialiteDB = FALSE;
CPLString osOldVal;
const char* pszOldVal = CPLGetConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", NULL);
if( pszOldVal != NULL )
{
osOldVal = pszOldVal;
pszOldVal = osOldVal.c_str();
}
/* -------------------------------------------------------------------- */
/* Create in-memory sqlite/spatialite DB */
/* -------------------------------------------------------------------- */
#ifdef HAVE_SPATIALITE
/* -------------------------------------------------------------------- */
/* Creating an empty SpatiaLite DB (with spatial_ref_sys populated */
/* has a significant cost. So at the first attempt, let's make */
/* one and cache it for later use. */
/* -------------------------------------------------------------------- */
#if 1
static size_t nEmptyDBSize = 0;
static GByte* pabyEmptyDB = NULL;
{
static CPLMutex* hMutex = NULL;
CPLMutexHolder oMutexHolder(&hMutex);
static int bTried = FALSE;
if( !bTried &&
CPLTestBool(CPLGetConfigOption("OGR_SQLITE_DIALECT_USE_SPATIALITE", "YES")) )
{
bTried = TRUE;
char* pszCachedFilename = (char*) CPLMalloc(256);
snprintf(pszCachedFilename, 256, "/vsimem/ogr2sqlite/reference_%p.db",
pszCachedFilename);
char** papszOptions = CSLAddString(NULL, "SPATIALITE=YES");
OGRSQLiteDataSource* poCachedDS = new OGRSQLiteDataSource();
nRet = poCachedDS->Create( pszCachedFilename, papszOptions );
CSLDestroy(papszOptions);
papszOptions = NULL;
delete poCachedDS;
if( nRet )
{
/* Note: the reference file keeps the ownership of the data, so that */
/* it gets released with VSICleanupFileManager() */
vsi_l_offset nEmptyDBSizeLarge = 0;
pabyEmptyDB = VSIGetMemFileBuffer( pszCachedFilename, &nEmptyDBSizeLarge, FALSE );
nEmptyDBSize = static_cast<size_t>(nEmptyDBSizeLarge);
}
CPLFree( pszCachedFilename );
}
}
/* The following configuration option is useful mostly for debugging/testing */
if( pabyEmptyDB != NULL && CPLTestBool(CPLGetConfigOption("OGR_SQLITE_DIALECT_USE_SPATIALITE", "YES")) )
{
GByte* pabyEmptyDBClone = (GByte*)VSI_MALLOC_VERBOSE(nEmptyDBSize);
if( pabyEmptyDBClone == NULL )
{
CPLFree(pszTmpDBName);
return NULL;
}
memcpy(pabyEmptyDBClone, pabyEmptyDB, nEmptyDBSize);
VSIFCloseL(VSIFileFromMemBuffer( pszTmpDBName, pabyEmptyDBClone, nEmptyDBSize, TRUE ));
poSQLiteDS = new OGRSQLiteDataSource();
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", "NO");
nRet = poSQLiteDS->Open( pszTmpDBName, TRUE, NULL );
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", pszOldVal);
if( !nRet )
{
/* should not happen really ! */
delete poSQLiteDS;
VSIUnlink(pszTmpDBName);
CPLFree(pszTmpDBName);
return NULL;
}
bSpatialiteDB = TRUE;
}
#else
/* No caching version */
poSQLiteDS = new OGRSQLiteDataSource();
char** papszOptions = CSLAddString(NULL, "SPATIALITE=YES");
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", "NO");
nRet = poSQLiteDS->Create( pszTmpDBName, papszOptions );
CPLSetThreadLocalConfigOption("OGR_SQLITE_STATIC_VIRTUAL_OGR", pszOldVal);
CSLDestroy(papszOptions);
papszOptions = NULL;
if( nRet )
{
//.........这里部分代码省略.........
示例6: CPLError
GDALDataset *CTable2Dataset::Create( const char * pszFilename,
int nXSize, int nYSize, int nBands,
GDALDataType eType,
char ** papszOptions )
{
if( eType != GDT_Float32 )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Attempt to create CTable2 file with unsupported data type '%s'.",
GDALGetDataTypeName( eType ) );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Try to open or create file. */
/* -------------------------------------------------------------------- */
VSILFILE *fp;
fp = VSIFOpenL( pszFilename, "wb" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to create file `%s' failed.\n",
pszFilename );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a file header, with a defaulted georeferencing. */
/* -------------------------------------------------------------------- */
char achHeader[160];
int nValue32;
double dfValue;
memset( achHeader, 0, sizeof(achHeader));
memcpy( achHeader+0, "CTABLE V2.0 ", 16 );
if( CSLFetchNameValue( papszOptions, "DESCRIPTION" ) != NULL )
strncpy( achHeader + 16,
CSLFetchNameValue( papszOptions, "DESCRIPTION" ),
80 );
// lower left origin (longitude, center of pixel, radians)
dfValue = 0;
CPL_LSBPTR64( &dfValue );
memcpy( achHeader + 96, &dfValue, 8 );
// lower left origin (latitude, center of pixel, radians)
dfValue = 0;
CPL_LSBPTR64( &dfValue );
memcpy( achHeader + 104, &dfValue, 8 );
// pixel width (radians)
dfValue = 0.01 * M_PI / 180.0;
CPL_LSBPTR64( &dfValue );
memcpy( achHeader + 112, &dfValue, 8 );
// pixel height (radians)
dfValue = 0.01 * M_PI / 180.0;
CPL_LSBPTR64( &dfValue );
memcpy( achHeader + 120, &dfValue, 8 );
// raster width in pixels
nValue32 = nXSize;
CPL_LSBPTR32( &nValue32 );
memcpy( achHeader + 128, &nValue32, 4 );
// raster width in pixels
nValue32 = nYSize;
CPL_LSBPTR32( &nValue32 );
memcpy( achHeader + 132, &nValue32, 4 );
VSIFWriteL( achHeader, 1, sizeof(achHeader), fp );
/* -------------------------------------------------------------------- */
/* Write zeroed grid data. */
/* -------------------------------------------------------------------- */
float *pafLine = (float *) CPLCalloc(sizeof(float)*2,nXSize);
int i;
for( i = 0; i < nYSize; i++ )
{
if( (int)VSIFWriteL( pafLine, sizeof(float)*2, nXSize, fp ) != nXSize )
{
CPLError( CE_Failure, CPLE_FileIO,
"Write failed at line %d, perhaps the disk is full?",
i );
return NULL;
}
}
/* -------------------------------------------------------------------- */
/* Cleanup and return. */
/* -------------------------------------------------------------------- */
CPLFree( pafLine );
VSIFCloseL( fp );
//.........这里部分代码省略.........
示例7: ISIS2Dataset
GDALDataset *ISIS2Dataset::Open( GDALOpenInfo * poOpenInfo )
{
/* -------------------------------------------------------------------- */
/* Does this look like a CUBE or an IMAGE Primary Data Object? */
/* -------------------------------------------------------------------- */
if( !Identify( poOpenInfo ) || poOpenInfo->fpL == nullptr )
return nullptr;
VSILFILE *fpQube = poOpenInfo->fpL;
poOpenInfo->fpL = nullptr;
ISIS2Dataset *poDS = new ISIS2Dataset();
if( ! poDS->oKeywords.Ingest( fpQube, 0 ) )
{
VSIFCloseL( fpQube );
delete poDS;
return nullptr;
}
VSIFCloseL( fpQube );
/* -------------------------------------------------------------------- */
/* We assume the user is pointing to the label (i.e. .lab) file. */
/* -------------------------------------------------------------------- */
// QUBE can be inline or detached and point to an image name
// ^QUBE = 76
// ^QUBE = ("ui31s015.img",6441<BYTES>) - has another label on the image
// ^QUBE = "ui31s015.img" - which implies no label or skip value
const char *pszQube = poDS->GetKeyword( "^QUBE" );
GUIntBig nQube = 0;
int bByteLocation = FALSE;
CPLString osTargetFile = poOpenInfo->pszFilename;
if( pszQube[0] == '"' )
{
const CPLString osTPath = CPLGetPath(poOpenInfo->pszFilename);
CPLString osFilename = pszQube;
poDS->CleanString( osFilename );
osTargetFile = CPLFormCIFilename( osTPath, osFilename, nullptr );
poDS->osExternalCube = osTargetFile;
}
else if( pszQube[0] == '(' )
{
const CPLString osTPath = CPLGetPath(poOpenInfo->pszFilename);
CPLString osFilename = poDS->GetKeywordSub("^QUBE",1,"");
poDS->CleanString( osFilename );
osTargetFile = CPLFormCIFilename( osTPath, osFilename, nullptr );
poDS->osExternalCube = osTargetFile;
nQube = atoi(poDS->GetKeywordSub("^QUBE",2,"1"));
if( strstr(poDS->GetKeywordSub("^QUBE",2,"1"),"<BYTES>") != nullptr )
bByteLocation = true;
}
else
{
nQube = atoi(pszQube);
if( strstr(pszQube,"<BYTES>") != nullptr )
bByteLocation = true;
}
/* -------------------------------------------------------------------- */
/* Check if file an ISIS2 header file? Read a few lines of text */
/* searching for something starting with nrows or ncols. */
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/* Checks to see if this is valid ISIS2 cube */
/* SUFFIX_ITEM tag in .cub file should be (0,0,0); no side-planes */
/* -------------------------------------------------------------------- */
const int s_ix = atoi(poDS->GetKeywordSub( "QUBE.SUFFIX_ITEMS", 1 ));
const int s_iy = atoi(poDS->GetKeywordSub( "QUBE.SUFFIX_ITEMS", 2 ));
const int s_iz = atoi(poDS->GetKeywordSub( "QUBE.SUFFIX_ITEMS", 3 ));
if( s_ix != 0 || s_iy != 0 || s_iz != 0 )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"*** ISIS 2 cube file has invalid SUFFIX_ITEMS parameters:\n"
"*** gdal isis2 driver requires (0, 0, 0), thus no sideplanes or backplanes\n"
"found: (%i, %i, %i)\n\n", s_ix, s_iy, s_iz );
delete poDS;
return nullptr;
}
/**************** end SUFFIX_ITEM check ***********************/
/*********** Grab layout type (BSQ, BIP, BIL) ************/
// AXIS_NAME = (SAMPLE,LINE,BAND)
/***********************************************************/
char szLayout[10] = "BSQ"; //default to band seq.
const char *value = poDS->GetKeyword( "QUBE.AXIS_NAME", "" );
if (EQUAL(value,"(SAMPLE,LINE,BAND)") )
strcpy(szLayout,"BSQ");
else if (EQUAL(value,"(BAND,LINE,SAMPLE)") )
strcpy(szLayout,"BIP");
else if (EQUAL(value,"(SAMPLE,BAND,LINE)") || EQUAL(value,"") )
strcpy(szLayout,"BSQ");
else {
//.........这里部分代码省略.........
示例8: CPLError
GDALDataset* SIGDEMDataset::CreateCopy(
const char * pszFilename,
GDALDataset * poSrcDS,
int /*bStrict*/,
char ** /*papszOptions*/,
GDALProgressFunc pfnProgress,
void * pProgressData) {
const int nBands = poSrcDS->GetRasterCount();
double adfGeoTransform[6] = { };
if (poSrcDS->GetGeoTransform(adfGeoTransform) != CE_None) {
CPLError(CE_Failure, CPLE_NotSupported,
"SIGDEM driver requires a valid GeoTransform.");
return nullptr;
}
if (nBands != 1) {
CPLError(CE_Failure, CPLE_NotSupported,
"SIGDEM driver doesn't support %d bands. Must be 1 band.",
nBands);
return nullptr;
}
VSILFILE *fp = VSIFOpenL(pszFilename, "wb");
if (fp == nullptr) {
CPLError(CE_Failure, CPLE_OpenFailed,
"Attempt to create file `%s' failed.", pszFilename);
return nullptr;
}
GDALRasterBand* band = poSrcDS->GetRasterBand(1);
const char* pszProjection = poSrcDS->GetProjectionRef();
int32_t nCols = poSrcDS->GetRasterXSize();
int32_t nRows = poSrcDS->GetRasterYSize();
int32_t nCoordinateSystemId = GetCoordinateSystemId(pszProjection);
SIGDEMHeader sHeader;
sHeader.nCoordinateSystemId = nCoordinateSystemId;
sHeader.dfMinX = adfGeoTransform[0];
const char* pszMin = band->GetMetadataItem("STATISTICS_MINIMUM");
if (pszMin == nullptr) {
sHeader.dfMinZ = -10000;
} else {
sHeader.dfMinZ = CPLAtof(pszMin);
}
sHeader.dfMaxY = adfGeoTransform[3];
const char* pszMax = band->GetMetadataItem("STATISTICS_MAXIMUM");
if (pszMax == nullptr) {
sHeader.dfMaxZ = 10000;
} else {
sHeader.dfMaxZ = CPLAtof(pszMax);
}
sHeader.nCols = poSrcDS->GetRasterXSize();
sHeader.nRows = poSrcDS->GetRasterYSize();
sHeader.dfXDim = adfGeoTransform[1];
sHeader.dfYDim = -adfGeoTransform[5];
sHeader.dfMaxX = sHeader.dfMinX + sHeader.nCols * sHeader.dfXDim;
sHeader.dfMinY = sHeader.dfMaxY - sHeader.nRows * sHeader.dfYDim;
sHeader.dfOffsetX = sHeader.dfMinX;
sHeader.dfOffsetY = sHeader.dfMinY;
if( !sHeader.Write(fp) )
{
VSIUnlink(pszFilename);
VSIFCloseL(fp);
return nullptr;
}
// Write fill with all NO_DATA values
int32_t* row = static_cast<int32_t*>(VSI_MALLOC2_VERBOSE(nCols, sizeof(int32_t)));
if( !row ) {
VSIUnlink(pszFilename);
VSIFCloseL(fp);
return nullptr;
}
std::fill(row, row + nCols, CPL_MSBWORD32(NO_DATA));
for (int i = 0; i < nRows; i++) {
if( VSIFWriteL(row, CELL_SIZE_FILE, nCols, fp) !=
static_cast<size_t>(nCols) )
{
VSIFree(row);
VSIUnlink(pszFilename);
VSIFCloseL(fp);
return nullptr;
}
}
VSIFree(row);
if (VSIFCloseL(fp) != 0) {
return nullptr;
}
if (nCoordinateSystemId <= 0) {
if (!EQUAL(pszProjection, "")) {
CPLString osPrjFilename = CPLResetExtension(pszFilename, "prj");
VSILFILE *fpProj = VSIFOpenL(osPrjFilename, "wt");
if (fpProj != nullptr) {
OGRSpatialReference oSRS;
oSRS.importFromWkt(pszProjection);
oSRS.morphToESRI();
//.........这里部分代码省略.........
示例9: CPLError
GDALDataset *GTXDataset::Create( const char * pszFilename,
int nXSize, int nYSize, int nBands,
GDALDataType eType,
char ** papszOptions )
{
if( eType != GDT_Float32 )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Attempt to create gtx file with unsupported data type '%s'.",
GDALGetDataTypeName( eType ) );
return NULL;
}
if( !EQUAL(CPLGetExtension(pszFilename),"gtx") )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Attempt to create gtx file with extension other than gtx." );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Try to create the file. */
/* -------------------------------------------------------------------- */
VSILFILE *fp;
fp = VSIFOpenL( pszFilename, "wb" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to create file `%s' failed.\n",
pszFilename );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Write out the header with stub georeferencing. */
/* -------------------------------------------------------------------- */
unsigned char header[40];
double dfXOrigin=0, dfYOrigin=0, dfXSize=0.01, dfYSize=0.01;
GInt32 nXSize32 = nXSize, nYSize32 = nYSize;
memcpy( header + 0, &dfYOrigin, 8 );
CPL_MSBPTR64( header + 0 );
memcpy( header + 8, &dfXOrigin, 8 );
CPL_MSBPTR64( header + 8 );
memcpy( header + 16, &dfYSize, 8 );
CPL_MSBPTR64( header + 16 );
memcpy( header + 24, &dfXSize, 8 );
CPL_MSBPTR64( header + 24 );
memcpy( header + 32, &nYSize32, 4 );
CPL_MSBPTR32( header + 32 );
memcpy( header + 36, &nXSize32, 4 );
CPL_MSBPTR32( header + 36 );
VSIFWriteL( header, 40, 1, fp );
VSIFCloseL( fp );
return (GDALDataset *) GDALOpen( pszFilename, GA_Update );
}
示例10: CPLError
//.........这里部分代码省略.........
/* -------------------------------------------------------------------- */
VSILFILE *fp = VSIFOpenL( pszFilename, "w" );
if( fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Failed to create file '%s': %s",
pszFilename, VSIStrerror( errno ) );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Prepare and write 512 byte header. */
/* -------------------------------------------------------------------- */
GByte abyHeader[512];
memset( abyHeader, 0, 512 );
abyHeader[0] = 1;
abyHeader[1] = 218;
abyHeader[2] = 1; // RLE
abyHeader[3] = 1; // 8bit
GInt16 nShortValue;
if( nBands == 1 )
nShortValue = CPL_MSBWORD16(2);
else
nShortValue = CPL_MSBWORD16(3);
memcpy( abyHeader + 4, &nShortValue, 2 );
nShortValue = CPL_MSBWORD16(nXSize);
memcpy( abyHeader + 6, &nShortValue, 2 );
nShortValue = CPL_MSBWORD16(nYSize);
memcpy( abyHeader + 8, &nShortValue, 2 );
nShortValue = CPL_MSBWORD16(nBands);
memcpy( abyHeader + 10, &nShortValue, 2 );
GInt32 nIntValue = CPL_MSBWORD32(0);
memcpy( abyHeader + 12, &nIntValue, 4 );
GUInt32 nUIntValue = CPL_MSBWORD32(255);
memcpy( abyHeader + 16, &nUIntValue, 4 );
VSIFWriteL( abyHeader, 1, 512, fp );
/* -------------------------------------------------------------------- */
/* Create our RLE compressed zero-ed dummy line. */
/* -------------------------------------------------------------------- */
GByte *pabyRLELine = reinterpret_cast<GByte *>(
CPLMalloc( ( nXSize / 127 ) * 2 + 4 ) );
int nPixelsRemaining = nXSize;
GInt32 nRLEBytes = 0;
while( nPixelsRemaining > 0 )
{
pabyRLELine[nRLEBytes] = static_cast<GByte>(
std::min( 127, nPixelsRemaining ) );
pabyRLELine[nRLEBytes+1] = 0;
nPixelsRemaining -= pabyRLELine[nRLEBytes];
nRLEBytes += 2;
}
/* -------------------------------------------------------------------- */
/* Prepare and write RLE offset/size tables with everything */
/* zeroed indicating dummy lines. */
/* -------------------------------------------------------------------- */
const int nTableLen = nYSize * nBands;
GInt32 nDummyRLEOffset = 512 + 4 * nTableLen * 2;
CPL_MSBPTR32( &nRLEBytes );
CPL_MSBPTR32( &nDummyRLEOffset );
for( int i = 0; i < nTableLen; i++ )
VSIFWriteL( &nDummyRLEOffset, 1, 4, fp );
for( int i = 0; i < nTableLen; i++ )
VSIFWriteL( &nRLEBytes, 1, 4, fp );
/* -------------------------------------------------------------------- */
/* write the dummy RLE blank line. */
/* -------------------------------------------------------------------- */
CPL_MSBPTR32( &nRLEBytes );
if( static_cast<GInt32>( VSIFWriteL( pabyRLELine, 1, nRLEBytes, fp ) )
!= nRLEBytes )
{
CPLError( CE_Failure, CPLE_FileIO,
"Failure writing SGI file '%s'.\n%s",
pszFilename,
VSIStrerror( errno ) );
return NULL;
}
VSIFCloseL( fp );
CPLFree( pabyRLELine );
return reinterpret_cast<GDALDataset *>(
GDALOpen( pszFilename, GA_Update ) );
}
示例11: CPLError
//.........这里部分代码省略.........
int nDecimalCount = 7;
int bHasNoDataValue = FALSE;
double dfNoDataValue =
poSrcDS->GetRasterBand(1)->GetNoDataValue(&bHasNoDataValue);
if (!bHasNoDataValue)
dfNoDataValue = 1.e30;
VSIFPrintfL(fp, "!\n");
VSIFPrintfL(fp, "! Created by GDAL.\n");
VSIFPrintfL(fp, "!\n");
VSIFPrintfL(fp, "@GRID FILE, GRID, %d\n", nValuesPerLine);
WriteRightJustified(fp, nFieldSize, 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, dfNoDataValue, 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, "", 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, nDecimalCount, 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, 1, 10);
VSIFPrintfL(fp, "\n");
WriteRightJustified(fp, nYSize, 10);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, nXSize, 10);
VSIFPrintfL(fp, ",");
if (CSLTestBoolean(CPLGetConfigOption("ZMAP_PIXEL_IS_POINT", "FALSE")))
{
WriteRightJustified(fp, adfGeoTransform[0] + adfGeoTransform[1] / 2, 14, 7);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, adfGeoTransform[0] + adfGeoTransform[1] * nXSize -
adfGeoTransform[1] / 2, 14, 7);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, adfGeoTransform[3] + adfGeoTransform[5] * nYSize -
adfGeoTransform[5] / 2, 14, 7);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, adfGeoTransform[3] + adfGeoTransform[5] / 2, 14, 7);
}
else
{
WriteRightJustified(fp, adfGeoTransform[0], 14, 7);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, adfGeoTransform[0] + adfGeoTransform[1] * nXSize, 14, 7);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, adfGeoTransform[3] + adfGeoTransform[5] * nYSize, 14, 7);
VSIFPrintfL(fp, ",");
WriteRightJustified(fp, adfGeoTransform[3], 14, 7);
}
VSIFPrintfL(fp, "\n");
VSIFPrintfL(fp, "0.0, 0.0, 0.0\n");
VSIFPrintfL(fp, "@\n");
/* -------------------------------------------------------------------- */
/* Copy imagery */
/* -------------------------------------------------------------------- */
double* padfLineBuffer = (double*) CPLMalloc(nYSize * sizeof(double));
int i, j;
CPLErr eErr = CE_None;
for(i=0;i<nXSize && eErr == CE_None;i++)
{
eErr = poSrcDS->GetRasterBand(1)->RasterIO(
GF_Read, i, 0, 1, nYSize,
padfLineBuffer, 1, nYSize,
GDT_Float64, 0, 0);
if (eErr != CE_None)
break;
int bEOLPrinted = FALSE;
for(j=0;j<nYSize;j++)
{
WriteRightJustified(fp, padfLineBuffer[j], nFieldSize, nDecimalCount);
if (((j + 1) % nValuesPerLine) == 0)
{
bEOLPrinted = TRUE;
VSIFPrintfL(fp, "\n");
}
else
bEOLPrinted = FALSE;
}
if (!bEOLPrinted)
VSIFPrintfL(fp, "\n");
if (!pfnProgress( (j+1) * 1.0 / nYSize, NULL, pProgressData))
{
eErr = CE_Failure;
break;
}
}
CPLFree(padfLineBuffer);
VSIFCloseL(fp);
if (eErr != CE_None)
return NULL;
return (GDALDataset*) GDALOpen(pszFilename, GA_ReadOnly);
}
示例12: VSIFOpenL
GDALDataset *ZMapDataset::Open( GDALOpenInfo * poOpenInfo )
{
if (!Identify(poOpenInfo))
return NULL;
/* -------------------------------------------------------------------- */
/* Find dataset characteristics */
/* -------------------------------------------------------------------- */
VSILFILE* fp = VSIFOpenL(poOpenInfo->pszFilename, "rb");
if (fp == NULL)
return NULL;
const char* pszLine;
while((pszLine = CPLReadLine2L(fp, 100, NULL)) != NULL)
{
if (*pszLine == '!')
{
continue;
}
else
break;
}
if (pszLine == NULL)
{
VSIFCloseL(fp);
return NULL;
}
/* Parse first header line */
char** papszTokens = CSLTokenizeString2( pszLine, ",", 0 );
if (CSLCount(papszTokens) != 3)
{
CSLDestroy(papszTokens);
VSIFCloseL(fp);
return NULL;
}
int nValuesPerLine = atoi(papszTokens[2]);
if (nValuesPerLine <= 0)
{
CSLDestroy(papszTokens);
VSIFCloseL(fp);
return NULL;
}
CSLDestroy(papszTokens);
papszTokens = NULL;
/* Parse second header line */
pszLine = CPLReadLine2L(fp, 100, NULL);
if (pszLine == NULL)
{
VSIFCloseL(fp);
return NULL;
}
papszTokens = CSLTokenizeString2( pszLine, ",", 0 );
if (CSLCount(papszTokens) != 5)
{
CSLDestroy(papszTokens);
VSIFCloseL(fp);
return NULL;
}
int nFieldSize = atoi(papszTokens[0]);
double dfNoDataValue = CPLAtofM(papszTokens[1]);
int nDecimalCount = atoi(papszTokens[3]);
int nColumnNumber = atoi(papszTokens[4]);
CSLDestroy(papszTokens);
papszTokens = NULL;
if (nFieldSize <= 0 || nFieldSize >= 40 ||
nDecimalCount <= 0 || nDecimalCount >= nFieldSize ||
nColumnNumber != 1)
{
CPLDebug("ZMap", "nFieldSize=%d, nDecimalCount=%d, nColumnNumber=%d",
nFieldSize, nDecimalCount, nColumnNumber);
VSIFCloseL(fp);
return NULL;
}
/* Parse third header line */
pszLine = CPLReadLine2L(fp, 100, NULL);
if (pszLine == NULL)
{
VSIFCloseL(fp);
return NULL;
}
papszTokens = CSLTokenizeString2( pszLine, ",", 0 );
if (CSLCount(papszTokens) != 6)
{
CSLDestroy(papszTokens);
VSIFCloseL(fp);
return NULL;
}
int nRows = atoi(papszTokens[0]);
int nCols = atoi(papszTokens[1]);
//.........这里部分代码省略.........
示例13: CPLError
int OGRGPXDataSource::Open( const char * pszFilename, int bUpdateIn)
{
if (bUpdateIn)
{
CPLError(CE_Failure, CPLE_NotSupported,
"OGR/GPX driver does not support opening a file in update mode");
return FALSE;
}
#ifdef HAVE_EXPAT
pszName = CPLStrdup( pszFilename );
/* -------------------------------------------------------------------- */
/* Try to open the file. */
/* -------------------------------------------------------------------- */
VSILFILE* fp = VSIFOpenL(pszFilename, "r");
if (fp == NULL)
return FALSE;
validity = GPX_VALIDITY_UNKNOWN;
CPLFree(pszVersion);
pszVersion = NULL;
bUseExtensions = FALSE;
nElementsRead = 0;
XML_Parser oParser = OGRCreateExpatXMLParser();
oCurrentParser = oParser;
XML_SetUserData(oParser, this);
XML_SetElementHandler(oParser, ::startElementValidateCbk, NULL);
XML_SetCharacterDataHandler(oParser, ::dataHandlerValidateCbk);
char aBuf[BUFSIZ];
int nDone;
unsigned int nLen;
int nCount = 0;
/* Begin to parse the file and look for the <gpx> element */
/* It *MUST* be the first element of an XML file */
/* So once we have read the first element, we know if we can */
/* handle the file or not with that driver */
do
{
nDataHandlerCounter = 0;
nLen = (unsigned int) VSIFReadL( aBuf, 1, sizeof(aBuf), fp );
nDone = VSIFEofL(fp);
if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR)
{
if (nLen <= BUFSIZ-1)
aBuf[nLen] = 0;
else
aBuf[BUFSIZ-1] = 0;
if (strstr(aBuf, "<?xml") && strstr(aBuf, "<gpx"))
{
CPLError(CE_Failure, CPLE_AppDefined,
"XML parsing of GPX file failed : %s at line %d, column %d",
XML_ErrorString(XML_GetErrorCode(oParser)),
(int)XML_GetCurrentLineNumber(oParser),
(int)XML_GetCurrentColumnNumber(oParser));
}
validity = GPX_VALIDITY_INVALID;
break;
}
if (validity == GPX_VALIDITY_INVALID)
{
break;
}
else if (validity == GPX_VALIDITY_VALID)
{
/* If we have recognized the <gpx> element, now we try */
/* to recognize if they are <extensions> tags */
/* But we stop to look for after an arbitrary number of tags */
if (bUseExtensions)
break;
else if (nElementsRead > 200)
break;
}
else
{
/* After reading 50 * BUFSIZE bytes, and not finding whether the file */
/* is GPX or not, we give up and fail silently */
nCount ++;
if (nCount == 50)
break;
}
} while (!nDone && nLen > 0 );
XML_ParserFree(oParser);
VSIFCloseL(fp);
if (validity == GPX_VALIDITY_VALID)
{
CPLDebug("GPX", "%s seems to be a GPX file.", pszFilename);
if (bUseExtensions)
CPLDebug("GPX", "It uses <extensions>");
if (pszVersion == NULL)
{
/* Default to 1.1 */
CPLError(CE_Warning, CPLE_AppDefined, "GPX schema version is unknown. "
//.........这里部分代码省略.........
示例14: EpsilonDatasetCreateCopy
//.........这里部分代码省略.........
VSILFILE* fp = VSIFOpenL(pszFilename, "wb");
if (fp == NULL)
return NULL;
/* -------------------------------------------------------------------- */
/* Compute number of blocks, block size, etc... */
/* -------------------------------------------------------------------- */
int nXSize = poSrcDS->GetRasterXSize();
int nYSize = poSrcDS->GetRasterYSize();
if (eMode == EPS_MODE_OTLPF)
{
nBlockXSize ++;
nBlockYSize ++;
}
int nXBlocks = (nXSize + nBlockXSize - 1) / nBlockXSize;
int nYBlocks = (nYSize + nBlockYSize - 1) / nBlockYSize;
int nBlocks = nXBlocks * nYBlocks;
int nUncompressedFileSize = nXSize * nYSize * nBands;
int nUncompressedBlockSize = nUncompressedFileSize / nBlocks;
int nTargetBlockSize = (int) (dfReductionFactor * nUncompressedBlockSize);
if (nBands == 1)
nTargetBlockSize = MAX (nTargetBlockSize, EPS_MIN_GRAYSCALE_BUF + 1);
else
nTargetBlockSize = MAX (nTargetBlockSize, EPS_MIN_TRUECOLOR_BUF + 1);
/* -------------------------------------------------------------------- */
/* Allocate work buffers */
/* -------------------------------------------------------------------- */
GByte* pabyBuffer = (GByte*)VSIMalloc3(nBlockXSize, nBlockYSize, nBands);
if (pabyBuffer == NULL)
{
VSIFCloseL(fp);
return NULL;
}
GByte* pabyOutBuf = (GByte*)VSIMalloc(nTargetBlockSize);
if (pabyOutBuf == NULL)
{
VSIFree(pabyBuffer);
VSIFCloseL(fp);
return NULL;
}
GByte** apapbyRawBuffer[3];
int i, j;
for(i=0;i<nBands;i++)
{
apapbyRawBuffer[i] = (GByte**) VSIMalloc(sizeof(GByte*) * nBlockYSize);
for(j=0;j<nBlockYSize;j++)
{
apapbyRawBuffer[i][j] =
pabyBuffer + (i * nBlockXSize + j) * nBlockYSize;
}
}
if (bRasterliteOutput)
{
const char* pszHeader = RASTERLITE_WAVELET_HEADER;
VSIFWriteL(pszHeader, 1, strlen(pszHeader) + 1, fp);
}
/* -------------------------------------------------------------------- */
/* Iterate over blocks */
/* -------------------------------------------------------------------- */
示例15: CPLError
int OGRGeoRSSDataSource::Open( const char * pszFilename, int bUpdateIn)
{
if (bUpdateIn)
{
CPLError(CE_Failure, CPLE_NotSupported,
"OGR/GeoRSS driver does not support opening a file in update mode");
return FALSE;
}
#ifdef HAVE_EXPAT
pszName = CPLStrdup( pszFilename );
/* -------------------------------------------------------------------- */
/* Try to open the file. */
/* -------------------------------------------------------------------- */
VSILFILE* fp = VSIFOpenL(pszFilename, "r");
if (fp == NULL)
return FALSE;
validity = GEORSS_VALIDITY_UNKNOWN;
XML_Parser oParser = OGRCreateExpatXMLParser();
XML_SetUserData(oParser, this);
XML_SetElementHandler(oParser, ::startElementValidateCbk, NULL);
XML_SetCharacterDataHandler(oParser, ::dataHandlerValidateCbk);
oCurrentParser = oParser;
char aBuf[BUFSIZ];
int nDone;
unsigned int nLen;
int nCount = 0;
/* Begin to parse the file and look for the <rss> or <feed> element */
/* It *MUST* be the first element of an XML file */
/* So once we have read the first element, we know if we can */
/* handle the file or not with that driver */
do
{
nDataHandlerCounter = 0;
nLen = (unsigned int) VSIFReadL( aBuf, 1, sizeof(aBuf), fp );
nDone = VSIFEofL(fp);
if (XML_Parse(oParser, aBuf, nLen, nDone) == XML_STATUS_ERROR)
{
if (nLen <= BUFSIZ-1)
aBuf[nLen] = 0;
else
aBuf[BUFSIZ-1] = 0;
if (strstr(aBuf, "<?xml") && (strstr(aBuf, "<rss") || strstr(aBuf, "<feed") || strstr(aBuf, "<atom:feed")))
{
CPLError(CE_Failure, CPLE_AppDefined,
"XML parsing of GeoRSS file failed : %s at line %d, column %d",
XML_ErrorString(XML_GetErrorCode(oParser)),
(int)XML_GetCurrentLineNumber(oParser),
(int)XML_GetCurrentColumnNumber(oParser));
}
validity = GEORSS_VALIDITY_INVALID;
break;
}
if (validity == GEORSS_VALIDITY_INVALID)
{
break;
}
else if (validity == GEORSS_VALIDITY_VALID)
{
break;
}
else
{
/* After reading 50 * BUFSIZ bytes, and not finding whether the file */
/* is GeoRSS or not, we give up and fail silently */
nCount ++;
if (nCount == 50)
break;
}
} while (!nDone && nLen > 0 );
XML_ParserFree(oParser);
VSIFCloseL(fp);
if (validity == GEORSS_VALIDITY_VALID)
{
CPLDebug("GeoRSS", "%s seems to be a GeoRSS file.", pszFilename);
nLayers = 1;
papoLayers = (OGRGeoRSSLayer **) CPLRealloc(papoLayers, nLayers * sizeof(OGRGeoRSSLayer*));
papoLayers[0] = new OGRGeoRSSLayer( pszName, "georss", this, NULL, FALSE );
}
return (validity == GEORSS_VALIDITY_VALID);
#else
char aBuf[256];
VSILFILE* fp = VSIFOpenL(pszFilename, "r");
if (fp)
{
unsigned int nLen = (unsigned int)VSIFReadL( aBuf, 1, 255, fp );
aBuf[nLen] = 0;
if (strstr(aBuf, "<?xml") && (strstr(aBuf, "<rss") || strstr(aBuf, "<atom:feed") || strstr(aBuf, "<feed")))
{
CPLError(CE_Failure, CPLE_NotSupported,
//.........这里部分代码省略.........