本文整理汇总了C++中VSIFReadL函数的典型用法代码示例。如果您正苦于以下问题:C++ VSIFReadL函数的具体用法?C++ VSIFReadL怎么用?C++ VSIFReadL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VSIFReadL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 );
/* -------------------------------------------------------------------- */
/* Determine what sort of object this is. */
/* -------------------------------------------------------------------- */
VSIStatBufL sStatBuf;
if( VSIStatL( pszFilename, &sStatBuf ) != 0 )
return FALSE;
if( VSI_ISDIR(sStatBuf.st_mode) )
return FALSE;
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)
{
//.........这里部分代码省略.........
示例2: VSIFSeekL
void E00GRIDDataset::ReadMetadata()
{
if (bHasReadMetadata)
return;
bHasReadMetadata = TRUE;
if (e00ReadPtr == NULL)
{
int nRoundedBlockXSize = ((nRasterXSize + VALS_PER_LINE - 1) /
VALS_PER_LINE) * VALS_PER_LINE;
vsi_l_offset nValsToSkip =
(vsi_l_offset)nRasterYSize * nRoundedBlockXSize;
vsi_l_offset nLinesToSkip = nValsToSkip / VALS_PER_LINE;
int nBytesPerLine = VALS_PER_LINE * E00_FLOAT_SIZE + nBytesEOL;
vsi_l_offset nPos = nDataStart + nLinesToSkip * nBytesPerLine;
VSIFSeekL(fp, nPos, SEEK_SET);
}
else
{
nLastYOff = -1;
const unsigned int BUFFER_SIZE = 65536;
const unsigned int NEEDLE_SIZE = 3*5;
const unsigned int nToRead = BUFFER_SIZE - NEEDLE_SIZE;
char* pabyBuffer = (char*)CPLCalloc(1, BUFFER_SIZE+NEEDLE_SIZE);
int nRead;
int bEOGFound = FALSE;
VSIFSeekL(fp, 0, SEEK_END);
vsi_l_offset nEndPos = VSIFTellL(fp);
if (nEndPos > BUFFER_SIZE)
nEndPos -= BUFFER_SIZE;
else
nEndPos = 0;
VSIFSeekL(fp, nEndPos, SEEK_SET);
#define GOTO_NEXT_CHAR() \
i ++; \
if (pabyBuffer[i] == 13 || pabyBuffer[i] == 10) \
{ \
i++; \
if (pabyBuffer[i] == 10) \
i++; \
} \
while ((nRead = VSIFReadL(pabyBuffer, 1, nToRead, fp)) != 0)
{
int i;
for(i = 0; i < nRead; i++)
{
if (pabyBuffer[i] == 'E')
{
GOTO_NEXT_CHAR();
if (pabyBuffer[i] == 'O')
{
GOTO_NEXT_CHAR();
if (pabyBuffer[i] == 'G')
{
GOTO_NEXT_CHAR();
if (pabyBuffer[i] == '~')
{
GOTO_NEXT_CHAR();
if (pabyBuffer[i] == '}')
{
bEOGFound = TRUE;
break;
}
}
}
}
}
}
if (bEOGFound)
{
VSIFSeekL(fp, VSIFTellL(fp) - nRead + i + 1, SEEK_SET);
e00ReadPtr->iInBufPtr = 0;
e00ReadPtr->szInBuf[0] = '\0';
break;
}
if (nEndPos == 0)
break;
if ((unsigned int)nRead == nToRead)
{
memmove(pabyBuffer + nToRead, pabyBuffer, NEEDLE_SIZE);
if (nEndPos >= (vsi_l_offset)nToRead)
nEndPos -= nToRead;
else
nEndPos = 0;
VSIFSeekL(fp, nEndPos, SEEK_SET);
}
else
break;
}
CPLFree(pabyBuffer);
if (!bEOGFound)
//.........这里部分代码省略.........
示例3: VSIFSeekL
CPLErr OZIRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
void * pImage )
{
OZIDataset *poGDS = (OZIDataset *) poDS;
int nBlock = nBlockYOff * nXBlocks + nBlockXOff;
VSIFSeekL(poGDS->fp, poGDS->panZoomLevelOffsets[nZoomLevel] +
12 + 1024 + 4 * nBlock, SEEK_SET);
int nPointer = ReadInt(poGDS->fp, poGDS->bOzi3, poGDS->nKeyInit);
if (nPointer < 0 || (vsi_l_offset)nPointer >= poGDS->nFileSize)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid offset for block (%d, %d) : %d",
nBlockXOff, nBlockYOff, nPointer);
return CE_Failure;
}
int nNextPointer = ReadInt(poGDS->fp, poGDS->bOzi3, poGDS->nKeyInit);
if (nNextPointer <= nPointer + 16 ||
(vsi_l_offset)nNextPointer >= poGDS->nFileSize)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Invalid next offset for block (%d, %d) : %d",
nBlockXOff, nBlockYOff, nNextPointer);
return CE_Failure;
}
VSIFSeekL(poGDS->fp, nPointer, SEEK_SET);
int nToRead = nNextPointer - nPointer;
GByte* pabyZlibBuffer = (GByte*)CPLMalloc(nToRead);
if (VSIFReadL(pabyZlibBuffer, nToRead, 1, poGDS->fp) != 1)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Not enough byte read for block (%d, %d)",
nBlockXOff, nBlockYOff);
CPLFree(pabyZlibBuffer);
return CE_Failure;
}
if (poGDS->bOzi3)
OZIDecrypt(pabyZlibBuffer, 16, poGDS->nKeyInit);
if (pabyZlibBuffer[0] != 0x78 ||
pabyZlibBuffer[1] != 0xDA)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Bad ZLIB signature for block (%d, %d) : 0x%02X 0x%02X",
nBlockXOff, nBlockYOff, pabyZlibBuffer[0], pabyZlibBuffer[1]);
CPLFree(pabyZlibBuffer);
return CE_Failure;
}
z_stream stream;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
stream.next_in = pabyZlibBuffer + 2;
stream.avail_in = nToRead - 2;
int err = inflateInit2(&(stream), -MAX_WBITS);
int i;
for(i=0;i<64 && err == Z_OK;i++)
{
stream.next_out = (Bytef*)pImage + (63 - i) * 64;
stream.avail_out = 64;
err = inflate(& (stream), Z_NO_FLUSH);
if (err != Z_OK && err != Z_STREAM_END)
break;
if (pabyTranslationTable)
{
int j;
GByte* ptr = ((GByte*)pImage) + (63 - i) * 64;
for(j=0;j<64;j++)
{
*ptr = pabyTranslationTable[*ptr];
ptr ++;
}
}
}
inflateEnd(&stream);
CPLFree(pabyZlibBuffer);
return (err == Z_OK || err == Z_STREAM_END) ? CE_None : CE_Failure;
}
示例4: CPLStrdup
int OGRIdrisiDataSource::Open( const char * pszFilename )
{
pszName = CPLStrdup( pszFilename );
VSILFILE* fpVCT = VSIFOpenL(pszFilename, "rb");
if (fpVCT == NULL)
return FALSE;
char* pszWTKString = NULL;
// --------------------------------------------------------------------
// Look for .vdc file
// --------------------------------------------------------------------
const char* pszVDCFilename = CPLResetExtension(pszFilename, "vdc");
VSILFILE* fpVDC = VSIFOpenL(pszVDCFilename, "rb");
if (fpVDC == NULL)
{
pszVDCFilename = CPLResetExtension(pszFilename, "VDC");
fpVDC = VSIFOpenL(pszVDCFilename, "rb");
}
char** papszVDC = NULL;
if (fpVDC != NULL)
{
VSIFCloseL(fpVDC);
fpVDC = NULL;
CPLPushErrorHandler(CPLQuietErrorHandler);
papszVDC = CSLLoad2(pszVDCFilename, 1024, 256, NULL);
CPLPopErrorHandler();
CPLErrorReset();
}
OGRwkbGeometryType eType = wkbUnknown;
if (papszVDC != NULL)
{
CSLSetNameValueSeparator( papszVDC, ":" );
const char *pszVersion = CSLFetchNameValue( papszVDC, "file format " );
if( pszVersion == NULL || !EQUAL( pszVersion, "IDRISI Vector A.1" ) )
{
CSLDestroy( papszVDC );
VSIFCloseL(fpVCT);
return FALSE;
}
const char *pszRefSystem
= CSLFetchNameValue( papszVDC, "ref. system " );
const char *pszRefUnits = CSLFetchNameValue( papszVDC, "ref. units " );
if (pszRefSystem != NULL && pszRefUnits != NULL)
IdrisiGeoReference2Wkt( pszFilename, pszRefSystem, pszRefUnits,
&pszWTKString);
}
GByte chType;
if (VSIFReadL(&chType, 1, 1, fpVCT) != 1)
{
VSIFCloseL(fpVCT);
CSLDestroy( papszVDC );
return FALSE;
}
if (chType == 1)
eType = wkbPoint;
else if (chType == 2)
eType = wkbLineString;
else if (chType == 3)
eType = wkbPolygon;
else
{
CPLError( CE_Failure, CPLE_AppDefined, "Unsupport geometry type : %d",
static_cast<int>(chType) );
VSIFCloseL(fpVCT);
CSLDestroy( papszVDC );
return FALSE;
}
const char *pszMinX = CSLFetchNameValue( papszVDC, "min. X " );
const char *pszMaxX = CSLFetchNameValue( papszVDC, "max. X " );
const char *pszMinY = CSLFetchNameValue( papszVDC, "min. Y " );
const char *pszMaxY = CSLFetchNameValue( papszVDC, "max. Y " );
OGRIdrisiLayer* poLayer = new OGRIdrisiLayer(pszFilename,
CPLGetBasename(pszFilename),
fpVCT, eType, pszWTKString);
papoLayers = static_cast<OGRLayer**>( CPLMalloc(sizeof(OGRLayer*)) );
papoLayers[nLayers ++] = poLayer;
if( pszMinX != NULL && pszMaxX != NULL && pszMinY != NULL &&
pszMaxY != NULL)
{
poLayer->SetExtent(
CPLAtof(pszMinX), CPLAtof(pszMinY), CPLAtof(pszMaxX),
CPLAtof(pszMaxY) );
}
//.........这里部分代码省略.........
示例5: EQUAL
OGRDataSource *OGRPGeoDriver::Open( const char * pszFilename,
int bUpdate )
{
OGRPGeoDataSource *poDS;
if( !EQUALN(pszFilename,"PGEO:",5)
&& !EQUAL(CPLGetExtension(pszFilename),"mdb") )
return NULL;
if( !EQUALN(pszFilename,"PGEO:",5) &&
EQUAL(CPLGetExtension(pszFilename),"mdb") )
{
VSILFILE* fp = VSIFOpenL(pszFilename, "rb");
if (!fp)
return NULL;
GByte* pabyHeader = (GByte*) CPLMalloc(100000);
VSIFReadL(pabyHeader, 100000, 1, fp);
VSIFCloseL(fp);
/* Look for GDB_GeomColumns table */
const GByte pabyNeedle[] = { 'G', 0, 'D', 0, 'B', 0, '_', 0, 'G', 0, 'e', 0, 'o', 0, 'm', 0, 'C', 0, 'o', 0, 'l', 0, 'u', 0, 'm', 0, 'n', 0, 's' };
int bFound = FALSE;
for(int i=0;i<100000 - (int)sizeof(pabyNeedle);i++)
{
if (memcmp(pabyHeader + i, pabyNeedle, sizeof(pabyNeedle)) == 0)
{
bFound = TRUE;
break;
}
}
CPLFree(pabyHeader);
if (!bFound)
return NULL;
}
#ifndef WIN32
// Try to register MDB Tools driver
//
// ODBCINST.INI NOTE:
// This operation requires write access to odbcinst.ini file
// located in directory pointed by ODBCINISYS variable.
// Usually, it points to /etc, so non-root users can overwrite this
// setting ODBCINISYS with location they have write access to, e.g.:
// $ export ODBCINISYS=$HOME/etc
// $ touch $ODBCINISYS/odbcinst.ini
//
// See: http://www.unixodbc.org/internals.html
//
if ( !InstallMdbDriver() )
{
CPLError( CE_Warning, CPLE_AppDefined,
"Unable to install MDB driver for ODBC, MDB access may not supported.\n" );
}
else
CPLDebug( "PGeo", "MDB Tools driver installed successfully!");
#endif /* ndef WIN32 */
// Open data source
poDS = new OGRPGeoDataSource();
if( !poDS->Open( pszFilename, bUpdate, TRUE ) )
{
delete poDS;
return NULL;
}
else
return poDS;
}
示例6: sizeof
CPLErr HF2RasterBand::IReadBlock( int nBlockXOff, int nLineYOff,
void * pImage )
{
HF2Dataset *poGDS = (HF2Dataset *) poDS;
int nXBlocks = (nRasterXSize + nBlockXSize - 1) / nBlockXSize;
int nYBlocks = (nRasterYSize + nBlockXSize - 1) / nBlockXSize;
if (!poGDS->LoadBlockMap())
return CE_Failure;
if (pafBlockData == NULL)
{
pafBlockData = (float*)VSIMalloc3(nXBlocks * sizeof(float), poGDS->nTileSize, poGDS->nTileSize);
if (pafBlockData == NULL)
return CE_Failure;
}
nLineYOff = nRasterYSize - 1 - nLineYOff;
int nBlockYOff = nLineYOff / nBlockXSize;
int nYOffInTile = nLineYOff % nBlockXSize;
if (nBlockYOff != nLastBlockYOff)
{
nLastBlockYOff = nBlockYOff;
memset(pafBlockData, 0, nXBlocks * sizeof(float) * nBlockXSize * nBlockXSize);
/* 4 * nBlockXSize is the upper bound */
void* pabyData = CPLMalloc( 4 * nBlockXSize );
int nxoff;
for(nxoff = 0; nxoff < nXBlocks; nxoff++)
{
VSIFSeekL(poGDS->fp, poGDS->panBlockOffset[(nYBlocks - 1 - nBlockYOff) * nXBlocks + nxoff], SEEK_SET);
float fScale, fOff;
VSIFReadL(&fScale, 4, 1, poGDS->fp);
VSIFReadL(&fOff, 4, 1, poGDS->fp);
CPL_LSBPTR32(&fScale);
CPL_LSBPTR32(&fOff);
int nTileWidth = MIN(nBlockXSize, nRasterXSize - nxoff * nBlockXSize);
int nTileHeight = MIN(nBlockXSize, nRasterYSize - nBlockYOff * nBlockXSize);
int j;
for(j=0;j<nTileHeight;j++)
{
GByte nWordSize;
VSIFReadL(&nWordSize, 1, 1, poGDS->fp);
if (nWordSize != 1 && nWordSize != 2 && nWordSize != 4)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Unexpected word size : %d", (int)nWordSize);
break;
}
GInt32 nVal;
VSIFReadL(&nVal, 4, 1, poGDS->fp);
CPL_LSBPTR32(&nVal);
VSIFReadL(pabyData, nWordSize * (nTileWidth - 1), 1, poGDS->fp);
#if defined(CPL_MSB)
if (nWordSize > 1)
GDALSwapWords(pabyData, nWordSize, nTileWidth - 1, nWordSize);
#endif
pafBlockData[nxoff * nBlockXSize * nBlockXSize + j * nBlockXSize + 0] = nVal * fScale + fOff;
int i;
for(i=1;i<nTileWidth;i++)
{
if (nWordSize == 1)
nVal += ((char*)pabyData)[i-1];
else if (nWordSize == 2)
nVal += ((GInt16*)pabyData)[i-1];
else
nVal += ((GInt32*)pabyData)[i-1];
pafBlockData[nxoff * nBlockXSize * nBlockXSize + j * nBlockXSize + i] = nVal * fScale + fOff;
}
}
}
CPLFree(pabyData);
}
int nTileWidth = MIN(nBlockXSize, nRasterXSize - nBlockXOff * nBlockXSize);
memcpy(pImage, pafBlockData + nBlockXOff * nBlockXSize * nBlockXSize +
nYOffInTile * nBlockXSize,
nTileWidth * sizeof(float));
return CE_None;
}
示例7: _tiffReadProc
static tsize_t
_tiffReadProc(thandle_t th, tdata_t buf, tsize_t size)
{
GDALTiffHandle* psGTH = (GDALTiffHandle*) th;
return VSIFReadL( buf, 1, size, psGTH->fpL );
}
示例8: CPLStrdup
int OGRHTFDataSource::Open( const char * pszFilename, int bUpdateIn)
{
if (bUpdateIn)
{
return FALSE;
}
pszName = CPLStrdup( pszFilename );
// --------------------------------------------------------------------
// Does this appear to be a .htf file?
// --------------------------------------------------------------------
VSILFILE* fp = VSIFOpenL(pszFilename, "rb");
if (fp == NULL)
return FALSE;
char szBuffer[11];
int nbRead = (int)VSIFReadL(szBuffer, 1, sizeof(szBuffer) - 1, fp);
szBuffer[nbRead] = '\0';
int bIsHTF = strcmp(szBuffer, "HTF HEADER") == 0;
if (!bIsHTF)
{
VSIFCloseL(fp);
return FALSE;
}
VSIFSeekL(fp, 0, SEEK_SET);
const char* pszLine;
int bEndOfHTFHeader = FALSE;
int bIsSouth = FALSE;
int bGeodeticDatumIsWGS84 = FALSE;
int bIsUTM = FALSE;
int nZone = 0;
int nLines = 0;
int bHasSWEasting = FALSE, bHasSWNorthing = FALSE, bHasNEEasting = FALSE, bHasNENorthing = FALSE;
double dfSWEasting = 0, dfSWNorthing = 0, dfNEEasting = 0, dfNENorthing = 0;
std::vector<CPLString> aosMD;
int nTotalSoundings = 0;
while( (pszLine = CPLReadLine2L(fp, 1024, NULL)) != NULL)
{
nLines ++;
if (nLines == 1000)
{
break;
}
if (*pszLine == ';' || *pszLine == '\0')
continue;
if (strcmp(pszLine, "END OF HTF HEADER") == 0)
{
bEndOfHTFHeader = TRUE;
break;
}
aosMD.push_back(pszLine);
if (strncmp(pszLine, "GEODETIC DATUM: ", 16) == 0)
{
if (strcmp(pszLine + 16, "WG84") == 0 ||
strcmp(pszLine + 16, "WGS84") == 0)
bGeodeticDatumIsWGS84 = TRUE;
else
{
VSIFCloseL(fp);
CPLError(CE_Failure, CPLE_NotSupported,
"Unsupported datum : %s", pszLine + 16);
return FALSE;
}
}
else if (strncmp(pszLine, "NE LATITUDE: -", 14) == 0)
bIsSouth = TRUE;
else if (strncmp(pszLine, "GRID REFERENCE SYSTEM: ", 23) == 0)
{
if (strncmp(pszLine + 23, "UTM", 3) == 0)
bIsUTM = TRUE;
else
{
VSIFCloseL(fp);
CPLError(CE_Failure, CPLE_NotSupported,
"Unsupported grid : %s", pszLine + 23);
return FALSE;
}
}
else if (strncmp(pszLine, "GRID ZONE: ", 11) == 0)
{
nZone = atoi(pszLine + 11);
}
else if (strncmp(pszLine, "SW GRID COORDINATE - EASTING: ", 30) == 0)
{
bHasSWEasting = TRUE;
dfSWEasting = atof(pszLine + 30);
}
else if (strncmp(pszLine, "SW GRID COORDINATE - NORTHING: ", 31) == 0)
{
bHasSWNorthing = TRUE;
dfSWNorthing = atof(pszLine + 31);
//.........这里部分代码省略.........
示例9: strstr
GDALDataset *XPMDataset::Open( GDALOpenInfo * poOpenInfo )
{
/* -------------------------------------------------------------------- */
/* First we check to see if the file has the expected header */
/* bytes. For now we expect the XPM file to start with a line */
/* containing the letters XPM, and to have "static" in the */
/* header. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->nHeaderBytes < 32
|| strstr((const char *) poOpenInfo->pabyHeader,"XPM") == NULL
|| strstr((const char *) poOpenInfo->pabyHeader,"static") == NULL )
return NULL;
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The XPM driver does not support update access to existing"
" files." );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Read the whole file into a memory strings. */
/* -------------------------------------------------------------------- */
unsigned int nFileSize;
char *pszFileContents;
VSILFILE *fp = VSIFOpenL( poOpenInfo->pszFilename, "rb" );
if( fp == NULL )
return NULL;
VSIFSeekL( fp, 0, SEEK_END );
nFileSize = VSIFTellL( fp );
pszFileContents = (char *) VSIMalloc(nFileSize+1);
if( pszFileContents == NULL )
{
CPLError( CE_Failure, CPLE_OutOfMemory,
"Insufficient memory for loading XPM file %s into memory.",
poOpenInfo->pszFilename );
VSIFCloseL(fp);
return NULL;
}
pszFileContents[nFileSize] = '\0';
VSIFSeekL( fp, 0, SEEK_SET );
if( VSIFReadL( pszFileContents, 1, nFileSize, fp ) != nFileSize)
{
CPLFree( pszFileContents );
CPLError( CE_Failure, CPLE_FileIO,
"Failed to read all %d bytes from file %s.",
nFileSize, poOpenInfo->pszFilename );
VSIFCloseL(fp);
return NULL;
}
VSIFCloseL(fp);
fp = NULL;
/* -------------------------------------------------------------------- */
/* Convert into a binary image. */
/* -------------------------------------------------------------------- */
GByte *pabyImage;
int nXSize, nYSize;
GDALColorTable *poCT = NULL;
CPLErrorReset();
pabyImage = ParseXPM( pszFileContents, &nXSize, &nYSize, &poCT );
CPLFree( pszFileContents );
if( pabyImage == NULL )
{
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
XPMDataset *poDS;
poDS = new XPMDataset();
/* -------------------------------------------------------------------- */
/* Capture some information from the file that is of interest. */
/* -------------------------------------------------------------------- */
poDS->nRasterXSize = nXSize;
poDS->nRasterYSize = nYSize;
/* -------------------------------------------------------------------- */
/* Create band information objects. */
/* -------------------------------------------------------------------- */
MEMRasterBand *poBand;
poBand = new MEMRasterBand( poDS, 1, pabyImage, GDT_Byte, 1, nXSize,
TRUE );
poBand->SetColorTable( poCT );
poDS->SetBand( 1, poBand );
//.........这里部分代码省略.........
示例10: BTDataset
GDALDataset *BTDataset::Open( GDALOpenInfo * poOpenInfo )
{
/* -------------------------------------------------------------------- */
/* Verify that this is some form of binterr file. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->nHeaderBytes < 256)
return NULL;
if( strncmp( (const char *) poOpenInfo->pabyHeader, "binterr", 7 ) != 0 )
return NULL;
/* -------------------------------------------------------------------- */
/* Create the dataset. */
/* -------------------------------------------------------------------- */
BTDataset *poDS;
poDS = new BTDataset();
memcpy( poDS->abyHeader, poOpenInfo->pabyHeader, 256 );
/* -------------------------------------------------------------------- */
/* Get the version. */
/* -------------------------------------------------------------------- */
char szVersion[4];
strncpy( szVersion, (char *) (poDS->abyHeader + 7), 3 );
szVersion[3] = '\0';
poDS->nVersionCode = (int) (atof(szVersion) * 10);
/* -------------------------------------------------------------------- */
/* Extract core header information, being careful about the */
/* version. */
/* -------------------------------------------------------------------- */
GInt32 nIntTemp;
GInt16 nDataSize;
GDALDataType eType;
memcpy( &nIntTemp, poDS->abyHeader + 10, 4 );
poDS->nRasterXSize = CPL_LSBWORD32( nIntTemp );
memcpy( &nIntTemp, poDS->abyHeader + 14, 4 );
poDS->nRasterYSize = CPL_LSBWORD32( nIntTemp );
if (!GDALCheckDatasetDimensions(poDS->nRasterXSize, poDS->nRasterYSize))
{
delete poDS;
return NULL;
}
memcpy( &nDataSize, poDS->abyHeader+18, 2 );
nDataSize = CPL_LSBWORD16( nDataSize );
if( poDS->abyHeader[20] != 0 && nDataSize == 4 )
eType = GDT_Float32;
else if( poDS->abyHeader[20] == 0 && nDataSize == 4 )
eType = GDT_Int32;
else if( poDS->abyHeader[20] == 0 && nDataSize == 2 )
eType = GDT_Int16;
else
{
CPLError( CE_Failure, CPLE_AppDefined,
".bt file data type unknown, got datasize=%d.",
nDataSize );
delete poDS;
return NULL;
}
/*
rcg, apr 7/06: read offset 62 for vert. units.
If zero, assume 1.0 as per spec.
*/
memcpy( &poDS->m_fVscale, poDS->abyHeader + 62, 4 );
CPL_LSBPTR32(&poDS->m_fVscale);
if(poDS->m_fVscale == 0.0f)
poDS->m_fVscale = 1.0f;
/* -------------------------------------------------------------------- */
/* Try to read a .prj file if it is indicated. */
/* -------------------------------------------------------------------- */
OGRSpatialReference oSRS;
if( poDS->nVersionCode >= 12 && poDS->abyHeader[60] != 0 )
{
const char *pszPrjFile = CPLResetExtension( poOpenInfo->pszFilename,
"prj" );
VSILFILE *fp;
fp = VSIFOpenL( pszPrjFile, "rt" );
if( fp != NULL )
{
char *pszBuffer, *pszBufPtr;
int nBufMax = 10000;
int nBytes;
pszBuffer = (char *) CPLMalloc(nBufMax);
nBytes = VSIFReadL( pszBuffer, 1, nBufMax-1, fp );
VSIFCloseL( fp );
//.........这里部分代码省略.........
示例11: ELASDataset
GDALDataset *ELASDataset::Open( GDALOpenInfo * poOpenInfo )
{
if( !Identify(poOpenInfo) )
return NULL;
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
ELASDataset *poDS;
const char *pszAccess;
if( poOpenInfo->eAccess == GA_Update )
pszAccess = "r+b";
else
pszAccess = "rb";
poDS = new ELASDataset();
poDS->fp = VSIFOpenL( poOpenInfo->pszFilename, pszAccess );
if( poDS->fp == NULL )
{
CPLError( CE_Failure, CPLE_OpenFailed,
"Attempt to open `%s' with acces `%s' failed.\n",
poOpenInfo->pszFilename, pszAccess );
delete poDS;
return NULL;
}
poDS->eAccess = poOpenInfo->eAccess;
/* -------------------------------------------------------------------- */
/* Read the header information. */
/* -------------------------------------------------------------------- */
poDS->bHeaderModified = FALSE;
if( VSIFReadL( &(poDS->sHeader), 1024, 1, poDS->fp ) != 1 )
{
CPLError( CE_Failure, CPLE_FileIO,
"Attempt to read 1024 byte header filed on file %s\n",
poOpenInfo->pszFilename );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Extract information of interest from the header. */
/* -------------------------------------------------------------------- */
int nStart, nEnd, nELASDataType, nBytesPerSample;
poDS->nLineOffset = CPL_MSBWORD32( poDS->sHeader.NBPR );
nStart = CPL_MSBWORD32( poDS->sHeader.IL );
nEnd = CPL_MSBWORD32( poDS->sHeader.LL );
poDS->nRasterYSize = nEnd - nStart + 1;
nStart = CPL_MSBWORD32( poDS->sHeader.IE );
nEnd = CPL_MSBWORD32( poDS->sHeader.LE );
poDS->nRasterXSize = nEnd - nStart + 1;
poDS->nBands = CPL_MSBWORD32( poDS->sHeader.NC );
if (!GDALCheckDatasetDimensions(poDS->nRasterXSize, poDS->nRasterYSize) ||
!GDALCheckBandCount(poDS->nBands, FALSE))
{
delete poDS;
return NULL;
}
nELASDataType = (poDS->sHeader.IH19[2] & 0x7e) >> 2;
nBytesPerSample = poDS->sHeader.IH19[3];
if( nELASDataType == 0 && nBytesPerSample == 1 )
poDS->eRasterDataType = GDT_Byte;
else if( nELASDataType == 1 && nBytesPerSample == 1 )
poDS->eRasterDataType = GDT_Byte;
else if( nELASDataType == 16 && nBytesPerSample == 4 )
poDS->eRasterDataType = GDT_Float32;
else if( nELASDataType == 17 && nBytesPerSample == 8 )
poDS->eRasterDataType = GDT_Float64;
else
{
delete poDS;
CPLError( CE_Failure, CPLE_AppDefined,
"Unrecognised image data type %d, with BytesPerSample=%d.\n",
nELASDataType, nBytesPerSample );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Band offsets are always multiples of 256 within a multi-band */
/* scanline of data. */
/* -------------------------------------------------------------------- */
poDS->nBandOffset =
(poDS->nRasterXSize * GDALGetDataTypeSize(poDS->eRasterDataType)/8);
if( poDS->nBandOffset % 256 != 0 )
{
poDS->nBandOffset =
poDS->nBandOffset - (poDS->nBandOffset % 256) + 256;
}
//.........这里部分代码省略.........
示例12: CPLError
GDALDataset *LCPDataset::Open( GDALOpenInfo * poOpenInfo )
{
/* -------------------------------------------------------------------- */
/* Verify that this is a FARSITE LCP file */
/* -------------------------------------------------------------------- */
if( !Identify( poOpenInfo ) )
return NULL;
/* -------------------------------------------------------------------- */
/* Confirm the requested access is supported. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_Update )
{
CPLError( CE_Failure, CPLE_NotSupported,
"The LCP driver does not support update access to existing"
" datasets.\n" );
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
LCPDataset *poDS;
VSILFILE *fpImage;
fpImage = VSIFOpenL(poOpenInfo->pszFilename, "rb");
if (fpImage == NULL)
return NULL;
poDS = new LCPDataset();
poDS->fpImage = fpImage;
/* -------------------------------------------------------------------- */
/* Read the header and extract some information. */
/* -------------------------------------------------------------------- */
int bHaveCrownFuels, bHaveGroundFuels;
int nBands, i;
long nWidth = -1, nHeight = -1;
int nTemp, nTemp2;
char szTemp[32];
char* pszList;
VSIFSeekL( poDS->fpImage, 0, SEEK_SET );
if (VSIFReadL( poDS->pachHeader, 1, LCP_HEADER_SIZE, poDS->fpImage ) != LCP_HEADER_SIZE)
{
CPLError(CE_Failure, CPLE_FileIO, "File too short");
delete poDS;
return NULL;
}
nWidth = CPL_LSBINT32PTR (poDS->pachHeader + 4164);
nHeight = CPL_LSBINT32PTR (poDS->pachHeader + 4168);
poDS->nRasterXSize = nWidth;
poDS->nRasterYSize = nHeight;
if (!GDALCheckDatasetDimensions(poDS->nRasterXSize, poDS->nRasterYSize))
{
delete poDS;
return NULL;
}
// crown fuels = canopy height, canopy base height, canopy bulk density
// 21 = have them, 20 = don't have them
bHaveCrownFuels = ( CPL_LSBINT32PTR (poDS->pachHeader + 0) - 20 );
// ground fuels = duff loading, coarse woody
bHaveGroundFuels = ( CPL_LSBINT32PTR (poDS->pachHeader + 4) - 20 );
if( bHaveCrownFuels )
{
if( bHaveGroundFuels )
nBands = 10;
else
nBands = 8;
}
else
{
if( bHaveGroundFuels )
nBands = 7;
else
nBands = 5;
}
// add dataset-level metadata
nTemp = CPL_LSBINT32PTR (poDS->pachHeader + 8);
sprintf(szTemp, "%d", nTemp);
poDS->SetMetadataItem( "LATITUDE", szTemp );
nTemp = CPL_LSBINT32PTR (poDS->pachHeader + 4204);
if ( nTemp == 0 )
poDS->SetMetadataItem( "LINEAR_UNIT", "Meters" );
if ( nTemp == 1 )
poDS->SetMetadataItem( "LINEAR_UNIT", "Feet" );
poDS->pachHeader[LCP_HEADER_SIZE-1] = '\0';
poDS->SetMetadataItem( "DESCRIPTION", poDS->pachHeader + 6804 );
//.........这里部分代码省略.........
示例13: _tiffReadProc
static tsize_t
_tiffReadProc(thandle_t fd, tdata_t buf, tsize_t size)
{
return VSIFReadL( buf, 1, size, (VSILFILE *) fd );
}
示例14: GS7BGDataset
GDALDataset *GS7BGDataset::Open( GDALOpenInfo * poOpenInfo )
{
if( !Identify(poOpenInfo) )
{
return NULL;
}
/* ------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* ------------------------------------------------------------------- */
GS7BGDataset *poDS = new GS7BGDataset();
/* ------------------------------------------------------------------- */
/* Open file with large file API. */
/* ------------------------------------------------------------------- */
poDS->eAccess = poOpenInfo->eAccess;
if( poOpenInfo->eAccess == GA_ReadOnly )
poDS->fp = VSIFOpenL( poOpenInfo->pszFilename, "rb" );
else
poDS->fp = VSIFOpenL( poOpenInfo->pszFilename, "r+b" );
if( poDS->fp == NULL )
{
delete poDS;
CPLError( CE_Failure, CPLE_OpenFailed,
"VSIFOpenL(%s) failed unexpectedly.",
poOpenInfo->pszFilename );
return NULL;
}
/* ------------------------------------------------------------------- */
/* Read the header. The Header section must be the first section */
/* in the file. */
/* ------------------------------------------------------------------- */
if( VSIFSeekL( poDS->fp, 0, SEEK_SET ) != 0 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO,
"Unable to seek to start of grid file header.\n" );
return NULL;
}
GInt32 nTag;
GInt32 nSize;
GInt32 nVersion;
if( VSIFReadL( (void *)&nTag, sizeof(GInt32), 1, poDS->fp ) != 1 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO, "Unable to read Tag.\n" );
return NULL;
}
CPL_LSBPTR32( &nTag );
if(nTag != nHEADER_TAG)
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO, "Header tag not found.\n" );
return NULL;
}
if( VSIFReadL( (void *)&nSize, sizeof(GInt32), 1, poDS->fp ) != 1 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO,
"Unable to read file section size.\n" );
return NULL;
}
CPL_LSBPTR32( &nSize );
if( VSIFReadL( (void *)&nVersion, sizeof(GInt32), 1, poDS->fp ) != 1 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO,
"Unable to read file version.\n" );
return NULL;
}
CPL_LSBPTR32( &nVersion );
if(nVersion != 1 && nVersion != 2)
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO,
"Incorrect file version (%d).", nVersion );
return NULL;
}
// advance until the grid tag is found
while(nTag != nGRID_TAG)
{
if( VSIFReadL( (void *)&nTag, sizeof(GInt32), 1, poDS->fp ) != 1 )
{
delete poDS;
CPLError( CE_Failure, CPLE_FileIO, "Unable to read Tag.\n" );
return NULL;
}
//.........这里部分代码省略.........
示例15: KRODataset
GDALDataset *KRODataset::Open( GDALOpenInfo * poOpenInfo )
{
if( !Identify( poOpenInfo ) )
return NULL;
/* -------------------------------------------------------------------- */
/* Create a corresponding GDALDataset. */
/* -------------------------------------------------------------------- */
KRODataset *poDS = new KRODataset();
poDS->eAccess = poOpenInfo->eAccess;
/* -------------------------------------------------------------------- */
/* Open the file. */
/* -------------------------------------------------------------------- */
if( poOpenInfo->eAccess == GA_ReadOnly )
poDS->fpImage = VSIFOpenL( poOpenInfo->pszFilename, "rb" );
else
poDS->fpImage = VSIFOpenL( poOpenInfo->pszFilename, "rb+" );
if( poDS->fpImage == NULL )
{
delete poDS;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Read the file header. */
/* -------------------------------------------------------------------- */
char achHeader[20] = { '\0' };
CPL_IGNORE_RET_VAL(VSIFReadL( achHeader, 1, 20, poDS->fpImage ));
int nXSize;
memcpy(&nXSize, achHeader + 4, 4);
CPL_MSBPTR32( &nXSize );
int nYSize = 0;
memcpy(&nYSize, achHeader + 8, 4);
CPL_MSBPTR32( &nYSize );
int nDepth = 0;
memcpy(&nDepth, achHeader + 12, 4);
CPL_MSBPTR32( &nDepth );
int nComp = 0;
memcpy(&nComp, achHeader + 16, 4);
CPL_MSBPTR32( &nComp );
if( !GDALCheckDatasetDimensions(nXSize, nYSize) ||
!GDALCheckBandCount(nComp, FALSE) )
{
delete poDS;
return NULL;
}
poDS->nRasterXSize = nXSize;
poDS->nRasterYSize = nYSize;
GDALDataType eDT = GDT_Unknown;
if( nDepth == 8 )
{
eDT = GDT_Byte;
}
else if( nDepth == 16 )
{
eDT = GDT_UInt16;
}
else if( nDepth == 32 )
{
eDT = GDT_Float32;
}
else
{
CPLError( CE_Failure, CPLE_AppDefined,
"Unhandled depth : %d", nDepth );
delete poDS;
return NULL;
}
const int nDataTypeSize = nDepth / 8;
if( nComp == 0 || nDataTypeSize == 0 ||
poDS->nRasterXSize > INT_MAX / (nComp * nDataTypeSize) )
{
CPLError( CE_Failure, CPLE_AppDefined,
"Too large width / number of bands" );
delete poDS;
return NULL;
}
/* -------------------------------------------------------------------- */
/* Create bands. */
/* -------------------------------------------------------------------- */
CPLErrorReset();
for( int iBand = 0; iBand < nComp; iBand++ )
{
RawRasterBand *poBand =
new RawRasterBand( poDS, iBand+1, poDS->fpImage,
20 + nDataTypeSize * iBand,
nComp * nDataTypeSize,
//.........这里部分代码省略.........